Skip to content

Commit 163a312

Browse files
author
Jiri Kosina
committed
Merge branch 'for-5.15/magicmouse' into for-linus
- High-resolution scroll support for Magicmouse devices
2 parents 1138b33 + 9d60648 commit 163a312

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

drivers/hid/hid-magicmouse.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
6868
#define TOUCH_STATE_START 0x30
6969
#define TOUCH_STATE_DRAG 0x40
7070

71+
/* Number of high-resolution events for each low-resolution detent. */
72+
#define SCROLL_HR_STEPS 10
73+
#define SCROLL_HR_MULT (120 / SCROLL_HR_STEPS)
74+
#define SCROLL_HR_THRESHOLD 90 /* units */
7175
#define SCROLL_ACCEL_DEFAULT 7
7276

7377
/* Touch surface information. Dimension is in hundredths of a mm, min and max
@@ -126,7 +130,11 @@ struct magicmouse_sc {
126130
short y;
127131
short scroll_x;
128132
short scroll_y;
133+
short scroll_x_hr;
134+
short scroll_y_hr;
129135
u8 size;
136+
bool scroll_x_active;
137+
bool scroll_y_active;
130138
} touches[16];
131139
int tracking_ids[16];
132140

@@ -248,12 +256,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
248256
unsigned long now = jiffies;
249257
int step_x = msc->touches[id].scroll_x - x;
250258
int step_y = msc->touches[id].scroll_y - y;
259+
int step_hr = ((64 - (int)scroll_speed) * msc->scroll_accel) /
260+
SCROLL_HR_STEPS;
261+
int step_x_hr = msc->touches[id].scroll_x_hr - x;
262+
int step_y_hr = msc->touches[id].scroll_y_hr - y;
251263

252264
/* Calculate and apply the scroll motion. */
253265
switch (state) {
254266
case TOUCH_STATE_START:
255267
msc->touches[id].scroll_x = x;
256268
msc->touches[id].scroll_y = y;
269+
msc->touches[id].scroll_x_hr = x;
270+
msc->touches[id].scroll_y_hr = y;
271+
msc->touches[id].scroll_x_active = false;
272+
msc->touches[id].scroll_y_active = false;
257273

258274
/* Reset acceleration after half a second. */
259275
if (scroll_acceleration && time_before(now,
@@ -280,6 +296,40 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
280296
msc->scroll_jiffies = now;
281297
input_report_rel(input, REL_WHEEL, step_y);
282298
}
299+
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+
307+
step_x_hr /= step_hr;
308+
if (step_x_hr != 0 &&
309+
msc->touches[id].scroll_x_active) {
310+
msc->touches[id].scroll_x_hr -= step_x_hr *
311+
step_hr;
312+
input_report_rel(input,
313+
REL_HWHEEL_HI_RES,
314+
-step_x_hr * SCROLL_HR_MULT);
315+
}
316+
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+
324+
step_y_hr /= step_hr;
325+
if (step_y_hr != 0 &&
326+
msc->touches[id].scroll_y_active) {
327+
msc->touches[id].scroll_y_hr -= step_y_hr *
328+
step_hr;
329+
input_report_rel(input,
330+
REL_WHEEL_HI_RES,
331+
step_y_hr * SCROLL_HR_MULT);
332+
}
283333
break;
284334
}
285335
}
@@ -481,6 +531,8 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
481531
if (emulate_scroll_wheel) {
482532
__set_bit(REL_WHEEL, input->relbit);
483533
__set_bit(REL_HWHEEL, input->relbit);
534+
__set_bit(REL_WHEEL_HI_RES, input->relbit);
535+
__set_bit(REL_HWHEEL_HI_RES, input->relbit);
484536
}
485537
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
486538
/* setting the device name to ensure the same driver settings

0 commit comments

Comments
 (0)