diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-01-06 09:36:57 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-01-06 09:36:57 -0500 |
commit | 97652320965bd24fb1f823dabbf71cb789b2e254 (patch) | |
tree | dee56ecc4cfcb52a6bc172f096ab6b6d71b0a1f0 | |
parent | ca0f456d6c267523615afaed421f28affeaccf6c (diff) |
update xkb state on layout change
-rw-r--r-- | types/wlr_keyboard.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 550ea67f..5a90e6b2 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -25,9 +25,13 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) { wlr_keyboard_led_update(keyboard, leds); } -static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { +/** + * Update the modifier state of the wlr-keyboard. Returns true if the modifier + * state changed. + */ +static bool keyboard_modifier_update(struct wlr_keyboard *keyboard) { if (keyboard->xkb_state == NULL) { - return; + return false; } xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, @@ -42,7 +46,7 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { latched == keyboard->modifiers->latched && locked == keyboard->modifiers->locked && group == keyboard->modifiers->group) { - return; + return false; } keyboard->modifiers->depressed = depressed; @@ -50,7 +54,7 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { keyboard->modifiers->locked = locked; keyboard->modifiers->group = group; - wl_signal_emit(&keyboard->events.modifiers, keyboard); + return true; } // https://www.geeksforgeeks.org/move-zeroes-end-array/ @@ -103,7 +107,11 @@ void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, } xkb_state_update_mask(keyboard->xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); - keyboard_modifier_update(keyboard); + + bool updated = keyboard_modifier_update(keyboard); + if (updated) { + wl_signal_emit(&keyboard->events.modifiers, keyboard); + } } void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, @@ -117,7 +125,12 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); } keyboard_led_update(keyboard); - keyboard_modifier_update(keyboard); + + bool updated = keyboard_modifier_update(keyboard); + if (updated) { + wl_signal_emit(&keyboard->events.modifiers, keyboard); + } + keyboard_key_update(keyboard, event); wl_signal_emit(&keyboard->events.key, event); } @@ -216,7 +229,12 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, strcpy(ptr, keymap_str); free(keymap_str); - // TODO need to update the state with the currently pressed keys + for (size_t i = 0; i < kb->num_keycodes; ++i) { + xkb_keycode_t keycode = kb->keycodes[i] + 8; + xkb_state_update_key(kb->xkb_state, keycode, XKB_KEY_DOWN); + } + + keyboard_modifier_update(kb); wl_signal_emit(&kb->events.keymap, kb); return; |