cocoa: distinguish between horizontal and vertical scroll

we need to switch the x and y deltas when Shift is being held because
macOS switches them around. otherwise we would get a horizontal scroll
on a vertical one and vice versa.

additional we switch from deltaX/Y to scrollingDeltaX/Y since the Apple
docs suggest it's the preferred way now. in my tests both reported the
same values on imprecise scrolls though.
This commit is contained in:
Akemi 2017-07-26 21:08:14 +02:00
parent 53188a14bf
commit b726f1eb90
1 changed files with 12 additions and 2 deletions

View File

@ -268,8 +268,18 @@
[self preciseScroll:event];
} else {
const int modifiers = [event modifierFlags];
const int mpkey = ([event deltaX] + [event deltaY]) > 0 ?
MP_MOUSE_BTN3 : MP_MOUSE_BTN4;
const float deltaX = (modifiers & NSEventModifierFlagShift) ?
[event scrollingDeltaY] : [event scrollingDeltaX];
const float deltaY = (modifiers & NSEventModifierFlagShift) ?
[event scrollingDeltaX] : [event scrollingDeltaY];
int mpkey;
if (fabs(deltaY) >= fabs(deltaX)) {
mpkey = deltaY > 0 ? MP_MOUSE_BTN3 : MP_MOUSE_BTN4;
} else {
mpkey = deltaX > 0 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6;
}
[self.adapter putKey:mpkey withModifiers:modifiers];
}
}