From c1c624daf0511f52727613ac890c959a66d1c58f Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:15:37 +0200 Subject: [PATCH] keybinds: add optional layoutDependent argument This allows to define keybinds as layout dependent. E.g. keybinds only trigger if the configured key exists in the currently active keyboard layout. The keybind will also only trigger on the physical key that is mapped to the configured key in the active layout. By default the new argument is false which means all keybinds by default are layout agnostic. This optional argument can be used to restore the earlier default behavior of having keys layout dependent. --- docs/labwc-config.5.scd | 12 ++++++++++-- include/config/keybind.h | 1 + src/config/keybind.c | 3 +++ src/config/rcxml.c | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index 8f37ea89..a68ab7e0 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -268,14 +268,22 @@ Therefore, where multiple objects of the same kind are required (for example ## KEYBOARD -** - Define a key binding in the format *modifier-key*, where supported +** + Define a *key* binding in the format *modifier-key*, where supported modifiers include S (shift); C (control); A (alt); W (super). Unlike Openbox, multiple space-separated key combinations and key-chains are not supported. The application "wev" (wayland event viewer) is packaged in a lot of distributions and can be used to view all available keynames. + *layoutDependent* [yes|no] + Make this specific keybind depend on the currently active keyboard + layout. If enabled, a keybind using a key which does not exist in + the currently active layout will not be executed. The physical key + to trigger a keybind may also change along with the active layout. + If set to "no" (or is absent) the keybind will be layout agnostic. + Default is no. + ** Keybind action. See labwc-action(5) diff --git a/include/config/keybind.h b/include/config/keybind.h index 82dabf9f..c61392aa 100644 --- a/include/config/keybind.h +++ b/include/config/keybind.h @@ -14,6 +14,7 @@ struct keybind { uint32_t modifiers; xkb_keysym_t *keysyms; size_t keysyms_len; + bool use_syms_only; xkb_keycode_t keycodes[MAX_KEYCODES]; size_t keycodes_len; int keycodes_layout; diff --git a/src/config/keybind.c b/src/config/keybind.c index 54a15e90..f741b2bd 100644 --- a/src/config/keybind.c +++ b/src/config/keybind.c @@ -59,6 +59,9 @@ update_keycodes_iter(struct xkb_keymap *keymap, xkb_keycode_t key, void *data) /* Prevent storing keycodes from multiple layouts */ continue; } + if (keybind->use_syms_only) { + continue; + } for (int i = 0; i < nr_syms; i++) { xkb_keysym_t sym = syms[i]; for (size_t j = 0; j < keybind->keysyms_len; j++) { diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 5b079cae..c8da660b 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -267,6 +267,8 @@ fill_keybind(char *nodename, char *content) } else if (!current_keybind) { wlr_log(WLR_ERROR, "expect element first. " "nodename: '%s' content: '%s'", nodename, content); + } else if (!strcasecmp(nodename, "layoutDependent")) { + set_bool(content, ¤t_keybind->use_syms_only); } else if (!strcmp(nodename, "name.action")) { current_keybind_action = action_create(content); if (current_keybind_action) {