sway: sleep earlier on battery
This commit is contained in:
parent
2e72543e96
commit
a843390315
2 changed files with 46 additions and 1 deletions
39
bin/suspend
Executable file
39
bin/suspend
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
BAT_PATH=/sys/class/power_supply
|
||||||
|
BAT=BAT0
|
||||||
|
MODE=suspend-then-hibernate
|
||||||
|
|
||||||
|
# 0: charging
|
||||||
|
# 1: discharging/unknown
|
||||||
|
function _state() {
|
||||||
|
f=$BAT_PATH/$BAT/status
|
||||||
|
s=1
|
||||||
|
if [ -e $f ]; then
|
||||||
|
s=$(grep -c Discharging $f)
|
||||||
|
fi
|
||||||
|
echo $s
|
||||||
|
}
|
||||||
|
|
||||||
|
function _suspend() {
|
||||||
|
state=$(_state)
|
||||||
|
force=${1:-0}
|
||||||
|
echo "INFO: state: $state, force: $force"
|
||||||
|
if [ $state -eq 1 -o $force -eq 1 ]; then
|
||||||
|
systemctl $MODE
|
||||||
|
else
|
||||||
|
echo "ERROR: state: $state, force: $force"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
suspend)
|
||||||
|
_suspend 0
|
||||||
|
;;
|
||||||
|
force)
|
||||||
|
_suspend 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "ERROR: invalid command: \"$1\""
|
||||||
|
echo "possible options: [suspend|force]"
|
||||||
|
;;
|
||||||
|
esac
|
8
config
8
config
|
@ -18,6 +18,7 @@ set $term termite
|
||||||
set $background $HOME/Cloud/xkonni/Pictures/wallpaper/5k_bavarian_forest_bw.jpg
|
set $background $HOME/Cloud/xkonni/Pictures/wallpaper/5k_bavarian_forest_bw.jpg
|
||||||
set $lock_cmd $HOME/.config/sway/bin/lock
|
set $lock_cmd $HOME/.config/sway/bin/lock
|
||||||
set $brightness_cmd "$HOME/.config/sway/bin/brightness
|
set $brightness_cmd "$HOME/.config/sway/bin/brightness
|
||||||
|
set $suspend_cmd "$HOME/.config/sway/bin/suspend
|
||||||
set $volume_cmd "$HOME/.config/sway/bin/volume
|
set $volume_cmd "$HOME/.config/sway/bin/volume
|
||||||
set $font "Cascadia Code PL Regular 10"
|
set $font "Cascadia Code PL Regular 10"
|
||||||
|
|
||||||
|
@ -33,11 +34,16 @@ output * bg $background fill
|
||||||
# You can get the names of your outputs by running: swaymsg -t get_outputs
|
# You can get the names of your outputs by running: swaymsg -t get_outputs
|
||||||
|
|
||||||
### Idle configuration
|
### Idle configuration
|
||||||
|
# 10 min screen off
|
||||||
|
# 15 min lock
|
||||||
|
# 30 min suspend on battery
|
||||||
|
# 120 min suspend
|
||||||
exec swayidle -w \
|
exec swayidle -w \
|
||||||
timeout 600 '$lock_cmd off' \
|
timeout 600 '$lock_cmd off' \
|
||||||
resume '$lock_cmd on' \
|
resume '$lock_cmd on' \
|
||||||
timeout 900 '$lock_cmd lockonly' \
|
timeout 900 '$lock_cmd lockonly' \
|
||||||
timeout 1800 '$lock_cmd suspend' \
|
timeout 1800 '$suspend_cmd suspend' \
|
||||||
|
timeout 7200 '$suspend_cmd force' \
|
||||||
before-sleep '$lock_cmd lock'
|
before-sleep '$lock_cmd lock'
|
||||||
bindsym $mod+Ctrl+Escape exec '$lock_cmd lock'
|
bindsym $mod+Ctrl+Escape exec '$lock_cmd lock'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue