apprt/gtk-ng: "cancel" should be default close response for dialog (#8427)

Fixes #8424

This is the response that will be sent when "escape" is pressed.

This also fixes a null ptr deref that was possible when this fix wasn't
in.
pull/8442/head
Mitchell Hashimoto 2025-08-27 09:48:19 -07:00 committed by GitHub
commit 7106d71a42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 3 deletions

View File

@ -499,7 +499,15 @@ pub const Application = extern struct {
const parent: ?*gtk.Widget = parent: { const parent: ?*gtk.Widget = parent: {
const list = gtk.Window.listToplevels(); const list = gtk.Window.listToplevels();
defer list.free(); defer list.free();
const focused = list.findCustom(null, findActiveWindow); const focused = @as(?*glib.List, list.findCustom(
null,
findActiveWindow,
)) orelse {
// If we have an active surface then we should have
// a window available but in the rare case we don't we
// should exit so we don't crash.
break :parent null;
};
break :parent @ptrCast(@alignCast(focused.f_data)); break :parent @ptrCast(@alignCast(focused.f_data));
}; };

View File

@ -10,7 +10,7 @@ const Common = @import("../class.zig").Common;
const Config = @import("config.zig").Config; const Config = @import("config.zig").Config;
const Dialog = @import("dialog.zig").Dialog; const Dialog = @import("dialog.zig").Dialog;
const log = std.log.scoped(.gtk_ghostty_config_errors_dialog); const log = std.log.scoped(.gtk_ghostty_close_confirmation_dialog);
pub const CloseConfirmationDialog = extern struct { pub const CloseConfirmationDialog = extern struct {
const Self = @This(); const Self = @This();

View File

@ -18,7 +18,6 @@ const gresource = @import("../build/gresource.zig");
const Common = @import("../class.zig").Common; const Common = @import("../class.zig").Common;
const Config = @import("config.zig").Config; const Config = @import("config.zig").Config;
const Application = @import("application.zig").Application; const Application = @import("application.zig").Application;
const CloseConfirmationDialog = @import("close_confirmation_dialog.zig").CloseConfirmationDialog;
const SplitTree = @import("split_tree.zig").SplitTree; const SplitTree = @import("split_tree.zig").SplitTree;
const Surface = @import("surface.zig").Surface; const Surface = @import("surface.zig").Surface;

View File

@ -7,4 +7,6 @@ template $GhosttyCloseConfirmationDialog: $GhosttyDialog {
cancel: _("Cancel"), cancel: _("Cancel"),
close: _("Close") destructive, close: _("Close") destructive,
] ]
close-response: "cancel";
} }