diff --git a/config.def.h b/config.def.h index f0e7aef..f714509 100644 --- a/config.def.h +++ b/config.def.h @@ -47,6 +47,10 @@ static const struct xkb_rule_names xkb_rules = { .options = NULL, }; +/* numlock and capslock */ +static const int numlock = 1; +static const int capslock = 0; + static const int repeat_rate = 25; static const int repeat_delay = 600; diff --git a/dwl.c b/dwl.c index c80c264..50e1825 100644 --- a/dwl.c +++ b/dwl.c @@ -944,6 +944,8 @@ createkeyboard(struct wlr_input_device *device) { struct xkb_context *context; struct xkb_keymap *keymap; + uint32_t leds = 0; + xkb_mod_mask_t locked_mods = 0; Keyboard *kb = device->data = ecalloc(1, sizeof(*kb)); kb->device = device; @@ -964,6 +966,34 @@ createkeyboard(struct wlr_input_device *device) wlr_seat_set_keyboard(seat, device); + if (numlock) { + xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); + if (mod_index != XKB_MOD_INVALID) { + locked_mods |= (uint32_t)1 << mod_index; + } + } + + if (capslock) { + xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS); + if (mod_index != XKB_MOD_INVALID) { + locked_mods |= (uint32_t)1 << mod_index; + } + } + + if (locked_mods) { + wlr_keyboard_notify_modifiers(device->keyboard, 0, 0, + locked_mods, 0); + + for (uint32_t i = 0; i < WLR_LED_COUNT; ++i) { + if (xkb_state_led_index_is_active( + device->keyboard->xkb_state, + device->keyboard->led_indexes[i])) { + leds |= (1 << i); + } + } + wlr_keyboard_led_update(device->keyboard, leds); + } + /* And add the keyboard to our list of keyboards */ wl_list_insert(&keyboards, &kb->link); }