mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
apprt/gtk: add version helpers
This adds version helpers similar to the adwaita version helpers so that build time and runtime version checks can be done.
This commit is contained in:
@ -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
|
||||
|
40
src/apprt/gtk/version.zig
Normal file
40
src/apprt/gtk/version.zig
Normal file
@ -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;
|
||||
}
|
Reference in New Issue
Block a user