mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
apprt/gtk: fix the combination of gtk-titlebar=false and gtk-tabs-location=hidden
Fixes: #3178 Signed-off-by: Tristan Partin <tristan@partin.io>
This commit is contained in:
@ -83,7 +83,7 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
|
|
||||||
// Create the window
|
// Create the window
|
||||||
const window: *c.GtkWidget = window: {
|
const window: *c.GtkWidget = window: {
|
||||||
if (self.isAdwWindow()) {
|
if ((comptime adwaita.versionAtLeast(0, 0, 0)) and adwaita.enabled(&self.app.config)) {
|
||||||
const window = c.adw_application_window_new(app.app);
|
const window = c.adw_application_window_new(app.app);
|
||||||
c.gtk_widget_add_css_class(@ptrCast(window), "adw");
|
c.gtk_widget_add_css_class(@ptrCast(window), "adw");
|
||||||
break :window window;
|
break :window window;
|
||||||
@ -125,7 +125,7 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
self.notebook = Notebook.create(self);
|
self.notebook = Notebook.create(self);
|
||||||
|
|
||||||
// If we are using Adwaita, then we can support the tab overview.
|
// If we are using Adwaita, then we can support the tab overview.
|
||||||
self.tab_overview = if ((comptime adwaita.versionAtLeast(1, 3, 0)) and adwaita.enabled(&self.app.config) and adwaita.versionAtLeast(1, 3, 0)) overview: {
|
self.tab_overview = if ((comptime adwaita.versionAtLeast(1, 4, 0)) and adwaita.enabled(&self.app.config) and adwaita.versionAtLeast(1, 4, 0)) 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_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);
|
||||||
@ -167,7 +167,7 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
// If we're using an AdwWindow then we can support the tab overview.
|
// If we're using an AdwWindow then we can support the tab overview.
|
||||||
if (self.tab_overview) |tab_overview| {
|
if (self.tab_overview) |tab_overview| {
|
||||||
if (comptime !adwaita.versionAtLeast(1, 4, 0)) unreachable;
|
if (comptime !adwaita.versionAtLeast(1, 4, 0)) unreachable;
|
||||||
assert(self.isAdwWindow());
|
assert(self.app.config.@"gtk-adwaita" and adwaita.versionAtLeast(1, 4, 0));
|
||||||
const btn = switch (app.config.@"gtk-tabs-location") {
|
const btn = switch (app.config.@"gtk-tabs-location") {
|
||||||
.top, .bottom, .left, .right => btn: {
|
.top, .bottom, .left, .right => btn: {
|
||||||
const btn = c.gtk_toggle_button_new();
|
const btn = c.gtk_toggle_button_new();
|
||||||
@ -279,13 +279,19 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
// Our actions for the menu
|
// Our actions for the menu
|
||||||
initActions(self);
|
initActions(self);
|
||||||
|
|
||||||
if (self.isAdwWindow()) {
|
if ((comptime adwaita.versionAtLeast(1, 4, 0)) and adwaita.versionAtLeast(1, 4, 0) and adwaita.enabled(&self.app.config)) {
|
||||||
if (comptime !adwaita.versionAtLeast(1, 4, 0)) unreachable;
|
|
||||||
const toolbar_view: *c.AdwToolbarView = @ptrCast(c.adw_toolbar_view_new());
|
const toolbar_view: *c.AdwToolbarView = @ptrCast(c.adw_toolbar_view_new());
|
||||||
|
|
||||||
const header_widget: *c.GtkWidget = self.header.?.asWidget();
|
if (self.header) |header| {
|
||||||
|
const header_widget = header.asWidget();
|
||||||
c.adw_toolbar_view_add_top_bar(toolbar_view, header_widget);
|
c.adw_toolbar_view_add_top_bar(toolbar_view, header_widget);
|
||||||
|
|
||||||
|
// If we are not decorated then we hide the titlebar.
|
||||||
|
if (!app.config.@"window-decoration") {
|
||||||
|
c.gtk_widget_set_visible(header_widget, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (self.app.config.@"gtk-tabs-location" != .hidden) {
|
if (self.app.config.@"gtk-tabs-location" != .hidden) {
|
||||||
const tab_bar = c.adw_tab_bar_new();
|
const tab_bar = c.adw_tab_bar_new();
|
||||||
c.adw_tab_bar_set_view(tab_bar, self.notebook.adw_tab_view);
|
c.adw_tab_bar_set_view(tab_bar, self.notebook.adw_tab_view);
|
||||||
@ -310,28 +316,15 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
c.adw_toolbar_view_set_top_bar_style(toolbar_view, toolbar_style);
|
c.adw_toolbar_view_set_top_bar_style(toolbar_view, toolbar_style);
|
||||||
c.adw_toolbar_view_set_bottom_bar_style(toolbar_view, toolbar_style);
|
c.adw_toolbar_view_set_bottom_bar_style(toolbar_view, toolbar_style);
|
||||||
|
|
||||||
// If we are not decorated then we hide the titlebar.
|
// Set our application window content.
|
||||||
if (!app.config.@"window-decoration") {
|
|
||||||
c.gtk_widget_set_visible(header_widget, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set our application window content. The content depends on if
|
|
||||||
// we're using an AdwTabOverview or not.
|
|
||||||
if (self.tab_overview) |tab_overview| {
|
|
||||||
c.adw_tab_overview_set_child(
|
c.adw_tab_overview_set_child(
|
||||||
@ptrCast(tab_overview),
|
@ptrCast(self.tab_overview),
|
||||||
@ptrCast(@alignCast(toolbar_view)),
|
@ptrCast(@alignCast(toolbar_view)),
|
||||||
);
|
);
|
||||||
c.adw_application_window_set_content(
|
c.adw_application_window_set_content(
|
||||||
@ptrCast(gtk_window),
|
@ptrCast(gtk_window),
|
||||||
@ptrCast(@alignCast(tab_overview)),
|
@ptrCast(@alignCast(self.tab_overview)),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
c.adw_application_window_set_content(
|
|
||||||
@ptrCast(gtk_window),
|
|
||||||
@ptrCast(@alignCast(toolbar_view)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else tab_bar: {
|
} 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)) {
|
||||||
@ -415,17 +408,6 @@ pub fn deinit(self: *Window) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this window should use an Adwaita window.
|
|
||||||
///
|
|
||||||
/// This must be `inline` so that the comptime check noops conditional
|
|
||||||
/// paths that are not enabled.
|
|
||||||
inline fn isAdwWindow(self: *Window) bool {
|
|
||||||
return (comptime adwaita.versionAtLeast(1, 4, 0)) and
|
|
||||||
adwaita.enabled(&self.app.config) and
|
|
||||||
adwaita.versionAtLeast(1, 4, 0) and
|
|
||||||
self.app.config.@"gtk-titlebar";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a new tab to this window.
|
/// Add a new tab to this window.
|
||||||
pub fn newTab(self: *Window, parent: ?*CoreSurface) !void {
|
pub fn newTab(self: *Window, parent: ?*CoreSurface) !void {
|
||||||
const alloc = self.app.core_app.alloc;
|
const alloc = self.app.core_app.alloc;
|
||||||
@ -557,7 +539,7 @@ fn gtkTabNewClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
|||||||
/// because we need to return an AdwTabPage from this function.
|
/// because we need to return an AdwTabPage from this function.
|
||||||
fn gtkNewTabFromOverview(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) ?*c.AdwTabPage {
|
fn gtkNewTabFromOverview(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) ?*c.AdwTabPage {
|
||||||
const self: *Window = userdataSelf(ud.?);
|
const self: *Window = userdataSelf(ud.?);
|
||||||
assert(self.isAdwWindow());
|
assert((comptime adwaita.versionAtLeast(1, 4, 0)) and adwaita.versionAtLeast(1, 4, 0) and adwaita.enabled(&self.app.config));
|
||||||
|
|
||||||
const alloc = self.app.core_app.alloc;
|
const alloc = self.app.core_app.alloc;
|
||||||
const surface = self.actionSurface();
|
const surface = self.actionSurface();
|
||||||
@ -739,7 +721,7 @@ fn gtkActionAbout(
|
|||||||
|
|
||||||
if ((comptime adwaita.versionAtLeast(1, 5, 0)) and
|
if ((comptime adwaita.versionAtLeast(1, 5, 0)) and
|
||||||
adwaita.versionAtLeast(1, 5, 0) and
|
adwaita.versionAtLeast(1, 5, 0) and
|
||||||
self.isAdwWindow())
|
adwaita.enabled(&self.app.config))
|
||||||
{
|
{
|
||||||
c.adw_show_about_dialog(
|
c.adw_show_about_dialog(
|
||||||
@ptrCast(self.window),
|
@ptrCast(self.window),
|
||||||
|
Reference in New Issue
Block a user