linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Chen <johnchen902@gmail.com>
To: linux-input@vger.kernel.org
Cc: Rohit Pidaparthi <rohitpid@gmail.com>,
	RicardoEPRodrigues <ricardo.e.p.rodrigues@gmail.com>,
	Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	John Chen <johnchen902@gmail.com>
Subject: [PATCH v2 2/4] HID: magicmouse: fix 3 button emulation of Mouse 2
Date: Tue, 30 Mar 2021 19:33:17 +0800	[thread overview]
Message-ID: <20210330113319.14010-3-johnchen902@gmail.com> (raw)
In-Reply-To: <20210330113319.14010-1-johnchen902@gmail.com>

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.

Signed-off-by: John Chen <johnchen902@gmail.com>
---
 drivers/hid/hid-magicmouse.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 7aad6ca56780..c646b4cd3783 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -440,6 +440,21 @@ static int magicmouse_raw_event(struct hid_device *hdev,
 	return 1;
 }
 
+static int magicmouse_event(struct hid_device *hdev, struct hid_field *field,
+		struct hid_usage *usage, __s32 value)
+{
+	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
+	if (msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 &&
+	    field->report->id == MOUSE2_REPORT_ID) {
+		// magic_mouse_raw_event has done all the work. Skip hidinput.
+		//
+		// Specifically, hidinput may modify BTN_LEFT and BTN_RIGHT,
+		// breaking emulate_3button.
+		return 1;
+	}
+	return 0;
+}
+
 static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
 {
 	int error;
@@ -754,6 +769,7 @@ static struct hid_driver magicmouse_driver = {
 	.id_table = magic_mice,
 	.probe = magicmouse_probe,
 	.raw_event = magicmouse_raw_event,
+	.event = magicmouse_event,
 	.input_mapping = magicmouse_input_mapping,
 	.input_configured = magicmouse_input_configured,
 };
-- 
2.31.0


  parent reply	other threads:[~2021-03-30 11:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 11:33 [PATCH v2 0/4] Hid: add Apple Magic Mouse 2 support John Chen
2021-03-30 11:33 ` [PATCH v2 1/4] HID: magicmouse: " John Chen
2021-04-05 17:30   ` Felix Hädicke
2021-03-30 11:33 ` John Chen [this message]
2021-04-07 11:15   ` [PATCH v2 2/4] HID: magicmouse: fix 3 button emulation of Mouse 2 Jiri Kosina
2021-03-30 11:33 ` [PATCH v2 3/4] HID: magicmouse: fix reconnection of Magic " John Chen
2021-03-30 11:33 ` [PATCH v2 4/4] HID: input: map battery capacity (00850065) John Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210330113319.14010-3-johnchen902@gmail.com \
    --to=johnchen902@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=ricardo.e.p.rodrigues@gmail.com \
    --cc=rohitpid@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).