diff options
author | Sébastien Delafond <sdelafond@gmail.com> | 2014-07-13 13:35:27 +0200 |
---|---|---|
committer | Sébastien Delafond <sdelafond@gmail.com> | 2014-07-13 13:35:27 +0200 |
commit | e32a45ed36d6000db4b39171149072d11b77af72 (patch) | |
tree | b5f4a7d43022c08c3298e82b3e9fc50f68be660f /contrib/scripts/x11idle.c | |
parent | 7697fa4daf3ec84f85711a84035d8f0224afd4e3 (diff) |
Imported Upstream version 8.0.7
Diffstat (limited to 'contrib/scripts/x11idle.c')
-rw-r--r-- | contrib/scripts/x11idle.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/contrib/scripts/x11idle.c b/contrib/scripts/x11idle.c new file mode 100644 index 0000000..22cefe1 --- /dev/null +++ b/contrib/scripts/x11idle.c @@ -0,0 +1,28 @@ +#include <X11/extensions/scrnsaver.h> +#include <stdio.h> + +/* Based on code from + * http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/ + * + * compile with 'gcc -l Xss x11idle.c -o x11idle' and copy x11idle into your + * path + */ +main() { + XScreenSaverInfo *info = XScreenSaverAllocInfo(); + //open the display specified by the DISPLAY environment variable + Display *display = XOpenDisplay(0); + + //display could be null if there is no X server running + if (info == NULL || display == NULL) { + return -1; + } + + //X11 is running, try to retrieve info + if (XScreenSaverQueryInfo(display, DefaultRootWindow(display), info) == 0) { + return -1; + } + + //info was retrieved successfully, print idle time + printf("%lu\n", info->idle); + return 0; +} |