-
Notifications
You must be signed in to change notification settings - Fork 187
/
i3lock-fancy
executable file
·139 lines (117 loc) · 5.81 KB
/
i3lock-fancy
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
134
135
136
137
138
139
#!/usr/bin/env bash
# Author: Dolores Portalatin <hello@doloresportalatin.info>
# Dependencies: imagemagick, i3lock-color-git, scrot, wmctrl (optional)
set -o errexit -o noclobber -o nounset
hue=(-level "0%,100%,0.6")
effect=(-filter Gaussian -resize 20% -define "filter:sigma=1.5" -resize 500.5%)
# default system sans-serif font
font=$(convert -list font | awk "{ a[NR] = \$2 } /family: $(fc-match sans -f "%{family}\n")/ { print a[NR-1]; exit }")
image=$(mktemp --suffix=.png)
shot=(import -silent -window root)
desktop=""
i3lock_cmd=(i3lock -i "$image")
shot_custom=false
options="Options:
-h, --help This help menu.
-d, --desktop Attempt to minimize all windows before locking.
-g, --greyscale Set background to greyscale instead of color.
-p, --pixelate Pixelate the background instead of blur, runs faster.
-f <fontname>, --font <fontname> Set a custom font.
-t <text>, --text <text> Set a custom text prompt.
-l, --listfonts Display a list of possible fonts for use with -f/--font.
Note: this option will not lock the screen, it displays
the list and exits immediately.
-n, --nofork Do not fork i3lock after starting.
-- Must be last option. Set command to use for taking a
screenshot. Default is 'import -window root'. Using 'scrot'
or 'maim' will increase script speed and allow setting
custom flags like having a delay."
# move pipefail down as for some reason "convert -list font" returns 1
set -o pipefail
trap 'rm -f "$image"' EXIT
temp="$(getopt -o :hdnpglt:f: -l desktop,help,listfonts,nofork,pixelate,greyscale,text:,font: --name "$0" -- "$@")"
eval set -- "$temp"
# l10n support
case "${LANG:-}" in
af_* ) text="Tik wagwoord om te ontsluit" ;; # Afrikaans
cs_* ) text="Pro odemčení zadajte heslo" ;; # Czech
de_* ) text="Bitte Passwort eingeben" ;; # Deutsch
da_* ) text="Indtast adgangskode" ;; # Danish
en_* ) text="Type password to unlock" ;; # English
es_* ) text="Ingrese su contraseña" ;; # Española
fr_* ) text="Entrez votre mot de passe" ;; # Français
he_* ) text="הקלד סיסמה לביטול הנעילה" ;; # Hebrew עברית
hi_* ) text="अनलॉक करने के लिए पासवर्ड टाईप करें" ;; #Hindi
id_* ) text="Masukkan kata sandi Anda" ;; # Bahasa Indonesia
it_* ) text="Inserisci la password" ;; # Italian
ja_* ) text="パスワードを入力してください" ;; # Japanese
lv_* ) text="Ievadi paroli" ;; # Latvian
nb_* ) text="Skriv inn passord" ;; # Norwegian
pl_* ) text="Podaj hasło" ;; # Polish
pt_* ) text="Digite a senha para desbloquear" ;; # Português
sk_* ) text="Pre odomknutie zadajte heslo" ;; # Slovak
tr_* ) text="Giriş yapmak için şifrenizi girin" ;; # Turkish
ru_* ) text="Введите пароль" ;; # Russian
zh_* ) text="请输入密码以解锁" ;; # Chinese
* ) text="Type password to unlock" ;; # Default to English
esac
while true ; do
case "$1" in
-h|--help)
printf "Usage: %s [options]\n\n%s\n\n" "${0##*/}" "$options"; exit 1 ;;
-d|--desktop) desktop=$(command -V wmctrl) ; shift ;;
-g|--greyscale) hue=(-level "0%,100%,0.6" -set colorspace Gray -average) ; shift ;;
-p|--pixelate) effect=(-scale 10% -scale 1000%) ; shift ;;
-f|--font)
case "$2" in
"") shift 2 ;;
*) font=$2 ; shift 2 ;;
esac ;;
-t|--text) text=$2 ; shift 2 ;;
-l|--listfonts)
convert -list font | awk -F: '/Font: / { print $2 }' | sort -du | command -- ${PAGER:-less}
exit 0 ;;
-n|--nofork) i3lock_cmd+=(--nofork) ; shift ;;
--) shift; shot_custom=true; break ;;
*) echo "error" ; exit 1 ;;
esac
done
if "$shot_custom" && [[ $# -gt 0 ]]; then
shot=("$@");
fi
command -- "${shot[@]}" "$image"
value="60" #brightness value to compare to
color=$(convert "$image" -gravity center -crop 100x100+0+0 +repage -colorspace hsb \
-resize 1x1 txt:- | awk -F '[%$]' 'NR==2{gsub(",",""); printf "%.0f\n", $(NF-1)}');
if [[ $color -gt $value ]]; then #white background image and black text
bw="black"
icon="/usr/share/i3lock-fancy/icons/lockdark.png"
param=("--inside-color=0000001c" "--ring-color=0000003e" \
"--line-color=00000000" "--keyhl-color=ffffff80" "--ringver-color=ffffff00" \
"--separator-color=22222260" "--insidever-color=ffffff1c" \
"--ringwrong-color=ffffff55" "--insidewrong-color=ffffff1c" \
"--verif-color=ffffff00" "--wrong-color=ff000000" "--time-color=ffffff00" \
"--date-color=ffffff00" "--layout-color=ffffff00")
else #black
bw="white"
icon="/usr/share/i3lock-fancy/icons/lock.png"
param=("--inside-color=ffffff1c" "--ring-color=ffffff3e" \
"--line-color=ffffff00" "--keyhl-color=00000080" "--ringver-color=00000000" \
"--separator-color=22222260" "--insidever-color=0000001c" \
"--ringwrong-color=00000055" "--insidewrong-color=0000001c" \
"--verif-color=00000000" "--wrong-color=ff000000" "--time-color=00000000" \
"--date-color=00000000" "--layout-color=00000000")
fi
convert "$image" "${hue[@]}" "${effect[@]}" -font "$font" -pointsize 26 -fill "$bw" -gravity center \
-annotate +0+160 "$text" "$icon" -gravity center -composite "$image"
# If invoked with -d/--desktop, we'll attempt to minimize all windows (ie. show
# the desktop) before locking.
${desktop} ${desktop:+-k on}
# try to use i3lock with prepared parameters
if ! "${i3lock_cmd[@]}" "${param[@]}" >/dev/null 2>&1; then
# We have failed, lets get back to stock one
"${i3lock_cmd[@]}"
fi
# As above, if we were passed -d/--desktop, we'll attempt to restore all windows
# after unlocking.
${desktop} ${desktop:+-k off}