[vlc-commits] macosx: Reset scrolling direction with timer, decrease timeout

David Fuhrmann git at videolan.org
Sat Sep 17 21:01:29 CEST 2016


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Sep 17 20:59:41 2016 +0200| [a3005d3db8c57592d2dc6b907e693875e0f03c27] | committer: David Fuhrmann

macosx: Reset scrolling direction with timer, decrease timeout

Reset the fixed scrolling direction with a timer and decrease
timeout to 0.4 seconds. This makes switching between horizontal
scrolling and vertical scrolling a bit easier.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a3005d3db8c57592d2dc6b907e693875e0f03c27
---

 modules/gui/macosx/VLCVoutView.m | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/modules/gui/macosx/VLCVoutView.m b/modules/gui/macosx/VLCVoutView.m
index 1689ed0..ef8d33d 100644
--- a/modules/gui/macosx/VLCVoutView.m
+++ b/modules/gui/macosx/VLCVoutView.m
@@ -47,8 +47,8 @@
  *****************************************************************************/
 @interface VLCVoutView()
 {
+    NSTimer *p_scrollTimer;
     NSInteger i_lastScrollWheelDirection;
-    NSTimeInterval t_lastScrollEvent;
 
     CGFloat f_cumulatedXScrollValue;
     CGFloat f_cumulatedYScrollValue;
@@ -230,11 +230,9 @@
 
 - (void)resetScrollWheelDirection
 {
-    /* release the scroll direction 0.8 secs after the last event */
-    if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80) {
-        i_lastScrollWheelDirection = 0;
-        f_cumulatedXScrollValue = f_cumulatedYScrollValue = 0.;
-    }
+    i_lastScrollWheelDirection = 0;
+    f_cumulatedXScrollValue = f_cumulatedYScrollValue = 0.;
+    msg_Dbg(getIntf(), "Reset scrolling timer");
 }
 
 - (void)scrollWheel:(NSEvent *)theEvent
@@ -266,7 +264,7 @@
 
     /* 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 */
+    /* the opposite direction is being blocked for a couple of milli seconds */
     if (f_deltaYAbs > f_directionThreshold) {
         if (i_lastScrollWheelDirection < 0) // last was a X
             return;
@@ -281,13 +279,7 @@
             msg_Dbg(p_intf, "Scrolling in y direction");
         }
 
-        t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
-        [self performSelector:@selector(resetScrollWheelDirection)
-                   withObject: NULL
-                   afterDelay:1.00];
-        return;
-    }
-    if (f_deltaXAbs > f_directionThreshold) {
+    } else if (f_deltaXAbs > f_directionThreshold) {
         if (i_lastScrollWheelDirection > 0) // last was a Y
             return;
         i_lastScrollWheelDirection = -1; // X
@@ -300,12 +292,13 @@
             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)
-                   withObject: NULL
-                   afterDelay:1.00];
+    if (p_scrollTimer) {
+        [p_scrollTimer invalidate];
+        p_scrollTimer = nil;
     }
+    p_scrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(resetScrollWheelDirection) userInfo:nil repeats:NO];
 }
 
 #pragma mark -



More information about the vlc-commits mailing list