apprt/gtk-ng: create-window action

This commit is contained in:
Mitchell Hashimoto
2025-07-29 15:05:36 -07:00
parent 0cc8b6d10f
commit fde50e0f1c
3 changed files with 27 additions and 5 deletions

View File

@ -1355,7 +1355,7 @@ const Action = struct {
self: *Application,
parent: ?*CoreSurface,
) !void {
const win = Window.new(self, parent);
const win = Window.new(self);
// Setup a binding so that whenever our config changes so does the
// window. There's never a time when the window config should be out
@ -1368,6 +1368,9 @@ const Action = struct {
.{},
);
// Create a new tab
win.newTab(parent);
// Show the window
gtk.Window.present(win.as(gtk.Window));
}

View File

@ -224,12 +224,10 @@ pub const Window = extern struct {
pub var offset: c_int = 0;
};
pub fn new(app: *Application, parent_: ?*CoreSurface) *Self {
const self = gobject.ext.newInstance(Self, .{
pub fn new(app: *Application) *Self {
return gobject.ext.newInstance(Self, .{
.application = app,
});
self.newTab(parent_);
return self;
}
fn init(self: *Self, _: *Class) callconv(.C) void {
@ -1012,6 +1010,25 @@ pub const Window = extern struct {
);
}
fn tabViewCreateWindow(
_: *adw.TabView,
_: *Self,
) callconv(.c) *adw.TabView {
// Create a new window without creating a new tab.
const win = gobject.ext.newInstance(
Self,
.{
.application = Application.default(),
},
);
// We have to show it otherwise it'll just be hidden.
gtk.Window.present(win.as(gtk.Window));
// Get our tab view
return win.private().tab_view;
}
fn tabCloseRequest(
tab: *Tab,
self: *Self,
@ -1262,6 +1279,7 @@ pub const Window = extern struct {
class.bindTemplateCallback("close_page", &tabViewClosePage);
class.bindTemplateCallback("page_attached", &tabViewPageAttached);
class.bindTemplateCallback("page_detached", &tabViewPageDetached);
class.bindTemplateCallback("tab_create_window", &tabViewCreateWindow);
class.bindTemplateCallback("notify_n_pages", &tabViewNPages);
class.bindTemplateCallback("notify_selected_page", &tabViewSelectedPage);
class.bindTemplateCallback("notify_config", &propConfig);

View File

@ -86,6 +86,7 @@ template $GhosttyWindow: Adw.ApplicationWindow {
close-page => $close_page();
page-attached => $page_attached();
page-detached => $page_detached();
create-window => $tab_create_window();
shortcuts: none;
}
}