macos: Remove the legacy SurfaceTree

pull/7523/head
Mitchell Hashimoto 2025-06-04 11:51:38 -07:00
parent 22819f8a29
commit f1ed07caf4
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
6 changed files with 24 additions and 37 deletions

View File

@ -741,8 +741,10 @@ class AppDelegate: NSObject,
func findSurface(forUUID uuid: UUID) -> Ghostty.SurfaceView? {
for c in terminalManager.windows {
if let v = c.controller.surfaceTree?.findUUID(uuid: uuid) {
return v
for view in c.controller.surfaceTree2 {
if view.uuid == uuid {
return view
}
}
}

View File

@ -30,11 +30,11 @@ class QuickTerminalController: BaseTerminalController {
init(_ ghostty: Ghostty.App,
position: QuickTerminalPosition = .top,
baseConfig base: Ghostty.SurfaceConfiguration? = nil,
surfaceTree tree: Ghostty.SplitNode? = nil
surfaceTree2 tree2: SplitTree<Ghostty.SurfaceView>? = nil
) {
self.position = position
self.derivedConfig = DerivedConfig(ghostty.config)
super.init(ghostty, baseConfig: base, surfaceTree: tree)
super.init(ghostty, baseConfig: base, surfaceTree2: tree2)
// Setup our notifications for behaviors
let center = NotificationCenter.default
@ -233,13 +233,14 @@ class QuickTerminalController: BaseTerminalController {
// Animate the window in
animateWindowIn(window: window, from: position)
// If our surface tree is nil then we initialize a new terminal. The surface
// tree can be nil if for example we run "eixt" in the terminal and force
// If our surface tree is empty then we initialize a new terminal. The surface
// tree can be empty if for example we run "exit" in the terminal and force
// animate out.
if (surfaceTree == nil) {
let leaf: Ghostty.SplitNode.Leaf = .init(ghostty.app!, baseConfig: nil)
surfaceTree = .leaf(leaf)
focusedSurface = leaf.surface
if surfaceTree2.isEmpty,
let ghostty_app = ghostty.app {
let view = Ghostty.SurfaceView(ghostty_app, baseConfig: nil)
surfaceTree2 = SplitTree(view: view)
focusedSurface = view
}
}

View File

@ -41,9 +41,7 @@ class BaseTerminalController: NSWindowController,
didSet { syncFocusToSurfaceTree() }
}
/// The surface tree for this window.
@Published var surfaceTree: Ghostty.SplitNode? = nil
/// The tree of splits within this terminal window.
@Published var surfaceTree2: SplitTree<Ghostty.SurfaceView> = .init() {
didSet { surfaceTreeDidChange(from: oldValue, to: surfaceTree2) }
}
@ -88,7 +86,6 @@ class BaseTerminalController: NSWindowController,
init(_ ghostty: Ghostty.App,
baseConfig base: Ghostty.SurfaceConfiguration? = nil,
surfaceTree tree: Ghostty.SplitNode? = nil,
surfaceTree2 tree2: SplitTree<Ghostty.SurfaceView>? = nil
) {
self.ghostty = ghostty
@ -98,7 +95,6 @@ class BaseTerminalController: NSWindowController,
// Initialize our initial surface.
guard let ghostty_app = ghostty.app else { preconditionFailure("app must be loaded") }
self.surfaceTree = tree ?? .leaf(.init(ghostty_app, baseConfig: base))
self.surfaceTree2 = tree2 ?? .init(view: Ghostty.SurfaceView(ghostty_app, baseConfig: base))
// Setup our notifications for behaviors
@ -171,11 +167,11 @@ class BaseTerminalController: NSWindowController,
}
}
/// Called when the surfaceTree variable changed.
/// Called when the surfaceTree2 variable changed.
///
/// Subclasses should call super first.
func surfaceTreeDidChange(from: SplitTree<Ghostty.SurfaceView>, to: SplitTree<Ghostty.SurfaceView>) {
// If our surface tree becomes nil then we have no focused surface.
// If our surface tree becomes empty then we have no focused surface.
if (to.isEmpty) {
focusedSurface = nil
}

View File

@ -45,7 +45,7 @@ class TerminalController: BaseTerminalController {
// Setup our initial derived config based on the current app config
self.derivedConfig = DerivedConfig(ghostty.config)
super.init(ghostty, baseConfig: base, surfaceTree: tree, surfaceTree2: tree2)
super.init(ghostty, baseConfig: base, surfaceTree2: tree2)
// Setup our notifications for behaviors
let center = NotificationCenter.default
@ -154,7 +154,7 @@ class TerminalController: BaseTerminalController {
// If we have no surfaces in our window (is that possible?) then we update
// our window appearance based on the root config. If we have surfaces, we
// don't call this because the TODO
if surfaceTree == nil {
if surfaceTree2.isEmpty {
syncAppearance(.init(config))
}
@ -456,10 +456,10 @@ class TerminalController: BaseTerminalController {
// If we have only a single surface (no splits) and there is a default size then
// we should resize to that default size.
if case let .leaf(leaf) = surfaceTree {
if case let .leaf(view) = surfaceTree2.root {
// If this is our first surface then our focused surface will be nil
// so we force the focused surface to the leaf.
focusedSurface = leaf.surface
focusedSurface = view
if let defaultSize {
window.setFrame(defaultSize, display: true)

View File

@ -197,10 +197,9 @@ class TerminalManager {
/// Creates a window controller, adds it to our managed list, and returns it.
func createWindow(withBaseConfig base: Ghostty.SurfaceConfiguration? = nil,
withSurfaceTree tree: Ghostty.SplitNode? = nil,
withSurfaceTree2 tree2: SplitTree<Ghostty.SurfaceView>? = nil) -> TerminalController {
// Initialize our controller to load the window
let c = TerminalController(ghostty, withBaseConfig: base, withSurfaceTree: tree, withSurfaceTree2: tree2)
let c = TerminalController(ghostty, withBaseConfig: base, withSurfaceTree2: tree2)
// Create a listener for when the window is closed so we can remove it.
let pubClose = NotificationCenter.default.publisher(

View File

@ -7,12 +7,10 @@ class TerminalRestorableState: Codable {
static let version: Int = 3
let focusedSurface: String?
let surfaceTree: Ghostty.SplitNode?
let surfaceTree2: SplitTree<Ghostty.SurfaceView>?
let surfaceTree2: SplitTree<Ghostty.SurfaceView>
init(from controller: TerminalController) {
self.focusedSurface = controller.focusedSurface?.uuid.uuidString
self.surfaceTree = controller.surfaceTree
self.surfaceTree2 = controller.surfaceTree2
}
@ -28,7 +26,6 @@ class TerminalRestorableState: Codable {
return nil
}
self.surfaceTree = v.value.surfaceTree
self.surfaceTree2 = v.value.surfaceTree2
self.focusedSurface = v.value.focusedSurface
}
@ -87,7 +84,6 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration {
// createWindow so that AppKit can place the window wherever it should
// be.
let c = appDelegate.terminalManager.createWindow(
withSurfaceTree: state.surfaceTree,
withSurfaceTree2: state.surfaceTree2
)
guard let window = c.window else {
@ -96,10 +92,8 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration {
}
// Setup our restored state on the controller
// First try to find the focused surface in surfaceTree2
if let focusedStr = state.focusedSurface,
let focusedUUID = UUID(uuidString: focusedStr) {
// Try surfaceTree2 first
// Find the focused surface in surfaceTree2
if let focusedStr = state.focusedSurface {
var foundView: Ghostty.SurfaceView?
for view in c.surfaceTree2 {
if view.uuid.uuidString == focusedStr {
@ -108,11 +102,6 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration {
}
}
// Fall back to surfaceTree if not found
if foundView == nil {
foundView = c.surfaceTree?.findUUID(uuid: focusedUUID)
}
if let view = foundView {
c.focusedSurface = view
restoreFocus(to: view, inWindow: window)