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

Bug: Yabai shows incorrect window attributs before focusing it #2480

Open
pyinto opened this issue Nov 20, 2024 · 4 comments
Open

Bug: Yabai shows incorrect window attributs before focusing it #2480

pyinto opened this issue Nov 20, 2024 · 4 comments

Comments

@pyinto
Copy link

pyinto commented Nov 20, 2024

The Issue

I've noticed that yabai sometimes doesn't return the correct attributes of certain windows. Now I have caught an example of such behavior that I can reproduce. This bug messes up my signals sometimes; that's how I found it.
I think it's related to #2320, but not sure yet.

Steps To Reproduce

  1. Open native Calendar app on space 3; Now we have one calendar window on space 3 with:
    {"title": "Calendar", "app": "Calendar"};

  2. Move your focus away from the space 3 to any other space:
    yabai -m space --focus 1

  3. Restart yabai:
    yabai --restart-service

  4. Query windows on space 3:
    yabai -m query --windows --space 3 | jq

    [
     {
       "id": 2247,
       "pid": 32366,
       "app": "Calendar",
       "title": "Calendar",
       "scratchpad": "",
       "frame": {
         "x": 8.0000,
         "y": 33.0000,
         "w": 3184.0000,
         "h": 1759.0000
       },
       "role": "",
       "subrole": "",
       "root-window": true,
       "display": 1,
       "space": 3,
       "level": 0,
       "sub-level": -20,
       "layer": "normal",
       "sub-layer": "below",
       "opacity": 1.0000,
       "split-type": "none",
       "split-child": "none",
       "stack-index": 0,
       "can-move": false,
       "can-resize": false,
       "has-focus": false,
       "has-shadow": false,
       "has-parent-zoom": false,
       "has-fullscreen-zoom": false,
       "has-ax-reference": false,
       "is-native-fullscreen": false,
       "is-visible": false,
       "is-minimized": false,
       "is-hidden": false,
       "is-floating": false,
       "is-sticky": false,
       "is-grabbed": false
     }
    ]
    • Note that can-move & can-resize attributes - both set to false for some reason! Which is not true, you can resize those windows!
  5. Focus main Calendar app window, in my case it's 2247:
    yabai -m window 2247 --focus

  6. Repeat step 3:
    yabai -m query --windows --space 3 | jq

    [
      {
        "id": 2247,
        "pid": 32366,
        "app": "Calendar",
        "title": "Calendar",
        "scratchpad": "",
        "frame": {
          "x": 8.0000,
          "y": 33.0000,
          "w": 3184.0000,
          "h": 1759.0000
        },
        "role": "AXWindow",
        "subrole": "AXStandardWindow",
        "root-window": true,
        "display": 1,
        "space": 3,
        "level": 0,
        "sub-level": 0,
        "layer": "normal",
        "sub-layer": "normal",
        "opacity": 1.0000,
        "split-type": "none",
        "split-child": "second_child",
        "stack-index": 0,
        "can-move": true,
        "can-resize": true,
        "has-focus": false,
        "has-shadow": false,
        "has-parent-zoom": false,
        "has-fullscreen-zoom": false,
        "has-ax-reference": true,
        "is-native-fullscreen": false,
        "is-visible": true,
        "is-minimized": false,
        "is-hidden": false,
        "is-floating": false,
        "is-sticky": false,
        "is-grabbed": false
      }
    ]
    • Note that can-move & can-resize attributes - both set to true now, which is correct. Also role and subrole are set now too, before it was empty.

My Environment

$ yabai --version
yabai-v7.1.5

scripting-addition
  payload v2.1.18

$ sw_vers
ProductName:            macOS
ProductVersion:         15.1.1
BuildVersion:           24B91
@pyinto
Copy link
Author

pyinto commented Nov 20, 2024

To fix this behavior I have a script that walks through all the spaces, and focus every window individually, but it's quite a work and takes time.
In that script I had to focus a space where those windows are located, because sometimes yabai will just throw an error on a legit "focusable" window: could not locate window with the specified id or could not locate the window to act on!. This part is not that easy to reproduce, but once I will found a way - will report it.

@koekeishiya
Copy link
Owner

koekeishiya commented Nov 20, 2024

This is a macOS API limitation.

Some window properties are only accessible when yabai has a valid AX-reference for that window.
This AX-reference can only be retrieved when the space that the window is visible on, is active.
If windows are already opened on inactive spaces when yabai is launched, yabai can detect those
windows and retrieve a limited amount of information about them. In addition, yabai window commands
will NOT WORK for these windows. These windows can be identified by looking at the has-ax-reference
property. Once the space that the window belongs to becomes active, yabai will automatically create
an AX-reference. The queries will from that point forwards contain complete information, and the window
can be used with yabai window commands.

The properties that contain incorrect information for windows with has-ax-reference: false are as follows:

{
"role": string,
"subrole": string,
"can-move": bool,
"can-resize": bool
}

There is no known workaround except for what you're already doing.

Edit: Note that window rules (or window commands in general with the exception of the query command) does not apply to these windows before has-ax-reference is reported as true. That is when yabai is actually in control of that window.

@pyinto
Copy link
Author

pyinto commented Nov 24, 2024

@koekeishiya, oh sorry I missed that part in the documentation... Regardless, it's very unfortunate if there are no other ways to fix it, even with SIP disabled. 😔

Is it also expected that focusing on such window would often crash (restart) yabai? What kind of information would be helpful to provide from my side for the investigation? Regular error logs don't have any useful information about the crash; it would look like this:

$ tail -f /tmp/yabai_***.err.log
could not locate the window to act on!
could not locate window with the specified id '37916'.
could not locate the window to act on!
could not locate window with the specified id '37867'.

And then I see a notification about yabai scripting loading, and then in the regular yabai_***.out.log logs, I see that the yabairc file initiating from scratch. If one has such a "fix" script that loops through all the windows, it's very annoying and disruptive.

@koekeishiya
Copy link
Owner

You can find proper crash logs in Console.app. Check for yabai and/or Dock entries.

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

No branches or pull requests

2 participants