Fix Ghostty config reload theme refresh (#812) (#818)

This commit is contained in:
Austin Wang 2026-03-03 16:28:51 -08:00 committed by GitHub
parent 34c6250a37
commit a12fb563ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 0 deletions

View file

@ -3372,6 +3372,39 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
return nil
}
func refreshTerminalSurfacesAfterGhosttyConfigReload(source: String) {
var refreshedCount = 0
forEachTerminalPanel { terminalPanel in
terminalPanel.hostedView.reconcileGeometryNow()
terminalPanel.surface.forceRefresh()
refreshedCount += 1
}
#if DEBUG
dlog("reload.config.surfaceRefresh source=\(source) count=\(refreshedCount)")
#endif
}
private func forEachTerminalPanel(_ body: (TerminalPanel) -> Void) {
var seenManagers: Set<ObjectIdentifier> = []
func visitManager(_ manager: TabManager?) {
guard let manager else { return }
let managerId = ObjectIdentifier(manager)
guard seenManagers.insert(managerId).inserted else { return }
for workspace in manager.tabs {
for panel in workspace.panels.values {
guard let terminalPanel = panel as? TerminalPanel else { continue }
body(terminalPanel)
}
}
}
visitManager(tabManager)
for context in mainWindowContexts.values {
visitManager(context.tabManager)
}
}
func focusMainWindow(windowId: UUID) -> Bool {
guard let window = windowForMainWindowId(windowId) else { return false }
if TerminalController.shouldSuppressSocketCommandActivation() {

View file

@ -660,6 +660,7 @@ class GhosttyApp {
private func loadDefaultConfigFilesWithLegacyFallback(_ config: ghostty_config_t) {
ghostty_config_load_default_files(config)
loadLegacyGhosttyConfigIfNeeded(config)
ghostty_config_load_recursive_files(config)
ghostty_config_finalize(config)
}
@ -767,6 +768,7 @@ class GhosttyApp {
ghostty_app_update_config(app, config)
lastAppearanceColorScheme = GhosttyConfig.currentColorSchemePreference()
NotificationCenter.default.post(name: .ghosttyConfigDidReload, object: nil)
scheduleSurfaceRefreshAfterConfigurationReload(source: source)
logThemeAction("reload end source=\(source) soft=\(soft) mode=soft")
return
}
@ -791,9 +793,16 @@ class GhosttyApp {
config = newConfig
lastAppearanceColorScheme = GhosttyConfig.currentColorSchemePreference()
NotificationCenter.default.post(name: .ghosttyConfigDidReload, object: nil)
scheduleSurfaceRefreshAfterConfigurationReload(source: source)
logThemeAction("reload end source=\(source) soft=\(soft) mode=full")
}
private func scheduleSurfaceRefreshAfterConfigurationReload(source: String) {
DispatchQueue.main.async {
AppDelegate.shared?.refreshTerminalSurfacesAfterGhosttyConfigReload(source: source)
}
}
func synchronizeThemeWithAppearance(_ appearance: NSAppearance?, source: String) {
let currentColorScheme = GhosttyConfig.currentColorSchemePreference(
appAppearance: appearance ?? NSApp?.effectiveAppearance