summaryrefslogtreecommitdiff
path: root/.local/bin/makewall
blob: 34586766ba6af120d3f3ec6912b9603c7ff62bad (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
30
31
32
33
34
35
#!/bin/sh

wallDir="${XDG_CONFIG_HOME:-$HOME}/wallpapers"

# Acquire the list of connected displays and their models
displays="$(wlr-randr --json | jq -r '.[] | select(.enabled) | "\(.name) \(.model)"')"
echo "$displays"

# 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() {
  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
while IFS=' ' read -r name model; do
  sanitized_model=$(sanitize_model "$model")
  setDisplay "$name" "$sanitized_model"
done <<< "$displays"