macintosh/hid: keycode-mapping for left click
diff mbox

Message ID 80pr9tz2pb.fsf@merkur.tec.linutronix.de
State Rejected
Headers show

Commit Message

John Ogness Sept. 14, 2009, 8:33 p.m. UTC
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(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Dmitry Torokhov Sept. 15, 2009, 6:19 a.m. UTC | #1
Hi John,

On Mon, Sep 14, 2009 at 10:33:20PM +0200, John Ogness wrote:
> 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.
> 

Thank you for the patch however I will not apply it. While kernel has a
lot of quirks to work around broken hardware those apply to the design
brokenness, not old-age brokenness.

Patch
diff mbox

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 */