aboutsummaryrefslogtreecommitdiff
path: root/pkgs/theme/swaybackground.sh
blob: 099994339d88160ccbdb2bccb0c6deb5de2dd1cc (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
36
37
38
39
40
41
42
43
#!/usr/bin/env bash

_background() {
	local resolution="${1:-1920x1080}"
	case "$resolution" in
		1920x1080|2560x1440|2560x1600)
			;;
		*)
			resolution="1920x1080"
			;;
	esac
	find "$BACKGROUND_LNXPCS" -type f -name "*-$resolution.png" | shuf -n 1
}

background() {
	local width="$1"
	local height="$2"
	local res
	res="$(_background "${width}x${height}")"
	if [ -n "$res" ]; then
		res="$(_background)"
	fi
	echo "$res"
}

set_backgrounds() {
	local ipc="$1"
	swaymsg -t get_outputs | jq -r '.[] | [.name,.rect.width,.rect.height] | join(",")' \
		| while IFS=, read -r name width height; do
			swaymsg $ipc \
				output "$name" \
				background "$(background "$width" "$height")" fill
		done
}

if [ -n "$WAYLAND_DISPLAY" ]; then
	set_backgrounds
else
	find "/run/user/$(id -u)/" -name "sway-ipc*" \
		| while read -r ipc; do
			set_backgrounds "-s '$ipc'"
		done
fi