Skip to content

Commit 9d60648

Browse files
JoseExpositoJiri Kosina
authored andcommitted
HID: magicmouse: high-resolution scroll threshold
In order to avoid triggering involuntary high-resolution scroll events due to tiny touch movement deltas, add a movement threshold. The value chosen for the threshold, about 1.5 ~ 2 mm, is similar to the threshold used on touchpads by libinput (see libinput evdev-mt-touchpad-gestures.c) to try to keep the scroll experience consistent. Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent d4b9f10 commit 9d60648

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

drivers/hid/hid-magicmouse.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
7171
/* Number of high-resolution events for each low-resolution detent. */
7272
#define SCROLL_HR_STEPS 10
7373
#define SCROLL_HR_MULT (120 / SCROLL_HR_STEPS)
74+
#define SCROLL_HR_THRESHOLD 90 /* units */
7475
#define SCROLL_ACCEL_DEFAULT 7
7576

7677
/* Touch surface information. Dimension is in hundredths of a mm, min and max
@@ -132,6 +133,8 @@ struct magicmouse_sc {
132133
short scroll_x_hr;
133134
short scroll_y_hr;
134135
u8 size;
136+
bool scroll_x_active;
137+
bool scroll_y_active;
135138
} touches[16];
136139
int tracking_ids[16];
137140

@@ -265,6 +268,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
265268
msc->touches[id].scroll_y = y;
266269
msc->touches[id].scroll_x_hr = x;
267270
msc->touches[id].scroll_y_hr = y;
271+
msc->touches[id].scroll_x_active = false;
272+
msc->touches[id].scroll_y_active = false;
268273

269274
/* Reset acceleration after half a second. */
270275
if (scroll_acceleration && time_before(now,
@@ -292,17 +297,33 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
292297
input_report_rel(input, REL_WHEEL, step_y);
293298
}
294299

300+
if (!msc->touches[id].scroll_x_active &&
301+
abs(step_x_hr) > SCROLL_HR_THRESHOLD) {
302+
msc->touches[id].scroll_x_active = true;
303+
msc->touches[id].scroll_x_hr = x;
304+
step_x_hr = 0;
305+
}
306+
295307
step_x_hr /= step_hr;
296-
if (step_x_hr != 0) {
308+
if (step_x_hr != 0 &&
309+
msc->touches[id].scroll_x_active) {
297310
msc->touches[id].scroll_x_hr -= step_x_hr *
298311
step_hr;
299312
input_report_rel(input,
300313
REL_HWHEEL_HI_RES,
301314
-step_x_hr * SCROLL_HR_MULT);
302315
}
303316

317+
if (!msc->touches[id].scroll_y_active &&
318+
abs(step_y_hr) > SCROLL_HR_THRESHOLD) {
319+
msc->touches[id].scroll_y_active = true;
320+
msc->touches[id].scroll_y_hr = y;
321+
step_y_hr = 0;
322+
}
323+
304324
step_y_hr /= step_hr;
305-
if (step_y_hr != 0) {
325+
if (step_y_hr != 0 &&
326+
msc->touches[id].scroll_y_active) {
306327
msc->touches[id].scroll_y_hr -= step_y_hr *
307328
step_hr;
308329
input_report_rel(input,

0 commit comments

Comments
 (0)