macos: zoomed splits put an emoji in the title bar

This commit is contained in:
Mitchell Hashimoto
2023-09-02 16:33:33 -07:00
parent 4570356e57
commit e2282f1f4d
3 changed files with 33 additions and 3 deletions

View File

@ -26,6 +26,7 @@ struct PrimaryView: View {
@FocusedValue(\.ghosttySurfaceView) private var focusedSurface @FocusedValue(\.ghosttySurfaceView) private var focusedSurface
@FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle @FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle
@FocusedValue(\.ghosttySurfaceZoomed) private var zoomedSplit
// This is true if this view should be the one to show the quit confirmation. // This is true if this view should be the one to show the quit confirmation.
var ownsQuitConfirmation: Bool { var ownsQuitConfirmation: Bool {
@ -49,6 +50,25 @@ struct PrimaryView: View {
return window == firstWindow return window == firstWindow
} }
// The title for our window
private var title: String {
var title = "👻"
if let surfaceTitle = surfaceTitle {
if (surfaceTitle.count > 0) {
title = surfaceTitle
}
}
if let zoomedSplit = zoomedSplit {
if zoomedSplit {
title = "🔍 " + title
}
}
return title
}
var body: some View { var body: some View {
switch ghostty.readiness { switch ghostty.readiness {
case .loading: case .loading:
@ -84,12 +104,11 @@ struct PrimaryView: View {
.onChange(of: focusedSurface) { newValue in .onChange(of: focusedSurface) { newValue in
self.focusedSurfaceWrapper.surface = newValue?.surface self.focusedSurfaceWrapper.surface = newValue?.surface
} }
.onChange(of: surfaceTitle) { newValue in .onChange(of: title) { newValue in
// We need to handle this manually because we are using AppKit lifecycle // We need to handle this manually because we are using AppKit lifecycle
// so navigationTitle no longer works. // so navigationTitle no longer works.
guard let window = self.window else { return } guard let window = self.window else { return }
guard let title = newValue else { return } window.title = newValue
window.title = title
} }
.confirmationDialog( .confirmationDialog(
"Quit Ghostty?", "Quit Ghostty?",

View File

@ -33,6 +33,7 @@ extension Ghostty {
SurfaceWrapper(surfaceView: surfaceView) SurfaceWrapper(surfaceView: surfaceView)
} }
} }
.focusedValue(\.ghosttySurfaceZoomed, zoomedSurface != nil)
} }
} }
} }

View File

@ -710,3 +710,13 @@ extension FocusedValues {
} }
} }
extension FocusedValues {
var ghosttySurfaceZoomed: Bool? {
get { self[FocusedGhosttySurfaceZoomed.self] }
set { self[FocusedGhosttySurfaceZoomed.self] = newValue }
}
struct FocusedGhosttySurfaceZoomed: FocusedValueKey {
typealias Value = Bool
}
}