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

517
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,283 +28,225 @@ 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
echo "Important : Update the image cache, Ex. ./lock.sh -g path/to/image.jpg"
if [ ! -f $l_dim ]; then echo
echo "Important : Update the image cache, Ex. ./lock.sh -g path/to/image.jpg" echo "See also : For other set of options and help use help command."
echo echo "Ex. ./lock.sh -h or ./lock.sh --help"
echo "See also : For other set of options and help use help command." echo
echo "Ex. ./lock.sh -h or ./lock.sh --help" echo "See : https://github.com/pavanjadhaw/betterlockscreen for addition info..."
echo exit 1
echo "See : https://github.com/pavanjadhaw/betterlockscreen for addition info..." else
exit 1 echo
else echo "Seems you havent provided any argument, see below for usage info"
echo echo
echo "Seems you havent provided any argument, see below for usage info" echo "See also : For other set of options and help use help command."
echo echo "Ex. ./lock.sh -h or ./lock.sh --help"
echo "See also : For other set of options and help use help command." echo
echo "Ex. ./lock.sh -h or ./lock.sh --help" echo "See : https://github.com/pavanjadhaw/betterlockscreen for addition info..."
echo echo
echo "See : https://github.com/pavanjadhaw/betterlockscreen for addition info..." exit 1
echo fi
exit 1 ;;
fi
-h | --help)
;; echo "Important : Update the image cache, Ex: ./lock.sh -g path/to/image.jpg"
echo
-h | --help) echo
echo "See : https://github.com/pavanjadhaw/betterlockscreen for additional info..."
echo "Important : Update the image cache, Ex: ./lock.sh -g path/to/image.jpg" echo
echo echo
echo echo "Options:"
echo "See : https://github.com/pavanjadhaw/betterlockscreen for additional info..." echo
echo echo " -h --help"
echo echo " For help. Ex: ./lock.sh -h or ./lock.sh --help"
echo "Options:" echo
echo echo
echo " -h --help" echo " -u --update"
echo " For help. Ex: ./lock.sh -h or ./lock.sh --help" echo " to update image cache, you should do this before using any other options"
echo echo " Ex: ./lock.sh -u path/to/image.png when image.png is custom background"
echo echo
echo " -u --update" echo
echo " to update image cache, you should do this before using any other options" echo " -l --lock"
echo " Ex: ./lock.sh -u path/to/image.png when image.png is custom background" echo " to lock screen, Ex. ./lock.sh -l"
echo echo " you can also use dimmed or blurred background for lockscreen"
echo echo " Ex: ./lock.sh -l dim (for dimmed background)"
echo " -l --lock" echo " Ex: ./lock.sh -l blur (for blurred background)"
echo " to lock screen, Ex. ./lock.sh -l" echo " Ex: ./lock.sh -l dimblur (for dimmed + blurred background)"
echo " you can also use dimmed or blurred background for lockscreen" echo
echo " Ex: ./lock.sh -l dim (for dimmed background)" echo
echo " Ex: ./lock.sh -l blur (for blurred background)" echo " -w --wall"
echo " Ex: ./lock.sh -l dimblur (for dimmed + blurred background)" echo " you can also set lockscreen background as wallpaper"
echo echo " to set wallpaper. Ex ./lock.sh -w or ./lock.sh --wall"
echo echo " you can also use dimmed or blurred variants"
echo " -w --wall" echo " Ex: ./lock.sh -w dim (for dimmed wallpaper)"
echo " you can also set lockscreen background as wallpaper" echo " Ex: ./lock.sh -w blur (for blurred wallpaper)"
echo " to set wallpaper. Ex ./lock.sh -w or ./lock.sh --wall" echo " Ex: ./lock.sh -w dimblur (for dimmed + blurred wallpaper)"
echo " you can also use dimmed or blurred variants" echo
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)" -l | --lock)
echo case "$2" in
;; "")
# default lockscreen
-l | --lock) prelock
playerctl pause
lock "$l_resized"
case "$2" in postlock
;;
"")
dim)
# default lockscreen # 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_resized" \
--timepos="x-90:h-ch+30" \ blur)
--datepos="tx+24:ty+25" \ # set lockscreen with blurred background
--clock --datestr "type password to unlock..." \ prelock
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \ lock "$l_blur"
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \ postlock
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \ ;;
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \ dimblur)
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff" # set lockscreen with dimmed + blurred background
prelock
# enable notifications once unlocked lock "$l_dimblur"
pkill -u "$USER" -USR2 dunst postlock
;; ;;
esac
;;
dim)
-w | --wall)
case "$2" in
# lockscreen with dimmed background "")
# stop dunst from showing notifications on lockscreen # set resized image as wallpaper if no argument is supplied by user
pkill -u "$USER" -USR1 dunst feh --bg-fill $resized
;;
i3lock \
-n -i "$l_dim" \ dim)
--timepos="x-90:h-ch+30" \ # set dimmed image as wallpaper
--datepos="tx+24:ty+25" \ feh --bg-fill $dim
--clock --datestr "Type password to unlock..." \ ;;
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \ blur)
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \ # set blurred image as wallpaper
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \ feh --bg-fill $blur
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \ ;;
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff"
dimblur)
# enable notifications once unlocked # set dimmed + blurred image as wallpaper
pkill -u "$USER" -USR2 dunst feh --bg-fill $dimblur
;; ;;
esac
blur)
;;
# set lockscreen with blurred background -u | --update)
# stop dunst from showing notifications on lockscreen rectangles=" "
pkill -u "$USER" -USR1 dunst SR=$(xrandr --query | grep ' connected' | grep -o '[0-9][0-9]*x[0-9][0-9]*[^ ]*')
for RES in $SR; do
i3lock \ SRA=(${RES//[x+]/ })
-n -i "$l_blur" \ CX=$((${SRA[2]} + 25))
--timepos="x-90:h-ch+30" \ CY=$((${SRA[1]} - 30))
--datepos="tx+24:ty+25" \ rectangles+="rectangle $CX,$CY $((CX+300)),$((CY-80)) "
--clock --datestr "Type password to unlock..." \ done
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \ # User supplied Image
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \ user_image="$folder/user_image.png"
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \ # find your resolution so images can be resized to match your screen resolution
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff" y_res=$(xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
# enable notifications once unlocked # create folder
pkill -u "$USER" -USR2 dunst if ! [[ -d $folder ]]; then
;; mkdir -p "$folder"
fi
dimblur) # get user image
cp "$2" "$user_image"
if [ ! -f $user_image ]; then
# set lockscreen with dimmed + blurred background echo "Please specify the path to the image you would like to use"
# stop dunst from showing notifications on lockscreen exit 1
pkill -u "$USER" -USR1 dunst fi
i3lock \ # replace orignal with user image
-n -i "$l_dimblur" \ cp "$user_image" "$orig_wall"
--timepos="x-90:h-ch+30" \ rm "$user_image"
--datepos="tx+24:ty+25" \
--clock --datestr "Type password to unlock..." \ echo "Generating alternate images based on the image you specified,"
--insidecolor=00000000 --ringcolor=ffffffff --line-uses-inside \ echo "please wait this might take few seconds..."
--keyhlcolor=d23c3dff --bshlcolor=d23c3dff --separatorcolor=00000000 \
--insidevercolor=fecf4dff --insidewrongcolor=d23c3dff \ # wallpapers
--ringvercolor=ffffffff --ringwrongcolor=ffffffff --indpos="x+280:h-70" \
--radius=20 --ring-width=3 --veriftext="" --wrongtext="" \ echo
--textcolor="ffffffff" --timecolor="ffffffff" --datecolor="ffffffff" echo "Converting provided image to match your resolution..."
# resize image
# enable notifications once unlocked convert "$orig_wall" -resize "$y_res""^" -gravity center -extent "$y_res" "$resized"
pkill -u "$USER" -USR2 dunst
;; echo
echo "Applying dim and blur effect to resized image"
# dim
esac convert "$resized" -fill black -colorize 40% "$dim"
;;
# blur
convert "$resized" -blur 0x5 "$blur"
-w | --wall)
# dimblur
convert "$dim" -blur 0x5 "$dimblur"
# w = set wallpaper
case "$2" in # lockscreen backgrounds
"")
echo
echo "caching images for faster screen locking"
# set resized image as wallpaper if no argument is supplied by user # resized
feh --bg-fill $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"
dim)
# blur
# set dimmed image as wallpaper convert "$blur" -draw "fill black fill-opacity 0.4 $rectangles" "$l_blur"
feh --bg-fill $dim
;; # blur
convert "$dimblur" -draw "fill black fill-opacity 0.4 $rectangles" "$l_dimblur"
blur) echo
echo "All required changes have been applied"
# set blurred image as wallpaper ;;
feh --bg-fill $blur esac
;;
dimblur)
# set dimmed + blurred image as wallpaper
feh --bg-fill $dimblur
;;
esac
;;
-u | --update)
# 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