]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keyboard: fallback on raw keysyms for bindings
authorJohan Malm <jgm323@gmail.com>
Mon, 17 Jul 2023 19:08:32 +0000 (20:08 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 18 Jul 2023 18:29:21 +0000 (19:29 +0100)
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

index 911c19d3b72d4b76a4be758939967d280db423d5..8f2d321b19cce9c4e1de504090854fbf7d998edf 100644 (file)
@@ -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: