From 2fae215e9b63e66dd11f59a3f43cef646d7ba633 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 20 Jul 2026 02:47:20 +0000 Subject: [PATCH 57/71] =?UTF-8?q?fix(macos):=20two=20windows=20at=20launch?= =?UTF-8?q?=20=E2=80=94=20gate=20the=20untitled=20window=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two contour windows opened at launch. The trace showed applicationOpenUntitled File: firing, which meant AppKit had already decided to open an untitled window (window #1); applicationDidFinishLaunching: then opened ours (window #2). The previous attempt implemented applicationOpenUntitledFile: returning NO, but that is the ACTION, consulted only after AppKit has committed to opening the window — too late. The GATE is applicationShouldOpenUntitledFile:; NO there stops AppKit from opening the untitled window at all. Implement it (return NO); keep applicationOpenUntitledFile: as belt-and-suspenders. Now exactly one window is created, by openTerminalWindow. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01AeG2jwYMX5gdvvtUnx3PJa --- src/contour_macos/main.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/contour_macos/main.mm b/src/contour_macos/main.mm index 3275c53f..d08b0259 100644 --- a/src/contour_macos/main.mm +++ b/src/contour_macos/main.mm @@ -94,6 +94,16 @@ return NO; } +// applicationShouldOpenUntitledFile: is the GATE — returning NO stops AppKit from opening an +// untitled window at all. (applicationOpenUntitledFile:, the action below, is only consulted if this +// returns YES, and returning NO there is too late — AppKit has already decided to open one. This is +// the actual cause of the two windows at launch: AppKit's untitled window plus ours.) +- (BOOL)applicationShouldOpenUntitledFile:(NSApplication*)app +{ + (void) app; + return NO; +} + - (BOOL)applicationOpenUntitledFile:(NSApplication*)app { (void) app;