-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GTK: refactor headerbar into separate Adwaita & GTK structs (#4850)
There's one behavioral change here. Before this patch, if `gtk-titlebar=false` we _never_ created a headerbar. This explicitly contradicted the comments in the source, and the documentation for `gtk-titlebar` imply that if a window starts out without a titlebar it can be brought back later with the `toggle_window_decorations` keybind action. After this patch, a headerbar is always created, but if `gtk-titlebar=false` or `window-decoration=false` it's immediately hidden. I'm not sure how this interacts with the current SSD/CSD detection that seems to happen when running Ghostty on non-Gnome DEs so it'll be important to get #4724 merged (plus any follow ups) to enable more explicit control of SSD/CSD.
- Loading branch information
Showing
4 changed files
with
203 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const HeaderBarAdw = @This(); | ||
|
||
const std = @import("std"); | ||
const c = @import("c.zig").c; | ||
|
||
const Window = @import("Window.zig"); | ||
const adwaita = @import("adwaita.zig"); | ||
|
||
const HeaderBar = @import("headerbar.zig").HeaderBar; | ||
|
||
const AdwHeaderBar = if (adwaita.versionAtLeast(0, 0, 0)) c.AdwHeaderBar else anyopaque; | ||
const AdwWindowTitle = if (adwaita.versionAtLeast(0, 0, 0)) c.AdwWindowTitle else anyopaque; | ||
|
||
/// the window that this headerbar is attached to | ||
window: *Window, | ||
/// the Adwaita headerbar widget | ||
headerbar: *AdwHeaderBar, | ||
/// the Adwaita window title widget | ||
title: *AdwWindowTitle, | ||
|
||
pub fn init(headerbar: *HeaderBar) void { | ||
if (!adwaita.versionAtLeast(0, 0, 0)) return; | ||
|
||
const window: *Window = @fieldParentPtr("headerbar", headerbar); | ||
headerbar.* = .{ | ||
.adw = .{ | ||
.window = window, | ||
.headerbar = @ptrCast(@alignCast(c.adw_header_bar_new())), | ||
.title = @ptrCast(@alignCast(c.adw_window_title_new( | ||
c.gtk_window_get_title(window.window) orelse "Ghostty", | ||
null, | ||
))), | ||
}, | ||
}; | ||
c.adw_header_bar_set_title_widget( | ||
headerbar.adw.headerbar, | ||
@ptrCast(@alignCast(headerbar.adw.title)), | ||
); | ||
} | ||
|
||
pub fn setVisible(self: HeaderBarAdw, visible: bool) void { | ||
c.gtk_widget_set_visible(self.asWidget(), @intFromBool(visible)); | ||
} | ||
|
||
pub fn asWidget(self: HeaderBarAdw) *c.GtkWidget { | ||
return @ptrCast(@alignCast(self.headerbar)); | ||
} | ||
|
||
pub fn packEnd(self: HeaderBarAdw, widget: *c.GtkWidget) void { | ||
if (comptime adwaita.versionAtLeast(0, 0, 0)) { | ||
c.adw_header_bar_pack_end( | ||
@ptrCast(@alignCast(self.headerbar)), | ||
widget, | ||
); | ||
} | ||
} | ||
|
||
pub fn packStart(self: HeaderBarAdw, widget: *c.GtkWidget) void { | ||
if (comptime adwaita.versionAtLeast(0, 0, 0)) { | ||
c.adw_header_bar_pack_start( | ||
@ptrCast(@alignCast(self.headerbar)), | ||
widget, | ||
); | ||
} | ||
} | ||
|
||
pub fn setTitle(self: HeaderBarAdw, title: [:0]const u8) void { | ||
if (comptime adwaita.versionAtLeast(0, 0, 0)) { | ||
c.adw_window_title_set_title(self.title, title); | ||
} | ||
} | ||
|
||
pub fn setSubtitle(self: HeaderBarAdw, subtitle: [:0]const u8) void { | ||
if (comptime adwaita.versionAtLeast(0, 0, 0)) { | ||
c.adw_window_title_set_subtitle(self.title, subtitle); | ||
} | ||
} |
Oops, something went wrong.