2021-01-18 02:54:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-11-21 23:56:50 +00:00
|
|
|
BLFILE="$HOME/.spool/idle.dim"
|
|
|
|
OPFILE="$HOME/.spool/active_outputs"
|
2022-12-12 23:04:23 +00:00
|
|
|
NOHIBERNATE="$HOME/.spool/hibernate_inhibitor"
|
2022-10-31 22:08:05 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-01-06 19:41:31 +00:00
|
|
|
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
|
2022-10-31 22:08:05 +00:00
|
|
|
}
|
2021-01-18 02:54:21 +00:00
|
|
|
|
|
|
|
if [ -z $1 ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
echo "Missing argument"
|
|
|
|
usage
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "-h" ] || [ $1 == "--help" ] || [ $1 == "help" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
usage
|
2021-01-18 02:54:21 +00:00
|
|
|
elif [ $1 == "start" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
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"
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "stop" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
pkill swayidle
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "fade" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
if [ ! -e $HOME/.spool/sway-hidden ]; then
|
|
|
|
kill -USR2 `cat $HOME/.spool/sway-transparency`
|
|
|
|
fi
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "unfade" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
if [ -e $HOME/.spool/sway-hidden ]; then
|
|
|
|
kill -USR2 `cat $HOME/.spool/sway-transparency`
|
2023-01-07 13:16:47 +00:00
|
|
|
/home/jpm/scripts/sway/displays.pl -w
|
2023-01-06 19:41:31 +00:00
|
|
|
fi
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "dim" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE
|
|
|
|
$HOME/scripts/thinkpad/blc.pl = 1 &>-
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "undim" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
$HOME/scripts/thinkpad/blc.pl = `cat $BLFILE` &>-
|
2022-04-19 04:26:56 +00:00
|
|
|
elif [ $1 == "lock" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
# Change nick to AFK
|
|
|
|
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
|
|
|
|
#'screen -S irssi -X stuff "/nick jpmAFK^M"'
|
|
|
|
:
|
2022-04-19 04:26:56 +00:00
|
|
|
elif [ $1 == "unlock" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
# Change nick to AFK
|
|
|
|
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
|
|
|
|
#'screen -S irssi -X stuff "/nick jpm^M"'
|
|
|
|
:
|
2022-10-31 22:08:05 +00:00
|
|
|
elif [ $1 == "sleep" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
|
2021-01-18 02:54:21 +00:00
|
|
|
elif [ $1 == "wake" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
/home/jpm/scripts/sway/displays.pl
|
2022-11-21 23:56:50 +00:00
|
|
|
elif [ $1 == "hibernate" ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
if [ -e $NOHIBERNATE ]; then
|
|
|
|
::
|
|
|
|
else
|
|
|
|
sudo systemctl start hibernate.target
|
|
|
|
fi
|
2021-01-18 02:54:21 +00:00
|
|
|
else
|
2023-01-06 19:41:31 +00:00
|
|
|
echo "Invalid argument: $1"
|
|
|
|
usage
|
2021-01-18 02:54:21 +00:00
|
|
|
fi
|