diff --git a/README.md b/README.md index 9079e0b..01d5644 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ betterlockscreen --lock blur ![scrot2](https://github.com/pavanjadhaw/betterlockscreen.demo/raw/master/scrots/scrot2.png 'scrot2.png') -> [Watch some of the features of betterlockscreen in action](https://www.youtube.com/watch?v=9Ng5FZwnn6M&feature=youtu.be) +> [Watch some of the features of betterlockscreen in action](https://youtu.be/9Ng5FZwnn6M) ## Table of Contents @@ -46,7 +46,7 @@ images as lockscreen background depending on argument provided by user. > Note: Make sure your system has all dependencies satisfied -- [i3lock-color](https://github.com/PandorasFox/i3lock-color) - i3lock fork with additional features( >= 2.11-c ) +- [i3lock-color](https://github.com/Raymo111/i3lock-color) - i3lock fork with additional features(`>= 2.13.c.3`) - [imagemagick](https://www.imagemagick.org/script/index.php) - To apply effects to images - [xdpyinfo](https://www.x.org/archive/X11R7.7/doc/man/man1/xdpyinfo.1.xhtml), [xrandr](https://www.x.org/wiki/Projects/XRandR/), [bc](https://www.gnu.org/software/bc/) and [feh](https://feh.finalrewind.org/) - To find screen resolution, set custom blur level and wallpaper handling. @@ -96,74 +96,129 @@ export PATH="${PATH}:${HOME}/.local/bin/" UtkarshVerma was so kind to provide an installation script for debian based systems, ![check it out here](https://github.com/UtkarshVerma/installer-scripts). +#### Void Linux + +##### xbps repository + +`betterlockscreen` is available in official Void's repository as `betterlockscreen`. + +Installing using `xbps` (will automatically install all required dependencies): `xbps-install -S betterlockscreen` + ### Configuration You can customise various colors for betterlockscreen, copy config file from examples directory to `~/.config/betterlockscreenrc` and edit it accordingly. If configuration file is not found then default configurations will be used. +```ini +# default options +display_on=0 +span_image=false +lock_timeout=300 +fx_list=(dim blur dimblur pixel dimpixel color) +dim_level=40 +blur_level=1 +pixel_scale=10,1000 +solid_color=333333 + +# theme options +loginbox=00000066 +loginshadow=00000000 +locktext="Type password to unlock..." +font="sans-serif" +ringcolor=ffffffff +insidecolor=00000000 +separatorcolor=00000000 +ringvercolor=ffffffff +insidevercolor=00000000 +ringwrongcolor=ffffffff +insidewrongcolor=d23c3dff +keyhlcolor=d23c3dff +bshlcolor=d23c3dff +verifcolor=ffffffff +timecolor=ffffffff +datecolor=ffffffff +wallpaper_cmd="feh --bg-fill --no-fehbg" +time_format="%H:%M:%S" +``` If you have installed betterlockscreen from AUR package, then you can copy default config from docs ```sh cp /usr/share/doc/betterlockscreen/examples/betterlockscreenrc ~/.config ``` -For multimonitor setups, now you can choose which monitor the clock is displayed on -modify screennumber in betterlockscreenrc accordingly. Its zero based i.e 0 = screen 1 - ### Usage Run `betterlockscreen` and point it to either a directory (`betterlockscreen -u "path/to/dir"`) or an image (`betterlockscreen -u "/path/to/img.jpg"`) and that's all. `betterlockscreen` will change update its cache with image you provided. ```sh -usage: betterlockscreen [-u "path/to/img.jpg"] [-l "dim, blur or dimblur"] - [-w "dim, blur, or dimblur"] [-t "custom text"] [-s "lockscreen and suspend"] - [-r "resolution"] [-b "factor"] +Usage: betterlockscreen [-u ] [-l ] [-w ] -betterlockscreen - faster and sweet looking lockscreen for linux systems. + -u --update + Update lock screen image -required: - -u, --update "path/to/img.jpg" caches all required images + -l --lock + Lock screen with cached image -usage: - -l, --lock effect-name - locks with provided effect - -w, --wall effect-name - set desktop background with provided effect - -s, --suspend effect-name - lockscreen and suspend + -w --wall + Set wallpaper with cached image - Available effects: - dim, blur or dimblur +Additional arguments: - -t, --text "custom text" - set custom lockscreen text - -b, blur 0.0 - 1.0 - set blur range - -d, --display 0-9 - screen to display loginbox - --span - span multiple screens + --display + Set display to draw loginbox + --span + Scale image to span multiple displays -Usage examples: -1. Updating image cache(required) -betterlockscreen -u ~/Pictures/Forests.png # caches given image -betterlockscreen -u ~/Pictures # caches random image from ~/Pictures directory + --off + Turn display off after N minutes -2. Custom resolution and blur range -betterlockscreen -u path/to/directory -r 1920x1080 -b 0.5 + --fx + List of effects to apply -3. Lockscreen -betterlockscreen -l dim # lockscreen with dim effect + -- + Pass following arguments to i3lock -4. Lockscreen with custom text -betterlockscreen -l dim -t "custom lockscreen text" +Effects arguments: -5. Set desktop background -betterlockscreen -w blur # set desktop background with blur effect + --dim + Dim image N percent (0-100) + + --blur + Blur image N amount (0.0-1.0) + + --pixel + Pixelate image with N shrink and N grow (unsupported) + + --color + Solid color background with HEX ``` + +#### Usage examples: +1. Update image cache with random image +`betterlockscreen -u ~/Wallpapers` + +2. Update image cache with only dim and pixel effects +`betterlockscreen -u ~/Wallpapers/image.png --fx dim,pixel` + +3. Update image cache with random image, multiple monitors, login on 1, spanning +`betterlockscreen -u ~/Wallpapers/Dual/ --display 1 --span` + +4. Update image cache with solid background only (ignore errors) +`betterlockscreen -u . --fx color --color 5833ff` + +5. Update image cache with different background images +`betterlockscreen -u ~/Wallpapers/image1.png -u ~/Wallpapers/image2.png` + +6. Lock screen with blur effect +`betterlockscreen --lock blur` + +7. Lock screen with multiple monitors, spanning +`betterlockscreen -l dimblur --display 1 --span` + + ### Set desktop background on startup Add this line to `.xinitrc`. @@ -211,10 +266,9 @@ alt + shift + x ``` ### Lockscreen when suspended(systemd service) - ```sh # move service file to proper dir (the aur package does this for you) -cp betterlockscreen@.service /etc/systemd/system/ +cp betterlockscreen@.service /usr/lib/systemd/system/ # enable systemd service systemctl enable betterlockscreen@$USER @@ -222,12 +276,17 @@ systemctl enable betterlockscreen@$USER # disable systemd service systemctl disable betterlockscreen@$USER - # Note: Now you can call systemctl suspend to suspend your system # and betterlockscreen service will be activated # so when your system wakes your screen will be locked. ``` +**Hint:** The systemd-unit expects betterlockscreen to be installed in "/usr/local/bin", so maybe you want to check or change this! + +Resources and more informations: + * https://gist.github.com/Raymo111/91ffd256b7aca6a85e8a99d6331d3b7b + * https://github.com/Raymo111/i3lock-color/issues/174#issuecomment-687149213 + --- ### Countributing @@ -249,7 +308,7 @@ Betterlockscreen is under [MIT](https://github.com/pavanjadhaw/betterlockscreen/ - Hat tip to anyone who's code was used - Thanks to those who contributed to make it better -- Inspiration - r/unixporn +- Inspiration - [r/unixporn](https://www.reddit.com/r/unixporn) [logo]: .github/hero.png [website]: https://mdxjs.com \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..f49854f --- /dev/null +++ b/TODO.md @@ -0,0 +1,9 @@ +# merge checklist + +* rename script +* fix paths +* s/multilockscreen/betterlockscreen/ +* combine READMEs +* update example rc +* check CLI args +* ensure feature parity diff --git a/betterlockscreen b/betterlockscreen index bbb0b93..f908c82 100755 --- a/betterlockscreen +++ b/betterlockscreen @@ -6,220 +6,438 @@ init_config () { - # user configuration file + # default options + display_on=0 + span_image=false + lock_timeout=300 + fx_list=(dim blur dimblur pixel dimpixel color) + dim_level=40 + blur_level=1 + pixel_scale=10,1000 + solid_color=333333 + description="" + + # default theme + loginbox=00000066 + loginshadow=00000000 + locktext="Type password to unlock..." + font="sans-serif" + ringcolor=ffffffff + insidecolor=00000000 + separatorcolor=00000000 + ringvercolor=ffffffff + insidevercolor=00000000 + ringwrongcolor=ffffffff + insidewrongcolor=d23c3dff + keyhlcolor=d23c3dff + bshlcolor=d23c3dff + verifcolor=ffffffff + timecolor=ffffffff + datecolor=ffffffff + layoutcolor=ffffffff + nocolor=00000000 + bgcolor=000000ff + wallpaper_cmd="feh --bg-fill --no-fehbg" + time_format="%H:%M:%S" + + # read user config USER_CONF="$HOME/.config/betterlockscreenrc" - if [ -e $USER_CONF ]; then + if [ -e "$USER_CONF" ]; then + # shellcheck source=/dev/null source "$USER_CONF" - # default configuration options - else - insidecolor=00000000 - ringcolor=ffffffff - keyhlcolor=d23c3dff - bshlcolor=d23c3dff - separatorcolor=00000000 - insidevercolor=00000000 - insidewrongcolor=d23c3dff - ringvercolor=ffffffff - ringwrongcolor=ffffffff - verifcolor=ffffffff - timecolor=ffffffff - datecolor=ffffffff - loginbox=00000066 - locktext='Type password to unlock...' - font="sans-serif" - display_on=0 - span_image=false - fi + fi - CACHE_DIR="$HOME/.cache/i3lock" - CUR_DIR="$CACHE_DIR/current" + # paths + CACHE_DIR="$HOME/.cache/i3lock" + CUR_DIR="$CACHE_DIR/current" - # wallpaper - CUR_W_RESIZE="$CUR_DIR/wall_resize.png" - CUR_W_DIM="$CUR_DIR/wall_dim.png" - CUR_W_BLUR="$CUR_DIR/wall_blur.png" - CUR_W_DIMBLUR="$CUR_DIR/wall_dimblur.png" - CUR_W_PIXEL="$CUR_DIR/wall_pixel.png" + # wallpaper + CUR_W_RESIZE="$CUR_DIR/wall_resize.png" + CUR_W_DIM="$CUR_DIR/wall_dim.png" + CUR_W_BLUR="$CUR_DIR/wall_blur.png" + CUR_W_DIMBLUR="$CUR_DIR/wall_dimblur.png" + CUR_W_PIXEL="$CUR_DIR/wall_pixel.png" + CUR_W_DIMPIXEL="$CUR_DIR/wall_dimpixel.png" + CUR_W_COLOR="$CUR_DIR/wall_color.png" - # locker - CUR_L_RESIZE="$CUR_DIR/lock_resize.png" - CUR_L_DIM="$CUR_DIR/lock_dim.png" - CUR_L_BLUR="$CUR_DIR/lock_blur.png" - CUR_L_DIMBLUR="$CUR_DIR/lock_dimblur.png" - CUR_L_PIXEL="$CUR_DIR/lock_pixel.png" + # lockscreen + CUR_L_RESIZE="$CUR_DIR/lock_resize.png" + CUR_L_DIM="$CUR_DIR/lock_dim.png" + CUR_L_BLUR="$CUR_DIR/lock_blur.png" + CUR_L_DIMBLUR="$CUR_DIR/lock_dimblur.png" + CUR_L_PIXEL="$CUR_DIR/lock_pixel.png" + CUR_L_DIMPIXEL="$CUR_DIR/lock_dimpixel.png" + CUR_L_COLOR="$CUR_DIR/lock_color.png" + + # Original DPMS timeout + DEFAULT_TIMEOUT=$(cut -d ' ' -f4 <<< "$(xset q | sed -n '25p')") + # Original DPMS status + DEFAULT_DPMS=$(xset q | awk '/^[[:blank:]]*DPMS is/ {print $(NF)}') } -init_config - - +# called before screen is locked prelock() { - if [ ! -z "$(pidof dunst)" ]; then - pkill -u "$USER" -USR1 dunst - fi + + # set dpms timeout + if [ "$DEFAULT_DPMS" == "Enabled" ]; then + xset dpms "$lock_timeout" + fi + # pause dunst + if command -v dunstctl &>/dev/null + then + dunstctl set-paused true + fi + if [[ "$runsuspend" = "true" ]]; then + lockargs="$lockargs -n" + fi } - +# lock screen with specified image lock() { - #$1 image path - i3lock \ - -i "$1" \ - --screen "$display_on" \ - --timepos='ix-170:iy-0' \ - --datepos='ix-240:iy+25' \ - --clock --date-align 1 --datestr "$locktext" \ - --insidecolor=$insidecolor --ringcolor=$ringcolor --line-uses-inside \ - --keyhlcolor=$keyhlcolor --bshlcolor=$bshlcolor --separatorcolor=$separatorcolor \ - --insidevercolor=$insidevercolor --insidewrongcolor=$insidewrongcolor \ - --ringvercolor=$ringvercolor --ringwrongcolor=$ringwrongcolor --indpos='x+280:y+h-70' \ - --radius=20 --ring-width=4 --veriftext='' --wrongtext='' \ - --verifcolor="$verifcolor" --timecolor="$timecolor" --datecolor="$datecolor" \ - --time-font="$font" --date-font="$font" --layout-font="$font" --verif-font="$font" --wrong-font="$font" \ - --noinputtext='' --force-clock $lockargs + echof act "Locking screen..." + + local image="$1" + + i3lock \ + -i "$image" \ + -c "$bgcolor" \ + --screen "$display_on" \ + --time-pos="ix-170:iy-0" --time-str "$time_format" \ + --date-pos="ix-240:iy+25" \ + --layout-pos="ix-90:iy-0" --layout-align 1 --layout-color="$layoutcolor" "$keylayout" \ + --clock --date-align 1 --date-str "$locktext" \ + --inside-color="$insidecolor" --ring-color="$ringcolor" --line-uses-inside \ + --keyhl-color="$keyhlcolor" --bshl-color="$bshlcolor" --separator-color=$separatorcolor \ + --insidever-color="$insidevercolor" --insidewrong-color="$insidewrongcolor" \ + --ringver-color="$ringvercolor" --ringwrong-color="$ringwrongcolor" --ind-pos="x+280:y+h-70" \ + --radius=20 --ring-width=4 --verif-text="" --wrong-text="" --wrong-color="$nocolor" \ + --verif-color="$verifcolor" --time-color="$timecolor" --date-color="$datecolor" \ + --time-font="$font" --date-font="$font" --layout-font="$font" --verif-font="$font" --wrong-font="$font" \ + --noinput-text="" --force-clock --pass-media-keys --pass-screen-keys --pass-power-keys \ + "${lockargs[@]}" +} + +# in case image isn't found +failsafe() { + + echof act "Locking screen... (FAILSAFE MODE)" + + local bgcolor="000000" + local text="ffffffff" + local error="ff0000" + + i3lock \ + -c "$bgcolor" \ + --screen "$display_on" \ + --time-pos="ix-170:iy-0" \ + --date-pos="ix-240:iy+25" \ + --clock --date-align 1 --date-str "$locktext" \ + --ind-pos="x+280:y+h-70" \ + --radius=20 --ring-width=4 --verif-text="" --wrong-text="" --wrong-color="$error" \ + --verif-color="$text" --time-color="$text" --date-color="$text" \ + --time-font="$font" --date-font="$font" --layout-font="$font" --verif-font="$font" --wrong-font="$font" \ + --noinput-text="" --force-clock } +# called after screen is unlocked postlock() { - if [ ! -z "$(pidof dunst)" ] ; then - pkill -u "$USER" -USR2 dunst - fi + + # restore default dpms timeout + if [ "$DEFAULT_DPMS" == "Enabled" ]; then + xset dpms "$DEFAULT_TIMEOUT" + fi + + # unpause dunst + if command -v dunstctl &>/dev/null + then + dunstctl set-paused false + fi } +# select effect and lock screen lockselect() { - prelock - case "$1" in - dim) - # lockscreen with dimmed background - lock "$CUR_L_DIM" - ;; - blur) - # set lockscreen with blurred background - lock "$CUR_L_BLUR" - ;; + echof act "Running prelock..." + prelock & - dimblur) - # set lockscreen with dimmed + blurred background - lock "$CUR_L_DIMBLUR" - ;; + case "$1" in + dim) if [ -f "$CUR_L_DIM" ]; then lock "$CUR_L_DIM"; else failsafe; fi ;; + blur) if [ -f "$CUR_L_BLUR" ]; then lock "$CUR_L_BLUR"; else failsafe; fi ;; + dimblur) if [ -f "$CUR_L_DIMBLUR" ]; then lock "$CUR_L_DIMBLUR"; else failsafe; fi ;; + pixel) if [ -f "$CUR_L_PIXEL" ]; then lock "$CUR_L_PIXEL"; else failsafe; fi ;; + dimpixel) if [ -f "$CUR_L_DIMPIXEL" ]; then lock "$CUR_L_DIMPIXEL"; else failsafe; fi ;; + color) if [ -f "$CUR_L_COLOR" ]; then lock "$CUR_L_COLOR"; else failsafe; fi ;; + *) if [ -f "$CUR_L_RESIZE" ]; then lock "$CUR_L_RESIZE"; else failsafe; fi ;; + esac - pixel) - # set lockscreen with pixelated background - lock "$CUR_L_PIXEL" - ;; - - *) - # default lockscreen - lock "$CUR_L_RESIZE" - ;; - esac - postlock + echof act "Running postlock..." + postlock & } +# calculate adjustments for hidpi displays logical_px() { - # get dpi value from xrdb - local DPI=$(xrdb -query | awk '/Xft.dpi/ {print $2}') - - # return the default value if no DPI is set - if [ -z "$DPI" ]; then - echo $1 - else - local SCALE=$(echo "scale=2; $DPI / 96.0" | bc) - # check if scaling the value is worthy - if [ $(echo "$SCALE > 1.25" | bc -l) -eq 0 ]; then - echo $1 - else - echo "$SCALE * $1 / 1" | bc - fi - fi + # $1: number of pixels to convert + # $2: 1 for width. 2 for height + local pixels="$1" + local direction="$2" + + # get dpi value from xdpyinfo + local DPI + DPI=$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$direction/p" | head -n1) + + # return the default value if no DPI is set + if [ -z "$DPI" ]; then + echo "$pixels" + else + local SCALE + SCALE=$(echo "scale=2; $DPI / 96.0" | bc) + + # check if scaling the value is worthy + if [ "$(echo "$SCALE > 1.25" | bc -l)" -eq 0 ]; then + echo "$pixels" + else + echo "$SCALE * $pixels / 1" | bc + fi + fi } -# get total resolution -# 1600x900 +# get total resolution, sets $TOTAL_SIZE get_total_size () { TOTAL_SIZE=$(xdpyinfo | grep -w "dimensions" | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/') } - +# get list of displays, sets $DISPLAY_LIST get_display_list () { - local DNUM=0 - mapfile -t DARR < <( xrandr --listactivemonitors ) - for DISP in "${DARR[@]:1}"; do - (( DNUM++ )) - DISP=$(echo $DISP | sed -r 's/\/[0-9]*//g') - IFS=' ' read -r -a LINE <<< "$DISP" - DLIST+=("$DNUM ${LINE[3]} ${LINE[2]}") + local count=0 + mapfile -t displays < <(xrandr --listactivemonitors) + for display in "${displays[@]:1}"; do + ((count++)) + display="$(echo "$display" | sed -r 's/\/[0-9]*//g')" + IFS=' ' read -r -a info <<< "$display" + DISPLAY_LIST+=("$count ${info[3]} ${info[2]}") done } +# populate $WALL_LIST depending on number of displays and images passed +get_wall_list() { -get_user_wall() { - local path="$1" - if [ ! -d "$path" ]; then - USER_WALL="$path" - return - fi - dir=("$path"/*) - dir="${dir[RANDOM % ${#dir[@]}]}" - get_user_wall "$dir" + local paths=("$@") + declare -ga WALL_LIST + + # multiple images and spanning conflict, bail out + if [ "${#paths[@]}" -gt 1 ] && [ "$span_image" = true ]; then + echof err "Can't use --span with multiple images!" + exit 1 + fi + + # if spanning return 1 image + if [ "$span_image" = true ]; then + get_image "${paths[0]}" + + # if # paths is 1 + elif [ "${#paths[@]}" -eq 1 ]; then + for ((i=0; i<${#DISPLAY_LIST[@]}; i++)); do + # add same image to $WALL_LIST for each display + get_image "${paths[0]}" + done + + # if # of paths equals # of displays + elif [ ${#paths[@]} -eq "${#DISPLAY_LIST[@]}" ]; then + for ((i=0; i<${#DISPLAY_LIST[@]}; i++)); do + # add each image to $WALL_LIST + get_image "${paths[$i]}" + done + + # if # of paths differ from # of display, bail out + else + echof err "${#paths[@]} images provided for ${#DISPLAY_LIST[@]} displays!" + exit 1 + fi } +# get image path, append to $WALL_LIST +get_image() { + + local path="$1" + + # we have a file + if [ -f "$path" ]; then + WALL_LIST+=("$path") + return + # we have a directory + elif [ -d "$path" ]; then + dir=("$path"/*) + rdir="${dir[RANDOM % ${#dir[@]}]}" + get_image "$rdir" # <-- calls itself + # not file or directory, bail out + else + echof err "invalid path: $path" + exit 1 + fi + +} + +# scale base image and generate effects resize_and_render () { - # arguments - local base=$1 - local path=$2 - local resolution=$3 + local base="$1" + local path="$2" + local resolution="$3" - # wallpaper - RES_RESIZE="$2/resize.png" - RES_DIM="$2/dim.png" - RES_BLUR="$2/blur.png" - RES_DIMBLUR="$2/dimblur.png" - RES_PIXEL="$2/pixel.png" + # resource paths + RES_RESIZE="$path/resize.png" + RES_DIM="$path/dim.png" + RES_BLUR="$path/blur.png" + RES_DIMBLUR="$path/dimblur.png" + RES_PIXEL="$path/pixel.png" + RES_DIMPIXEL="$path/dimpixel.png" + RES_COLOR="$path/color.png" - # defaults - [[ $blur_level ]] || blur_level=1 - RES_DIM="$2/dim.png" - RES_BLUR="$2/blur.png" - RES_DIMBLUR="$2/dimblur.png" + # resize + base_resize "$base" "$RES_RESIZE" "$resolution" - # defaults - [[ $blur_level ]] || blur_level=1 + # effects + for effect in "${fx_list[@]}"; do + case $effect in + dim) fx_dim "$RES_RESIZE" "$RES_DIM";; + blur) fx_blur "$RES_RESIZE" "$RES_BLUR" "$resolution";; + dimblur) fx_dimblur "$RES_RESIZE" "$RES_DIMBLUR" "$resolution";; + pixel) fx_pixel "$RES_RESIZE" "$RES_PIXEL";; + dimpixel) fx_dimpixel "$RES_RESIZE" "$RES_DIMPIXEL";; + color) fx_color "$RES_COLOR" "$resolution";; + esac + done - echo "Resizing original and applying effects..." +} - # apply resize - eval convert "$base" -resize "$resolution""^" -gravity center -extent "$resolution" "$RES_RESIZE" +# apply resize +base_resize() { - # apply dim - eval convert "$RES_RESIZE" -fill black -colorize 40% "$RES_DIM" + local input="$1" + local output="$2" + local size="$3" - # apply blur - blur_shrink=$(echo "scale=2; 20 / $blur_level" | bc) - blur_sigma=$(echo "scale=2; 0.6 * $blur_level" | bc) - eval convert "$RES_RESIZE" \ - -filter Gaussian \ - -resize "$blur_shrink%" \ - -define "filter:sigma=$blur_sigma" \ - -resize "$resolution^" -gravity center -extent "$resolution" \ - "$RES_BLUR" + echof act "Resizing base image..." + eval convert "$input" \ + -resize "$size""^" \ + -gravity center \ + -extent "$size" \ + "$output" +} - # apply dimblur - eval convert "$RES_DIM" \ - -filter Gaussian \ - -resize "$blur_shrink%" \ - -define "filter:sigma=$blur_sigma" \ - -resize "$resolution^" -gravity center -extent "$resolution" \ - "$RES_DIMBLUR" +# apply dim +fx_dim() { + local input="$1" + local output="$2" - # pixelate - eval convert "$RES_RESIZE" \ - -scale 10% \ - -scale 1000% \ - "$RES_PIXEL" + echof act "Rendering 'dim' effect..." + eval convert "$input" \ + -fill black -colorize "$dim_level"% \ + "$output" +} + +# apply blur +fx_blur() { + local input="$1" + local output="$2" + local size="$3" + + echof act "Rendering 'blur' effect..." + blur_shrink=$(echo "scale=2; 20 / $blur_level" | bc) + blur_sigma=$(echo "scale=2; 0.6 * $blur_level" | bc) + eval convert "$input" \ + -filter Gaussian \ + -resize "$blur_shrink%" \ + -define "filter:sigma=$blur_sigma" \ + -resize "$size^" -gravity center -extent "$size" \ + "$output" +} + +# apply dimblur +fx_dimblur() { + local input="$1" + local output="$2" + local size="$3" + + echof act "Rendering 'dimblur' effect..." + blur_shrink=$(echo "scale=2; 20 / $blur_level" | bc) + blur_sigma=$(echo "scale=2; 0.6 * $blur_level" | bc) + eval convert "$input" \ + -fill black -colorize "$dim_level"% \ + -filter Gaussian \ + -resize "$blur_shrink%" \ + -define "filter:sigma=$blur_sigma" \ + -resize "$size^" -gravity center -extent "$size" \ + "$output" +} + +# pixelate +fx_pixel() { + local input="$1" + local output="$2" + + echof act "Rendering 'pixel' effect..." + IFS=',' read -ra range <<< "$pixel_scale" + eval convert "$input" \ + -scale "${range[0]}"% -scale "${range[1]}"% \ + "$output" +} + +# apply dimpixel +fx_dimpixel() { + local input="$1" + local output="$2" + + echof act "Rendering 'dimpixel' effect..." + IFS=',' read -ra range <<< "$pixel_scale" + eval convert "$input" \ + -fill black -colorize "$dim_level"% \ + -scale "${range[0]}"% -scale "${range[1]}"% \ + "$output" +} + +# create solid color +fx_color() { + local output="$1" + local size="$2" + + echof act "Rendering 'color' effect..." + eval convert -size "$size" canvas:\#"$solid_color" "$RES_COLOR" +} + +# create loginbox rectangle, set $RECTANGLE +create_loginbox () { + RECTANGLE="$CUR_DIR/rectangle.png" + local shadow="$CUR_DIR/shadow.png" + local width height + width=$(logical_px 300 1) + height=$(logical_px 80 2) + convert -size "$width"x"$height" xc:\#"$loginbox" -fill none $RECTANGLE + convert $RECTANGLE \ + \( -clone 0 -background \#"$loginshadow" -shadow 100x5+0+0 \) +swap \ + -background none -layers merge +repage $shadow + composite -compose Dst_Out -gravity center \ + $RECTANGLE $shadow -alpha Set $shadow + convert $shadow $RECTANGLE -geometry +10+10 -composite $RECTANGLE + [[ $shadow ]] && rm $shadow +} + +# create rectangle with description, set $DESCRECT +create_description () { + DESCRECT="$CUR_DIR/description.png" + local shadow="$CUR_DIR/shadow.png" + convert -background none -family "$(fc-match "$font" family)" -style Normal -pointsize 14 -fill \#"$datecolor" label:"\ $description\ " -bordercolor \#"$loginbox" -border 10 $DESCRECT + convert $DESCRECT \ + \( -clone 0 -background \#"$loginshadow" -shadow 100x5+0+0 \) +swap \ + -background none -layers merge +repage $shadow + composite -compose Dst_Out -gravity center \ + $DESCRECT $shadow -alpha Set $shadow + convert $shadow $DESCRECT -geometry +10+10 -composite $DESCRECT + [[ $shadow ]] && rm $shadow } # delete and recreate directory @@ -227,297 +445,387 @@ purge_cache () { if [[ -d "$1" ]]; then rm -r "$1" fi - mkdir -p "$1" + mkdir -p "$1" } -# update locker and wallpaper images +# update lockscreen and wallpaper images update () { - wallpaper=$1 - rectangles=" " + local images=("$@") - get_user_wall "$wallpaper" # Returns USER_WALL - echo "Original: $USER_WALL" + echof act "Updating image cache..." + mkdir -p "$CACHE_DIR" &>/dev/null - get_display_list # Returns DLIST - get_total_size # Return TOTAL_SIZE + get_display_list # DISPLAY_LIST + get_total_size # TOTAL_SIZE + echof info "Detected ${#DISPLAY_LIST[@]} display(s) @ $TOTAL_SIZE total resolution" - # create base images per display - for DISP in "${DLIST[@]}"; do - DNUM="$(cut -d" " -f1 <<<"${DISP}")" - DDEV="$(cut -d" " -f2 <<<"${DISP}")" - DGEO=($(cut -d" " -f3 <<<"${DISP}")) - DRES=(${DGEO[0]//[+]/ }) - DPOS="+${DRES[1]}+${DRES[2]}" - DPATH="$CACHE_DIR/$DNUM-$DDEV" + get_wall_list "${images[@]}" # WALL_LIST + echof info "Original image(s): ${WALL_LIST[*]##*/}" - #get_geometry $DGEO # Returns SCREEN_* - if [[ $DNUM -eq "$display_on" ]] || [[ "$display_on" -eq 0 ]]; then - SRA=(${DGEO//[x+]/ }) - CX=$((${SRA[2]} + $(logical_px 25))) - CY=$((${SRA[3]} + ${SRA[1]} - $(logical_px 30))) - rectangles+="rectangle $CX,$CY $((CX+$(logical_px 300))),$((CY-$(logical_px 80))) " + # Prepare description box to obtain width for positioning + local descwidth + local descheight + if [ -z "$description" ]; then + descwidth=0 + descheight=0 + else + create_description + descwidth=$(identify -format "%[fx:w]" "$DESCRECT") + descheight=$(identify -format "%[fx:h]" "$DESCRECT") + fi + + for ((i=0; i<${#DISPLAY_LIST[@]}; i++)); do + display="${DISPLAY_LIST[$i]}" + USER_WALL="${WALL_LIST[$i]}" + + # escape spaces for IM + if echo "$USER_WALL" | grep -E -q "[[:space:]]"; then + USER_WALL="${USER_WALL// /\\ }" fi - echo "Found: $DDEV ($DNUM)" - echo "Resolution: ${DRES[0]}" + IFS=' ' read -r -a dinfo <<< "$display" + local id="${dinfo[0]}" + local device="${dinfo[1]}" + local geometry="${dinfo[2]}" - purge_cache $DPATH + read -r -a cols <<< "${geometry//[x+-]/ }" + local position="${geometry#*${cols[1]}}" + local resolution="${geometry%${position}*}" - # we only need one set of images when spanning - if [ "$span_image" = true ] && [ $DNUM -gt 1 ]; then - continue + if [[ $id -eq "$display_on" ]] || [[ "$display_on" -eq 0 ]]; then + + IFS='x' read -r -a dimension <<< "$resolution" + res_x="${dimension[0]}" + res_y="${dimension[1]}" + read -r -a val <<< "${position//[+-]/ }" + read -r -a sym <<< "${position//[0-9]/ }" + pos_x="${sym[0]}${val[0]}" + pos_y="${sym[1]}${val[1]}" + + rect_x=$((pos_x + $(logical_px 15 1))) + rect_y=$((pos_y + res_y - $(logical_px 120 2))) + positions+=("+$((rect_x))+$((rect_y))") + + descrect_x=$((pos_x + res_x - descwidth - $(logical_px 15 1))) + descrect_y=$((pos_y + res_y - descheight - $(logical_px 20 2))) + positions_desc+=("+$((descrect_x))+$((descrect_y))") fi + local path="$CACHE_DIR/$id-$device" + purge_cache "$path" + if [ "$span_image" = true ]; then - # render wallpaper at total display size (3840x1080) - resize_and_render $USER_WALL $DPATH $TOTAL_SIZE + if [ "$id" -gt 1 ]; then + continue + else + device="[span]" + id="*" + resolution="$TOTAL_SIZE" + fi + fi + + echof info "Processing display: $device ($id)" + echof info "Resolution: $resolution" + + if [ "$span_image" = true ]; then + resize_and_render "$USER_WALL" "$path" "$resolution" else - # render wallpaper at each display size - resize_and_render $USER_WALL $DPATH ${DRES[0]} - # add to parameters for position on canvas - PARAM_RESIZE="$PARAM_RESIZE $RES_RESIZE -geometry $DPOS -composite " - PARAM_DIM="$PARAM_DIM $RES_DIM -geometry $DPOS -composite " - PARAM_BLUR="$PARAM_BLUR $RES_BLUR -geometry $DPOS -composite " - PARAM_DIMBLUR="$PARAM_DIMBLUR $RES_DIMBLUR -geometry $DPOS -composite " - PARAM_PIXEL="$PARAM_PIXEL $RES_PIXEL -geometry $DPOS -composite " + resize_and_render "$USER_WALL" "$path" "$resolution" + + PARAM_RESIZE="$PARAM_RESIZE $RES_RESIZE -geometry $position -composite " + PARAM_DIM="$PARAM_DIM $RES_DIM -geometry $position -composite " + PARAM_BLUR="$PARAM_BLUR $RES_BLUR -geometry $position -composite " + PARAM_DIMBLUR="$PARAM_DIMBLUR $RES_DIMBLUR -geometry $position -composite " + PARAM_PIXEL="$PARAM_PIXEL $RES_PIXEL -geometry $position -composite " + PARAM_DIMPIXEL="$PARAM_DIMPIXEL $RES_DIMPIXEL -geometry $position -composite " + PARAM_COLOR="$PARAM_COLOR $RES_COLOR -geometry $position -composite " fi done - purge_cache $CUR_DIR + purge_cache "$CUR_DIR" - if [ "$span_image" = true ] || [ ${#DLIST[@]} -lt 2 ]; then - echo "Copying final wallpaper images..." - cp $RES_RESIZE $CUR_W_RESIZE - cp $RES_DIM $CUR_W_DIM - cp $RES_BLUR $CUR_W_BLUR - cp $RES_DIMBLUR $CUR_W_DIMBLUR - cp $RES_PIXEL $CUR_W_PIXEL + if [ "$span_image" = true ] || [ ${#DISPLAY_LIST[@]} -lt 2 ]; then + echof act "Rendering final wallpaper images..." + [[ -f "$RES_RESIZE" ]] && cp $RES_RESIZE $CUR_W_RESIZE + [[ -f "$RES_DIM" ]] && cp $RES_DIM $CUR_W_DIM + [[ -f "$RES_BLUR" ]] && cp $RES_BLUR $CUR_W_BLUR + [[ -f "$RES_DIMBLUR" ]] && cp $RES_DIMBLUR $CUR_W_DIMBLUR + [[ -f "$RES_PIXEL" ]] && cp $RES_PIXEL $CUR_W_PIXEL + [[ -f "$RES_DIMPIXEL" ]] && cp $RES_DIMPIXEL $CUR_W_DIMPIXEL + [[ -f "$RES_COLOR" ]] && cp $RES_COLOR $CUR_W_COLOR else - echo "Creating canvas: $TOTAL_SIZE" - convert -size $TOTAL_SIZE 'xc:black' $CUR_W_RESIZE - convert -size $TOTAL_SIZE 'xc:black' $CUR_W_DIM - convert -size $TOTAL_SIZE 'xc:black' $CUR_W_BLUR - convert -size $TOTAL_SIZE 'xc:black' $CUR_W_DIMBLUR - convert -size $TOTAL_SIZE 'xc:black' $CUR_W_PIXEL + echof act "Creating canvas: $TOTAL_SIZE" + [[ -f "$RES_RESIZE" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_RESIZE + [[ -f "$RES_DIM" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_DIM + [[ -f "$RES_BLUR" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_BLUR + [[ -f "$RES_DIMBLUR" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_DIMBLUR + [[ -f "$RES_PIXEL" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_PIXEL + [[ -f "$RES_DIMPIXEL" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_DIMPIXEL + [[ -f "$RES_COLOR" ]] && convert -size $TOTAL_SIZE 'xc:blue' $CUR_W_COLOR - echo "Rendering final wallpaper images..." - convert $CUR_W_RESIZE $PARAM_RESIZE $CUR_W_RESIZE - convert $CUR_W_DIM $PARAM_DIM $CUR_W_DIM - convert $CUR_W_BLUR $PARAM_BLUR $CUR_W_BLUR - convert $CUR_W_DIMBLUR $PARAM_DIMBLUR $CUR_W_DIMBLUR - convert $CUR_W_PIXEL $PARAM_PIXEL $CUR_W_PIXEL + echof act "Rendering final wallpaper images..." + [[ -f "$CUR_W_RESIZE" ]] && convert $CUR_W_RESIZE $PARAM_RESIZE $CUR_W_RESIZE + [[ -f "$CUR_W_DIM" ]] && convert $CUR_W_DIM $PARAM_DIM $CUR_W_DIM + [[ -f "$CUR_W_BLUR" ]] && convert $CUR_W_BLUR $PARAM_BLUR $CUR_W_BLUR + [[ -f "$CUR_W_DIMBLUR" ]] && convert $CUR_W_DIMBLUR $PARAM_DIMBLUR $CUR_W_DIMBLUR + [[ -f "$CUR_W_PIXEL" ]] && convert $CUR_W_PIXEL $PARAM_PIXEL $CUR_W_PIXEL + [[ -f "$CUR_W_DIMPIXEL" ]] && convert $CUR_W_DIMPIXEL $PARAM_DIMPIXEL $CUR_W_DIMPIXEL + [[ -f "$CUR_W_COLOR" ]] && convert $CUR_W_COLOR $PARAM_COLOR $CUR_W_COLOR fi - echo "Rendering final locker images..." - convert "$CUR_W_RESIZE" -draw "fill #$loginbox $rectangles" "$CUR_L_RESIZE" - convert "$CUR_W_DIM" -draw "fill #$loginbox $rectangles" "$CUR_L_DIM" - convert "$CUR_W_BLUR" -draw "fill #$loginbox $rectangles" "$CUR_L_BLUR" - convert "$CUR_W_DIMBLUR" -draw "fill #$loginbox $rectangles" "$CUR_L_DIMBLUR" - convert "$CUR_W_PIXEL" -draw "fill #$loginbox $rectangles" "$CUR_L_PIXEL" + echof act "Rendering final lockscreen images..." + + create_loginbox + for pos in "${positions[@]}"; do + PARAM_RECT="$PARAM_RECT $RECTANGLE -geometry $pos -composite " + done + + if [ ! -z "$description" ]; then + create_description + for descpos in "${positions_desc[@]}"; do + PARAM_RECT="$PARAM_RECT $DESCRECT -geometry $descpos -composite " + done + fi + + [[ -f "$CUR_W_RESIZE" ]] && convert $CUR_W_RESIZE $PARAM_RECT $CUR_L_RESIZE + [[ -f "$CUR_W_DIM" ]] && convert $CUR_W_DIM $PARAM_RECT $CUR_L_DIM + [[ -f "$CUR_W_BLUR" ]] && convert $CUR_W_BLUR $PARAM_RECT $CUR_L_BLUR + [[ -f "$CUR_W_DIMBLUR" ]] && convert $CUR_W_DIMBLUR $PARAM_RECT $CUR_L_DIMBLUR + [[ -f "$CUR_W_PIXEL" ]] && convert $CUR_W_PIXEL $PARAM_RECT $CUR_L_PIXEL + [[ -f "$CUR_W_DIMPIXEL" ]] && convert $CUR_W_DIMPIXEL $PARAM_RECT $CUR_L_DIMPIXEL + [[ -f "$CUR_W_COLOR" ]] && convert $CUR_W_COLOR $PARAM_RECT $CUR_L_COLOR + + [[ $RECTANGLE ]] && rm "$RECTANGLE" + [[ $DESCRECT ]] && rm "$DESCRECT" + + echof ok "Done" + } - +# set wallpaper with effect wallpaper() { - local fopt + + local effect="$1" + + # make wallpaper span displays get_display_list - if [ "$span_image" = true ] || [[ "${#DLIST[@]}" -gt 1 ]]; then - fopt="--no-xinerama" + if [ "$span_image" = true ] || [[ "${#DISPLAY_LIST[@]}" -gt 1 ]]; then + wallpaper_cmd="$wallpaper_cmd --no-xinerama" fi - case "$1" in - '') - # set resized image as wallpaper if no argument is supplied by user - feh --bg-fill "$fopt" "$CUR_W_RESIZE" - ;; - dim) - # set dimmed image as wallpaper - feh --bg-fill "$fopt" "$CUR_W_DIM" - ;; - - blur) - # set blurred image as wallpaper - feh --bg-fill "$fopt" "$CUR_W_BLUR" - ;; - - dimblur) - # set dimmed + blurred image as wallpaper - feh --bg-fill "$fopt" "$CUR_W_DIMBLUR" - ;; - - pixel) - # set pixelated image as wallpaper - feh --bg-fill "$fopt" "$CUR_W_PIXEL" - ;; - esac + # set wallpaper + case "$effect" in + dim) wallpaper="$CUR_W_DIM";; + blur) wallpaper="$CUR_W_BLUR";; + dimblur) wallpaper="$CUR_W_DIMBLUR";; + pixel) wallpaper="$CUR_W_PIXEL";; + dimpixel) wallpaper="$CUR_W_DIMPIXEL";; + color) wallpaper="$CUR_W_COLOR";; + *) wallpaper="$CUR_W_RESIZE";; + esac + eval "$wallpaper_cmd $wallpaper" } +# wrap echo with fancy prefix +echof() { -empty() { - if [ -f $CUR_L_RESIZE ]; then - echo -e "\nSeems you haven't provided any arguments. See below for usage details." - else - echo 'Important: Update the image cache (e.g. betterlockscreen -u path/to/image.jpg).' - echo - echo ' Image cache must be updated to initially configure or update the wallpaper used.' - fi + local prefix="$1" + local message="$2" - echo - echo 'For other sets of options and help, use the help command.' - echo 'e.g. betterlockscreen -h or betterlockscreen --help' - echo - echo 'See: https://github.com/pavanjadhaw/betterlockscreen for additional info...' - exit 1 + case "$prefix" in + header) msgpfx="[\e[1;95mB\e[m]";; + info) msgpfx="[\e[1;97m=\e[m]";; + act) msgpfx="[\e[1;92m*\e[m]";; + ok) msgpfx="[\e[1;93m+\e[m]";; + error) msgpfx="[\e[1;91m!\e[m]";; + *) msgpfx="";; + esac + echo -e "$msgpfx $message" } - +# help message usage() { - echo 'Important: Update the image cache (e.g. betterlockscreen -u path/to/image.jpg).' - echo ' Image cache must be updated to initially configure or update wallpaper used' - echo - echo - echo 'See: https://github.com/pavanjadhaw/betterlockscreen for additional info...' - echo - echo - echo 'Options:' - echo - echo ' -h --help' - echo ' For help (e.g. betterlockscreen -h or betterlockscreen --help).' - echo - echo - echo ' -u --update' - echo ' to update image cache, you should do this before using any other options' - 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.' - echo - echo - echo ' -l --lock' - 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)' - echo - echo - echo ' -s --suspend' - 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)' - echo - echo - echo ' -w --wall' - echo ' you can also set lockscreen background as wallpaper' - 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)' - echo - echo - echo ' -d --display' - echo ' to be used after -u' - echo ' used to set which screen to display login box.' - echo ' E.g: betterlockscreen -u path/to/image.png -d 1' - echo ' E.g: betterlockscreen -u path/to/image.png --display 2' - echo - echo - echo ' --span' - echo ' to be used after -u' - echo ' used to create wall and locker images that span multiple displays.' - echo ' E.g: betterlockscreen -u path/to/image.png --span' - echo - echo - echo ' -b --blur' - echo ' to be used after -u' - echo ' used to set blur intensity. Default to 1.' - echo ' E.g: betterlockscreen -u path/to/image.png -b 3' - echo ' E.g: betterlockscreen -u path/to/image.png --blur 0.5' - echo - echo - echo ' -t --text' - echo ' to set custom lockscreen text (max 31 chars)' - echo " E.g: betterlockscreen -l dim -t \"Don't touch my machine!\"" - echo ' E.g: betterlockscreen --text "Hi, user!" -s blur' + echo + echo "Usage: betterlockscreen [-u ] [-l ] [-w ]" + echo + echo " -u --update " + echo " Update lock screen image" + echo + echo " -l --lock " + echo " Lock screen with cached image" + echo + echo " -w --wall " + echo " Set wallpaper with cached image" + echo + echo "Additional arguments:" + echo + echo " --display " + echo " Set display to draw loginbox" + echo + echo " --span" + echo " Scale image to span multiple displays" + echo + echo " --off " + echo " Turn display off after N minutes" + echo + echo " --fx " + echo " List of effects to generate" + echo + echo " --desc " + echo " Set a description for the new lock screen image" + echo " (Only has an effect in combination with --update)" + echo + echo " --show-layout" + echo " Show current keyboard layout" + echo + echo " --wallpaper-cmd " + echo " to set your custom wallpaper setter" + echo + echo " --time-format " + echo " to set the time format used by i3lock-color" + echo + echo " -- " + echo " Pass additional arguments to i3lock" + echo + echo "Effects arguments:" + echo + echo " --dim " + echo " Dim image N percent (0-100)" + echo + echo " --blur " + echo " Blur image N amount (0.0-1.0)" + echo + echo " --pixel " + echo " Pixelate image with N shrink and N grow (unsupported)" + echo + echo " --color " + echo " Solid color background with HEX" + echo + exit 1 } +echof header "betterlockscreen" -# Options -[[ "$1" = '' ]] && empty +init_config +# show usage when no arguments passed +[[ "$1" = "" ]] && usage + +# process arguments +lockargs=() for arg in "$@"; do - [[ "${arg:0:1}" = '-' ]] || continue + [[ "${arg:0:1}" = '-' ]] || continue - case "$1" in - -h | --help) - usage - break - ;; + case "$1" in + -u | --update) + runupdate=true + imagepaths+=("$2") + shift 2 + ;; - -s | --suspend) - runsuspend=true - ;& + -s | --suspend) + runsuspend=true + ;& - -l | --lock) - runlock=true - [[ $runsuspend ]] || lockargs="$lockargs -n" - [[ ${2:0:1} = '-' ]] && shift 1 || { lockstyle="$2"; shift 2; } - ;; + -l | --lock) + runlock=true + if [[ ${2:0:1} = '-' ]]; then + shift 1 + else + lockstyle="$2"; shift 2 + fi + ;; - -w | --wall | --wallpaper) - wallpaper "$2" - shift 2 - ;; + -w | --wall) + wallpaper "$2" + shift 2 + ;; - -u | --update) - runupdate=true - imagepath="$2" - shift 2 - ;; + --wallpaper-cmd) + wallpaper_cmd="$2" + shift 2 + ;; - -t | --text) - locktext="$2" - shift 2 - ;; + --time-format) + time_format="$2" + shift 2 + ;; - -d | --display) - display_on="$2" - shift 2 - ;; + --display) + display_on="$2" + shift 2 + ;; - --span) - span_image=true + --span) + span_image=true shift 1 - ;; + ;; - -b | --blur) - blur_level="$2" - shift 2 - ;; + --off) + lock_timeout="$2" + shift 2 + ;; - --) - lockargs="$lockargs ${@:2}" - break - ;; + --text) + locktext="$2" + shift 2 + ;; - *) - echo "invalid argument: $1" - break - ;; - esac + --show-layout) + keylayout="--keylayout 2"; + shift 1 + ;; + + --fx) + IFS=',' read -ra fx_list <<< "$2" + shift 2 + ;; + + --dim) + dim_level="$2" + shift 2 + ;; + + --blur) + blur_level="$2" + shift 2 + ;; + + --pixel) + pixel_scale="$2" + shift 2 + ;; + + --color) + solid_color="${2//\#/}" + shift 2 + ;; + + --desc) + description="$2" + shift 2 + ;; + + --) + lockargs+=("${@:2}") + break + ;; + + -h | --help | *) + usage + break + ;; + esac done -# some defaults -[[ $display_on ]] || display_on=0 -[[ $span_image ]] || span_image=false - # Run image generation -[[ $runupdate ]] && update "$imagepath" +[[ $runupdate ]] && update "${imagepaths[@]}" # Activate lockscreen +[[ $runsuspend ]] || lockargs+=(-n) [[ $runlock ]] && lockselect "$lockstyle" && \ - { [[ $runsuspend ]] && systemctl suspend; } + { [[ $runsuspend ]] && systemctl suspend; } exit 0 \ No newline at end of file diff --git a/examples/betterlockscreenrc b/examples/betterlockscreenrc index f4b65b5..fedde94 100644 --- a/examples/betterlockscreenrc +++ b/examples/betterlockscreenrc @@ -1,18 +1,29 @@ -# configuration file for betterlockscreen +# ~/.config/betterlockscreenrc -insidecolor=00000000 +# default options +display_on=0 +span_image=false +lock_timeout=5 +fx_list=(dim blur dimblur pixel dimpixel color) +dim_level=40 +blur_level=1 +pixel_scale=10,1000 +solid_color=333333 + +# default theme +loginbox=00000066 +loginshadow=00000000 +locktext="Type password to unlock..." +font="sans-serif" ringcolor=ffffffff +insidecolor=00000000 +separatorcolor=00000000 +ringvercolor=ffffffff +insidevercolor=00000000 +ringwrongcolor=ffffffff +insidewrongcolor=d23c3dff keyhlcolor=d23c3dff bshlcolor=d23c3dff -separatorcolor=00000000 -insidevercolor=00000000 -insidewrongcolor=d23c3dff -ringvercolor=ffffffff -ringwrongcolor=ffffffff verifcolor=ffffffff timecolor=ffffffff datecolor=ffffffff -loginbox=00000066 -font="sans-serif" -display_on=0 -span_image=false