diff options
author | dscho <dscho> | 2009-03-07 19:18:55 +0000 |
---|---|---|
committer | dscho <dscho> | 2009-03-07 19:18:55 +0000 |
commit | e12c4ccf235e1760364c9a9930a5f1f56c4c7098 (patch) | |
tree | af35ada95ff8ff4a52324954dd9a17a883694a0e /client_examples/SDLvncviewer.c | |
parent | 1b2083d8aa7e5b329611c6357487ae1d5aacb4f8 (diff) | |
download | libvncserver-e12c4ccf235e1760364c9a9930a5f1f56c4c7098.zip libvncserver-e12c4ccf235e1760364c9a9930a5f1f56c4c7098.tar.gz |
SDLvncviewer: refactor event handling
Instead of having deep indent levels, put the code to handle events into
its own function. That also helps readability.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 'client_examples/SDLvncviewer.c')
-rw-r--r-- | client_examples/SDLvncviewer.c | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 2f011ee..738e9c6 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -8,7 +8,7 @@ struct { int sdl; int rfb; } buttonMapping[]={ {0,0} }; -static int enableResizable; +static int enableResizable, viewOnly, buttonMask; #ifdef SDL_ASYNCBLIT int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; #else @@ -343,13 +343,60 @@ log_to_file(const char *format, ...) } #endif +static void handleSDLEvent(rfbClient *cl, SDL_Event *e) +{ + switch(e->type) { +#if SDL_MAJOR_VERSION > 1 || SDL_MINOR_VERSION >= 2 + case SDL_VIDEOEXPOSE: + SendFramebufferUpdateRequest(cl, 0, 0, + cl->width, cl->height, FALSE); + break; +#endif + case SDL_MOUSEBUTTONUP: + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEMOTION: { + int x, y, state, i; + if (viewOnly) + break; + + state = SDL_GetMouseState(&x, &y); + if (sdlPixels) { + x = x * cl->width / realWidth; + y = y * cl->height / realHeight; + } + for (buttonMask = 0, i = 0; buttonMapping[i].sdl; i++) + if (state & SDL_BUTTON(buttonMapping[i].sdl)) + buttonMask |= buttonMapping[i].rfb; + SendPointerEvent(cl, x, y, buttonMask); + break; + } + case SDL_KEYUP: + case SDL_KEYDOWN: + if (viewOnly) + break; + SendKeyEvent(cl, SDL_key2rfbKeySym(&e->key), + e->type == SDL_KEYDOWN ? TRUE : FALSE); + break; + case SDL_QUIT: + rfbClientCleanup(cl); + exit(0); + case SDL_ACTIVEEVENT: + break; + case SDL_VIDEORESIZE: + setRealDimension(cl, e->resize.w, e->resize.h); + break; + default: + rfbClientLog("ignore SDL event: 0x%x\n", e->type); + } +} + #ifdef mac #define main SDLmain #endif int main(int argc,char** argv) { rfbClient* cl; - int i, j, buttonMask = 0, viewOnly = 0; + int i, j; SDL_Event e; #ifdef LOG_TO_FILE @@ -385,47 +432,7 @@ int main(int argc,char** argv) { while(1) { if(SDL_PollEvent(&e)) - switch(e.type) { -#if SDL_MAJOR_VERSION>1 || SDL_MINOR_VERSION>=2 - case SDL_VIDEOEXPOSE: - SendFramebufferUpdateRequest(cl,0,0,cl->width,cl->height,FALSE); - break; -#endif - case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEMOTION: { - int x,y; - if (viewOnly) - break; - int state=SDL_GetMouseState(&x,&y); - int i; - - if (sdlPixels) { - x = x * cl->width / realWidth; - y = y * cl->height / realHeight; - } - for(buttonMask=0,i=0;buttonMapping[i].sdl;i++) - if(state&SDL_BUTTON(buttonMapping[i].sdl)) - buttonMask|=buttonMapping[i].rfb; - SendPointerEvent(cl,x,y,buttonMask); - } - break; - case SDL_KEYUP: case SDL_KEYDOWN: - if (viewOnly) - break; - SendKeyEvent(cl,SDL_key2rfbKeySym(&e.key),(e.type==SDL_KEYDOWN)?TRUE:FALSE); - break; - case SDL_QUIT: - rfbClientCleanup(cl); - return 0; - case SDL_ACTIVEEVENT: - break; - case SDL_VIDEORESIZE: - setRealDimension(cl, - e.resize.w, e.resize.h); - break; - default: - rfbClientLog("ignore SDL event: 0x%x\n",e.type); - } + handleSDLEvent(cl, &e); else { i=WaitForMessage(cl,500); if(i<0) |