From 0388dc35bb82ea8cdc729f566fad45ed83cd7e9d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 Mar 2023 15:26:58 -0800 Subject: [PATCH] macos: set proper window title for focused split --- macos/Sources/Ghostty/Ghostty.SplitView.swift | 7 ++----- macos/Sources/Ghostty/SurfaceView.swift | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.SplitView.swift b/macos/Sources/Ghostty/Ghostty.SplitView.swift index e2af77be3..2b0f1a29e 100644 --- a/macos/Sources/Ghostty/Ghostty.SplitView.swift +++ b/macos/Sources/Ghostty/Ghostty.SplitView.swift @@ -7,10 +7,12 @@ 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 { TerminalSplitChild(app) + .navigationTitle(surfaceTitle ?? "Ghostty") } } } @@ -22,11 +24,6 @@ extension Ghostty { case horizontal } - enum Side: Hashable { - case TopLeft - case BottomRight - } - /// The stored state between invocations. class ViewState: ObservableObject { /// The direction of the split currently diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 3c1079885..76c123fcd 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -5,10 +5,12 @@ extension Ghostty { /// Render a terminal for the active app in the environment. struct Terminal: View { @Environment(\.ghosttyApp) private var app + @FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle: String? var body: some View { if let app = self.app { TerminalForApp(app) + .navigationTitle(surfaceTitle ?? "Ghostty") } } } @@ -46,8 +48,7 @@ extension Ghostty { GeometryReader { geo in Surface(view: surfaceView, hasFocus: hasFocus, size: geo.size) .focused($surfaceFocus) - .focusedValue(\.ghosttySurfaceView, surfaceView) - .navigationTitle(surfaceView.title) + .focusedValue(\.ghosttySurfaceTitle, surfaceView.title) } .ghosttySurfaceView(surfaceView) } @@ -547,3 +548,14 @@ extension FocusedValues { } } +extension FocusedValues { + var ghosttySurfaceTitle: String? { + get { self[FocusedGhosttySurfaceTitle.self] } + set { self[FocusedGhosttySurfaceTitle.self] = newValue } + } + + struct FocusedGhosttySurfaceTitle: FocusedValueKey { + typealias Value = String + } +} +