dotfiles/scripts/.local/bin/lockscreen
Marty Oehme 496522605f
X: Improve lockscreen handling
Added lockscreen trapping and media pausing for lockscreen.
When it is invoked `lockscreen`, all media will be attempted to be pause
and the system will be muted.
Then the lockscreen is engaged.
This should happen automatically when the screen shuts off or the system
suspends or hibernates and can be invoked manually, as before, with
super+x shortcut.
2021-07-28 14:41:02 +02:00

55 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env sh
# Example locker script -- demonstrates how to use the --transfer-sleep-lock
# option with i3lock's forking mode to delay sleep until the screen is locked.
## CONFIGURATION ##############################################################
# Options to pass to i3lock
i3lock_options="-e -f -c 1d2021"
# Run before starting the locker
pre_lock() {
# pause all currently playing media and mute system
type mpc >/dev/null 2>&1 && mpc -q pause
type playerctl >/dev/null 2>&1 && playerctl -s pause
type amixer >/dev/null 2>&1 && amixer -q set Master mute
return
}
# Run after the locker exits
post_lock() {
return
}
###############################################################################
pre_lock
# We set a trap to kill the locker if we get killed, then start the locker and
# wait for it to exit. The waiting is not that straightforward when the locker
# forks, so we use this polling only if we have a sleep lock to deal with.
if [ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]; then
kill_i3lock() {
pkill -xu $EUID "$@" i3lock
}
trap kill_i3lock TERM INT
# we have to make sure the locker does not inherit a copy of the lock fd
i3lock $i3lock_options {XSS_SLEEP_LOCK_FD}<&-
# now close our fd (only remaining copy) to indicate we're ready to sleep
exec {XSS_SLEEP_LOCK_FD}<&-
while kill_i3lock -0; do
sleep 0.5
done
else
trap 'kill %%' TERM INT
i3lock -n $i3lock_options &
wait
fi
post_lock