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.
pull/12822/head
Adam Bouker 2026-04-27 11:35:04 -05:00
parent 2e5ad917eb
commit 57d202066d
1 changed files with 13 additions and 1 deletions

View File

@ -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
}
}
}