From 86c4a8ed7d11b0b2589c39aad03aa01a476bbd54 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 25 Mar 2023 16:41:18 -0700 Subject: [PATCH] apprt/embedded: support new process alive callback on close --- include/ghostty.h | 2 +- macos/Sources/Ghostty/AppState.swift | 6 ++++-- src/apprt/embedded.zig | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/ghostty.h b/include/ghostty.h index 96f7de272..0d808373d 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -221,7 +221,7 @@ typedef void (*ghostty_runtime_set_title_cb)(void *, const char *); typedef const char* (*ghostty_runtime_read_clipboard_cb)(void *); typedef void (*ghostty_runtime_write_clipboard_cb)(void *, const char *); typedef void (*ghostty_runtime_new_split_cb)(void *, ghostty_split_direction_e); -typedef void (*ghostty_runtime_close_surface_cb)(void *); +typedef void (*ghostty_runtime_close_surface_cb)(void *, bool); typedef void (*ghostty_runtime_focus_split_cb)(void *, ghostty_split_focus_direction_e); typedef struct { diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index ab2fa605d..90bc93785 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -60,7 +60,7 @@ extension Ghostty { read_clipboard_cb: { userdata in AppState.readClipboard(userdata) }, write_clipboard_cb: { userdata, str in AppState.writeClipboard(userdata, string: str) }, new_split_cb: { userdata, direction in AppState.newSplit(userdata, direction: direction) }, - close_surface_cb: { userdata in AppState.closeSurface(userdata) }, + close_surface_cb: { userdata, processAlive in AppState.closeSurface(userdata, processAlive: processAlive) }, focus_split_cb: { userdata, direction in AppState.focusSplit(userdata, direction: direction) } ) @@ -132,7 +132,9 @@ extension Ghostty { ]) } - static func closeSurface(_ userdata: UnsafeMutableRawPointer?) { + static func closeSurface(_ userdata: UnsafeMutableRawPointer?, processAlive: Bool) { + // TODO: handle processAlive to show confirmation dialog. We probably want to attach + // it to the notification and let downstream handle it. guard let surface = self.surfaceUserdata(from: userdata) else { return } NotificationCenter.default.post(name: Notification.ghosttyCloseSurface, object: surface) } diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 08fd04a5d..9dceddc8d 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -56,7 +56,7 @@ pub const App = struct { new_split: ?*const fn (SurfaceUD, input.SplitDirection) callconv(.C) void = null, /// Close the current surface given by this function. - close_surface: ?*const fn (SurfaceUD) callconv(.C) void = null, + close_surface: ?*const fn (SurfaceUD, bool) callconv(.C) void = null, /// Focus the previous/next split (if any). focus_split: ?*const fn (SurfaceUD, input.SplitFocusDirection) callconv(.C) void = null, @@ -188,13 +188,13 @@ pub const Surface = struct { func(self.opts.userdata, direction); } - pub fn close(self: *const Surface) void { + pub fn close(self: *const Surface, process_alive: bool) void { const func = self.app.opts.close_surface orelse { log.info("runtime embedder does not support closing a surface", .{}); return; }; - func(self.opts.userdata); + func(self.opts.userdata, process_alive); } pub fn gotoSplit(self: *const Surface, direction: input.SplitFocusDirection) void { @@ -506,7 +506,7 @@ pub const CAPI = struct { /// Request that the surface become closed. This will go through the /// normal trigger process that a close surface input binding would. export fn ghostty_surface_request_close(ptr: *Surface) void { - ptr.close(); + ptr.core_surface.close(); } /// Request that the surface split in the given direction.