gtk: make sure that window-decoration is honored on all paths (#4130)

Fix a regression from #4110 .
This commit is contained in:
Mitchell Hashimoto
2024-12-30 19:22:26 -08:00
committed by GitHub
2 changed files with 16 additions and 8 deletions

View File

@ -156,6 +156,9 @@ pub fn init(self: *Window, app: *App) !void {
if (app.config.@"gtk-titlebar") { if (app.config.@"gtk-titlebar") {
const header = HeaderBar.init(self); 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(); const btn = c.gtk_menu_button_new();
c.gtk_widget_set_tooltip_text(btn, "Main Menu"); 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| { if (self.header) |header| {
const header_widget = header.asWidget(); 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) {
@ -516,13 +514,19 @@ pub fn toggleWindowDecorations(self: *Window) void {
const new_decorated = !old_decorated; const new_decorated = !old_decorated;
c.gtk_window_set_decorated(self.window, @intFromBool(new_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 // 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 // decorated state. GTK tends to consider the titlebar part of the frame
// and hides it with decorations, but libadwaita doesn't. This makes it // and hides it with decorations, but libadwaita doesn't. This makes it
// explicit. // explicit.
if (self.header) |v| { if (self.header) |headerbar| {
const widget = v.asWidget(); headerbar.setVisible(new_decorated);
c.gtk_widget_set_visible(widget, @intFromBool(new_decorated));
} }
} }

View File

@ -30,6 +30,10 @@ pub const HeaderBar = union(enum) {
return .{ .gtk = @ptrCast(headerbar) }; return .{ .gtk = @ptrCast(headerbar) };
} }
pub fn setVisible(self: HeaderBar, visible: bool) void {
c.gtk_widget_set_visible(self.asWidget(), @intFromBool(visible));
}
pub fn asWidget(self: HeaderBar) *c.GtkWidget { pub fn asWidget(self: HeaderBar) *c.GtkWidget {
return switch (self) { return switch (self) {
.adw => |headerbar| @ptrCast(@alignCast(headerbar)), .adw => |headerbar| @ptrCast(@alignCast(headerbar)),