From 93b0545d11bf8c7f065203f7f3eaf1d0e3730dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 21 Feb 2022 21:54:09 +0100 Subject: Add initial version --- pkgs/theme/swaybackground.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 pkgs/theme/swaybackground.sh (limited to 'pkgs/theme/swaybackground.sh') 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 -- cgit v1.2.3