@@ -42,9 +42,6 @@ static rfbBool resize(rfbClient* client) {
4242 if (enableResizable )
4343 sdlFlags |= SDL_WINDOW_RESIZABLE ;
4444
45- client -> updateRect .x = client -> updateRect .y = 0 ;
46- client -> updateRect .w = width ; client -> updateRect .h = height ;
47-
4845 /* (re)create the surface used as the client's framebuffer */
4946 SDL_FreeSurface (rfbClientGetClientData (client , SDL_Init ));
5047 SDL_Surface * sdl = SDL_CreateRGBSurface (0 ,
@@ -307,7 +304,8 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e)
307304 char * text = SDL_GetClipboardText ();
308305 if (text ) {
309306 rfbClientLog ("sending clipboard text '%s'\n" , text );
310- SendClientCutText (cl , text , strlen (text ));
307+ if (!SendClientCutTextUTF8 (cl , text , strlen (text )))
308+ SendClientCutText (cl , text , strlen (text ));
311309 }
312310 }
313311
@@ -420,18 +418,37 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e)
420418 return TRUE;
421419}
422420
423- static void got_selection (rfbClient * cl , const char * text , int len )
421+ static void got_selection_latin1 (rfbClient * cl , const char * text , int len )
424422{
425- rfbClientLog ("received clipboard text '%s'\n" , text );
423+ rfbClientLog ("received latin1 clipboard text '%s'\n" , text );
426424 if (SDL_SetClipboardText (text ) != 0 )
427- rfbClientErr ("could not set received clipboard text: %s\n" , SDL_GetError ());
425+ rfbClientErr ("could not set received latin1 clipboard text: %s\n" , SDL_GetError ());
426+ }
427+
428+ static void got_selection_utf8 (rfbClient * cl , const char * buf , int len )
429+ {
430+ rfbClientLog ("received utf8 clipboard text '%s'\n" , buf );
431+ if (SDL_SetClipboardText (buf ) != 0 )
432+ rfbClientErr ("could not set received utf8 clipboard text: %s\n" , SDL_GetError ());
428433}
429434
430435
431436static rfbCredential * get_credential (rfbClient * cl , int credentialType ){
432- rfbCredential * c = malloc (sizeof (rfbCredential ));
437+ rfbCredential * c = malloc (sizeof (rfbCredential ));
438+ if (!c ) {
439+ return NULL ;
440+ }
433441 c -> userCredential .username = malloc (RFB_BUF_SIZE );
442+ if (!c -> userCredential .username ) {
443+ free (c );
444+ return NULL ;
445+ }
434446 c -> userCredential .password = malloc (RFB_BUF_SIZE );
447+ if (!c -> userCredential .password ) {
448+ free (c -> userCredential .username );
449+ free (c );
450+ return NULL ;
451+ }
435452
436453 if (credentialType != rfbCredentialTypeUser ) {
437454 rfbClientErr ("something else than username and password required for authentication\n" );
@@ -496,7 +513,11 @@ int main(int argc,char** argv) {
496513 cl -> GotFrameBufferUpdate = update ;
497514 cl -> HandleKeyboardLedState = kbd_leds ;
498515 cl -> HandleTextChat = text_chat ;
499- cl -> GotXCutText = got_selection ;
516+ /* two different cut text handlers here for demo purposes, you
517+ might as well use the same callback for both if it doesn't
518+ matter for your application */
519+ cl -> GotXCutText = got_selection_latin1 ;
520+ cl -> GotXCutTextUTF8 = got_selection_utf8 ;
500521 cl -> GetCredential = get_credential ;
501522 cl -> listenPort = LISTEN_PORT_OFFSET ;
502523 cl -> listen6Port = LISTEN_PORT_OFFSET ;
0 commit comments