From 220d40e99ae189a9ef064bd252dc691dd0bf5f62 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Mon, 30 Dec 2024 16:09:07 -0600 Subject: [PATCH 1/2] gtk: make sure that window-decoration is honored on all paths --- src/apprt/gtk/Window.zig | 8 +++----- src/apprt/gtk/headerbar.zig | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index f3d53e4eb..98bea6da2 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -156,6 +156,9 @@ pub fn init(self: *Window, app: *App) !void { if (app.config.@"gtk-titlebar") { const header = HeaderBar.init(self); + // If we are not decorated then we hide the titlebar. + header.setVisible(app.config.@"window-decoration"); + { const btn = c.gtk_menu_button_new(); c.gtk_widget_set_tooltip_text(btn, "Main Menu"); @@ -298,11 +301,6 @@ pub fn init(self: *Window, app: *App) !void { if (self.header) |header| { const header_widget = header.asWidget(); 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) { diff --git a/src/apprt/gtk/headerbar.zig b/src/apprt/gtk/headerbar.zig index b1567ce27..87dfa8d1a 100644 --- a/src/apprt/gtk/headerbar.zig +++ b/src/apprt/gtk/headerbar.zig @@ -30,6 +30,10 @@ pub const HeaderBar = union(enum) { return .{ .gtk = @ptrCast(headerbar) }; } + pub fn setVisible(self: HeaderBar, visible: bool) void { + c.gtk_widget_set_visible(self.asWidget(), if (visible) 1 else 0); + } + pub fn asWidget(self: HeaderBar) *c.GtkWidget { return switch (self) { .adw => |headerbar| @ptrCast(@alignCast(headerbar)), From f97f7e8a707024f5d88a1ffbfcea1554947b8bc4 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Mon, 30 Dec 2024 19:40:13 -0600 Subject: [PATCH 2/2] gtk: also add css window-decorated class when toggling window decorations --- src/apprt/gtk/Window.zig | 12 +++++++++--- src/apprt/gtk/headerbar.zig | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index 98bea6da2..c9e274ea0 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -514,13 +514,19 @@ pub fn toggleWindowDecorations(self: *Window) void { const new_decorated = !old_decorated; c.gtk_window_set_decorated(self.window, @intFromBool(new_decorated)); + // Fix any artifacting that may occur in window corners. + if (new_decorated) { + c.gtk_widget_add_css_class(@ptrCast(self.window), "without-window-decoration-and-with-titlebar"); + } else { + c.gtk_widget_remove_css_class(@ptrCast(self.window), "without-window-decoration-and-with-titlebar"); + } + // If we have a titlebar, then we also show/hide it depending on the // decorated state. GTK tends to consider the titlebar part of the frame // and hides it with decorations, but libadwaita doesn't. This makes it // explicit. - if (self.header) |v| { - const widget = v.asWidget(); - c.gtk_widget_set_visible(widget, @intFromBool(new_decorated)); + if (self.header) |headerbar| { + headerbar.setVisible(new_decorated); } } diff --git a/src/apprt/gtk/headerbar.zig b/src/apprt/gtk/headerbar.zig index 87dfa8d1a..5bb92aca2 100644 --- a/src/apprt/gtk/headerbar.zig +++ b/src/apprt/gtk/headerbar.zig @@ -31,7 +31,7 @@ pub const HeaderBar = union(enum) { } pub fn setVisible(self: HeaderBar, visible: bool) void { - c.gtk_widget_set_visible(self.asWidget(), if (visible) 1 else 0); + c.gtk_widget_set_visible(self.asWidget(), @intFromBool(visible)); } pub fn asWidget(self: HeaderBar) *c.GtkWidget {