From 878b5be1854442ae7588200ca538e97f1ded0c3e Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 5 Feb 2024 16:15:43 -0500 Subject: [PATCH 1/3] fix(macOS): Restore custom titlebar background Required for when a transparent background is used in conjunction with non-native fullscreen. --- .../Features/Terminal/TerminalWindow.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index 2c4633a20..8dc42f141 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -45,6 +45,10 @@ class TerminalWindow: NSWindow { 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 // the window from hiding the tab bar when we get down to a single tab. DispatchQueue.main.async { @@ -61,8 +65,12 @@ class TerminalWindow: NSWindow { } } + private var storedTitlebarBackgroundColor: CGColor? = nil + // Assign a background color to the titlebar area. func setTitlebarBackground(_ color: CGColor) { + storedTitlebarBackgroundColor = color + guard let titlebarContainer = contentView?.superview?.subviews.first(where: { $0.className == "NSTitlebarContainerView" }) else { return } @@ -71,6 +79,13 @@ class TerminalWindow: NSWindow { 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, detect the tab bar being added, and override its behavior. override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) { From 1d6b952c8fa1b6741d70420f47754cd8137553e8 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 5 Feb 2024 17:05:13 -0500 Subject: [PATCH 2/3] fix(macOS): Improve updating of transparent titlebar tabs backgrounds FAR from a perfect fix, as the background seen through the tabs during window drags will be behind by a frame or so still, but definitely a vast improvement over not updating at all. --- .../Features/Terminal/TerminalController.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 080f2d871..f9ab6cfc7 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -140,6 +140,18 @@ class TerminalController: NSWindowController, NSWindowDelegate, } } + func fixTabBar() { + // We do this to make sure that the tab bar will always re-composite. If we don't, + // then the it will "drag" pieces of the background with it when a transparent + // window is moved around. + // + // There might be a better way to make the tab bar "un-lazy", but I can't find it. + if let window = window, !window.isOpaque { + window.isOpaque = true + window.isOpaque = false + } + } + @objc private func onFrameDidChange(_ notification: NSNotification) { // This is a huge hack to set the proper shortcut for tab selection // on tab reordering using the mouse. There is no event, delegate, etc. @@ -335,6 +347,11 @@ class TerminalController: NSWindowController, NSWindowDelegate, func windowDidBecomeKey(_ notification: Notification) { self.relabelTabs() + self.fixTabBar() + } + + func windowDidMove(_ notification: Notification) { + self.fixTabBar() } // Called when the window will be encoded. We handle the data encoding here in the From 3c0317bf9dbd67e85a9c2ac7e586117546abb8ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 Feb 2024 19:04:50 -0800 Subject: [PATCH 3/3] macos: small stylistic edits --- macos/Sources/Features/Terminal/TerminalController.swift | 2 +- macos/Sources/Features/Terminal/TerminalWindow.swift | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index f9ab6cfc7..2fabadd77 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -140,7 +140,7 @@ class TerminalController: NSWindowController, NSWindowDelegate, } } - func fixTabBar() { + private func fixTabBar() { // We do this to make sure that the tab bar will always re-composite. If we don't, // then the it will "drag" pieces of the background with it when a transparent // window is moved around. diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index 8dc42f141..e2d14ad1f 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -29,6 +29,7 @@ class TerminalWindow: NSWindow { private var windowButtonsBackdrop: NSView? = nil private var windowDragHandle: WindowDragView? = nil + private var storedTitlebarBackgroundColor: CGColor? = nil // The tab bar controller ID from macOS static private let TabBarController = NSUserInterfaceItemIdentifier("_tabBarController") @@ -65,8 +66,6 @@ class TerminalWindow: NSWindow { } } - private var storedTitlebarBackgroundColor: CGColor? = nil - // Assign a background color to the titlebar area. func setTitlebarBackground(_ color: CGColor) { storedTitlebarBackgroundColor = color @@ -80,9 +79,8 @@ class TerminalWindow: NSWindow { } // Make sure the titlebar has the assigned background color. - func restoreTitlebarBackground() { + private func restoreTitlebarBackground() { guard let color = storedTitlebarBackgroundColor else { return } - setTitlebarBackground(color) }