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