From cbf562ecb339abe16466e8a21900a821ab3917fe Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 11 Feb 2025 16:38:12 -0800 Subject: [PATCH] apprt/embedded: make performAction return the performable state --- include/ghostty.h | 2 +- macos/Sources/Ghostty/Ghostty.App.swift | 11 ++++++++--- src/apprt/embedded.zig | 6 ++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/ghostty.h b/include/ghostty.h index 246fb9ed3..99276cf23 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -644,7 +644,7 @@ typedef void (*ghostty_runtime_write_clipboard_cb)(void*, ghostty_clipboard_e, bool); typedef void (*ghostty_runtime_close_surface_cb)(void*, bool); -typedef void (*ghostty_runtime_action_cb)(ghostty_app_t, +typedef bool (*ghostty_runtime_action_cb)(ghostty_app_t, ghostty_target_s, ghostty_action_s); diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index 43c0f245a..a6b35f8cf 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -423,7 +423,7 @@ extension Ghostty { // MARK: Actions (macOS) - static func action(_ app: ghostty_app_t, target: ghostty_target_s, action: ghostty_action_s) { + static func action(_ app: ghostty_app_t, target: ghostty_target_s, action: ghostty_action_s) -> Bool { // Make sure it a target we understand so all our action handlers can assert switch (target.tag) { case GHOSTTY_TARGET_APP, GHOSTTY_TARGET_SURFACE: @@ -431,7 +431,7 @@ extension Ghostty { default: Ghostty.logger.warning("unknown action target=\(target.tag.rawValue)") - return + return false } // Action dispatch @@ -541,10 +541,15 @@ extension Ghostty { fallthrough case GHOSTTY_ACTION_QUIT_TIMER: Ghostty.logger.info("known but unimplemented action action=\(action.tag.rawValue)") - + return false default: Ghostty.logger.warning("unknown action action=\(action.tag.rawValue)") + return false } + + // If we reached here then we assume performed since all unknown actions + // are captured in the switch and return false. + return true } private static func quit(_ app: ghostty_app_t) { diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 3174f161e..02bbda0d9 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -46,7 +46,7 @@ pub const App = struct { wakeup: *const fn (AppUD) callconv(.C) void, /// Callback called to handle an action. - action: *const fn (*App, apprt.Target.C, apprt.Action.C) callconv(.C) void, + action: *const fn (*App, apprt.Target.C, apprt.Action.C) callconv(.C) bool, /// Read the clipboard value. The return value must be preserved /// by the host until the next call. If there is no valid clipboard @@ -495,13 +495,11 @@ pub const App = struct { action, value, }); - self.opts.action( + return self.opts.action( self, target.cval(), @unionInit(apprt.Action, @tagName(action), value).cval(), ); - - return true; } fn performPreAction(