diff options
author | Aditya Garg <gargaditya08@live.com> | 2022-11-04 14:55:35 +0300 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2022-11-15 01:46:20 +0300 |
commit | fd7b68b763c4dfa65e3c145c624427d5fd11202f (patch) | |
tree | 7f814f075fc65a432735a5c4133f07cf0291f520 /drivers/hid/hid-apple.c | |
parent | 084bc074c231e716cbcb9e8f9db05b17fd3563cf (diff) | |
download | linux-fd7b68b763c4dfa65e3c145c624427d5fd11202f.tar.xz |
HID: apple: Swap Control and Command keys on Apple keyboards
This patch allows users to swap the control and command keys. This can be
useful for the Mac users who are used to using Command instead of Control
in macOS for various commonly used shortcuts.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-apple.c')
-rw-r--r-- | drivers/hid/hid-apple.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index c671ce94671c..1ccab8aa326c 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -59,6 +59,12 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") "(For people who want to keep Windows PC keyboard muscle memory. " "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)"); +static unsigned int swap_ctrl_cmd; +module_param(swap_ctrl_cmd, uint, 0644); +MODULE_PARM_DESC(swap_ctrl_cmd, "Swap the Control (\"Ctrl\") and Command (\"Flag\") keys. " + "(For people who are used to Mac shortcuts involving Command instead of Control. " + "[0] = No change. 1 = Swapped.)"); + static unsigned int swap_fn_leftctrl; module_param(swap_fn_leftctrl, uint, 0644); MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. " @@ -308,7 +314,15 @@ static const struct apple_key_translation swapped_option_cmd_keys[] = { { KEY_LEFTALT, KEY_LEFTMETA }, { KEY_LEFTMETA, KEY_LEFTALT }, { KEY_RIGHTALT, KEY_RIGHTMETA }, - { KEY_RIGHTMETA,KEY_RIGHTALT }, + { KEY_RIGHTMETA, KEY_RIGHTALT }, + { } +}; + +static const struct apple_key_translation swapped_ctrl_cmd_keys[] = { + { KEY_LEFTCTRL, KEY_LEFTMETA }, + { KEY_LEFTMETA, KEY_LEFTCTRL }, + { KEY_RIGHTCTRL, KEY_RIGHTMETA }, + { KEY_RIGHTMETA, KEY_RIGHTCTRL }, { } }; @@ -407,6 +421,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, code = trans->to; } + if (swap_ctrl_cmd) { + trans = apple_find_translation(swapped_ctrl_cmd_keys, code); + + if (trans) + code = trans->to; + } + if (code == KEY_FN) asc->fn_on = !!value; |