apprt/gtk: let GTK titlebar be toggleable

This adds the gtk-titlebar option, which allows you to toggle the GTK
titlebar on (default) and off.

Under some circumstances (e.g. tiling WMs with titlebars enabled), one
may wish to disable the GTK titlebar/CSD for aesthetic reasons. This
allows you to do that.

Fixes #920.
This commit is contained in:
Chris Marchesi
2023-11-20 20:00:35 -08:00
parent 7fba402499
commit 39e3fca210
2 changed files with 26 additions and 14 deletions

View File

@@ -79,20 +79,24 @@ pub fn init(self: *Window, app: *App) !void {
// Use the new GTK4 header bar. We only create a header bar if we have
// window decorations.
if (app.config.@"window-decoration") {
const header = c.gtk_header_bar_new();
c.gtk_window_set_titlebar(gtk_window, header);
{
const btn = c.gtk_menu_button_new();
c.gtk_widget_set_tooltip_text(btn, "Main Menu");
c.gtk_menu_button_set_icon_name(@ptrCast(btn), "open-menu-symbolic");
c.gtk_menu_button_set_menu_model(@ptrCast(btn), @ptrCast(@alignCast(app.menu)));
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
}
{
const btn = c.gtk_button_new_from_icon_name("tab-new-symbolic");
c.gtk_widget_set_tooltip_text(btn, "New Tab");
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
_ = c.g_signal_connect_data(btn, "clicked", c.G_CALLBACK(&gtkTabNewClick), self, null, c.G_CONNECT_DEFAULT);
// gtk-titlebar can also be used to disable the header bar (but keep
// the window manager's decorations).
if (app.config.@"gtk-titlebar") {
const header = c.gtk_header_bar_new();
c.gtk_window_set_titlebar(gtk_window, header);
{
const btn = c.gtk_menu_button_new();
c.gtk_widget_set_tooltip_text(btn, "Main Menu");
c.gtk_menu_button_set_icon_name(@ptrCast(btn), "open-menu-symbolic");
c.gtk_menu_button_set_menu_model(@ptrCast(btn), @ptrCast(@alignCast(app.menu)));
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
}
{
const btn = c.gtk_button_new_from_icon_name("tab-new-symbolic");
c.gtk_widget_set_tooltip_text(btn, "New Tab");
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
_ = c.g_signal_connect_data(btn, "clicked", c.G_CALLBACK(&gtkTabNewClick), self, null, c.G_CONNECT_DEFAULT);
}
}
} else {
// Hide window decoration if configured. This has to happen before