Commit 0b51cd66 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

xcb/window: simplify xcb-keysyms usage

parent f7fbf59b
......@@ -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
......
......@@ -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 */
......
......@@ -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 */
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment