From 4657f30f7f0a05ae4c206171261c2fea8752e253 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 4 Aug 2024 14:33:37 -0500 Subject: [PATCH] Fix quit-after-last-window-closed=true, quit-after-last-window-closed-delay=null The case when `quit-after-last-window-closed=true` and `quit-after-last-window-closed-delay=null` was broken because control gets stuck inside `g_main_context_iteration` and never returns to our code. In that case add a 0ms timer that will return control flow from GLib back to our code so that we can quit. Fixes #2039 --- src/apprt/gtk/App.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 56419d604..8f3e7c997 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -529,8 +529,8 @@ pub fn startQuitTimer(self: *App) void { // This is a no-op unless we are configured to quit after last window is closed. if (!self.config.@"quit-after-last-window-closed") return; - // If a delay is configured, set a timeout function to quit after the delay. if (self.config.@"quit-after-last-window-closed-delay") |v| { + // If a delay is configured, set a timeout function to quit after the delay. const ms: u64 = std.math.divTrunc( u64, v.duration, @@ -538,6 +538,10 @@ pub fn startQuitTimer(self: *App) void { ) catch std.math.maxInt(c.guint); const t = std.math.cast(c.guint, ms) orelse std.math.maxInt(c.guint); self.quit_timer = .{ .active = c.g_timeout_add(t, gtkQuitTimerExpired, self) }; + } else { + // If no delay is configured, we still need a 0ms timer to break out of + // g_main_context_iteration so that control returns to our code. + self.quit_timer = .{ .active = c.g_timeout_add(0, gtkQuitTimerExpired, self) }; } }