diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2018-02-22 08:05:13 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2018-02-22 10:35:32 +0100 |
commit | abb4f2c9655503f14dc55064f29c4f59b07e96ff (patch) | |
tree | 2de1661b57cc82aeb53d21aeac9e1c1a54dafd87 /ui/keymaps.c | |
parent | 23ad24e48cf28ac2542ade657efbf7f802d7c8a0 (diff) |
keymap: consider modifier state when picking a mapping
Pass the modifier state to the keymap lookup function. In case multiple
keysym -> keycode mappings exist look at the modifier state and prefer
the mapping where the modifier state matches.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20180222070513.8740-6-kraxel@redhat.com
Diffstat (limited to 'ui/keymaps.c')
-rw-r--r-- | ui/keymaps.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/ui/keymaps.c b/ui/keymaps.c index 1eba6d7057..43fe604724 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -176,8 +176,12 @@ kbd_layout_t *init_keyboard_layout(const name2keysym_t *table, } -int keysym2scancode(kbd_layout_t *k, int keysym) +int keysym2scancode(kbd_layout_t *k, int keysym, + bool shift, bool altgr, bool ctrl) { + static const uint32_t mask = + SCANCODE_SHIFT | SCANCODE_ALTGR | SCANCODE_CTRL; + uint32_t mods, i; struct keysym2code *keysym2code; #ifdef XK_ISO_Left_Tab @@ -193,6 +197,33 @@ int keysym2scancode(kbd_layout_t *k, int keysym) return 0; } + if (keysym2code->count == 1) { + return keysym2code->keycodes[0]; + } + + /* + * We have multiple keysym -> keycode mappings. + * + * Check whenever we find one mapping where the modifier state of + * the mapping matches the current user interface modifier state. + * If so, prefer that one. + */ + mods = 0; + if (shift) { + mods |= SCANCODE_SHIFT; + } + if (altgr) { + mods |= SCANCODE_ALTGR; + } + if (ctrl) { + mods |= SCANCODE_CTRL; + } + + for (i = 0; i < keysym2code->count; i++) { + if ((keysym2code->keycodes[i] & mask) == mods) { + return keysym2code->keycodes[i]; + } + } return keysym2code->keycodes[0]; } |