set the title of the window

This commit is contained in:
Mitchell Hashimoto
2023-08-04 17:24:28 -07:00
parent 9105637697
commit 994d456223
2 changed files with 11 additions and 2 deletions

View File

@ -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
}

View File

@ -28,6 +28,7 @@ class PrimaryWindow: NSWindow {
appDelegate: appDelegate,
focusedSurfaceWrapper: window.focusedSurfaceWrapper))
window.windowController?.shouldCascadeWindows = true
window.title = "Ghostty 👻"
return window
}