Merge pull request #2241 from Pangoraw/adw_tab_page

apprt/gtk: remove adw_tab_page from tab
This commit is contained in:
Mitchell Hashimoto
2024-09-13 06:48:52 -07:00
committed by GitHub
3 changed files with 6 additions and 20 deletions

View File

@ -37,11 +37,6 @@ elem: Surface.Container.Elem,
// can easily re-focus that terminal.
focus_child: *Surface,
/// If the notebook implementation is AdwTabView, then this is the tab's
/// AdwTabPage. If we have libadwaita disabled then this will be undefined
/// memory and is unsafe to use.
adw_tab_page: *c.GObject,
pub fn create(alloc: Allocator, window: *Window, parent_: ?*CoreSurface) !*Tab {
var tab = try alloc.create(Tab);
errdefer alloc.destroy(tab);
@ -58,7 +53,6 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void {
.box = undefined,
.elem = undefined,
.focus_child = undefined,
.adw_tab_page = undefined,
};
// Create a Box in which we'll later keep either Surface or Split.
@ -82,9 +76,7 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void {
// Set the userdata of the box to point to this tab.
c.g_object_set_data(@ptrCast(box_widget), GHOSTTY_TAB, self);
if (try window.notebook.addTab(self, "Ghostty")) |page| {
self.adw_tab_page = page;
}
try window.notebook.addTab(self, "Ghostty");
// Attach all events
_ = c.g_signal_connect_data(box_widget, "destroy", c.G_CALLBACK(&gtkDestroy), self, null, c.G_CONNECT_DEFAULT);

View File

@ -439,14 +439,14 @@ fn gtkTabNewClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
/// Create a new tab from the AdwTabOverview. We can't copy gtkTabNewClick
/// because we need to return an AdwTabPage from this function.
fn gtkNewTabFromOverview(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) ?*c.GObject {
const self: *Window = @ptrCast(@alignCast(ud orelse return null));
fn gtkNewTabFromOverview(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) ?*c.AdwTabPage {
const self: *Window = userdataSelf(ud.?);
assert(self.isAdwWindow());
const alloc = self.app.core_app.alloc;
const surface = self.actionSurface();
const tab = Tab.create(alloc, self, surface) catch return null;
return tab.adw_tab_page;
return c.adw_tab_view_get_page(self.notebook.adw_tab_view, @ptrCast(@alignCast(tab.box)));
}
fn gtkRefocusTerm(v: *c.GtkWindow, ud: ?*anyopaque) callconv(.C) bool {

View File

@ -205,10 +205,8 @@ pub const Notebook = union(enum) {
};
}
/// Adds a new tab with the given title to the notebook. If the notebook
/// is an adwaita tab view, this will return an AdwTabPage. If the notebook
/// is a GTK notebook, this will return null.
pub fn addTab(self: Notebook, tab: *Tab, title: [:0]const u8) !?*c.GObject {
/// Adds a new tab with the given title to the notebook.
pub fn addTab(self: Notebook, tab: *Tab, title: [:0]const u8) !void {
const box_widget: *c.GtkWidget = @ptrCast(tab.box);
switch (self) {
.adw_tab_view => |tab_view| {
@ -219,8 +217,6 @@ pub const Notebook = union(enum) {
// Switch to the new tab
c.adw_tab_view_set_selected_page(tab_view, page);
return @ptrCast(@alignCast(page));
},
.gtk_notebook => |notebook| {
// Build the tab label
@ -276,8 +272,6 @@ pub const Notebook = union(enum) {
// Switch to the new tab
c.gtk_notebook_set_current_page(notebook, page_idx);
return null;
},
}
}