src/video/x11/SDL_x11clipboard.c
changeset 9578 e78393ffcd50
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
     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;