All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: dmitry.torokhov@gmail.com
Cc: Franz.Sirl-kernel@lauterbach.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-input@vger.kernel.org
Subject: [PATCH] macintosh/hid: keycode-mapping for left click
Date: Mon, 14 Sep 2009 22:33:20 +0200	[thread overview]
Message-ID: <80pr9tz2pb.fsf@merkur.tec.linutronix.de> (raw)

Hi,

This patch adds support for mapping the left mouse button to a
keycode. The driver already mapped the middle and right buttons.

Since the single mouse-button on my Apple laptop broke, I figured the
driver might as well support all three buttons. Now I can keep using my
laptop without problems.

The patch is against 2.6.31.

John Ogness

(I do not belong to either linux-input or linux-kernel mailing lists, so
please reply directly. Thanks.)


Signed off by: <john.ogness@linutronix.de>
---
 drivers/macintosh/mac_hid.c |   24 ++++++++++++++++++++----
 include/linux/sysctl.h      |    3 ++-
 kernel/sysctl_check.c       |    1 +
 3 files changed, 23 insertions(+), 5 deletions(-)
Index: linux-2.6.31/drivers/macintosh/mac_hid.c
===================================================================
--- linux-2.6.31.orig/drivers/macintosh/mac_hid.c
+++ linux-2.6.31/drivers/macintosh/mac_hid.c
@@ -19,6 +19,7 @@
 static struct input_dev *emumousebtn;
 static int emumousebtn_input_register(void);
 static int mouse_emulate_buttons;
+static int mouse_button1_keycode;			/* no default */
 static int mouse_button2_keycode = KEY_RIGHTCTRL;	/* right control key */
 static int mouse_button3_keycode = KEY_RIGHTALT;	/* right option key */
 static int mouse_last_keycode;
@@ -35,6 +36,14 @@ static ctl_table mac_hid_files[] = {
 		.proc_handler	= &proc_dointvec,
 	},
 	{
+		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON1_KEYCODE,
+		.procname	= "mouse_button1_keycode",
+		.data		= &mouse_button1_keycode,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
+	{
 		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,
 		.procname	= "mouse_button2_keycode",
 		.data		= &mouse_button2_keycode,
@@ -87,12 +96,19 @@ int mac_hid_mouse_emulate_buttons(int ca
 	case 1:
 		/* Called from keyboard.c */
 		if (mouse_emulate_buttons
-		    && (keycode == mouse_button2_keycode
+		    && ((keycode == mouse_button1_keycode
+			 && mouse_button1_keycode)
+			|| keycode == mouse_button2_keycode
 			|| keycode == mouse_button3_keycode)) {
 			if (mouse_emulate_buttons == 1) {
-				input_report_key(emumousebtn,
-						 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
-						 down);
+				unsigned int code;
+				if (keycode == mouse_button1_keycode)
+					code = BTN_LEFT;
+				else if (keycode == mouse_button2_keycode)
+					code = BTN_MIDDLE;
+				else
+					code = BTN_RIGHT;
+				input_report_key(emumousebtn, code, down);
 				input_sync(emumousebtn);
 				return 1;
 			}
Index: linux-2.6.31/include/linux/sysctl.h
===================================================================
--- linux-2.6.31.orig/include/linux/sysctl.h
+++ linux-2.6.31/include/linux/sysctl.h
@@ -916,7 +916,8 @@ enum {
 	DEV_MAC_HID_MOUSE_BUTTON_EMULATION=3,
 	DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
 	DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
-	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
+	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6,
+	DEV_MAC_HID_MOUSE_BUTTON1_KEYCODE=7,
 };
 
 /* /proc/sys/dev/scsi */
Index: linux-2.6.31/kernel/sysctl_check.c
===================================================================
--- linux-2.6.31.orig/kernel/sysctl_check.c
+++ linux-2.6.31/kernel/sysctl_check.c
@@ -816,6 +816,7 @@ static const struct trans_ctl_table tran
 	/* DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES unused */
 	/* DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES unused */
 	{ DEV_MAC_HID_MOUSE_BUTTON_EMULATION,	"mouse_button_emulation" },
+	{ DEV_MAC_HID_MOUSE_BUTTON1_KEYCODE,	"mouse_button1_keycode" },
 	{ DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,	"mouse_button2_keycode" },
 	{ DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,	"mouse_button3_keycode" },
 	/* DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES unused */

WARNING: multiple messages have this Message-ID (diff)
From: John Ogness <john.ogness@linutronix.de>
To: dmitry.torokhov@gmail.com
Cc: Franz.Sirl-kernel@lauterbach.com, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org
Subject: [PATCH] macintosh/hid: keycode-mapping for left click
Date: Mon, 14 Sep 2009 22:33:20 +0200	[thread overview]
Message-ID: <80pr9tz2pb.fsf@merkur.tec.linutronix.de> (raw)

Hi,

This patch adds support for mapping the left mouse button to a
keycode. The driver already mapped the middle and right buttons.

Since the single mouse-button on my Apple laptop broke, I figured the
driver might as well support all three buttons. Now I can keep using my
laptop without problems.

The patch is against 2.6.31.

John Ogness

(I do not belong to either linux-input or linux-kernel mailing lists, so
please reply directly. Thanks.)


Signed off by: <john.ogness@linutronix.de>
---
 drivers/macintosh/mac_hid.c |   24 ++++++++++++++++++++----
 include/linux/sysctl.h      |    3 ++-
 kernel/sysctl_check.c       |    1 +
 3 files changed, 23 insertions(+), 5 deletions(-)
Index: linux-2.6.31/drivers/macintosh/mac_hid.c
===================================================================
--- linux-2.6.31.orig/drivers/macintosh/mac_hid.c
+++ linux-2.6.31/drivers/macintosh/mac_hid.c
@@ -19,6 +19,7 @@
 static struct input_dev *emumousebtn;
 static int emumousebtn_input_register(void);
 static int mouse_emulate_buttons;
+static int mouse_button1_keycode;			/* no default */
 static int mouse_button2_keycode = KEY_RIGHTCTRL;	/* right control key */
 static int mouse_button3_keycode = KEY_RIGHTALT;	/* right option key */
 static int mouse_last_keycode;
@@ -35,6 +36,14 @@ static ctl_table mac_hid_files[] = {
 		.proc_handler	= &proc_dointvec,
 	},
 	{
+		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON1_KEYCODE,
+		.procname	= "mouse_button1_keycode",
+		.data		= &mouse_button1_keycode,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
+	{
 		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,
 		.procname	= "mouse_button2_keycode",
 		.data		= &mouse_button2_keycode,
@@ -87,12 +96,19 @@ int mac_hid_mouse_emulate_buttons(int ca
 	case 1:
 		/* Called from keyboard.c */
 		if (mouse_emulate_buttons
-		    && (keycode == mouse_button2_keycode
+		    && ((keycode == mouse_button1_keycode
+			 && mouse_button1_keycode)
+			|| keycode == mouse_button2_keycode
 			|| keycode == mouse_button3_keycode)) {
 			if (mouse_emulate_buttons == 1) {
-				input_report_key(emumousebtn,
-						 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
-						 down);
+				unsigned int code;
+				if (keycode == mouse_button1_keycode)
+					code = BTN_LEFT;
+				else if (keycode == mouse_button2_keycode)
+					code = BTN_MIDDLE;
+				else
+					code = BTN_RIGHT;
+				input_report_key(emumousebtn, code, down);
 				input_sync(emumousebtn);
 				return 1;
 			}
Index: linux-2.6.31/include/linux/sysctl.h
===================================================================
--- linux-2.6.31.orig/include/linux/sysctl.h
+++ linux-2.6.31/include/linux/sysctl.h
@@ -916,7 +916,8 @@ enum {
 	DEV_MAC_HID_MOUSE_BUTTON_EMULATION=3,
 	DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
 	DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
-	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
+	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6,
+	DEV_MAC_HID_MOUSE_BUTTON1_KEYCODE=7,
 };
 
 /* /proc/sys/dev/scsi */
Index: linux-2.6.31/kernel/sysctl_check.c
===================================================================
--- linux-2.6.31.orig/kernel/sysctl_check.c
+++ linux-2.6.31/kernel/sysctl_check.c
@@ -816,6 +816,7 @@ static const struct trans_ctl_table tran
 	/* DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES unused */
 	/* DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES unused */
 	{ DEV_MAC_HID_MOUSE_BUTTON_EMULATION,	"mouse_button_emulation" },
+	{ DEV_MAC_HID_MOUSE_BUTTON1_KEYCODE,	"mouse_button1_keycode" },
 	{ DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,	"mouse_button2_keycode" },
 	{ DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,	"mouse_button3_keycode" },
 	/* DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES unused */

             reply	other threads:[~2009-09-14 20:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-14 20:33 John Ogness [this message]
2009-09-14 20:33 ` [PATCH] macintosh/hid: keycode-mapping for left click John Ogness
2009-09-15  6:19 ` Dmitry Torokhov

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=80pr9tz2pb.fsf@merkur.tec.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=Franz.Sirl-kernel@lauterbach.com \
    --cc=dmitry.torokhov@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.