-
Notifications
You must be signed in to change notification settings - Fork 1
/
lock.sh
executable file
·252 lines (211 loc) · 6.53 KB
/
lock.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/bash
# Author : Pavan Jadhaw
# Github Profile : https://github.com/pavanjadhaw
# Project Repository : https://github.com/pavanjadhaw/betterlockscreen
# ratio for rectangle to be drawn for time background on lockscreen
# Original Image
orig_wall=$HOME/.wall.png
# create folder in /tmp directory
folder="/tmp/lock"
# Versions (from here)
# You can use these images to set different versions as wallpaper
# lockscreen background.
resized="$folder/resized.png" # resized image for your resolution
# images to be used as wallpaper
dim="$folder/dim.png" # image with subtle overlay of black
blur="$folder/blur.png" # blurred version
dimblur="$folder/dimblur.png"
# lockscreen images (images to be used as lockscreen background)
l_resized="$folder/l_resized.png"
l_dim="$folder/l_dim.png"
l_blur="$folder/l_blur.png"
l_dimblur="$folder/l_dimblur.png"
prelock() {
pkill -u "$USER" -USR1 dunst
}
lock() {
#$1 image path
letterEnteredColor=d23c3dff
letterRemovedColor=d23c3dff
passwordCorrect=00000000
passwordIncorrect=d23c3dff
background=00000000
foreground=ffffffff
i3lock \
-n -i "$1" \
--timepos="x-90:h-ch+30" \
--datepos="tx+24:ty+25" \
--clock --datestr "Type password to unlock..." \
--insidecolor=$background --ringcolor=$foreground --line-uses-inside \
--keyhlcolor=$letterEnteredColor --bshlcolor=$letterRemovedColor --separatorcolor=$background \
--insidevercolor=$passwordCorrect --insidewrongcolor=$passwordIncorrect \
--ringvercolor=$foreground --ringwrongcolor=$foreground --indpos="x+280:h-70" \
--radius=20 --ring-width=4 --veriftext="" --wrongtext="" \
--textcolor="$foreground" --timecolor="$foreground" --datecolor="$foreground"
}
postlock() {
pkill -u "$USER" -USR2 dunst
}
# Options
case "$1" in
"")
if [ ! -f $l_dim ]; then
echo "Important : Update the image cache, Ex. ./lock.sh -g path/to/image.jpg"
echo
echo "See also : For other set of options and help use help command."
echo "Ex. ./lock.sh -h or ./lock.sh --help"
echo
echo "See : https://github.com/pavanjadhaw/betterlockscreen for addition info..."
exit 1
else
echo
echo "Seems you havent provided any argument, see below for usage info"
echo
echo "See also : For other set of options and help use help command."
echo "Ex. ./lock.sh -h or ./lock.sh --help"
echo
echo "See : https://github.com/pavanjadhaw/betterlockscreen for addition info..."
echo
exit 1
fi
;;
-h | --help)
echo "Important : Update the image cache, Ex: ./lock.sh -g path/to/image.jpg"
echo
echo
echo "See : https://github.com/pavanjadhaw/betterlockscreen for additional info..."
echo
echo
echo "Options:"
echo
echo " -h --help"
echo " For help. Ex: ./lock.sh -h or ./lock.sh --help"
echo
echo
echo " -u --update"
echo " to update image cache, you should do this before using any other options"
echo " Ex: ./lock.sh -u path/to/image.png when image.png is custom background"
echo
echo
echo " -l --lock"
echo " to lock screen, Ex. ./lock.sh -l"
echo " you can also use dimmed or blurred background for lockscreen"
echo " Ex: ./lock.sh -l dim (for dimmed background)"
echo " Ex: ./lock.sh -l blur (for blurred background)"
echo " Ex: ./lock.sh -l dimblur (for dimmed + blurred background)"
echo
echo
echo " -w --wall"
echo " you can also set lockscreen background as wallpaper"
echo " to set wallpaper. Ex ./lock.sh -w or ./lock.sh --wall"
echo " you can also use dimmed or blurred variants"
echo " Ex: ./lock.sh -w dim (for dimmed wallpaper)"
echo " Ex: ./lock.sh -w blur (for blurred wallpaper)"
echo " Ex: ./lock.sh -w dimblur (for dimmed + blurred wallpaper)"
echo
;;
-l | --lock)
case "$2" in
"")
# default lockscreen
prelock
playerctl pause > /dev/null 2>&1
lock "$l_resized"
postlock
;;
dim)
# lockscreen with dimmed background
prelock
lock "$l_dim"
postlock
;;
blur)
# set lockscreen with blurred background
prelock
lock "$l_blur"
postlock
;;
dimblur)
# set lockscreen with dimmed + blurred background
prelock
lock "$l_dimblur"
postlock
;;
esac
;;
-w | --wall)
case "$2" in
"")
# set resized image as wallpaper if no argument is supplied by user
feh --bg-fill $resized
;;
dim)
# set dimmed image as wallpaper
feh --bg-fill $dim
;;
blur)
# set blurred image as wallpaper
feh --bg-fill $blur
;;
dimblur)
# set dimmed + blurred image as wallpaper
feh --bg-fill $dimblur
;;
esac
;;
-u | --update)
rectangles=" "
SR=$(xrandr --query | grep ' connected' | grep -o '[0-9][0-9]*x[0-9][0-9]*[^ ]*')
for RES in $SR; do
SRA=(${RES//[x+]/ })
CX=$((${SRA[2]} + 25))
CY=$((${SRA[1]} - 30))
rectangles+="rectangle $CX,$CY $((CX+300)),$((CY-80)) "
done
# User supplied Image
user_image="$folder/user_image.png"
# find your resolution so images can be resized to match your screen resolution
y_res=$(xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
# create folder
if ! [[ -d $folder ]]; then
mkdir -p "$folder"
fi
# get user image
cp "$2" "$user_image"
if [ ! -f $user_image ]; then
echo "Please specify the path to the image you would like to use"
exit 1
fi
# replace orignal with user image
cp "$user_image" "$orig_wall"
rm "$user_image"
echo "Generating alternate images based on the image you specified,"
echo "please wait this might take few seconds..."
# wallpapers
echo
echo "Converting provided image to match your resolution..."
# resize image
convert "$orig_wall" -resize "$y_res""^" -gravity center -extent "$y_res" "$resized"
echo
echo "Applying dim and blur effect to resized image"
# dim
convert "$resized" -fill black -colorize 40% "$dim"
# blur
convert "$resized" -blur 0x5 "$blur"
# dimblur
convert "$dim" -blur 0x5 "$dimblur"
# lockscreen backgrounds
echo
echo "caching images for faster screen locking"
# resized
convert "$resized" -draw "fill black fill-opacity 0.4 $rectangles" "$l_resized"
# dim
convert "$dim" -draw "fill black fill-opacity 0.4 $rectangles" "$l_dim"
# blur
convert "$blur" -draw "fill black fill-opacity 0.4 $rectangles" "$l_blur"
# blur
convert "$dimblur" -draw "fill black fill-opacity 0.4 $rectangles" "$l_dimblur"
echo
echo "All required changes have been applied"
;;
esac