core: quit flag is reset after tick

This commit is contained in:
Mitchell Hashimoto
2023-03-27 10:10:06 -07:00
parent 41943b9a00
commit f36a35ecc9
4 changed files with 17 additions and 11 deletions

View File

@@ -81,8 +81,12 @@ pub fn tick(self: *App, rt_app: *apprt.App) !bool {
i += 1;
}
// Drain our mailbox only if we're not quitting.
if (!self.quit) try self.drainMailbox(rt_app);
// Drain our mailbox
try self.drainMailbox(rt_app);
// No matter what, we reset the quit flag after a tick. If the apprt
// doesn't want to quit, then we can't force it to.
defer self.quit = false;
// We quit if our quit flag is on or if we have closed all surfaces.
return self.quit or self.surfaces.items.len == 0;
@@ -175,11 +179,6 @@ fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
fn setQuit(self: *App) !void {
if (self.quit) return;
self.quit = true;
// Mark that all our surfaces should close
for (self.surfaces.items) |surface| {
surface.setShouldClose();
}
}
/// Handle a window message

View File

@@ -390,9 +390,10 @@ pub const CAPI = struct {
/// Tick the event loop. This should be called whenever the "wakeup"
/// callback is invoked for the runtime.
export fn ghostty_app_tick(v: *App) void {
_ = v.core_app.tick(v) catch |err| {
export fn ghostty_app_tick(v: *App) bool {
return v.core_app.tick(v) catch |err| err: {
log.err("error app tick err={}", .{err});
break :err false;
};
}