macOS: add shared OSSurfaceView

This commit is contained in:
Lukas
2026-04-12 11:54:16 +02:00
parent c36b458ad5
commit 8bd1aba40a
3 changed files with 25 additions and 15 deletions

View File

@@ -0,0 +1,21 @@
import Foundation
import GhosttyKit
extension Ghostty {
class OSSurfaceView: OSView, ObservableObject {
typealias ID = UUID
/// Unique ID per surface
let id: UUID
init(id: UUID?, frame: CGRect) {
self.id = id ?? UUID()
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) is not supported for this view")
}
}
}

View File

@@ -7,11 +7,7 @@ import GhosttyKit
extension Ghostty {
/// The NSView implementation for a terminal surface.
class SurfaceView: OSView, ObservableObject, Codable, Identifiable {
typealias ID = UUID
/// Unique ID per surface
let id: UUID
class SurfaceView: OSSurfaceView, Codable, Identifiable {
// The current title of the surface as defined by the pty. This can be
// changed with escape codes. This is public because the callbacks go
@@ -255,7 +251,6 @@ extension Ghostty {
init(_ app: ghostty_app_t, baseConfig: SurfaceConfiguration? = nil, uuid: UUID? = nil) {
self.markedText = NSMutableAttributedString()
self.id = uuid ?? .init()
// Our initial config always is our application wide config.
if let appDelegate = NSApplication.shared.delegate as? AppDelegate {
@@ -273,7 +268,7 @@ extension Ghostty {
// Initialize with some default frame size. The important thing is that this
// is non-zero so that our layer bounds are non-zero so that our renderer
// can do SOMETHING.
super.init(frame: NSRect(x: 0, y: 0, width: 800, height: 600))
super.init(id: uuid, frame: NSRect(x: 0, y: 0, width: 800, height: 600))
// Our cache of screen data
cachedScreenContents = .init(duration: .milliseconds(500)) { [weak self] in

View File

@@ -3,12 +3,7 @@ import GhosttyKit
extension Ghostty {
/// The UIView implementation for a terminal surface.
class SurfaceView: UIView, ObservableObject {
typealias ID = UUID
/// Unique ID per surface
let id: UUID
class SurfaceView: OSSurfaceView {
// The current title of the surface as defined by the pty. This can be
// changed with escape codes. This is public because the callbacks go
// to the app level and it is set from there.
@@ -65,12 +60,11 @@ extension Ghostty {
private(set) var surface: ghostty_surface_t?
init(_ app: ghostty_app_t, baseConfig: SurfaceConfiguration? = nil, uuid: UUID? = nil) {
self.id = uuid ?? .init()
// Initialize with some default frame size. The important thing is that this
// is non-zero so that our layer bounds are non-zero so that our renderer
// can do SOMETHING.
super.init(frame: CGRect(x: 0, y: 0, width: 800, height: 600))
super.init(id: uuid, frame: CGRect(x: 0, y: 0, width: 800, height: 600))
// Setup our surface. This will also initialize all the terminal IO.
let surface_cfg = baseConfig ?? SurfaceConfiguration()