30 lines
1.1 KiB
Bash
Executable file
30 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source "${HOME}/.local/lib/sp-functions"
|
|
|
|
getwpno() {
|
|
wpno=$(printf "%02d\n" $(($(echo "$1" | awk '{print $1}' | grep -o "^[1-9]*")-1)) | cut -c 1 | sed 's/[^0-9]*//g')
|
|
echo "${wpno}" | tee "${cache_dir}/displays/${2}"
|
|
}
|
|
|
|
setbg() {
|
|
for d in ${outputs[@]};do
|
|
d_wpno=$(cat "${cache_dir}/displays/${d}")
|
|
swaymsg output "${d}" bg "$HOME/.config/sway/assets/wallpaper/${d}/${d_wpno}.jpg" fill
|
|
done
|
|
}
|
|
|
|
output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | {name} | "\(.name)"')
|
|
outputs=( $(swaymsg -t get_outputs | jq -r '.[] | {name} | "\(.name)"') )
|
|
workspace=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused) | {name} | "\(.name)"')
|
|
getwpno "${workspace}" "${output}"
|
|
setbg "${output}" "${wpno}"
|
|
|
|
swaymsg -r -t subscribe -m '["workspace"]' | jq -rc --unbuffered 'select(.change == "focus") | .current | "\(.name) \(.output)"' | while read name output;do
|
|
wsno=$(($(echo "$name" | awk '{print $1}' | grep -o "^[1-9]*")-1))
|
|
wpno_last=$(cat "${cache_dir}/displays/${output}")
|
|
getwpno "${name}" "${output}"
|
|
if [[ "${wpno}" -ne "${wpno_last}" ]];then
|
|
setbg "${output}" "${wpno}"
|
|
fi
|
|
done
|