mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00
HID: magicmouse: enable high-resolution scroll
The Magic Mouse, generations 1 and 2, doesn't have a physical scroll wheel, instead, the REL_WHEEL and REL_HWHEEL events are emulated when sliding a finger on the surface of the mouse. However, the smooth movement of the finger is transformed into a step based scroll on the screen, leading to a suboptimal user experience. Emulate high-resolution scroll by sending REL_WHEEL_HI_RES and REL_HWHEEL_HI_RES events so the scroll on the screen is closer to the finger movement. Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
df04fbe868
commit
d4b9f10a0e
1 changed files with 31 additions and 0 deletions
|
@ -68,6 +68,9 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
|
||||||
#define TOUCH_STATE_START 0x30
|
#define TOUCH_STATE_START 0x30
|
||||||
#define TOUCH_STATE_DRAG 0x40
|
#define TOUCH_STATE_DRAG 0x40
|
||||||
|
|
||||||
|
/* Number of high-resolution events for each low-resolution detent. */
|
||||||
|
#define SCROLL_HR_STEPS 10
|
||||||
|
#define SCROLL_HR_MULT (120 / SCROLL_HR_STEPS)
|
||||||
#define SCROLL_ACCEL_DEFAULT 7
|
#define SCROLL_ACCEL_DEFAULT 7
|
||||||
|
|
||||||
/* Touch surface information. Dimension is in hundredths of a mm, min and max
|
/* Touch surface information. Dimension is in hundredths of a mm, min and max
|
||||||
|
@ -126,6 +129,8 @@ struct magicmouse_sc {
|
||||||
short y;
|
short y;
|
||||||
short scroll_x;
|
short scroll_x;
|
||||||
short scroll_y;
|
short scroll_y;
|
||||||
|
short scroll_x_hr;
|
||||||
|
short scroll_y_hr;
|
||||||
u8 size;
|
u8 size;
|
||||||
} touches[16];
|
} touches[16];
|
||||||
int tracking_ids[16];
|
int tracking_ids[16];
|
||||||
|
@ -248,12 +253,18 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
|
||||||
unsigned long now = jiffies;
|
unsigned long now = jiffies;
|
||||||
int step_x = msc->touches[id].scroll_x - x;
|
int step_x = msc->touches[id].scroll_x - x;
|
||||||
int step_y = msc->touches[id].scroll_y - y;
|
int step_y = msc->touches[id].scroll_y - y;
|
||||||
|
int step_hr = ((64 - (int)scroll_speed) * msc->scroll_accel) /
|
||||||
|
SCROLL_HR_STEPS;
|
||||||
|
int step_x_hr = msc->touches[id].scroll_x_hr - x;
|
||||||
|
int step_y_hr = msc->touches[id].scroll_y_hr - y;
|
||||||
|
|
||||||
/* Calculate and apply the scroll motion. */
|
/* Calculate and apply the scroll motion. */
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case TOUCH_STATE_START:
|
case TOUCH_STATE_START:
|
||||||
msc->touches[id].scroll_x = x;
|
msc->touches[id].scroll_x = x;
|
||||||
msc->touches[id].scroll_y = y;
|
msc->touches[id].scroll_y = y;
|
||||||
|
msc->touches[id].scroll_x_hr = x;
|
||||||
|
msc->touches[id].scroll_y_hr = y;
|
||||||
|
|
||||||
/* Reset acceleration after half a second. */
|
/* Reset acceleration after half a second. */
|
||||||
if (scroll_acceleration && time_before(now,
|
if (scroll_acceleration && time_before(now,
|
||||||
|
@ -280,6 +291,24 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
|
||||||
msc->scroll_jiffies = now;
|
msc->scroll_jiffies = now;
|
||||||
input_report_rel(input, REL_WHEEL, step_y);
|
input_report_rel(input, REL_WHEEL, step_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
step_x_hr /= step_hr;
|
||||||
|
if (step_x_hr != 0) {
|
||||||
|
msc->touches[id].scroll_x_hr -= step_x_hr *
|
||||||
|
step_hr;
|
||||||
|
input_report_rel(input,
|
||||||
|
REL_HWHEEL_HI_RES,
|
||||||
|
-step_x_hr * SCROLL_HR_MULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
step_y_hr /= step_hr;
|
||||||
|
if (step_y_hr != 0) {
|
||||||
|
msc->touches[id].scroll_y_hr -= step_y_hr *
|
||||||
|
step_hr;
|
||||||
|
input_report_rel(input,
|
||||||
|
REL_WHEEL_HI_RES,
|
||||||
|
step_y_hr * SCROLL_HR_MULT);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -481,6 +510,8 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
|
||||||
if (emulate_scroll_wheel) {
|
if (emulate_scroll_wheel) {
|
||||||
__set_bit(REL_WHEEL, input->relbit);
|
__set_bit(REL_WHEEL, input->relbit);
|
||||||
__set_bit(REL_HWHEEL, input->relbit);
|
__set_bit(REL_HWHEEL, input->relbit);
|
||||||
|
__set_bit(REL_WHEEL_HI_RES, input->relbit);
|
||||||
|
__set_bit(REL_HWHEEL_HI_RES, input->relbit);
|
||||||
}
|
}
|
||||||
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
|
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
|
||||||
/* setting the device name to ensure the same driver settings
|
/* setting the device name to ensure the same driver settings
|
||||||
|
|
Loading…
Add table
Reference in a new issue