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

Unreliable focus change when closing windows. Focus race condition with macOS #1097

Open
nikitabobko opened this issue Feb 16, 2025 · 0 comments
Labels
bug Something isn't working as expected

Comments

@nikitabobko
Copy link
Owner

nikitabobko commented Feb 16, 2025

When the window is closed, AeroSpace receives two events from macOS:

  • The window is destroyed
  • The focused window is changed

The events system is unreliable in macOS. The events might come in whatever order, or sometimes the events might not be even delivered 🤷

AeroSpace logic relies neither on the nature of the events nor on their order. AeroSpace only uses events as a signal to "re-evaluate the world" (check if windows no longer exist, check if new windows are appeared, re-layout the windows)

And here comes the problem, whenever AeroSpace detects that the window is destroyed, AeroSpace issues a focus request to focus the previously focused window on the workspace of the destroyed window. We do so to keep the focused workspace focused (Pointer in the code: MacWindow.swift:garbageCollect). Unfortunately, AeroSpace plays a "race condition" game with the macOS that tries to focus next window of the app.

It leads to the following user facing issue: AeroSpace may lose the "race condition" #854 #571

What is the proposed solution to fix the problem? I don't have one. I don't know. Until it's clear how to fix the issue, the issue exists for the documentation purposes.

Also read the thread: #571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

1 participant