From 436a047f56cf5f5c92d946faa6b08e3ed7aa2309 Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Wed, 25 Jul 2018 14:22:00 +0200 Subject: SDLvncviewer: add a very simple GetCredentials callback --- client_examples/SDLvncviewer.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 8fe6f57..6dce992 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -475,6 +475,30 @@ static void got_selection(rfbClient *cl, const char *text, int len) } +static rfbCredential* get_credential(rfbClient* cl, int credentialType){ + rfbCredential *c = malloc(sizeof(rfbCredential)); + c->userCredential.username = malloc(RFB_BUF_SIZE); + c->userCredential.password = malloc(RFB_BUF_SIZE); + + if(credentialType != rfbCredentialTypeUser) { + rfbClientErr("something else than username and password required for authentication\n"); + return NULL; + } + + rfbClientLog("username and password required for authentication!\n"); + printf("user: "); + fgets(c->userCredential.username, RFB_BUF_SIZE, stdin); + printf("pass: "); + fgets(c->userCredential.password, RFB_BUF_SIZE, stdin); + + /* remove trailing newlines */ + c->userCredential.username[strcspn(c->userCredential.username, "\n")] = 0; + c->userCredential.password[strcspn(c->userCredential.password, "\n")] = 0; + + return c; +} + + #ifdef mac #define main SDLmain #endif @@ -523,6 +547,7 @@ int main(int argc,char** argv) { cl->HandleKeyboardLedState=kbd_leds; cl->HandleTextChat=text_chat; cl->GotXCutText = got_selection; + cl->GetCredential = get_credential; cl->listenPort = LISTEN_PORT_OFFSET; cl->listen6Port = LISTEN_PORT_OFFSET; if(!rfbInitClient(cl,&argc,argv)) -- cgit v1.2.3 From 65126b58268c53931fd742aa5e57bb892b60b4a7 Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Wed, 16 May 2018 18:13:44 +0200 Subject: SDLvncviewer: make display work with SDL2 --- client_examples/SDLvncviewer.c | 144 +++++++++++++++++++++++++---------------- client_examples/scrap.c | 3 +- 2 files changed, 92 insertions(+), 55 deletions(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 6dce992..f23edf8 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -17,13 +17,12 @@ struct { int sdl; int rfb; } buttonMapping[]={ }; static int enableResizable = 1, viewOnly, listenLoop, buttonMask; -#ifdef SDL_ASYNCBLIT - int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; -#else - int sdlFlags = SDL_HWSURFACE | SDL_HWACCEL; -#endif +int sdlFlags; static int realWidth, realHeight, bytesPerPixel, rowStride; static char *sdlPixels; +SDL_Texture *sdlTexture; +SDL_Renderer *sdlRenderer; +SDL_Window *sdlWindow; static int rightAltKeyDown, leftAltKeyDown; @@ -32,53 +31,76 @@ static rfbBool resize(rfbClient* client) { depth=client->format.bitsPerPixel; if (enableResizable) - sdlFlags |= SDL_RESIZABLE; + sdlFlags |= SDL_WINDOW_RESIZABLE; client->updateRect.x = client->updateRect.y = 0; client->updateRect.w = width; client->updateRect.h = height; - rfbBool okay=SDL_VideoModeOK(width,height,depth,sdlFlags); - if(!okay) - for(depth=24;!okay && depth>4;depth/=2) - okay=SDL_VideoModeOK(width,height,depth,sdlFlags); - if(okay) { - SDL_Surface* sdl=SDL_SetVideoMode(width,height,depth,sdlFlags); - rfbClientSetClientData(client, SDL_Init, sdl); - client->width = sdl->pitch / (depth / 8); - if (sdlPixels) { - free(client->frameBuffer); - sdlPixels = NULL; - } - client->frameBuffer=sdl->pixels; - - client->format.bitsPerPixel=depth; - client->format.redShift=sdl->format->Rshift; - client->format.greenShift=sdl->format->Gshift; - client->format.blueShift=sdl->format->Bshift; - client->format.redMax=sdl->format->Rmask>>client->format.redShift; - client->format.greenMax=sdl->format->Gmask>>client->format.greenShift; - client->format.blueMax=sdl->format->Bmask>>client->format.blueShift; - SetFormatAndEncodings(client); + /* (re)create the surface used as the client's framebuffer */ + SDL_FreeSurface(rfbClientGetClientData(client, SDL_Init)); + SDL_Surface* sdl=SDL_CreateRGBSurface(0, + width, + height, + depth, + 0,0,0,0); + if(!sdl) + rfbClientErr("resize: error creating surface: %s\n", SDL_GetError()); + + rfbClientSetClientData(client, SDL_Init, sdl); + client->width = sdl->pitch / (depth / 8); + if (sdlPixels) { + free(client->frameBuffer); + sdlPixels = NULL; + } + client->frameBuffer=sdl->pixels; + + client->format.bitsPerPixel=depth; + client->format.redShift=sdl->format->Rshift; + client->format.greenShift=sdl->format->Gshift; + client->format.blueShift=sdl->format->Bshift; + client->format.redMax=sdl->format->Rmask>>client->format.redShift; + client->format.greenMax=sdl->format->Gmask>>client->format.greenShift; + client->format.blueMax=sdl->format->Bmask>>client->format.blueShift; + SetFormatAndEncodings(client); + + /* create or resize the window */ + if(!sdlWindow) { + sdlWindow = SDL_CreateWindow(client->desktopName, + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + width, + height, + sdlFlags); + if(!sdlWindow) + rfbClientErr("resize: error creating window: %s\n", SDL_GetError()); } else { - SDL_Surface* sdl=rfbClientGetClientData(client, SDL_Init); - rfbClientLog("Could not set resolution %dx%d!\n", - client->width,client->height); - if(sdl) { - client->width=sdl->pitch / (depth / 8); - client->height=sdl->h; - } else { - client->width=0; - client->height=0; - } - return FALSE; + SDL_SetWindowSize(sdlWindow, width, height); } - SDL_WM_SetCaption(client->desktopName, "SDL"); + + /* create the renderer if it does not already exist */ + if(!sdlRenderer) { + sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0); + if(!sdlRenderer) + rfbClientErr("resize: error creating renderer: %s\n", SDL_GetError()); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); /* make the scaled rendering look smoother. */ + } + SDL_RenderSetLogicalSize(sdlRenderer, width, height); /* this is a departure from the SDL1.2-based version, but more in the sense of a VNC viewer in keeeping aspect ratio */ + + /* (re)create the texture that sits in between the surface->pixels and the renderer */ + if(sdlTexture) + SDL_DestroyTexture(sdlTexture); + sdlTexture = SDL_CreateTexture(sdlRenderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + width, height); + if(!sdlTexture) + rfbClientErr("resize: error creating texture: %s\n", SDL_GetError()); return TRUE; } static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { rfbKeySym k = 0; - SDLKey sym = e->keysym.sym; + /*FIXMESDLKey sym = e->keysym.sym; switch (sym) { case SDLK_BACKSPACE: k = XK_BackSpace; break; @@ -153,7 +175,7 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_BREAK: k = XK_Break; break; default: break; } - /* both SDL and X11 keysyms match ASCII in the range 0x01-0x7f */ + // 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)) { @@ -169,7 +191,7 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { else rfbClientLog("Unknown keysym: %d\n", sym); } - +*/ return k; } @@ -245,19 +267,29 @@ static void update(rfbClient* cl,int x,int y,int w,int h) { w -= x; h -= y; } - SDL_UpdateRect(rfbClientGetClientData(cl, SDL_Init), x, y, w, h); + SDL_Surface *sdl = rfbClientGetClientData(cl, SDL_Init); + /* update texture from surface->pixels */ + SDL_Rect r = {x,y,w,h}; + if(SDL_UpdateTexture(sdlTexture, &r, sdl->pixels + y*sdl->pitch + x*4, sdl->pitch) < 0) + rfbClientErr("update: failed to update texture: %s\n", SDL_GetError()); + /* copy texture to renderer and show */ + if(SDL_RenderClear(sdlRenderer) < 0) + rfbClientErr("update: failed to clear renderer: %s\n", SDL_GetError()); + if(SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL) < 0) + rfbClientErr("update: failed to copy texture to renderer: %s\n", SDL_GetError()); + SDL_RenderPresent(sdlRenderer); } static void setRealDimension(rfbClient *client, int w, int h) { SDL_Surface* sdl; - + /*FIXME if (w < 0) { const SDL_VideoInfo *info = SDL_GetVideoInfo(); w = info->current_h; h = info->current_w; } - + */ if (w == realWidth && h == realHeight) return; @@ -280,7 +312,7 @@ static void setRealDimension(rfbClient *client, int w, int h) sdl = rfbClientGetClientData(client, SDL_Init); if (sdl->w != w || sdl->h != h) { int depth = sdl->format->BitsPerPixel; - sdl = SDL_SetVideoMode(w, h, depth, sdlFlags); + //FIXMEsdl = SDL_SetVideoMode(w, h, depth, sdlFlags); rfbClientSetClientData(client, SDL_Init, sdl); sdlPixels = sdl->pixels; rowStride = sdl->pitch / (depth / 8); @@ -374,12 +406,14 @@ static void cleanup(rfbClient* cl) static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) { switch(e->type) { -#if SDL_MAJOR_VERSION > 1 || SDL_MINOR_VERSION >= 2 - case SDL_VIDEOEXPOSE: + case SDL_WINDOWEVENT: + switch (e->window.event) { + case SDL_WINDOWEVENT_EXPOSED: SendFramebufferUpdateRequest(cl, 0, 0, cl->width, cl->height, FALSE); break; -#endif + } + break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: @@ -437,6 +471,7 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) rfbClientCleanup(cl); exit(0); } + /*FIXME case SDL_ACTIVEEVENT: if (!e->active.gain && rightAltKeyDown) { SendKeyEvent(cl, XK_Alt_R, FALSE); @@ -457,12 +492,15 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) SendClientCutText(cl, data, len); } break; + */ case SDL_SYSWMEVENT: clipboard_filter(e); break; + /*FIXME case SDL_VIDEORESIZE: setRealDimension(cl, e->resize.w, e->resize.h); break; + */ default: rfbClientLog("ignore SDL event: 0x%x\n", e->type); } @@ -471,7 +509,7 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) static void got_selection(rfbClient *cl, const char *text, int len) { - put_scrap(T('T', 'E', 'X', 'T'), len, text); + //FIXMEput_scrap(T('T', 'E', 'X', 'T'), len, text); } @@ -532,9 +570,7 @@ int main(int argc,char** argv) { argc = j; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, - SDL_DEFAULT_REPEAT_INTERVAL); + //FIXME SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); atexit(SDL_Quit); signal(SIGINT, exit); diff --git a/client_examples/scrap.c b/client_examples/scrap.c index 0ee22bf..1344b75 100644 --- a/client_examples/scrap.c +++ b/client_examples/scrap.c @@ -209,7 +209,8 @@ int init_scrap(void) SDL_SetError("SDL is not running on known window manager"); SDL_VERSION(&info.version); - if (SDL_GetWMInfo(&info)) { + //FIXMEif (SDL_GetWMInfo(&info)) + { /* Save the information for later use */ #if defined(X11_SCRAP) if (info.subsystem == SDL_SYSWM_X11) { -- cgit v1.2.3 From 8f1b565dbeab0afd2965ef2fe8af86aabb1275dc Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Wed, 25 Jul 2018 16:35:09 +0200 Subject: SDLvncviewer: make input work with SDL2 ... at least somewhat. This is far from perfect but no regression compared to SDL1.2 functionality. --- client_examples/SDLvncviewer.c | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index f23edf8..2908e4c 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -100,7 +100,7 @@ static rfbBool resize(rfbClient* client) { static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { rfbKeySym k = 0; - /*FIXMESDLKey sym = e->keysym.sym; + SDL_Keycode sym = e->keysym.sym; switch (sym) { case SDLK_BACKSPACE: k = XK_BackSpace; break; @@ -111,16 +111,16 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_ESCAPE: k = XK_Escape; break; case SDLK_SPACE: k = XK_space; break; case SDLK_DELETE: k = XK_Delete; break; - case SDLK_KP0: k = XK_KP_0; break; - case SDLK_KP1: k = XK_KP_1; break; - case SDLK_KP2: k = XK_KP_2; break; - case SDLK_KP3: k = XK_KP_3; break; - case SDLK_KP4: k = XK_KP_4; break; - case SDLK_KP5: k = XK_KP_5; break; - case SDLK_KP6: k = XK_KP_6; break; - case SDLK_KP7: k = XK_KP_7; break; - case SDLK_KP8: k = XK_KP_8; break; - case SDLK_KP9: k = XK_KP_9; break; + case SDLK_KP_0: k = XK_KP_0; break; + case SDLK_KP_1: k = XK_KP_1; break; + case SDLK_KP_2: k = XK_KP_2; break; + case SDLK_KP_3: k = XK_KP_3; break; + case SDLK_KP_4: k = XK_KP_4; break; + case SDLK_KP_5: k = XK_KP_5; break; + case SDLK_KP_6: k = XK_KP_6; break; + case SDLK_KP_7: k = XK_KP_7; break; + case SDLK_KP_8: k = XK_KP_8; break; + case SDLK_KP_9: k = XK_KP_9; break; case SDLK_KP_PERIOD: k = XK_KP_Decimal; break; case SDLK_KP_DIVIDE: k = XK_KP_Divide; break; case SDLK_KP_MULTIPLY: k = XK_KP_Multiply; break; @@ -152,27 +152,24 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_F13: k = XK_F13; break; case SDLK_F14: k = XK_F14; break; case SDLK_F15: k = XK_F15; break; - case SDLK_NUMLOCK: k = XK_Num_Lock; break; + case SDLK_NUMLOCKCLEAR: k = XK_Num_Lock; break; case SDLK_CAPSLOCK: k = XK_Caps_Lock; break; - case SDLK_SCROLLOCK: k = XK_Scroll_Lock; break; + case SDLK_SCROLLLOCK: k = XK_Scroll_Lock; break; case SDLK_RSHIFT: k = XK_Shift_R; break; case SDLK_LSHIFT: k = XK_Shift_L; break; case SDLK_RCTRL: k = XK_Control_R; break; case SDLK_LCTRL: k = XK_Control_L; break; case SDLK_RALT: k = XK_Alt_R; break; case SDLK_LALT: k = XK_Alt_L; break; - case SDLK_RMETA: k = XK_Meta_R; break; - case SDLK_LMETA: k = XK_Meta_L; break; - case SDLK_LSUPER: k = XK_Super_L; break; - case SDLK_RSUPER: k = XK_Super_R; break; + case SDLK_LGUI: k = XK_Super_L; break; + case SDLK_RGUI: k = XK_Super_R; break; #if 0 case SDLK_COMPOSE: k = XK_Compose; break; #endif case SDLK_MODE: k = XK_Mode_switch; break; case SDLK_HELP: k = XK_Help; break; - case SDLK_PRINT: k = XK_Print; break; + case SDLK_PRINTSCREEN: k = XK_Print; break; case SDLK_SYSREQ: k = XK_Sys_Req; break; - case SDLK_BREAK: k = XK_Break; break; default: break; } // both SDL and X11 keysyms match ASCII in the range 0x01-0x7f @@ -185,13 +182,14 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { k &= ~0x20; } } - if (k == 0) { + /*TODO: try out SDL_TEXTINPUT for unicode input + if (k == 0) { if (e->keysym.unicode < 0x100) k = e->keysym.unicode; else rfbClientLog("Unknown keysym: %d\n", sym); } -*/ + */ return k; } @@ -460,6 +458,9 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) if (e->key.keysym.sym == SDLK_LALT) leftAltKeyDown = e->type == SDL_KEYDOWN; break; + case SDL_TEXTINPUT: + /* TODO: maybe use this for unicode input */ + break; case SDL_QUIT: if(listenLoop) { @@ -570,7 +571,6 @@ int main(int argc,char** argv) { argc = j; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); - //FIXME SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); atexit(SDL_Quit); signal(SIGINT, exit); -- cgit v1.2.3 From bfdb850bfb73ac08146fb7a5d4415c91116eccda Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Thu, 26 Jul 2018 11:14:03 +0200 Subject: SDLvncviewer: use SDL2 for clipboard handling By using this, we can get rid of our own homebrewn solution scrap.[c|h] and drop X11 from the build system. --- CMakeLists.txt | 9 +- client_examples/SDLvncviewer.c | 54 ++-- client_examples/scrap.c | 559 ----------------------------------------- client_examples/scrap.h | 18 -- 4 files changed, 26 insertions(+), 614 deletions(-) delete mode 100644 client_examples/scrap.c delete mode 100644 client_examples/scrap.h (limited to 'client_examples/SDLvncviewer.c') diff --git a/CMakeLists.txt b/CMakeLists.txt index c831ee9..86038d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ option(WITH_ZLIB "Search for the zlib compression library to support additional option(WITH_JPEG "Search for the libjpeg compression library to support additional encodings" ON) option(WITH_PNG "Search for the PNG compression library to support additional encodings" ON) option(WITH_SDL "Search for the Simple Direct Media Layer library to build an example SDL vnc client" ON) -option(WITH_X11 "Search for X11 to build the example SDL vnc client with clipboard support" ON) option(WITH_THREADS "Search for a threading library to build with multithreading support" ON) option(WITH_GNUTLS "Search for the GnuTLS secure communications library to support encryption" ON) option(WITH_OPENSSL "Search for the OpenSSL cryptography library to support encryption" ON) @@ -105,11 +104,6 @@ if(WITH_SDL) endif(WITH_SDL) -if(WITH_X11) - find_package(X11) -endif(WITH_X11) - - if(WITH_THREADS) find_package(Threads) endif(WITH_THREADS) @@ -506,7 +500,6 @@ if(SDL2_FOUND) ${LIBVNCCLIENT_EXAMPLES} SDLvncviewer ) - set(SDLvncviewer_EXTRA_SOURCES scrap.c) endif(SDL2_FOUND) if(FFMPEG_FOUND) @@ -530,7 +523,7 @@ foreach(e ${LIBVNCCLIENT_EXAMPLES}) add_executable(client_examples_${e} ${LIBVNCCLIEXAMPLE_DIR}/${e}.c ${LIBVNCCLIEXAMPLE_DIR}/${${e}_EXTRA_SOURCES} ) set_target_properties(client_examples_${e} PROPERTIES OUTPUT_NAME ${e}) set_target_properties(client_examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/client_examples) - target_link_libraries(client_examples_${e} vncclient ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY} ${X11_LIBRARIES} ${FFMPEG_LIBRARIES}) + target_link_libraries(client_examples_${e} vncclient ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES}) endforeach(e ${LIBVNCCLIENT_EXAMPLES}) diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 2908e4c..ff0543c 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -5,7 +5,6 @@ #include #include #include -#include "scrap.h" struct { int sdl; int rfb; } buttonMapping[]={ {1, rfbButton1Mask}, @@ -410,6 +409,28 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) SendFramebufferUpdateRequest(cl, 0, 0, cl->width, cl->height, FALSE); break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + if (SDL_HasClipboardText()) { + char *text = SDL_GetClipboardText(); + if(text) { + rfbClientLog("sending clipboard text '%s'\n", text); + SendClientCutText(cl, text, strlen(text)); + } + } + + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + if (rightAltKeyDown) { + SendKeyEvent(cl, XK_Alt_R, FALSE); + rightAltKeyDown = FALSE; + rfbClientLog("released right Alt key\n"); + } + if (leftAltKeyDown) { + SendKeyEvent(cl, XK_Alt_L, FALSE); + leftAltKeyDown = FALSE; + rfbClientLog("released left Alt key\n"); + } + break; } break; case SDL_MOUSEBUTTONUP: @@ -473,31 +494,6 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) exit(0); } /*FIXME - case SDL_ACTIVEEVENT: - if (!e->active.gain && rightAltKeyDown) { - SendKeyEvent(cl, XK_Alt_R, FALSE); - rightAltKeyDown = FALSE; - rfbClientLog("released right Alt key\n"); - } - if (!e->active.gain && leftAltKeyDown) { - SendKeyEvent(cl, XK_Alt_L, FALSE); - leftAltKeyDown = FALSE; - rfbClientLog("released left Alt key\n"); - } - - if (e->active.gain && lost_scrap()) { - static char *data = NULL; - static int len = 0; - get_scrap(T('T', 'E', 'X', 'T'), &len, &data); - if (len) - SendClientCutText(cl, data, len); - } - break; - */ - case SDL_SYSWMEVENT: - clipboard_filter(e); - break; - /*FIXME case SDL_VIDEORESIZE: setRealDimension(cl, e->resize.w, e->resize.h); break; @@ -510,7 +506,9 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) static void got_selection(rfbClient *cl, const char *text, int len) { - //FIXMEput_scrap(T('T', 'E', 'X', 'T'), len, text); + rfbClientLog("received clipboard text '%s'\n", text); + if(SDL_SetClipboardText(text) != 0) + rfbClientErr("could not set received clipboard text: %s\n", SDL_GetError()); } @@ -593,8 +591,6 @@ int main(int argc,char** argv) { break; } - init_scrap(); - while(1) { if(SDL_PollEvent(&e)) { /* diff --git a/client_examples/scrap.c b/client_examples/scrap.c deleted file mode 100644 index 1344b75..0000000 --- a/client_examples/scrap.c +++ /dev/null @@ -1,559 +0,0 @@ -/* Handle clipboard text and data in arbitrary formats */ - -#include -#include - -#ifdef WIN32 -#include -#include -#else -#include -#include -#endif -#include "scrap.h" -#include "rfb/rfbconfig.h" - -/* Determine what type of clipboard we are using */ -#if defined(__unix__) && !defined(__QNXNTO__) && defined(SDL_VIDEO_DRIVER_X11) -#define X11_SCRAP -#elif defined(__WIN32__) -#define WIN_SCRAP -#elif defined(__QNXNTO__) -#define QNX_SCRAP -#else -#warning Unknown window manager for clipboard handling -#endif /* scrap type */ - -/* System dependent data types */ -#if defined(X11_SCRAP) -typedef Atom scrap_type; -static Atom XA_TARGETS, XA_TEXT, XA_COMPOUND_TEXT, XA_UTF8_STRING; -#elif defined(WIN_SCRAP) -typedef UINT scrap_type; -#elif defined(QNX_SCRAP) -typedef uint32_t scrap_type; -#define Ph_CL_TEXT T('T', 'E', 'X', 'T') -#else -typedef int scrap_type; -#endif /* scrap type */ - -/* System dependent variables */ -#if defined(X11_SCRAP) -static Display *SDL_Display; -static Window SDL_Window; -static void (*Lock_Display)(void); -static void (*Unlock_Display)(void); -static Atom XA_UTF8_STRING; -#elif defined(WIN_SCRAP) -static HWND SDL_Window; -#elif defined(QNX_SCRAP) -static unsigned short InputGroup; -#endif /* scrap type */ - -#define FORMAT_PREFIX "SDL_scrap_0x" - -static scrap_type convert_format(int type) -{ - switch (type) { - case T('T', 'E', 'X', 'T'): -#if defined(X11_SCRAP) - return XA_UTF8_STRING ? XA_UTF8_STRING : XA_STRING; -#elif defined(WIN_SCRAP) - return CF_TEXT; -#elif defined(QNX_SCRAP) - return Ph_CL_TEXT; -#endif /* scrap type */ - default: - { - char format[sizeof(FORMAT_PREFIX)+8+1]; - - sprintf(format, "%s%08lx", FORMAT_PREFIX, - (unsigned long)type); -#if defined(X11_SCRAP) - return XInternAtom(SDL_Display, format, False); -#elif defined(WIN_SCRAP) - return RegisterClipboardFormat(format); -#endif /* scrap type */ - } - } -} - -/* Convert internal data to scrap format */ -static int convert_data(int type, char *dst, const char *src, int srclen) -{ - int dstlen; - - dstlen = 0; - switch (type) { - case T('T', 'E', 'X', 'T'): - if (dst) { - while (--srclen >= 0) { -#if defined(__unix__) - if (*src == '\r') { - *dst++ = '\n'; - ++dstlen; - } - else -#elif defined(__WIN32__) - if (*src == '\r') { - *dst++ = '\r'; - ++dstlen; - *dst++ = '\n'; - ++dstlen; - } - else -#endif - { - *dst++ = *src; - ++dstlen; - } - ++src; - } - *dst = '\0'; - ++dstlen; - } - else { - while (--srclen >= 0) { -#if defined(__unix__) - if (*src == '\r') - ++dstlen; - else -#elif defined(__WIN32__) - if (*src == '\r') { - ++dstlen; - ++dstlen; - } - else -#endif - { - ++dstlen; - } - ++src; - } - ++dstlen; - } - break; - default: - if (dst) { - *(int *)dst = srclen; - dst += sizeof(int); - memcpy(dst, src, srclen); - } - dstlen = sizeof(int)+srclen; - break; - } - return(dstlen); -} - -/* Convert scrap data to internal format */ -static int convert_scrap(int type, char *dst, char *src, int srclen) -{ - int dstlen; - - dstlen = 0; - switch (type) { - case T('T', 'E', 'X', 'T'): - { - if (srclen == 0) - srclen = strlen(src); - if (dst) { - while (--srclen >= 0) { -#if defined(__WIN32__) - if (*src == '\r') - /* drop extraneous '\r' */; - else -#endif - if (*src == '\n') { - *dst++ = '\r'; - ++dstlen; - } - else { - *dst++ = *src; - ++dstlen; - } - ++src; - } - *dst = '\0'; - ++dstlen; - } - else { - while (--srclen >= 0) { -#if defined(__WIN32__) - /* drop extraneous '\r' */; - if (*src != '\r') -#endif - ++dstlen; - ++src; - } - ++dstlen; - } - break; - } - default: - dstlen = *(int *)src; - if (dst) - memcpy(dst, src + sizeof(int), - srclen ? srclen - sizeof(int) : dstlen); - break; - } - return dstlen; -} - -int init_scrap(void) -{ - SDL_SysWMinfo info; - int retval; - - /* Grab the window manager specific information */ - retval = -1; - SDL_SetError("SDL is not running on known window manager"); - - SDL_VERSION(&info.version); - //FIXMEif (SDL_GetWMInfo(&info)) - { - /* Save the information for later use */ -#if defined(X11_SCRAP) - if (info.subsystem == SDL_SYSWM_X11) { - SDL_Display = info.info.x11.display; - SDL_Window = info.info.x11.window; - Lock_Display = info.info.x11.lock_func; - Unlock_Display = info.info.x11.unlock_func; - - /* Enable the special window hook events */ - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_SetEventFilter(clipboard_filter); - - XA_TARGETS = XInternAtom(SDL_Display, "TARGETS", False); - XA_TEXT = XInternAtom(SDL_Display, "TEXT", False); - XA_COMPOUND_TEXT = XInternAtom(SDL_Display, - "COMPOUND_TEXT", False); - XA_UTF8_STRING = XInternAtom(SDL_Display, - "UTF8_STRING", False); - - retval = 0; - } - else - SDL_SetError("SDL is not running on X11"); -#elif defined(WIN_SCRAP) - SDL_Window = info.window; - retval = 0; -#elif defined(QNX_SCRAP) - InputGroup = PhInputGroup(NULL); - retval = 0; -#endif /* scrap type */ - } - return(retval); -} - -int lost_scrap(void) -{ - int retval; - -#if defined(X11_SCRAP) - if (Lock_Display) - Lock_Display(); - retval = (XGetSelectionOwner(SDL_Display, XA_PRIMARY) != SDL_Window); - if (Unlock_Display) - Unlock_Display(); -#elif defined(WIN_SCRAP) - retval = (GetClipboardOwner() != SDL_Window); -#elif defined(QNX_SCRAP) - retval = (PhInputGroup(NULL) != InputGroup); -#endif /* scrap type */ - - return(retval); -} - -void put_scrap(int type, int srclen, const char *src) -{ - scrap_type format; - int dstlen; - char *dst; - - format = convert_format(type); - dstlen = convert_data(type, NULL, src, srclen); - -#if defined(X11_SCRAP) - dst = (char *)malloc(dstlen); - if (dst != NULL) { - if (Lock_Display) - Lock_Display(); - convert_data(type, dst, src, srclen); - XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), - XA_CUT_BUFFER0, format, 8, PropModeReplace, - (unsigned char *)dst, dstlen); - free(dst); - if (lost_scrap()) - XSetSelectionOwner(SDL_Display, XA_PRIMARY, - SDL_Window, CurrentTime); - if (Unlock_Display) - Unlock_Display(); - } -#elif defined(WIN_SCRAP) - if (OpenClipboard(SDL_Window)) { - HANDLE hMem; - - hMem = GlobalAlloc((GMEM_MOVEABLE|GMEM_DDESHARE), dstlen); - if (hMem != NULL) { - dst = (char *)GlobalLock(hMem); - convert_data(type, dst, src, srclen); - GlobalUnlock(hMem); - EmptyClipboard(); - SetClipboardData(format, hMem); - } - CloseClipboard(); - } -#elif defined(QNX_SCRAP) -#if (_NTO_VERSION < 620) /* before 6.2.0 releases */ -#define PhClipboardHdr PhClipHeader -#endif - { - PhClipboardHdr clheader = { Ph_CLIPBOARD_TYPE_TEXT, 0, NULL }; - int* cldata; - int status; - - dst = (char *)malloc(dstlen+4); - if (dst != NULL) { - cldata = (int*)dst; - *cldata = type; - convert_data(type, dst+4, src, srclen); - clheader.data = dst; -#if (_NTO_VERSION < 620) /* before 6.2.0 releases */ - if (dstlen > 65535) - /* maximum photon clipboard size :(*/ - clheader.length = 65535; - else -#endif - clheader.length = dstlen+4; - status = PhClipboardCopy(InputGroup, 1, &clheader); - if (status == -1) - fprintf(stderr, - "Photon: copy to clipboard failed!\n"); - free(dst); - } - } -#endif /* scrap type */ -} - -void get_scrap(int type, int *dstlen, char **dst) -{ - scrap_type format; - - *dstlen = 0; - format = convert_format(type); - -#if defined(X11_SCRAP) - { - Window owner; - Atom selection; - Atom seln_type; - int seln_format; - unsigned long nbytes; - unsigned long overflow; - char *src; - - if (Lock_Display) - Lock_Display(); - owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY); - if (Unlock_Display) - Unlock_Display(); - if ((owner == None) || (owner == SDL_Window)) { - owner = DefaultRootWindow(SDL_Display); - selection = XA_CUT_BUFFER0; - } - else { - int selection_response = 0; - SDL_Event event; - - owner = SDL_Window; - if (Lock_Display) - Lock_Display(); - selection = XInternAtom(SDL_Display, "SDL_SELECTION", - False); - XConvertSelection(SDL_Display, XA_PRIMARY, format, - selection, owner, CurrentTime); - if (Unlock_Display) - Unlock_Display(); - while (!selection_response) { - SDL_WaitEvent(&event); - if (event.type == SDL_SYSWMEVENT) { - XEvent xevent = - event.syswm.msg->event.xevent; - - if ((xevent.type == SelectionNotify) && - (xevent.xselection.requestor - == owner)) - selection_response = 1; - } - } - } - if (Lock_Display) - Lock_Display(); - if (XGetWindowProperty(SDL_Display, owner, selection, - 0, INT_MAX/4, False, format, &seln_type, - &seln_format, &nbytes, &overflow, - (unsigned char **)&src) == Success) { - if (seln_type == format) { - *dstlen = convert_scrap(type, NULL, - src, nbytes); - *dst = (char *)realloc(*dst, *dstlen); - if (*dst == NULL) - *dstlen = 0; - else - convert_scrap(type, *dst, src, nbytes); - } - XFree(src); - } - } - if (Unlock_Display) - Unlock_Display(); -#elif defined(WIN_SCRAP) - if (IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window)) { - HANDLE hMem; - char *src; - - hMem = GetClipboardData(format); - if (hMem != NULL) { - src = (char *)GlobalLock(hMem); - *dstlen = convert_scrap(type, NULL, src, 0); - *dst = (char *)realloc(*dst, *dstlen); - if (*dst == NULL) - *dstlen = 0; - else - convert_scrap(type, *dst, src, 0); - GlobalUnlock(hMem); - } - CloseClipboard(); - } -#elif defined(QNX_SCRAP) -#if (_NTO_VERSION < 620) /* before 6.2.0 releases */ - { - void* clhandle; - PhClipHeader* clheader; - int* cldata; - - clhandle = PhClipboardPasteStart(InputGroup); - if (clhandle != NULL) { - clheader = PhClipboardPasteType(clhandle, - Ph_CLIPBOARD_TYPE_TEXT); - if (clheader != NULL) { - cldata = clheader->data; - if ((clheader->length>4) && (*cldata == type)) { - *dstlen = convert_scrap(type, NULL, - (char*)clheader->data+4, - clheader->length-4); - *dst = (char *)realloc(*dst, *dstlen); - if (*dst == NULL) - *dstlen = 0; - else - convert_scrap(type, *dst, - (char*)clheader->data+4, - clheader->length-4); - } - } - PhClipboardPasteFinish(clhandle); - } - } -#else /* 6.2.0 and 6.2.1 and future releases */ - { - void* clhandle; - PhClipboardHdr* clheader; - int* cldata; - - clheader=PhClipboardRead(InputGroup, Ph_CLIPBOARD_TYPE_TEXT); - if (clheader!=NULL) { - cldata=clheader->data; - if ((clheader->length>4) && (*cldata==type)) { - *dstlen = convert_scrap(type, NULL, - (char*)clheader->data+4, - clheader->length-4); - *dst = (char *)realloc(*dst, *dstlen); - if (*dst == NULL) - *dstlen = 0; - else - convert_scrap(type, *dst, - (char*)clheader->data+4, - clheader->length-4); - } - } - } -#endif -#endif /* scrap type */ -} - -int clipboard_filter(const SDL_Event *event) -{ -#if defined(X11_SCRAP) - /* Post all non-window manager specific events */ - if (event->type != SDL_SYSWMEVENT) - return(1); - - /* Handle window-manager specific clipboard events */ - switch (event->syswm.msg->event.xevent.type) { - /* Copy the selection from XA_CUT_BUFFER0 to the requested property */ - case SelectionRequest: { - XSelectionRequestEvent *req; - XEvent sevent; - int seln_format; - unsigned long nbytes; - unsigned long overflow; - unsigned char *seln_data; - - req = &event->syswm.msg->event.xevent.xselectionrequest; - if (req->target == XA_TARGETS) { - Atom supported[] = { - XA_TEXT, XA_COMPOUND_TEXT, XA_UTF8_STRING, - XA_TARGETS, XA_STRING - }; - XEvent response; - - XChangeProperty(SDL_Display, req->requestor, - req->property, req->target, 32, PropModeReplace, - (unsigned char*)supported, - sizeof(supported) / sizeof(supported[0])); - response.xselection.property=None; - response.xselection.type= SelectionNotify; - response.xselection.display= req->display; - response.xselection.requestor= req->requestor; - response.xselection.selection=req->selection; - response.xselection.target= req->target; - response.xselection.time = req->time; - XSendEvent (SDL_Display, req->requestor,0,0,&response); - XFlush (SDL_Display); - return 1; - } - - sevent.xselection.type = SelectionNotify; - sevent.xselection.display = req->display; - sevent.xselection.selection = req->selection; - sevent.xselection.target = None; - sevent.xselection.property = req->property; - sevent.xselection.requestor = req->requestor; - sevent.xselection.time = req->time; - if (XGetWindowProperty(SDL_Display, - DefaultRootWindow(SDL_Display), XA_CUT_BUFFER0, - 0, INT_MAX/4, False, req->target, - &sevent.xselection.target, &seln_format, - &nbytes, &overflow, &seln_data) == Success) { - if (sevent.xselection.target == req->target) { - if (sevent.xselection.target == XA_STRING && - nbytes > 0 && - seln_data[nbytes-1] == '\0') - --nbytes; - XChangeProperty(SDL_Display, req->requestor, - req->property, sevent.xselection.target, - seln_format, PropModeReplace, - seln_data, nbytes); - sevent.xselection.property = req->property; - } - XFree(seln_data); - } - XSendEvent(SDL_Display,req->requestor,False,0,&sevent); - XSync(SDL_Display, False); - break; - } - } - /* Post the event for X11 clipboard reading above */ -#endif /* X11_SCRAP */ - return(1); -} diff --git a/client_examples/scrap.h b/client_examples/scrap.h deleted file mode 100644 index 647bd74..0000000 --- a/client_examples/scrap.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Handle clipboard text and data in arbitrary formats */ - -/* Miscellaneous defines */ -#define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0)) - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -extern int init_scrap(void); -extern int lost_scrap(void); -extern void put_scrap(int type, int srclen, const char *src); -extern void get_scrap(int type, int *dstlen, char **dst); -extern int clipboard_filter(const SDL_Event *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -- cgit v1.2.3 From c562ed4b99c0c077bde9be376911932b6c93a07e Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Thu, 26 Jul 2018 11:33:11 +0200 Subject: SDLvncviewer: remove obsolete video scaling code --- client_examples/SDLvncviewer.c | 129 ----------------------------------------- 1 file changed, 129 deletions(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index ff0543c..da07622 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -17,8 +17,6 @@ struct { int sdl; int rfb; } buttonMapping[]={ static int enableResizable = 1, viewOnly, listenLoop, buttonMask; int sdlFlags; -static int realWidth, realHeight, bytesPerPixel, rowStride; -static char *sdlPixels; SDL_Texture *sdlTexture; SDL_Renderer *sdlRenderer; SDL_Window *sdlWindow; @@ -47,10 +45,6 @@ static rfbBool resize(rfbClient* client) { rfbClientSetClientData(client, SDL_Init, sdl); client->width = sdl->pitch / (depth / 8); - if (sdlPixels) { - free(client->frameBuffer); - sdlPixels = NULL; - } client->frameBuffer=sdl->pixels; client->format.bitsPerPixel=depth; @@ -192,78 +186,7 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { return k; } -static uint32_t get(rfbClient *cl, int x, int y) -{ - switch (bytesPerPixel) { - case 1: return ((uint8_t *)cl->frameBuffer)[x + y * cl->width]; - case 2: return ((uint16_t *)cl->frameBuffer)[x + y * cl->width]; - case 4: return ((uint32_t *)cl->frameBuffer)[x + y * cl->width]; - default: - rfbClientErr("Unknown bytes/pixel: %d", bytesPerPixel); - exit(1); - } -} - -static void put(int x, int y, uint32_t v) -{ - switch (bytesPerPixel) { - case 1: ((uint8_t *)sdlPixels)[x + y * rowStride] = v; break; - case 2: ((uint16_t *)sdlPixels)[x + y * rowStride] = v; break; - case 4: ((uint32_t *)sdlPixels)[x + y * rowStride] = v; break; - default: - rfbClientErr("Unknown bytes/pixel: %d", bytesPerPixel); - exit(1); - } -} - -static void resizeRectangleToReal(rfbClient *cl, int x, int y, int w, int h) -{ - int i0 = x * realWidth / cl->width; - int i1 = ((x + w) * realWidth - 1) / cl->width + 1; - int j0 = y * realHeight / cl->height; - int j1 = ((y + h) * realHeight - 1) / cl->height + 1; - int i, j; - - for (j = j0; j < j1; j++) - for (i = i0; i < i1; i++) { - int x0 = i * cl->width / realWidth; - int x1 = ((i + 1) * cl->width - 1) / realWidth + 1; - int y0 = j * cl->height / realHeight; - int y1 = ((j + 1) * cl->height - 1) / realHeight + 1; - uint32_t r = 0, g = 0, b = 0; - - for (y = y0; y < y1; y++) - for (x = x0; x < x1; x++) { - uint32_t v = get(cl, x, y); -#define REDSHIFT cl->format.redShift -#define REDMAX cl->format.redMax -#define GREENSHIFT cl->format.greenShift -#define GREENMAX cl->format.greenMax -#define BLUESHIFT cl->format.blueShift -#define BLUEMAX cl->format.blueMax - r += (v >> REDSHIFT) & REDMAX; - g += (v >> GREENSHIFT) & GREENMAX; - b += (v >> BLUESHIFT) & BLUEMAX; - } - r /= (x1 - x0) * (y1 - y0); - g /= (x1 - x0) * (y1 - y0); - b /= (x1 - x0) * (y1 - y0); - - put(i, j, (r << REDSHIFT) | (g << GREENSHIFT) | - (b << BLUESHIFT)); - } -} - static void update(rfbClient* cl,int x,int y,int w,int h) { - if (sdlPixels) { - resizeRectangleToReal(cl, x, y, w, h); - w = ((x + w) * realWidth - 1) / cl->width + 1; - h = ((y + h) * realHeight - 1) / cl->height + 1; - x = x * realWidth / cl->width; - y = y * realHeight / cl->height; - w -= x; - h -= y; - } SDL_Surface *sdl = rfbClientGetClientData(cl, SDL_Init); /* update texture from surface->pixels */ SDL_Rect r = {x,y,w,h}; @@ -277,49 +200,6 @@ static void update(rfbClient* cl,int x,int y,int w,int h) { SDL_RenderPresent(sdlRenderer); } -static void setRealDimension(rfbClient *client, int w, int h) -{ - SDL_Surface* sdl; - /*FIXME - if (w < 0) { - const SDL_VideoInfo *info = SDL_GetVideoInfo(); - w = info->current_h; - h = info->current_w; - } - */ - if (w == realWidth && h == realHeight) - return; - - if (!sdlPixels) { - int size; - - sdlPixels = (char *)client->frameBuffer; - rowStride = client->width; - - bytesPerPixel = client->format.bitsPerPixel / 8; - size = client->width * bytesPerPixel * client->height; - client->frameBuffer = malloc(size); - if (!client->frameBuffer) { - rfbClientErr("Could not allocate %d bytes", size); - exit(1); - } - memcpy(client->frameBuffer, sdlPixels, size); - } - - sdl = rfbClientGetClientData(client, SDL_Init); - if (sdl->w != w || sdl->h != h) { - int depth = sdl->format->BitsPerPixel; - //FIXMEsdl = SDL_SetVideoMode(w, h, depth, sdlFlags); - rfbClientSetClientData(client, SDL_Init, sdl); - sdlPixels = sdl->pixels; - rowStride = sdl->pitch / (depth / 8); - } - - realWidth = w; - realHeight = h; - update(client, 0, 0, client->width, client->height); -} - static void kbd_leds(rfbClient* cl, int value, int pad) { /* note: pad is for future expansion 0=unused */ fprintf(stderr,"Led State= 0x%02X\n", value); @@ -460,10 +340,6 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) break; } } - if (sdlPixels) { - x = x * cl->width / realWidth; - y = y * cl->height / realHeight; - } SendPointerEvent(cl, x, y, buttonMask); buttonMask &= ~(rfbButton4Mask | rfbButton5Mask); break; @@ -493,11 +369,6 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) rfbClientCleanup(cl); exit(0); } - /*FIXME - case SDL_VIDEORESIZE: - setRealDimension(cl, e->resize.w, e->resize.h); - break; - */ default: rfbClientLog("ignore SDL event: 0x%x\n", e->type); } -- cgit v1.2.3 From a2b5284e077b2905656ee77675d8b8949df0497c Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Sat, 28 Jul 2018 14:17:56 +0200 Subject: SDLvncviewer: implement Unicode input handling --- client_examples/SDLvncviewer.c | 46 ++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index da07622..9c509b0 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -15,6 +15,15 @@ struct { int sdl; int rfb; } buttonMapping[]={ {0,0} }; +struct { char mask; int bits_stored; } utf8Mapping[]= { + {0b00111111, 6}, + {0b01111111, 7}, + {0b00011111, 5}, + {0b00001111, 4}, + {0b00000111, 3}, + {0,0} +}; + static int enableResizable = 1, viewOnly, listenLoop, buttonMask; int sdlFlags; SDL_Texture *sdlTexture; @@ -102,7 +111,6 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_RETURN: k = XK_Return; break; case SDLK_PAUSE: k = XK_Pause; break; case SDLK_ESCAPE: k = XK_Escape; break; - case SDLK_SPACE: k = XK_space; break; case SDLK_DELETE: k = XK_Delete; break; case SDLK_KP_0: k = XK_KP_0; break; case SDLK_KP_1: k = XK_KP_1; break; @@ -165,27 +173,21 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_SYSREQ: k = XK_Sys_Req; break; default: break; } - // 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; - } - } - /*TODO: try out SDL_TEXTINPUT for unicode input - if (k == 0) { - if (e->keysym.unicode < 0x100) - k = e->keysym.unicode; - else - rfbClientLog("Unknown keysym: %d\n", sym); - } - */ return k; } +/* UTF-8 decoding is from https://rosettacode.org/wiki/UTF-8_encode_and_decode which is under GFDL 1.2 */ +static rfbKeySym utf8char2rfbKeySym(const char chr[4]) { + int bytes = strlen(chr); + int shift = utf8Mapping[0].bits_stored * (bytes - 1); + rfbKeySym codep = (*chr++ & utf8Mapping[bytes].mask) << shift; + for(int i = 1; i < bytes; ++i, ++chr) { + shift -= utf8Mapping[0].bits_stored; + codep |= ((char)*chr & utf8Mapping[0].mask) << shift; + } + return codep; +} + static void update(rfbClient* cl,int x,int y,int w,int h) { SDL_Surface *sdl = rfbClientGetClientData(cl, SDL_Init); /* update texture from surface->pixels */ @@ -356,7 +358,11 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) leftAltKeyDown = e->type == SDL_KEYDOWN; break; case SDL_TEXTINPUT: - /* TODO: maybe use this for unicode input */ + if (viewOnly) + break; + rfbKeySym sym = utf8char2rfbKeySym(e->text.text); + SendKeyEvent(cl, sym, TRUE); + SendKeyEvent(cl, sym, FALSE); break; case SDL_QUIT: if(listenLoop) -- cgit v1.2.3 From b0957702a88e6547ecca252165cef4a653239fec Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Sat, 28 Jul 2018 14:23:19 +0200 Subject: SDLvncviewer: adhere to C89 --- client_examples/SDLvncviewer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 9c509b0..67820a8 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -181,7 +181,8 @@ static rfbKeySym utf8char2rfbKeySym(const char chr[4]) { int bytes = strlen(chr); int shift = utf8Mapping[0].bits_stored * (bytes - 1); rfbKeySym codep = (*chr++ & utf8Mapping[bytes].mask) << shift; - for(int i = 1; i < bytes; ++i, ++chr) { + int i; + for(i = 1; i < bytes; ++i, ++chr) { shift -= utf8Mapping[0].bits_stored; codep |= ((char)*chr & utf8Mapping[0].mask) << shift; } -- cgit v1.2.3 From 97c9b6c5d7959df3ea18c397a01db2b266ce204a Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Mon, 30 Jul 2018 18:58:28 +0200 Subject: SDLvncviewer: handle mouse wheel events --- client_examples/SDLvncviewer.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index 67820a8..e2d4357 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -29,6 +29,8 @@ int sdlFlags; SDL_Texture *sdlTexture; SDL_Renderer *sdlRenderer; SDL_Window *sdlWindow; +/* client's pointer position */ +int x,y; static int rightAltKeyDown, leftAltKeyDown; @@ -316,11 +318,39 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) break; } break; + case SDL_MOUSEWHEEL: + { + int steps; + if (viewOnly) + break; + + if(e->wheel.y > 0) + for(steps = 0; steps < e->wheel.y; ++steps) { + SendPointerEvent(cl, x, y, rfbButton4Mask); + SendPointerEvent(cl, x, y, 0); + } + if(e->wheel.y < 0) + for(steps = 0; steps > e->wheel.y; --steps) { + SendPointerEvent(cl, x, y, rfbButton5Mask); + SendPointerEvent(cl, x, y, 0); + } + if(e->wheel.x > 0) + for(steps = 0; steps < e->wheel.x; ++steps) { + SendPointerEvent(cl, x, y, 0b01000000); + SendPointerEvent(cl, x, y, 0); + } + if(e->wheel.x < 0) + for(steps = 0; steps > e->wheel.x; --steps) { + SendPointerEvent(cl, x, y, 0b00100000); + SendPointerEvent(cl, x, y, 0); + } + break; + } case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: { - int x, y, state, i; + int state, i; if (viewOnly) break; -- cgit v1.2.3 From 474f64e5db23ccd14b2a281b4076be081297d110 Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Mon, 30 Jul 2018 19:47:26 +0200 Subject: SDLvncviewer: work around SDL_TEXTINPUT not generating chars with CTRL down --- client_examples/SDLvncviewer.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'client_examples/SDLvncviewer.c') diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c index e2d4357..d17b74e 100644 --- a/client_examples/SDLvncviewer.c +++ b/client_examples/SDLvncviewer.c @@ -175,6 +175,10 @@ static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) { case SDLK_SYSREQ: k = XK_Sys_Req; break; default: break; } + /* SDL_TEXTINPUT does not generate characters if ctrl is down, so handle those here */ + if (k == 0 && sym > 0x0 && sym < 0x100 && e->keysym.mod & KMOD_CTRL) + k = sym; + return k; } -- cgit v1.2.3