-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsxss.c
67 lines (54 loc) · 1.04 KB
/
sxss.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
57
58
59
60
61
62
63
64
65
66
67
/*
* simple X screensaver
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/extensions/scrnsaver.h>
#include <xcb/xproto.h>
#include "config.h"
#define VERSION "0.1.0"
static void
spawn(char *const argv[])
{
switch (fork()) {
case 0:
execvp(argv[0], argv);
perror("execvp");
_exit(1);
case -1:
perror("fork");
}
}
static void
die(const char *str)
{
fprintf(stderr, "%s\n", str);
exit(1);
}
int
main(int argc, char *argv[])
{
if (argc > 1) die("sxss-"VERSION);
XScreenSaverInfo *info;
Display *dpy;
int base, errbase;
if (!(dpy = XOpenDisplay(0))) die("Cannot open display.");
if (!XScreenSaverQueryExtension(dpy, &base, &errbase))
die("Screensaver extension not activated.");
while(1) {
info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
switch(info->state) {
case ScreenSaverDisabled:
sleep(10);
break;
case ScreenSaverOn:
break;
case ScreenSaverOff:
if (info->til_or_since < 1000) spawn(screensaver);
break;
}
sleep(1);
}
}