mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
apprt/gtk: integrate app needsConfirmQuit
This commit is contained in:
@ -228,6 +228,12 @@ pub const App = struct {
|
||||
}
|
||||
c.g_list_free(list);
|
||||
|
||||
// If the app says we don't need to confirm, then we can quit now.
|
||||
if (!self.core_app.needsConfirmQuit()) {
|
||||
self.quitNow();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we have windows, then we want to confirm that we want to exit.
|
||||
const alert = c.gtk_message_dialog_new(
|
||||
null,
|
||||
@ -259,20 +265,8 @@ pub const App = struct {
|
||||
c.gtk_widget_show(alert);
|
||||
}
|
||||
|
||||
fn gtkQuitConfirmation(
|
||||
alert: *c.GtkMessageDialog,
|
||||
response: c.gint,
|
||||
ud: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
_ = ud;
|
||||
|
||||
// Close the alert window
|
||||
c.gtk_window_destroy(@ptrCast(alert));
|
||||
|
||||
// If we didn't confirm then we're done
|
||||
if (response != c.GTK_RESPONSE_YES) return;
|
||||
|
||||
// Force close all open windows
|
||||
fn quitNow(self: *App) void {
|
||||
_ = self;
|
||||
const list = c.gtk_window_list_toplevels();
|
||||
defer c.g_list_free(list);
|
||||
c.g_list_foreach(list, struct {
|
||||
@ -285,6 +279,23 @@ pub const App = struct {
|
||||
}.callback, null);
|
||||
}
|
||||
|
||||
fn gtkQuitConfirmation(
|
||||
alert: *c.GtkMessageDialog,
|
||||
response: c.gint,
|
||||
ud: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const self: *App = @ptrCast(@alignCast(ud orelse return));
|
||||
|
||||
// Close the alert window
|
||||
c.gtk_window_destroy(@ptrCast(alert));
|
||||
|
||||
// If we didn't confirm then we're done
|
||||
if (response != c.GTK_RESPONSE_YES) return;
|
||||
|
||||
// Force close all open windows
|
||||
self.quitNow();
|
||||
}
|
||||
|
||||
/// This is called by the "activate" signal. This is sent on program
|
||||
/// startup and also when a secondary instance launches and requests
|
||||
/// a new window.
|
||||
|
Reference in New Issue
Block a user