summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/platform/cocoa/window.m36
1 files changed, 26 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;