1 #include <X11/extensions/scrnsaver.h>
5 * http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/
7 * compile with 'gcc -l Xss x11idle.c -o x11idle' and copy x11idle into your
11 XScreenSaverInfo
*info
= XScreenSaverAllocInfo();
12 //open the display specified by the DISPLAY environment variable
13 Display
*display
= XOpenDisplay(0);
15 //display could be null if there is no X server running
16 if (info
== NULL
|| display
== NULL
) {
20 //X11 is running, try to retrieve info
21 if (XScreenSaverQueryInfo(display
, DefaultRootWindow(display
), info
) == 0) {
25 //info was retrieved successfully, print idle time
26 printf("%lu\n", info
->idle
);