34 lines
844 B
Bash
Executable file
34 lines
844 B
Bash
Executable file
#!/bin/bash
|
|
|
|
getpids() {
|
|
pids=( $(pgrep swaybg) )
|
|
}
|
|
|
|
killpids() {
|
|
for i in ${pids[@]};do
|
|
kill "${i}" && echo "killed ${i}"
|
|
done
|
|
}
|
|
|
|
setbg() {
|
|
output="$1"
|
|
wpno_last="${wpno}"
|
|
wpno=$(printf "%02d\n" $(($(echo "$2" | awk '{print $1}' | grep -o "^[1-9]*")-1)) | cut -c 1)
|
|
[[ "${wpno}" -ne "${wpno_last}" ]] && swaybg -i "$HOME/.config/sway/assets/wallpaper/${output}/${wpno}.jpg" -o "${output}" &
|
|
}
|
|
|
|
getpids
|
|
|
|
output=$(swaymsg -t get_outputs | jq -r '.[] | {name} | "\(.name)"')
|
|
workspace=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused) | {name} | "\(.name)"')
|
|
setbg "${output}" "${workspace}"
|
|
|
|
killpids
|
|
|
|
swaymsg -r -t subscribe -m '["workspace"]' | jq -rc --unbuffered 'select(.change == "focus") | .current | "\(.name) \(.output)"' | while read name output;do
|
|
|
|
getpids
|
|
setbg "${output}" "${name}"
|
|
killpids
|
|
|
|
done
|