summaryrefslogtreecommitdiff
path: root/.config/niri/set-backdrop.sh
blob: efd02b392ee09661743bf57f1e8ac7c81801507f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Push a blurred copy of a wallpaper to the awww-daemon backdrop namespace.
# Prefers a pre-made <name>-blur.<ext> sibling; otherwise generates one into the cache.
# Used by theme-switcher.sh and apply-colors.sh for the niri Overview backdrop.

set -euo pipefail

IMG="${1:-}"
if [ -z "$IMG" ] || [ ! -f "$IMG" ]; then
    echo "usage: $0 <image>" >&2
    exit 1
fi

EXT="${IMG##*.}"
SIBLING="${IMG%.*}-blur.${EXT}"
if [ -f "$SIBLING" ]; then
    BLURRED="$SIBLING"
else
    CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/niri-backdrop"
    mkdir -p "$CACHE_DIR"
    BASE=$(basename "${IMG%.*}")
    BLURRED="$CACHE_DIR/${BASE}-blur.jpg"
    if [ ! -f "$BLURRED" ] || [ "$IMG" -nt "$BLURRED" ]; then
        magick "$IMG" -blur 0x16 -quality 90 "$BLURRED"
    fi
fi

awww img "$BLURRED" -n backdrop
echo "$BLURRED" >/tmp/current_backdrop_state