#!/bin/bash # Based on /usr/share/doc/xss-lock/transfer-sleep-lock-i3lock.sh on # Debian stretch # # xss-lock should be invoked like this: # # % xss-lock --transfer-sleep-lock -- i3-startup-xtrlock-inner-lock # ensure we can easily see the blue padlock # commented out because if the active window is virt-viewer, and mouse # is hovering over "Leave fullscreen", this will cause virt-viewer to # grab the mouse before xtrlock can lock the screen # xmouse-away-from-edge xtrlock_args="" if [ -e "$HOME/local/xtrlock-please-blank" ]; then xtrlock_args="-b" rm ~/local/xtrlock-please-blank fi # If unclutter is unclutter-xfixes, we want to kill it and restart # later so that it doesn't hide xtrlock's cursor. Note that classic # unclutter won't hide xtrlock's cursor. Rather than checking which # unclutter we have, though, just kill it pkill -xu $EUID unclutter ||: # 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 # pre-sleep commands # kill caffeination because it tends to be ineffective after # system has come back from suspend xset +dpms pkill -u $USER i3-nagbar kill_xtrlock() { pkill -xu $EUID "$@" xtrlock } trap kill_xtrlock TERM INT # we have to make sure the locker does not inherit a copy of the lock fd xtrlock $xtrlock_args -f {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_xtrlock -0; do sleep 0.5 done else trap 'kill %%' TERM INT xtrlock $xtrlock_args & wait fi unclutter -idle 5 -root -noevents &