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 9578e78393ffcd50
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
     1.1 --- a/src/video/x11/SDL_x11clipboard.c	Sun Apr 26 20:46:07 2015 -0700
     1.2 +++ b/src/video/x11/SDL_x11clipboard.c	Sun Apr 26 13:53:46 2015 +0300
     1.3 @@ -49,6 +49,14 @@
     1.4      return None;
     1.5  }
     1.6  
     1.7 +/* We use our own cut-buffer for intermediate storage instead of  
     1.8 +   XA_CUT_BUFFER0 because their use isn't really defined for holding UTF8. */ 
     1.9 +Atom
    1.10 +X11_GetSDLCutBufferClipboardType(Display *display)
    1.11 +{
    1.12 +    return X11_XInternAtom(display, "SDL_CUTBUFFER", False);
    1.13 +}
    1.14 +
    1.15  int
    1.16  X11_SetClipboardText(_THIS, const char *text)
    1.17  {
    1.18 @@ -66,7 +74,7 @@
    1.19      /* Save the selection on the root window */
    1.20      format = TEXT_FORMAT;
    1.21      X11_XChangeProperty(display, DefaultRootWindow(display),
    1.22 -        XA_CUT_BUFFER0, format, 8, PropModeReplace,
    1.23 +        X11_GetSDLCutBufferClipboardType(display), format, 8, PropModeReplace,
    1.24          (const unsigned char *)text, SDL_strlen(text));
    1.25  
    1.26      if (XA_CLIPBOARD != None &&
    1.27 @@ -109,9 +117,14 @@
    1.28      window = GetWindow(_this);
    1.29      format = TEXT_FORMAT;
    1.30      owner = X11_XGetSelectionOwner(display, XA_CLIPBOARD);
    1.31 -    if ((owner == None) || (owner == window)) {
    1.32 +    if (owner == None) {
    1.33 +        /* Fall back to ancient X10 cut-buffers which do not support UTF8 strings*/
    1.34          owner = DefaultRootWindow(display);
    1.35          selection = XA_CUT_BUFFER0;
    1.36 +        format = XA_STRING;
    1.37 +    } else if (owner == window) {
    1.38 +        owner = DefaultRootWindow(display);
    1.39 +        selection = X11_GetSDLCutBufferClipboardType(display);
    1.40      } else {
    1.41          /* Request that the selection owner copy the data to our window */
    1.42          owner = window;
     2.1 --- a/src/video/x11/SDL_x11clipboard.h	Sun Apr 26 20:46:07 2015 -0700
     2.2 +++ b/src/video/x11/SDL_x11clipboard.h	Sun Apr 26 13:53:46 2015 +0300
     2.3 @@ -26,6 +26,7 @@
     2.4  extern int X11_SetClipboardText(_THIS, const char *text);
     2.5  extern char *X11_GetClipboardText(_THIS);
     2.6  extern SDL_bool X11_HasClipboardText(_THIS);
     2.7 +extern Atom X11_GetSDLCutBufferClipboardType(Display *display);
     2.8  
     2.9  #endif /* _SDL_x11clipboard_h */
    2.10  
     3.1 --- a/src/video/x11/SDL_x11events.c	Sun Apr 26 20:46:07 2015 -0700
     3.2 +++ b/src/video/x11/SDL_x11events.c	Sun Apr 26 13:53:46 2015 +0300
     3.3 @@ -1106,7 +1106,7 @@
     3.4          }
     3.5          break;
     3.6  
     3.7 -    /* Copy the selection from XA_CUT_BUFFER0 to the requested property */
     3.8 +    /* Copy the selection from our own CUTBUFFER to the requested property */
     3.9      case SelectionRequest: {
    3.10              XSelectionRequestEvent *req;
    3.11              XEvent sevent;
    3.12 @@ -1129,7 +1129,7 @@
    3.13              sevent.xselection.requestor = req->requestor;
    3.14              sevent.xselection.time = req->time;
    3.15              if (X11_XGetWindowProperty(display, DefaultRootWindow(display),
    3.16 -                    XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
    3.17 +                    X11_GetSDLCutBufferClipboardType(display), 0, INT_MAX/4, False, req->target,
    3.18                      &sevent.xselection.target, &seln_format, &nbytes,
    3.19                      &overflow, &seln_data) == Success) {
    3.20                  Atom XA_TARGETS = X11_XInternAtom(display, "TARGETS", 0);