2017-12-31 06:15:50 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-12-07 18:51:34 +00:00
|
|
|
|
2017-12-08 06:01:03 +00:00
|
|
|
# Author : Pavan Jadhaw
|
|
|
|
# Github Profile : https://github.com/pavanjadhaw
|
|
|
|
# Project Repository : https://github.com/pavanjadhaw/betterlockscreen
|
|
|
|
|
2018-06-12 15:27:01 +00:00
|
|
|
# find your resolution so images can be resized to match your screen resolution
|
|
|
|
res=$(xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
|
|
|
|
|
|
|
|
init_filenames() {
|
|
|
|
#$1 resolution
|
|
|
|
|
|
|
|
# create folder in ~/.cache/i3lock directory
|
2018-06-19 17:23:27 +00:00
|
|
|
res_folder="$HOME/.cache/i3lock/$1"
|
|
|
|
folder="$HOME/.cache/i3lock/current"
|
|
|
|
echo "Got" $@ $res_folder
|
|
|
|
if [ ! -d $folder -o -n "$2" ]
|
|
|
|
then
|
|
|
|
rm $folder
|
|
|
|
ln -s $res_folder $folder
|
|
|
|
fi
|
2018-06-12 15:27:01 +00:00
|
|
|
|
|
|
|
# ratio for rectangle to be drawn for time background on lockscreen
|
|
|
|
# Original Image
|
|
|
|
orig_wall="$folder/wall.png"
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
}
|
2017-12-14 03:10:51 +00:00
|
|
|
|
2018-06-12 15:27:01 +00:00
|
|
|
init_filenames $res
|
2017-12-07 18:51:34 +00:00
|
|
|
|
2017-12-09 01:03:02 +00:00
|
|
|
prelock() {
|
2018-06-13 10:07:46 +00:00
|
|
|
if [ ! -z "$(pidof dunst)" ] ; then
|
|
|
|
pkill -u "$USER" -USR1 dunst
|
|
|
|
fi
|
2017-12-09 01:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lock() {
|
|
|
|
#$1 image path
|
|
|
|
letterEnteredColor=d23c3dff
|
|
|
|
letterRemovedColor=d23c3dff
|
|
|
|
passwordCorrect=00000000
|
|
|
|
passwordIncorrect=d23c3dff
|
|
|
|
background=00000000
|
|
|
|
foreground=ffffffff
|
|
|
|
i3lock \
|
2018-01-17 12:25:51 +00:00
|
|
|
-t -i "$1" \
|
2018-05-31 21:56:22 +00:00
|
|
|
--timepos="x+110:h-70" \
|
|
|
|
--datepos="x+135:h-45" \
|
2017-12-09 01:03:02 +00:00
|
|
|
--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="" \
|
2018-04-11 13:48:00 +00:00
|
|
|
--verifcolor="$foreground" --timecolor="$foreground" --datecolor="$foreground" \
|
2018-04-27 17:18:51 +00:00
|
|
|
--noinputtext="" --force-clock $lockargs
|
2017-12-09 01:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
postlock() {
|
2018-06-13 10:07:46 +00:00
|
|
|
if [ ! -z "$(pidof dunst)" ] ; then
|
|
|
|
pkill -u "$USER" -USR2 dunst
|
|
|
|
fi
|
2017-12-09 01:03:02 +00:00
|
|
|
}
|
2017-12-08 06:01:03 +00:00
|
|
|
|
2017-12-10 22:52:33 +00:00
|
|
|
rec_get_random() {
|
2017-12-10 22:55:43 +00:00
|
|
|
dir="$1"
|
|
|
|
if [ ! -d "$dir" ]; then
|
|
|
|
user_input="$dir"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
dir=($dir/*)
|
|
|
|
dir=${dir[RANDOM % ${#dir[@]}]}
|
|
|
|
rec_get_random "$dir"
|
2017-12-10 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-04-27 17:18:51 +00:00
|
|
|
lockselect() {
|
|
|
|
case "$1" in
|
|
|
|
"")
|
|
|
|
# default lockscreen
|
|
|
|
prelock
|
2018-08-13 03:53:40 +00:00
|
|
|
lock "$l_resized"
|
2018-04-27 17:18:51 +00:00
|
|
|
postlock
|
|
|
|
;;
|
|
|
|
|
|
|
|
dim)
|
|
|
|
# lockscreen with dimmed background
|
|
|
|
prelock
|
2018-08-13 03:53:40 +00:00
|
|
|
lock "$l_dim"
|
2018-04-27 17:18:51 +00:00
|
|
|
postlock
|
|
|
|
;;
|
|
|
|
|
|
|
|
blur)
|
|
|
|
# set lockscreen with blurred background
|
|
|
|
prelock
|
2018-08-13 03:53:40 +00:00
|
|
|
lock "$l_blur"
|
2018-04-27 17:18:51 +00:00
|
|
|
postlock
|
|
|
|
;;
|
|
|
|
|
|
|
|
dimblur)
|
|
|
|
# set lockscreen with dimmed + blurred background
|
|
|
|
prelock
|
2018-08-13 03:53:40 +00:00
|
|
|
lock "$l_dimblur"
|
2018-04-27 17:18:51 +00:00
|
|
|
postlock
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2017-12-31 16:41:51 +00:00
|
|
|
usage() {
|
2017-12-08 06:01:03 +00:00
|
|
|
|
2018-05-20 18:26:18 +00:00
|
|
|
echo "Important: Update the image cache (e.g. betterlockscreen -u path/to/image.jpg)."
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " Image cache must be updated to initially configure or update wallpaper used"
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
|
|
|
echo
|
2018-05-20 18:18:06 +00:00
|
|
|
echo "See: https://github.com/pavanjadhaw/betterlockscreen for additional info..."
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " -h --help"
|
2017-12-14 03:10:51 +00:00
|
|
|
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " For help (e.g. betterlockscreen -h or betterlockscreen --help)."
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " -u --update"
|
|
|
|
echo " to update image cache, you should do this before using any other options"
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " E.g: betterlockscreen -u path/to/image.png when image.png is custom background"
|
|
|
|
echo " Or you can use betterlockscreen -u path/to/imagedir and a random file will be selected."
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " -l --lock"
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " to lock screen (e.g. betterlockscreen -l)"
|
|
|
|
echo " you can also use dimmed or blurred background for lockscreen."
|
|
|
|
echo " E.g: betterlockscreen -l dim (for dimmed background)"
|
|
|
|
echo " E.g: betterlockscreen -l blur (for blurred background)"
|
|
|
|
echo " E.g: betterlockscreen -l dimblur (for dimmed + blurred background)"
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " -s --suspend"
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " to suspend system and lock screen (e.g. betterlockscreen -s)"
|
|
|
|
echo " you can also use dimmed or blurred background for lockscreen."
|
|
|
|
echo " E.g: betterlockscreen -s dim (for dimmed background)"
|
|
|
|
echo " E.g: betterlockscreen -s blur (for blurred background)"
|
|
|
|
echo " E.g: betterlockscreen -s dimblur (for dimmed + blurred background)"
|
2017-12-24 04:33:52 +00:00
|
|
|
echo
|
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " -w --wall"
|
|
|
|
echo " you can also set lockscreen background as wallpaper"
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " to set wallpaper (e.g. betterlockscreen -w or betterlockscreen --wall)"
|
|
|
|
echo " you can also use dimmed or blurred variants."
|
|
|
|
echo " E.g: betterlockscreen -w dim (for dimmed wallpaper)"
|
|
|
|
echo " E.g: betterlockscreen -w blur (for blurred wallpaper)"
|
|
|
|
echo " E.g: betterlockscreen -w dimblur (for dimmed + blurred wallpaper)"
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
2017-12-24 04:36:53 +00:00
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " -r --resolution"
|
|
|
|
echo " to be used after -u"
|
|
|
|
echo " used to set a custom resolution for the image cache."
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " E.g: betterlockscreen -u path/to/image.png -r 1920x1080"
|
|
|
|
echo " E.g: betterlockscreen -u path/to/image.png --resolution 3840x1080"
|
2017-12-29 14:37:27 +00:00
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo
|
|
|
|
echo " -b --blur"
|
|
|
|
echo " to be used after -u"
|
|
|
|
echo " used to set blur intensity. Default to 1."
|
2018-05-20 18:26:18 +00:00
|
|
|
echo " E.g: betterlockscreen -u path/to/image.png -b 3"
|
|
|
|
echo " E.g: betterlockscreen -u path/to/image.png --blur 0.5"
|
2017-12-31 16:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Options
|
|
|
|
case "$1" in
|
|
|
|
"")
|
|
|
|
if [ ! -f $l_dim ]; then
|
2018-05-20 18:26:18 +00:00
|
|
|
echo "Important: Update the image cache (e.g. betterlockscreen -u path/to/image.jpg)."
|
2017-12-31 16:41:51 +00:00
|
|
|
echo
|
2018-04-27 17:18:51 +00:00
|
|
|
echo " Image cache must be updated to initially configure or update wallpaper used"
|
|
|
|
echo
|
2018-05-20 18:18:06 +00:00
|
|
|
echo "See also: For other set of options and help use help command."
|
2018-05-20 18:26:18 +00:00
|
|
|
echo "E.g. betterlockscreen -h or betterlockscreen --help"
|
2017-12-31 16:41:51 +00:00
|
|
|
|
|
|
|
echo
|
2018-05-20 18:18:06 +00:00
|
|
|
echo "See: https://github.com/pavanjadhaw/betterlockscreen for addition info..."
|
2017-12-31 16:41:51 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "Seems you havent provided any argument, see below for usage info"
|
|
|
|
echo
|
2018-05-20 18:18:06 +00:00
|
|
|
echo "See also: For other set of options and help use help command."
|
2017-12-31 16:41:51 +00:00
|
|
|
|
2018-05-20 18:26:18 +00:00
|
|
|
echo "E.g. betterlockscreen -h or betterlockscreen --help"
|
2017-12-31 16:41:51 +00:00
|
|
|
|
|
|
|
echo
|
2018-05-20 18:18:06 +00:00
|
|
|
echo "See: https://github.com/pavanjadhaw/betterlockscreen for addition info..."
|
2017-12-31 16:41:51 +00:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
-h | --help)
|
|
|
|
|
2018-04-27 17:18:51 +00:00
|
|
|
usage
|
2017-12-09 01:03:02 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
-l | --lock)
|
2018-04-26 09:27:15 +00:00
|
|
|
lockargs="-n"
|
2018-04-27 17:18:51 +00:00
|
|
|
lockselect "$2"
|
2017-12-09 01:03:02 +00:00
|
|
|
;;
|
|
|
|
|
2017-12-24 04:33:52 +00:00
|
|
|
-s | --suspend)
|
2018-08-13 03:53:40 +00:00
|
|
|
lockselect "$2"
|
|
|
|
systemctl suspend
|
2017-12-24 04:33:52 +00:00
|
|
|
;;
|
|
|
|
|
2017-12-09 01:03:02 +00:00
|
|
|
-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)
|
2017-12-29 14:37:27 +00:00
|
|
|
background="$2"
|
|
|
|
shift 2
|
|
|
|
|
|
|
|
# default blur level
|
|
|
|
blur_level=1
|
|
|
|
|
|
|
|
# parse update arguments
|
|
|
|
while [ $# -gt 0 ]; do
|
2018-04-27 17:18:51 +00:00
|
|
|
case "$1" in
|
2017-12-29 14:37:27 +00:00
|
|
|
-r | --resolution )
|
2018-06-12 15:27:01 +00:00
|
|
|
res="$2"
|
2018-06-19 17:23:27 +00:00
|
|
|
init_filenames $res force
|
2018-04-27 17:18:51 +00:00
|
|
|
shift 2
|
|
|
|
;;
|
2017-12-29 14:37:27 +00:00
|
|
|
-b | --blur )
|
2018-04-27 17:18:51 +00:00
|
|
|
blur_level="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2017-12-29 14:37:27 +00:00
|
|
|
*)
|
2018-04-27 17:18:51 +00:00
|
|
|
shift ;;
|
|
|
|
esac
|
2017-12-29 14:37:27 +00:00
|
|
|
done
|
|
|
|
|
2017-12-09 01:03:02 +00:00
|
|
|
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"
|
|
|
|
|
|
|
|
# create folder
|
2017-12-14 02:49:59 +00:00
|
|
|
if [ ! -d $folder ]; then
|
|
|
|
echo "Creating '$folder' directory to cache processed images."
|
2017-12-09 01:03:02 +00:00
|
|
|
mkdir -p "$folder"
|
|
|
|
fi
|
|
|
|
|
2017-12-10 19:16:21 +00:00
|
|
|
# get random file in dir if passed argument is a dir
|
2017-12-29 14:37:27 +00:00
|
|
|
rec_get_random "$background"
|
2017-12-10 22:52:33 +00:00
|
|
|
|
2017-12-09 01:03:02 +00:00
|
|
|
# get user image
|
2017-12-10 19:16:21 +00:00
|
|
|
cp "$user_input" "$user_image"
|
2017-12-09 01:03:02 +00:00
|
|
|
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
|
2018-06-12 15:27:01 +00:00
|
|
|
convert "$orig_wall" -resize "$res""^" -gravity center -extent "$res" "$resized"
|
2017-12-09 01:03:02 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Applying dim and blur effect to resized image"
|
|
|
|
# dim
|
|
|
|
convert "$resized" -fill black -colorize 40% "$dim"
|
|
|
|
|
|
|
|
# blur
|
2017-12-29 14:37:27 +00:00
|
|
|
blur_shrink=$(echo "scale=2; 20 / $blur_level" | bc)
|
|
|
|
blur_sigma=$(echo "scale=2; 0.6 * $blur_level" | bc)
|
|
|
|
convert "$resized" \
|
2018-04-27 17:18:51 +00:00
|
|
|
-filter Gaussian \
|
|
|
|
-resize "$blur_shrink%" \
|
|
|
|
-define "filter:sigma=$blur_sigma" \
|
2018-06-12 15:27:01 +00:00
|
|
|
-resize "$res^" -gravity center -extent "$res" \
|
2018-04-27 17:18:51 +00:00
|
|
|
"$blur"
|
2017-12-09 01:03:02 +00:00
|
|
|
|
|
|
|
# dimblur
|
2017-12-29 14:37:27 +00:00
|
|
|
convert "$dim" \
|
2018-04-27 17:18:51 +00:00
|
|
|
-filter Gaussian \
|
|
|
|
-resize "$blur_shrink%" \
|
|
|
|
-define "filter:sigma=$blur_sigma" \
|
2018-06-12 15:27:01 +00:00
|
|
|
-resize "$res^" -gravity center -extent "$res" \
|
2018-04-27 17:18:51 +00:00
|
|
|
"$dimblur"
|
2017-12-09 01:03:02 +00:00
|
|
|
|
|
|
|
# lockscreen backgrounds
|
|
|
|
|
|
|
|
echo
|
2017-12-14 02:49:59 +00:00
|
|
|
echo "Caching images for faster screen locking"
|
2017-12-09 01:03:02 +00:00
|
|
|
# resized
|
2018-04-27 17:18:51 +00:00
|
|
|
convert "$resized" -draw "fill rgba(0, 0, 0, 0.4) $rectangles" "$l_resized"
|
2017-12-09 01:03:02 +00:00
|
|
|
|
|
|
|
# dim
|
2018-04-08 16:28:39 +00:00
|
|
|
convert "$dim" -draw "fill rgba(0, 0, 0, 0.4) $rectangles" "$l_dim"
|
2017-12-09 01:03:02 +00:00
|
|
|
|
|
|
|
# blur
|
2018-04-08 16:28:39 +00:00
|
|
|
convert "$blur" -draw "fill rgba(0, 0, 0, 0.4) $rectangles" "$l_blur"
|
2017-12-09 01:03:02 +00:00
|
|
|
|
|
|
|
# blur
|
2018-04-08 16:28:39 +00:00
|
|
|
convert "$dimblur" -draw "fill rgba(0, 0, 0, 0.4) $rectangles" "$l_dimblur"
|
2017-12-09 01:03:02 +00:00
|
|
|
echo
|
|
|
|
echo "All required changes have been applied"
|
|
|
|
;;
|
2018-04-27 17:18:51 +00:00
|
|
|
|
|
|
|
*)
|
|
|
|
echo "invalid argument"
|
|
|
|
;;
|
2017-12-09 01:03:02 +00:00
|
|
|
esac
|