From e32a45ed36d6000db4b39171149072d11b77af72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Delafond?= Date: Sun, 13 Jul 2014 13:35:27 +0200 Subject: Imported Upstream version 8.0.7 --- contrib/scripts/x11idle.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 contrib/scripts/x11idle.c (limited to 'contrib/scripts/x11idle.c') 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 +#include + +/* 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; +} -- cgit v1.2.3