@@ -1838,3 +1838,48 @@ void hidinput_disconnect(struct hid_device *hid)
1838
1838
}
1839
1839
EXPORT_SYMBOL_GPL (hidinput_disconnect );
1840
1840
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