macintosh/hid: keycode-mapping for left click
Subsystems (3)
PATCH 1/1 macintosh/hid: keycode-mapping for left click
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: <[email protected]>
--- drivers/macintosh/mac_hid.c | 24 ++++++++++++++++++++---- include/linux/sysctl.h | 3 ++- kernel/sysctl_check.c | 1 + 3 files changed, 23 insertions(+), 5 deletions(-)
drivers/macintosh/mac_hid.c +20 -4
@@ -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 cacase 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 ; }
include/linux/sysctl.h +2 -1
@@ -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 */
kernel/sysctl_check.c +1 -0
@@ -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 */
Hi John,
Quoted 9 lines · John Ogness
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.
Signature · 1 line
Dmitry