diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index c8434a024..035e4d347 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -85,6 +85,16 @@ quit_timer: union(enum) { pub fn init(core_app: *CoreApp, opts: Options) !App { _ = opts; + // Log our GTK version + log.info("GTK version build={d}.{d}.{d} runtime={d}.{d}.{d}", .{ + c.GTK_MAJOR_VERSION, + c.GTK_MINOR_VERSION, + c.GTK_MICRO_VERSION, + c.gtk_get_major_version(), + c.gtk_get_minor_version(), + c.gtk_get_micro_version(), + }); + // We need to export GDK_DEBUG to run on Wayland after GTK 4.14. // Older versions of GTK do not support these values so it is safe // to always set this. Forwards versions are uncertain so we'll have to diff --git a/src/apprt/gtk/version.zig b/src/apprt/gtk/version.zig new file mode 100644 index 000000000..c61e940fb --- /dev/null +++ b/src/apprt/gtk/version.zig @@ -0,0 +1,40 @@ +const c = @import("c.zig").c; + +/// Verifies that the GTK version is at least the given version. +/// +/// This can be run in both a comptime and runtime context. If it +/// is run in a comptime context, it will only check the version +/// in the headers. If it is run in a runtime context, it will +/// check the actual version of the library we are linked against. +/// +/// This is inlined so that the comptime checks will disable the +/// runtime checks if the comptime checks fail. +pub inline fn atLeast( + comptime major: u16, + comptime minor: u16, + comptime micro: u16, +) bool { + // If our header has lower versions than the given version, + // 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_MINOR_VERSION < minor or + c.GTK_MICRO_VERSION < micro) return false; + + // If we're in comptime then we can't check the runtime version. + if (@inComptime()) return true; + + // We use the functions instead of the constants such as + // c.GTK_MINOR_VERSION because the function gets the actual + // runtime version. + if (c.gtk_get_major_version() >= major) { + if (c.gtk_get_major_version() > major) return true; + if (c.gtk_get_minor_version() >= minor) { + if (c.gtk_get_minor_version() > minor) return true; + return c.gtk_get_micro_version() >= micro; + } + } + + return false; +}