From 89df27462960a9edac9a4eb9919a20038c6f2c8d Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 2 Feb 2013 23:32:19 +0200 Subject: [PATCH] support .unicode of returned events --- src/video/omapdss/linux/xenv.c | 11 +++++++++++ src/video/omapdss/linux/xenv.h | 1 + src/video/omapdss/sdlif.c | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/video/omapdss/linux/xenv.c b/src/video/omapdss/linux/xenv.c index 40bf92c..80c54d8 100644 --- a/src/video/omapdss/linux/xenv.c +++ b/src/video/omapdss/linux/xenv.c @@ -58,6 +58,7 @@ struct xstuff { FPTR(XPending); FPTR(XLookupKeysym); FPTR(XkbSetDetectableAutoRepeat); + FPTR(XkbKeycodeToKeysym); FPTR(XStoreName); FPTR(XIconifyWindow); FPTR(XMoveResizeWindow); @@ -117,6 +118,7 @@ static int x11h_init(int *xenv_flags, const char *window_title) FPTR_LINK(g_xstuff, x11lib, XPending); FPTR_LINK(g_xstuff, x11lib, XLookupKeysym); FPTR_LINK(g_xstuff, x11lib, XkbSetDetectableAutoRepeat); + FPTR_LINK(g_xstuff, x11lib, XkbKeycodeToKeysym); FPTR_LINK(g_xstuff, x11lib, XStoreName); FPTR_LINK(g_xstuff, x11lib, XIconifyWindow); FPTR_LINK(g_xstuff, x11lib, XMoveResizeWindow); @@ -424,6 +426,15 @@ int xenv_minimize(void) return -1; } +int xenv_keycode_to_keysym(int kc, int shift) +{ + if (g_xstuff.display) + return g_xstuff.pXkbKeycodeToKeysym(g_xstuff.display, + kc, 0, shift); + + return -1; +} + void xenv_finish(void) { // TODO: cleanup X? diff --git a/src/video/omapdss/linux/xenv.h b/src/video/omapdss/linux/xenv.h index 6abda19..05dd457 100644 --- a/src/video/omapdss/linux/xenv.h +++ b/src/video/omapdss/linux/xenv.h @@ -14,5 +14,6 @@ int xenv_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed), void *cb_arg); int xenv_minimize(void); +int xenv_keycode_to_keysym(int kc, int shift); void xenv_finish(void); diff --git a/src/video/omapdss/sdlif.c b/src/video/omapdss/sdlif.c index b367c3a..96388f2 100644 --- a/src/video/omapdss/sdlif.c +++ b/src/video/omapdss/sdlif.c @@ -237,9 +237,45 @@ static void omap_InitOSKeymap(SDL_VideoDevice *this) static int key_event_cb(void *cb_arg, int sdl_kc, int sdl_sc, int is_pressed) { SDL_keysym keysym = { 0, }; + int shift = 0; + SDLMod mod; + int ret; keysym.sym = sdl_kc; keysym.scancode = sdl_sc; + + /* 0xff if pandora's Fn, so we exclude it too.. */ + if (is_pressed && sdl_kc < 0xff && SDL_TranslateUNICODE) { + mod = SDL_GetModState(); + if (!(mod & KMOD_CTRL) && (!!(mod & KMOD_SHIFT) ^ !!(mod & KMOD_CAPS))) + shift = 1; + + /* prefer X mapping, if that doesn't work use hardcoded one */ + ret = xenv_keycode_to_keysym(sdl_sc, shift); + if (ret >= 0) { + keysym.unicode = ret; + if ((mod & KMOD_CTRL) + && 0x60 <= keysym.unicode && keysym.unicode <= 0x7f) + { + keysym.unicode -= 0x60; + } + /* hmh.. */ + if ((keysym.unicode & 0xff00) == 0xff00) + keysym.unicode &= ~0xff00; + } + else { + keysym.unicode = sdl_kc; + if ((mod & KMOD_CTRL) && 0x60 <= sdl_kc && sdl_kc <= 0x7f) + { + keysym.unicode = sdl_kc - 0x60; + } + else if (shift && 'a' <= sdl_kc && sdl_kc <= 'z') + { + keysym.unicode = sdl_kc - 'a' + 'A'; + } + } + } + SDL_PrivateKeyboard(is_pressed, &keysym); } -- 2.39.5