X11: Fixed SelectionRequest replies for target TARGETS.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 04 Jun 2015 15:41:39 -0400
changeset 9706 92472fcca43f
parent 9705 f037dd7d7cc9
child 9707 5ca9f59ab336
X11: Fixed SelectionRequest replies for target TARGETS. Fixes Google Chrome, etc, freezing up when SDL owns the clipboard selection and actually sends thems the correct text for pasting. Confirmed working with Unicode strings in UTF-8 format. There were a few tweaks in this patch, but the specific fix is that event.xselection.target in the SelectionNotify event we send back in reply must be set to the same atom as the request ("TARGETS" in this case), and we failed to do that in this special case. Things that don't ask for a target, like the Gnome Terminal app, worked fine because they don't ask for TARGETS and just go right to asking for a UTF8_STRING, and Mozilla apparently just was more liberal in what they accepted in reply. Chrome would reject our wrong reply and freeze up waiting for a valid one. Someone should fix that in Chrome, too. :) Fixes Bugzilla #2926.
--- a/src/video/x11/SDL_x11events.c	Thu Jun 04 10:59:02 2015 -0400
+++ b/src/video/x11/SDL_x11events.c	Thu Jun 04 15:41:39 2015 -0400
@@ -1189,6 +1189,7 @@
             sevent.xselection.property = None;
             sevent.xselection.requestor = req->requestor;
             sevent.xselection.time = req->time;
             if (X11_XGetWindowProperty(display, DefaultRootWindow(display),
                     X11_GetSDLCutBufferClipboardType(display), 0, INT_MAX/4, False, req->target,
                     &sevent.xselection.target, &seln_format, &nbytes,
@@ -1200,12 +1201,13 @@
                         seln_data, nbytes);
                     sevent.xselection.property = req->property;
                 } else if (XA_TARGETS == req->target) {
-                    Atom SupportedFormats[] = { sevent.xselection.target, XA_TARGETS };
+                    Atom SupportedFormats[] = { XA_TARGETS, sevent.xselection.target };
                     X11_XChangeProperty(display, req->requestor, req->property,
                         XA_ATOM, 32, PropModeReplace,
                         (unsigned char*)SupportedFormats,
-                        sizeof(SupportedFormats)/sizeof(*SupportedFormats));
+                        SDL_arraysize(SupportedFormats));
                     sevent.xselection.property = req->property;
+                    sevent.xselection.target = XA_TARGETS;