[vlc-commits] macosx: Refine scroll wheel event forwarding
David Fuhrmann
git at videolan.org
Mon Sep 26 23:14:15 CEST 2016
vlc/vlc-2.2 | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Sep 17 20:43:51 2016 +0200| [f318ffc4480153b7b8b75947ca95f1d03a597965] | committer: 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
(cherry picked from commit 3eb0885f611df44e6ed336920bbe7e011a10c589)
(cherry picked from commit 64a447df3f02f2e5628498ff2c01116174cd042f)
Signed-off-by: David Fuhrmann <dfuhrmann at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=f318ffc4480153b7b8b75947ca95f1d03a597965
---
modules/gui/macosx/VideoView.h | 3 +++
modules/gui/macosx/VideoView.m | 56 +++++++++++++++++++++++++++---------------
2 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/modules/gui/macosx/VideoView.h b/modules/gui/macosx/VideoView.h
index 3ba9e05..4e11ea2 100644
--- a/modules/gui/macosx/VideoView.h
+++ b/modules/gui/macosx/VideoView.h
@@ -37,6 +37,9 @@
NSInteger i_lastScrollWheelDirection;
NSTimeInterval t_lastScrollEvent;
+ CGFloat f_cumulatedXScrollValue;
+ CGFloat f_cumulatedYScrollValue;
+
CGFloat f_cumulated_magnification;
vout_thread_t *p_vout;
diff --git a/modules/gui/macosx/VideoView.m b/modules/gui/macosx/VideoView.m
index c02e449..3029885 100644
--- a/modules/gui/macosx/VideoView.m
+++ b/modules/gui/macosx/VideoView.m
@@ -190,12 +190,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 = VLCIntf;
CGFloat f_deltaX = [theEvent deltaX];
CGFloat f_deltaY = [theEvent deltaY];
@@ -205,30 +211,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] == NSMouseEventSubtype);
+ 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->p_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->p_libvlc, "key-pressed", key);
+ msg_Dbg(p_intf, "Scrolling in y direction");
+ }
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
@@ -236,13 +246,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->p_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->p_libvlc, "key-pressed", key);
+ msg_Dbg(p_intf, "Scrolling in x direction");
+ }
t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
[self performSelector:@selector(resetScrollWheelDirection)
More information about the vlc-commits
mailing list