summaryrefslogtreecommitdiff
path: root/contrib/scripts/x11idle.c
diff options
context:
space:
mode:
authorSebastien Delafond <seb@debian.org>2013-08-11 16:27:56 +0200
committerS├ębastien Delafond <sdelafond@gmail.com>2014-07-13 13:35:27 +0200
commit53b246b7d66bfa03ab9bcf47d4647913b401e3d6 (patch)
treeb5ea4e732c2219456d13048feb05b37b22a76391 /contrib/scripts/x11idle.c
parent8606e2621fc00fd8b334a06924aeef3aab7a2e4d (diff)
parente32a45ed36d6000db4b39171149072d11b77af72 (diff)
Imported Debian patch 8.0.7-1
Diffstat (limited to 'contrib/scripts/x11idle.c')
-rw-r--r--contrib/scripts/x11idle.c28
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;
+}