close_tab keybind (gtk apprt only) (#4033)

Title. Adds a close_tab keybind that essentially behaves the exact same
as clicking the tab close button on the tab bar.
This commit is contained in:
Sabarigirish Manikandan
2025-01-09 00:37:00 +05:30
committed by GitHub
parent 34a0b206f8
commit 306c7ea2be
7 changed files with 45 additions and 0 deletions

View File

@ -562,6 +562,7 @@ typedef enum {
GHOSTTY_ACTION_QUIT,
GHOSTTY_ACTION_NEW_WINDOW,
GHOSTTY_ACTION_NEW_TAB,
GHOSTTY_ACTION_CLOSE_TAB,
GHOSTTY_ACTION_NEW_SPLIT,
GHOSTTY_ACTION_CLOSE_ALL_WINDOWS,
GHOSTTY_ACTION_TOGGLE_FULLSCREEN,

View File

@ -4061,6 +4061,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
{},
),
.close_tab => try self.rt_app.performAction(
.{ .surface = self },
.close_tab,
{},
),
inline .previous_tab,
.next_tab,
.last_tab,

View File

@ -82,6 +82,9 @@ pub const Action = union(Key) {
/// the tab should be opened in a new window.
new_tab,
/// Closes the tab belonging to the currently focused split.
close_tab,
/// Create a new split. The value determines the location of the split
/// relative to the target.
new_split: SplitDirection,
@ -225,6 +228,7 @@ pub const Action = union(Key) {
quit,
new_window,
new_tab,
close_tab,
new_split,
close_all_windows,
toggle_fullscreen,

View File

@ -218,6 +218,7 @@ pub const App = struct {
.toggle_split_zoom,
.present_terminal,
.close_all_windows,
.close_tab,
.toggle_tab_overview,
.toggle_window_decorations,
.toggle_quick_terminal,

View File

@ -477,6 +477,7 @@ pub fn performAction(
.toggle_fullscreen => self.toggleFullscreen(target, value),
.new_tab => try self.newTab(target),
.close_tab => try self.closeTab(target),
.goto_tab => self.gotoTab(target, value),
.move_tab => self.moveTab(target, value),
.new_split => try self.newSplit(target, value),
@ -532,6 +533,23 @@ fn newTab(_: *App, target: apprt.Target) !void {
}
}
fn closeTab(_: *App, target: apprt.Target) !void {
switch (target) {
.app => {},
.surface => |v| {
const tab = v.rt_surface.container.tab() orelse {
log.info(
"close_tab invalid for container={s}",
.{@tagName(v.rt_surface.container)},
);
return;
};
tab.window.closeTab(tab);
},
}
}
fn gotoTab(_: *App, target: apprt.Target, tab: apprt.action.GotoTab) void {
switch (target) {
.app => {},
@ -1743,6 +1761,7 @@ fn initMenu(self: *App) void {
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "New Window", "win.new_window");
c.g_menu_append(section, "New Tab", "win.new_tab");
c.g_menu_append(section, "Close Tab", "win.close_tab");
c.g_menu_append(section, "Split Right", "win.split_right");
c.g_menu_append(section, "Split Down", "win.split_down");
c.g_menu_append(section, "Close Window", "win.close");

View File

@ -2373,6 +2373,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
.{ .key = .{ .translated = .t }, .mods = .{ .ctrl = true, .shift = true } },
.{ .new_tab = {} },
);
try result.keybind.set.put(
alloc,
.{ .key = .{ .translated = .w }, .mods = .{ .ctrl = true, .shift = true } },
.{ .close_tab = {} },
);
try result.keybind.set.put(
alloc,
.{ .key = .{ .translated = .left }, .mods = .{ .ctrl = true, .shift = true } },
@ -2653,6 +2658,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
.{ .key = .{ .translated = .t }, .mods = .{ .super = true } },
.{ .new_tab = {} },
);
try result.keybind.set.put(
alloc,
.{ .key = .{ .translated = .w }, .mods = .{ .super = true } },
.{ .close_tab = {} },
);
try result.keybind.set.put(
alloc,
.{ .key = .{ .translated = .left_bracket }, .mods = .{ .super = true, .shift = true } },

View File

@ -383,6 +383,9 @@ pub const Action = union(enum) {
/// This only works for macOS currently.
close_all_windows: void,
/// Closes the tab belonging to the currently focused split.
close_tab: void,
/// Toggle fullscreen mode of window.
toggle_fullscreen: void,
@ -750,6 +753,7 @@ pub const Action = union(enum) {
.resize_split,
.equalize_splits,
.inspector,
.close_tab,
=> .surface,
};
}