mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-15 14:26:09 +00:00
gtk: introduce Zig bindings for GTK/GObject (#5560)
`zig-gobject` is a set of GObject bindings that allow us to write GTK-facing code in Zig instead of getting hands dirty with C. It's been tested and refined in real-life applications and several GTK contributors agree that it is a marked improvement over using the C API directly, such as allowing method call syntax and avoiding many manual `@ptrCast`s. This PR doesn't actually contain any changes to our preexisting GTK code — the migration process is intended to begin in chunks, firstly in self-contained components (e.g. the header bar, overlays, etc.), and then full-scale migration can begin when we remove non-Adwaita GTK builds for 1.2. (After all, why port code that you'll remove later either way?)
This commit is contained in:
@@ -430,9 +430,32 @@ pub fn add(
|
||||
},
|
||||
|
||||
.gtk => {
|
||||
const gobject = b.dependency("gobject", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const gobject_imports = .{
|
||||
.{ "gobject", "gobject2" },
|
||||
.{ "glib", "glib2" },
|
||||
.{ "gtk", "gtk4" },
|
||||
.{ "gdk", "gdk4" },
|
||||
};
|
||||
inline for (gobject_imports) |import| {
|
||||
const name, const module = import;
|
||||
step.root_module.addImport(name, gobject.module(module));
|
||||
}
|
||||
|
||||
step.linkSystemLibrary2("gtk4", dynamic_link_opts);
|
||||
if (self.config.adwaita) step.linkSystemLibrary2("libadwaita-1", dynamic_link_opts);
|
||||
if (self.config.x11) step.linkSystemLibrary2("X11", dynamic_link_opts);
|
||||
|
||||
if (self.config.adwaita) {
|
||||
step.linkSystemLibrary2("libadwaita-1", dynamic_link_opts);
|
||||
step.root_module.addImport("adw", gobject.module("adw1"));
|
||||
}
|
||||
|
||||
if (self.config.x11) {
|
||||
step.linkSystemLibrary2("X11", dynamic_link_opts);
|
||||
step.root_module.addImport("gdk_x11", gobject.module("gdkx114"));
|
||||
}
|
||||
|
||||
if (self.config.wayland) {
|
||||
const scanner = Scanner.create(b.dependency("zig_wayland", .{}), .{
|
||||
@@ -460,6 +483,7 @@ pub fn add(
|
||||
scanner.generate("org_kde_kwin_server_decoration_manager", 1);
|
||||
|
||||
step.root_module.addImport("wayland", wayland);
|
||||
step.root_module.addImport("gdk_wayland", gobject.module("gdkwayland4"));
|
||||
step.linkSystemLibrary2("wayland-client", dynamic_link_opts);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user