From 360d05bf72947602523ae5410fa1e96c91be9fb8 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 4 Jun 2015 15:41:39 -0400 Subject: [PATCH] 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 245e3161b2ab2..c73bdc3254b47 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -1189,6 +1189,7 @@ X11_DispatchEvent(_THIS) 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 @@ X11_DispatchEvent(_THIS) 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; } X11_XFree(seln_data); }