From 242858b96340ca170c6d573a24c8805769ac90a5 Mon Sep 17 00:00:00 2001 From: Troels Thomsen Date: Mon, 20 May 2024 10:22:27 +0200 Subject: [PATCH 1/3] Color after setting window theme and tab mode --- .../Features/Terminal/TerminalController.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index aab789845..7598b7007 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -259,13 +259,6 @@ class TerminalController: NSWindowController, NSWindowDelegate, // when cascading. window.center() - // Set the background color of the window - let backgroundColor = NSColor(ghostty.config.backgroundColor) - window.backgroundColor = backgroundColor - - // This makes sure our titlebar renders correctly when there is a transparent background - window.titlebarColor = backgroundColor.withAlphaComponent(ghostty.config.backgroundOpacity) - // Make sure our theme is set on the window so styling is correct. if let windowTheme = ghostty.config.windowTheme { window.windowTheme = .init(rawValue: windowTheme) @@ -282,6 +275,13 @@ class TerminalController: NSWindowController, NSWindowDelegate, } } + // Set the background color of the window + let backgroundColor = NSColor(ghostty.config.backgroundColor) + window.backgroundColor = backgroundColor + + // This makes sure our titlebar renders correctly when there is a transparent background + window.titlebarColor = backgroundColor.withAlphaComponent(ghostty.config.backgroundOpacity) + // Initialize our content view to the SwiftUI root window.contentView = NSHostingView(rootView: TerminalView( ghostty: self.ghostty, From 47874742a146403ecddd331ead1ba63b9c4b0c08 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 20 May 2024 20:07:50 -0400 Subject: [PATCH 2/3] Extract guard statement --- .../Features/Terminal/TerminalWindow.swift | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index da0afa8d6..ce6f25e1e 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -136,14 +136,8 @@ class TerminalWindow: NSWindow { updateResetZoomTitlebarButtonVisibility() - // The remainder of the styles we only apply if we're on "auto" theming - // because they conflict with the appearance being forced a certain - // direction. Titlebar tabs are excluded (they always style the titlebar) - // because historically this is how they've always worked. So this - // exclusion only applies to native tabs. See issue #1709. - if let windowTheme, windowTheme != .auto && !titlebarTabs { - return - } + // The remainder of this function only applies to styled tabs. + guard hasStyledTabs else { return } titlebarSeparatorStyle = tabbedWindows != nil && !titlebarTabs ? .line : .none @@ -177,6 +171,20 @@ class TerminalWindow: NSWindow { // MARK: - Tab Bar Styling + // This is true if we should apply styles to the titlebar or tab bar. + var hasStyledTabs: Bool { + // If we have titlebar tabs then we always style. + guard !titlebarTabs else { return true } + + // This should never happen, but if we don't have a theme set then + // we just style the tabs. Either response here is probably okay. + guard let windowTheme else { return true } + + // We only style if the window theme is auto. Any other specific + // window theme type will always show up as that native theme. + return windowTheme == .auto + } + var hasVeryDarkBackground: Bool { backgroundColor.luminance < 0.05 } From f79674097fe2d13b8a4b12debc530c638e251a9a Mon Sep 17 00:00:00 2001 From: Troels Thomsen Date: Tue, 21 May 2024 08:58:51 +0200 Subject: [PATCH 3/3] Avoid coloring when using native tabs --- .../Features/Terminal/TerminalController.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 7598b7007..b0c2df1ca 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -173,6 +173,8 @@ class TerminalController: NSWindowController, NSWindowDelegate, window.titlebarFont = nil } + guard window.hasStyledTabs else { return } + // The titlebar is always updated. We don't need to worry about opacity // because we handle it here. let backgroundColor = OSColor(ghostty.config.backgroundColor) @@ -275,12 +277,14 @@ class TerminalController: NSWindowController, NSWindowDelegate, } } - // Set the background color of the window - let backgroundColor = NSColor(ghostty.config.backgroundColor) - window.backgroundColor = backgroundColor + if window.hasStyledTabs { + // Set the background color of the window + let backgroundColor = NSColor(ghostty.config.backgroundColor) + window.backgroundColor = backgroundColor - // This makes sure our titlebar renders correctly when there is a transparent background - window.titlebarColor = backgroundColor.withAlphaComponent(ghostty.config.backgroundOpacity) + // This makes sure our titlebar renders correctly when there is a transparent background + window.titlebarColor = backgroundColor.withAlphaComponent(ghostty.config.backgroundOpacity) + } // Initialize our content view to the SwiftUI root window.contentView = NSHostingView(rootView: TerminalView(