Skip to content

Commit e2b95b2

Browse files
committed
Revert "HID: input: simplify/fix high-res scroll event handling"
This reverts commit 044ee89. It turns out the current API is not that compatible with some Microsoft mice, so better start again from scratch. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Harry Cutts <hcutts@chromium.org> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Jiri Kosina <jkosina@suse.cz>
1 parent fb862c3 commit e2b95b2

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

drivers/hid/hid-input.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,30 +1858,31 @@ EXPORT_SYMBOL_GPL(hidinput_disconnect);
18581858
void hid_scroll_counter_handle_scroll(struct hid_scroll_counter *counter,
18591859
int hi_res_value)
18601860
{
1861-
int low_res_value, remainder, multiplier;
1861+
int low_res_scroll_amount;
1862+
/* Some wheels will rest 7/8ths of a notch from the previous notch
1863+
* after slow movement, so we want the threshold for low-res events to
1864+
* be in the middle of the notches (e.g. after 4/8ths) as opposed to on
1865+
* the notches themselves (8/8ths).
1866+
*/
1867+
int threshold = counter->resolution_multiplier / 2;
18621868

18631869
input_report_rel(counter->dev, REL_WHEEL_HI_RES,
18641870
hi_res_value * counter->microns_per_hi_res_unit);
18651871

1866-
/*
1867-
* Update the low-res remainder with the high-res value,
1868-
* but reset if the direction has changed.
1869-
*/
1870-
remainder = counter->remainder;
1871-
if ((remainder ^ hi_res_value) < 0)
1872-
remainder = 0;
1873-
remainder += hi_res_value;
1874-
1875-
/*
1876-
* Then just use the resolution multiplier to see if
1877-
* we should send a low-res (aka regular wheel) event.
1878-
*/
1879-
multiplier = counter->resolution_multiplier;
1880-
low_res_value = remainder / multiplier;
1881-
remainder -= low_res_value * multiplier;
1882-
counter->remainder = remainder;
1883-
1884-
if (low_res_value)
1885-
input_report_rel(counter->dev, REL_WHEEL, low_res_value);
1872+
counter->remainder += hi_res_value;
1873+
if (abs(counter->remainder) >= threshold) {
1874+
/* Add (or subtract) 1 because we want to trigger when the wheel
1875+
* is half-way to the next notch (i.e. scroll 1 notch after a
1876+
* 1/2 notch movement, 2 notches after a 1 1/2 notch movement,
1877+
* etc.).
1878+
*/
1879+
low_res_scroll_amount =
1880+
counter->remainder / counter->resolution_multiplier
1881+
+ (hi_res_value > 0 ? 1 : -1);
1882+
input_report_rel(counter->dev, REL_WHEEL,
1883+
low_res_scroll_amount);
1884+
counter->remainder -=
1885+
low_res_scroll_amount * counter->resolution_multiplier;
1886+
}
18861887
}
18871888
EXPORT_SYMBOL_GPL(hid_scroll_counter_handle_scroll);

0 commit comments

Comments
 (0)