From: Don Armstrong Date: Sun, 9 Feb 2020 06:19:42 +0000 (-0800) Subject: add i3 locker script X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=commitdiff_plain;h=07b73066dd1384d18778a90dcd85f03b5df1e54c add i3 locker script --- diff --git a/locker b/locker new file mode 100755 index 0000000..14b026f --- /dev/null +++ b/locker @@ -0,0 +1,51 @@ +#!/bin/bash + +# 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="-c 000000" + +# 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