mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
support app quitting to close all windows
This commit is contained in:
11
src/App.zig
11
src/App.zig
@ -74,7 +74,8 @@ pub fn wakeup(self: App) void {
|
||||
/// Run the main event loop for the application. This blocks until the
|
||||
/// application quits or every window is closed.
|
||||
pub fn run(self: *App) !void {
|
||||
while (self.windows.items.len > 0) {
|
||||
var quit: bool = false;
|
||||
while (!quit and self.windows.items.len > 0) {
|
||||
// Block for any glfw events.
|
||||
try glfw.waitEvents();
|
||||
|
||||
@ -100,12 +101,12 @@ pub fn run(self: *App) !void {
|
||||
}
|
||||
|
||||
// Drain our mailbox
|
||||
try self.drainMailbox();
|
||||
try self.drainMailbox(&quit);
|
||||
}
|
||||
}
|
||||
|
||||
/// Drain the mailbox.
|
||||
fn drainMailbox(self: *App) !void {
|
||||
fn drainMailbox(self: *App, quit: *bool) !void {
|
||||
var drain = self.mailbox.drain();
|
||||
defer drain.deinit();
|
||||
|
||||
@ -113,6 +114,7 @@ fn drainMailbox(self: *App) !void {
|
||||
log.debug("mailbox message={}", .{message});
|
||||
switch (message) {
|
||||
.new_window => try self.newWindow(),
|
||||
.quit => quit.* = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -134,4 +136,7 @@ fn newWindow(self: *App) !void {
|
||||
pub const Message = union(enum) {
|
||||
/// Create a new terminal window.
|
||||
new_window: void,
|
||||
|
||||
/// Quit
|
||||
quit: void,
|
||||
};
|
||||
|
@ -342,7 +342,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
|
||||
.grid_size = grid_size,
|
||||
.config = config,
|
||||
|
||||
.imgui_ctx = if (!DevMode.enabled) void else try imgui.Context.create(),
|
||||
.imgui_ctx = if (!DevMode.enabled) {} else try imgui.Context.create(),
|
||||
};
|
||||
errdefer if (DevMode.enabled) self.imgui_ctx.destroy();
|
||||
|
||||
@ -766,6 +766,13 @@ fn keyCallback(
|
||||
},
|
||||
|
||||
.close_window => win.window.setShouldClose(true),
|
||||
|
||||
.quit => {
|
||||
_ = win.app.mailbox.push(.{
|
||||
.quit = {},
|
||||
}, .{ .instant = {} });
|
||||
win.app.wakeup();
|
||||
},
|
||||
}
|
||||
|
||||
// Bindings always result in us ignoring the char if printable
|
||||
|
@ -168,6 +168,14 @@ pub const Config = struct {
|
||||
.{ .close_window = {} },
|
||||
);
|
||||
|
||||
if (builtin.os.tag == .macos) {
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .q, .mods = .{ .super = true } },
|
||||
.{ .close_window = {} },
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,9 @@ pub const Action = union(enum) {
|
||||
|
||||
/// Close the current window
|
||||
close_window: void,
|
||||
|
||||
/// Quit ghostty
|
||||
quit: void,
|
||||
};
|
||||
|
||||
/// Trigger is the associated key state that can trigger an action.
|
||||
|
Reference in New Issue
Block a user