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

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:59:41 2016 +0200| [52807c8c4eb88022c619e88dd13c7d8cb7007460] | 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.

(cherry picked from commit a3005d3db8c57592d2dc6b907e693875e0f03c27)
Signed-off-by: David Fuhrmann <dfuhrmann at videolan.org>

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

 modules/gui/macosx/VideoView.h |  4 ++--
 modules/gui/macosx/VideoView.m | 28 +++++++++++-----------------
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/modules/gui/macosx/VideoView.h b/modules/gui/macosx/VideoView.h
index 4e11ea2..0a119f5 100644
--- a/modules/gui/macosx/VideoView.h
+++ b/modules/gui/macosx/VideoView.h
@@ -28,14 +28,14 @@
 
 #import <vlc_vout.h>
 
-
 /*****************************************************************************
  * VLCVoutView interface
  *****************************************************************************/
 @interface VLCVoutView : NSView
 {
+    NSTimer *p_scrollTimer;
+
     NSInteger i_lastScrollWheelDirection;
-    NSTimeInterval t_lastScrollEvent;
 
     CGFloat f_cumulatedXScrollValue;
     CGFloat f_cumulatedYScrollValue;
diff --git a/modules/gui/macosx/VideoView.m b/modules/gui/macosx/VideoView.m
index 3029885..6cc583b 100644
--- a/modules/gui/macosx/VideoView.m
+++ b/modules/gui/macosx/VideoView.m
@@ -189,11 +189,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(VLCIntf, "Reset scrolling timer");
 }
 
 - (void)scrollWheel:(NSEvent *)theEvent
@@ -225,7 +223,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;
@@ -240,13 +238,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
@@ -259,12 +251,14 @@
             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)
-                   withObject: NULL
-                   afterDelay:1.00];
+    if (p_scrollTimer) {
+        [p_scrollTimer invalidate];
+        [p_scrollTimer release];
+        p_scrollTimer = nil;
     }
+    p_scrollTimer = [[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(resetScrollWheelDirection) userInfo:nil repeats:NO] retain];
 }
 
 #pragma mark -



More information about the vlc-commits mailing list