summaryrefslogtreecommitdiff
path: root/lock
blob: 51bfe8ae1e49852f8991ee2cfb698b9a64b78753 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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.

## Prepare image

SCREEN_RESOLUTION="$(xdpyinfo | grep dimensions | cut -d' ' -f7)"
BGCOLOR="0,0,0"
convert "$HOME/photos/wallpapers/morgan-flag.png" -gravity Northwest -background $BGCOLOR -extent "$SCREEN_RESOLUTION" $HOME/photos/wallpapers/.lockscreen.png


## CONFIGURATION ##############################################################

# Options to pass to i3lock
i3lock_options="-ti $HOME/photos/wallpapers/.lockscreen.png"


# Run before starting the locker
pre_lock() {
    # Pause music
    #if pgrep xmms2 &> /dev/null; then
        #xmms2 pause
    #fi

    # Set pidgin away.
    if pgrep pidgin &> /dev/null; then
        currentStatusMessage="$(purple-remote 'getstatusmessage')"
        currentStatus="$(purple-remote 'getstatus')"
        purple-remote 'setstatus?status=away&message=Away'
    fi

    return
}

# Run after the locker exits
post_lock() {
    if pgrep pidgin &> /dev/null; then
        purple-remote 'setstatus?status='"$currentStatus"'&message='"$currentStatusMessage"
    fi

    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