From 57d202066d138e9078f89c9b27302a5aee6b9422 Mon Sep 17 00:00:00 2001 From: Adam Bouker Date: Mon, 27 Apr 2026 11:35:04 -0500 Subject: [PATCH] macOS: clear stale OSC 11 background cache on config change SurfaceView caches the background color set by OSC 11 in backgroundColor. TerminalWindow.preferredBackgroundColor consults that cache before falling back to derivedConfig.backgroundColor, so once OSC 11 has fired the cached value masks any later config change. After a light/dark theme auto-switch this leaves the window chrome on the previous theme's color until the application next emits OSC 11. In ghosttyConfigDidChange, after updating derivedConfig, drop the cache when it no longer matches the new config-derived background. A subsequent ghosttyColorDidChange repopulates it as before, so within-config OSC 11 behavior is unchanged. --- .../Ghostty/Surface View/SurfaceView_AppKit.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift index 887482b30..c0013ec78 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift @@ -725,7 +725,19 @@ extension Ghostty { // Update our derived config DispatchQueue.main.async { [weak self] in - self?.derivedConfig = DerivedConfig(config) + guard let self else { return } + self.derivedConfig = DerivedConfig(config) + + // If the cached OSC 11 background color disagrees with the new + // config-derived background, drop it so window chrome follows + // the new config (e.g., on light/dark theme auto-switch). The + // cached value is restored next time the terminal emits a + // color_change. + if let cached = self.backgroundColor, + cached != self.derivedConfig.backgroundColor + { + self.backgroundColor = nil + } } }