]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keybinds: add optional layoutDependent argument
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 11 Sep 2023 13:15:37 +0000 (15:15 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 11 Sep 2023 13:41:19 +0000 (15:41 +0200)
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
include/config/keybind.h
src/config/keybind.c
src/config/rcxml.c

index 8f37ea89fcc293a97657f040fc50c229fc93326d..a68ab7e0eab3c6740850e2411ffaa8463c864a27 100644 (file)
@@ -268,14 +268,22 @@ Therefore, where multiple objects of the same kind are required (for example
 
 ## KEYBOARD
 
-*<keyboard><keybind key="">*
-       Define a key binding in the format *modifier-key*, where supported
+*<keyboard><keybind key="" layoutDependent="">*
+       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.
+
 *<keyboard><keybind key=""><action name="">*
        Keybind action. See labwc-action(5)
 
index 82dabf9fe8589a887a21ed250fbaaf17a514bd06..c61392aa4711888d0541fb1ee7b0614a8be83cf8 100644 (file)
@@ -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;
index 54a15e90f7d9d36548b85e4e31f8f57a15a10609..f741b2bdd085597412e6f385e41aa128cb1c79f4 100644 (file)
@@ -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++) {
index 5b079cae3c3a735870f171f2dd9cc277a41ea198..c8da660b44745096d25aee95fa5cd2b9dec2d618 100644 (file)
@@ -267,6 +267,8 @@ fill_keybind(char *nodename, char *content)
        } else if (!current_keybind) {
                wlr_log(WLR_ERROR, "expect <keybind key=\"\"> element first. "
                        "nodename: '%s' content: '%s'", nodename, content);
+       } else if (!strcasecmp(nodename, "layoutDependent")) {
+               set_bool(content, &current_keybind->use_syms_only);
        } else if (!strcmp(nodename, "name.action")) {
                current_keybind_action = action_create(content);
                if (current_keybind_action) {