From f4242dda56e88db94856912a7a13a6dab05255f4 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 20 Jul 2026 02:37:46 +0000 Subject: [PATCH 55/71] debug(macos): trace + suppress AppKit auto-window-open (spurious windows) Running fastfetch spawns an extra window that opens and closes (twice). Nothing in our escape-sequence handling opens a window, so the trigger is likely an AppKit app-level behavior fired during the terminal detection/activation fastfetch does. Add: - a trace in openTerminalWindow to see when/if it is called; - applicationShouldHandleReopen: and applicationOpenUntitledFile: returning NO (with traces), which both suppress AppKit's auto-open-an-untitled-window behavior AND reveal if one of them is the culprit; - an applicationDidBecomeActive: trace. If the spurious window stops, one of the suppressions fixed it; the traces confirm which. Traces to be removed once diagnosed. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01AeG2jwYMX5gdvvtUnx3PJa --- src/contour_macos/main.mm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/contour_macos/main.mm b/src/contour_macos/main.mm index e5cc92bc..89f68988 100644 --- a/src/contour_macos/main.mm +++ b/src/contour_macos/main.mm @@ -20,6 +20,7 @@ - (void)openTerminalWindow { + NSLog(@"[trace] openTerminalWindow called"); NSRect const frame = NSMakeRect(0, 0, 720, 432); NSUInteger const style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; @@ -83,6 +84,30 @@ return YES; } +// Trace + suppress the AppKit auto-open-a-window behaviors, in case one of these is what spawns the +// spurious window when fastfetch runs (e.g. an activation/reopen). Returning NO / not opening a +// window here prevents AppKit from creating an untitled document window on its own. +- (BOOL)applicationShouldHandleReopen:(NSApplication*)app hasVisibleWindows:(BOOL)flag +{ + (void) app; + NSLog(@"[trace] applicationShouldHandleReopen hasVisibleWindows=%d", flag); + return NO; +} + +- (BOOL)applicationOpenUntitledFile:(NSApplication*)app +{ + (void) app; + NSLog(@"[trace] applicationOpenUntitledFile"); + return NO; +} + +- (void)applicationDidBecomeActive:(NSNotification*)note +{ + (void) note; + NSLog(@"[trace] applicationDidBecomeActive (windows=%lu)", + (unsigned long) [[NSApp windows] count]); +} + @end // Builds a minimal standard menu bar: application menu (Quit), Shell (New/Close), Edit