[vlc-commits] xcb/window: simplify xcb-keysyms usage

Rémi Denis-Courmont git at videolan.org
Sun May 20 19:50:55 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 17 23:22:26 2018 +0300| [0b51cd66c788b8622ca98bb341a3efde1c50e336] | committer: Rémi Denis-Courmont

xcb/window: simplify xcb-keysyms usage

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0b51cd66c788b8622ca98bb341a3efde1c50e336
---

 modules/video_output/Makefile.am  |  8 ++---
 modules/video_output/xcb/events.h |  8 ++---
 modules/video_output/xcb/keys.c   | 64 +++------------------------------------
 modules/video_output/xcb/window.c | 26 ++++++++++++----
 4 files changed, 33 insertions(+), 73 deletions(-)

diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index dcc3cdc694..7281340b3f 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -147,10 +147,7 @@ libxcb_xv_plugin_la_CFLAGS = $(AM_CFLAGS) \
 libxcb_xv_plugin_la_LIBADD = libvlc_xcb_events.la \
 	$(XCB_LIBS) $(XCB_SHM_LIBS) $(XCB_XV_LIBS)
 
-libxcb_window_plugin_la_SOURCES =  \
-	video_output/xcb/keys.c \
-	video_output/xcb/keysym.h video_output/xcb/xcb_keysym.h \
-	video_output/xcb/window.c
+libxcb_window_plugin_la_SOURCES = video_output/xcb/window.c
 libxcb_window_plugin_la_CFLAGS = $(AM_CFLAGS) \
 	$(CFLAGS_xcb_window) \
 	$(XPROTO_CFLAGS) $(XCB_CFLAGS) $(XCB_KEYSYMS_CFLAGS)
@@ -169,6 +166,9 @@ if HAVE_XCB
 pkglib_LTLIBRARIES += libvlc_xcb_events.la
 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
 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 33b9d8e97e..868da8bbf4 100644
--- a/modules/video_output/xcb/events.h
+++ b/modules/video_output/xcb/events.h
@@ -26,12 +26,12 @@
 
 #include <vlc_vout_display.h>
 
+#ifdef HAVE_XCB_KEYSYMS
+# include <xcb/xcb_keysyms.h>
 /* keys.c */
-typedef struct key_handler_t key_handler_t;
-key_handler_t *XCB_keyHandler_Create(xcb_connection_t *);
-void XCB_keyHandler_Destroy (key_handler_t *);
-int XCB_keyHandler_Process(key_handler_t *, xcb_generic_event_t *,
+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/keys.c b/modules/video_output/xcb/keys.c
index 2c7e519c79..5b71e65c36 100644
--- a/modules/video_output/xcb/keys.c
+++ b/modules/video_output/xcb/keys.c
@@ -32,42 +32,11 @@
 #include <vlc_common.h>
 #include "events.h"
 
-#ifdef HAVE_XCB_KEYSYMS
 #include <xcb/xcb_keysyms.h>
 #include <X11/keysym.h>
 #include <X11/XF86keysym.h>
 #include <vlc_actions.h>
 
-struct key_handler_t
-{
-    xcb_key_symbols_t *syms;
-};
-
-/**
- * Create an X11 key event handler for a VLC window.
- *
- * The caller shall arrange receiving applicable X11 events, and pass them to
- * ProcessKeyEvent() later.
- *
- * @param conn XCB connection to the X server (to fetch key mappings)
- * @return NULL on error, or a key handling context.
- */
-key_handler_t *XCB_keyHandler_Create(xcb_connection_t *conn)
-{
-    key_handler_t *ctx = malloc (sizeof (*ctx));
-    if (!ctx)
-        return NULL;
-
-    ctx->syms = xcb_key_symbols_alloc (conn);
-    return ctx;
-}
-
-void XCB_keyHandler_Destroy (key_handler_t *ctx)
-{
-    xcb_key_symbols_free (ctx->syms);
-    free (ctx);
-}
-
 static int keysymcmp (const void *pa, const void *pb)
 {
     int a = *(const xcb_keysym_t *)pa;
@@ -130,21 +99,21 @@ static uint_fast32_t ConvertKeySym (xcb_keysym_t sym)
 /**
  * Process an X11 event, convert into VLC hotkey event if applicable.
  *
- * @param ctx key handler created with CreateKeyHandler()
+ * @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(key_handler_t *ctx, xcb_generic_event_t *ev,
+int XCB_keyHandler_Process(xcb_key_symbols_t *syms, xcb_generic_event_t *ev,
                            vout_window_t *window)
 {
-    assert (ctx);
+    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 (ctx->syms, e, 0);
+            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")",
@@ -176,7 +145,7 @@ int XCB_keyHandler_Process(key_handler_t *ctx, xcb_generic_event_t *ev,
         {
             xcb_mapping_notify_event_t *e = (xcb_mapping_notify_event_t *)ev;
             msg_Dbg(window, "refreshing keyboard mapping");
-            xcb_refresh_keyboard_mapping (ctx->syms, e);
+            xcb_refresh_keyboard_mapping(syms, e);
             break;
         }
 
@@ -187,26 +156,3 @@ int XCB_keyHandler_Process(key_handler_t *ctx, xcb_generic_event_t *ev,
     free (ev);
     return 0;
 }
-
-#else /* HAVE_XCB_KEYSYMS */
-
-key_handler_t *XCB_keyHandler_Create(xcb_connection_t *conn)
-{
-    (void) conn;
-    return NULL;
-}
-
-void XCB_keyHandler_Destroy (key_handler_t *ctx)
-{
-    (void) ctx;
-    abort ();
-}
-
-int XCB_keyHandler_Process(key_handler_t *ctx, xcb_generic_event_t *ev,
-                           vout_window_t *window)
-{
-    (void) ctx; (void) ev; (void) window;
-    abort ();
-}
-
-#endif /* HAVE_XCB_KEYSYMS */
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index efb43d26dc..26853f4011 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -43,7 +43,9 @@ typedef xcb_atom_t Atom;
 struct vout_window_sys_t
 {
     xcb_connection_t *conn;
-    key_handler_t *keys;
+#ifdef HAVE_XCB_KEYSYMS
+    xcb_key_symbols_t *keys;
+#endif
     vlc_thread_t thread;
 
     xcb_cursor_t cursor; /* blank cursor */
@@ -61,8 +63,10 @@ static void ProcessEvent (vout_window_t *wnd, xcb_generic_event_t *ev)
 {
     vout_window_sys_t *sys = wnd->sys;
 
+#ifdef HAVE_XCB_KEYSYMS
     if (sys->keys != NULL && XCB_keyHandler_Process(sys->keys, ev, wnd) == 0)
         return;
+#endif
 
     switch (ev->response_type & 0x7f)
     {
@@ -416,10 +420,12 @@ static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
     wnd->sys = p_sys;
 
     p_sys->conn = conn;
+#ifdef HAVE_XCB_KEYSYMS
     if (var_InheritBool (wnd, "keyboard-events"))
-        p_sys->keys = XCB_keyHandler_Create(conn);
+        p_sys->keys = xcb_key_symbols_alloc(conn);
     else
         p_sys->keys = NULL;
+#endif
     p_sys->root = scr->root;
 
     /* ICCCM
@@ -491,8 +497,10 @@ static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
      * request from this thread must be completed at this point. */
     if (vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
     {
+#ifdef HAVE_XCB_KEYSYMS
         if (p_sys->keys != NULL)
-            XCB_keyHandler_Destroy (p_sys->keys);
+            xcb_key_symbols_free(p_sys->keys);
+#endif
         goto error;
     }
 
@@ -520,8 +528,10 @@ static void Close (vout_window_t *wnd)
 
     vlc_cancel (p_sys->thread);
     vlc_join (p_sys->thread, NULL);
+#ifdef HAVE_XCB_KEYSYMS
     if (p_sys->keys != NULL)
-        XCB_keyHandler_Destroy (p_sys->keys);
+        xcb_key_symbols_free(p_sys->keys);
+#endif
 
     xcb_disconnect (conn);
     free (wnd->display.x11);
@@ -653,16 +663,18 @@ static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg)
     vout_window_ReportSize(wnd, geo->width, geo->height);
     free (geo);
 
+#ifdef HAVE_XCB_KEYSYMS
     /* Try to subscribe to keyboard and mouse events (only one X11 client can
      * subscribe to input events, so this can fail). */
     if (var_InheritBool (wnd, "keyboard-events"))
     {
-        p_sys->keys = XCB_keyHandler_Create(conn);
+        p_sys->keys = xcb_key_symbols_alloc(conn);
         if (p_sys->keys != NULL)
             value |= XCB_EVENT_MASK_KEY_PRESS;
     }
     else
         p_sys->keys = NULL;
+#endif
 
     if (var_InheritBool(wnd, "mouse-events"))
         value |= XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE;
@@ -673,8 +685,10 @@ static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg)
     CacheAtoms (p_sys);
     if (vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
     {
+#ifdef HAVE_XCB_KEYSYMS
         if (p_sys->keys != NULL)
-            XCB_keyHandler_Destroy (p_sys->keys);
+            xcb_key_symbols_free(p_sys->keys);
+#endif
         goto error;
     }
 



More information about the vlc-commits mailing list