i3lock-custom: Major refactor

Polish the imagemagick pipeline
Be less error-tolerant in subshell
Make program flow easier to read
And open the gates to having a bar on top of it all
This commit is contained in:
Salt 2018-11-04 02:29:16 -06:00
parent 278e3942a2
commit 0ec90646ba

View File

@ -6,10 +6,11 @@
# Distributed under terms of the MIT license.
#
tmpdir="$(mktemp -d /tmp/i3lock-custom-XXXXXXXX)"
tmpdir="$(mktemp -d "/tmp/i3lock-custom-$(whoami)-XXXXXXXX")"
[ -z ${tmpdir+x} ] && exit 2
cleanup() {
rm -rf "$tmpdir"
[ -z "$i3lockpid" ] || kill "$i3lockpid"
}
trap "cleanup" EXIT
# Papirus Dark's object-locked.svg, rendererd, gzipped and base64'd
@ -49,25 +50,45 @@ klg/Tyn9KCMwN3XMDWhrx7stDd1Q4nnRBSHUZn1vrKVXpOqvTAwcKBPunsekzX3q6Z0/Udt6hnii
EOF
}
(
cd "$tmpdir"
# Take a screenshot
import -window root stage1.bmp
step_produce_image() {
(
# Really wanna make damn sure that we handle this well
set +e
umask 077
cd "$tmpdir"
# Grab a screenshot and perform some calculations to make our black bar
import -window root scrot.bmp
lockimg_gz | base64 -d | gunzip > lock.png
rectangle="rectangle $(convert scrot.bmp -print "0,%[fx:h/2+128] %w,%[fx:h/2-128]" /dev/null)"
# Blur out the important bits
convert stage1.bmp -blur 10x5 stage2.bmp
# Do the do
# Output is in PNG so i3lock doesn't OOM
convert \
scrot.bmp \
-blur 10x5 \
-fill \#282828 \
-draw "$rectangle" \
lock.png -gravity center -compose Exclusion -composite \
end.png
)
return $?
}
step_start_i3lock() {
i3lock -i "$tmpdir/end.png" &
i3lockpid="$!"
}
step_wait() {
wait
exit 0
}
# Put a grey bar over it
rectangle="rectangle $(convert stage2.bmp -print "0,%[fx:h/2+128] %w,%[fx:h/2-128]" /dev/null)"
convert stage2.bmp -fill \#282828 -draw "$rectangle" stage3.bmp
main() {
step_produce_image || exit 1
step_start_i3lock
step_wait
wait
exit 0
}
# Stick a lock icon on there
lockimg_gz | base64 -d | gunzip > lock.png
convert -compose Exclusion -composite -gravity center stage3.bmp lock.png stage4.bmp
# Convert the output to PNG so i3lock doesn't OOM
convert stage4.bmp end.png
)
i3lock -i "$tmpdir/end.png"
main $@