From b726f1eb9060bf9abbd83a06298c557e25557612 Mon Sep 17 00:00:00 2001 From: Akemi Date: Wed, 26 Jul 2017 21:08:14 +0200 Subject: 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. --- video/out/cocoa/events_view.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/video/out/cocoa/events_view.m b/video/out/cocoa/events_view.m index b9b2bbb9b9..3162e5e9c9 100644 --- a/video/out/cocoa/events_view.m +++ b/video/out/cocoa/events_view.m @@ -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]; } } -- cgit v1.2.3