From 994d456223ffae1fc4e888942b7f9eced2a669a8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 4 Aug 2023 17:24:28 -0700 Subject: [PATCH] set the title of the window --- .../Features/Primary Window/PrimaryView.swift | 12 ++++++++++-- .../Features/Primary Window/PrimaryWindow.swift | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Features/Primary Window/PrimaryView.swift b/macos/Sources/Features/Primary Window/PrimaryView.swift index adeef5574..a7843f9ba 100644 --- a/macos/Sources/Features/Primary Window/PrimaryView.swift +++ b/macos/Sources/Features/Primary Window/PrimaryView.swift @@ -16,12 +16,13 @@ struct PrimaryView: View { @State private var window: NSWindow? // This handles non-native fullscreen - @State private var fsHandler = FullScreenHandler() + @State private var fullScreen = FullScreenHandler() // This seems like a crutch after switchign from SwiftUI to AppKit lifecycle. @FocusState private var focused: Bool @FocusedValue(\.ghosttySurfaceView) private var focusedSurface + @FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle var body: some View { switch ghostty.readiness { @@ -58,6 +59,13 @@ struct PrimaryView: View { .onChange(of: focusedSurface) { newValue in self.focusedSurfaceWrapper.surface = newValue?.surface } + .onChange(of: surfaceTitle) { newValue in + // We need to handle this manually because we are using AppKit lifecycle + // so navigationTitle no longer works. + guard let window = self.window else { return } + guard let title = newValue else { return } + window.title = title + } .confirmationDialog( "Quit Ghostty?", isPresented: confirmQuitting) { @@ -115,7 +123,7 @@ struct PrimaryView: View { guard let useNonNativeFullscreenAny = notification.userInfo?[Ghostty.Notification.NonNativeFullscreenKey] else { return } guard let useNonNativeFullscreen = useNonNativeFullscreenAny as? Bool else { return } - self.fsHandler.toggleFullscreen(window: window, nonNativeFullscreen: useNonNativeFullscreen) + self.fullScreen.toggleFullscreen(window: window, nonNativeFullscreen: useNonNativeFullscreen) // After toggling fullscreen we need to focus the terminal again. self.focused = true } diff --git a/macos/Sources/Features/Primary Window/PrimaryWindow.swift b/macos/Sources/Features/Primary Window/PrimaryWindow.swift index 9eccb52f2..7b2e7c08e 100644 --- a/macos/Sources/Features/Primary Window/PrimaryWindow.swift +++ b/macos/Sources/Features/Primary Window/PrimaryWindow.swift @@ -28,6 +28,7 @@ class PrimaryWindow: NSWindow { appDelegate: appDelegate, focusedSurfaceWrapper: window.focusedSurfaceWrapper)) window.windowController?.shouldCascadeWindows = true + window.title = "Ghostty 👻" return window }