]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - herbstluftwm/autostart
herbstluftwm: Search for a screen locker.
[config/dotfiles.git] / herbstluftwm / autostart
index 424ea9b94279952c224c6d189dc1fb0f55d8f772..22dbd0fb4b38f64dbf50fe44eeeffbcf20c9d5f6 100755 (executable)
@@ -24,6 +24,19 @@ set -e
 hc() {
     herbstclient "$@"
 }
+installed() {
+    type "$1" >/dev/null 2>&1
+}
+# $1: timeout
+notify() {
+    if installed dzen2; then
+        sed 's/\^/^^/g' | dzen2 -fg blue -bg yellow -y 15 -h 30 -p "$1"
+    elif installed xmessage; then
+        # Fallback solution, display first line of stdin.
+        read x
+        xmessage -timeout "$1" "$x" &
+    fi
+}
 
 # Tell all clients the configuration file was reloaded. Should be the first
 # command in the autostart file.
@@ -44,9 +57,18 @@ hc keybind $mod-Shift-Return spawn urxvt
 hc keybind $mod-Shift-c close
 hc keybind $mod-q reload
 hc keybind $mod-Shift-q quit
+# Find an existing screen locker.
+for locker in xtrlock ''; do
+    if installed "$locker"; then
+        break
+    fi
+done
+if test -z "$locker"; then
+    echo 'No screen locker found!' | notify 60
+fi
 # Lock the screen. The sleep is necessary to allow xtrlock to grab the
 # keyboard input.
-hc keybind $mod-z spawn sh -c 'sleep 1 && exec xtrlock'
+hc keybind $mod-z spawn sh -c "sleep 1 && exec $locker"
 
 # Tag key bindings. Create tags 1 to 9 with bindings to switch and move
 # windows to them.
@@ -145,11 +167,6 @@ hc rule focus=off \
 hc unlock
 
 
-# $1: timeout
-notify() {
-    sed 's/\^/^^/g' | dzen2 -fg blue -bg yellow -y 15 -h 30 -p "$@"
-}
-
 # To notify me if set -e has terminated the script (then this part won't get
 # executed).
 echo 'hlwm restarted' | notify 1