From 8d68489c55d5f22ac67df59be1b6cd030bd759ee Mon Sep 17 00:00:00 2001 From: Tobias Pape Date: Tue, 15 Jul 2025 18:12:39 +0200 Subject: [PATCH] Work around strange SwiftUI behavior in "older" macOSen. The Quick Terminal would not appear anymore, as somewhere in the framework the Quick Terminal Window's geometry gets corrupted when the window is added to the UI. This works around by caching the windows geometry and reusing it afterwards --- .../QuickTerminal/QuickTerminalController.swift | 12 ++++++++++++ .../Features/QuickTerminal/QuickTerminalWindow.swift | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift index 3bd8bc18f..b9f879a30 100644 --- a/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift @@ -111,12 +111,24 @@ class QuickTerminalController: BaseTerminalController { // Setup our initial size based on our configured position position.setLoaded(window) + // Upon first adding this Window to its host view, older SwiftUI + // seems to have a "hiccup" and corrupts the frameRect, + // sometimes setting the size to zero, sometimes corrupting it. + // We pass the actual window's frame as "inital" frame directly + // to the window, so it can use that instead of the frameworks + // "interpretation" + if let qtWindow = window as? QuickTerminalWindow { + qtWindow.initialFrame = window.frame + } // Setup our content window.contentView = NSHostingView(rootView: TerminalView( ghostty: self.ghostty, viewModel: self, delegate: self )) + if let qtWindow = window as? QuickTerminalWindow { + qtWindow.initialFrame = nil + } // Animate the window in animateIn() diff --git a/macos/Sources/Features/QuickTerminal/QuickTerminalWindow.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalWindow.swift index 005808a23..663f868f9 100644 --- a/macos/Sources/Features/QuickTerminal/QuickTerminalWindow.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalWindow.swift @@ -29,4 +29,14 @@ class QuickTerminalWindow: NSPanel { // We don't want to activate the owning app when quick terminal is triggered. self.styleMask.insert(.nonactivatingPanel) } + var initialFrame: NSRect? = nil + override func setFrame(_ frameRect: NSRect, display flag: Bool) { + // Upon first adding this Window to its host view, older SwiftUI + // seems to have a "hiccup" and corrupts the frameRect, + // sometimes setting the size to zero, sometimes corrupting it. + // If we find we have cached the "initial" frame, use that instead + // the propagated one throught the framework + super.setFrame(initialFrame ?? frameRect, display: flag) + } + }