From 5206933399775e5ff46baefbbb3a776c2a9bb84c Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Mon, 12 Oct 2026 10:53:22 +0300 Subject: feat: add type-safe native platform headers and portable drag support - Add include/yasl/native/{wayland,cocoa,x11}.h with type-safe handle accessors. - Unify drag-and-drop and window carry support across Wayland, X11, and Cocoa. - Preserve full ABI compatibility for capability flags. - Install native headers conditionally based on enabled backend. - Include missing tablet example and backend test suites. --- tests/cocoa/test_cursor.m | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/cocoa/test_cursor.m (limited to 'tests/cocoa/test_cursor.m') diff --git a/tests/cocoa/test_cursor.m b/tests/cocoa/test_cursor.m new file mode 100644 index 0000000..0f3ba06 --- /dev/null +++ b/tests/cocoa/test_cursor.m @@ -0,0 +1,53 @@ +#import +#include +#include + +static void assert_transparent(NSCursor *cursor) +{ + assert(cursor); + NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithData:cursor.image.TIFFRepresentation]; + assert(bitmap && bitmap.hasAlpha); + for (NSInteger y = 0; y < bitmap.pixelsHigh; y++) + for (NSInteger x = 0; x < bitmap.pixelsWide; x++) + assert([bitmap colorAtX:x y:y].alphaComponent == 0); +} + +int main(void) +{ + @autoreleasepool { + struct yasl_display *display = yasl_display_open(NULL, NULL); + assert(display); + struct yasl_surface_spec spec = {.title = "Cursor test", .size = {320, 240}}; + struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec); + assert(surface); + NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); + NSView *view = window.contentView; + yasl_surface_set_cursor(surface, YASL_CURSOR_HIDDEN); + [view cursorUpdate:nil]; + NSCursor *hidden = [NSCursor currentCursor]; + assert_transparent(hidden); + + NSEvent *motion = [NSEvent mouseEventWithType:NSEventTypeMouseMoved + location:NSMakePoint(100, 120) modifierFlags:0 timestamp:0 + windowNumber:window.windowNumber context:nil eventNumber:0 clickCount:0 pressure:0]; + [view mouseMoved:motion]; + [view cursorUpdate:nil]; + assert([NSCursor currentCursor] == hidden); + struct yasl_input_event event; + bool moved = false; + while (yasl_surface_input_poll(surface, &event)) + if (event.kind == YASL_INPUT_MOUSE && event.mouse.kind == YASL_PTR_MOTION) + moved = true; + assert(moved); + + [[NSCursor arrowCursor] set]; /* Simulate leaving and re-entering. */ + [view cursorUpdate:nil]; + assert([NSCursor currentCursor] == hidden); + yasl_surface_set_cursor(surface, YASL_CURSOR_ARROW); + [view cursorUpdate:nil]; + assert([NSCursor currentCursor] == [NSCursor arrowCursor]); + yasl_surface_destroy(surface); + yasl_display_close(display); + } + return 0; +} -- cgit v1.2.3