Save power mode before sleep, set to power-saver, then restore

This commit is contained in:
John Mertz 2024-08-18 13:06:26 -06:00
parent b32759643a
commit 20102a4006
1 changed files with 4 additions and 0 deletions

View File

@ -7,6 +7,7 @@ SLEEP_TIMEOUT=600 # ten minutes
HIBERNATE_TIMEOUT=3600 # one hour HIBERNATE_TIMEOUT=3600 # one hour
BLFILE="$HOME/.local/state/idle.dim" BLFILE="$HOME/.local/state/idle.dim"
POWERMODE="$HOME/.local/state/power_profile"
OPFILE="$HOME/.local/state/active_outputs" OPFILE="$HOME/.local/state/active_outputs"
STATEFILE="$HOME/.local/state/idle.state" STATEFILE="$HOME/.local/state/idle.state"
IDLEMODE=$(cat $HOME/.local/state/idle_mode) IDLEMODE=$(cat $HOME/.local/state/idle_mode)
@ -163,6 +164,8 @@ elif [[ $1 == "unlock" ]]; then
fi fi
elif [[ $1 == "sleep" ]]; then elif [[ $1 == "sleep" ]]; then
if [[ $IDLEMODE -gt 3 ]]; then if [[ $IDLEMODE -gt 3 ]]; then
powerprofilesctl get > $POWERMODE
powerprofilesctl set power-saver
echo 'sleep' > $STATEFILE 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
@ -175,6 +178,7 @@ elif [[ $1 == "unsleep" ]]; then
if [[ -e $STATEFILE ]]; then if [[ -e $STATEFILE ]]; then
rm $STATEFILE rm $STATEFILE
fi fi
powerprofilesctl set $(cat $POWERMODE)
elif [[ $1 == "hibernate" ]]; then elif [[ $1 == "hibernate" ]]; then
if [[ $IDLEMODE -gt 4 ]]; then if [[ $IDLEMODE -gt 4 ]]; then
echo 'hibernate' > $STATEFILE echo 'hibernate' > $STATEFILE