forked from cdown/clipnotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipnotify.c
52 lines (41 loc) · 1.3 KB
/
clipnotify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(void) {
Display *disp = XOpenDisplay(NULL);
if (!disp) {
perror("Can't open X display");
exit(1);
}
int event_base, error_base;
assert(XFixesQueryExtension(disp, &event_base, &error_base));
Window root = DefaultRootWindow(disp);
Atom clipboard = XInternAtom(disp, "CLIPBOARD", False);
XFixesSelectSelectionInput(disp, root, XA_PRIMARY, XFixesSetSelectionOwnerNotifyMask);
XFixesSelectSelectionInput(disp, root, clipboard, XFixesSetSelectionOwnerNotifyMask);
XEvent evt;
while (True)
{
XNextEvent(disp, &evt);
if (evt.type == event_base + XFixesSelectionNotify)
{
XFixesSelectionNotifyEvent *e = (XFixesSelectionNotifyEvent*)&evt;
if (e->selection == XA_PRIMARY)
printf("primary ");
else if (e->selection == clipboard)
printf("clipboard ");
else {
perror("Unknown selection");
exit(1);
}
printf("0x%08x\n", e->owner);
} else {
perror("Unknown event type");
exit(1);
}
fflush(stdout);
}
}