From 671697a211870e86b9f3d37480ab2d7c6073e620 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 8 Dec 2012 13:35:07 +0100 Subject: [PATCH] Move X11 keyboard event to x11_common. TODO: Add to xegl and xvideo. --- gfx/context/glx_ctx.c | 17 +---------------- gfx/context/x11_common.c | 21 +++++++++++++++++++++ gfx/context/x11_common.h | 2 ++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/gfx/context/glx_ctx.c b/gfx/context/glx_ctx.c index d358629013..ff328f957b 100644 --- a/gfx/context/glx_ctx.c +++ b/gfx/context/glx_ctx.c @@ -20,7 +20,6 @@ #include "../gfx_context.h" #include "../gl_common.h" #include "../gfx_common.h" -#include "../../input/input_common.h" #include "x11_common.h" #include @@ -219,21 +218,7 @@ static void gfx_ctx_check_window(bool *quit, case KeyPress: case KeyRelease: - if (g_extern.system.key_event) - { - static XComposeStatus state; - char keybuf[32]; - - bool down = event.type == KeyPress; - uint32_t character = 0; - unsigned key = input_translate_keysym_to_rk(XLookupKeysym(&event.xkey, 0)); - - // FIXME: UTF-8. - if (down && XLookupString(&event.xkey, keybuf, sizeof(keybuf), 0, &state)) - character = keybuf[0]; - - g_extern.system.key_event(down, key, character, 0); - } + x11_handle_key_event(&event); break; } } diff --git a/gfx/context/x11_common.c b/gfx/context/x11_common.c index 4720d356ce..8ebb9cb384 100644 --- a/gfx/context/x11_common.c +++ b/gfx/context/x11_common.c @@ -20,6 +20,7 @@ #include #include "../image.h" #include "../../general.h" +#include "../../input/input_common.h" void x11_hide_mouse(Display *dpy, Window win) { @@ -285,3 +286,23 @@ unsigned x11_get_xinerama_monitor(Display *dpy, int x, int y, } #endif +void x11_handle_key_event(XEvent *event) +{ + if (!g_extern.system.key_event) + return; + + static XComposeStatus state; + char keybuf[32]; + + bool down = event->type == KeyPress; + uint32_t character = 0; + unsigned key = input_translate_keysym_to_rk(XLookupKeysym(&event->xkey, 0)); + + // FIXME: UTF-8. + if (down && XLookupString(&event->xkey, keybuf, sizeof(keybuf), 0, &state)) + character = keybuf[0]; + + // FIXME: Mod handling. + g_extern.system.key_event(down, key, character, 0); +} + diff --git a/gfx/context/x11_common.h b/gfx/context/x11_common.h index d21c48313a..f1530b7289 100644 --- a/gfx/context/x11_common.h +++ b/gfx/context/x11_common.h @@ -49,5 +49,7 @@ unsigned x11_get_xinerama_monitor(Display *dpy, int x, int y, int w, int h); #endif +void x11_handle_key_event(XEvent *event); + #endif