apprt/gtk-ng: tab overview new tab

This commit is contained in:
Mitchell Hashimoto
2025-07-29 10:29:24 -07:00
parent ccc8dac0a5
commit 0da6b2049d
2 changed files with 17 additions and 3 deletions

View File

@ -301,6 +301,10 @@ pub const Window = extern struct {
/// at the position dictated by the `window-new-tab-position` config.
/// The new tab will be selected.
pub fn newTab(self: *Self, parent_: ?*CoreSurface) void {
_ = self.newTabPage(parent_);
}
fn newTabPage(self: *Self, parent_: ?*CoreSurface) *adw.TabPage {
const priv = self.private();
const tab_view = priv.tab_view;
@ -314,8 +318,7 @@ pub const Window = extern struct {
const config = if (priv.config) |v| v.get() else {
// If we don't have a config we just append it at the end.
// This should never happen.
_ = tab_view.append(tab.as(gtk.Widget));
return;
return tab_view.append(tab.as(gtk.Widget));
};
const position = switch (config.@"window-new-tab-position") {
.current => current: {
@ -339,6 +342,8 @@ pub const Window = extern struct {
"title",
.{ .sync_create = true },
);
return page;
}
/// Updates various appearance properties. This should always be safe
@ -616,10 +621,17 @@ pub const Window = extern struct {
//---------------------------------------------------------------
// Signal handlers
fn btnNewTab(_: *adw.SplitButton, self: *Window) callconv(.c) void {
fn btnNewTab(_: *adw.SplitButton, self: *Self) callconv(.c) void {
self.performBindingAction(.new_tab);
}
fn tabOverviewCreateTab(
_: *adw.TabOverview,
self: *Self,
) callconv(.c) *adw.TabPage {
return self.newTabPage(if (self.getActiveSurface()) |v| v.core() else null);
}
fn windowCloseRequest(
_: *gtk.Window,
self: *Self,
@ -1092,6 +1104,7 @@ pub const Window = extern struct {
// Template Callbacks
class.bindTemplateCallback("new_tab", &btnNewTab);
class.bindTemplateCallback("overview_create_tab", &tabOverviewCreateTab);
class.bindTemplateCallback("close_request", &windowCloseRequest);
class.bindTemplateCallback("close_page", &tabViewClosePage);
class.bindTemplateCallback("page_attached", &tabViewPageAttached);

View File

@ -18,6 +18,7 @@ template $GhosttyWindow: Adw.ApplicationWindow {
handle-menubar-accel: false;
content: Adw.TabOverview tab_overview {
create-tab => $overview_create_tab();
enable-new-tab: true;
view: tab_view;