mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 01:06:08 +03:00
apprt/gtk: close keybind doesn't leak memory
This commit is contained in:
@ -46,6 +46,9 @@ pub const App = struct {
|
|||||||
cursor_default: *c.GdkCursor,
|
cursor_default: *c.GdkCursor,
|
||||||
cursor_ibeam: *c.GdkCursor,
|
cursor_ibeam: *c.GdkCursor,
|
||||||
|
|
||||||
|
/// This is set to false when the main loop should exit.
|
||||||
|
running: bool = true,
|
||||||
|
|
||||||
pub fn init(core_app: *CoreApp, opts: Options) !App {
|
pub fn init(core_app: *CoreApp, opts: Options) !App {
|
||||||
_ = opts;
|
_ = opts;
|
||||||
|
|
||||||
@ -161,12 +164,12 @@ pub const App = struct {
|
|||||||
|
|
||||||
/// Run the event loop. This doesn't return until the app exits.
|
/// Run the event loop. This doesn't return until the app exits.
|
||||||
pub fn run(self: *App) !void {
|
pub fn run(self: *App) !void {
|
||||||
while (true) {
|
while (self.running) {
|
||||||
_ = c.g_main_context_iteration(self.ctx, 1);
|
_ = c.g_main_context_iteration(self.ctx, 1);
|
||||||
|
|
||||||
// Tick the terminal app
|
// Tick the terminal app
|
||||||
const should_quit = try self.core_app.tick(self);
|
const should_quit = try self.core_app.tick(self);
|
||||||
if (should_quit) return;
|
if (should_quit) self.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +195,29 @@ pub const App = struct {
|
|||||||
try window.init(self);
|
try window.init(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn quit(self: *App) void {
|
||||||
|
const list = c.gtk_window_list_toplevels();
|
||||||
|
|
||||||
|
// If we have no toplevel windows, then we're done.
|
||||||
|
if (list == null) {
|
||||||
|
self.running = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have toplevel windows, so we want to go through each and
|
||||||
|
// request that they exit.
|
||||||
|
defer c.g_list_free(list);
|
||||||
|
c.g_list_foreach(list, struct {
|
||||||
|
fn callback(data: c.gpointer, ud: c.gpointer) callconv(.C) void {
|
||||||
|
_ = ud;
|
||||||
|
const ptr = data orelse return;
|
||||||
|
const widget = @ptrCast(*c.GtkWidget, @alignCast(@alignOf(c.GtkWidget), ptr));
|
||||||
|
const window = @ptrCast(*c.GtkWindow, widget);
|
||||||
|
c.gtk_window_destroy(window);
|
||||||
|
}
|
||||||
|
}.callback, null);
|
||||||
|
}
|
||||||
|
|
||||||
fn activate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
|
fn activate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
|
||||||
_ = app;
|
_ = app;
|
||||||
_ = ud;
|
_ = ud;
|
||||||
|
@ -346,6 +346,11 @@ pub const Config = struct {
|
|||||||
.{ .key = .w, .mods = .{ .ctrl = true, .shift = true } },
|
.{ .key = .w, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
.{ .close_surface = {} },
|
.{ .close_surface = {} },
|
||||||
);
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .q, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
|
.{ .quit = {} },
|
||||||
|
);
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .f4, .mods = .{ .alt = true } },
|
.{ .key = .f4, .mods = .{ .alt = true } },
|
||||||
|
Reference in New Issue
Block a user