Skip to content

Commit

Permalink
gtk: refactor gtk & adw notebook implementations
Browse files Browse the repository at this point in the history
Put GTK and libadwaita notebook implementations into separate structs/
files for clarity.
  • Loading branch information
jcollie committed Nov 2, 2024
1 parent 179358c commit 6c97ee8
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 468 deletions.
2 changes: 1 addition & 1 deletion src/apprt/gtk/Tab.zig
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +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);
try window.notebook.addTab(self, "Ghostty");
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);
Expand Down
14 changes: 7 additions & 7 deletions src/apprt/gtk/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ pub fn init(self: *Window, alloc: Allocator, app: *App) std.mem.Allocator.Error!
// If we have a tab overview then we can set it on our notebook.
if (self.tab_overview) |tab_overview| {
if (comptime !adwaita.versionAtLeast(1, 4, 0)) unreachable;
assert(self.notebook.* == .adw_tab_view);
c.adw_tab_overview_set_view(@ptrCast(tab_overview), self.notebook.adw_tab_view.tab_view);
assert(self.notebook.* == .adw);
c.adw_tab_overview_set_view(@ptrCast(tab_overview), self.notebook.adw.tab_view);
}

self.context_menu = c.gtk_popover_menu_new_from_model(@ptrCast(@alignCast(self.app.context_menu)));
Expand Down Expand Up @@ -279,7 +279,7 @@ pub fn init(self: *Window, alloc: Allocator, app: *App) std.mem.Allocator.Error!
const header_widget: *c.GtkWidget = @ptrCast(@alignCast(self.header.?));
c.adw_toolbar_view_add_top_bar(toolbar_view, header_widget);
const tab_bar = c.adw_tab_bar_new();
c.adw_tab_bar_set_view(tab_bar, self.notebook.adw_tab_view.tab_view);
c.adw_tab_bar_set_view(tab_bar, self.notebook.adw.tab_view);

if (!app.config.@"gtk-wide-tabs") c.adw_tab_bar_set_expand_tabs(tab_bar, 0);

Expand Down Expand Up @@ -323,7 +323,7 @@ pub fn init(self: *Window, alloc: Allocator, app: *App) std.mem.Allocator.Error!
}
} else {
switch (self.notebook.*) {
.adw_tab_view => |tab_view| if (comptime adwaita.versionAtLeast(0, 0, 0)) {
.adw => |*adw| if (comptime adwaita.versionAtLeast(0, 0, 0)) {
// In earlier adwaita versions, we need to add the tabbar manually since we do not use
// an AdwToolbarView.
const tab_bar: *c.AdwTabBar = c.adw_tab_bar_new().?;
Expand All @@ -343,14 +343,14 @@ pub fn init(self: *Window, alloc: Allocator, app: *App) std.mem.Allocator.Error!
@ptrCast(@alignCast(tab_bar)),
),
}
c.adw_tab_bar_set_view(tab_bar, tab_view.tab_view);
c.adw_tab_bar_set_view(tab_bar, adw.tab_view);

if (!app.config.@"gtk-wide-tabs") {
c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
}
},

.gtk_notebook => {},
.gtk => {},
}

// The box is our main child
Expand Down Expand Up @@ -553,7 +553,7 @@ fn gtkNewTabFromOverview(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) ?*c.AdwT
const alloc = self.app.core_app.alloc;
const surface = self.actionSurface();
const tab = Tab.create(alloc, self, surface) catch return null;
return c.adw_tab_view_get_page(self.notebook.adw_tab_view.tab_view, @ptrCast(@alignCast(tab.box)));
return c.adw_tab_view_get_page(self.notebook.adw.tab_view, @ptrCast(@alignCast(tab.box)));
}

fn adwTabOverviewOpen(
Expand Down
Loading

0 comments on commit 6c97ee8

Please sign in to comment.