From a85916f00f5ffae93e8b3c8b0ca7de784515fd8d Mon Sep 17 00:00:00 2001 From: foxnne Date: Thu, 12 Dec 2024 15:06:18 -0600 Subject: [PATCH] core: darwin: implement `cursor_mode` and `cursor_shape` updates --- src/Core.zig | 2 ++ src/core/Darwin.zig | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Core.zig b/src/Core.zig index 2803c624..d9d04536 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -56,6 +56,7 @@ windows: mach.Objects( /// Vertical sync mode, prevents screen tearing. vsync_mode: VSyncMode = .none, + /// Window display mode: fullscreen, windowed or borderless fullscreen display_mode: DisplayMode = .windowed, /// Cursor @@ -108,6 +109,7 @@ windows: mach.Objects( .render_attachment = true, }, + /// Container for native platform-specific information native: ?Platform.Native = null, }, ), diff --git a/src/core/Darwin.zig b/src/core/Darwin.zig index 058c54a6..7cf9926c 100644 --- a/src/core/Darwin.zig +++ b/src/core/Darwin.zig @@ -98,6 +98,31 @@ pub fn tick(core: *Core) !void { frame.size.height = @floatFromInt(core.windows.get(window_id, .height)); native_window.setFrame_display_animate(native_window.frameRectForContentRect(frame), true, true); } + + if (core.windows.updated(window_id, .cursor_mode)) { + switch (core_window.cursor_mode) { + .normal => objc.app_kit.Cursor.unhide(), + .disabled, .hidden => objc.app_kit.Cursor.hide(), + } + } + + if (core.windows.updated(window_id, .cursor_shape)) { + const Cursor = objc.app_kit.Cursor; + + Cursor.pop(); + + switch (core_window.cursor_shape) { + .arrow => Cursor.arrowCursor().push(), + .ibeam => Cursor.IBeamCursor().push(), + .crosshair => Cursor.crosshairCursor().push(), + .pointing_hand => Cursor.pointingHandCursor().push(), + .not_allowed => Cursor.operationNotAllowedCursor().push(), + .resize_ns => Cursor.resizeUpDownCursor().push(), + .resize_ew => Cursor.resizeLeftRightCursor().push(), + .resize_all => Cursor.closedHandCursor().push(), + else => std.log.warn("Unsupported cursor", .{}), + } + } } else { try initWindow(core, window_id); }