ENH allow screenlocker to also suspend

This commit is contained in:
Nathan Dwarshuis 2023-01-17 22:45:55 -05:00
parent 1d53b6562c
commit 2d2e6fac76
1 changed files with 18 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#! /bin/bash #! /bin/bash
## lock the screen using i3lock ## lock the screen using i3lock (and maybe suspend)
## usage: screenlock [SUSPEND]
# WORKAROUND make the date show up in the right place on 2+ monitor setups # WORKAROUND make the date show up in the right place on 2+ monitor setups
# I want it to only show up on the primary screen, so use xrandr to get the # I want it to only show up on the primary screen, so use xrandr to get the
@ -12,6 +14,7 @@ xpos=$(echo "$geometry" | cut -f2 -d" ")
xoffset=$(("$xpos" + "$width" / 2)) xoffset=$(("$xpos" + "$width" / 2))
datepos="$xoffset:600" datepos="$xoffset:600"
# lock and fork so we can suspend with the screen locked
i3lock --color=000000 \ i3lock --color=000000 \
--pass-media-keys \ --pass-media-keys \
--nofork \ --nofork \
@ -42,4 +45,17 @@ i3lock --color=000000 \
--wrong-size=72 \ --wrong-size=72 \
--verif-size=72 \ --verif-size=72 \
--radius=300 \ --radius=300 \
--ring-width=25 --ring-width=25 &
# suspend if we want, and if this machine is currently using a battery
batpath=/sys/class/power_supply/BAT0/status
if [ -f "$batpath" ] && \
[ "$(cat $batpath)" == "Discharging" ] && \
[ "$1" == "true" ]; then
systemctl suspend
fi
# block until the screen is unlocked (since xss-lock expects the locker to exit
# only when unlocked)
wait