Skip to content

Commit

Permalink
keyboard: fallback on raw keysyms for bindings
Browse files Browse the repository at this point in the history
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 labwc#163 labwc#365 labwc#992
  • Loading branch information
johanmalm committed Jul 18, 2023
1 parent 8686023 commit c6e2f66
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c6e2f66

Please sign in to comment.