diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-09-02 23:34:01 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-09-02 23:34:01 -0400 |
commit | 43dbb32d741e11f8e06341f515944ec757d4578f (patch) | |
tree | c100c1a137e1668aa725ce6c0a94794f37b6a1c2 /.local/bin/makewall | |
parent | 21bd4aae35ab8b3bd10216f76417567086c78abf (diff) |
Diffstat (limited to '.local/bin/makewall')
-rwxr-xr-x | .local/bin/makewall | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/.local/bin/makewall b/.local/bin/makewall index 614d030..3458676 100755 --- a/.local/bin/makewall +++ b/.local/bin/makewall @@ -2,29 +2,34 @@ wallDir="${XDG_CONFIG_HOME:-$HOME}/wallpapers" -# Acquire the list of connected displays -displays="$(wlr-randr --json | jq -r '.[] | select(.enabled) | .name')" +# Acquire the list of connected displays and their models +displays="$(wlr-randr --json | jq -r '.[] | select(.enabled) | "\(.name) \(.model)"')" echo "$displays" -# If there is a wallpaper with a filename matching the display -# name, set it as the wallpaper for that display. -# ex: DP-1.jpg and DP-1.png are both valid filenames -# Otherwise, set the wallpaper to the default wallpaper -# (default.png or default.jpg) +# Sanitize the model names by replacing spaces with hyphens +sanitize_model() { + echo "$1" | sed 's/\s/-/g' +} + +# If there is a wallpaper with a filename matching the display name or sanitized model, +# set it as the wallpaper for that display. setDisplay() { - case $(ls $wallDir) in - *"$1"*) - wall=$(ls $wallDir | grep "$1" | head -n 1) - ;; - *) - wall=$(ls $wallDir | grep "default" | head -n 1) - ;; - esac - swaybg --output $1 -m fill --image $wallDir/$wall & + name="$1" + model="$2" + case $(ls $wallDir) in + *"$name"*|*"$model"*) + wall=$(ls $wallDir | grep -E "$name|$model" | head -n 1) + ;; + *) + wall=$(ls $wallDir | grep "default" | head -n 1) + ;; + esac + swaybg --output "$name" -m fill --image "$wallDir/$wall" & } # Set the wallpaper for each display -killall swaybg > /dev/null 2>&1 -for display in $displays; do - setDisplay $display -done +killall swaybg >/dev/null 2>&1 +while IFS=' ' read -r name model; do + sanitized_model=$(sanitize_model "$model") + setDisplay "$name" "$sanitized_model" +done <<< "$displays" |