Merge pull request #1782 from tt/avoid-coloring-when-using-native-tabs

Avoid coloring when using native tabs
This commit is contained in:
Mitchell Hashimoto
2024-05-21 07:07:47 -04:00
committed by GitHub
2 changed files with 27 additions and 15 deletions

View File

@ -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)
@ -259,13 +261,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 +277,15 @@ class TerminalController: NSWindowController, NSWindowDelegate,
}
}
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)
}
// Initialize our content view to the SwiftUI root
window.contentView = NSHostingView(rootView: TerminalView(
ghostty: self.ghostty,

View File

@ -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
}