From e61938793a5e6a090d7e30ee0af0c4ed98b7d38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Mon, 17 Oct 2022 19:10:37 +0200 Subject: [PATCH] gtkeventcontrollerscroll: 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. Related to https://gitlab.gnome.org/GNOME/mutter/-/issues/2469 --- gtk/gtkeventcontrollerscroll.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gtk/gtkeventcontrollerscroll.c b/gtk/gtkeventcontrollerscroll.c index 6d1e8734e9..4e006de310 100644 --- a/gtk/gtkeventcontrollerscroll.c +++ b/gtk/gtkeventcontrollerscroll.c @@ -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; }