]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keybinds: allow non-english based keybinds
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 5 Sep 2023 16:25:01 +0000 (18:25 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 7 Sep 2023 22:24:36 +0000 (23:24 +0100)
src/config/keybind.c

index 5700c54cfa378c70be256d76b0afe47b5ba3a0ff..9a0ac197061f0d3fa33ab9c1076408e76ebaded9 100644 (file)
@@ -45,6 +45,7 @@ keybind_the_same(struct keybind *a, struct keybind *b)
 struct keybind *
 keybind_create(const char *keybind)
 {
+       xkb_keysym_t sym;
        struct keybind *k = znew(*k);
        xkb_keysym_t keysyms[MAX_KEYSYMS];
        gchar **symnames = g_strsplit(keybind, "-", -1);
@@ -54,9 +55,21 @@ keybind_create(const char *keybind)
                if (modifier != 0) {
                        k->modifiers |= modifier;
                } else {
-                       xkb_keysym_t sym = xkb_keysym_to_lower(
-                               xkb_keysym_from_name(symname,
-                                       XKB_KEYSYM_CASE_INSENSITIVE));
+                       sym = xkb_keysym_from_name(symname, XKB_KEYSYM_CASE_INSENSITIVE);
+                       if (sym == XKB_KEY_NoSymbol && g_utf8_strlen(symname, -1) == 1) {
+                               /*
+                                * xkb_keysym_from_name() only handles a legacy set of single
+                                * characters. Thus we try to get the unicode codepoint here
+                                * and try a direct translation instead.
+                                *
+                                * This allows using keybinds like 'W-รถ' and similar.
+                                */
+                               gunichar codepoint = g_utf8_get_char_validated(symname, -1);
+                               if (codepoint != (gunichar)-1) {
+                                       sym = xkb_utf32_to_keysym(codepoint);
+                               }
+                       }
+                       sym = xkb_keysym_to_lower(sym);
                        if (sym == XKB_KEY_NoSymbol) {
                                wlr_log(WLR_ERROR, "unknown keybind (%s)", symname);
                                free(k);