gtk: remove c.zig

It has been done.
pull/6792/head
Leah Amelia Chen 2025-02-25 08:55:56 +01:00
parent 73341b052b
commit a773588c99
No known key found for this signature in database
4 changed files with 28 additions and 99 deletions

View File

@ -1,73 +0,0 @@
/// View helps with creating a view with a constraint layout by
/// managing all the boilerplate. The caller is responsible for
/// providing the widgets, their names, and the VFL code and gets
/// a root box as a result ready to be used.
const View = @This();
const std = @import("std");
const c = @import("c.zig").c;
const log = std.log.scoped(.gtk);
/// The box that contains all of the widgets.
root: *c.GtkWidget,
/// A single widget used in the view.
pub const Widget = struct {
/// The name of the widget used for the layout code. This is also
/// the name set for the widget for CSS styling.
name: [:0]const u8,
/// The widget itself.
widget: *c.GtkWidget,
};
/// Initialize a new constraint layout view with the given widgets
/// and VFL.
pub fn init(widgets: []const Widget, vfl: []const [*:0]const u8) !View {
// Box to store all our widgets
const box = c.gtk_box_new(c.GTK_ORIENTATION_VERTICAL, 0);
errdefer c.g_object_unref(box);
c.gtk_widget_set_vexpand(box, 1);
c.gtk_widget_set_hexpand(box, 1);
// Setup our constraint layout and attach it to the box
const layout = c.gtk_constraint_layout_new();
errdefer c.g_object_unref(layout);
c.gtk_widget_set_layout_manager(@ptrCast(box), layout);
// Setup our views table
const views = c.g_hash_table_new(c.g_str_hash, c.g_str_equal);
defer c.g_hash_table_unref(views);
// Add our widgets
for (widgets) |widget| {
c.gtk_widget_set_parent(widget.widget, box);
c.gtk_widget_set_name(widget.widget, widget.name);
_ = c.g_hash_table_insert(
views,
@constCast(@ptrCast(widget.name.ptr)),
widget.widget,
);
}
// Add all of our constraints for layout
var err_: ?*c.GError = null;
const list = c.gtk_constraint_layout_add_constraints_from_descriptionv(
@ptrCast(layout),
vfl.ptr,
vfl.len,
8,
8,
views,
&err_,
);
if (err_) |err| {
defer c.g_error_free(err);
log.warn("error building view message={s}", .{err.message});
return error.OperationFailed;
}
c.g_list_free(list);
return .{ .root = box };
}

View File

@ -1,8 +0,0 @@
/// Imported C API directly from header files
pub const c = @cImport({
@cInclude("gtk/gtk.h");
@cInclude("adwaita.h");
// compatibility
@cInclude("ghostty_gtk_compat.h");
});

View File

@ -11,11 +11,17 @@ const gtk = @import("gtk");
const log = std.log.scoped(.gtk);
pub const version: std.SemanticVersion = .{
.major = c.GTK_MAJOR_VERSION,
.minor = c.GTK_MINOR_VERSION,
.patch = c.GTK_MICRO_VERSION,
};
pub fn logVersion() void {
log.info("GTK version build={d}.{d}.{d} runtime={d}.{d}.{d}", .{
c.GTK_MAJOR_VERSION,
c.GTK_MINOR_VERSION,
c.GTK_MICRO_VERSION,
version.major,
version.minor,
version.patch,
gtk.getMajorVersion(),
gtk.getMinorVersion(),
gtk.getMicroVersion(),
@ -45,10 +51,11 @@ pub inline fn atLeast(
// we can return false immediately. This prevents us from
// compiling against unknown symbols and makes runtime checks
// very slightly faster.
if (comptime c.GTK_MAJOR_VERSION < major or
(c.GTK_MAJOR_VERSION == major and c.GTK_MINOR_VERSION < minor) or
(c.GTK_MAJOR_VERSION == major and c.GTK_MINOR_VERSION == minor and c.GTK_MICRO_VERSION < micro))
return false;
if (comptime version.order(.{
.major = major,
.minor = minor,
.patch = micro,
}) == .lt) return false;
// If we're in comptime then we can't check the runtime version.
if (@inComptime()) return true;

View File

@ -6,7 +6,10 @@ const build_config = @import("../build_config.zig");
const internal_os = @import("../os/main.zig");
const xev = @import("../global.zig").xev;
const renderer = @import("../renderer.zig");
const gtk = if (build_config.app_runtime == .gtk) @import("../apprt/gtk/c.zig").c else void;
const gtk_version = @import("../apprt/gtk/version.zig").version;
const gtk = @import("gtk");
const adw = @import("adw");
pub const Options = struct {};
@ -42,23 +45,23 @@ pub fn run(alloc: Allocator) !u8 {
try stdout.print(" - desktop env: {s}\n", .{@tagName(internal_os.desktopEnvironment())});
try stdout.print(" - GTK version:\n", .{});
try stdout.print(" build : {d}.{d}.{d}\n", .{
gtk.GTK_MAJOR_VERSION,
gtk.GTK_MINOR_VERSION,
gtk.GTK_MICRO_VERSION,
gtk_version.major,
gtk_version.minor,
gtk_version.patch,
});
try stdout.print(" runtime : {d}.{d}.{d}\n", .{
gtk.gtk_get_major_version(),
gtk.gtk_get_minor_version(),
gtk.gtk_get_micro_version(),
gtk.getMajorVersion(),
gtk.getMinorVersion(),
gtk.getMicroVersion(),
});
try stdout.print(" - libadwaita : enabled\n", .{});
try stdout.print(" build : {s}\n", .{
gtk.ADW_VERSION_S,
adw.VERSION_S,
});
try stdout.print(" runtime : {}.{}.{}\n", .{
gtk.adw_get_major_version(),
gtk.adw_get_minor_version(),
gtk.adw_get_micro_version(),
adw.getMajorVersion(),
adw.getMinorVersion(),
adw.getMicroVersion(),
});
if (comptime build_options.x11) {
try stdout.print(" - libX11 : enabled\n", .{});