diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 9862e1288..fd5ca9ffb 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -149,10 +149,8 @@ class BaseTerminalController: NSWindowController, /// /// Subclasses should call super first. func surfaceTreeDidChange(from: Ghostty.SplitNode?, to: Ghostty.SplitNode?) { - // If our surface tree becomes nil then ensure all surfaces - // in the old tree have closed. + // If our surface tree becomes nil then we have no focused surface. if (to == nil) { - from?.close() focusedSurface = nil } } diff --git a/macos/Sources/Ghostty/Ghostty.SplitNode.swift b/macos/Sources/Ghostty/Ghostty.SplitNode.swift index 95c019b1f..97b20acd3 100644 --- a/macos/Sources/Ghostty/Ghostty.SplitNode.swift +++ b/macos/Sources/Ghostty/Ghostty.SplitNode.swift @@ -102,19 +102,6 @@ extension Ghostty { } } - /// Close the surface associated with this node. This will likely deinitialize the - /// surface. At this point, the surface view in this node tree can never be used again. - func close() { - switch (self) { - case .leaf(let leaf): - leaf.surface.close() - - case .split(let container): - container.topLeft.close() - container.bottomRight.close() - } - } - /// Returns true if any surface in the split stack requires quit confirmation. func needsConfirmQuit() -> Bool { switch (self) { @@ -224,7 +211,7 @@ extension Ghostty { self.app = app self.surface = SurfaceView(app, baseConfig: baseConfig, uuid: uuid) } - + // MARK: - Hashable func hash(into hasher: inout Hasher) { diff --git a/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift b/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift index 3e942d774..92528ace7 100644 --- a/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift +++ b/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift @@ -75,7 +75,6 @@ extension Ghostty { .onReceive(pubZoom) { onZoom(notification: $0) } } } - .id(node) // Needed for change detection on node } else { // On these events we want to reset the split state and call it. let pubSplit = center.publisher(for: Notification.ghosttyNewSplit, object: zoomedSurface!) @@ -289,7 +288,7 @@ extension Ghostty { let neighbors: SplitNode.Neighbors @Binding var node: SplitNode? - @StateObject var container: SplitNode.Container + @ObservedObject var container: SplitNode.Container var body: some View { SplitView( @@ -331,7 +330,6 @@ extension Ghostty { } // Closing - container.topLeft.close() node = container.bottomRight switch (node) { @@ -362,7 +360,6 @@ extension Ghostty { } // Closing - container.bottomRight.close() node = container.topLeft switch (node) { diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 8e8838471..99f901792 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -279,22 +279,14 @@ extension Ghostty { // Remove ourselves from secure input if we have to SecureInput.shared.removeScoped(ObjectIdentifier(self)) - guard let surface = self.surface else { return } - ghostty_surface_free(surface) - } - - /// Close the surface early. This will free the associated Ghostty surface and the view will - /// no longer render. The view can never be used again. This is a way for us to free the - /// Ghostty resources while references may still be held to this view. I've found that SwiftUI - /// tends to hold this view longer than it should so we free the expensive stuff explicitly. - func close() { // Remove any notifications associated with this surface let identifiers = Array(self.notificationIdentifiers) UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers) - guard let surface = self.surface else { return } - ghostty_surface_free(surface) - self.surface = nil + // Free our core surface resources + if let surface = self.surface { + ghostty_surface_free(surface) + } } func focusDidChange(_ focused: Bool) {