[vlc-commits] xcb/window: inline key events handling
Rémi Denis-Courmont
git at videolan.org
Thu May 24 08:00:20 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed May 23 21:52:20 2018 +0300| [3761fcaf34f94506811e7b5581683d9917ff06cd] | committer: Rémi Denis-Courmont
xcb/window: inline key events handling
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3761fcaf34f94506811e7b5581683d9917ff06cd
---
modules/video_output/Makefile.am | 2 +-
modules/video_output/xcb/events.h | 7 ---
modules/video_output/xcb/vlc_xkb.h | 26 +++++++++
modules/video_output/xcb/window.c | 49 +++++++++++++++--
modules/video_output/xcb/{keys.c => xkb.c} | 85 ++++--------------------------
5 files changed, 81 insertions(+), 88 deletions(-)
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index c44c1331c8..4a33e11fca 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -168,7 +168,7 @@ vout_LTLIBRARIES += libxcb_x11_plugin.la libxcb_window_plugin.la
if HAVE_XCB_KEYSYMS
libxcb_window_plugin_la_SOURCES += \
video_output/xcb/keysym.h video_output/xcb/xcb_keysym.h \
- video_output/xcb/keys.c
+ video_output/xcb/vlc_xkb.h video_output/xcb/xkb.c
libxcb_window_plugin_la_CFLAGS += -DHAVE_XCB_KEYSYMS
endif
if HAVE_XCB_XVIDEO
diff --git a/modules/video_output/xcb/events.h b/modules/video_output/xcb/events.h
index 868da8bbf4..91f4595061 100644
--- a/modules/video_output/xcb/events.h
+++ b/modules/video_output/xcb/events.h
@@ -26,13 +26,6 @@
#include <vlc_vout_display.h>
-#ifdef HAVE_XCB_KEYSYMS
-# include <xcb/xcb_keysyms.h>
-/* keys.c */
-int XCB_keyHandler_Process(xcb_key_symbols_t *, xcb_generic_event_t *,
- vout_window_t *);
-#endif
-
/* events.c */
/**
diff --git a/modules/video_output/xcb/vlc_xkb.h b/modules/video_output/xcb/vlc_xkb.h
new file mode 100644
index 0000000000..1572f0d240
--- /dev/null
+++ b/modules/video_output/xcb/vlc_xkb.h
@@ -0,0 +1,26 @@
+/**
+ * @file vlc_xkb.h
+ * @brief XKeyboard symbol mappings for VLC
+ */
+/*****************************************************************************
+ * Copyright © 2009 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
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <stdint.h>
+
+uint_fast32_t vlc_xkb_convert_keysym(uint_fast32_t sym);
+
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index 4648a24741..1e4eae8a06 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -31,6 +31,10 @@
#include <limits.h> /* _POSIX_HOST_NAME_MAX */
#include <xcb/xcb.h>
+#ifdef HAVE_XCB_KEYSYMS
+# include <xcb/xcb_keysyms.h>
+# include "vlc_xkb.h"
+#endif
typedef xcb_atom_t Atom;
#include <X11/Xatom.h> /* XA_WM_NAME */
@@ -72,13 +76,42 @@ static int ProcessEvent(vout_window_t *wnd, xcb_generic_event_t *ev)
vout_window_sys_t *sys = wnd->sys;
int ret = 0;
+ switch (ev->response_type & 0x7f)
+ {
+ case XCB_KEY_PRESS:
+ {
#ifdef HAVE_XCB_KEYSYMS
- if (sys->keys != NULL && XCB_keyHandler_Process(sys->keys, ev, wnd) == 0)
- return 0;
+ xcb_key_press_event_t *e = (xcb_key_press_event_t *)ev;
+ xcb_keysym_t sym = xcb_key_press_lookup_keysym(sys->keys, e, 0);
+ uint_fast32_t vk = vlc_xkb_convert_keysym(sym);
+
+ msg_Dbg(wnd, "key: 0x%08"PRIxFAST32" (X11: 0x%04"PRIx32")",
+ vk, sym);
+ if (vk == KEY_UNSET)
+ break;
+ if (e->state & XCB_MOD_MASK_SHIFT) /* Shift */
+ vk |= KEY_MODIFIER_SHIFT;
+ /* XCB_MOD_MASK_LOCK */ /* Caps Lock */
+ if (e->state & XCB_MOD_MASK_CONTROL) /* Control */
+ vk |= KEY_MODIFIER_CTRL;
+ if (e->state & XCB_MOD_MASK_1) /* Alternate */
+ vk |= KEY_MODIFIER_ALT;
+ /* XCB_MOD_MASK_2 */ /* Numeric Pad Lock */
+ if (e->state & XCB_MOD_MASK_3) /* Super */
+ vk |= KEY_MODIFIER_META;
+ if (e->state & XCB_MOD_MASK_4) /* Meta */
+ vk |= KEY_MODIFIER_META;
+ if (e->state & XCB_MOD_MASK_5) /* Alternate Graphic */
+ vk |= KEY_MODIFIER_ALT;
+
+ vout_window_ReportKeyPress(wnd, vk);
#endif
+ break;
+ }
+
+ case XCB_KEY_RELEASE:
+ break;
- switch (ev->response_type & 0x7f)
- {
/* Note a direct mapping of buttons from XCB to VLC is assumed. */
case XCB_BUTTON_PRESS:
{
@@ -118,7 +151,15 @@ static int ProcessEvent(vout_window_t *wnd, xcb_generic_event_t *ev)
break;
case XCB_MAPPING_NOTIFY:
+ {
+#ifdef HAVE_XCB_KEYSYMS
+ xcb_mapping_notify_event_t *e = (xcb_mapping_notify_event_t *)ev;
+
+ msg_Dbg(wnd, "refreshing keyboard mapping");
+ xcb_refresh_keyboard_mapping(sys->keys, e);
+#endif
break;
+ }
default:
msg_Dbg (wnd, "unhandled event %"PRIu8, ev->response_type);
diff --git a/modules/video_output/xcb/keys.c b/modules/video_output/xcb/xkb.c
similarity index 51%
rename from modules/video_output/xcb/keys.c
rename to modules/video_output/xcb/xkb.c
index 5b71e65c36..bbc8920283 100644
--- a/modules/video_output/xcb/keys.c
+++ b/modules/video_output/xcb/xkb.c
@@ -1,6 +1,6 @@
/**
- * @file keys.c
- * @brief X C Bindings VLC keyboard event handling
+ * @file xkb.c
+ * @brief XKeyboard symbols mapping for VLC
*/
/*****************************************************************************
* Copyright © 2009 Rémi Denis-Courmont
@@ -25,31 +25,26 @@
#endif
#include <stdlib.h>
-#include <inttypes.h>
-#include <assert.h>
-
-#include <xcb/xcb.h>
-#include <vlc_common.h>
-#include "events.h"
-
-#include <xcb/xcb_keysyms.h>
+#include <stdint.h>
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
+#include <vlc_common.h>
#include <vlc_actions.h>
+#include "video_output/xcb/vlc_xkb.h"
static int keysymcmp (const void *pa, const void *pb)
{
- int a = *(const xcb_keysym_t *)pa;
- int b = *(const xcb_keysym_t *)pb;
+ int a = *(const uint32_t *)pa;
+ int b = *(const uint32_t *)pb;
return a - b;
}
-static uint_fast32_t ConvertKeySym (xcb_keysym_t sym)
+uint_fast32_t vlc_xkb_convert_keysym(uint_fast32_t sym)
{
static const struct
{
- xcb_keysym_t x11;
+ uint32_t x11;
uint32_t vlc;
} *res, tab[] = {
#include "xcb_keysym.h"
@@ -94,65 +89,3 @@ static uint_fast32_t ConvertKeySym (xcb_keysym_t sym)
return KEY_UNSET;
}
-
-
-/**
- * Process an X11 event, convert into VLC hotkey event if applicable.
- *
- * @param syms XCB key symbols (created by xcb_key_symbols_alloc())
- * @param ev XCB event to process
- * @return 0 if the event was handled and free()'d, non-zero otherwise
- */
-int XCB_keyHandler_Process(xcb_key_symbols_t *syms, xcb_generic_event_t *ev,
- vout_window_t *window)
-{
- assert(syms != NULL);
-
- switch (ev->response_type & 0x7f)
- {
- case XCB_KEY_PRESS:
- {
- xcb_key_press_event_t *e = (xcb_key_press_event_t *)ev;
- xcb_keysym_t sym = xcb_key_press_lookup_keysym(syms, e, 0);
- uint_fast32_t vk = ConvertKeySym (sym);
-
- msg_Dbg(window, "key: 0x%08"PRIxFAST32" (X11: 0x%04"PRIx32")",
- vk, sym);
- if (vk == KEY_UNSET)
- break;
- if (e->state & XCB_MOD_MASK_SHIFT) /* Shift */
- vk |= KEY_MODIFIER_SHIFT;
- /* XCB_MOD_MASK_LOCK */ /* Caps Lock */
- if (e->state & XCB_MOD_MASK_CONTROL) /* Control */
- vk |= KEY_MODIFIER_CTRL;
- if (e->state & XCB_MOD_MASK_1) /* Alternate */
- vk |= KEY_MODIFIER_ALT;
- /* XCB_MOD_MASK_2 */ /* Numeric Pad Lock */
- if (e->state & XCB_MOD_MASK_3) /* Super */
- vk |= KEY_MODIFIER_META;
- if (e->state & XCB_MOD_MASK_4) /* Meta */
- vk |= KEY_MODIFIER_META;
- if (e->state & XCB_MOD_MASK_5) /* Alternate Graphic */
- vk |= KEY_MODIFIER_ALT;
- vout_window_ReportKeyPress(window, vk);
- break;
- }
-
- case XCB_KEY_RELEASE:
- break;
-
- case XCB_MAPPING_NOTIFY:
- {
- xcb_mapping_notify_event_t *e = (xcb_mapping_notify_event_t *)ev;
- msg_Dbg(window, "refreshing keyboard mapping");
- xcb_refresh_keyboard_mapping(syms, e);
- break;
- }
-
- default:
- return -1;
- }
-
- free (ev);
- return 0;
-}
More information about the vlc-commits
mailing list