adw: add support for gtk-tabs-location = bottom

this falls back to top when using either right or left.
This commit is contained in:
Paul Berg
2024-09-11 14:07:01 +02:00
parent 0c286a049a
commit 7aa6b0008a
3 changed files with 23 additions and 11 deletions

View File

@ -138,7 +138,6 @@ pub fn init(self: *Window, app: *App) !void {
}
self.notebook = Notebook.create(self, box);
c.gtk_box_append(@ptrCast(box), self.notebook.as_widget());
self.context_menu = c.gtk_popover_menu_new_from_model(@ptrCast(@alignCast(self.app.context_menu)));
c.gtk_widget_set_parent(self.context_menu, window);
@ -158,14 +157,20 @@ pub fn init(self: *Window, app: *App) !void {
if (build_options.libadwaita and app.config.@"gtk-adwaita" and app.config.@"gtk-titlebar" and header != null and c.ADW_MINOR_VERSION >= 4) {
const toolbar_view: *c.AdwToolbarView = @ptrCast(c.adw_toolbar_view_new());
c.adw_toolbar_view_add_top_bar(toolbar_view, @ptrCast(@alignCast(header.?)));
const header_widget: *c.GtkWidget = @ptrCast(@alignCast(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);
if (!app.config.@"gtk-wide-tabs") c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
c.adw_toolbar_view_add_top_bar(toolbar_view, @ptrCast(@alignCast(tab_bar)));
const tab_bar_widget: *c.GtkWidget = @ptrCast(@alignCast(tab_bar));
switch (self.app.config.@"gtk-tabs-location") {
// left and right is not supported in libadwaita.
.top, .left, .right => c.adw_toolbar_view_add_top_bar(toolbar_view, tab_bar_widget),
.bottom => c.adw_toolbar_view_add_bottom_bar(toolbar_view, tab_bar_widget),
}
c.adw_toolbar_view_set_content(toolbar_view, box);
c.adw_application_window_set_content(@ptrCast(gtk_window), @ptrCast(@alignCast(toolbar_view)));
@ -258,7 +263,7 @@ pub fn gotoNextTab(self: *Window, surface: *Surface) void {
/// Go to the next tab for a surface.
pub fn gotoLastTab(self: *Window) void {
const max = self.notebook.nPages() -| 1;
const max = self.notebook.nPages() -| 1;
self.gotoTab(@intCast(max));
}

View File

@ -19,11 +19,17 @@ pub const Notebook = union(enum) {
const adwaita = build_options.libadwaita and app.config.@"gtk-adwaita";
if (adwaita) {
const tab_view = c.adw_tab_view_new();
const tab_view = c.adw_tab_view_new().?;
c.gtk_box_append(@ptrCast(box), @ptrCast(@alignCast(tab_view)));
if (!window.app.config.@"gtk-titlebar" or c.ADW_MINOR_VERSION < 4) {
const tab_bar = c.adw_tab_bar_new();
c.gtk_box_prepend(@ptrCast(box), @ptrCast(@alignCast(tab_bar)));
switch (app.config.@"gtk-tabs-location") {
// left and right is not supported in libadwaita.
.top, .left, .right => c.gtk_box_prepend(@ptrCast(box), @ptrCast(@alignCast(tab_bar))),
.bottom => c.gtk_box_append(@ptrCast(box), @ptrCast(@alignCast(tab_bar))),
}
c.adw_tab_bar_set_view(tab_bar, tab_view);
if (!window.app.config.@"gtk-wide-tabs")
@ -34,7 +40,7 @@ pub const Notebook = union(enum) {
_ = c.g_signal_connect_data(tab_view, "create-window", c.G_CALLBACK(&adwTabViewCreateWindow), window, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(tab_view, "notify::selected-page", c.G_CALLBACK(&adwSelectPage), window, null, c.G_CONNECT_DEFAULT);
return .{ .adw_tab_view = tab_view.? };
return .{ .adw_tab_view = tab_view };
}
// Create a notebook to hold our tabs.
@ -59,19 +65,17 @@ pub const Notebook = union(enum) {
c.gtk_widget_set_vexpand(notebook_widget, 1);
c.gtk_widget_set_hexpand(notebook_widget, 1);
// If we are in fullscreen mode, new windows start fullscreen.
if (app.config.fullscreen) c.gtk_window_fullscreen(window.window);
// All of our events
_ = c.g_signal_connect_data(notebook, "page-added", c.G_CALLBACK(&gtkPageAdded), window, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(notebook, "page-removed", c.G_CALLBACK(&gtkPageRemoved), window, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(notebook, "switch-page", c.G_CALLBACK(&gtkSwitchPage), window, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(notebook, "create-window", c.G_CALLBACK(&gtkNotebookCreateWindow), window, null, c.G_CONNECT_DEFAULT);
c.gtk_box_append(@ptrCast(box), notebook_widget);
return .{ .gtk_notebook = notebook };
}
pub fn as_widget(self: Notebook) *c.GtkWidget {
pub fn asWidget(self: Notebook) *c.GtkWidget {
return switch (self) {
.adw_tab_view => |ptr| @ptrCast(@alignCast(ptr)),
.gtk_notebook => |ptr| @ptrCast(@alignCast(ptr)),

View File

@ -1421,6 +1421,9 @@ keybind: Keybinds = .{},
/// Determines the side of the screen that the GTK tab bar will stick to.
/// Top, bottom, left, and right are supported. The default is top.
///
/// If this option has value `left` or `right` when using `libadwaita`, it falls
/// back to `top`.
@"gtk-tabs-location": GtkTabsLocation = .top,
/// If `true` (default), then the Ghostty GTK tabs will be "wide." Wide tabs