From 5867fe425f290ac2995ab59b95eac2c74111d5ac Mon Sep 17 00:00:00 2001 From: Trevor Elkins Date: Thu, 26 Dec 2024 17:44:06 -0500 Subject: [PATCH] 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.