diff options
author | Mike Blumenkrantz <zmike@osg.samsung.com> | 2016-01-20 11:40:43 -0500 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2016-01-20 23:17:10 +0200 |
commit | 0ce17ef3ea3722c1cfe7af38a55616afb3ba1b27 (patch) | |
tree | dba8782ae13548f9e1ccf915bf69939825fdaa15 /src/keymap.c | |
parent | 7f3bb16729c5c1e3864ff249eb7ca40bdc6a2963 (diff) | |
download | xorg-lib-libxkbcommon-0ce17ef3ea3722c1cfe7af38a55616afb3ba1b27.tar.gz |
keymap: add xkb_keymap_key_by_name(), xkb_keymap_key_get_name(), tests
xkb_keymap_key_by_name() allows finding a keycode from a given keyname and
is useful for generating keyboard events to use in regression tests
during CI
xkb_keymap_key_get_name() is the inverse of xkb_keymap_key_by_name()
Signed-off-by: Mike Blumenkrantz <zmike@osg.samsung.com>
[ran: some stylistic tweaks + another test case]
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/keymap.c')
-rw-r--r-- | src/keymap.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/keymap.c b/src/keymap.c index a9fc9b4..859c64a 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -470,6 +470,40 @@ xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter, iter(keymap, key->keycode, data); } +XKB_EXPORT const char * +xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t kc) +{ + const struct xkb_key *key = XkbKey(keymap, kc); + + if (!key) + return NULL; + + return xkb_atom_text(keymap->ctx, key->name); +} + +XKB_EXPORT xkb_keycode_t +xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name) +{ + struct xkb_key *key; + xkb_atom_t atom; + + atom = xkb_atom_lookup(keymap->ctx, name); + if (atom) { + xkb_atom_t ratom = XkbResolveKeyAlias(keymap, atom); + if (ratom) + atom = ratom; + } + if (!atom) + return XKB_KEYCODE_INVALID; + + xkb_keys_foreach(key, keymap) { + if (key->name == atom) + return key->keycode; + } + + return XKB_KEYCODE_INVALID; +} + /** * Simple boolean specifying whether or not the key should repeat. */ |