Skip to content

Commit 70b1275

Browse files
committed
examples: wire up utf-8 clipboard handling in SDLVncviewer
1 parent fed2c8b commit 70b1275

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

examples/client/SDLvncviewer.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e)
307307
char *text = SDL_GetClipboardText();
308308
if(text) {
309309
rfbClientLog("sending clipboard text '%s'\n", text);
310-
SendClientCutText(cl, text, strlen(text));
310+
if(!SendClientCutTextUTF8(cl, text, strlen(text)))
311+
SendClientCutText(cl, text, strlen(text));
311312
}
312313
}
313314

@@ -420,11 +421,18 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e)
420421
return TRUE;
421422
}
422423

423-
static void got_selection(rfbClient *cl, const char *text, int len)
424+
static void got_selection_latin1(rfbClient *cl, const char *text, int len)
424425
{
425-
rfbClientLog("received clipboard text '%s'\n", text);
426+
rfbClientLog("received latin1 clipboard text '%s'\n", text);
426427
if(SDL_SetClipboardText(text) != 0)
427-
rfbClientErr("could not set received clipboard text: %s\n", SDL_GetError());
428+
rfbClientErr("could not set received latin1 clipboard text: %s\n", SDL_GetError());
429+
}
430+
431+
static void got_selection_utf8(rfbClient *cl, const char *buf, int len)
432+
{
433+
rfbClientLog("received utf8 clipboard text '%s'\n", buf);
434+
if(SDL_SetClipboardText(buf) != 0)
435+
rfbClientErr("could not set received utf8 clipboard text: %s\n", SDL_GetError());
428436
}
429437

430438

@@ -496,7 +504,11 @@ int main(int argc,char** argv) {
496504
cl->GotFrameBufferUpdate=update;
497505
cl->HandleKeyboardLedState=kbd_leds;
498506
cl->HandleTextChat=text_chat;
499-
cl->GotXCutText = got_selection;
507+
/* two different cut text handlers here for demo purposes, you
508+
might as well use the same callback for both if it doesn't
509+
matter for your application */
510+
cl->GotXCutText = got_selection_latin1;
511+
cl->GotXCutTextUTF8 = got_selection_utf8;
500512
cl->GetCredential = get_credential;
501513
cl->listenPort = LISTEN_PORT_OFFSET;
502514
cl->listen6Port = LISTEN_PORT_OFFSET;

0 commit comments

Comments
 (0)