mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
apprt/gtk: add gtk-tabs-location=hidden
This is only supported on libadwaita. Instead of the normal tab overview button, we will use an AdwTabButton[0]. Link: https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.6/class.TabButton.html [0] Signed-off-by: Tristan Partin <tristan@partin.io>
This commit is contained in:
@ -120,9 +120,13 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
// Create our box which will hold our widgets in the main content area.
|
// Create our box which will hold our widgets in the main content area.
|
||||||
const box = c.gtk_box_new(c.GTK_ORIENTATION_VERTICAL, 0);
|
const box = c.gtk_box_new(c.GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
|
||||||
|
// Setup our notebook
|
||||||
|
self.notebook = Notebook.create(self);
|
||||||
|
|
||||||
// If we are using an AdwWindow then we can support the tab overview.
|
// If we are using an AdwWindow then we can support the tab overview.
|
||||||
self.tab_overview = if (self.isAdwWindow()) overview: {
|
self.tab_overview = if (self.isAdwWindow()) overview: {
|
||||||
const tab_overview = c.adw_tab_overview_new();
|
const tab_overview = c.adw_tab_overview_new();
|
||||||
|
c.adw_tab_overview_set_view(@ptrCast(tab_overview), self.notebook.adw_tab_view);
|
||||||
c.adw_tab_overview_set_enable_new_tab(@ptrCast(tab_overview), 1);
|
c.adw_tab_overview_set_enable_new_tab(@ptrCast(tab_overview), 1);
|
||||||
_ = c.g_signal_connect_data(
|
_ = c.g_signal_connect_data(
|
||||||
tab_overview,
|
tab_overview,
|
||||||
@ -170,18 +174,34 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
if (comptime !adwaita.versionAtLeast(1, 4, 0)) unreachable;
|
if (comptime !adwaita.versionAtLeast(1, 4, 0)) unreachable;
|
||||||
assert(self.isAdwWindow());
|
assert(self.isAdwWindow());
|
||||||
|
|
||||||
const btn = c.gtk_toggle_button_new();
|
const btn = btn: {
|
||||||
c.gtk_widget_set_tooltip_text(btn, "Show Open Tabs");
|
switch (app.config.@"gtk-tabs-location") {
|
||||||
c.gtk_button_set_icon_name(@ptrCast(btn), "view-grid-symbolic");
|
.top, .bottom, .left, .right => {
|
||||||
|
const btn = c.gtk_toggle_button_new();
|
||||||
|
c.gtk_widget_set_tooltip_text(btn, "Show Open Tabs");
|
||||||
|
c.gtk_button_set_icon_name(@ptrCast(btn), "view-grid-symbolic");
|
||||||
|
_ = c.g_object_bind_property(
|
||||||
|
btn,
|
||||||
|
"active",
|
||||||
|
tab_overview,
|
||||||
|
"open",
|
||||||
|
c.G_BINDING_BIDIRECTIONAL | c.G_BINDING_SYNC_CREATE,
|
||||||
|
);
|
||||||
|
|
||||||
|
break :btn btn;
|
||||||
|
},
|
||||||
|
.hidden => {
|
||||||
|
const btn = c.adw_tab_button_new();
|
||||||
|
c.adw_tab_button_set_view(@ptrCast(btn), self.notebook.adw_tab_view);
|
||||||
|
c.gtk_actionable_set_action_name(@ptrCast(btn), "overview.open");
|
||||||
|
|
||||||
|
break :btn btn;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
c.gtk_widget_set_focus_on_click(btn, c.FALSE);
|
c.gtk_widget_set_focus_on_click(btn, c.FALSE);
|
||||||
c.adw_header_bar_pack_end(@ptrCast(header), btn);
|
c.adw_header_bar_pack_end(@ptrCast(header), btn);
|
||||||
_ = c.g_object_bind_property(
|
|
||||||
btn,
|
|
||||||
"active",
|
|
||||||
tab_overview,
|
|
||||||
"open",
|
|
||||||
c.G_BINDING_BIDIRECTIONAL | c.G_BINDING_SYNC_CREATE,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -225,9 +245,6 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
c.gtk_box_append(@ptrCast(box), warning_box);
|
c.gtk_box_append(@ptrCast(box), warning_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup our notebook
|
|
||||||
self.notebook = Notebook.create(self);
|
|
||||||
|
|
||||||
// Setup our toast overlay if we have one
|
// Setup our toast overlay if we have one
|
||||||
self.toast_overlay = if (adwaita.enabled(&self.app.config)) toast: {
|
self.toast_overlay = if (adwaita.enabled(&self.app.config)) toast: {
|
||||||
const toast_overlay = c.adw_toast_overlay_new();
|
const toast_overlay = c.adw_toast_overlay_new();
|
||||||
@ -279,16 +296,20 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
|
|
||||||
const header_widget: *c.GtkWidget = @ptrCast(@alignCast(self.header.?));
|
const header_widget: *c.GtkWidget = @ptrCast(@alignCast(self.header.?));
|
||||||
c.adw_toolbar_view_add_top_bar(toolbar_view, header_widget);
|
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);
|
if (self.app.config.@"gtk-tabs-location" != .hidden) {
|
||||||
|
const tab_bar = c.adw_tab_bar_new();
|
||||||
|
c.adw_tab_bar_set_view(tab_bar, self.notebook.adw_tab_view);
|
||||||
|
|
||||||
const tab_bar_widget: *c.GtkWidget = @ptrCast(@alignCast(tab_bar));
|
if (!app.config.@"gtk-wide-tabs") c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
|
||||||
switch (self.app.config.@"gtk-tabs-location") {
|
|
||||||
// left and right is not supported in libadwaita.
|
const tab_bar_widget: *c.GtkWidget = @ptrCast(@alignCast(tab_bar));
|
||||||
.top, .left, .right => c.adw_toolbar_view_add_top_bar(toolbar_view, tab_bar_widget),
|
switch (self.app.config.@"gtk-tabs-location") {
|
||||||
.bottom => c.adw_toolbar_view_add_bottom_bar(toolbar_view, tab_bar_widget),
|
// left and right are 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),
|
||||||
|
.hidden => unreachable,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.adw_toolbar_view_set_content(toolbar_view, box);
|
c.adw_toolbar_view_set_content(toolbar_view, box);
|
||||||
|
|
||||||
@ -322,15 +343,16 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
@ptrCast(@alignCast(toolbar_view)),
|
@ptrCast(@alignCast(toolbar_view)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else tab_bar: {
|
||||||
switch (self.notebook) {
|
switch (self.notebook) {
|
||||||
.adw_tab_view => |tab_view| if (comptime adwaita.versionAtLeast(0, 0, 0)) {
|
.adw_tab_view => |tab_view| if (comptime adwaita.versionAtLeast(0, 0, 0)) {
|
||||||
|
if (app.config.@"gtk-tabs-location" == .hidden) break :tab_bar;
|
||||||
|
|
||||||
// In earlier adwaita versions, we need to add the tabbar manually since we do not use
|
// In earlier adwaita versions, we need to add the tabbar manually since we do not use
|
||||||
// an AdwToolbarView.
|
// an AdwToolbarView.
|
||||||
const tab_bar: *c.AdwTabBar = c.adw_tab_bar_new().?;
|
const tab_bar: *c.AdwTabBar = c.adw_tab_bar_new().?;
|
||||||
c.gtk_widget_add_css_class(@ptrCast(@alignCast(tab_bar)), "inline");
|
c.gtk_widget_add_css_class(@ptrCast(@alignCast(tab_bar)), "inline");
|
||||||
switch (app.config.@"gtk-tabs-location") {
|
switch (app.config.@"gtk-tabs-location") {
|
||||||
// left and right is not supported in libadwaita.
|
|
||||||
.top,
|
.top,
|
||||||
.left,
|
.left,
|
||||||
.right,
|
.right,
|
||||||
@ -343,12 +365,11 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
@ptrCast(box),
|
@ptrCast(box),
|
||||||
@ptrCast(@alignCast(tab_bar)),
|
@ptrCast(@alignCast(tab_bar)),
|
||||||
),
|
),
|
||||||
|
.hidden => unreachable,
|
||||||
}
|
}
|
||||||
c.adw_tab_bar_set_view(tab_bar, tab_view);
|
c.adw_tab_bar_set_view(tab_bar, tab_view);
|
||||||
|
|
||||||
if (!app.config.@"gtk-wide-tabs") {
|
if (!app.config.@"gtk-wide-tabs") c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
|
||||||
c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
.gtk_notebook => {},
|
.gtk_notebook => {},
|
||||||
|
@ -29,7 +29,7 @@ pub const Notebook = union(enum) {
|
|||||||
const notebook_widget: *c.GtkWidget = c.gtk_notebook_new();
|
const notebook_widget: *c.GtkWidget = c.gtk_notebook_new();
|
||||||
const notebook: *c.GtkNotebook = @ptrCast(notebook_widget);
|
const notebook: *c.GtkNotebook = @ptrCast(notebook_widget);
|
||||||
const notebook_tab_pos: c_uint = switch (app.config.@"gtk-tabs-location") {
|
const notebook_tab_pos: c_uint = switch (app.config.@"gtk-tabs-location") {
|
||||||
.top => c.GTK_POS_TOP,
|
.top, .hidden => c.GTK_POS_TOP,
|
||||||
.bottom => c.GTK_POS_BOTTOM,
|
.bottom => c.GTK_POS_BOTTOM,
|
||||||
.left => c.GTK_POS_LEFT,
|
.left => c.GTK_POS_LEFT,
|
||||||
.right => c.GTK_POS_RIGHT,
|
.right => c.GTK_POS_RIGHT,
|
||||||
|
@ -1727,10 +1727,17 @@ keybind: Keybinds = .{},
|
|||||||
@"gtk-titlebar": bool = true,
|
@"gtk-titlebar": bool = true,
|
||||||
|
|
||||||
/// Determines the side of the screen that the GTK tab bar will stick to.
|
/// 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.
|
/// Top, bottom, left, right, and hidden are supported. The default is top.
|
||||||
///
|
///
|
||||||
/// If this option has value `left` or `right` when using Adwaita, it falls
|
/// If this option has value `left` or `right` when using Adwaita, it falls
|
||||||
/// back to `top`.
|
/// back to `top`. `hidden`, meaning that tabs don't exist, is not supported
|
||||||
|
/// without using Adwaita, falling back to `top`.
|
||||||
|
///
|
||||||
|
/// When `hidden` is set and Adwaita is enabled, a tab button displaying the
|
||||||
|
/// number of tabs will appear in the title bar. It has the ability to open a
|
||||||
|
/// tab overview for displaying tabs. Alternatively, you can use the
|
||||||
|
/// `toggle_tab_overview` action in a keybind if your window doesn't have a
|
||||||
|
/// title bar, or you can switch tabs with keybinds.
|
||||||
@"gtk-tabs-location": GtkTabsLocation = .top,
|
@"gtk-tabs-location": GtkTabsLocation = .top,
|
||||||
|
|
||||||
/// Determines the appearance of the top and bottom bars when using the
|
/// Determines the appearance of the top and bottom bars when using the
|
||||||
@ -4854,6 +4861,7 @@ pub const GtkTabsLocation = enum {
|
|||||||
bottom,
|
bottom,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
|
hidden,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// See adw-toolbar-style
|
/// See adw-toolbar-style
|
||||||
|
Reference in New Issue
Block a user