diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2018-03-06 20:41:24 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2018-03-06 20:41:24 -0700 |
commit | 482fd38b1684191e6367d2a9c00fa1b95be4300b (patch) | |
tree | 96484d97075ce1707ae193fae7a1ee7f8dcef1fb /bin/i3-startup-i3lock-inner | |
parent | 95cc94184908c6f944585346e5ab4f4d57108d51 (diff) | |
download | dotfiles-482fd38b1684191e6367d2a9c00fa1b95be4300b.tar.gz |
ensure that i3lock has locked the screen before going to sleep
Diffstat (limited to 'bin/i3-startup-i3lock-inner')
-rwxr-xr-x | bin/i3-startup-i3lock-inner | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bin/i3-startup-i3lock-inner b/bin/i3-startup-i3lock-inner new file mode 100755 index 00000000..bd08cda2 --- /dev/null +++ b/bin/i3-startup-i3lock-inner @@ -0,0 +1,54 @@ +#!/bin/bash + +# From /usr/share/doc/xss-lock/transfer-sleep-lock-i3lock.sh on Debian stretch + +## CONFIGURATION ############################################################## + +# Options to pass to i3lock +if [ -e "$HOME/local/wallpaper.png" ]; then + i3lock_options="-i $HOME/local/wallpaper.png" +else + i3lock_options="-c 3f3f3f" +fi + +# Run before starting the locker +pre_lock() { + mpc pause + 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 |