X11: Fixed SelectionRequest replies for target TARGETS.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 04 Jun 2015 15:41:39 -0400
changeset 970692472fcca43f
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.
src/video/x11/SDL_x11events.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Thu Jun 04 10:59:02 2015 -0400
     1.2 +++ b/src/video/x11/SDL_x11events.c	Thu Jun 04 15:41:39 2015 -0400
     1.3 @@ -1189,6 +1189,7 @@
     1.4              sevent.xselection.property = None;
     1.5              sevent.xselection.requestor = req->requestor;
     1.6              sevent.xselection.time = req->time;
     1.7 +
     1.8              if (X11_XGetWindowProperty(display, DefaultRootWindow(display),
     1.9                      X11_GetSDLCutBufferClipboardType(display), 0, INT_MAX/4, False, req->target,
    1.10                      &sevent.xselection.target, &seln_format, &nbytes,
    1.11 @@ -1200,12 +1201,13 @@
    1.12                          seln_data, nbytes);
    1.13                      sevent.xselection.property = req->property;
    1.14                  } else if (XA_TARGETS == req->target) {
    1.15 -                    Atom SupportedFormats[] = { sevent.xselection.target, XA_TARGETS };
    1.16 +                    Atom SupportedFormats[] = { XA_TARGETS, sevent.xselection.target };
    1.17                      X11_XChangeProperty(display, req->requestor, req->property,
    1.18                          XA_ATOM, 32, PropModeReplace,
    1.19                          (unsigned char*)SupportedFormats,
    1.20 -                        sizeof(SupportedFormats)/sizeof(*SupportedFormats));
    1.21 +                        SDL_arraysize(SupportedFormats));
    1.22                      sevent.xselection.property = req->property;
    1.23 +                    sevent.xselection.target = XA_TARGETS;
    1.24                  }
    1.25                  X11_XFree(seln_data);
    1.26              }