Skip to content

Commit 3dcc5f7

Browse files
johnchen902Jiri Kosina
authored andcommitted
HID: magicmouse: fix 3 button emulation of Mouse 2
It is observed that, with 3 button emulation, when middle button is clicked, either the left button or right button is clicked as well. It is caused by hidinput "correctly" acting on the event, oblivious to the 3 button emulation. As raw_event has taken care of everything, no further processing is needed. However, the only way to stop at raw_event is to return an error (negative) value. Therefore, the processing is stopped at event instead. [[email protected]: fix comment style] Signed-off-by: John Chen <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 2b0c086 commit 3dcc5f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

drivers/hid/hid-magicmouse.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ static int magicmouse_raw_event(struct hid_device *hdev,
440440
return 1;
441441
}
442442

443+
static int magicmouse_event(struct hid_device *hdev, struct hid_field *field,
444+
struct hid_usage *usage, __s32 value)
445+
{
446+
struct magicmouse_sc *msc = hid_get_drvdata(hdev);
447+
if (msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 &&
448+
field->report->id == MOUSE2_REPORT_ID) {
449+
/*
450+
* magic_mouse_raw_event has done all the work. Skip hidinput.
451+
*
452+
* Specifically, hidinput may modify BTN_LEFT and BTN_RIGHT,
453+
* breaking emulate_3button.
454+
*/
455+
return 1;
456+
}
457+
return 0;
458+
}
459+
443460
static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
444461
{
445462
int error;
@@ -754,6 +771,7 @@ static struct hid_driver magicmouse_driver = {
754771
.id_table = magic_mice,
755772
.probe = magicmouse_probe,
756773
.raw_event = magicmouse_raw_event,
774+
.event = magicmouse_event,
757775
.input_mapping = magicmouse_input_mapping,
758776
.input_configured = magicmouse_input_configured,
759777
};

0 commit comments

Comments
 (0)