Skip to content

Commit 276e722

Browse files
author
Jiri Kosina
committed
Merge branch 'for-4.20/logitech-highres' into for-linus
High-resolution support for hid-logitech
2 parents 4e7be68 + d9ca1c9 commit 276e722

File tree

5 files changed

+383
-28
lines changed

5 files changed

+383
-28
lines changed

Documentation/input/event-codes.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,16 @@ A few EV_REL codes have special meanings:
190190
* REL_WHEEL, REL_HWHEEL:
191191

192192
- These codes are used for vertical and horizontal scroll wheels,
193-
respectively.
193+
respectively. The value is the number of "notches" moved on the wheel, the
194+
physical size of which varies by device. For high-resolution wheels (which
195+
report multiple events for each notch of movement, or do not have notches)
196+
this may be an approximation based on the high-resolution scroll events.
197+
198+
* REL_WHEEL_HI_RES:
199+
200+
- If a vertical scroll wheel supports high-resolution scrolling, this code
201+
will be emitted in addition to REL_WHEEL. The value is the (approximate)
202+
distance travelled by the user's finger, in microns.
194203

195204
EV_ABS
196205
------

drivers/hid/hid-input.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,3 +1838,48 @@ void hidinput_disconnect(struct hid_device *hid)
18381838
}
18391839
EXPORT_SYMBOL_GPL(hidinput_disconnect);
18401840

1841+
/**
1842+
* hid_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
1843+
* events given a high-resolution wheel
1844+
* movement.
1845+
* @counter: a hid_scroll_counter struct describing the wheel.
1846+
* @hi_res_value: the movement of the wheel, in the mouse's high-resolution
1847+
* units.
1848+
*
1849+
* Given a high-resolution movement, this function converts the movement into
1850+
* microns and emits high-resolution scroll events for the input device. It also
1851+
* uses the multiplier from &struct hid_scroll_counter to emit low-resolution
1852+
* scroll events when appropriate for backwards-compatibility with userspace
1853+
* input libraries.
1854+
*/
1855+
void hid_scroll_counter_handle_scroll(struct hid_scroll_counter *counter,
1856+
int hi_res_value)
1857+
{
1858+
int low_res_scroll_amount;
1859+
/* Some wheels will rest 7/8ths of a notch from the previous notch
1860+
* after slow movement, so we want the threshold for low-res events to
1861+
* be in the middle of the notches (e.g. after 4/8ths) as opposed to on
1862+
* the notches themselves (8/8ths).
1863+
*/
1864+
int threshold = counter->resolution_multiplier / 2;
1865+
1866+
input_report_rel(counter->dev, REL_WHEEL_HI_RES,
1867+
hi_res_value * counter->microns_per_hi_res_unit);
1868+
1869+
counter->remainder += hi_res_value;
1870+
if (abs(counter->remainder) >= threshold) {
1871+
/* Add (or subtract) 1 because we want to trigger when the wheel
1872+
* is half-way to the next notch (i.e. scroll 1 notch after a
1873+
* 1/2 notch movement, 2 notches after a 1 1/2 notch movement,
1874+
* etc.).
1875+
*/
1876+
low_res_scroll_amount =
1877+
counter->remainder / counter->resolution_multiplier
1878+
+ (hi_res_value > 0 ? 1 : -1);
1879+
input_report_rel(counter->dev, REL_WHEEL,
1880+
low_res_scroll_amount);
1881+
counter->remainder -=
1882+
low_res_scroll_amount * counter->resolution_multiplier;
1883+
}
1884+
}
1885+
EXPORT_SYMBOL_GPL(hid_scroll_counter_handle_scroll);

0 commit comments

Comments
 (0)