macos: use enum for window theme

This commit is contained in:
Mitchell Hashimoto
2024-05-17 16:31:18 -04:00
parent c437416014
commit 69a3137956
2 changed files with 19 additions and 5 deletions

View File

@ -254,8 +254,11 @@ class TerminalController: NSWindowController, NSWindowDelegate,
// This makes sure our titlebar renders correctly when there is a transparent background
window.titlebarColor = backgroundColor.withAlphaComponent(ghostty.config.backgroundOpacity)
window.windowTheme = ghostty.config.windowTheme
// Make sure our theme is set on the window so styling is correct.
if let windowTheme = ghostty.config.windowTheme {
window.windowTheme = .init(rawValue: windowTheme)
}
// Handle titlebar tabs config option. Something about what we do while setting up the
// titlebar tabs interferes with the window restore process unless window.tabbingMode

View File

@ -75,8 +75,10 @@ class TerminalWindow: NSWindow {
tab.attributedTitle = attributedTitle
}
}
var windowTheme: String?
// The window theme configuration from Ghostty. This is used to control some
// behaviors that don't look quite right in certain situations.
var windowTheme: TerminalWindowTheme?
// We only need to set this once, but need to do it after the window has been created in order
// to determine if the theme is using a very dark background, in which case we don't want to
@ -134,7 +136,10 @@ class TerminalWindow: NSWindow {
updateResetZoomTitlebarButtonVisibility()
guard let windowTheme, windowTheme == "auto" else { return }
// 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. See issue #1709.
guard let windowTheme, windowTheme == .auto else { return }
titlebarSeparatorStyle = tabbedWindows != nil && !titlebarTabs ? .line : .none
@ -631,3 +636,9 @@ fileprivate class WindowButtonsBackdropView: NSView {
layer?.addSublayer(overlayLayer)
}
}
enum TerminalWindowTheme: String {
case auto
case light
case dark
}