From d5d7399ba108f5d8a082c1a8ff082bf7d7e6b9de Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 23 Aug 2023 18:42:29 +0530 Subject: wayland: blurred lockscreen support --- .local/bin/cwall | 86 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) (limited to '.local/bin/cwall') diff --git a/.local/bin/cwall b/.local/bin/cwall index c20abb3..ad670fc 100755 --- a/.local/bin/cwall +++ b/.local/bin/cwall @@ -1,8 +1,9 @@ #!/bin/sh -bgpid="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/swaybg.pid" -bgroot="${XDG_DATA_HOME:-$HOME/.local/share}" -bgimg="${bgroot}/wallpaper" +bgdpid="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/swaybg.pid" +bgroot="${XDG_DATA_HOME:-$HOME/.local/share}/wallpaper" +bgdesk="${bgroot}/desktop" +bglock="${bgroot}/lockscreen" die() { @@ -32,6 +33,11 @@ dep_check() unset dep } +mimetype() +{ + file --brief --dereference --mime-type "$1" +} + randimg() { # usage: randbg dir @@ -52,18 +58,18 @@ randimg() -o -iname "*.webp" | shuf -n1)" [ -z "$img" ] && - break; + return 1 # make sure the file is an actual image - case "$(file --brief --dereference --mime-type "$img")" in + case "$(mimetype "$img")" in "image/"*) echo "$img" - break; + break ;; *) attempt=$((attempt + 1)) [ "$attempt" -gt "$maxattempts" ] && - break; + return 1 esac done } @@ -72,39 +78,37 @@ updatewall() { : "${1:?}" - rm -f "$bgimg" - cp "$1" "$bgimg" - - [ -s "$bgpid" ] && - kill -9 "$(cat "$bgpid")" - swaybg --mode fill --image "$bgimg" > /dev/null 2>&1 & - echo $! > "$bgpid" -} - -main() -{ - [ ! -r "$1" ] && - usage && exit 1; - [ ! -d "$bgroot" ] && - mkdir -p "$bgroot" - - dep_check swaybg file - - case "$(file --brief --dereference --mime-type "$1")" in - "image/"*) - updatewall "$1" - ;; - "inode/directory") - img=$(randimg "$1") - [ -z "$img" ] && - die "no image file in directory" - - updatewall "$img" - ;; - *) - die "invalid image file" - ;; - esac + rm -f "$bgdesk" + cp "$1" "$bgdesk" + + [ -s "$bgdpid" ] && + kill -9 "$(cat "$bgdpid")" + swaybg --mode fill --image "$bgdesk" > /dev/null 2>&1 & + echo $! > "$bgdpid" + + if command -v ffmpeg > /dev/null; then + rm -f "$bglock" + ffmpeg -loglevel quiet \ + -i "$bgdesk" -vf "boxblur=50" -f mjpeg "$bglock" + else + ln -fs "$bgdesk" "$bglock" + fi } -main "$@" +######## +# MAIN # +######## + +[ ! -r "$1" ] && usage && exit 1 +[ ! -d "$bgroot" ] && mkdir -p "$bgroot" +dep_check swaybg file + +case "$(mimetype "$1")" in +"image/"*) updatewall "$1" ;; +"inode/directory") + img=$(randimg "$1") || + die "no image file in directory" + updatewall "$img" + ;; +*) die "invalid image file" +esac -- cgit v1.2.3