64 lines
2.3 KiB
Plaintext
64 lines
2.3 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
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
|
||
|
'
|
||
|
}
|
||
|
poll
|
||
|
[ ${1-x} == '-d' ] && exit 0
|
||
|
|
||
|
swaymsg -t subscribe -m '[ "workspace", "window" ]' |
|
||
|
jq --unbuffered -c '.' |
|
||
|
while read -r EVENT;do
|
||
|
poll
|
||
|
done
|
||
|
|