From 3afb9065f03f662a3f158b35add3eeffacfbfa23 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 20 Nov 2024 15:22:05 -0800 Subject: [PATCH] macos: listen for config change and post a notification --- macos/Sources/Ghostty/Ghostty.App.swift | 28 +++++++++++++++++++++++++ macos/Sources/Ghostty/Package.swift | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index 489493ad3..cc365ce4f 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -524,6 +524,9 @@ extension Ghostty { case GHOSTTY_ACTION_KEY_SEQUENCE: keySequence(app, target: target, v: action.action.key_sequence) + case GHOSTTY_ACTION_CONFIG_CHANGE: + configChange(app, target: target, v: action.action.config_change) + case GHOSTTY_ACTION_COLOR_CHANGE: fallthrough case GHOSTTY_ACTION_CLOSE_ALL_WINDOWS: @@ -1159,6 +1162,31 @@ extension Ghostty { } } + private static func configChange( + _ app: ghostty_app_t, + target: ghostty_target_s, + v: ghostty_action_config_change_s) { + switch (target.tag) { + case GHOSTTY_TARGET_APP: + NotificationCenter.default.post( + name: .ghosttyConfigChange, + object: nil + ) + return + + case GHOSTTY_TARGET_SURFACE: + guard let surface = target.target.surface else { return } + guard let surfaceView = self.surfaceView(from: surface) else { return } + NotificationCenter.default.post( + name: .ghosttyConfigChange, + object: surfaceView + ) + + default: + assertionFailure() + } + } + // MARK: User Notifications /// Handle a received user notification. This is called when a user notification is clicked or dismissed by the user diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index e4ab91a5f..b926edab5 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -206,6 +206,10 @@ extension Ghostty { // MARK: Surface Notification extension Notification.Name { + /// Configuration change. If the object is nil then it is app-wide. Otherwise its surface-specific. + static let ghosttyConfigChange = Notification.Name("com.mitchellh.ghostty.configChange") + static let GhosttyConfigChangeKey = ghosttyConfigChange.rawValue + /// Goto tab. Has tab index in the userinfo. static let ghosttyMoveTab = Notification.Name("com.mitchellh.ghostty.moveTab") static let GhosttyMoveTabKey = ghosttyMoveTab.rawValue