From 0223fb747477e30892c39506145363c536e5d03f Mon Sep 17 00:00:00 2001 From: Ingo Krabbe Date: Mon, 14 Sep 2020 22:36:18 +0200 Subject: [PATCH] detailed documentation in x11-selection-mod.h --- src/cmd/devdraw/x11-screen.c | 13 +------------ src/cmd/devdraw/x11-selection-mod.h | 27 +++++++++++++++++++++------ src/cmd/snarfer/snarfer.c | 21 +++------------------ 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/cmd/devdraw/x11-screen.c b/src/cmd/devdraw/x11-screen.c index 1951d6b2..6225698f 100644 --- a/src/cmd/devdraw/x11-screen.c +++ b/src/cmd/devdraw/x11-screen.c @@ -1576,23 +1576,12 @@ __xputsnarf(char *data) static int _xselect(XEvent *e) { - char *name; XEvent r; XSelectionRequestEvent *xe; - Atom a[4]; memset(&r, 0, sizeof r); xe = (XSelectionRequestEvent*)e; -if(0) fprint(2, "xselect target=%d requestor=%d property=%d selection=%d (sizeof atom=%d)\n", - xe->target, xe->requestor, xe->property, xe->selection, sizeof a[0]); - MODIFY_SELECTION(name, xe) { - name = XGetAtomName(_x.display, xe->target); - if(strcmp(name, "TIMESTAMP") != 0) - fprint(2, "%s: cannot handle selection request for '%s' (%d)\n", - argv0, name, (int)xe->target); - r.xselection.property = None; - } - if (name) XFree(name); + MODIFY_SELECTION(xe); r.xselection.display = xe->display; /* r.xselection.property filled above */ r.xselection.target = xe->target; diff --git a/src/cmd/devdraw/x11-selection-mod.h b/src/cmd/devdraw/x11-selection-mod.h index 9acfd635..1189649d 100644 --- a/src/cmd/devdraw/x11-selection-mod.h +++ b/src/cmd/devdraw/x11-selection-mod.h @@ -1,7 +1,16 @@ -/* a few snippets for selections */ -#define MODIFY_SELECTION(name, xe) \ +/* I found such code in snarfer and in devdraw, so I moved it into this + definition: MODIFY_SELECTION, that works for both functions + x11-screen.c:/^_xselect/ and ../snarfer/snarfer.c:/^xselectionrequest/ + This removes annoying "cannot handle selection requests" for types + 'text/plain;charset=UTF-8' and 'text/uri-list', both now compared, ignoring + case. */ +#define MODIFY_SELECTION(xe) do { \ + Atom a[4]; \ + char* name; \ +if(0) fprint(2, "xselect target=%d requestor=%d property=%d selection=%d\n", \ + xe->target, xe->requestor, xe->property, xe->selection); \ r.xselection.property = xe->property; \ - name = 0x0; \ + memset(&name, 0, sizeof name); \ if(xe->target == _x.targets){ \ a[0] = _x.utf8string; \ a[1] = XA_STRING; \ @@ -18,10 +27,16 @@ || (cistrcmp(name, "text/uri-list") == 0)))){ \ /* text/plain;charset=UTF-8 seems nonstandard but is used by Synergy */ \ /* if the target is STRING we're supposed to reply with Latin1 XXX */ \ - xunlock(); \ qlock(&clip.lk); \ - xlock(); \ XChangeProperty(_x.display, xe->requestor, xe->property, xe->target, \ 8, PropModeReplace, (uchar*)clip.buf, strlen(clip.buf)); \ qunlock(&clip.lk); \ - }else + }else { \ + if(strcmp(name, "TIMESTAMP") != 0) \ + fprint(2, "%s: cannot handle selection request for '%s' (%d)\n", \ + argv0, name, (int)xe->target); \ + r.xselection.property = None; \ + } \ + if (name) XFree(name); \ +} \ +while (0) diff --git a/src/cmd/snarfer/snarfer.c b/src/cmd/snarfer/snarfer.c index e2cd363c..fff437ff 100644 --- a/src/cmd/snarfer/snarfer.c +++ b/src/cmd/snarfer/snarfer.c @@ -144,27 +144,12 @@ main(int argc, char **argv) void xselectionrequest(XEvent *e) { - char *name; - Atom a[4]; XEvent r; XSelectionRequestEvent *xe; - XDisplay *xd; - - xd = _x.display; memset(&r, 0, sizeof r); xe = (XSelectionRequestEvent*)e; -if(0) fprint(2, "xselect target=%d requestor=%d property=%d selection=%d\n", - xe->target, xe->requestor, xe->property, xe->selection); - MODIFY_SELECTION(name, xe){ - name = XGetAtomName(xd, xe->target); - if(strcmp(name, "TIMESTAMP") != 0) - fprint(2, "%s: cannot handle selection request for '%s' (%d)\n", - argv0, name, (int)xe->target); - r.xselection.property = None; - if (name) { XFree(name); name= 0x0; } - } - + MODIFY_SELECTION(xe); r.xselection.display = xe->display; /* r.xselection.property filled above */ r.xselection.target = xe->target; @@ -173,8 +158,8 @@ if(0) fprint(2, "xselect target=%d requestor=%d property=%d selection=%d\n", r.xselection.time = xe->time; r.xselection.send_event = True; r.xselection.selection = xe->selection; - XSendEvent(xd, xe->requestor, False, 0, &r); - XFlush(xd); + XSendEvent(_x.display, xe->requestor, False, 0, &r); + XFlush(_x.display); } char*