From: Michael D. Lowis Date: Tue, 31 Jan 2017 17:03:49 +0000 (-0500) Subject: Fixed X11 selection protocol. Now we respond to targets requests instead of ignoring... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=6195839b7b1a6f52ab3e5fa8bccaec23916a8ec5;p=projs%2Ftide.git Fixed X11 selection protocol. Now we respond to targets requests instead of ignoring them --- diff --git a/lib/x11.c b/lib/x11.c index 51919d4..63df657 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -542,17 +542,32 @@ static void selrequest(XEvent* evnt) { XEvent s; struct XSel* sel = selfetch( evnt->xselectionrequest.selection ); s.xselection.type = SelectionNotify; - s.xselection.property = evnt->xselectionrequest.property;; - s.xselection.requestor = evnt->xselectionrequest.requestor;; - s.xselection.selection = evnt->xselectionrequest.selection;; - s.xselection.target = evnt->xselectionrequest.target;; - s.xselection.time = evnt->xselectionrequest.time;; - XChangeProperty(X.display, - s.xselection.requestor, - s.xselection.property, - SelTarget, - 8, PropModeReplace, (unsigned char*)sel->text, strlen(sel->text)); - XSendEvent(X.display, evnt->xselectionrequest.requestor, True, 0, &s); + s.xselection.property = evnt->xselectionrequest.property; + s.xselection.requestor = evnt->xselectionrequest.requestor; + s.xselection.selection = evnt->xselectionrequest.selection; + s.xselection.target = evnt->xselectionrequest.target; + s.xselection.time = evnt->xselectionrequest.time; + + Atom target = evnt->xselectionrequest.target; + Atom xatargets = XInternAtom(X.display, "TARGETS", 0); + Atom xastring = XInternAtom(X.display, "STRING", 0); + if (target == xatargets) { + /* respond with the supported type */ + XChangeProperty( + X.display, + s.xselection.requestor, + s.xselection.property, + XA_ATOM, 32, PropModeReplace, + (unsigned char*)&SelTarget, 1); + } else if (target == SelTarget || target == xastring) { + XChangeProperty( + X.display, + s.xselection.requestor, + s.xselection.property, + SelTarget, 8, PropModeReplace, + (unsigned char*)sel->text, strlen(sel->text)); + } + XSendEvent(X.display, s.xselection.requestor, True, 0, &s); } bool x11_getsel(int selid, void(*cbfn)(char*)) {