fix(macOS): Restore custom titlebar background

Required for when a transparent background is used in conjunction with non-native fullscreen.
This commit is contained in:
Qwerasd
2024-02-05 16:15:43 -05:00
parent 1e6cffaccb
commit 878b5be185

View File

@ -45,6 +45,10 @@ class TerminalWindow: NSWindow {
self.toolbar = TerminalToolbar(identifier: "Toolbar") self.toolbar = TerminalToolbar(identifier: "Toolbar")
} }
// Set a custom background on the titlebar - this is required for when
// titlebar tabs is used in conjunction with a transparent background.
self.restoreTitlebarBackground()
// We have to wait before setting the titleVisibility or else it prevents // We have to wait before setting the titleVisibility or else it prevents
// the window from hiding the tab bar when we get down to a single tab. // the window from hiding the tab bar when we get down to a single tab.
DispatchQueue.main.async { DispatchQueue.main.async {
@ -61,8 +65,12 @@ class TerminalWindow: NSWindow {
} }
} }
private var storedTitlebarBackgroundColor: CGColor? = nil
// Assign a background color to the titlebar area. // Assign a background color to the titlebar area.
func setTitlebarBackground(_ color: CGColor) { func setTitlebarBackground(_ color: CGColor) {
storedTitlebarBackgroundColor = color
guard let titlebarContainer = contentView?.superview?.subviews.first(where: { guard let titlebarContainer = contentView?.superview?.subviews.first(where: {
$0.className == "NSTitlebarContainerView" $0.className == "NSTitlebarContainerView"
}) else { return } }) else { return }
@ -71,6 +79,13 @@ class TerminalWindow: NSWindow {
titlebarContainer.layer?.backgroundColor = color titlebarContainer.layer?.backgroundColor = color
} }
// Make sure the titlebar has the assigned background color.
func restoreTitlebarBackground() {
guard let color = storedTitlebarBackgroundColor else { return }
setTitlebarBackground(color)
}
// This is called by macOS for native tabbing in order to add the tab bar. We hook into // This is called by macOS for native tabbing in order to add the tab bar. We hook into
// this, detect the tab bar being added, and override its behavior. // this, detect the tab bar being added, and override its behavior.
override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) { override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) {