repeated tasks with pre-lock, lock, post-lock are made into functions.

spaces + tabs => tabs only

removed consecutive empty lines

moved resolution rectangles calculation to --update where it's only used
This commit is contained in:
Deluxo 2017-12-09 03:03:02 +02:00 committed by Pavan Jadhaw
parent bb74d3f3ed
commit b1abdc8590

195
lock.sh
View file

@ -5,33 +5,12 @@
# Project Repository : https://github.com/pavanjadhaw/betterlockscreen # Project Repository : https://github.com/pavanjadhaw/betterlockscreen
# ratio for rectangle to be drawn for time background on lockscreen # ratio for rectangle to be drawn for time background on lockscreen
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
# 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/')
# echo " "
# echo " "
# echo "Your screen resolution is : $y_res"
# echo " "
# echo " "
# Original Image # Original Image
orig_wall=$HOME/.wall.png orig_wall=$HOME/.wall.png
# create folder in /tmp directory # create folder in /tmp directory
folder="/tmp/lock" folder="/tmp/lock"
# User supplied Image
user_image="$folder/user_image.png"
# Versions (from here) # Versions (from here)
# You can use these images to set different versions as wallpaper # You can use these images to set different versions as wallpaper
# lockscreen background. # lockscreen background.
@ -49,11 +28,39 @@ l_blur="$folder/l_blur.png"
l_dimblur="$folder/l_dimblur.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 # Options
case "$1" in case "$1" in
"") "")
if [ ! -f $l_dim ]; then if [ ! -f $l_dim ]; then
echo "Important : Update the image cache, Ex. ./lock.sh -g path/to/image.jpg" echo "Important : Update the image cache, Ex. ./lock.sh -g path/to/image.jpg"
echo echo
@ -73,11 +80,9 @@ case "$1" in
echo echo
exit 1 exit 1
fi fi
;; ;;
-h | --help) -h | --help)
echo "Important : Update the image cache, Ex: ./lock.sh -g path/to/image.jpg" echo "Important : Update the image cache, Ex: ./lock.sh -g path/to/image.jpg"
echo echo
echo echo
@ -114,148 +119,78 @@ case "$1" in
;; ;;
-l | --lock) -l | --lock)
case "$2" in case "$2" in
"") "")
# default lockscreen # default lockscreen
# stop dunst from showing notifications on lockscreen prelock
pkill -u "$USER" -USR1 dunst playerctl pause
lock "$l_resized"
i3lock \ postlock
-n -i "$l_resized" \
--timepos="x-90:h-ch+30" \
--datepos="tx+24:ty+25" \
--clock --datestr "type password to unlock..." \
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff"
# enable notifications once unlocked
pkill -u "$USER" -USR2 dunst
;; ;;
dim) dim)
# lockscreen with dimmed background # lockscreen with dimmed background
# stop dunst from showing notifications on lockscreen prelock
pkill -u "$USER" -USR1 dunst lock "$l_dim"
postlock
i3lock \
-n -i "$l_dim" \
--timepos="x-90:h-ch+30" \
--datepos="tx+24:ty+25" \
--clock --datestr "Type password to unlock..." \
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff"
# enable notifications once unlocked
pkill -u "$USER" -USR2 dunst
;; ;;
blur) blur)
# set lockscreen with blurred background # set lockscreen with blurred background
# stop dunst from showing notifications on lockscreen prelock
pkill -u "$USER" -USR1 dunst lock "$l_blur"
postlock
i3lock \
-n -i "$l_blur" \
--timepos="x-90:h-ch+30" \
--datepos="tx+24:ty+25" \
--clock --datestr "Type password to unlock..." \
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff"
# enable notifications once unlocked
pkill -u "$USER" -USR2 dunst
;; ;;
dimblur) dimblur)
# set lockscreen with dimmed + blurred background # set lockscreen with dimmed + blurred background
# stop dunst from showing notifications on lockscreen prelock
pkill -u "$USER" -USR1 dunst lock "$l_dimblur"
postlock
i3lock \
-n -i "$l_dimblur" \
--timepos="x-90:h-ch+30" \
--datepos="tx+24:ty+25" \
--clock --datestr "Type password to unlock..." \
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff"
# enable notifications once unlocked
pkill -u "$USER" -USR2 dunst
;; ;;
esac esac
;; ;;
-w | --wall) -w | --wall)
# w = set wallpaper
case "$2" in case "$2" in
"") "")
# set resized image as wallpaper if no argument is supplied by user # set resized image as wallpaper if no argument is supplied by user
feh --bg-fill $resized feh --bg-fill $resized
;; ;;
dim) dim)
# set dimmed image as wallpaper # set dimmed image as wallpaper
feh --bg-fill $dim feh --bg-fill $dim
;; ;;
blur) blur)
# set blurred image as wallpaper # set blurred image as wallpaper
feh --bg-fill $blur feh --bg-fill $blur
;; ;;
dimblur) dimblur)
# set dimmed + blurred image as wallpaper # set dimmed + blurred image as wallpaper
feh --bg-fill $dimblur feh --bg-fill $dimblur
;; ;;
esac esac
;; ;;
-u | --update) -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 # create folder
if ! [[ -d $folder ]]; then if ! [[ -d $folder ]]; then
@ -276,9 +211,7 @@ case "$1" in
echo "Generating alternate images based on the image you specified," echo "Generating alternate images based on the image you specified,"
echo "please wait this might take few seconds..." echo "please wait this might take few seconds..."
# wallpapers
# wallpapers {{{
echo echo
echo "Converting provided image to match your resolution..." echo "Converting provided image to match your resolution..."
@ -296,12 +229,7 @@ case "$1" in
# dimblur # dimblur
convert "$dim" -blur 0x5 "$dimblur" convert "$dim" -blur 0x5 "$dimblur"
# lockscreen backgrounds
# }}}
# lockscreen backgrounds {{{
echo echo
echo "caching images for faster screen locking" echo "caching images for faster screen locking"
@ -317,15 +245,8 @@ case "$1" in
# blur # blur
convert "$dimblur" -draw "fill black fill-opacity 0.4 $rectangles" "$l_dimblur" convert "$dimblur" -draw "fill black fill-opacity 0.4 $rectangles" "$l_dimblur"
# }}}
echo echo
echo "All required changes have been applied" echo "All required changes have been applied"
;; ;;
esac esac