From 460ef9c7a4bd2527f7f17eb8c95eeff3b67455f8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 12 Jan 2015 16:41:00 +0100 Subject: wayland: implement key modifiers Includes shift, ctrl, alt, meta. --- video/out/wayland_common.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index c4cbaf697a..bf318d7bbc 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -46,10 +46,6 @@ #include "input/event.h" #include "input/keycodes.h" -#define MOD_SHIFT_MASK 0x01 -#define MOD_ALT_MASK 0x02 -#define MOD_CONTROL_MASK 0x04 - static int lookupkey(int key); static void hide_cursor(struct vo_wayland_state * wl); @@ -296,24 +292,34 @@ static void keyboard_handle_key(void *data, uint32_t state) { struct vo_wayland_state *wl = data; - uint32_t code, num_syms; - int mpkey; - const xkb_keysym_t *syms; - xkb_keysym_t sym; + uint32_t code = code = key + 8; + xkb_keysym_t sym = xkb_state_key_get_one_sym(wl->input.xkb.state, code); + + int mpmod = state == WL_KEYBOARD_KEY_STATE_PRESSED ? MP_KEY_STATE_DOWN + : MP_KEY_STATE_UP; - code = key + 8; - num_syms = xkb_state_key_get_syms(wl->input.xkb.state, code, &syms); + static const char *mod_names[] = {XKB_MOD_NAME_SHIFT, XKB_MOD_NAME_CTRL, + XKB_MOD_NAME_ALT, XKB_MOD_NAME_LOGO, 0}; + static int mods[] = {MP_KEY_MODIFIER_SHIFT, MP_KEY_MODIFIER_CTRL, + MP_KEY_MODIFIER_ALT, MP_KEY_MODIFIER_META, 0}; - sym = XKB_KEY_NoSymbol; - if (num_syms == 1) - sym = syms[0]; + for (int n = 0; mods[n]; n++) { + xkb_mod_index_t index = + xkb_keymap_mod_get_index(wl->input.xkb.keymap, mod_names[n]); + if (!xkb_state_mod_index_is_consumed(wl->input.xkb.state, code, index) + && xkb_state_mod_index_is_active(wl->input.xkb.state, index, + XKB_STATE_MODS_DEPRESSED)) + mpmod |= mods[n]; + } - if (sym != XKB_KEY_NoSymbol && (mpkey = lookupkey(sym))) { - if (state == WL_KEYBOARD_KEY_STATE_PRESSED) - mp_input_put_key(wl->vo->input_ctx, mpkey | MP_KEY_STATE_DOWN); - else - mp_input_put_key(wl->vo->input_ctx, mpkey | MP_KEY_STATE_UP); + int mpkey = lookupkey(sym); + if (mpkey) { + mp_input_put_key(wl->vo->input_ctx, mpkey | mpmod); + } else { + char s[80]; + if (xkb_keysym_to_utf8(sym, s, sizeof(s)) > 0) + mp_input_put_key_utf8(wl->vo->input_ctx, mpmod, bstr0(s)); } } -- cgit v1.2.3