diff options
author | sinanmohd <sinan@firemail.cc> | 2023-08-23 18:42:29 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-08-23 18:42:29 +0530 |
commit | d5d7399ba108f5d8a082c1a8ff082bf7d7e6b9de (patch) | |
tree | 56c1af1c48902eca8bfec80f2aad50975ba21dd3 /.local/bin | |
parent | dc1e0aabb05e5900b76b90846800c203b289e49a (diff) |
wayland: blurred lockscreen support
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/cwall | 86 |
1 files changed, 45 insertions, 41 deletions
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 |