mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
gtk: add separate close_window apprt action
For *some* reason we have a binding for close_window but it merely closes the surface and not the entire window. That is not only misleading but also just wrong. Now we make a separate apprt action for close_window that would make it show a close confirmation prompt identical to as if the user had clicked the (X) button on the window titlebar.
This commit is contained in:
@ -600,6 +600,7 @@ typedef enum {
|
|||||||
GHOSTTY_ACTION_COLOR_CHANGE,
|
GHOSTTY_ACTION_COLOR_CHANGE,
|
||||||
GHOSTTY_ACTION_RELOAD_CONFIG,
|
GHOSTTY_ACTION_RELOAD_CONFIG,
|
||||||
GHOSTTY_ACTION_CONFIG_CHANGE,
|
GHOSTTY_ACTION_CONFIG_CHANGE,
|
||||||
|
GHOSTTY_ACTION_CLOSE_WINDOW,
|
||||||
} ghostty_action_tag_e;
|
} ghostty_action_tag_e;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
|
@ -4292,7 +4292,11 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
|
|
||||||
.close_surface => self.close(),
|
.close_surface => self.close(),
|
||||||
|
|
||||||
.close_window => self.app.closeSurface(self),
|
.close_window => return try self.rt_app.performAction(
|
||||||
|
.{ .surface = self },
|
||||||
|
.close_window,
|
||||||
|
{},
|
||||||
|
),
|
||||||
|
|
||||||
.crash => |location| switch (location) {
|
.crash => |location| switch (location) {
|
||||||
.main => @panic("crash binding action, crashing intentionally"),
|
.main => @panic("crash binding action, crashing intentionally"),
|
||||||
|
@ -241,6 +241,9 @@ pub const Action = union(Key) {
|
|||||||
/// for changes.
|
/// for changes.
|
||||||
config_change: ConfigChange,
|
config_change: ConfigChange,
|
||||||
|
|
||||||
|
/// Closes the currently focused window.
|
||||||
|
close_window,
|
||||||
|
|
||||||
/// Sync with: ghostty_action_tag_e
|
/// Sync with: ghostty_action_tag_e
|
||||||
pub const Key = enum(c_int) {
|
pub const Key = enum(c_int) {
|
||||||
quit,
|
quit,
|
||||||
@ -283,6 +286,7 @@ pub const Action = union(Key) {
|
|||||||
color_change,
|
color_change,
|
||||||
reload_config,
|
reload_config,
|
||||||
config_change,
|
config_change,
|
||||||
|
close_window,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Sync with: ghostty_action_u
|
/// Sync with: ghostty_action_u
|
||||||
|
@ -219,6 +219,7 @@ pub const App = struct {
|
|||||||
.toggle_split_zoom,
|
.toggle_split_zoom,
|
||||||
.present_terminal,
|
.present_terminal,
|
||||||
.close_all_windows,
|
.close_all_windows,
|
||||||
|
.close_window,
|
||||||
.close_tab,
|
.close_tab,
|
||||||
.toggle_tab_overview,
|
.toggle_tab_overview,
|
||||||
.toggle_window_decorations,
|
.toggle_window_decorations,
|
||||||
|
@ -481,10 +481,11 @@ pub fn performAction(
|
|||||||
.app => null,
|
.app => null,
|
||||||
.surface => |v| v,
|
.surface => |v| v,
|
||||||
}),
|
}),
|
||||||
|
.close_window => return try self.closeWindow(target),
|
||||||
.toggle_maximize => self.toggleMaximize(target),
|
.toggle_maximize => self.toggleMaximize(target),
|
||||||
.toggle_fullscreen => self.toggleFullscreen(target, value),
|
.toggle_fullscreen => self.toggleFullscreen(target, value),
|
||||||
.new_tab => try self.newTab(target),
|
.new_tab => try self.newTab(target),
|
||||||
.close_tab => try self.closeTab(target),
|
.close_tab => return try self.closeTab(target),
|
||||||
.goto_tab => return self.gotoTab(target, value),
|
.goto_tab => return self.gotoTab(target, value),
|
||||||
.move_tab => self.moveTab(target, value),
|
.move_tab => self.moveTab(target, value),
|
||||||
.new_split => try self.newSplit(target, value),
|
.new_split => try self.newSplit(target, value),
|
||||||
@ -549,19 +550,20 @@ fn newTab(_: *App, target: apprt.Target) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn closeTab(_: *App, target: apprt.Target) !void {
|
fn closeTab(_: *App, target: apprt.Target) !bool {
|
||||||
switch (target) {
|
switch (target) {
|
||||||
.app => {},
|
.app => return false,
|
||||||
.surface => |v| {
|
.surface => |v| {
|
||||||
const tab = v.rt_surface.container.tab() orelse {
|
const tab = v.rt_surface.container.tab() orelse {
|
||||||
log.info(
|
log.info(
|
||||||
"close_tab invalid for container={s}",
|
"close_tab invalid for container={s}",
|
||||||
.{@tagName(v.rt_surface.container)},
|
.{@tagName(v.rt_surface.container)},
|
||||||
);
|
);
|
||||||
return;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
tab.closeWithConfirmation();
|
tab.closeWithConfirmation();
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1426,6 +1428,17 @@ fn setSecureInput(_: *App, target: apprt.Target, value: apprt.action.SecureInput
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn closeWindow(_: *App, target: apprt.action.Target) !bool {
|
||||||
|
switch (target) {
|
||||||
|
.app => return false,
|
||||||
|
.surface => |v| {
|
||||||
|
const window = v.rt_surface.container.window() orelse return false;
|
||||||
|
window.closeWithConfirmation();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn quit(self: *App) void {
|
fn quit(self: *App) void {
|
||||||
// If we're already not running, do nothing.
|
// If we're already not running, do nothing.
|
||||||
if (!self.running) return;
|
if (!self.running) return;
|
||||||
|
Reference in New Issue
Block a user