mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
detailed documentation in x11-selection-mod.h
This commit is contained in:
parent
5cacec27d7
commit
0223fb7474
3 changed files with 25 additions and 36 deletions
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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*
|
||||
|
|
Loading…
Reference in a new issue