koekeishiya / yabai

A tiling window manager for macOS based on binary space partitioning
MIT License
22.48k stars 630 forks source link

Is there a way to detect the toggle status of a scratchpad? #2333

Open ognistik opened 3 weeks ago

ognistik commented 3 weeks ago

I LOVE the new scratchpads feature, super handy. However, one thing that I haven't been able to figure out is if there's any way to detect the toggle status of a window with a scratchpad. The "is-visible" property is only a good indicator if the user is in the same space as the scratchpad being queried, but being in a separate space, the is-visible will be false regardless of whether the scratchpad is toggled on or off.

I have the following script, for example, triggered by a space change, which will destroy spaces without windows, treating minimized or hidden windows as if there were none.

#!/usr/bin/env bash

# Check if there's any fullscreen space and exit if there is
yabai -m query --spaces --display | \
jq -re 'all(."is-native-fullscreen" | not)' &> /dev/null || exit;

# Find hidden and minimized
hidden_minimized=$(yabai -m query --windows | jq 'map(select(."is-hidden" or ."is-minimized")) | map(."id")');

# Find and destroy empty, unfocused spaces
yabai -m query --spaces | \
jq -re "map(select((.\"has-focus\" | not) and (\
  .\"windows\" | map(select(. as \$window | $hidden_minimized | index(\$window) | not))\
  ) == []).index) | reverse | .[]" | \
xargs -I % sh -c 'yabai -m space % --destroy'

I'd love to include non-active scratchpads together with hidden or minimized windows. Often times the space seems empty, but only because there's an invisible scratchpad asigned in there. This doesn't make a lot of sense, especially since scratchads are pulled over to any space when toggled. In other words, scratchpads in giving the impression that they are "floating" in an invisible space, so-to-speak, waiting to appear when toggled... but in reality they do have a space assigned, and this is what is giving me a bit of trouble.

Another case where it would be useful to have a way to find the scratchpad toggle status, would be if I wanted to toggle "off" specific scratchpads in case they are "on". Again, this is possible at the focused space level (at least in my single display setup), but not once the user moves away to a different space.