From d9d1a1b9803dcfc8396c6bfd078bce2be67d3d2b Mon Sep 17 00:00:00 2001 From: Dimitris Zenios Date: Sun, 26 Apr 2015 13:53:46 +0300 Subject: [PATCH] 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 | 17 +++++++++++++++-- src/video/x11/SDL_x11clipboard.h | 1 + src/video/x11/SDL_x11events.c | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index 2999d9837e444..45c8349f477f8 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -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; diff --git a/src/video/x11/SDL_x11clipboard.h b/src/video/x11/SDL_x11clipboard.h index 46291cf608cdf..fe6c85075435d 100644 --- a/src/video/x11/SDL_x11clipboard.h +++ b/src/video/x11/SDL_x11clipboard.h @@ -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 */ diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index e5a9c2848feb1..f0f6d685da94c 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -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);