diff --git a/src/Window.zig b/src/Window.zig index 56fc7697e..3018f2602 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -29,6 +29,7 @@ const Config = @import("config.zig").Config; const input = @import("input.zig"); const DevMode = @import("DevMode.zig"); const App = @import("App.zig"); +const internal_os = @import("os/main.zig"); // Get native API access on certain platforms so we can do more customization. const glfwNative = glfw.Native(.{ @@ -333,7 +334,12 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window { // Create the cursor const cursor = try glfw.Cursor.createStandard(.ibeam); errdefer cursor.destroy(); - try window.setCursor(cursor); + if ((comptime !builtin.target.isDarwin()) or internal_os.macosVersionAtLeast(13, 0, 0)) { + // We only set our cursor if we're NOT on Mac, or if we are then the + // macOS version is >= 13 (Ventura). On prior versions, glfw crashes + // since we use a tab group. + try window.setCursor(cursor); + } // The mutex used to protect our renderer state. var mutex = try alloc.create(std.Thread.Mutex); diff --git a/src/os/macos_version.zig b/src/os/macos_version.zig new file mode 100644 index 000000000..575dd2b72 --- /dev/null +++ b/src/os/macos_version.zig @@ -0,0 +1,21 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const assert = std.debug.assert; +const objc = @import("objc"); + +/// Verifies that the running macOS system version is at least the given version. +pub fn macosVersionAtLeast(major: i64, minor: i64, patch: i64) bool { + assert(builtin.target.isDarwin()); + + const NSProcessInfo = objc.Class.getClass("NSProcessInfo").?; + const info = NSProcessInfo.msgSend(objc.Object, objc.sel("processInfo"), .{}); + return info.msgSend(bool, objc.sel("isOperatingSystemAtLeastVersion:"), .{ + NSOperatingSystemVersion{ .major = major, .minor = minor, .patch = patch }, + }); +} + +pub const NSOperatingSystemVersion = extern struct { + major: i64, + minor: i64, + patch: i64, +}; diff --git a/src/os/main.zig b/src/os/main.zig index a11fad9e3..38f90133f 100644 --- a/src/os/main.zig +++ b/src/os/main.zig @@ -3,3 +3,4 @@ pub usingnamespace @import("file.zig"); pub usingnamespace @import("locale.zig"); +pub usingnamespace @import("macos_version.zig");