[PATCH] Adding an example script for automatic X11 idle watching.

From: Christoph Lohmann <20h_AT_r-36.net>
Date: Fri, 7 Dec 2012 20:20:01 +0100

---
 README |  8 ++++++++
 xsidle | 29 +++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100755 xsidle
diff --git a/README b/README
index a81290d..e9c2607 100644
--- a/README
+++ b/README
_AT_@ -22,3 +22,11 @@ Afterwards enter the following command to build and install slock
 Running slock
 -------------
 Simply invoke the 'slock' command. To get out of it, enter your password.
+
+Automatic startup on idle
+-------------------------
+Slock includes a script 'xsidle', which will run a command after a certain
+elapsed X11 idle time. It requires the xgetidle[0] application.
+
+[0] http://git.suckless.org/xgetidle/
+
diff --git a/xsidle b/xsidle
new file mode 100755
index 0000000..fb84343
--- /dev/null
+++ b/xsidle
_AT_@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# xsidle will wait for _time_ seconds of X11 idle time to elapse to run _cmd_
+#
+
+if [ $# -lt 1 ];
+then
+	printf "usage: %s cmd [time]\n" "$(basename $0)" 2>&1
+	exit 1
+fi
+cmd="$1"
+
+seconds=60
+if [ $# -gt 1 ];
+then
+	seconds=$2
+fi
+
+while true
+do
+	tosleep=$(($seconds - $(xgetidle -s)))
+	if [ $tosleep -le 0 ];
+	then
+		$cmd
+	else
+		sleep $tosleep
+	fi
+done
+
-- 
1.8.0.1.264.g226dcb5
--------------090405000600070607010109--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Fri Dec 07 2012 - 21:24:02 CET