[vlc-commits] macosx: lock the scroll direction for 0.8 secs, so the user can scroll through the movie or adjust the volume without affecting the other function (close #6893)

Felix Paul Kühne git at videolan.org
Mon May 28 19:58:54 CEST 2012


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon May 28 19:35:09 2012 +0200| [d751400813e0717d30d35da639cd9de32cb8c544] | committer: Felix Paul Kühne

macosx: lock the scroll direction for 0.8 secs, so the user can scroll through the movie or adjust the volume without affecting the other function (close #6893)

This is especially needed for the multitouch trackpads
(cherry picked from commit d34619d34cc2e93c02f66dd04b41f74a6ec4eeed)

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

 modules/gui/macosx/controls.h |    3 +++
 modules/gui/macosx/controls.m |   46 ++++++++++++++++++++++++++++++++++-------
 2 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/modules/gui/macosx/controls.h b/modules/gui/macosx/controls.h
index 8797a0c..4488bc3 100644
--- a/modules/gui/macosx/controls.h
+++ b/modules/gui/macosx/controls.h
@@ -39,6 +39,9 @@
     IBOutlet id o_specificTime_sec_lbl;
     IBOutlet id o_specificTime_stepper;
     IBOutlet id o_specificTime_mi;
+
+    NSInteger i_lastScrollWheelDirection;
+    NSTimeInterval t_lastScrollEvent;
 }
 - (IBAction)play:(id)sender;
 - (IBAction)stop:(id)sender;
diff --git a/modules/gui/macosx/controls.m b/modules/gui/macosx/controls.m
index 1570401..ba6d9a0 100644
--- a/modules/gui/macosx/controls.m
+++ b/modules/gui/macosx/controls.m
@@ -54,6 +54,8 @@
     [o_specificTime_ok_btn setTitle: _NS("OK")];
     [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
     [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
+
+    i_lastScrollWheelDirection = 0;
 }
 
 
@@ -254,6 +256,13 @@
     vlc_object_release( p_input );
 }
 
+- (void)resetScrollWheelDirection
+{
+    /* release the scroll direction 0.8 secs after the last event */
+    if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80)
+        i_lastScrollWheelDirection = 0;
+}
+
 - (void)scrollWheel:(NSEvent *)theEvent
 {
     intf_thread_t * p_intf = VLCIntf;
@@ -271,7 +280,8 @@
 
     CGFloat f_yabsvalue = f_deltaY > 0.0f ? f_deltaY : -f_deltaY;
     CGFloat f_xabsvalue = f_deltaX > 0.0f ? f_deltaX : -f_deltaX;
-    int i_yvlckey, i_xvlckey;
+
+    int i_yvlckey, i_xvlckey = 0;
 
     if (b_invertedEventFromDevice)
     {
@@ -298,15 +308,37 @@
             i_xvlckey = KEY_MOUSEWHEELLEFT;
     }
 
-    /* Send multiple key event, depending on the intensity of the event */
-    for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
-        var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
+    /* 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 (i_lastScrollWheelDirection < 0) // last was a X
+            return;
 
-    /* Prioritize Y event (sound volume) over X event */
-    if (f_yabsvalue < 0.05)
+        i_lastScrollWheelDirection = 1; // Y
+        for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
+            var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
+
+        t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
+        [self performSelector:@selector(resetScrollWheelDirection)
+                   withObject: NULL
+                   afterDelay:1.00];
+        return;
+    }
+    if (f_xabsvalue > 0.05)
     {
+        if (i_lastScrollWheelDirection > 0) // last was a Y
+            return;
+
+        i_lastScrollWheelDirection = -1; // X
         for (NSUInteger i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
-         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
+            var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
+
+        t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
+        [self performSelector:@selector(resetScrollWheelDirection)
+                   withObject: NULL
+                   afterDelay:1.00];
     }
 }
 



More information about the vlc-commits mailing list