]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keybind: allow keybinding "-"
authorChloƩ Vulquin <code@toast.bunkerlabs.net>
Mon, 13 May 2024 20:56:25 +0000 (22:56 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 14 May 2024 14:30:49 +0000 (16:30 +0200)
Updates #1811

src/config/keybind.c

index 1de02513b71c434d4ce3f7f7e749cc0bde077806..3370c09ddc441b9dd89a35f9fd6f893b34c6324d 100644 (file)
@@ -124,6 +124,25 @@ keybind_create(const char *keybind)
        gchar **symnames = g_strsplit(keybind, "-", -1);
        for (size_t i = 0; symnames[i]; i++) {
                char *symname = symnames[i];
+               /*
+                * Since "-" is used as a separator, a keybind string like "W--"
+                * becomes "W", "", "". This means that it is impossible to bind
+                * an action to the "-" key in this way.
+                * We detect empty ""s outputted by g_strsplit and treat them as
+                * literal "-"s.
+                */
+               if (!symname[0]) {
+                       /*
+                        * You might have noticed that in the "W--" example, the
+                        * output is "W", "", ""; which turns into "W", "-",
+                        * "-". In order to avoid such duplications, we perform
+                        * a lookahead on the tokens to treat that edge-case.
+                        */
+                       if (symnames[i+1] && !symnames[i+1][0]) {
+                               continue;
+                       }
+                       symname = "-";
+               }
                uint32_t modifier = parse_modifier(symname);
                if (modifier != 0) {
                        k->modifiers |= modifier;