From c6e2f667d37942e7c517e5c6591dd2a8164a1c9e Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 17 Jul 2023 20:08:32 +0100 Subject: [PATCH] keyboard: fallback on raw keysyms for bindings When looking up keybinds, if the translated keysyms (based on the keymap for the keyboard) do not match a defined keybind, try raw keysyms (as if there were no modifier translation). This allows a user to define for example keybind with "S-1" rather than "S-exclam". It also supports "W-S-Tab". Fixes: issues #163 #365 #992 --- src/keyboard.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/keyboard.c b/src/keyboard.c index 911c19d3..8f2d321b 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -141,6 +141,17 @@ handle_compositor_keybindings(struct keyboard *keyboard, translated.nr_syms = xkb_state_key_get_syms(wlr_keyboard->xkb_state, keycode, &translated.syms); + /* + * Get keysyms from the keyboard as if there was no modifier + * translations. For example, get Shift+1 rather than Shift+! (with US + * keyboard layout). + */ + struct keysyms raw = { 0 }; + xkb_layout_index_t layout_index = + xkb_state_key_get_layout(wlr_keyboard->xkb_state, keycode); + raw.nr_syms = xkb_keymap_key_get_syms_by_level(wlr_keyboard->keymap, + keycode, layout_index, 0, &raw.syms); + bool handled = false; key_state_set_pressed(event->keycode, @@ -246,6 +257,12 @@ handle_compositor_keybindings(struct keyboard *keyboard, for (int i = 0; i < translated.nr_syms; i++) { handled |= handle_keybinding(server, modifiers, translated.syms[i]); } + if (handled) { + goto out; + } + for (int i = 0; i < raw.nr_syms; i++) { + handled |= handle_keybinding(server, modifiers, raw.syms[i]); + } } out: