[vlc-devel] [PATCH] qt: support horizontal scroll

Maxim Sergeev gudvinr at gmail.com
Fri Apr 2 15:19:45 UTC 2021


Fixes #20498 for both 3.0 and 4.0

Tracking of horizontal scroll events was never implemented
but this setting present in configuration.

To avoid detection of erratic movements along the lines with angleDelta,
introduce allowance zone for each axis.
Angle determines how close to axis angleDelta is.
For horizontal events it is set to 30 degrees (15 for each side).
For vertical events angle is 53 degrees (30 * 16/9).
It is a little wider since touchpads are asymmetrical.

Following patch made for VLC 3.0 but qtWheelEventToVLCKey method can be 
included to VLC 4.0 tree as is.
In VLC 4.0 customwidgets.cpp located in modules/gui/qt/widgets/native/

---
diff --git a/modules/gui/qt/util/customwidgets.cpp 
b/modules/gui/qt/util/customwidgets.cpp
index 3879cc350b..f8d2acf5e3 100644
--- a/modules/gui/qt/util/customwidgets.cpp
+++ b/modules/gui/qt/util/customwidgets.cpp
@@ -31,6 +31,7 @@
  #include "customwidgets.hpp"
  #include "qt.hpp"               /* needed for qtr,  but not necessary */

+#include <QtMath>  // for scroll deadzone calculation
  #include <QPainter>
  #include <QRect>
  #include <QKeyEvent>
@@ -297,13 +298,28 @@ int qtEventToVLCKey( QKeyEvent *e )

  int qtWheelEventToVLCKey( QWheelEvent *e )
  {
-    int i_vlck = 0;
-    /* Handle modifiers */
-    i_vlck |= qtKeyModifiersToVLC( e );
-    if ( e->delta() > 0 )
-        i_vlck |= KEY_MOUSEWHEELUP;
-    else
-        i_vlck |= KEY_MOUSEWHEELDOWN;
+    const qreal v_cos_deadzone = 0.45; // ~63 degrees
+    const qreal h_cos_deadzone = 0.95; // ~15 degrees
+
+    int i_vlck = qtKeyModifiersToVLC(e);  // Handle modifiers
+
+    QPoint p = e->angleDelta();
+    if (!p.isNull())
+    {
+        qreal cos = qFabs(p.x())/qSqrt(qPow(p.x(), 2) + qPow(p.y(), 2));
+
+        if (cos < v_cos_deadzone)
+        {
+            if (p.y() > 0) i_vlck |= KEY_MOUSEWHEELUP;
+            else           i_vlck |= KEY_MOUSEWHEELDOWN;
+        }
+        else if (cos > h_cos_deadzone)
+        {
+            if (p.x() > 0) i_vlck |= KEY_MOUSEWHEELLEFT;
+            else           i_vlck |= KEY_MOUSEWHEELRIGHT;
+        }
+    }
+
      return i_vlck;
  }
---


More information about the vlc-devel mailing list