X11: Use our own cut-buffer for intermediate clipboard storage.
authorDimitris Zenios <dimitris.zenios@gmail.com>
Sun, 26 Apr 2015 13:53:46 +0300
changeset 9578 e78393ffcd50
parent 9577 05445a09a406
child 9579 9a5b4bf6f4d1
X11: Use our own cut-buffer for intermediate clipboard storage. XA_CUTBUFFER0 is not defined for holding UTF8 strings.
src/video/x11/SDL_x11clipboard.c
src/video/x11/SDL_x11clipboard.h
src/video/x11/SDL_x11events.c
--- a/src/video/x11/SDL_x11clipboard.c	Sun Apr 26 20:46:07 2015 -0700
+++ b/src/video/x11/SDL_x11clipboard.c	Sun Apr 26 13:53:46 2015 +0300
@@ -49,6 +49,14 @@
     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 @@
     /* 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 @@
     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;
--- a/src/video/x11/SDL_x11clipboard.h	Sun Apr 26 20:46:07 2015 -0700
+++ b/src/video/x11/SDL_x11clipboard.h	Sun Apr 26 13:53:46 2015 +0300
@@ -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 */
 
--- a/src/video/x11/SDL_x11events.c	Sun Apr 26 20:46:07 2015 -0700
+++ b/src/video/x11/SDL_x11events.c	Sun Apr 26 13:53:46 2015 +0300
@@ -1106,7 +1106,7 @@
         }
         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 @@
             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);