From 5867fe425f290ac2995ab59b95eac2c74111d5ac Mon Sep 17 00:00:00 2001 From: Trevor Elkins Date: Thu, 26 Dec 2024 17:44:06 -0500 Subject: [PATCH 1/2] Move notification handling outside of the current render loop --- .../Sources/Ghostty/SurfaceView_AppKit.swift | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 48c4249be..45f036470 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -361,17 +361,23 @@ extension Ghostty { @objc private func onUpdateRendererHealth(notification: SwiftUI.Notification) { guard let healthAny = notification.userInfo?["health"] else { return } guard let health = healthAny as? ghostty_action_renderer_health_e else { return } - healthy = health == GHOSTTY_RENDERER_HEALTH_OK + DispatchQueue.main.async { [weak self] in + self?.healthy = health == GHOSTTY_RENDERER_HEALTH_OK + } } @objc private func ghosttyDidContinueKeySequence(notification: SwiftUI.Notification) { guard let keyAny = notification.userInfo?[Ghostty.Notification.KeySequenceKey] else { return } guard let key = keyAny as? Ghostty.KeyEquivalent else { return } - keySequence.append(key) + DispatchQueue.main.async { [weak self] in + self?.keySequence.append(key) + } } @objc private func ghosttyDidEndKeySequence(notification: SwiftUI.Notification) { - keySequence = [] + DispatchQueue.main.async { [weak self] in + self?.keySequence = [] + } } @objc private func ghosttyConfigDidChange(_ notification: SwiftUI.Notification) { @@ -381,7 +387,9 @@ extension Ghostty { ] as? Ghostty.Config else { return } // Update our derived config - self.derivedConfig = DerivedConfig(config) + DispatchQueue.main.async { [weak self] in + self?.derivedConfig = DerivedConfig(config) + } } @objc private func ghosttyColorDidChange(_ notification: SwiftUI.Notification) { @@ -391,7 +399,9 @@ extension Ghostty { switch (change.kind) { case .background: - self.backgroundColor = change.color + DispatchQueue.main.async { [weak self] in + self?.backgroundColor = change.color + } default: // We don't do anything for the other colors yet. From c1f61b434484d41a99ec2ebbd5293c6c42928e66 Mon Sep 17 00:00:00 2001 From: Trevor Elkins Date: Thu, 26 Dec 2024 17:48:14 -0500 Subject: [PATCH 2/2] one more --- macos/Sources/Ghostty/SurfaceView_AppKit.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 45f036470..60de024d3 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -423,7 +423,9 @@ extension Ghostty { // We also just trigger a backing property change. Just in case the screen has // a different scaling factor, this ensures that we update our content scale. // Issue: https://github.com/ghostty-org/ghostty/issues/2731 - viewDidChangeBackingProperties() + DispatchQueue.main.async { [weak self] in + self?.viewDidChangeBackingProperties() + } } // MARK: - NSView