[vlc-commits] macosx: Swiping on time slider enabled

Daksh Shah git at videolan.org
Sun Mar 18 22:05:54 CET 2018


vlc/vlc-3.0 | branch: master | Daksh Shah <daksh17336 at iiitd.ac.in> | Sun Mar 11 10:01:57 2018 +0530| [714736846af72e8b704b7752f262cb708f6136df] | committer: Jean-Baptiste Kempf

macosx: Swiping on time slider enabled

Fixes #19964

Signed-off-by: Marvin Scholz <epirat07 at gmail.com>
(cherry picked from commit ed832e6bdb5873a811028613d0ad8b4e43d31936)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/gui/macosx/VLCControlsBarCommon.m |  3 +++
 modules/gui/macosx/VLCSlider.h            |  3 +++
 modules/gui/macosx/VLCSlider.m            | 26 ++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/modules/gui/macosx/VLCControlsBarCommon.m b/modules/gui/macosx/VLCControlsBarCommon.m
index 61942fe03f..04a0105792 100644
--- a/modules/gui/macosx/VLCControlsBarCommon.m
+++ b/modules/gui/macosx/VLCControlsBarCommon.m
@@ -276,6 +276,9 @@
         case NSLeftMouseDragged:
             f_updated = [sender floatValue];
             break;
+        case NSScrollWheel:
+            f_updated = [sender floatValue];
+            break;
 
         default:
             return;
diff --git a/modules/gui/macosx/VLCSlider.h b/modules/gui/macosx/VLCSlider.h
index ba95b63ab0..36e8659c8c 100644
--- a/modules/gui/macosx/VLCSlider.h
+++ b/modules/gui/macosx/VLCSlider.h
@@ -28,6 +28,9 @@
 @property (nonatomic, getter=getIndefinite,setter=setIndefinite:) BOOL indefinite;
 @property (nonatomic, getter=getKnobHidden,setter=setKnobHidden:) BOOL isKnobHidden;
 
+/* Indicates if the slider is scrollable with the mouse or trackpad scrollwheel. */
+ at property (readwrite) BOOL isScrollable;
+
 - (void)setSliderStyleLight;
 - (void)setSliderStyleDark;
 
diff --git a/modules/gui/macosx/VLCSlider.m b/modules/gui/macosx/VLCSlider.m
index 245c4faab0..b89d2c3f0d 100644
--- a/modules/gui/macosx/VLCSlider.m
+++ b/modules/gui/macosx/VLCSlider.m
@@ -33,6 +33,7 @@
     if (self) {
         NSAssert([self.cell isKindOfClass:[VLCSliderCell class]],
                  @"VLCSlider cell is not VLCSliderCell");
+        _isScrollable = YES;
     }
     return self;
 }
@@ -42,6 +43,31 @@
     return [VLCSliderCell class];
 }
 
+- (void)scrollWheel:(NSEvent *)event
+{
+    if (!_isScrollable)
+        return [super scrollWheel:event];
+    double increment;
+    CGFloat deltaY = [event scrollingDeltaY];
+    double range = [self maxValue] - [self minValue];
+
+    // Scroll less for high precision, else it's too fast
+    if (event.hasPreciseScrollingDeltas) {
+        increment = (range * 0.002) * deltaY;
+    } else {
+        if (deltaY == 0.0)
+            return;
+        increment = (range * 0.01 * deltaY);
+    }
+
+    // If scrolling is inversed, increment in other direction
+    if (!event.isDirectionInvertedFromDevice)
+        increment = -increment;
+
+    [self setDoubleValue:self.doubleValue - increment];
+    [self sendAction:self.action to:self.target];
+}
+
 // Workaround for 10.7
 // http://stackoverflow.com/questions/3985816/custom-nsslidercell
 - (void)setNeedsDisplayInRect:(NSRect)invalidRect {



More information about the vlc-commits mailing list