From 5aa351412212d0db86f792368a1adc82456c303a Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Wed, 5 Apr 2023 12:49:03 -0700 Subject: [PATCH 1/2] config: add confirm-close-surface --- src/config.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/config.zig b/src/config.zig index c7b55060c..6d75e4e11 100644 --- a/src/config.zig +++ b/src/config.zig @@ -164,6 +164,10 @@ pub const Config = struct { /// Additional configuration files to read. @"config-file": RepeatableString = .{}, + // Confirms that a surface should be closed before closing it. This defaults + // to true. If set to false, surfaces will close without any confirmation. + @"confirm-close-surface": bool = true, + /// This is set by the CLI parser for deinit. _arena: ?ArenaAllocator = null, From 3c49ece06911f96ca0e4104e62ced1e4b978d470 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Wed, 5 Apr 2023 12:49:12 -0700 Subject: [PATCH 2/2] pass through confirm close config in surface --- src/Surface.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Surface.zig b/src/Surface.zig index 9208469dd..481847c20 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -140,6 +140,7 @@ const DerivedConfig = struct { clipboard_read: bool, clipboard_write: bool, clipboard_trim_trailing_spaces: bool, + confirm_close_surface: bool, mouse_interval: u64, pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig { @@ -153,6 +154,7 @@ const DerivedConfig = struct { .clipboard_read = config.@"clipboard-read", .clipboard_write = config.@"clipboard-write", .clipboard_trim_trailing_spaces = config.@"clipboard-trim-trailing-spaces", + .confirm_close_surface = config.@"confirm-close-surface", .mouse_interval = config.@"click-repeat-interval" * 1_000_000, // 500ms // Assignments happen sequentially so we have to do this last @@ -526,7 +528,22 @@ pub fn deinit(self: *Surface) void { /// Close this surface. This will trigger the runtime to start the /// close process, which should ultimately deinitialize this surface. pub fn close(self: *Surface) void { - self.rt_surface.close(!self.child_exited); + const process_alive = process_alive: { + // Inform close() if it should hold open the surface or not. If the child + // exited, we don't want to + var process_alive = !self.child_exited; + + // However, if we are configured to not hold open surfaces explicitly, + // just tell close to not hold them open by saying there are no alive + // processes + if (!self.config.confirm_close_surface) { + process_alive = false; + } + + break :process_alive process_alive; + }; + + self.rt_surface.close(process_alive); } /// Called from the app thread to handle mailbox messages to our specific