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
This commit is contained in:
José Expósito 2022-10-17 19:10:37 +02:00 committed by Carlos Garnacho
parent 2f584c16f0
commit e61938793a

View 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;
}