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