Skip to content

Commit

Permalink
gtk: last_active_tab
Browse files Browse the repository at this point in the history
  • Loading branch information
SkamDart committed Jul 3, 2024
1 parent 655743c commit 27f5a6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/apprt/gtk/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,18 @@ pub fn gotoTab(self: *Surface, n: usize) void {
window.gotoTab(n);
}

pub fn gotoLastActiveTab(self: *Surface) void {
const window = self.container.window() orelse {
log.info(
"gotoLastActiveTab invalid for container={s}",
.{@tagName(self.container)},
);
return;
};

window.gotoLastActiveTab();
}

pub fn setShouldClose(self: *Surface) void {
_ = self;
}
Expand Down
22 changes: 22 additions & 0 deletions src/apprt/gtk/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ window: *c.GtkWindow,
/// The notebook (tab grouping) for this window.
notebook: *c.GtkNotebook,

last_active_tab_index: c_int = 0,

pub fn create(alloc: Allocator, app: *App) !*Window {
// Allocate a fixed pointer for our window. We try to minimize
// allocations but windows and other GUI requirements are so minimal
Expand Down Expand Up @@ -248,6 +250,9 @@ pub fn gotoPreviousTab(self: *Window, surface: *Surface) void {
// Do nothing if we have one tab
if (next_idx == page_idx) return;

// Cache the last active tab index for our last-active-tab hotkey.
self.last_active_tab_index = page_idx;

c.gtk_notebook_set_current_page(self.notebook, next_idx);
self.focusCurrentTab();
}
Expand All @@ -265,6 +270,9 @@ pub fn gotoNextTab(self: *Window, surface: *Surface) void {
const next_idx = if (page_idx < max) page_idx + 1 else 0;
if (next_idx == page_idx) return;

// Cache the last active tab index for our last-active-tab hotkey.
self.last_active_tab_index = page_idx;

c.gtk_notebook_set_current_page(self.notebook, next_idx);
self.focusCurrentTab();
}
Expand All @@ -278,6 +286,20 @@ pub fn gotoTab(self: *Window, n: usize) void {
c.gtk_notebook_set_current_page(self.notebook, page_idx);
self.focusCurrentTab();
}

// Cache the last active tab index for our last-active-tab hotkey.
self.last_active_tab_index = page_idx;
}

// Goto the more recently selected tab.
pub fn gotoLastActiveTab(self: *Window) void {
if (self.last_active_tab_index >= 0) {
const page_idx = c.gtk_notebook_get_current_page(self.notebook);
c.gtk_notebook_set_current_page(self.notebook, self.last_active_tab_index);
self.focusCurrentTab();
log.debug("going to last active tab", .{});
self.last_active_tab_index = page_idx;
}
}

/// Toggle fullscreen for this window.
Expand Down

0 comments on commit 27f5a6d

Please sign in to comment.