mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
gtk: make previous_tab, next_tab, last_tab, and goto_tab performable
This commit is contained in:

committed by
Mitchell Hashimoto

parent
57e7565b7f
commit
69fd438370
@ -526,7 +526,7 @@ pub fn performAction(
|
||||
|
||||
.new_tab => try self.newTab(target),
|
||||
.close_tab => try self.closeTab(target),
|
||||
.goto_tab => self.gotoTab(target, value),
|
||||
.goto_tab => return self.gotoTab(target, value),
|
||||
.move_tab => self.moveTab(target, value),
|
||||
.new_split => try self.newSplit(target, value),
|
||||
.resize_split => self.resizeSplit(target, value),
|
||||
@ -600,24 +600,26 @@ fn closeTab(_: *App, target: apprt.Target) !void {
|
||||
}
|
||||
}
|
||||
|
||||
fn gotoTab(_: *App, target: apprt.Target, tab: apprt.action.GotoTab) void {
|
||||
fn gotoTab(_: *App, target: apprt.Target, tab: apprt.action.GotoTab) bool {
|
||||
switch (target) {
|
||||
.app => {},
|
||||
.app => {
|
||||
return false;
|
||||
},
|
||||
.surface => |v| {
|
||||
const window = v.rt_surface.container.window() orelse {
|
||||
log.info(
|
||||
"gotoTab invalid for container={s}",
|
||||
.{@tagName(v.rt_surface.container)},
|
||||
);
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
|
||||
switch (tab) {
|
||||
return switch (tab) {
|
||||
.previous => window.gotoPreviousTab(v.rt_surface),
|
||||
.next => window.gotoNextTab(v.rt_surface),
|
||||
.last => window.gotoLastTab(),
|
||||
else => window.gotoTab(@intCast(@intFromEnum(tab))),
|
||||
}
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -2124,7 +2124,7 @@ pub fn present(self: *Surface) void {
|
||||
if (self.container.window()) |window| {
|
||||
if (self.container.tab()) |tab| {
|
||||
if (window.notebook.getTabPosition(tab)) |position|
|
||||
window.notebook.gotoNthTab(position);
|
||||
_ = window.notebook.gotoNthTab(position);
|
||||
}
|
||||
c.gtk_window_present(window.window);
|
||||
}
|
||||
|
@ -506,23 +506,25 @@ pub fn closeTab(self: *Window, tab: *Tab) void {
|
||||
}
|
||||
|
||||
/// Go to the previous tab for a surface.
|
||||
pub fn gotoPreviousTab(self: *Window, surface: *Surface) void {
|
||||
pub fn gotoPreviousTab(self: *Window, surface: *Surface) bool {
|
||||
const tab = surface.container.tab() orelse {
|
||||
log.info("surface is not attached to a tab bar, cannot navigate", .{});
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
self.notebook.gotoPreviousTab(tab);
|
||||
if (!self.notebook.gotoPreviousTab(tab)) return false;
|
||||
self.focusCurrentTab();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Go to the next tab for a surface.
|
||||
pub fn gotoNextTab(self: *Window, surface: *Surface) void {
|
||||
pub fn gotoNextTab(self: *Window, surface: *Surface) bool {
|
||||
const tab = surface.container.tab() orelse {
|
||||
log.info("surface is not attached to a tab bar, cannot navigate", .{});
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
self.notebook.gotoNextTab(tab);
|
||||
if (!self.notebook.gotoNextTab(tab)) return false;
|
||||
self.focusCurrentTab();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Move the current tab for a surface.
|
||||
@ -535,19 +537,20 @@ pub fn moveTab(self: *Window, surface: *Surface, position: c_int) void {
|
||||
}
|
||||
|
||||
/// Go to the last tab for a surface.
|
||||
pub fn gotoLastTab(self: *Window) void {
|
||||
pub fn gotoLastTab(self: *Window) bool {
|
||||
const max = self.notebook.nPages();
|
||||
self.gotoTab(@intCast(max));
|
||||
return self.gotoTab(@intCast(max));
|
||||
}
|
||||
|
||||
/// Go to the specific tab index.
|
||||
pub fn gotoTab(self: *Window, n: usize) void {
|
||||
if (n == 0) return;
|
||||
pub fn gotoTab(self: *Window, n: usize) bool {
|
||||
if (n == 0) return false;
|
||||
const max = self.notebook.nPages();
|
||||
if (max == 0) return;
|
||||
const page_idx = std.math.cast(c_int, n - 1) orelse return;
|
||||
self.notebook.gotoNthTab(@min(page_idx, max - 1));
|
||||
if (max == 0) return false;
|
||||
const page_idx = std.math.cast(c_int, n - 1) orelse return false;
|
||||
if (!self.notebook.gotoNthTab(@min(page_idx, max - 1))) return false;
|
||||
self.focusCurrentTab();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Toggle tab overview (if present)
|
||||
|
@ -59,11 +59,14 @@ pub const Notebook = union(enum) {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn gotoNthTab(self: *Notebook, position: c_int) void {
|
||||
pub fn gotoNthTab(self: *Notebook, position: c_int) bool {
|
||||
const current_page_ = self.currentPage();
|
||||
if (current_page_) |current_page| if (current_page == position) return false;
|
||||
switch (self.*) {
|
||||
.adw => |*adw| adw.gotoNthTab(position),
|
||||
.gtk => |*gtk| gtk.gotoNthTab(position),
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn getTabPosition(self: *Notebook, tab: *Tab) ?c_int {
|
||||
@ -73,8 +76,8 @@ pub const Notebook = union(enum) {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn gotoPreviousTab(self: *Notebook, tab: *Tab) void {
|
||||
const page_idx = self.getTabPosition(tab) orelse return;
|
||||
pub fn gotoPreviousTab(self: *Notebook, tab: *Tab) bool {
|
||||
const page_idx = self.getTabPosition(tab) orelse return false;
|
||||
|
||||
// The next index is the previous or we wrap around.
|
||||
const next_idx = if (page_idx > 0) page_idx - 1 else next_idx: {
|
||||
@ -83,19 +86,21 @@ pub const Notebook = union(enum) {
|
||||
};
|
||||
|
||||
// Do nothing if we have one tab
|
||||
if (next_idx == page_idx) return;
|
||||
if (next_idx == page_idx) return false;
|
||||
|
||||
self.gotoNthTab(next_idx);
|
||||
return self.gotoNthTab(next_idx);
|
||||
}
|
||||
|
||||
pub fn gotoNextTab(self: *Notebook, tab: *Tab) void {
|
||||
const page_idx = self.getTabPosition(tab) orelse return;
|
||||
pub fn gotoNextTab(self: *Notebook, tab: *Tab) bool {
|
||||
const page_idx = self.getTabPosition(tab) orelse return false;
|
||||
|
||||
const max = self.nPages() -| 1;
|
||||
const next_idx = if (page_idx < max) page_idx + 1 else 0;
|
||||
if (next_idx == page_idx) return;
|
||||
|
||||
self.gotoNthTab(next_idx);
|
||||
// Do nothing if we have one tab
|
||||
if (next_idx == page_idx) return false;
|
||||
|
||||
return self.gotoNthTab(next_idx);
|
||||
}
|
||||
|
||||
pub fn moveTab(self: *Notebook, tab: *Tab, position: c_int) void {
|
||||
|
Reference in New Issue
Block a user