mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00

We were using the NSView resize func before but this isn't called by SwiftUI on macOS 12. Instead we wrap it in a GeometryReader and detect the size change in updateNSView so we can call the proper ghostty callback.
25 lines
920 B
Swift
25 lines
920 B
Swift
import SwiftUI
|
|
import GhosttyKit
|
|
|
|
struct TerminalView: View {
|
|
let app: ghostty_app_t
|
|
@FocusState private var surfaceFocus: Bool
|
|
@Environment(\.isKeyWindow) private var isKeyWindow: Bool
|
|
@State private var title: String = "Ghostty"
|
|
|
|
// This is true if the terminal is considered "focused". The terminal is focused if
|
|
// it is both individually focused and the containing window is key.
|
|
private var hasFocus: Bool { surfaceFocus && isKeyWindow }
|
|
|
|
var body: some View {
|
|
// We use a GeometryReader to get the frame bounds so that our metal surface
|
|
// is up to date. See TerminalSurfaceView for why we don't use the NSView
|
|
// resize callback.
|
|
GeometryReader { geo in
|
|
TerminalSurfaceView(app, hasFocus: hasFocus, size: geo.size, title: $title)
|
|
.focused($surfaceFocus)
|
|
.navigationTitle(title)
|
|
}
|
|
}
|
|
}
|