macOS: move readonly to OSSurfaceView

This commit is contained in:
Lukas
2026-04-12 12:12:49 +02:00
parent 3834751aef
commit 2efe851cda
3 changed files with 23 additions and 16 deletions

View File

@@ -42,14 +42,37 @@ extension Ghostty {
// structure because I'm lazy.
@Published var surfaceSize: ghostty_surface_size_s?
/// True when the surface is in readonly mode.
@Published private(set) var readonly: Bool = false
init(id: UUID?, frame: CGRect) {
self.id = id ?? UUID()
super.init(frame: frame)
// Before we initialize the surface we want to register our notifications
// so there is no window where we can't receive them.
let center = NotificationCenter.default
center.addObserver(
self,
selector: #selector(ghosttyDidChangeReadonly(_:)),
name: .ghosttyDidChangeReadonly,
object: self,
)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) is not supported for this view")
}
deinit {
NotificationCenter.default
.removeObserver(self)
}
@objc private func ghosttyDidChangeReadonly(_ notification: Foundation.Notification) {
guard let value = notification.userInfo?[Foundation.Notification.Name.ReadonlyKey] as? Bool else { return }
readonly = value
}
}
}

View File

@@ -99,9 +99,6 @@ extension Ghostty {
/// True when the bell is active. This is set inactive on focus or event.
@Published private(set) var bell: Bool = false
/// True when the surface is in readonly mode.
@Published private(set) var readonly: Bool = false
/// True when the surface should show a highlight effect (e.g., when presented via goto_split).
@Published private(set) var highlighted: Bool = false
@@ -324,11 +321,6 @@ extension Ghostty {
selector: #selector(ghosttyBellDidRing(_:)),
name: .ghosttyBellDidRing,
object: self)
center.addObserver(
self,
selector: #selector(ghosttyDidChangeReadonly(_:)),
name: .ghosttyDidChangeReadonly,
object: self)
center.addObserver(
self,
selector: #selector(windowDidChangeScreen),
@@ -747,11 +739,6 @@ extension Ghostty {
bell = true
}
@objc private func ghosttyDidChangeReadonly(_ notification: SwiftUI.Notification) {
guard let value = notification.userInfo?[SwiftUI.Notification.Name.ReadonlyKey] as? Bool else { return }
readonly = value
}
@objc private func windowDidChangeScreen(notification: SwiftUI.Notification) {
guard let window = self.window else { return }
guard let object = notification.object as? NSWindow, window == object else { return }

View File

@@ -14,9 +14,6 @@ extension Ghostty {
// The current search state. When non-nil, the search overlay should be shown.
@Published var searchState: SearchState?
/// True when the surface is in readonly mode.
@Published private(set) var readonly: Bool = false
/// True when the surface should show a highlight effect (e.g., when presented via goto_split).
@Published private(set) var highlighted: Bool = false