Commit 6a7736f8 authored by dscho's avatar dscho

translate keys based on unicode (much more reliable than sym)

parent 54906d73
#include <SDL.h> #include <SDL.h>
#include <rfb/rfbclient.h> #include <rfb/rfbclient.h>
struct { int sdl; int rfb; } buttonMapping[]={
{1, rfbButton1Mask},
{3, rfbButton2Mask},
{2, rfbButton3Mask},
{0,0}
};
static rfbBool resize(rfbClient* client) { static rfbBool resize(rfbClient* client) {
static char first=TRUE; static char first=TRUE;
#ifdef SDL_ASYNCBLIT #ifdef SDL_ASYNCBLIT
...@@ -46,145 +53,90 @@ static rfbBool resize(rfbClient* client) { ...@@ -46,145 +53,90 @@ static rfbBool resize(rfbClient* client) {
return TRUE; return TRUE;
} }
static rfbKeySym SDL_keysym2rfbKeySym(int keysym) { static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) {
switch(keysym) { rfbKeySym k = 0;
case SDLK_BACKSPACE: return XK_BackSpace; switch(e->keysym.sym) {
case SDLK_TAB: return XK_ISO_Left_Tab; case SDLK_BACKSPACE: k = XK_BackSpace; break;
case SDLK_CLEAR: return XK_Clear; case SDLK_TAB: k = XK_ISO_Left_Tab; break;
case SDLK_RETURN: return XK_Return; case SDLK_CLEAR: k = XK_Clear; break;
case SDLK_PAUSE: return XK_Pause; case SDLK_RETURN: k = XK_Return; break;
case SDLK_ESCAPE: return XK_Escape; case SDLK_PAUSE: k = XK_Pause; break;
case SDLK_SPACE: return XK_space; case SDLK_ESCAPE: k = XK_Escape; break;
case SDLK_EXCLAIM: return XK_exclam; case SDLK_SPACE: k = XK_space; break;
case SDLK_QUOTEDBL: return XK_quotedbl; case SDLK_DELETE: k = XK_Delete; break;
case SDLK_HASH: return XK_numbersign; case SDLK_KP0: k = XK_KP_0; break;
case SDLK_DOLLAR: return XK_dollar; case SDLK_KP1: k = XK_KP_1; break;
case SDLK_AMPERSAND: return XK_ampersand; case SDLK_KP2: k = XK_KP_2; break;
case SDLK_QUOTE: return XK_apostrophe; case SDLK_KP3: k = XK_KP_3; break;
case SDLK_LEFTPAREN: return XK_parenleft; case SDLK_KP4: k = XK_KP_4; break;
case SDLK_RIGHTPAREN: return XK_parenright; case SDLK_KP5: k = XK_KP_5; break;
case SDLK_ASTERISK: return XK_asterisk; case SDLK_KP6: k = XK_KP_6; break;
case SDLK_PLUS: return XK_plus; case SDLK_KP7: k = XK_KP_7; break;
case SDLK_COMMA: return XK_comma; case SDLK_KP8: k = XK_KP_8; break;
case SDLK_MINUS: return XK_minus; case SDLK_KP9: k = XK_KP_9; break;
case SDLK_PERIOD: return XK_period; case SDLK_KP_PERIOD: k = XK_KP_Decimal; break;
case SDLK_SLASH: return XK_slash; case SDLK_KP_DIVIDE: k = XK_KP_Divide; break;
case SDLK_0: return XK_0; case SDLK_KP_MULTIPLY: k = XK_KP_Multiply; break;
case SDLK_1: return XK_1; case SDLK_KP_MINUS: k = XK_KP_Subtract; break;
case SDLK_2: return XK_2; case SDLK_KP_PLUS: k = XK_KP_Add; break;
case SDLK_3: return XK_3; case SDLK_KP_ENTER: k = XK_KP_Enter; break;
case SDLK_4: return XK_4; case SDLK_KP_EQUALS: k = XK_KP_Equal; break;
case SDLK_5: return XK_5; case SDLK_UP: k = XK_Up; break;
case SDLK_6: return XK_6; case SDLK_DOWN: k = XK_Down; break;
case SDLK_7: return XK_7; case SDLK_RIGHT: k = XK_Right; break;
case SDLK_8: return XK_8; case SDLK_LEFT: k = XK_Left; break;
case SDLK_9: return XK_9; case SDLK_INSERT: k = XK_Insert; break;
case SDLK_COLON: return XK_colon; case SDLK_HOME: k = XK_Home; break;
case SDLK_SEMICOLON: return XK_semicolon; case SDLK_END: k = XK_End; break;
case SDLK_LESS: return XK_less; case SDLK_PAGEUP: k = XK_Page_Up; break;
case SDLK_EQUALS: return XK_equal; case SDLK_PAGEDOWN: k = XK_Page_Down; break;
case SDLK_GREATER: return XK_greater; case SDLK_F1: k = XK_F1; break;
case SDLK_QUESTION: return XK_question; case SDLK_F2: k = XK_F2; break;
case SDLK_AT: return XK_at; case SDLK_F3: k = XK_F3; break;
case SDLK_LEFTBRACKET: return XK_bracketleft; case SDLK_F4: k = XK_F4; break;
case SDLK_BACKSLASH: return XK_backslash; case SDLK_F5: k = XK_F5; break;
case SDLK_RIGHTBRACKET: return XK_bracketright; case SDLK_F6: k = XK_F6; break;
case SDLK_CARET: return XK_asciicircum; case SDLK_F7: k = XK_F7; break;
case SDLK_UNDERSCORE: return XK_underscore; case SDLK_F8: k = XK_F8; break;
case SDLK_BACKQUOTE: return XK_grave; case SDLK_F9: k = XK_F9; break;
case SDLK_a: return XK_a; case SDLK_F10: k = XK_F10; break;
case SDLK_b: return XK_b; case SDLK_F11: k = XK_F11; break;
case SDLK_c: return XK_c; case SDLK_F12: k = XK_F12; break;
case SDLK_d: return XK_d; case SDLK_F13: k = XK_F13; break;
case SDLK_e: return XK_e; case SDLK_F14: k = XK_F14; break;
case SDLK_f: return XK_f; case SDLK_F15: k = XK_F15; break;
case SDLK_g: return XK_g; case SDLK_NUMLOCK: k = XK_Num_Lock; break;
case SDLK_h: return XK_h; case SDLK_CAPSLOCK: k = XK_Caps_Lock; break;
case SDLK_i: return XK_i; case SDLK_SCROLLOCK: k = XK_Scroll_Lock; break;
case SDLK_j: return XK_j; case SDLK_RSHIFT: k = XK_Shift_R; break;
case SDLK_k: return XK_k; case SDLK_LSHIFT: k = XK_Shift_L; break;
case SDLK_l: return XK_l; case SDLK_RCTRL: k = XK_Control_R; break;
case SDLK_m: return XK_m; case SDLK_LCTRL: k = XK_Control_L; break;
case SDLK_n: return XK_n; case SDLK_RALT: k = XK_Alt_R; break;
case SDLK_o: return XK_o; case SDLK_LALT: k = XK_Alt_L; break;
case SDLK_p: return XK_p; case SDLK_RMETA: k = XK_Meta_R; break;
case SDLK_q: return XK_q; case SDLK_LMETA: k = XK_Meta_L; break;
case SDLK_r: return XK_r;
case SDLK_s: return XK_s;
case SDLK_t: return XK_t;
case SDLK_u: return XK_u;
case SDLK_v: return XK_v;
case SDLK_w: return XK_w;
case SDLK_x: return XK_x;
case SDLK_y: return XK_y;
case SDLK_z: return XK_z;
case SDLK_DELETE: return XK_Delete;
case SDLK_KP0: return XK_KP_0;
case SDLK_KP1: return XK_KP_1;
case SDLK_KP2: return XK_KP_2;
case SDLK_KP3: return XK_KP_3;
case SDLK_KP4: return XK_KP_4;
case SDLK_KP5: return XK_KP_5;
case SDLK_KP6: return XK_KP_6;
case SDLK_KP7: return XK_KP_7;
case SDLK_KP8: return XK_KP_8;
case SDLK_KP9: return XK_KP_9;
case SDLK_KP_PERIOD: return XK_KP_Decimal;
case SDLK_KP_DIVIDE: return XK_KP_Divide;
case SDLK_KP_MULTIPLY: return XK_KP_Multiply;
case SDLK_KP_MINUS: return XK_KP_Subtract;
case SDLK_KP_PLUS: return XK_KP_Add;
case SDLK_KP_ENTER: return XK_KP_Enter;
case SDLK_KP_EQUALS: return XK_KP_Equal;
case SDLK_UP: return XK_Up;
case SDLK_DOWN: return XK_Down;
case SDLK_RIGHT: return XK_Right;
case SDLK_LEFT: return XK_Left;
case SDLK_INSERT: return XK_Insert;
case SDLK_HOME: return XK_Home;
case SDLK_END: return XK_End;
case SDLK_PAGEUP: return XK_Page_Up;
case SDLK_PAGEDOWN: return XK_Page_Down;
case SDLK_F1: return XK_F1;
case SDLK_F2: return XK_F2;
case SDLK_F3: return XK_F3;
case SDLK_F4: return XK_F4;
case SDLK_F5: return XK_F5;
case SDLK_F6: return XK_F6;
case SDLK_F7: return XK_F7;
case SDLK_F8: return XK_F8;
case SDLK_F9: return XK_F9;
case SDLK_F10: return XK_F10;
case SDLK_F11: return XK_F11;
case SDLK_F12: return XK_F12;
case SDLK_F13: return XK_F13;
case SDLK_F14: return XK_F14;
case SDLK_F15: return XK_F15;
case SDLK_NUMLOCK: return XK_Num_Lock;
case SDLK_CAPSLOCK: return XK_Caps_Lock;
case SDLK_SCROLLOCK: return XK_Scroll_Lock;
case SDLK_RSHIFT: return XK_Shift_R;
case SDLK_LSHIFT: return XK_Shift_L;
case SDLK_RCTRL: return XK_Control_R;
case SDLK_LCTRL: return XK_Control_L;
case SDLK_RALT: return XK_Alt_R;
case SDLK_LALT: return XK_Alt_L;
case SDLK_RMETA: return XK_Meta_R;
case SDLK_LMETA: return XK_Meta_L;
#if 0 #if 0
/* TODO: find out keysyms */ /* TODO: find out keysyms */
case SDLK_LSUPER: return XK_LSuper; /* left "windows" key */ case SDLK_LSUPER: k = XK_LSuper; break; /* left "windows" key */
case SDLK_RSUPER: return XK_RSuper; /* right "windows" key */ case SDLK_RSUPER: k = XK_RSuper; break; /* right "windows" key */
case SDLK_COMPOSE: return XK_Compose; case SDLK_COMPOSE: k = XK_Compose; break;
#endif #endif
case SDLK_MODE: return XK_Mode_switch; case SDLK_MODE: k = XK_Mode_switch; break;
case SDLK_HELP: return XK_Help; case SDLK_HELP: k = XK_Help; break;
case SDLK_PRINT: return XK_Print; case SDLK_PRINT: k = XK_Print; break;
case SDLK_SYSREQ: return XK_Sys_Req; case SDLK_SYSREQ: k = XK_Sys_Req; break;
case SDLK_BREAK: return XK_Break; case SDLK_BREAK: k = XK_Break; break;
default: rfbClientLog("Unknown keysym: %d\n",keysym); default: break;
} }
return 0; if (k == 0) {
if (e->keysym.unicode < 0x100)
k = e->keysym.unicode;
else
rfbClientLog("Unknown keysym: %d\n",e->keysym.sym);
}
return k;
} }
static void update(rfbClient* cl,int x,int y,int w,int h) { static void update(rfbClient* cl,int x,int y,int w,int h) {
...@@ -265,12 +217,6 @@ int main(int argc,char** argv) { ...@@ -265,12 +217,6 @@ int main(int argc,char** argv) {
case SDL_MOUSEMOTION: { case SDL_MOUSEMOTION: {
int x,y; int x,y;
int state=SDL_GetMouseState(&x,&y); int state=SDL_GetMouseState(&x,&y);
struct { int sdl; int rfb; } buttonMapping[]={
{1, rfbButton1Mask},
{3, rfbButton2Mask},
{2, rfbButton3Mask},
{0,0}
};
int i; int i;
for(buttonMask=0,i=0;buttonMapping[i].sdl;i++) for(buttonMask=0,i=0;buttonMapping[i].sdl;i++)
if(state&SDL_BUTTON(buttonMapping[i].sdl)) if(state&SDL_BUTTON(buttonMapping[i].sdl))
...@@ -279,7 +225,7 @@ int main(int argc,char** argv) { ...@@ -279,7 +225,7 @@ int main(int argc,char** argv) {
} }
break; break;
case SDL_KEYUP: case SDL_KEYDOWN: case SDL_KEYUP: case SDL_KEYDOWN:
SendKeyEvent(cl,SDL_keysym2rfbKeySym(e.key.keysym.sym),(e.type==SDL_KEYDOWN)?TRUE:FALSE); SendKeyEvent(cl,SDL_key2rfbKeySym(&e.key),(e.type==SDL_KEYDOWN)?TRUE:FALSE);
break; break;
case SDL_QUIT: case SDL_QUIT:
rfbClientCleanup(cl); rfbClientCleanup(cl);
......
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