Support for blocking hibernation

This commit is contained in:
John Mertz 2022-11-21 18:56:50 -05:00
parent 4bdd817ae1
commit 14310c3c58
1 changed files with 22 additions and 17 deletions

View File

@ -1,7 +1,8 @@
#!/bin/bash
BLFILE="/home/jpm/.spool/idle.dim"
OPFILE="/home/jpm/.spool/active_outputs"
BLFILE="$HOME/.spool/idle.dim"
OPFILE="$HOME/.spool/active_outputs"
NOHIBERNATE="$HOME/.spool/hibernate_inhibitor
FADE_TIMEOUT=60 # one minute
DIM_TIMEOUT=120 # two minutes
@ -12,18 +13,18 @@ SUSPEND_TIMEOUT=3600 # one hour
function usage()
{
echo "usage: $0 <option>
start - Initialize 'swayidle' script. This should be declared in Sway config.
stop - Kill 'swayidle' script. Consider idle-inhibitor instead.
fade - First idle action. Fades all windows to show background.
unfade - Restore opacity for faded windows.
dim - Reduce display brightness to minimum.
undim - Restore brightness to level prior to 'dim'.
lock - Mark as inactive and start 'swaylock'.
unlock - (Run upon unlock) Mark as active again.
sleep - Disable displays, but continue background processes.
wake - Re-enable displays.
suspend - Hibernate.
help - This message."
start - Initialize 'swayidle' script. This should be declared in Sway config.
stop - Kill 'swayidle' script. Consider idle-inhibitor instead.
fade - First idle action. Fades all windows to show background.
unfade - Restore opacity for faded windows.
dim - Reduce display brightness to minimum.
undim - Restore brightness to level prior to 'dim'.
lock - Mark as inactive and start 'swaylock'.
unlock - (Run upon unlock) Mark as active again.
sleep - Disable displays, but continue background processes.
wake - Re-enable displays.
hibernate - Hibernate.
help - This message."
exit
}
@ -42,7 +43,7 @@ elif [ $1 == "start" ]; then
resume "$0 unlock" \
timeout $DPMS_TIMEOUT "$0 sleep" \
resume "$0 wake" \
timeout $SUSPEND_TIMEOUT "$0 suspend"
timeout $SUSPEND_TIMEOUT "$0 hibernate"
elif [ $1 == "stop" ]; then
pkill swayidle
elif [ $1 == "fade" ]; then
@ -72,8 +73,12 @@ elif [ $1 == "sleep" ]; then
for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
elif [ $1 == "wake" ]; then
/home/jpm/scripts/sway/displays.pl
elif [ $1 == "suspend" ]; then
sudo systemctl start hibernate.target
elif [ $1 == "hibernate" ]; then
if [ -e $NOHIBERNATE ]; then
;;
else
sudo systemctl start hibernate.target
fi
else
echo "Invalid argument: $1"
usage