From 4c91e0213a3e7234c837ec54d6f17f28871fc586 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Wed, 14 Oct 2026 12:53:48 +0300 Subject: cocoa: fix --- src/platform/cocoa/window.m | 36 ++++++++++++++++++++++++++---------- tests/cocoa/test_tablet.m | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/platform/cocoa/window.m b/src/platform/cocoa/window.m index 4b97ce1..8f01365 100644 --- a/src/platform/cocoa/window.m +++ b/src/platform/cocoa/window.m @@ -469,6 +469,22 @@ static double event_double(NSEvent *event, const char *name) return ((double (*)(id, SEL))objc_msgSend)(event, selector); } +static NSEventSubtype tablet_subtype(NSEvent *ev) +{ + if (!ev) + return NSEventSubtypeMouseEvent; + switch (ev.type) { + case NSEventTypeLeftMouseDown: case NSEventTypeLeftMouseUp: + case NSEventTypeRightMouseDown: case NSEventTypeRightMouseUp: + case NSEventTypeOtherMouseDown: case NSEventTypeOtherMouseUp: + case NSEventTypeMouseMoved: case NSEventTypeLeftMouseDragged: + case NSEventTypeRightMouseDragged: case NSEventTypeOtherMouseDragged: + return ev.subtype; + default: + return NSEventSubtypeMouseEvent; + } +} + static void push_pen(struct cocoa_surface *w, NSEvent *event, unsigned action, bool contact) { if (!w || w->closed || w->tablet_device == YASL_PRIVATE_PTR_DEV_MOUSE) return; @@ -489,13 +505,13 @@ static void push_pen(struct cocoa_surface *w, NSEvent *event, unsigned action, b pen.x = point.x * scale; pen.y = (w->view.bounds.size.height - point.y) * scale; } - if (event.buttonMask & NSEventButtonMaskPenTip) - pen.buttons |= YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY); - if (event.buttonMask & NSEventButtonMaskPenLowerSide) - pen.buttons |= YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_SECONDARY); - if (event.buttonMask & NSEventButtonMaskPenUpperSide) - pen.buttons |= YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_MIDDLE); - if (event.type == NSEventTypeTabletPoint || event.subtype == NSEventSubtypeTabletPoint) { + if (event.type == NSEventTypeTabletPoint || tablet_subtype(event) == NSEventSubtypeTabletPoint) { + if (event.buttonMask & NSEventButtonMaskPenTip) + pen.buttons |= YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_PRIMARY); + if (event.buttonMask & NSEventButtonMaskPenLowerSide) + pen.buttons |= YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_SECONDARY); + if (event.buttonMask & NSEventButtonMaskPenUpperSide) + pen.buttons |= YASL_PRIVATE_BUTTON_BIT(YASL_PRIVATE_BUTTON_MIDDLE); pen.pressure = fmax(0.0, fmin(1.0, event.pressure)); pen.axes_valid |= YASL_PRIVATE_PEN_PRESSURE; pen.axes_changed |= YASL_PRIVATE_PEN_PRESSURE; @@ -558,7 +574,7 @@ static void push_pointer(struct cocoa_surface *w, NSEvent *ev, enum yasl_private (button < 0 || button > 4)) return; bool proximity = ev.type == NSEventTypeTabletProximity || - ev.subtype == NSEventSubtypeTabletProximity; + tablet_subtype(ev) == NSEventSubtypeTabletProximity; if (proximity) { if (ev.isEnteringProximity) { w->tablet_device = ev.pointingDeviceType == NSPointingDeviceTypeEraser ? @@ -582,7 +598,7 @@ static void push_pointer(struct cocoa_surface *w, NSEvent *ev, enum yasl_private if (type == YASL_PRIVATE_EVENT_POINTER_LEAVE && w->tablet_device != YASL_PRIVATE_PTR_DEV_MOUSE) { device = w->tablet_device; w->tablet_down = false; - } else if (ev.type == NSEventTypeTabletPoint || ev.subtype == NSEventSubtypeTabletPoint) { + } else if (ev.type == NSEventTypeTabletPoint || tablet_subtype(ev) == NSEventSubtypeTabletPoint) { /* pointingDeviceType belongs to proximity events. Remember that * event's tool so erasers and zero-pressure hover stay classified. */ device = w->tablet_device == YASL_PRIVATE_PTR_DEV_ERASER ? YASL_PRIVATE_PTR_DEV_ERASER : YASL_PRIVATE_PTR_DEV_PEN; @@ -621,7 +637,7 @@ static void push_pointer(struct cocoa_surface *w, NSEvent *ev, enum yasl_private input_queue_push(&w->input, &input_ev); if (type == YASL_PRIVATE_EVENT_POINTER_LEAVE && device != YASL_PRIVATE_PTR_DEV_MOUSE) { push_pen(w, ev, YASL_PRIVATE_PEN_LEAVE, false); - } else if (ev.type == NSEventTypeTabletPoint || ev.subtype == NSEventSubtypeTabletPoint) { + } else if (ev.type == NSEventTypeTabletPoint || tablet_subtype(ev) == NSEventSubtypeTabletPoint) { unsigned action = button == YASL_PRIVATE_BUTTON_PRIMARY && type == YASL_PRIVATE_EVENT_POINTER_DOWN ? YASL_PRIVATE_PEN_DOWN : button == YASL_PRIVATE_BUTTON_PRIMARY && type == YASL_PRIVATE_EVENT_POINTER_UP ? YASL_PRIVATE_PEN_UP : YASL_PRIVATE_PEN_MOVE; diff --git a/tests/cocoa/test_tablet.m b/tests/cocoa/test_tablet.m index 5cd7375..c13ee07 100644 --- a/tests/cocoa/test_tablet.m +++ b/tests/cocoa/test_tablet.m @@ -22,6 +22,32 @@ @end @implementation TabletSample +{ + NSEventSubtype _subtype; + NSUInteger _buttonMask; +} +- (NSEventSubtype)subtype +{ + assert(self.type == NSEventTypeLeftMouseDown || self.type == NSEventTypeLeftMouseUp || + self.type == NSEventTypeRightMouseDown || self.type == NSEventTypeRightMouseUp || + self.type == NSEventTypeOtherMouseDown || self.type == NSEventTypeOtherMouseUp || + self.type == NSEventTypeMouseMoved || self.type == NSEventTypeLeftMouseDragged || + self.type == NSEventTypeRightMouseDragged || self.type == NSEventTypeOtherMouseDragged); + return _subtype; +} +- (void)setSubtype:(NSEventSubtype)subtype +{ + _subtype = subtype; +} +- (NSUInteger)buttonMask +{ + assert(self.type == NSEventTypeTabletPoint || self.subtype == NSEventSubtypeTabletPoint); + return _buttonMask; +} +- (void)setButtonMask:(NSUInteger)buttonMask +{ + _buttonMask = buttonMask; +} - (float)pressure { assert(self.type == NSEventTypeTabletPoint || self.subtype == NSEventSubtypeTabletPoint); @@ -160,6 +186,10 @@ int main(void) [view mouseMoved:native]; ev = next(surface, YASL_PRIVATE_EVENT_POINTER_MOTION); assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_MOUSE && !ev.pointer.pen.pressure); + sample.type = NSEventTypeMouseExited; + [view mouseExited:native]; + ev = next(surface, YASL_PRIVATE_EVENT_POINTER_LEAVE); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_MOUSE && ev.type == YASL_PRIVATE_EVENT_POINTER_LEAVE); [sample release]; yasl_private_surface_destroy(surface); yasl_private_display_close(display); -- cgit v1.2.3