From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:25:01 +0000 (+0200) Subject: keybinds: allow non-english based keybinds X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=272222e3c92b61c826cf38d283c2acc93d47e3f4;p=proto%2Flabwc.git keybinds: allow non-english based keybinds --- diff --git a/src/config/keybind.c b/src/config/keybind.c index 5700c54c..9a0ac197 100644 --- a/src/config/keybind.c +++ b/src/config/keybind.c @@ -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);