From: José Expósito Date: Mon, 17 Oct 2022 17:10:37 +0000 (+0200) Subject: gtkeventcontrollerscroll: Send lores scroll in the middle of the detent X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~3^2~1^2~22 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2092d21bad455cea8f3a440dd6a23113f63f53a0;p=gtk4.git 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 --- 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; }