-
Notifications
You must be signed in to change notification settings - Fork 0
/
i3lock-extra.sh
executable file
·133 lines (107 loc) · 3.62 KB
/
i3lock-extra.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
cfg_tmpdir="/run/user/$UID/i3lock-extra"
cfg_pixelize_scale='10'
err() { printf '%s\n' "$*" >&2; }
usage() {
while read; do printf '%s\n' "$REPLY"; done <<- EOF
Usage: i3lock-extra [flags]
Flags:
--help|-h Show this message.
--umask|-u Set umask.
--tmpdir|-d Directory to store temporary files in.
This should not be accessible by other users!
--image_file|-i Lock screen with an image.
--screenshot|-s Lock screen with a screenshot of your current workspace.
# Modifiers (apply to both screenshots and specified images):
--overlay-image|-o Overlay another image over the main one.
Gets applied after all other modifiers.
-x Position of overlay image
-y Position of overlay image
--grayscale|-g Make the image grayscale.
--pixelize|-p Pixelize the image.
--pixelize-scale|-P Sets the number by which the image is resized down and up
again to achieve the pixelize effect. For example, 4 means
that it will be resized to 1/4 of the original and blown back up.
--blur|-b Blur the image.
EOF
}
deskshot() {
scrot "$cfg_tmpdir/lockbg.png"
image_file="${cfg_tmpdir}/lockbg.png"
}
image_prepare() {
declare -a convert_args
declare scale_down scale_up
if (( f_grayscale )); then
convert_args+=( -grayscale rec601luma )
fi
if (( f_pixelize )); then
scale_down=$(( 100/cfg_pixelize_scale ))
scale_up=$(( ( 100/cfg_pixelize_scale ) * cfg_pixelize_scale * cfg_pixelize_scale ))
convert_args+=( -scale "$scale_down%" -scale "$scale_up%" )
fi
if (( f_blur )); then
convert_args+=( -blur 4x8 )
fi
if [[ "$convert_args" ]]; then
convert "$image_file" "${convert_args[@]}" "$cfg_tmpdir/lockbg.png"
image_file="$cfg_tmpdir/lockbg.png"
fi
if [ -f "$overlay_image" -a "$x" -a "$y" ]; then
convert -geometry +$x+$y -composite -matte "$image_file" "$overlay_image" "$cfg_tmpdir/lockbg.png"
elif [ -f "$overlay_image" ]; then
convert -gravity center -composite -matte "$image_file" "$overlay_image" "$cfg_tmpdir/lockbg.png"
image_file="$cfg_tmpdir/lockbg.png"
fi
}
main() {
umask 0077 # All files and dirs created should only be accessible by the user.
# Restart i3lock on non-zero exit code by default.
f_secloop=1
while (( $# )); do
case "$1" in
--help|-h) usage; return 0;;
--tmpdir|-d) cfg_tmpdir=$2; shift;;
--umask|-u) umask "$2"; shift;;
--image-file|-i) image_file=$2; shift;;
--overlay-image|-o) overlay_image=$2; shift;;
-x) x=$2; shift;;
-y) y=$2; shift;;
--screenshot|-s) f_screenshot=1;;
--grayscale|-g) f_grayscale=1;;
--pixelize|-p) f_pixelize=1;;
--pixelize-scale|-P) cfg_pixelize_scale=$2; shift;;
--blur|-b) f_blur=1;;
--unsecure) f_secloop=0;;
--) shift; break;;
-*)
err "Unknown key: $1"
usage
return 1
;;
*) break;;
esac
shift
done
if ! [[ -d "$cfg_tmpdir" ]]; then
mkdir -p "$cfg_tmpdir" || {
return 1
}
fi
if (( f_screenshot )); then
deskshot
fi
if ! [[ $image_file ]]; then
usage
return 1
fi
image_prepare
if (( f_secloop )); then
until i3lock -n -t -i "$image_file"; do
true
done
else
i3lock -n -t -i "$image_file"
fi
}
main "$@"