improve idle behaviour

This commit is contained in:
John Mertz 2022-10-31 18:08:05 -04:00
parent 03bb1b1695
commit d90eaeed5c
Signed by: jpm
GPG Key ID: E9C5EA2D867501AB
1 changed files with 65 additions and 39 deletions

View File

@ -1,50 +1,76 @@
#!/bin/bash
BLFILE="/home/jpm/.config/blc.last"
OPFILE="/home/jpm/.config/active_outputs"
BLFILE="/home/jpm/.spool/idle.dim"
OPFILE="/home/jpm/.spool/active_outputs"
FADE_TIMEOUT=60 # one minute
DIM_TIMEOUT=120 # two minutes
LOCK_TIMEOUT=300 # five minutes
DPMS_TIMEOUT=600 # ten minutes
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."
exit
}
if [ -z $1 ]; then
echo "Missing argument: start, warn, lock, unlock, sleep, wake, or resume"
echo "Missing argument"
usage
elif [ $1 == "-h" ] || [ $1 == "--help" ] || [ $1 == "help" ]; then
usage
elif [ $1 == "start" ]; then
swayidle -w timeout 270 "/home/jpm/scripts/sway/idle.sh warn" \
resume "/home/jpm/scripts/sway/idle.sh resume" \
timeout 300 "/home/jpm/scripts/sway/idle.sh sleep" \
resume "/home/jpm/scripts/sway/idle.sh wake" \
before-sleep "/usr/bin/swaylock -c 000000"
elif [ $1 == "warn" ]; then
# Store current brightness
echo $(/home/jpm/scripts/thinkpad/blc.pl %) > $BLFILE
# Dim display
/home/jpm/scripts/thinkpad/blc.pl = 1
# Warning notifications
/home/jpm/scripts/sway/idlecountdown.sh
swayidle -w \
timeout $FADE_TIMEOUT "$0 fade" \
resume "$0 unfade" \
timeout $DIM_TIMEOUT "$0 dim" \
resume "$0 undim" \
timeout $LOCK_TIMEOUT "$0 lock" \
resume "$0 unlock" \
timeout $DPMS_TIMEOUT "$0 sleep" \
resume "$0 wake" \
timeout $SUSPEND_TIMEOUT "$0 suspend"
elif [ $1 == "stop" ]; then
pkill swayidle
elif [ $1 == "fade" ]; then
$HOME/scripts/sway/fade.pl start
elif [ $1 == "unfade" ]; then
$HOME/scripts/sway/fade.pl stop
elif [ $1 == "dim" ]; then
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE
$HOME/scripts/thinkpad/blc.pl = 1 &>-
elif [ $1 == "undim" ]; then
$HOME/scripts/thinkpad/blc.pl = `cat $BLFILE` &>-
elif [ $1 == "lock" ]; then
echo $(/home/jpm/scripts/thinkpad/blc.pl %) > $BLFILE
/home/jpm/scripts/thinkpad/blc.pl = 1
ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
'screen -S irssi -X stuff "/nick jpmAFK^M"'
elif [ $1 == "unlock" ]; then
/home/jpm/scripts/thinkpad/blc.pl = `cat $BLFILE`
elif [ $1 == "sleep" ]; then
# Change nick to AFK
ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
'screen -S irssi -X stuff "/nick jpmAFK^M"'
# Turn off monitor
#for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
#'screen -S irssi -X stuff "/nick jpmAFK^M"'
:
elif [ $1 == "unlock" ]; then
# Change nick to AFK
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
#'screen -S irssi -X stuff "/nick jpm^M"'
:
elif [ $1 == "sleep" ]; then
for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
elif [ $1 == "wake" ]; then
# Kill additional counters that might have been started
/home/jpm/scripts/sway/idle.sh resume
# Restore output(s)
/home/jpm/scripts/sway/displays.pl
#for i in `cat $OPFILE`; do swaymsg "output $i dpms on"; done
# Lock screen
swaylock -c 000000
# Restore brightness level
/home/jpm/scripts/thinkpad/blc.pl = $(cat $BLFILE)
elif [ $1 == "resume" ]; then
# Kill warning
for i in `pkill idlecountdown`; do kill $i; done
/home/jpm/scripts/thinkpad/blc.pl = $(cat $BLFILE)
elif [ $1 == "suspend" ]; then
sudo systemctl start hibernate.target
else
echo "Invalid argument: start, warn, lock, unlock, sleep, wake, or resume"
echo "Invalid argument: $1"
usage
fi