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] Some applications don't tile when CGSCopySpacesForWindows returns empty #1574

Open
XOR-op opened this issue Nov 21, 2023 · 2 comments
Open
Labels

Comments

@XOR-op
Copy link

XOR-op commented Nov 21, 2023

Describe the bug
When windows from some applications are created, they won't tile properly, until some updates(e.g. internal .add event) to the space containing the misbehaved window. This buggy behavior happens at random.

When I digged into the code base, I found the issue comes from WindowManager::add(). The code would run successfully until it reaches line 423, which tries to get the corresponding space for the window. After the failed trial, WindowManager will issue an unknown event instead of a normal add event. Therefore, some subsequent operations cannot be correctly performed, resulting some windows not properly tiled.

Looking deeper into the code. In CGWindowsInfo::windowSpace(), if this line returns an empty array, the subsequent operations will fail.

Interestingly, if we want to bypass the check in WindowManager::add(), line 425, we are still unable to get the proper behavior. I don't know if this can be resolved.

If we cannot bypass the space empty check, since CGSCopySpacesForWindows is a private MacOS API, we cannot do much with that. However, I wonder if we can have some workaround of that, for example some timeout or retry mechanism.

There have been a lot of bug reports of this problem, like #1335, #1364 and #1398. I guess my observation is the root cause of some of those. I want to see if any experienced MacOS developer could help.

Applications:
Applications which have this bug frequently: Typora, Kitty
Applications that never have this bug: Firefox, Vscode, Chrome and many more.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
Properly handled add event and windows should tile.

Versions:

  • macOS: 13.6.2
  • Amethyst: 0.20.0(108)
@ianyh
Copy link
Owner

ianyh commented Jan 8, 2024

Thanks for the thorough analysis! I made a proposed fix for it. Are you able to build and try it out?

@XOR-op
Copy link
Author

XOR-op commented Jan 14, 2024

Thanks for your help! Unfortunately, this fix doesn't work for me. I guess it could be something more subtle happened when calling the macOS API.

P.S. an update for the affected applications: Firefox now also suffers from this problem too after an update, as well as Jetbrains Gateway. I have no idea why this issue will happen, why it only targets to a subset of applications and what's the shared common between all these apps (Kitty is a native Swift app, Typora is Electron and JB Gateway is probably written in Java).

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

No branches or pull requests

2 participants