From d71344bcddd2fe7447224f29a31695f5844b4474 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 3 Oct 2017 09:15:48 +0200 Subject: [PATCH] Fix modifiers support with backend != wayland --- rootston/rootston.ini.example | 6 ++++++ types/wlr_keyboard.c | 35 ++++++++++++++++++++++++++--------- types/wlr_seat.c | 26 ++++---------------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index 58e5816b..8dd51ea2 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -24,3 +24,9 @@ geometry = 2500x800 map-to-output = VGA-1 # Restrict cursor movements for this mouse to concrete rectangle geometry = 2500x800 + +# Keybindings +# Maps key combinations with commands to execute +# The special command "exit" stops the compositor +[bindings] +Logo+q=exit diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 9c111af4..168475bd 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -21,22 +21,39 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) { wlr_keyboard_led_update(keyboard, leds); } +void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) { + if (mods_depressed == keyboard->modifiers.depressed && + mods_latched == keyboard->modifiers.latched && + mods_locked == keyboard->modifiers.locked && + group == keyboard->modifiers.group) { + return; + } + keyboard->modifiers.depressed = mods_depressed; + keyboard->modifiers.latched = mods_latched; + keyboard->modifiers.locked = mods_locked; + keyboard->modifiers.group = group; +} + void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event) { uint32_t keycode = event->keycode + 8; xkb_state_update_key(keyboard->xkb_state, keycode, event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); keyboard_led_update(keyboard); - wl_signal_emit(&keyboard->events.key, event); -} -void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard, - uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, - uint32_t group) { - keyboard->modifiers.depressed = mods_depressed; - keyboard->modifiers.latched = mods_latched; - keyboard->modifiers.locked = mods_locked; - keyboard->modifiers.group = group; + xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_DEPRESSED); + xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_LATCHED); + xkb_mod_mask_t locked = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_LOCKED); + xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state, + XKB_STATE_LAYOUT_EFFECTIVE); + wlr_keyboard_update_modifiers(keyboard, depressed, latched, locked, group); + + wl_signal_emit(&keyboard->events.key, event); } void wlr_keyboard_init(struct wlr_keyboard *kb, diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ff050223..66b2f18e 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -402,28 +402,10 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { handle->seat_keyboard = seat_kb; } - xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, - XKB_STATE_MODS_DEPRESSED); - xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state, - XKB_STATE_MODS_LATCHED); - xkb_mod_mask_t locked = xkb_state_serialize_mods(keyboard->xkb_state, - XKB_STATE_MODS_LOCKED); - xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state, - XKB_STATE_LAYOUT_EFFECTIVE); - if (depressed != keyboard->modifiers.depressed || - latched != keyboard->modifiers.latched || - locked != keyboard->modifiers.locked || - group != keyboard->modifiers.group) { - keyboard->modifiers.depressed = depressed; - keyboard->modifiers.latched = latched; - keyboard->modifiers.locked = locked; - keyboard->modifiers.group = group; - - uint32_t modifiers_serial = wl_display_next_serial(seat->display); - wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial, depressed, - latched, locked, group); - } - + uint32_t modifiers_serial = wl_display_next_serial(seat->display); + wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial, + keyboard->modifiers.depressed, keyboard->modifiers.latched, + keyboard->modifiers.locked, keyboard->modifiers.group); uint32_t key_serial = wl_display_next_serial(seat->display); wl_keyboard_send_key(handle->keyboard, key_serial, (uint32_t)event->time_usec, event->keycode, key_state);