X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=openbox%2Ftranslate.c;h=a7cac55721328e0da76eeb14bfc272ccde86172e;hb=d389e67d22259e6a1d822b99ab0dbd27389bdade;hp=a26017e512065fe2b5926dcea603760e578a40b6;hpb=2442cdfd85e5229c7ee4ac49ca66a7d55ffcb919;p=chaz%2Fopenbox diff --git a/openbox/translate.c b/openbox/translate.c index a26017e5..a7cac557 100644 --- a/openbox/translate.c +++ b/openbox/translate.c @@ -139,3 +139,29 @@ translation_fail: g_strfreev(parsed); return ret; } + +const gchar *translate_keycode(guint keycode) +{ + KeySym sym; + const gchar *ret = NULL; + + if ((sym = XKeycodeToKeysym(ob_display, keycode, 0)) != NoSymbol) + ret = XKeysymToString(sym); + return g_locale_to_utf8(ret, -1, NULL, NULL, NULL); +} + +gunichar translate_unichar(guint keycode) +{ + gunichar unikey = 0; + + const char *key; + if ((key = translate_keycode(keycode)) != NULL && + /* don't accept keys that aren't a single letter, like "space" */ + key[1] == '\0') + { + unikey = g_utf8_get_char_validated(key, -1); + if (unikey == (gunichar)-1 || unikey == (gunichar)-2 || unikey == 0) + unikey = 0; + } + return unikey; +}