From aad302f2361a8503d82692b2d50a82b4cdd81955 Mon Sep 17 00:00:00 2001 From: Pete Schaffner Date: Sun, 11 Feb 2024 14:24:35 +0100 Subject: [PATCH] Make new tab icon respond to window's key status --- .../Features/Terminal/TerminalWindow.swift | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index b4194c113..44864d511 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -16,8 +16,14 @@ class TerminalWindow: NSWindow { } super.becomeKey() + updateNewTabButtonOpacity() } - + + override func resignKey() { + super.resignKey() + updateNewTabButtonOpacity() + } + // MARK: - Titlebar Tabs // Used by the window controller to enable/disable titlebar tabs. @@ -215,6 +221,8 @@ class TerminalWindow: NSWindow { // Color the new tab button's image to match the color of the tab title/keyboard shortcut labels, // just as it does in the stock tab bar. + updateNewTabButtonOpacity() + guard let titlebarContainer = contentView?.superview?.subviews.first(where: { $0.className == "NSTitlebarContainerView" }) else { return } @@ -250,6 +258,21 @@ class TerminalWindow: NSWindow { newTabButtonImageView.frame = newTabButton.bounds } + // Since we are coloring the new tab button's image, it doesn't respond to the + // window's key status changes in terms of becoming less prominent visually, + // so we need to do it manually. + private func updateNewTabButtonOpacity() { + guard let titlebarContainer = contentView?.superview?.subviews.first(where: { + $0.className == "NSTitlebarContainerView" + }) else { return } + guard let newTabButton: NSButton = titlebarContainer.firstDescendant(withClassName: "NSTabBarNewTabButton") as? NSButton else { return } + guard let newTabButtonImageView: NSImageView = newTabButton.subviews.first(where: { + $0 as? NSImageView != nil + }) as? NSImageView else { return } + + newTabButtonImageView.alphaValue = isKeyWindow ? 1 : 0.5 + } + private func addWindowButtonsBackdrop(titlebarView: NSView, toolbarView: NSView) { // If we already made the view, just make sure it's unhidden and correctly placed as a subview. if let view = windowButtonsBackdrop {