From 76073fe5fad8799e5850805f2f090af2cb62c741 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 23:41:31 +0300 Subject: Simplify the public event and CPU API Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 --- tests/cocoa/test_tablet.m | 111 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 33 deletions(-) (limited to 'tests/cocoa/test_tablet.m') diff --git a/tests/cocoa/test_tablet.m b/tests/cocoa/test_tablet.m index 715a66e..8eb63d5 100644 --- a/tests/cocoa/test_tablet.m +++ b/tests/cocoa/test_tablet.m @@ -1,5 +1,5 @@ #import -#include +#include #include /* A strict event double catches querying tablet-only properties on ordinary @@ -15,6 +15,10 @@ @property NSPointingDeviceType tool; @property float samplePressure; @property NSPoint sampleTilt; +@property double sampleRotation; +@property double sampleTangential; +@property NSInteger sampleDeviceID; +@property NSInteger sampleToolID; @end @implementation TabletSample @@ -33,70 +37,106 @@ assert(self.type == NSEventTypeTabletProximity || self.subtype == NSEventSubtypeTabletProximity); return self.tool; } +- (double)rotation { return self.sampleRotation; } +- (double)tangentialPressure { return self.sampleTangential; } +- (NSInteger)pointingDeviceID { return self.sampleDeviceID; } +- (NSInteger)pointingDeviceSerialNumber { return self.sampleToolID; } @end -static struct yasl_event next(struct yasl_surface *surface) +static struct yasl_private_event next(struct yasl_surface *surface, enum yasl_private_event_type type) { - struct yasl_event event; - while (yasl_surface_poll_event(surface, &event)) - return event; - assert(!"Expected a pointer event"); - return (struct yasl_event){0}; + struct yasl_private_event event; + assert(yasl_private_surface_poll_event(surface, &event)); + assert(event.type == type); + return event; } int main(void) { @autoreleasepool { - struct yasl_display *display = yasl_display_open(NULL, NULL); - assert(display && (yasl_display_caps(display) & YASL_CAP_TABLET)); - struct yasl_window_spec spec = {.title = "Tablet test", .size = {320, 240}}; - struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec); + struct yasl_private_display *display = yasl_private_display_open(NULL, NULL); + assert(display && (yasl_private_display_caps(display) & YASL_PRIVATE_CAP_TABLET)); + struct yasl_private_window_spec spec = {.title = "Tablet test", .size = {320, 240}}; + struct yasl_surface *surface = yasl_private_surface_create_toplevel(display, &spec); assert(surface); - NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); + NSWindow *window = (NSWindow *)yasl_private_surface_get_native_handle(surface); NSView *view = window.contentView; - struct yasl_event event; - while (yasl_surface_poll_event(surface, &event)) {} + struct yasl_private_event event; + while (yasl_private_surface_poll_event(surface, &event)) {} TabletSample *sample = [TabletSample new]; NSEvent *native = (NSEvent *)sample; sample.type = NSEventTypeTabletProximity; sample.enteringProximity = YES; sample.tool = NSPointingDeviceTypePen; + sample.sampleDeviceID = 17; + sample.sampleToolID = 29; [view tabletProximity:native]; sample.type = NSEventTypeMouseMoved; sample.subtype = NSEventSubtypeTabletPoint; sample.locationInWindow = NSMakePoint(100, 120); sample.sampleTilt = NSMakePoint(-0.5, 0.5); + sample.sampleRotation = 37.5; + sample.sampleTangential = -0.25; [view mouseMoved:native]; - struct yasl_event ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_PEN && ev.type == YASL_EVENT_POINTER_MOTION && !ev.pointer.pen.pressure); + struct yasl_private_event pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_ENTER && pen.pen.device_id == 17 && pen.pen.tool_id == 29); + struct yasl_private_event ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN && ev.type == YASL_PRIVATE_EVENT_POINTER_MOTION && !ev.pointer.pen.pressure); assert(ev.pointer.pen.tilt_x == -45 && ev.pointer.pen.tilt_y == -45); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_MOVE && pen.pen.device_id == 17 && pen.pen.tool_id == 29); + assert((pen.pen.axes_valid & (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)) == + (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)); + assert(pen.pen.rotation == 37.5 && pen.pen.tangential == -0.25); + assert((pen.pen.axes_valid & (YASL_PRIVATE_PEN_ROTATION | YASL_PRIVATE_PEN_TANGENTIAL)) == + (YASL_PRIVATE_PEN_ROTATION | YASL_PRIVATE_PEN_TANGENTIAL)); sample.type = NSEventTypeLeftMouseDown; sample.samplePressure = 0.5; + sample.buttonMask = NSEventButtonMaskPenTip; [view mouseDown:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_PEN && ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.button == YASL_BUTTON_PRIMARY); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_DOWN); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN && ev.type == YASL_PRIVATE_EVENT_POINTER_DOWN && ev.pointer.button == YASL_PRIVATE_BUTTON_PRIMARY); assert(ev.pointer.pen.pressure == 32767); - struct yasl_vector2i position = ev.pointer.pos; + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_DOWN && pen.pen.in_contact && pen.pen.pressure == 0.5); + assert(pen.pen.buttons == YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY)); + assert(pen.pen.changed_button == YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY)); + struct yasl_private_vector2i position = ev.pointer.pos; /* Native tablet events cover stationary pressure changes. */ sample.type = NSEventTypeTabletPoint; sample.subtype = NSEventSubtypeMouseEvent; sample.buttonMask = NSEventButtonMaskPenTip; sample.samplePressure = 1.5; [view tabletPoint:native]; - ev = next(surface); - assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); assert(ev.pointer.pos.x == position.x && ev.pointer.pos.y == position.y); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_MOVE && pen.pen.pressure == 1.0); + sample.buttonMask |= NSEventButtonMaskPenLowerSide; + [view tabletPoint:native]; + next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_BUTTON); + assert(pen.pen.buttons == (YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY) | + YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_SECONDARY))); + assert(pen.pen.changed_button == YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_SECONDARY)); + sample.buttonMask = NSEventButtonMaskPenTip; sample.samplePressure = 0; /* Zero does not release a held tip button. */ [view tabletPoint:native]; - assert(next(surface).type == YASL_EVENT_POINTER_MOTION); + assert(next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION).type == YASL_PRIVATE_EVENT_POINTER_MOTION); + next(surface, YASL_PRIVATE_EVENT_PEN); sample.buttonMask = 0; [view tabletPoint:native]; - ev = next(surface); - assert(ev.type == YASL_EVENT_POINTER_UP && !ev.pointer.pen.pressure && ev.pointer.device == YASL_PTR_DEV_PEN); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_UP); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_UP && !ev.pointer.pen.pressure && ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_UP && !pen.pen.in_contact && pen.pen.pressure == 0.0); sample.type = NSEventTypeTabletProximity; sample.enteringProximity = NO; [view tabletProximity:native]; - assert(next(surface).type == YASL_EVENT_POINTER_LEAVE); + assert(next(surface, YASL_PRIVATE_EVENT_POINTER_LEAVE).type == YASL_PRIVATE_EVENT_POINTER_LEAVE); + assert(next(surface, YASL_PRIVATE_EVENT_PEN).pen.action == YASL_PRIVATE_PEN_LEAVE); sample.enteringProximity = YES; sample.tool = NSPointingDeviceTypeEraser; [view tabletProximity:native]; @@ -104,20 +144,25 @@ int main(void) sample.samplePressure = 0.75; sample.buttonMask = NSEventButtonMaskPenTip; [view tabletPoint:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.pen.pressure > 0); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_ENTER && pen.pen.tool == 2); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_DOWN); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_ERASER && ev.type == YASL_PRIVATE_EVENT_POINTER_DOWN && ev.pointer.pen.pressure > 0); + pen = next(surface, YASL_PRIVATE_EVENT_PEN); + assert(pen.pen.action == YASL_PRIVATE_PEN_DOWN && pen.pen.tool == 2 && pen.pen.in_contact); sample.type = NSEventTypeTabletProximity; sample.enteringProximity = NO; [view tabletProximity:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.type == YASL_EVENT_POINTER_LEAVE && !ev.pointer.pen.pressure); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_LEAVE); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_ERASER && ev.type == YASL_PRIVATE_EVENT_POINTER_LEAVE && !ev.pointer.pen.pressure); + assert(next(surface, YASL_PRIVATE_EVENT_PEN).pen.action == YASL_PRIVATE_PEN_LEAVE); sample.type = NSEventTypeMouseMoved; [view mouseMoved:native]; - ev = next(surface); - assert(ev.pointer.device == YASL_PTR_DEV_MOUSE && !ev.pointer.pen.pressure); + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_MOUSE && !ev.pointer.pen.pressure); [sample release]; - yasl_surface_destroy(surface); - yasl_display_close(display); + yasl_private_surface_destroy(surface); + yasl_private_display_close(display); } return 0; } -- cgit v1.2.3