From 69a3137956dbecad7ab7628c6fc258274982c74d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 May 2024 16:31:18 -0400 Subject: [PATCH] macos: use enum for window theme --- .../Features/Terminal/TerminalController.swift | 7 +++++-- .../Features/Terminal/TerminalWindow.swift | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index e2c96eb07..419505aa8 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -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 diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index a77fa43df..070ad46dc 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -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 +}