mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 01:06:08 +03:00
"goto_tab" key binding to jump to a specific tab, defaults to Super+N
The apprt surface must implement `gotoTab` to make this work. This is only implemented in GTK for now.
This commit is contained in:
@ -927,6 +927,12 @@ pub fn keyCallback(
|
|||||||
} else log.warn("runtime doesn't implement gotoNextTab", .{});
|
} else log.warn("runtime doesn't implement gotoNextTab", .{});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.goto_tab => |n| {
|
||||||
|
if (@hasDecl(apprt.Surface, "gotoTab")) {
|
||||||
|
self.rt_surface.gotoTab(n);
|
||||||
|
} else log.warn("runtime doesn't implement gotoTab", .{});
|
||||||
|
},
|
||||||
|
|
||||||
.close_window => {
|
.close_window => {
|
||||||
_ = self.app_mailbox.push(.{ .close = self }, .{ .instant = {} });
|
_ = self.app_mailbox.push(.{ .close = self }, .{ .instant = {} });
|
||||||
},
|
},
|
||||||
|
@ -329,6 +329,17 @@ const Window = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Go to the specific tab index.
|
||||||
|
fn gotoTab(self: *Window, n: usize) void {
|
||||||
|
if (n == 0) return;
|
||||||
|
const max = c.gtk_notebook_get_n_pages(self.notebook);
|
||||||
|
const page_idx = std.math.cast(c_int, n - 1) orelse return;
|
||||||
|
if (page_idx < max) {
|
||||||
|
c.gtk_notebook_set_current_page(self.notebook, page_idx);
|
||||||
|
self.focusCurrentTab();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Grabs focus on the currently selected tab.
|
/// Grabs focus on the currently selected tab.
|
||||||
fn focusCurrentTab(self: *Window) void {
|
fn focusCurrentTab(self: *Window) void {
|
||||||
const page_idx = c.gtk_notebook_get_current_page(self.notebook);
|
const page_idx = c.gtk_notebook_get_current_page(self.notebook);
|
||||||
@ -591,6 +602,10 @@ pub const Surface = struct {
|
|||||||
self.window.gotoNextTab(self);
|
self.window.gotoNextTab(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn gotoTab(self: *Surface, n: usize) void {
|
||||||
|
self.window.gotoTab(n);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setShouldClose(self: *Surface) void {
|
pub fn setShouldClose(self: *Surface) void {
|
||||||
_ = self;
|
_ = self;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +288,19 @@ pub const Config = struct {
|
|||||||
.{ .key = .right_bracket, .mods = .{ .super = true, .shift = true } },
|
.{ .key = .right_bracket, .mods = .{ .super = true, .shift = true } },
|
||||||
.{ .next_tab = {} },
|
.{ .next_tab = {} },
|
||||||
);
|
);
|
||||||
|
{
|
||||||
|
// Cmd+N for goto tab N
|
||||||
|
const start = @enumToInt(inputpkg.Key.one);
|
||||||
|
const end = @enumToInt(inputpkg.Key.nine);
|
||||||
|
var i: usize = start;
|
||||||
|
while (i <= end) : (i += 1) {
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = @intToEnum(inputpkg.Key, i), .mods = .{ .super = true } },
|
||||||
|
.{ .goto_tab = (i - start) + 1 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (comptime builtin.target.isDarwin()) {
|
if (comptime builtin.target.isDarwin()) {
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
|
@ -161,6 +161,9 @@ pub const Action = union(enum) {
|
|||||||
/// Go to the next tab
|
/// Go to the next tab
|
||||||
next_tab: void,
|
next_tab: void,
|
||||||
|
|
||||||
|
/// Go to the tab with the specific number, 1-indexed.
|
||||||
|
goto_tab: usize,
|
||||||
|
|
||||||
/// Close the current window or tab
|
/// Close the current window or tab
|
||||||
close_window: void,
|
close_window: void,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user