diff options
author | Jaroslaw Kubik <jarek@froglogic.com> | 2020-02-05 17:42:06 +0100 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2020-03-20 19:20:36 +0200 |
commit | d92a248c48227d09f6fdcfafaf339a5ff586e042 (patch) | |
tree | ebe2a8a30a6db5d6c4ebf10f786983515521eef3 /test | |
parent | 0345aba082c83e9950f9dd8b7ea3bf91fe566a02 (diff) | |
download | xorg-lib-libxkbcommon-d92a248c48227d09f6fdcfafaf339a5ff586e042.tar.gz |
API to query modifier set required to type a keysym
The new API is useful to implement features like auto-type and
desktop automation. Since the inputs for these features is usually
specified in terms of the symbols that need to be typed, the
implementation needs to be able to invert the keycode->keysym
transformation and produce a sequence of keycodes that can be used
to type the requested character(s).
Diffstat (limited to 'test')
-rw-r--r-- | test/keymap.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/keymap.c b/test/keymap.c index 75b92c1..75e59f3 100644 --- a/test/keymap.c +++ b/test/keymap.c @@ -38,6 +38,11 @@ main(void) struct xkb_keymap *keymap; xkb_keycode_t kc; const char *keyname; + xkb_mod_mask_t masks_out[4] = { 0, 0, 0, 0 }; + size_t mask_count; + xkb_mod_mask_t shift_mask; + xkb_mod_mask_t lock_mask; + xkb_mod_mask_t mod2_mask; assert(context); @@ -59,6 +64,43 @@ main(void) keyname = xkb_keymap_key_get_name(keymap, kc); assert(streq(keyname, "COMP")); + kc = xkb_keymap_key_by_name(keymap, "AC01"); + assert(kc != XKB_KEYCODE_INVALID); + + // AC01 level 0 ('a') requires no modifiers on us-pc104 + mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4); + assert(mask_count == 0); + + shift_mask = 1 << xkb_keymap_mod_get_index(keymap, "Shift"); + lock_mask = 1 << xkb_keymap_mod_get_index(keymap, "Lock"); + mod2_mask = 1 << xkb_keymap_mod_get_index(keymap, "Mod2"); + + // AC01 level 1 ('A') requires either Shift or Lock modifiers on us-pc104 + mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 1, masks_out, 4); + assert(mask_count == 2); + assert(masks_out[0] == shift_mask); + assert(masks_out[1] == lock_mask); + + kc = xkb_keymap_key_by_name(keymap, "KP1"); + + // KP1 level 0 ('End') requires no modifiers or Shift+Mod2 on us-pc104 + mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4); + assert(mask_count == 2); + assert(masks_out[0] == 0); + assert(masks_out[1] == (shift_mask | mod2_mask)); + + // KP1 level 1 ('1') requires either Shift or Mod2 modifiers on us-pc104 + mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 1, masks_out, 4); + assert(mask_count == 2); + assert(masks_out[0] == shift_mask); + assert(masks_out[1] == mod2_mask); + + // Return key is not affected by modifiers on us-pc104 + kc = xkb_keymap_key_by_name(keymap, "RTRN"); + mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4); + assert(mask_count == 1); + assert(masks_out[0] == 0); + xkb_keymap_unref(keymap); xkb_context_unref(context); } |