From dfd588d5a84c1524e9992ec9c51928f470c2ef2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Wed, 23 May 2018 22:19:46 +0300 Subject: [PATCH] xcb: add support for XKB to VLC key conversion --- modules/video_output/xcb/vlc_xkb.h | 3 +++ modules/video_output/xcb/xkb.c | 34 +++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/video_output/xcb/vlc_xkb.h b/modules/video_output/xcb/vlc_xkb.h index 1572f0d240..b7c7287d65 100644 --- a/modules/video_output/xcb/vlc_xkb.h +++ b/modules/video_output/xcb/vlc_xkb.h @@ -22,5 +22,8 @@ #include +struct xkb_state; + uint_fast32_t vlc_xkb_convert_keysym(uint_fast32_t sym); +uint_fast32_t vlc_xkb_get_one(struct xkb_state *state, uint_fast32_t keycode); diff --git a/modules/video_output/xcb/xkb.c b/modules/video_output/xcb/xkb.c index bbc8920283..0e4f5021cc 100644 --- a/modules/video_output/xcb/xkb.c +++ b/modules/video_output/xcb/xkb.c @@ -3,7 +3,7 @@ * @brief XKeyboard symbols mapping for VLC */ /***************************************************************************** - * Copyright © 2009 Rémi Denis-Courmont + * Copyright © 2009-2018 Rémi Denis-Courmont * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by @@ -89,3 +89,35 @@ uint_fast32_t vlc_xkb_convert_keysym(uint_fast32_t sym) return KEY_UNSET; } + +#ifdef HAVE_XKBCOMMON +# include + +struct modifiers +{ + char name[8]; + uint32_t mask; +}; + +static const struct modifiers modifiers[] = +{ + { XKB_MOD_NAME_SHIFT, KEY_MODIFIER_SHIFT }, + { XKB_MOD_NAME_CTRL, KEY_MODIFIER_CTRL }, + { XKB_MOD_NAME_ALT, KEY_MODIFIER_ALT }, + { XKB_MOD_NAME_LOGO, KEY_MODIFIER_META }, +}; + +uint_fast32_t vlc_xkb_get_one(struct xkb_state *state, uint_fast32_t keycode) +{ + xkb_keysym_t keysym = xkb_state_key_get_one_sym(state, keycode + 8); + uint_fast32_t vk = vlc_xkb_convert_keysym(keysym); + + if (vk != KEY_UNSET) + for (size_t i = 0; i < ARRAY_SIZE(modifiers); i++) + if (xkb_state_mod_name_is_active(state, modifiers[i].name, + XKB_STATE_MODS_EFFECTIVE) > 0) + vk |= modifiers[i].mask; + + return vk; +} +#endif /* HAVE_XKBCOMMON */ -- GitLab