summaryrefslogtreecommitdiff
path: root/.config/niri/set-backdrop.sh
blob: 32e4144d8353e8a8339022f90f6207892d6d4208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
# Generate a blurred copy of WALLPAPER and set it as the awww backdrop layer.
set -eu
WP="${1:?usage: set-backdrop.sh <wallpaper>}"
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/niri-backdrop"
mkdir -p "$CACHE_DIR"
name="$(basename "${WP%.*}")"
blur="$CACHE_DIR/${name}-blur.jpg"
# (re)generate the blur only if it is missing
[ -f "$blur" ] || magick "$WP" -blur 0x40 -quality 85 "$blur"
# wait for the backdrop daemon socket, then set the image
for _ in 1 2 3 4 5 6 7 8; do
    if awww img --namespace backdrop "$blur" 2>/dev/null; then
        exit 0
    fi
    sleep 0.5
done
echo "set-backdrop: awww backdrop daemon not reachable" >&2
exit 1