2024-03-30 14:30:52 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-03-30 21:05:07 +00:00
|
|
|
. "$(dirname "$0")/track_anything.sh"
|
|
|
|
|
2024-03-30 14:30:52 +00:00
|
|
|
poll() {
|
|
|
|
swaymsg -t get_tree |
|
|
|
|
jq -c --unbuffered '.
|
|
|
|
# prep the output var
|
|
|
|
| {} as $out
|
|
|
|
|
|
|
|
# find the count of scratch windows that are exposed
|
|
|
|
| [.. | select(.type=="workspace" and .num == null)? | .focus[]] as $scratch_windows
|
|
|
|
| [.. | select(.type=="workspace" and .num)? | .focus[]] as $exposed_windows
|
|
|
|
| ($exposed_windows - ($exposed_windows - $scratch_windows)) as $exposed_scratch
|
|
|
|
| ($out | .exposed_scratch = $exposed_scratch) as $out
|
|
|
|
| ($out | .exposed_scratch_count = ($exposed_scratch | length)) as $out
|
|
|
|
|
|
|
|
# get and save the current workspace name
|
|
|
|
| (.. | select(.current_workspace)? | .current_workspace) as $cws
|
|
|
|
|
|
|
|
# now, loop over all workspaces by using the recursive descent operator (..)
|
|
|
|
# and select all the workspaces (.type == "workspace")
|
|
|
|
| [ (.. | select(.type=="workspace")?)
|
|
|
|
|
|
|
|
# if its a con or a floating_con, include it in the window count
|
|
|
|
| (.window_count = ([.. | select(.type == "con" or .type == "floating_con")?] | length))
|
|
|
|
|
|
|
|
# and delete all the extraneous info
|
|
|
|
| del(.rect,.deco_rect,.window_rect,.geometry,.nodes,.floating_nodes)
|
|
|
|
|
|
|
|
# add a default class
|
|
|
|
| (.class = ["workspace-switcher"])
|
|
|
|
|
|
|
|
# and add active class to the current workspace
|
|
|
|
| (if (.name == $cws) then .class += ["active"] | .current = true else .current = false end)
|
|
|
|
|
|
|
|
# add urgent if its urgent
|
|
|
|
| (if (.urgent) then .class += ["urgent"] end)
|
|
|
|
|
|
|
|
# now join the classes
|
|
|
|
| .class |= join(" ")
|
|
|
|
|
|
|
|
# and save to $all for further processing into $out
|
|
|
|
] as $all
|
|
|
|
|
|
|
|
# add .workspaces to $out for anything that has a workspace number
|
|
|
|
| ($out | .workspaces = [$all | .[] | select(.num)?]) as $out
|
|
|
|
|
|
|
|
# add .scratches to $out for any workspace that does _not_ have a number
|
|
|
|
# (these are distinguished by being scratch but also cant be reached by next/prev)
|
|
|
|
| ($out | .scratches = [$all | .[] | select(.num == null)]) as $out
|
|
|
|
|
|
|
|
# now that weve built up $out, we will return it.
|
|
|
|
| $out
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
2024-03-30 21:05:07 +00:00
|
|
|
rate_limit .1
|
|
|
|
poll_interval 10
|
|
|
|
on_sway
|
2024-03-30 21:58:51 +00:00
|
|
|
output_string .*
|
2024-03-30 21:05:07 +00:00
|
|
|
filter uniq
|
2024-03-30 14:30:52 +00:00
|
|
|
|
2024-03-30 21:05:07 +00:00
|
|
|
start "$@"
|