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 <johannes.schindelin@gmx.de>
pull/1/head
Johannes Schindelin 11 years ago
parent 1078e8a8b0
commit f11e49b4e7
  1. 19
      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;

Loading…
Cancel
Save