From c83bf1de75a401b0eacc6417018c1f316dcf2b94 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 11 Dec 2025 13:50:12 -0800 Subject: [PATCH] macos: simplify terminal controller a bunch --- .../Terminal/TerminalController.swift | 24 ++++--------------- .../Terminal/TerminalRestorable.swift | 5 ++-- .../Window Styles/TerminalWindow.swift | 11 ++++++--- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 7941ae22e..a980723ba 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -54,16 +54,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr /// The configuration derived from the Ghostty config so we don't need to rely on references. private(set) var derivedConfig: DerivedConfig - /// The accent color that should be rendered for this tab. - var tabColor: TerminalTabColor = .none { - didSet { - guard tabColor != oldValue else { return } - if let terminalWindow = window as? TerminalWindow { - terminalWindow.display(tabColor: tabColor) - } - window?.invalidateRestorableState() - } - } /// The notification cancellable for focused surface property changes. private var surfaceAppearanceCancellables: Set = [] @@ -870,12 +860,14 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr with undoState: UndoState ) { self.init(ghostty, withSurfaceTree: undoState.surfaceTree) - self.tabColor = undoState.tabColor // Show the window and restore its frame showWindow(nil) if let window { window.setFrame(undoState.frame, display: true) + if let terminalWindow = window as? TerminalWindow { + terminalWindow.tabColor = undoState.tabColor + } // If we have a tab group and index, restore the tab to its original position if let tabGroup = undoState.tabGroup, @@ -912,7 +904,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr focusedSurface: focusedSurface?.id, tabIndex: window.tabGroup?.windows.firstIndex(of: window), tabGroup: window.tabGroup, - tabColor: tabColor) + tabColor: (window as? TerminalWindow)?.tabColor ?? .none) } //MARK: - NSWindowController @@ -954,9 +946,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr delegate: self, )) - if let terminalWindow = window as? TerminalWindow { - terminalWindow.display(tabColor: tabColor) - } // If we have a default size, we want to apply it. if let defaultSize { switch (defaultSize) { @@ -1195,11 +1184,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr } } - - func setTabColor(_ color: TerminalTabColor) { - tabColor = color - } - @IBAction func returnToDefaultSize(_ sender: Any?) { guard let window, let defaultSize else { return } defaultSize.apply(to: window) diff --git a/macos/Sources/Features/Terminal/TerminalRestorable.swift b/macos/Sources/Features/Terminal/TerminalRestorable.swift index 931739987..ce13f2620 100644 --- a/macos/Sources/Features/Terminal/TerminalRestorable.swift +++ b/macos/Sources/Features/Terminal/TerminalRestorable.swift @@ -15,7 +15,7 @@ class TerminalRestorableState: Codable { self.focusedSurface = controller.focusedSurface?.id.uuidString self.surfaceTree = controller.surfaceTree self.effectiveFullscreenMode = controller.fullscreenStyle?.fullscreenMode - self.tabColor = controller.tabColor + self.tabColor = (controller.window as? TerminalWindow)?.tabColor ?? .none } init?(coder aDecoder: NSCoder) { @@ -97,7 +97,8 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration { return } - c.tabColor = state.tabColor + // Restore our tab color + (window as? TerminalWindow)?.tabColor = state.tabColor // Setup our restored state on the controller // Find the focused surface in surfaceTree diff --git a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift index 706165573..2828a9c56 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift @@ -46,8 +46,13 @@ class TerminalWindow: NSWindow { windowController as? TerminalController } - func display(tabColor: TerminalTabColor) { - tabColorSelection = tabColor + var tabColor: TerminalTabColor { + get { tabColorSelection } + set { + guard tabColorSelection != newValue else { return } + tabColorSelection = newValue + invalidateRestorableState() + } } // MARK: NSWindow Overrides @@ -756,7 +761,7 @@ extension TerminalWindow { paletteItem.view = makeTabColorPaletteView( selectedColor: tabColorSelection ) { [weak target] color in - target?.setTabColor(color) + (target?.window as? TerminalWindow)?.tabColor = color } menu.addItem(paletteItem) }