-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlock
executable file
·88 lines (68 loc) · 2.16 KB
/
lock
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /bin/bash
LOGO=`dirname $0`/arch-logo.png
IMG=/tmp/screen_locked.png
PARTS=/tmp/lock_parts_
PART1=${PARTS}0.jpg
PART2=${PARTS}1.jpg
# colors of the circle
NORMAL_COLOR="#005fd7"
SUCCESS_COLOR="#00ff5f"
FAILURE_COLOR="#d70000"
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
cat << EOF
$ lock
Lock screen
Using an i3lock fork: https://github.com/Lixxia/i3lock
EOF
exit
fi
hash scrot magick i3lock || exit 127
# take a screenshot
scrot -o $IMG
add_logo_user() {
# add small arch logo to screen center
# magick $1 $LOGO -gravity center -geometry +0-10 -composite $1
# add user@hostname above the logo
magick $1 -font Comic-Code-Ligatures-Bold-Nerd-Font-Complete -fill grey -pointsize 22 -gravity center -draw "text 0,-150 '$USER@$(cat /etc/hostname)'" $1
## list of fonts: identify -list font
}
process_image() {
# blur logo, to give it a glow
add_logo_user $1
# blur screenshot
magick $1 -blur 0x6 $1
## see for customizing blur: https://www.imagemagick.org/Usage/blur/#blur_args
# clear logo over the blur
add_logo_user $1
}
if [ "$(xrandr --listmonitors | head -n1 | awk '{ print $2 }')" -ge 2 ]; then # 2 monitors
magick $IMG -crop 2x1@ $PARTS%d.jpg
process_image $PART1
process_image $PART2
magick $PARTS*.jpg +append $IMG
else
process_image $IMG
fi
wait_fingerprint() {
while pidof i3lock >/dev/null; do
if (timeout 5 fprintd-verify | grep -q verify-match); then
pkill i3lock
fi
done
}
# copied from the conversation here: https://github.com/i3/i3lock/issues/210#issuecomment-1047552957
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 -i $IMG --ignore-empty-password --24 -o "$SUCCESS_COLOR" -w "$FAILURE_COLOR" -l "$NORMAL_COLOR" {XSS_SLEEP_LOCK_FD}<&-
# now close our fd (only remaining copy) to indicate we're ready to sleep
exec {XSS_SLEEP_LOCK_FD}<&-
wait_fingerprint
else
trap 'kill %%' TERM INT
i3lock -ni $IMG --ignore-empty-password --24 -o "$SUCCESS_COLOR" -w "$FAILURE_COLOR" -l "$NORMAL_COLOR" &
wait_fingerprint
fi