62 lines
1.8 KiB
Plaintext
62 lines
1.8 KiB
Plaintext
|
#! /bin/bash
|
||
|
|
||
|
## 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
|
||
|
# I want it to only show up on the primary screen, so use xrandr to get the
|
||
|
# dimensions and position of the primary monitor and calculate the date position
|
||
|
# from that
|
||
|
geometry=$(xrandr | sed -n 's/^.*primary \([0-9]*\)x[0-9]*+\([0-9]\)*+[0-9]* .*/\1 \2/p')
|
||
|
width=$(echo "$geometry" | cut -f1 -d" ")
|
||
|
xpos=$(echo "$geometry" | cut -f2 -d" ")
|
||
|
xoffset=$(("$xpos" + "$width" / 2))
|
||
|
datepos="$xoffset:600"
|
||
|
|
||
|
# lock and fork so we can suspend with the screen locked
|
||
|
i3lock --color=000000 \
|
||
|
--pass-media-keys \
|
||
|
--nofork \
|
||
|
--ignore-empty-password \
|
||
|
--screen=0 \
|
||
|
--indicator \
|
||
|
--inside-color=00000055 \
|
||
|
--insidever-color=00000055 \
|
||
|
--insidewrong-color=00000055 \
|
||
|
--ring-color=555555ff \
|
||
|
--ringwrong-color=ff3333ff \
|
||
|
--ringver-color=99ceffff \
|
||
|
--keyhl-color=99ceffff \
|
||
|
--bshl-color=9523ffff \
|
||
|
--line-color=00000000 \
|
||
|
--separator-color=00000000 \
|
||
|
--clock \
|
||
|
--verif-color=99ceffff \
|
||
|
--wrong-color=ff8282ff \
|
||
|
--time-color=ffffffff \
|
||
|
--time-size=72 \
|
||
|
--time-str="%H:%M" \
|
||
|
--date-color=ffffffff \
|
||
|
--date-size=42 \
|
||
|
--date-str="%b %d, %Y" \
|
||
|
--date-align 0 \
|
||
|
--date-pos="$datepos" \
|
||
|
--wrong-size=72 \
|
||
|
--verif-size=72 \
|
||
|
--radius=300 \
|
||
|
--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
|