Commit 3eb0885f authored by David Fuhrmann's avatar David Fuhrmann

macosx: Refine scroll wheel event forwarding

Starting with Sierra, the platform emits more fine granular
scrolling events than before. Now, the deltas from each event
are accumulated and forwarded after they reach a certain threshold.

close #17349
parent 4894beeb
......@@ -50,6 +50,9 @@
NSInteger i_lastScrollWheelDirection;
NSTimeInterval t_lastScrollEvent;
CGFloat f_cumulatedXScrollValue;
CGFloat f_cumulatedYScrollValue;
CGFloat f_cumulated_magnification;
vout_thread_t *p_vout;
......@@ -228,12 +231,18 @@
- (void)resetScrollWheelDirection
{
/* release the scroll direction 0.8 secs after the last event */
if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80)
if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80) {
i_lastScrollWheelDirection = 0;
f_cumulatedXScrollValue = f_cumulatedYScrollValue = 0.;
}
}
- (void)scrollWheel:(NSEvent *)theEvent
{
const CGFloat f_xThreshold = 0.8;
const CGFloat f_yThreshold = 1.0;
const CGFloat f_directionThreshold = 0.05;
intf_thread_t * p_intf = getIntf();
CGFloat f_deltaX = [theEvent deltaX];
CGFloat f_deltaY = [theEvent deltaY];
......@@ -243,30 +252,34 @@
f_deltaY = -f_deltaY;
}
CGFloat f_yabsvalue = f_deltaY > 0.0f ? f_deltaY : -f_deltaY;
CGFloat f_xabsvalue = f_deltaX > 0.0f ? f_deltaX : -f_deltaX;
CGFloat f_deltaXAbs = ABS(f_deltaX);
CGFloat f_deltaYAbs = ABS(f_deltaY);
int i_yvlckey, i_xvlckey = 0;
if (f_deltaY < 0.0f)
i_yvlckey = KEY_MOUSEWHEELDOWN;
else
i_yvlckey = KEY_MOUSEWHEELUP;
// A mouse scroll wheel has lower sensitivity. We want to scroll at least
// with every event here.
BOOL isMouseScrollWheel = ([theEvent subtype] == NSEventSubtypeMouseEvent);
if (isMouseScrollWheel && f_deltaYAbs < f_yThreshold)
f_deltaY = f_deltaY > 0. ? f_yThreshold : -f_yThreshold;
if (f_deltaX < 0.0f)
i_xvlckey = KEY_MOUSEWHEELRIGHT;
else
i_xvlckey = KEY_MOUSEWHEELLEFT;
if (isMouseScrollWheel && f_deltaXAbs < f_xThreshold)
f_deltaX = f_deltaX > 0. ? f_xThreshold : -f_xThreshold;
/* in the following, we're forwarding either a x or a y event */
/* Multiple key events are send depending on the intensity of the event */
/* the opposite direction is being blocked for 0.8 secs */
if (f_yabsvalue > 0.05) {
if (f_deltaYAbs > f_directionThreshold) {
if (i_lastScrollWheelDirection < 0) // last was a X
return;
i_lastScrollWheelDirection = 1; // Y
for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.); i++)
var_SetInteger(p_intf->obj.libvlc, "key-pressed", i_yvlckey);
f_cumulatedYScrollValue += f_deltaY;
int key = f_cumulatedYScrollValue < 0.0f ? KEY_MOUSEWHEELDOWN : KEY_MOUSEWHEELUP;
while (ABS(f_cumulatedYScrollValue) >= f_yThreshold) {
f_cumulatedYScrollValue -= (f_cumulatedYScrollValue > 0 ? f_yThreshold : -f_yThreshold);
var_SetInteger(p_intf->obj.libvlc, "key-pressed", key);
msg_Dbg(p_intf, "Scrolling in y direction");
}
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
......@@ -274,13 +287,19 @@
afterDelay:1.00];
return;
}
if (f_xabsvalue > 0.05) {
if (f_deltaXAbs > f_directionThreshold) {
if (i_lastScrollWheelDirection > 0) // last was a Y
return;
i_lastScrollWheelDirection = -1; // X
for (NSUInteger i = 0; i < (int)(f_xabsvalue/6.+1.); i++)
var_SetInteger(p_intf->obj.libvlc, "key-pressed", i_xvlckey);
f_cumulatedXScrollValue += f_deltaX;
int key = f_cumulatedXScrollValue < 0.0f ? KEY_MOUSEWHEELRIGHT : KEY_MOUSEWHEELLEFT;
while (ABS(f_cumulatedXScrollValue) >= f_xThreshold) {
f_cumulatedXScrollValue -= (f_cumulatedXScrollValue > 0 ? f_xThreshold : -f_xThreshold);
var_SetInteger(p_intf->obj.libvlc, "key-pressed", key);
msg_Dbg(p_intf, "Scrolling in x direction");
}
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment