mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-04-20 00:18:53 +03:00
core: quit flag is reset after tick
This commit is contained in:
@ -251,7 +251,7 @@ void ghostty_config_finalize(ghostty_config_t);
|
|||||||
|
|
||||||
ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s *, ghostty_config_t);
|
ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s *, ghostty_config_t);
|
||||||
void ghostty_app_free(ghostty_app_t);
|
void ghostty_app_free(ghostty_app_t);
|
||||||
int ghostty_app_tick(ghostty_app_t);
|
bool ghostty_app_tick(ghostty_app_t);
|
||||||
void *ghostty_app_userdata(ghostty_app_t);
|
void *ghostty_app_userdata(ghostty_app_t);
|
||||||
|
|
||||||
ghostty_surface_t ghostty_surface_new(ghostty_app_t, ghostty_surface_config_s*);
|
ghostty_surface_t ghostty_surface_new(ghostty_app_t, ghostty_surface_config_s*);
|
||||||
|
@ -106,7 +106,13 @@ extension Ghostty {
|
|||||||
|
|
||||||
func appTick() {
|
func appTick() {
|
||||||
guard let app = self.app else { return }
|
guard let app = self.app else { return }
|
||||||
ghostty_app_tick(app)
|
|
||||||
|
// Tick our app, which lets us know if we want to quit
|
||||||
|
let exit = ghostty_app_tick(app)
|
||||||
|
if (!exit) { return }
|
||||||
|
|
||||||
|
// We want to quit, start that process
|
||||||
|
NSApplication.shared.terminate(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request that the given surface is closed. This will trigger the full normal surface close event
|
/// Request that the given surface is closed. This will trigger the full normal surface close event
|
||||||
|
13
src/App.zig
13
src/App.zig
@ -81,8 +81,12 @@ pub fn tick(self: *App, rt_app: *apprt.App) !bool {
|
|||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drain our mailbox only if we're not quitting.
|
// Drain our mailbox
|
||||||
if (!self.quit) try self.drainMailbox(rt_app);
|
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.
|
// We quit if our quit flag is on or if we have closed all surfaces.
|
||||||
return self.quit or self.surfaces.items.len == 0;
|
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 {
|
fn setQuit(self: *App) !void {
|
||||||
if (self.quit) return;
|
if (self.quit) return;
|
||||||
self.quit = true;
|
self.quit = true;
|
||||||
|
|
||||||
// Mark that all our surfaces should close
|
|
||||||
for (self.surfaces.items) |surface| {
|
|
||||||
surface.setShouldClose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle a window message
|
/// Handle a window message
|
||||||
|
@ -390,9 +390,10 @@ pub const CAPI = struct {
|
|||||||
|
|
||||||
/// Tick the event loop. This should be called whenever the "wakeup"
|
/// Tick the event loop. This should be called whenever the "wakeup"
|
||||||
/// callback is invoked for the runtime.
|
/// callback is invoked for the runtime.
|
||||||
export fn ghostty_app_tick(v: *App) void {
|
export fn ghostty_app_tick(v: *App) bool {
|
||||||
_ = v.core_app.tick(v) catch |err| {
|
return v.core_app.tick(v) catch |err| err: {
|
||||||
log.err("error app tick err={}", .{err});
|
log.err("error app tick err={}", .{err});
|
||||||
|
break :err false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user