Skip to content

Commit

Permalink
gtk: add config entry to hide titlebar when the window is maximized
Browse files Browse the repository at this point in the history
Fixes ghostty-org#3381

Note that ghostty-org#4936 will need to be merged or you'll need to rely on Gnome's
default keybinding for unmaximizing a window (super+down).
  • Loading branch information
jcollie authored and Aaron-212 committed Jan 14, 2025
1 parent ae6a088 commit cd4c860
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/apprt/gtk/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub fn init(self: *Window, app: *App) !void {
}

_ = c.g_signal_connect_data(gtk_window, "notify::decorated", c.G_CALLBACK(&gtkWindowNotifyDecorated), self, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(gtk_window, "notify::maximized", c.G_CALLBACK(&gtkWindowNotifyMaximized), self, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(gtk_window, "notify::fullscreened", c.G_CALLBACK(&gtkWindowNotifyFullscreened), self, null, c.G_CONNECT_DEFAULT);

// If we are disabling decorations then disable them right away.
Expand Down Expand Up @@ -601,6 +602,22 @@ fn gtkRealize(v: *c.GtkWindow, ud: ?*anyopaque) callconv(.C) bool {
return true;
}

fn gtkWindowNotifyMaximized(
_: *c.GObject,
_: *c.GParamSpec,
ud: ?*anyopaque,
) callconv(.C) void {
const self = userdataSelf(ud orelse return);
const maximized = c.gtk_window_is_maximized(self.window) != 0;
if (!maximized) {
self.headerbar.setVisible(true);
return;
}
if (self.app.config.@"gtk-titlebar-hide-when-maximized") {
self.headerbar.setVisible(false);
}
}

fn gtkWindowNotifyDecorated(
object: *c.GObject,
_: *c.GParamSpec,
Expand Down
4 changes: 4 additions & 0 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,10 @@ keybind: Keybinds = .{},
/// title bar, or you can switch tabs with keybinds.
@"gtk-tabs-location": GtkTabsLocation = .top,

/// If this is `true`, the titlebar will be hidden when the window is maximized,
/// and shown when the titlebar is unmaximized. GTK only.
@"gtk-titlebar-hide-when-maximized": bool = false,

/// Determines the appearance of the top and bottom bars when using the
/// Adwaita tab bar. This requires `gtk-adwaita` to be enabled (it is
/// by default).
Expand Down

0 comments on commit cd4c860

Please sign in to comment.