[mutter] backends/native: Send lores scroll in the middle of the detent



commit 5fa1a8cf42182b6348c0fcf1aca47c1ceded4a7a
Author: José Expósito <jose exposito89 gmail com>
Date:   Mon Oct 17 18:56:29 2022 +0200

    backends/native: Send lores scroll in the middle of the detent
    
    Some mice send a value slightly lower than 120 for some detents. The
    current approach waits until a value of 120 is reached before sending a
    low-resolution scroll event.
    
    For example, the MX Master 3 sends a value of 112 in some detents:
    
                  detent                   detent
        |                        |                       |
                            ^    ^                    ^
                            112  REL_WHEEL            224
    
    As illustrated, only one event was sent but two were expected. However,
    sending the low-resolution scroll event in the middle plus the existing
    heuristics to reset the accumulator solve this issue:
    
                  detent                   detent
        |                        |                       |
                    ^          ^             ^          ^
                    REL_WHEEL  112           REL_WHEEL  224
    
    Send low-resolution scroll events in the middle of the detent to solve
    this problem.
    
    Fix https://gitlab.gnome.org/GNOME/mutter/-/issues/2469
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2668>

 src/backends/native/meta-seat-impl.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
index def778eb5a..d8b5610d1a 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -916,7 +916,7 @@ meta_seat_impl_notify_discrete_scroll_in_impl (MetaSeatImpl        *seat_impl,
 {
   MetaInputDeviceNative *evdev_device;
   double dx = 0, dy = 0;
-  int discrete_dx = 0, discrete_dy = 0;
+  int low_res_value = 0;
 
   /* Convert into DISCRETE_SCROLL_STEP range. 120/DISCRETE_SCROLL_STEP = 12.0 */
   dx = dx_value120 / 12.0;
@@ -949,23 +949,29 @@ meta_seat_impl_notify_discrete_scroll_in_impl (MetaSeatImpl        *seat_impl,
 
   evdev_device->value120.acc_dx += dx_value120;
   evdev_device->value120.acc_dy += dy_value120;
-  discrete_dx = (evdev_device->value120.acc_dx / 120);
-  discrete_dy = (evdev_device->value120.acc_dy / 120);
 
-  if (discrete_dx != 0)
+  if (abs (evdev_device->value120.acc_dx) >= 60)
     {
-      evdev_device->value120.acc_dx -= (discrete_dx * 120);
+      low_res_value = (evdev_device->value120.acc_dx / 120);
+      if (low_res_value == 0)
+        low_res_value = (dx_value120 > 0) ? 1 : -1;
+
       notify_discrete_scroll (input_device, time_us,
-                              discrete_to_direction (discrete_dx, 0),
+                              discrete_to_direction (low_res_value, 0),
                               scroll_source, FALSE);
+      evdev_device->value120.acc_dx -= (low_res_value * 120);
     }
 
-  if (discrete_dy != 0)
+  if (abs (evdev_device->value120.acc_dy) >= 60)
     {
-      evdev_device->value120.acc_dy -= (discrete_dy * 120);
+      low_res_value = (evdev_device->value120.acc_dy / 120);
+      if (low_res_value == 0)
+        low_res_value = (dy_value120 > 0) ? 1 : -1;
+
       notify_discrete_scroll (input_device, time_us,
-                              discrete_to_direction (0, discrete_dy),
+                              discrete_to_direction (0, low_res_value),
                               scroll_source, FALSE);
+      evdev_device->value120.acc_dy -= (low_res_value * 120);
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]