aboutsummaryrefslogtreecommitdiff
path: root/pkgs/theme/swaybackground.sh
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2022-02-21 21:54:09 +0100
committerKarel Kočí <cynerd@email.cz>2022-06-10 14:05:48 +0200
commit93b0545d11bf8c7f065203f7f3eaf1d0e3730dce (patch)
treeda93fa5fcd14c493d8ccd86c98f40d26c9697869 /pkgs/theme/swaybackground.sh
downloadnixos-personal-93b0545d11bf8c7f065203f7f3eaf1d0e3730dce.tar.gz
nixos-personal-93b0545d11bf8c7f065203f7f3eaf1d0e3730dce.tar.bz2
nixos-personal-93b0545d11bf8c7f065203f7f3eaf1d0e3730dce.zip
Add initial version
Diffstat (limited to 'pkgs/theme/swaybackground.sh')
-rwxr-xr-xpkgs/theme/swaybackground.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/pkgs/theme/swaybackground.sh b/pkgs/theme/swaybackground.sh
new file mode 100755
index 0000000..0999943
--- /dev/null
+++ b/pkgs/theme/swaybackground.sh
@@ -0,0 +1,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