Skip to content

Commit

Permalink
X11: Use our own cut-buffer for intermediate clipboard storage.
Browse files Browse the repository at this point in the history
XA_CUTBUFFER0 is not defined for holding UTF8 strings.
  • Loading branch information
zenios committed Apr 26, 2015
1 parent 93bd476 commit d9d1a1b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/video/x11/SDL_x11clipboard.c
Expand Up @@ -49,6 +49,14 @@ GetWindow(_THIS)
return None;
}

/* We use our own cut-buffer for intermediate storage instead of
XA_CUT_BUFFER0 because their use isn't really defined for holding UTF8. */
Atom
X11_GetSDLCutBufferClipboardType(Display *display)
{
return X11_XInternAtom(display, "SDL_CUTBUFFER", False);
}

int
X11_SetClipboardText(_THIS, const char *text)
{
Expand All @@ -66,7 +74,7 @@ X11_SetClipboardText(_THIS, const char *text)
/* Save the selection on the root window */
format = TEXT_FORMAT;
X11_XChangeProperty(display, DefaultRootWindow(display),
XA_CUT_BUFFER0, format, 8, PropModeReplace,
X11_GetSDLCutBufferClipboardType(display), format, 8, PropModeReplace,
(const unsigned char *)text, SDL_strlen(text));

if (XA_CLIPBOARD != None &&
Expand Down Expand Up @@ -109,9 +117,14 @@ X11_GetClipboardText(_THIS)
window = GetWindow(_this);
format = TEXT_FORMAT;
owner = X11_XGetSelectionOwner(display, XA_CLIPBOARD);
if ((owner == None) || (owner == window)) {
if (owner == None) {
/* Fall back to ancient X10 cut-buffers which do not support UTF8 strings*/
owner = DefaultRootWindow(display);
selection = XA_CUT_BUFFER0;
format = XA_STRING;
} else if (owner == window) {
owner = DefaultRootWindow(display);
selection = X11_GetSDLCutBufferClipboardType(display);
} else {
/* Request that the selection owner copy the data to our window */
owner = window;
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11clipboard.h
Expand Up @@ -26,6 +26,7 @@
extern int X11_SetClipboardText(_THIS, const char *text);
extern char *X11_GetClipboardText(_THIS);
extern SDL_bool X11_HasClipboardText(_THIS);
extern Atom X11_GetSDLCutBufferClipboardType(Display *display);

#endif /* _SDL_x11clipboard_h */

Expand Down
4 changes: 2 additions & 2 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -1106,7 +1106,7 @@ X11_DispatchEvent(_THIS)
}
break;

/* Copy the selection from XA_CUT_BUFFER0 to the requested property */
/* Copy the selection from our own CUTBUFFER to the requested property */
case SelectionRequest: {
XSelectionRequestEvent *req;
XEvent sevent;
Expand All @@ -1129,7 +1129,7 @@ X11_DispatchEvent(_THIS)
sevent.xselection.requestor = req->requestor;
sevent.xselection.time = req->time;
if (X11_XGetWindowProperty(display, DefaultRootWindow(display),
XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
X11_GetSDLCutBufferClipboardType(display), 0, INT_MAX/4, False, req->target,
&sevent.xselection.target, &seln_format, &nbytes,
&overflow, &seln_data) == Success) {
Atom XA_TARGETS = X11_XInternAtom(display, "TARGETS", 0);
Expand Down

0 comments on commit d9d1a1b

Please sign in to comment.