Fix intermittent window not coming to front on macOS startup#174
Merged
Fix intermittent window not coming to front on macOS startup#174
Conversation
Move setActivationPolicy(Regular) from applicationDidFinishLaunching to before finishLaunching() in init(). The window server processes activation policy changes asynchronously via IPC, so calling it inside the launch callback and immediately trying to activate creates a race condition — sometimes the promotion completes in time, sometimes it doesn't, causing the window to stay behind other apps. This matches what GLFW and SDL do: set the policy as early as possible so the window server has time to promote the process before any window is created or activation is attempted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nishu-builder
pushed a commit
to Metta-AI/mettagrid
that referenced
this pull request
Apr 9, 2026
## Summary - Updates the windy nimby lock hash from `d87b6ad` to `45f58a2` (latest master) ## What changed in windy The new windy includes [treeform/windy#174](treeform/windy#174) which fixes an intermittent bug where the mettascope window would not come to the front on macOS startup. **Root cause:** `setActivationPolicy(NSApplicationActivationPolicyRegular)` was called inside the `applicationDidFinishLaunching` callback and then immediately tried to activate the app. This policy change tells the macOS window server (a separate process) to promote the app from a background process to a regular GUI app, but the window server processes this asynchronously via IPC. Sometimes the promotion completed before the activation request arrived (window comes to front), sometimes it didn't (window stays behind other apps). **Fix:** Moved `setActivationPolicy` to before `finishLaunching()` in `init()`, giving the window server more time to process the policy change before any window is created or activation is attempted. This is the same approach used by GLFW and SDL. Also includes: - [treeform/windy#172](treeform/windy#172): Unify `pollHttp` behavior across platforms - [treeform/windy#173](treeform/windy#173): Fix readme spelling and grammar ## Test plan - [x] Launch mettascope repeatedly on macOS and verify the window consistently comes to front 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setActivationPolicy(NSApplicationActivationPolicyRegular)fromapplicationDidFinishLaunchingto beforefinishLaunching()ininit(), fixing intermittent failure of the window to come to front on startup.Problem
When a process starts (especially from terminal / without a
.appbundle), macOS classifies it as a background process.setActivationPolicy(Regular)tells the window server to promote it to a regular GUI app, but the window server processes this asynchronously via IPC.The old code set the policy inside
applicationDidFinishLaunchingand immediately calledactivateIgnoringOtherApps(true)— a race condition with the window server. Sometimes the promotion finished in time (window comes to front), sometimes it didn't (window stays behind).Fix
Set the activation policy as early as possible — before
finishLaunching()— so the window server has time to process the policy change before any window is created or activation is attempted. This is the same approach used by GLFW and SDL.Test plan
onFocusChange) still fire correctly🤖 Generated with Claude Code