summaryrefslogtreecommitdiff
path: root/bin/i3-startup-xtrlock-inner-lock
blob: 3721d4c05bb102f58d2c91c3bffde5dec6cab0d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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 &