asmvik / asmvik/yabai

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

Open
#2,333 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C
Stars
29.6k
Forks
750
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing yabai's scratchpad handling and the existing window query fields, especially "is-visible", to understand how state is represented across spaces. Done means users can query whether a scratchpad is toggled on or off even from another space, then use that status in scripts like the one shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, c
Domain
cli, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.