Log current state to file (non-idle means that the state file does not exist)

Use existence of state file in new script to know whether to fade or unfade windows/notifications
This commit is contained in:
John Mertz 2024-04-19 18:08:30 -06:00
parent c0cb1ed8a7
commit 0abcd17f22
2 changed files with 31 additions and 1 deletions

View File

@ -8,6 +8,7 @@ HIBERNATE_TIMEOUT=3600 # one hour
BLFILE="$HOME/.local/state/idle.dim" BLFILE="$HOME/.local/state/idle.dim"
OPFILE="$HOME/.local/state/active_outputs" OPFILE="$HOME/.local/state/active_outputs"
STATEFILE="$HOME/.local/state/idle.state"
IDLEMODE=$(cat $HOME/.local/state/idle_mode) IDLEMODE=$(cat $HOME/.local/state/idle_mode)
if [[ -n $2 ]]; then if [[ -n $2 ]]; then
if [[ $2 == '--ignore_mode' ]]; then if [[ $2 == '--ignore_mode' ]]; then
@ -89,12 +90,19 @@ elif [[ $1 == "start" ]]; then
resume "$0 unsleep" \ resume "$0 unsleep" \
timeout $HIBERNATE_TIMEOUT "$0 hibernate" \ timeout $HIBERNATE_TIMEOUT "$0 hibernate" \
resume "$0 unhibernate" resume "$0 unhibernate"
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "daemon" ]]; then elif [[ $1 == "daemon" ]]; then
nohup $0 start 2>/dev/null & nohup $0 start 2>/dev/null &
elif [[ $1 == "stop" ]]; then elif [[ $1 == "stop" ]]; then
pkill swayidle pkill swayidle
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "fade" ]]; then elif [[ $1 == "fade" ]]; then
if [[ $IDLEMODE -gt 0 ]]; then if [[ $IDLEMODE -gt 0 ]]; then
echo 'hide' > $STATEFILE
if [[ ! -e $HOME/.local/state/sway-hidden ]]; then if [[ ! -e $HOME/.local/state/sway-hidden ]]; then
kill -USR2 $(cat $HOME/.local/state/sway-transparency) kill -USR2 $(cat $HOME/.local/state/sway-transparency)
makoctl mode -a hide makoctl mode -a hide
@ -107,24 +115,35 @@ elif [[ $1 == "unfade" ]]; then
#$HOME/scripts/sway/displays.pl -w #$HOME/scripts/sway/displays.pl -w
makoctl mode -r hide makoctl mode -r hide
fi fi
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "dim" ]]; then elif [[ $1 == "dim" ]]; then
if [[ $IDLEMODE -gt 1 ]]; then if [[ $IDLEMODE -gt 1 ]]; then
echo 'dim' > $STATEFILE
# I don't currently have any dimable monitors, so fade was created instead # I don't currently have any dimable monitors, so fade was created instead
makoctl set-mode away
echo $($HOME/scripts/thinkpad/blc.pl %) >$BLFILE echo $($HOME/scripts/thinkpad/blc.pl %) >$BLFILE
$HOME/scripts/thinkpad/blc.pl = 1 &>- $HOME/scripts/thinkpad/blc.pl = 1 &>-
fi fi
elif [[ $1 == "undim" ]]; then elif [[ $1 == "undim" ]]; then
makoctl set-mode default makoctl set-mode default
$HOME/scripts/thinkpad/blc.pl = $(cat $BLFILE) &>- $HOME/scripts/thinkpad/blc.pl = $(cat $BLFILE) &>-
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "lock" ]]; then elif [[ $1 == "lock" ]]; then
if [[ $IDLEMODE -gt 2 ]]; then if [[ $IDLEMODE -gt 2 ]]; then
echo 'lock' > $STATEFILE
swaylock -f -c 00000000 swaylock -f -c 00000000
fi fi
elif [[ $1 == "unlock" ]]; then elif [[ $1 == "unlock" ]]; then
kill -USR1 $(pgrep swaylock) kill -USR1 $(pgrep swaylock)
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "sleep" ]]; then elif [[ $1 == "sleep" ]]; then
if [[ $IDLEMODE -gt 3 ]]; then if [[ $IDLEMODE -gt 3 ]]; then
echo 'sleep' > $STATEFILE
for i in $(cat $OPFILE); do swaymsg "output $i dpms off"; done for i in $(cat $OPFILE); do swaymsg "output $i dpms off"; done
fi fi
elif [[ $1 == "unsleep" ]]; then elif [[ $1 == "unsleep" ]]; then
@ -133,8 +152,12 @@ elif [[ $1 == "unsleep" ]]; then
cd $HOME/scripts/sway cd $HOME/scripts/sway
source $HOME/.dotfiles/bash/plenv-path.sh source $HOME/.dotfiles/bash/plenv-path.sh
$HOME/scripts/sway/displays.pl 2>&1 >$HOME/.local/state/display_unsleep $HOME/scripts/sway/displays.pl 2>&1 >$HOME/.local/state/display_unsleep
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "hibernate" ]]; then elif [[ $1 == "hibernate" ]]; then
if [[ $IDLEMODE -gt 4 ]]; then if [[ $IDLEMODE -gt 4 ]]; then
echo 'hibernate' > $STATEFILE
sudo systemctl suspend-then-hibernate.target sudo systemctl suspend-then-hibernate.target
fi fi
else else

7
sway/toggle_fade.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if [[ -e ${HOME}/.local/state/idle.state ]]; then
${HOME}/scripts/sway/idle.sh unfade
else
${HOME}/scripts/sway/idle.sh fade
fi