mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 01:06:08 +03:00
Merge pull request #2239 from Pangoraw/notebook-nobox
apprt/gtk: make Notebook.create not depend on parent box
This commit is contained in:
@ -197,7 +197,8 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup our notebook
|
// Setup our notebook
|
||||||
self.notebook = Notebook.create(self, box);
|
self.notebook = Notebook.create(self);
|
||||||
|
c.gtk_box_append(@ptrCast(box), self.notebook.asWidget());
|
||||||
|
|
||||||
// If we have a tab overview then we can set it on our notebook.
|
// If we have a tab overview then we can set it on our notebook.
|
||||||
if (tab_overview_) |tab_overview| {
|
if (tab_overview_) |tab_overview| {
|
||||||
@ -270,6 +271,36 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
switch (self.notebook) {
|
||||||
|
.adw_tab_view => |tab_view| 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().?;
|
||||||
|
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 (!app.config.@"gtk-wide-tabs") {
|
||||||
|
c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
.gtk_notebook => {},
|
||||||
|
}
|
||||||
|
|
||||||
// The box is our main child
|
// The box is our main child
|
||||||
c.gtk_window_set_child(gtk_window, box);
|
c.gtk_window_set_child(gtk_window, box);
|
||||||
if (self.header) |h| c.gtk_window_set_titlebar(gtk_window, @ptrCast(@alignCast(h)));
|
if (self.header) |h| c.gtk_window_set_titlebar(gtk_window, @ptrCast(@alignCast(h)));
|
||||||
|
@ -16,13 +16,13 @@ pub const Notebook = union(enum) {
|
|||||||
adw_tab_view: *AdwTabView,
|
adw_tab_view: *AdwTabView,
|
||||||
gtk_notebook: *c.GtkNotebook,
|
gtk_notebook: *c.GtkNotebook,
|
||||||
|
|
||||||
pub fn create(window: *Window, box: *c.GtkWidget) @This() {
|
pub fn create(window: *Window) Notebook {
|
||||||
const app = window.app;
|
const app = window.app;
|
||||||
if (adwaita.enabled(&app.config)) return initAdw(window, box);
|
if (adwaita.enabled(&app.config)) return initAdw(window);
|
||||||
return initGtk(window, box);
|
return initGtk(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initGtk(window: *Window, box: *c.GtkWidget) Notebook {
|
fn initGtk(window: *Window) Notebook {
|
||||||
const app = window.app;
|
const app = window.app;
|
||||||
|
|
||||||
// Create a notebook to hold our tabs.
|
// Create a notebook to hold our tabs.
|
||||||
@ -57,36 +57,14 @@ pub const Notebook = union(enum) {
|
|||||||
_ = c.g_signal_connect_data(notebook, "switch-page", c.G_CALLBACK(>kSwitchPage), window, null, c.G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(notebook, "switch-page", c.G_CALLBACK(>kSwitchPage), window, null, c.G_CONNECT_DEFAULT);
|
||||||
_ = c.g_signal_connect_data(notebook, "create-window", c.G_CALLBACK(>kNotebookCreateWindow), window, null, c.G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(notebook, "create-window", c.G_CALLBACK(>kNotebookCreateWindow), window, null, c.G_CONNECT_DEFAULT);
|
||||||
|
|
||||||
c.gtk_box_append(@ptrCast(box), notebook_widget);
|
|
||||||
return .{ .gtk_notebook = notebook };
|
return .{ .gtk_notebook = notebook };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initAdw(window: *Window, box: *c.GtkWidget) Notebook {
|
fn initAdw(window: *Window) Notebook {
|
||||||
const app = window.app;
|
const app = window.app;
|
||||||
assert(adwaita.enabled(&app.config));
|
assert(adwaita.enabled(&app.config));
|
||||||
|
|
||||||
const tab_view: *c.AdwTabView = c.adw_tab_view_new().?;
|
const tab_view: *c.AdwTabView = c.adw_tab_view_new().?;
|
||||||
c.gtk_box_append(@ptrCast(box), @ptrCast(@alignCast(tab_view)));
|
|
||||||
if ((comptime !adwaita.versionAtLeast(1, 4, 0)) or
|
|
||||||
!adwaita.versionAtLeast(1, 4, 0) or
|
|
||||||
!app.config.@"gtk-titlebar")
|
|
||||||
{
|
|
||||||
const tab_bar: *c.AdwTabBar = c.adw_tab_bar_new().?;
|
|
||||||
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 (!app.config.@"gtk-wide-tabs") {
|
|
||||||
c.adw_tab_bar_set_expand_tabs(tab_bar, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = c.g_signal_connect_data(tab_view, "page-attached", c.G_CALLBACK(&adwPageAttached), window, null, c.G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(tab_view, "page-attached", c.G_CALLBACK(&adwPageAttached), window, null, c.G_CONNECT_DEFAULT);
|
||||||
_ = 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, "create-window", c.G_CALLBACK(&adwTabViewCreateWindow), window, null, c.G_CONNECT_DEFAULT);
|
||||||
@ -95,6 +73,13 @@ pub const Notebook = union(enum) {
|
|||||||
return .{ .adw_tab_view = tab_view };
|
return .{ .adw_tab_view = tab_view };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn asWidget(self: Notebook) *c.GtkWidget {
|
||||||
|
return switch (self) {
|
||||||
|
.adw_tab_view => |tab_view| @ptrCast(@alignCast(tab_view)),
|
||||||
|
.gtk_notebook => |notebook| @ptrCast(@alignCast(notebook)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn nPages(self: Notebook) c_int {
|
pub fn nPages(self: Notebook) c_int {
|
||||||
return switch (self) {
|
return switch (self) {
|
||||||
.gtk_notebook => |notebook| c.gtk_notebook_get_n_pages(notebook),
|
.gtk_notebook => |notebook| c.gtk_notebook_get_n_pages(notebook),
|
||||||
|
Reference in New Issue
Block a user