core: darwin: implement cursor_mode and cursor_shape updates

This commit is contained in:
foxnne 2024-12-12 15:06:18 -06:00 committed by Emi Gutekanst
parent 60a68a7453
commit a85916f00f
2 changed files with 27 additions and 0 deletions

View file

@ -56,6 +56,7 @@ windows: mach.Objects(
/// Vertical sync mode, prevents screen tearing. /// Vertical sync mode, prevents screen tearing.
vsync_mode: VSyncMode = .none, vsync_mode: VSyncMode = .none,
/// Window display mode: fullscreen, windowed or borderless fullscreen
display_mode: DisplayMode = .windowed, display_mode: DisplayMode = .windowed,
/// Cursor /// Cursor
@ -108,6 +109,7 @@ windows: mach.Objects(
.render_attachment = true, .render_attachment = true,
}, },
/// Container for native platform-specific information
native: ?Platform.Native = null, native: ?Platform.Native = null,
}, },
), ),

View file

@ -98,6 +98,31 @@ pub fn tick(core: *Core) !void {
frame.size.height = @floatFromInt(core.windows.get(window_id, .height)); frame.size.height = @floatFromInt(core.windows.get(window_id, .height));
native_window.setFrame_display_animate(native_window.frameRectForContentRect(frame), true, true); 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 { } else {
try initWindow(core, window_id); try initWindow(core, window_id);
} }