Skip to content

Commit fd7b68b

Browse files
AdityaGarg8Jiri Kosina
authored andcommitted
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>
1 parent 084bc07 commit fd7b68b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

drivers/hid/hid-apple.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\")
5959
"(For people who want to keep Windows PC keyboard muscle memory. "
6060
"[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
6161

62+
static unsigned int swap_ctrl_cmd;
63+
module_param(swap_ctrl_cmd, uint, 0644);
64+
MODULE_PARM_DESC(swap_ctrl_cmd, "Swap the Control (\"Ctrl\") and Command (\"Flag\") keys. "
65+
"(For people who are used to Mac shortcuts involving Command instead of Control. "
66+
"[0] = No change. 1 = Swapped.)");
67+
6268
static unsigned int swap_fn_leftctrl;
6369
module_param(swap_fn_leftctrl, uint, 0644);
6470
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[] = {
308314
{ KEY_LEFTALT, KEY_LEFTMETA },
309315
{ KEY_LEFTMETA, KEY_LEFTALT },
310316
{ KEY_RIGHTALT, KEY_RIGHTMETA },
311-
{ KEY_RIGHTMETA,KEY_RIGHTALT },
317+
{ KEY_RIGHTMETA, KEY_RIGHTALT },
318+
{ }
319+
};
320+
321+
static const struct apple_key_translation swapped_ctrl_cmd_keys[] = {
322+
{ KEY_LEFTCTRL, KEY_LEFTMETA },
323+
{ KEY_LEFTMETA, KEY_LEFTCTRL },
324+
{ KEY_RIGHTCTRL, KEY_RIGHTMETA },
325+
{ KEY_RIGHTMETA, KEY_RIGHTCTRL },
312326
{ }
313327
};
314328

@@ -407,6 +421,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
407421
code = trans->to;
408422
}
409423

424+
if (swap_ctrl_cmd) {
425+
trans = apple_find_translation(swapped_ctrl_cmd_keys, code);
426+
427+
if (trans)
428+
code = trans->to;
429+
}
430+
410431
if (code == KEY_FN)
411432
asc->fn_on = !!value;
412433

0 commit comments

Comments
 (0)