-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
46 lines (41 loc) · 1.16 KB
/
main.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
#include <X11/extensions/XInput2.h>
#include <stdio.h>
static void xi_select_events(int);
static Display *d;
static Window r; // root-window
void xi_select_events(const int event) {
unsigned char mask[3] = {None};
XISetMask(mask, event);
XIEventMask event_mask;
event_mask.deviceid = XIAllMasterDevices;
event_mask.mask_len = sizeof(mask);
event_mask.mask = mask;
XISelectEvents(d, r, &event_mask, 1);
}
int main(void) {
if (!(d = XOpenDisplay(NULL))) {
printf("Couldn't open Display.\n");
return 1;
}
r = XDefaultRootWindow(d);
xi_select_events(XI_RawKeyPress);
XEvent e;
XGenericEventCookie *c;
while (!XNextEvent(d, &e)) {
if (!XGetEventData(d, (c = &e.xcookie)))
continue;
switch (c->evtype) {
case XI_RawKeyPress:
xi_select_events(XI_RawMotion);
XFixesHideCursor(d, r);
break;
case XI_RawMotion:
xi_select_events(XI_RawKeyPress);
XFixesShowCursor(d, r);
break;
}
XFreeEventData(d, c);
XSync(d, True);
}
XCloseDisplay(d);
}