gtkeventcontrollerscroll: Send lores scroll in the middle of the detent
authorJosé Expósito <jose.exposito89@gmail.com>
Mon, 17 Oct 2022 17:10:37 +0000 (19:10 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 5 Jun 2023 11:57:52 +0000 (07:57 -0400)
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.

Related to https://gitlab.gnome.org/GNOME/mutter/-/issues/2469

gtk/gtkeventcontrollerscroll.c

index 6d1e8734e9b0debbd7e741c8ee591cac4a452055..4e006de310510c37fbf63d1974b08d80f4bb6e34 100644 (file)
@@ -410,16 +410,22 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller,
             }
           else
             {
-              if (ABS (scroll->cur_dx) >= 1)
+              if (ABS (scroll->cur_dx) >= 0.5)
                 {
                   steps = trunc (scroll->cur_dx);
+                  if (steps == 0)
+                    steps = (scroll->cur_dx > 0) ? 1 : -1;
+
                   scroll->cur_dx -= steps;
                   dx = steps;
                 }
 
-              if (ABS (scroll->cur_dy) >= 1)
+              if (ABS (scroll->cur_dy) >= 0.5)
                 {
                   steps = trunc (scroll->cur_dy);
+                  if (steps == 0)
+                    steps = (scroll->cur_dy > 0) ? 1 : -1;
+
                   scroll->cur_dy -= steps;
                   dy = steps;
                 }
@@ -459,16 +465,22 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller,
           scroll->cur_dy += dy;
           dx = dy = 0;
 
-          if (ABS (scroll->cur_dx) >= 1)
+          if (ABS (scroll->cur_dx) >= 0.5)
             {
               steps = trunc (scroll->cur_dx);
+              if (steps == 0)
+                steps = (scroll->cur_dx > 0) ? 1 : -1;
+
               scroll->cur_dx -= steps;
               dx = steps;
             }
 
-          if (ABS (scroll->cur_dy) >= 1)
+          if (ABS (scroll->cur_dy) >= 0.5)
             {
               steps = trunc (scroll->cur_dy);
+              if (steps == 0)
+                steps = (scroll->cur_dy > 0) ? 1 : -1;
+
               scroll->cur_dy -= steps;
               dy = steps;
             }