macos: simplify terminal controller a bunch

pull/9784/head
Mitchell Hashimoto 2025-12-11 13:50:12 -08:00
parent 1073e89a0d
commit c83bf1de75
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 15 additions and 25 deletions

View File

@ -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. /// The configuration derived from the Ghostty config so we don't need to rely on references.
private(set) var derivedConfig: DerivedConfig 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. /// The notification cancellable for focused surface property changes.
private var surfaceAppearanceCancellables: Set<AnyCancellable> = [] private var surfaceAppearanceCancellables: Set<AnyCancellable> = []
@ -870,12 +860,14 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
with undoState: UndoState with undoState: UndoState
) { ) {
self.init(ghostty, withSurfaceTree: undoState.surfaceTree) self.init(ghostty, withSurfaceTree: undoState.surfaceTree)
self.tabColor = undoState.tabColor
// Show the window and restore its frame // Show the window and restore its frame
showWindow(nil) showWindow(nil)
if let window { if let window {
window.setFrame(undoState.frame, display: true) 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 we have a tab group and index, restore the tab to its original position
if let tabGroup = undoState.tabGroup, if let tabGroup = undoState.tabGroup,
@ -912,7 +904,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
focusedSurface: focusedSurface?.id, focusedSurface: focusedSurface?.id,
tabIndex: window.tabGroup?.windows.firstIndex(of: window), tabIndex: window.tabGroup?.windows.firstIndex(of: window),
tabGroup: window.tabGroup, tabGroup: window.tabGroup,
tabColor: tabColor) tabColor: (window as? TerminalWindow)?.tabColor ?? .none)
} }
//MARK: - NSWindowController //MARK: - NSWindowController
@ -954,9 +946,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
delegate: self, delegate: self,
)) ))
if let terminalWindow = window as? TerminalWindow {
terminalWindow.display(tabColor: tabColor)
}
// If we have a default size, we want to apply it. // If we have a default size, we want to apply it.
if let defaultSize { if let defaultSize {
switch (defaultSize) { switch (defaultSize) {
@ -1195,11 +1184,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
} }
} }
func setTabColor(_ color: TerminalTabColor) {
tabColor = color
}
@IBAction func returnToDefaultSize(_ sender: Any?) { @IBAction func returnToDefaultSize(_ sender: Any?) {
guard let window, let defaultSize else { return } guard let window, let defaultSize else { return }
defaultSize.apply(to: window) defaultSize.apply(to: window)

View File

@ -15,7 +15,7 @@ class TerminalRestorableState: Codable {
self.focusedSurface = controller.focusedSurface?.id.uuidString self.focusedSurface = controller.focusedSurface?.id.uuidString
self.surfaceTree = controller.surfaceTree self.surfaceTree = controller.surfaceTree
self.effectiveFullscreenMode = controller.fullscreenStyle?.fullscreenMode self.effectiveFullscreenMode = controller.fullscreenStyle?.fullscreenMode
self.tabColor = controller.tabColor self.tabColor = (controller.window as? TerminalWindow)?.tabColor ?? .none
} }
init?(coder aDecoder: NSCoder) { init?(coder aDecoder: NSCoder) {
@ -97,7 +97,8 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration {
return return
} }
c.tabColor = state.tabColor // Restore our tab color
(window as? TerminalWindow)?.tabColor = state.tabColor
// Setup our restored state on the controller // Setup our restored state on the controller
// Find the focused surface in surfaceTree // Find the focused surface in surfaceTree

View File

@ -46,8 +46,13 @@ class TerminalWindow: NSWindow {
windowController as? TerminalController windowController as? TerminalController
} }
func display(tabColor: TerminalTabColor) { var tabColor: TerminalTabColor {
tabColorSelection = tabColor get { tabColorSelection }
set {
guard tabColorSelection != newValue else { return }
tabColorSelection = newValue
invalidateRestorableState()
}
} }
// MARK: NSWindow Overrides // MARK: NSWindow Overrides
@ -756,7 +761,7 @@ extension TerminalWindow {
paletteItem.view = makeTabColorPaletteView( paletteItem.view = makeTabColorPaletteView(
selectedColor: tabColorSelection selectedColor: tabColorSelection
) { [weak target] color in ) { [weak target] color in
target?.setTabColor(color) (target?.window as? TerminalWindow)?.tabColor = color
} }
menu.addItem(paletteItem) menu.addItem(paletteItem)
} }