Browse Source

Added x11idle and build

Samuel W. Flint 7 years ago
parent
commit
acdc228a30
3 changed files with 33 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 3 0
      build-x11idle.sh
  3. 29 0
      x11idle.c

+ 1 - 0
.gitignore

@@ -11,3 +11,4 @@ auto/*
 /excuse
 /decide
 /pango-list-typefaces
+/x11idle

+ 3 - 0
build-x11idle.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+gcc -l Xss -l X11 x11idle.c -o x11idle

+ 29 - 0
x11idle.c

@@ -0,0 +1,29 @@
+#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
+ */
+
+int 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;
+}