From 5502cf5ae4b54377d2eb69aa970987eb75e94da8 Mon Sep 17 00:00:00 2001 From: treeform Date: Tue, 7 Apr 2026 16:33:28 -0700 Subject: [PATCH] Fix intermittent window not coming to front on macOS startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/windy/platforms/macos/platform.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/windy/platforms/macos/platform.nim b/src/windy/platforms/macos/platform.nim index 81545bb..bb060a9 100644 --- a/src/windy/platforms/macos/platform.nim +++ b/src/windy/platforms/macos/platform.nim @@ -320,7 +320,6 @@ proc applicationDidFinishLaunching( notification: NSNotification ): ID {.cdecl.} = NSApp.setPresentationOptions(NSApplicationPresentationDefault) - NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular) NSApp.activateIgnoringOtherApps(true) proc windowDidResize( @@ -846,6 +845,13 @@ proc init() {.raises: [].} = addMethod "doCommandBySelector:", doCommandBySelector addMethod "resetCursorRects", resetCursorRects + # Set activation policy before finishLaunching so the window server has + # time to promote this process to a regular GUI app before we try to + # activate or show any windows. Setting it inside applicationDidFinish- + # Launching is too late — the window server processes policy changes + # asynchronously, causing intermittent failures to come to front. + NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular) + let appDelegate = WindyAppDelegate.new() NSApp.setDelegate(appDelegate)