Skip to content

fix: suppress unintended tag switch from macOS auto-activation after app termination#161

Open
typester wants to merge 2 commits intomainfrom
fix/auto-tag-change
Open

fix: suppress unintended tag switch from macOS auto-activation after app termination#161
typester wants to merge 2 commits intomainfrom
fix/auto-tag-change

Conversation

@typester
Copy link
Owner

When apps are terminated in quick succession (e.g., repeated Cmd-Q), macOS auto-activates another app which may have hidden windows on a different tag, causing an unwanted tag switch. The existing deferred logic (same-batch WindowDestroyed detection) cannot handle this because the AppTerminated event arrives in a later batch (~60ms delay).

Add last_app_terminated_at timestamp to RunLoopContext. When a deferred tag switch decision finds the window still alive but an app was terminated within the last 2 seconds, suppress the tag switch and restore focus to the current display's visible window instead.

typester added 2 commits March 6, 2026 10:38
…app termination

When apps are terminated in quick succession (e.g., repeated Cmd-Q),
macOS auto-activates another app which may have hidden windows on a
different tag, causing an unwanted tag switch. The existing deferred
logic (same-batch WindowDestroyed detection) cannot handle this because
the AppTerminated event arrives in a later batch (~60ms delay).

Add last_app_terminated_at timestamp to RunLoopContext. When a deferred
tag switch decision finds the window still alive but an app was
terminated within the last 2 seconds, suppress the tag switch and
restore focus to the current display's visible window instead.
Rename last_app_terminated_at to last_focused_window_destroyed_at and
set the timestamp when the focused window is destroyed (not just on
AppTerminated). This covers Cmd-W closing the last window of an app
and batch-separated events where workspace callback hasn't fired yet.

Also narrow the timestamp scope to only fire when focus is actually
lost, preventing false suppression after background app termination.
@typester typester force-pushed the fix/auto-tag-change branch from 9f63a37 to f52b549 Compare March 7, 2026 18:18
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

Successfully merging this pull request may close these issues.

1 participant