summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-11-05 21:34:59 +0200
committerRan Benita <ran234@gmail.com>2012-11-05 21:34:59 +0200
commit7891c9170bda67bc710ba9cad1b48263d14d7ec2 (patch)
tree4bb87c525ce3b104330ba159c9759f6cc1431948
parentfb201645b2bae1f4a1f7a6dfa37e14a0de04556e (diff)
keysym-utf: also translate special keysyms like Tab and Return
The keysym2ucs.c file apparently leaves out some keysyms, which libX11 deals with separately (like in _XkbHandleSpecialSym()). The problematic keysyms are the keypad ones (for which we already added some support) and keysyms which use 0xff** instead of 0x00** < 0x20. This code should fix them properly, as much as I could gather from libX11 and http://www.cl.cam.ac.uk/~mgk25/ucs/keysym2ucs.c and other sources (which are not aware of locale). https://bugs.freedesktop.org/show_bug.cgi?id=56780 Reported-by: Gatis Paeglis <gatis.paeglis@digia.com> Signed-off-by: Ran Benita <ran234@gmail.com>
-rw-r--r--src/keysym-utf.c37
-rw-r--r--test/keysym.c17
2 files changed, 27 insertions, 27 deletions
diff --git a/src/keysym-utf.c b/src/keysym-utf.c
index 67dbb22..ae01f09 100644
--- a/src/keysym-utf.c
+++ b/src/keysym-utf.c
@@ -836,16 +836,2 @@ const struct codepair keysymtab[] = {
-const struct codepair keysymtab_kp[] = {
- { 0xff80, 0x0020 }, /* KP_Space SPACE */
- { 0xffaa, 0x002a }, /* KP_Multiply * ASTERISK */
- { 0xffab, 0x002b }, /* KP_Plus + PLUS SIGN */
- /* XXX: It's debatable what KP_Separator and KP_Decimal should represent,
- * as well as locale-specific. So just enforce English colonial
- * hegemony on the world for the time being. */
- { 0xffac, 0x002e }, /* KP_Separator . FULL STOP */
- { 0xffad, 0x002d }, /* KP_Subtract - HYPHEN-MINUS */
- { 0xffae, 0x002e }, /* KP_Decimal . FULL STOP */
- { 0xffaf, 0x002f }, /* KP_Divide / SOLIDUS */
- { 0xffbd, 0x003d }, /* KP_Equal = EQUAL SIGN */
-};
-
/* binary search with range check */
@@ -879,4 +865,2 @@ xkb_keysym_to_utf32(xkb_keysym_t keysym)
{
- uint32_t retval = 0;
-
/* first check for Latin-1 characters (1:1 mapping) */
@@ -886,4 +870,13 @@ xkb_keysym_to_utf32(xkb_keysym_t keysym)
- if (keysym >= 0xffb0 && keysym <= 0xffb9)
- return keysym - (0xffb0 - 0x0030);
+ /* patch encoding botch */
+ if (keysym == XKB_KEY_KP_Space)
+ return XKB_KEY_space & 0x7f;
+
+ /* special keysyms */
+ if ((keysym >= XKB_KEY_BackSpace && keysym <= XKB_KEY_Clear) ||
+ (keysym >= XKB_KEY_KP_Multiply && keysym <= XKB_KEY_KP_9) ||
+ keysym == XKB_KEY_Return || keysym == XKB_KEY_Escape ||
+ keysym == XKB_KEY_Delete || keysym == XKB_KEY_KP_Tab ||
+ keysym == XKB_KEY_KP_Enter || keysym == XKB_KEY_KP_Equal)
+ return keysym & 0x7f;
@@ -893,10 +886,4 @@ xkb_keysym_to_utf32(xkb_keysym_t keysym)
- /* search smaller keypad table */
- retval = bin_search(keysymtab_kp, ARRAY_SIZE(keysymtab_kp) - 1, keysym);
-
/* search main table */
- if (!retval)
- retval = bin_search(keysymtab, ARRAY_SIZE(keysymtab) - 1, keysym);
-
- return retval;
+ return bin_search(keysymtab, ARRAY_SIZE(keysymtab) - 1, keysym);
}
diff --git a/test/keysym.c b/test/keysym.c
index 595f829..fe6138d 100644
--- a/test/keysym.c
+++ b/test/keysym.c
@@ -75,4 +75,6 @@ test_utf8(xkb_keysym_t keysym, const char *expected)
- fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
- fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
+ fprintf(stderr, "Expected keysym %#x -> %s (%u bytes)\n", keysym, expected,
+ (unsigned) strlen(expected));
+ fprintf(stderr, "Received keysym %#x -> %s (%u bytes)\n\n", keysym, s,
+ (unsigned) strlen(s));
@@ -135,2 +137,13 @@ main(void)
assert(test_utf8(XKB_KEY_KP_Space, " "));
+ assert(test_utf8(XKB_KEY_BackSpace, "\b"));
+ assert(test_utf8(XKB_KEY_Escape, "\e"));
+ assert(test_utf8(XKB_KEY_KP_Separator, ","));
+ assert(test_utf8(XKB_KEY_KP_Decimal, "."));
+ assert(test_utf8(XKB_KEY_Tab, "\t"));
+ assert(test_utf8(XKB_KEY_KP_Tab, "\t"));
+ assert(test_utf8(XKB_KEY_hyphen, "­"));
+ assert(test_utf8(XKB_KEY_Linefeed, "\n"));
+ assert(test_utf8(XKB_KEY_Return, "\r"));
+ assert(test_utf8(XKB_KEY_KP_Enter, "\r"));
+ assert(test_utf8(XKB_KEY_KP_Equal, "="));
assert(test_utf8(XKB_KEY_9, "9"));