X11: Use our own cut-buffer for intermediate clipboard storage.

XA_CUTBUFFER0 is not defined for holding UTF8 strings.
This commit is contained in:
Dimitris Zenios 2015-04-26 13:53:46 +03:00
parent 93bd476de9
commit d9d1a1b980
3 changed files with 18 additions and 4 deletions

View File

@ -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)
{
@ -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 &&
@ -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;

View File

@ -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 */

View File

@ -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;
@ -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);