diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 84911e13b..03665c955 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -237,6 +237,14 @@ class TerminalController: NSWindowController, NSWindowDelegate, viewModel: self, delegate: self )) + + // Give the titlebar a custom background color to account for transparent windows. + window.setTitlebarBackground( + window + .backgroundColor + .withAlphaComponent(self.ghostty.config.backgroundOpacity) + .cgColor + ) // In various situations, macOS automatically tabs new windows. Ghostty handles // its own tabbing so we DONT want this behavior. This detects this scenario and undoes diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index af7956d4d..bcafc0e96 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -78,6 +78,16 @@ class TerminalWindow: NSWindow { } } + // Assign a background color to the titlebar area. + public func setTitlebarBackground(_ color: CGColor) { + guard let titlebarContainer = contentView?.superview?.subviews.first(where: { + $0.className == "NSTitlebarContainerView" + }) else { return } + + titlebarContainer.wantsLayer = true + titlebarContainer.layer?.backgroundColor = color + } + private var windowButtonsBackdrop: NSView? = nil private func addWindowButtonsBackdrop(titlebarView: NSView, toolbarView: NSView) {