From dc6e5e143704c92df9f3c21e2e23cff7425eac2b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 9 Mar 2023 11:40:47 -0800 Subject: [PATCH] macos: fix bug where like... 5 terminals were being launched in the background --- macos/Sources/Ghostty/Ghostty.SplitView.swift | 30 ++++++++++--------- src/Surface.zig | 1 + 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.SplitView.swift b/macos/Sources/Ghostty/Ghostty.SplitView.swift index bdfd9c2b1..47a8be4f2 100644 --- a/macos/Sources/Ghostty/Ghostty.SplitView.swift +++ b/macos/Sources/Ghostty/Ghostty.SplitView.swift @@ -7,12 +7,10 @@ extension Ghostty { /// split direction by splitting the terminal. struct TerminalSplit: View { @Environment(\.ghosttyApp) private var app - @FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle: String? - + var body: some View { if let app = app { TerminalSplitRoot(app: app) - .navigationTitle(surfaceTitle ?? "Ghostty") } } } @@ -49,7 +47,6 @@ extension Ghostty { class Leaf: ObservableObject { let app: ghostty_app_t @Published var surface: SurfaceView - @Published var parent: SplitNode? = nil /// Initialize a new leaf which creates a new terminal surface. init(_ app: ghostty_app_t) { @@ -85,21 +82,26 @@ extension Ghostty { /// This is an ignored value because at the root we can't close. @State private var ignoredRequestClose: Bool = false + @FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle: String? + init(app: ghostty_app_t) { - _node = State(initialValue: SplitNode.noSplit(.init(app))) + _node = State(wrappedValue: SplitNode.noSplit(.init(app))) } var body: some View { - switch (node) { - case .noSplit(let leaf): - TerminalSplitLeaf(leaf: leaf, node: $node, requestClose: $ignoredRequestClose) - - case .horizontal(let container): - TerminalSplitContainer(direction: .horizontal, node: $node, container: container) - - case .vertical(let container): - TerminalSplitContainer(direction: .vertical, node: $node, container: container) + ZStack { + switch (node) { + case .noSplit(let leaf): + TerminalSplitLeaf(leaf: leaf, node: $node, requestClose: $ignoredRequestClose) + + case .horizontal(let container): + TerminalSplitContainer(direction: .horizontal, node: $node, container: container) + + case .vertical(let container): + TerminalSplitContainer(direction: .vertical, node: $node, container: container) + } } + .navigationTitle(surfaceTitle ?? "Ghostty") } } diff --git a/src/Surface.zig b/src/Surface.zig index b3e7693cd..f2452b85b 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -476,6 +476,7 @@ pub fn deinit(self: *Surface) void { self.alloc.destroy(self.font_group); self.alloc.destroy(self.renderer_state.mutex); + log.info("surface closed addr={x}", .{@ptrToInt(self)}); } /// Called from the app thread to handle mailbox messages to our specific