-
Notifications
You must be signed in to change notification settings - Fork 3
/
xprintidle.c
84 lines (67 loc) · 2.2 KB
/
xprintidle.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
This program prints the "idle time" of the user to stdout. The "idle
time" is the number of milliseconds since input was received on any
input device. If unsuccessful, the program prints a message to stderr
and exits with a non-zero exit code.
Copyright (c) 2005, 2008 Magnus Henoch <[email protected]>
Copyright (c) 2006, 2007 by Danny Kukawka
Copyright (c) 2008 Eivind Magnus Hvidevold <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the
Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <X11/Xlib.h>
#include <X11/extensions/dpms.h>
#include <X11/extensions/scrnsaver.h>
#include <stdio.h>
void usage(char *name);
int main(int argc, char *argv[])
{
XScreenSaverInfo *ssi;
Display *dpy;
int event_basep, error_basep;
if (argc != 1) {
usage(argv[0]);
return 1;
}
dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
fprintf(stderr, "couldn't open display\n");
return 1;
}
if (!XScreenSaverQueryExtension(dpy, &event_basep, &error_basep)) {
fprintf(stderr, "screen saver extension not supported\n");
return 1;
}
ssi = XScreenSaverAllocInfo();
if (ssi == NULL) {
fprintf(stderr, "couldn't allocate screen saver info\n");
return 1;
}
if (!XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), ssi)) {
fprintf(stderr, "couldn't query screen saver info\n");
return 1;
}
printf("%lu\n", ssi->idle);
XFree(ssi);
XCloseDisplay(dpy);
return 0;
}
void usage(char *name)
{
fprintf(stderr,
"Usage:\n"
"%s\n"
"That is, no command line arguments. The user's idle time\n"
"in milliseconds is printed on stdout.\n",
name);
}