-
Notifications
You must be signed in to change notification settings - Fork 0
/
xss-events.c
56 lines (46 loc) · 1.29 KB
/
xss-events.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
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/extensions/scrnsaver.h>
int main(int argc, char *argv[]) {
Display *display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Couldn't open display!\n");
exit(EXIT_FAILURE);
}
int xss_major_opcode;
int xss_event_offset;
int xss_error_offset;
if (!XQueryExtension(display, ScreenSaverName, &xss_major_opcode, &xss_event_offset, &xss_error_offset)) {
fprintf(stderr, ScreenSaverName " extension is not available!\n");
exit(EXIT_FAILURE);
}
XScreenSaverSelectInput(display, DefaultRootWindow(display), ScreenSaverNotifyMask | ScreenSaverCycleMask);
int previous_state = -1;
while (1) {
XScreenSaverInfo info;
if (!XScreenSaverQueryInfo(display, DefaultRootWindow(display), &info)) {
fprintf(stderr, "Couldn't query screen saver info!\n");
exit(EXIT_FAILURE);
}
if (info.state != previous_state) {
previous_state = info.state;
switch (info.state) {
case ScreenSaverOn:
printf("on\n");
break;
case ScreenSaverOff:
printf("off\n");
break;
case ScreenSaverDisabled:
printf("disabled\n");
break;
}
fflush(stdout);
}
XEvent event;
XNextEvent(display, &event); // wait for next event
}
XCloseDisplay(display);
return 0;
}