From 2ab5d3cd816645e967622e3e061ef57cb206e6e6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 18 Jul 2025 11:19:21 -0700 Subject: [PATCH] apprt/gtk-ng: implement the quit_timer action to just quit --- src/apprt/action.zig | 13 ++++++++++--- src/apprt/gtk-ng/class/application.zig | 18 +++++++++++++++++- src/apprt/gtk-ng/class/surface.zig | 2 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/apprt/action.zig b/src/apprt/action.zig index 1afd59869..425e39974 100644 --- a/src/apprt/action.zig +++ b/src/apprt/action.zig @@ -203,9 +203,16 @@ pub const Action = union(Key) { open_config, /// Called when there are no more surfaces and the app should quit - /// after the configured delay. This can be cancelled by sending - /// another quit_timer action with "stop". Multiple "starts" shouldn't - /// happen and can be ignored or cause a restart it isn't that important. + /// after the configured delay. + /// + /// Despite the name, this is the notification that libghostty sends + /// when there are no more surfaces regardless of if the configuration + /// wants to quit after close, has any delay set, etc. It's up to the + /// apprt to implement the proper logic based on the config. + /// + /// This can be cancelled by sending another quit_timer action with "stop". + /// Multiple "starts" shouldn't happen and can be ignored or cause a + /// restart it isn't that important. quit_timer: QuitTimer, /// Set the window floating state. A floating window is one that is diff --git a/src/apprt/gtk-ng/class/application.zig b/src/apprt/gtk-ng/class/application.zig index 1e7a5de25..c115d59cc 100644 --- a/src/apprt/gtk-ng/class/application.zig +++ b/src/apprt/gtk-ng/class/application.zig @@ -378,6 +378,8 @@ pub const Application = extern struct { }, ), + .quit_timer => try Action.quitTimer(self, value), + // Unimplemented .quit, .close_window, @@ -407,7 +409,6 @@ pub const Application = extern struct { .toggle_tab_overview, .toggle_split_zoom, .toggle_window_decorations, - .quit_timer, .prompt_title, .toggle_quick_terminal, .secure_input, @@ -867,6 +868,21 @@ const Action = struct { const win = Window.new(self); gtk.Window.present(win.as(gtk.Window)); } + + pub fn quitTimer( + self: *Application, + mode: apprt.action.QuitTimer, + ) !void { + // TODO: An actual quit timer implementation. For now, we immediately + // quit on no windows regardless of the config. + switch (mode) { + .start => { + self.private().running = false; + }, + + .stop => {}, + } + } }; /// This sets various GTK-related environment variables as necessary diff --git a/src/apprt/gtk-ng/class/surface.zig b/src/apprt/gtk-ng/class/surface.zig index 26943560b..d515bfd65 100644 --- a/src/apprt/gtk-ng/class/surface.zig +++ b/src/apprt/gtk-ng/class/surface.zig @@ -220,6 +220,8 @@ pub const Surface = extern struct { // Deinit the surface v.deinit(); + const alloc = Application.default().allocator(); + alloc.destroy(v); } gobject.Object.virtual_methods.finalize.call(