diff options
author | Jaroslaw Kubik <jarek@froglogic.com> | 2020-02-12 23:44:42 +0100 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2020-02-24 09:54:09 +0200 |
commit | 0345aba082c83e9950f9dd8b7ea3bf91fe566a02 (patch) | |
tree | df668811fa129e0af1151544525ebc76f7200243 /src | |
parent | 1b23a650abf09a8bbebc566900d0e22a58a826d3 (diff) | |
download | xorg-lib-libxkbcommon-0345aba082c83e9950f9dd8b7ea3bf91fe566a02.tar.gz |
Support translation Unicode codepoints to keysyms
In order to support features like auto-type and UI automation, the
relevant tools need to be able to invert the keycode->keysym->text
transformation. In order to facilitate that, a new API was added.
It allows querying the keysyms that correspond to particular Unicode
codepoints. For all practical purposes, it can be thought of as an
inverse of xkb_keysym_to_utf32().
Diffstat (limited to 'src')
-rw-r--r-- | src/keysym-utf.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/keysym-utf.c b/src/keysym-utf.c index 61e0a06..a49944a 100644 --- a/src/keysym-utf.c +++ b/src/keysym-utf.c @@ -897,6 +897,35 @@ xkb_keysym_to_utf32(xkb_keysym_t keysym) return bin_search(keysymtab, ARRAY_SIZE(keysymtab) - 1, keysym); } +XKB_EXPORT xkb_keysym_t +xkb_utf32_to_keysym(uint32_t ucs) +{ + /* first check for Latin-1 characters (1:1 mapping) */ + if ((ucs >= 0x0020 && ucs <= 0x007e) || + (ucs >= 0x00a0 && ucs <= 0x00ff)) + return ucs; + + /* special keysyms */ + if ((ucs >= (XKB_KEY_BackSpace & 0x7f) && ucs <= (XKB_KEY_Clear & 0x7f)) || + ucs == (XKB_KEY_Return & 0x7f) || ucs == (XKB_KEY_Escape & 0x7f)) + return ucs | 0xff00; + if (ucs == (XKB_KEY_Delete & 0x7f)) + return XKB_KEY_Delete; + + /* Unicode non-symbols and code points outside Unicode planes */ + if ((ucs >= 0xfdd0 && ucs <= 0xfdef) || + ucs > 0x10ffff || (ucs & 0xfffe) == 0xfffe) + return XKB_KEY_NoSymbol; + + /* search main table */ + for (size_t i = 0; i < ARRAY_SIZE(keysymtab); i++) + if (keysymtab[i].ucs == ucs) + return keysymtab[i].keysym; + + /* Use direct encoding if everything else fails */ + return ucs | 0x01000000; +} + /* * Copyright © 2012 Intel Corporation * |