scripts/sway/idle.sh

90 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
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
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.
hibernate - Hibernate.
help - This message."
exit
}
if [ -z $1 ]; then
echo "Missing argument"
usage
elif [ $1 == "-h" ] || [ $1 == "--help" ] || [ $1 == "help" ]; then
usage
elif [ $1 == "start" ]; then
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 hibernate"
elif [ $1 == "stop" ]; then
pkill swayidle
elif [ $1 == "fade" ]; then
if [ ! -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency`
fi
elif [ $1 == "unfade" ]; then
if [ -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency`
<<<<<<< Updated upstream
=======
/home/jpm/scripts/sway/displays.pl -w
>>>>>>> Stashed changes
fi
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
# Change nick to AFK
#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
/home/jpm/scripts/sway/displays.pl
elif [ $1 == "hibernate" ]; then
if [ -e $NOHIBERNATE ]; then
::
else
sudo systemctl start hibernate.target
fi
else
echo "Invalid argument: $1"
usage
fi