aboutsummaryrefslogtreecommitdiffstats
path: root/home
diff options
context:
space:
mode:
authorMark Nipper <nipsy@bitgnome.net>2025-01-24 15:20:50 -0800
committerMark Nipper <nipsy@bitgnome.net>2025-01-24 15:20:50 -0800
commit7cb02514ad3a51ac98326e71c7edad8e6ae23fde (patch)
tree2c524b2f99ab25c09ec178ced04f8e32d190c561 /home
parent01db02f45e4fe4aa8957f8d8e1170239faf92907 (diff)
downloadnix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.tar
nix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.tar.gz
nix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.tar.bz2
nix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.tar.lz
nix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.tar.xz
nix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.tar.zst
nix-7cb02514ad3a51ac98326e71c7edad8e6ae23fde.zip
Add xscreensaver hot corners script
Diffstat (limited to 'home')
-rw-r--r--home/nipsy/common/optional/desktops/i3/default.nix7
-rwxr-xr-xhome/nipsy/common/optional/desktops/i3/xscreensaver-activate94
2 files changed, 101 insertions, 0 deletions
diff --git a/home/nipsy/common/optional/desktops/i3/default.nix b/home/nipsy/common/optional/desktops/i3/default.nix
index c7a521d..bbfc50c 100644
--- a/home/nipsy/common/optional/desktops/i3/default.nix
+++ b/home/nipsy/common/optional/desktops/i3/default.nix
@@ -36,6 +36,8 @@
foreground = #e5e5e5
cursor-color = #ffffff
'';
+
+ "bin/xscreensaver-activate".source = ./xscreensaver-activate;
};
packages = [
@@ -79,6 +81,11 @@
always = true;
notification = false;
}
+ {
+ command = "~/bin/xscreensaver-activate";
+ always = true;
+ notification = false;
+ }
];
window.border = 0;
window.commands = [
diff --git a/home/nipsy/common/optional/desktops/i3/xscreensaver-activate b/home/nipsy/common/optional/desktops/i3/xscreensaver-activate
new file mode 100755
index 0000000..b558da8
--- /dev/null
+++ b/home/nipsy/common/optional/desktops/i3/xscreensaver-activate
@@ -0,0 +1,94 @@
+#!/usr/bin/env zsh
+
+# record our own PID to avoid duplicate invocations
+PIDFILE="/dev/shm/${0:t}.pid"
+
+# check for already running script
+if [[ -f ${PIDFILE} ]]; then
+ for i in $(pidof -x ${0:t}); do
+ if [[ ${i} -eq $(cat ${PIDFILE}) ]]; then
+ echo "${0:t} already running!" >&2
+ exit 1
+ fi
+ done
+fi
+
+# record current PID
+echo ${$} > ${PIDFILE}
+
+# wait a bit for everything to start
+sleep 30
+
+# check whether xscreensaver itself is running and start it if not
+if ! systemctl --user --quiet is-active xscreensaver.service; then
+ systemctl --user start xscreensaver.service
+fi
+
+# retrieve current Xorg screen size so we know where the corners are
+xrandr | grep ^Screen | grep -Eo 'current [[:digit:]]+ x [[:digit:]]+' | cut -d' ' -f2,4 | read max_x max_y
+echo "read screen size as ${max_x} x ${max_y}"
+
+# main loop
+while true; do
+
+ # retrieve current mouse position and set environment variables
+ eval $(xdotool getmouselocation --shell)
+
+ # keep xscreensaver deactivated if we're in the top right corner of the screen
+ if [[ ${X} -eq $((max_x - 1)) && ${Y} -eq $((max_y - max_y)) ]]; then
+
+ # make sure xscreensaver is even running before telling it to stay idle
+ if pidof xscreensaver &>/dev/null; then
+ sleep 5
+ xscreensaver-command -deactivate &>/dev/null
+ fi
+
+ # mouse is in the top left corner -- potentially activate xscreensaver right now
+ elif [[ ${X} -eq $((max_x - max_x)) && ${Y} -eq $((max_y - max_y)) ]]; then
+
+ # sleep a bit and then check mouse coordinates again
+ sleep 5
+ eval $(xdotool getmouselocation --shell)
+
+ # mouse is still in the top left corner -- we must really want to activate xscreensaver
+ if [[ ${X} -eq $((max_x - max_x)) && ${Y} -eq $((max_y - max_y)) ]]; then
+
+ # make sure xscreensaver is actually running
+ if pidof xscreensaver &>/dev/null; then
+
+ # make sure it hasn't already activated
+ if ! xscreensaver-command -time | grep -q 'screen blanked since'; then
+
+ # activate it!
+ xscreensaver-command -activate &>/dev/null
+
+ fi
+
+ fi
+
+ fi
+
+ # a Steam game is running
+ elif ps axfu | grep '/home/nipsy/.steam/debian-installation/steamapps/common' | grep -qv grep; then
+
+ # make sure xscreensaver is even running before telling it to stay idle
+ if pidof xscreensaver &>/dev/null; then
+ sleep 5
+ xscreensaver-command -deactivate &>/dev/null
+ fi
+
+ fi
+
+ # die off if we're no longer running on a connected Xorg screen any longer -- this should be the normal termination path for this script
+ if ! xdpyinfo &>/dev/null; then
+ rm ${PIDFILE}
+ exit 0
+ fi
+
+ # arbitrary sleep for script to avoid CPU sucking infinite loop
+ sleep 5
+
+done
+
+# exit with error since we should never get here
+exit 1