From f11e49b4e7faa78730a4125de3c6b8b56965e48a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 29 Mar 2012 13:21:34 -0500 Subject: SDLvncviewer: fix the SDL_KEYUP issue Keys got stuck because unicode is 0 upon SDL_KEYUP events, even if the same key event sets unicode correctly in SDL_KEYDOWN events. Work around that for the common case (ASCII) using the fact that both SDL and X11 keysyms were created with ASCII compatibility in mind. So as long as we type ASCII symbols, we can map things trivially. Signed-off-by: Johannes Schindelin --- client_examples/SDLvncviewer.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 5fa8f2c..f704ccc 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -78,7 +78,9 @@ static rfbBool resize(rfbClient* client) { static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { rfbKeySym k = 0; - switch(e->keysym.sym) { + SDLKey sym = e->keysym.sym; + + switch (sym) { case SDLK_BACKSPACE: k = XK_BackSpace; break; case SDLK_TAB: k = XK_Tab; break; case SDLK_CLEAR: k = XK_Clear; break; @@ -152,16 +154,21 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_BREAK: k = XK_Break; break; default: break; } - if (k == 0 && e->keysym.sym >= SDLK_a && e->keysym.sym <= SDLK_z) { - k = XK_a + e->keysym.sym - SDLK_a; - if (e->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) - k &= ~0x20; + /* both SDL and X11 keysyms match ASCII in the range 0x01-0x7f */ + if (k == 0 && sym > 0x0 && sym < 0x100) { + k = sym; + if (e->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) { + if (k >= '1' && k <= '9') + k &= ~0x10; + else if (k >= 'a' && k <= 'f') + k &= ~0x20; + } } if (k == 0) { if (e->keysym.unicode < 0x100) k = e->keysym.unicode; else - rfbClientLog("Unknown keysym: %d\n",e->keysym.sym); + rfbClientLog("Unknown keysym: %d\n", sym); } return k; -- cgit v1.2.3