]> git.donarmstrong.com Git - bin.git/commitdiff
update screensaver
authorDon Armstrong <don@donarmstrong.com>
Sun, 1 Jul 2018 19:55:48 +0000 (12:55 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 1 Jul 2018 19:55:48 +0000 (12:55 -0700)
screensaver [new file with mode: 0755]

diff --git a/screensaver b/screensaver
new file mode 100755 (executable)
index 0000000..a0c1942
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+cmd_exists () {
+    if which "$1" >/dev/null 2>&1; then
+        return 0;
+    else
+        return 1;
+    fi;
+}
+
+fork () {
+    ( "$@" >/dev/null 2>&1 & )
+}
+
+cmd_running () {
+    if pkill -0 -u "$(id -u)" "$1"; then
+        return 0;
+    else
+        return 1;
+    fi;
+}
+
+should_stop () {
+    if [ "x$1" = "xoff" ] || [ "x$1" = "xstop" ] ; then
+        return 0;
+    else
+        return 1;
+    fi;
+}
+
+
+if cmd_exists slock && cmd_exists xautolock; then
+    if cmd_running "xautolock"; then
+        if should_stop "$1"; then
+            xautolock -exit;
+        fi;
+    else
+        if ! should_stop "$1"; then
+            fork xautolock -notifier true -bell 0 -locker slock;
+        fi;
+    fi;
+elif cmd_exists xscreensaver && [ -e ~/.xscreensaver ]; then
+    if cmd_running "xscreensaver"; then
+        if should_stop "$1"; then
+            xscreensaver-command -exit;
+        fi;
+    else
+        if ! should_stop "$1"; then
+            fork XENVIRONMENT=~/.xscreensaver /usr/bin/xscreensaver;
+        fi;
+    fi;
+elif cmd_exists xautolock; then
+    if cmd_running "xautolock"; then
+        if should_stop "$1"; then
+            xautolock -exit;
+        fi;
+    else
+        if ! should_stop "$1"; then
+            fork xautolock -notifier true -bell 0;
+        fi;
+    fi;
+fi;