Greetings comrades,

attached is a patched for slock to add a simple script for idle watching
in your current X11 sessions. It is using xgetidle[0] for getting the
X11 idle time.


Sincerely,

Christoph Lohmann

[0] http://git.suckless.org/xgetidle/
>From 319d24028a01fcf81e246ee44f2640938094a941 Mon Sep 17 00:00:00 2001
From: Christoph Lohmann <2...@r-36.net>
Date: Fri, 7 Dec 2012 20:20:01 +0100
Subject: [PATCH] Adding an example script for automatic X11 idle watching.

---
 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
@@ -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
@@ -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

Reply via email to