Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose additional attributes in query system for better multi-display support #116

Closed
dominiklohmann opened this issue Jul 12, 2019 · 10 comments
Labels
enhancement New feature or request

Comments

@dominiklohmann
Copy link
Collaborator

dominiklohmann commented Jul 12, 2019

Discussion

Below are some attributes that can easily be added to the current query system without too much overhead, which are all aimed at improving multi-display support.

I believe that all of these attributes are available to yabai internally already, but they are not exposed by the query system. I tried to come up with a reasonable set of attributes that are either impossible or very hard to consistently get with the current system.

There's just one breaking change in there, but it's so slight that I don't think it matters much, especially with how useless the "windows" attribute was in space queries.

Feature request

Window queries

  • "space" attribute that holds the space index of the target window
  • "display" attribute that holds the display index of the target window
  • "focused" attribute that holds whether the target window is focused

Space queries

  • change "windows" attribute from count of windows to an array of all window ids on the target space (to get the count: use jq '.windows | length' instead of jq '.windows')
  • "visible" attribute that holds whether the target space is visible on its display
  • "focused" attribute that holds whether the target space is focused
  • "native-fullscreen" attribute that holds whether the target space is in native-fullscreen modee
  • "first-window" attribute that holds the window id of the first tiled window on the target space or null if it does not exist
  • "last-window" attribute that holds the window id of the last tiled window on the target space or null if it does not exist

Display queries

  • "spaces" attribute that holds an array of all space indices on the target display, sorted by order of appearance in Mission Control, including native-fullscreen spaces

Hypothetical example outputs

yabai -m query --windows --window | jq
{
  "id": 61201,
  "pid": 71741,
  "app": "iTerm2",
  "title": "zsh:~",
  "frame": {
    "x": 20,
    "y": 42,
    "w": 1640,
    "h": 988
  },
  "level": 0,
  "role": "AXWindow",
  "subrole": "AXStandardWindow",
  "movable": 1,
  "resizable": 1,
  "split": "none",
  "floating": 1,
  "sticky": 0,
  "border": 0,
  "zoom-parent": 0,
  "zoom-fullscreen": 0,
  "native-fullscreen": 0,
  "space": 1,
  "display": 1,
  "focused": 1
}
yabai -m query --spaces --space | jq
{
  "id": 4,
  "index": 1,
  "display": 1,
  "windows": [61201, 62450, 68203],
  "type": "bsp",
  "visible": 1,
  "focused": 0,
  "native-fullscreen": 0,
  "first-window": 61201,
  "last-window": 61201
}
yabai -m query --displays --display | jq
{
  "id": 69734406,
  "index": 1,
  "spaces": 6,
  "frame": {
    "x": 0,
    "y": 0,
    "w": 1680,
    "h": 1050
  },
  "spaces": [1, 2, 3, 0, 0, 0]
}
@koekeishiya
Copy link
Owner

Seems reasonable to do.

This may not be the correct issue, but regarding mission-control indexes. Say there are 4 spaces, numbered 1-4 accordingly. After the named Desktop 2, there is a fullscreen space. Would it not make sense to have the fullscreen space be mission-control index 3? I know this breaks with the names given by Apple, which appear to be a simple enumeration of user-spaces - there is no internal name given to spaces (except for the uuid string), which is why I suspect this.

The current system where we skip fullscreen spaces is something I did to remain consistent with the numbering given by Apple, but I don't think we ever discussed whether this is the correct way to handle this.

@koekeishiya koekeishiya added the enhancement New feature or request label Jul 12, 2019
@dominiklohmann
Copy link
Collaborator Author

dominiklohmann commented Jul 12, 2019

This might actually be the proper way to deal with it. Do you want me to separate this out into another issue?

If people wanted the old way back, they could then still do this, assuming there'd also be a "native-fullscreen" attribute for spaces (added it to the list in the first post):

# this only works if the query output is guaranteed to be ordered by appearance
old_index=4
yabai -m space --focus \
    "$(yabai -m query --spaces
        | jq -re "[.[] | select(.\"native-fullscreen\" == 0)][${old_index}].index")"

@goranmoomin
Copy link

goranmoomin commented Jul 12, 2019

@koekeishiya What about (not modifying the current setting) allowing users to give spaces names?
(I didn't look at current yabai's new features for a while, so maybe this might be already implemented)
In the hypothetical named-space yabai, the full screen space will have names as "<App name>" or "<App name> 2", ... eg.

yabai might go farther, and injecting the space names to Mission Control.

Sent with GitHawk

@dominiklohmann
Copy link
Collaborator Author

@pcr910303 See https:/koekeishiya/chunkwm/issues/599 for previous discussion about naming spaces. I think it's out of scope for this issue, but space names and adding space names as space selectors is something that certainly seems worth looking at.

@goranmoomin
Copy link

@dominiklohmann Thanks for pointing out!

Sent with GitHawk

@koekeishiya
Copy link
Owner

This might actually be the proper way to deal with it. Do you want me to separate this out into another issue?

That would probably be the best, yeah.

assuming there'd also be a "native-fullscreen" attribute for spaces

I've been thinking for some time now that the type of the space should be visible in the query output somehow. We can either add a type attribute, that is set to "user", "fullscreen", "system" or whatever types of spaces there are, or simply do "native-fullscreen" as you suggested. I suppose "native-fullscreen" is all you really care about, so that may be sufficient.

@koekeishiya
Copy link
Owner

koekeishiya commented Jul 12, 2019

Implemented on master. Regarding space and type - ended up with native-fullscreen attribute.

If first-window or last-window is not known, their value will be 0 instead of null. 0 is not a valid window id on macOS and it was easier to output a number rather than having to do a number or a string based on whether the value was present or not.

@koekeishiya koekeishiya added the addressed on master; not released Fixed upstream, but not yet released label Jul 12, 2019
@dominiklohmann
Copy link
Collaborator Author

dominiklohmann commented Jul 12, 2019

If first-window or last-window is not known, their value will be 0 instead of null. 0 is not a valid window id on macOS and it was easier to output a number rather than having to do a number or a string based on whether the value was present or not.

The reason for this was that jq -e returns a non-zero exit code if the result is null or false. The workaround is to do .key != 0 instead, which I guess is okay. It's already the same for all the boolean values that use 0 and 1 instead of false and true.

@dominiklohmann
Copy link
Collaborator Author

dominiklohmann commented Jul 13, 2019

I've got one more: "visible" as an attribute for window queries. Listing all windows from all visible spaces requires a long command chain otherwise.

Compare:

# before (runs yabai (1 + display count) times, jq twice)
yabai -m query --spaces \
    | jq -r ".[] | select(.visible == 1).index" \
    | xargs yabai -m query --windows --space \
    | jq -rs "add"

# after (runs yabai once, jq once)
yabai -m query --windows \
    | jq -r "map(select(.visible == 1))"

koekeishiya added a commit that referenced this issue Jul 13, 2019
@koekeishiya
Copy link
Owner

Implemented on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants