Skip to content

Commit 346338e

Browse files
free5lotJiri Kosina
authored andcommitted
HID: apple: Swap the Fn and Left Control keys on Apple keyboards
This patch allows users to swap the Fn and left Control keys on all Apple keyboards: internal (e.g. Macbooks) and external (both wired and wireless). The patch adds a new hid-apple module param: swap_fn_leftctrl (off by default). Signed-off-by: Zakhar Semenov <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 47cf1b4 commit 346338e

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

drivers/hid/hid-apple.c

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

54+
static unsigned int swap_fn_leftctrl;
55+
module_param(swap_fn_leftctrl, uint, 0644);
56+
MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
57+
"(For people who want to keep PC keyboard muscle memory. "
58+
"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
59+
5460
struct apple_sc {
5561
unsigned long quirks;
5662
unsigned int fn_on;
@@ -162,6 +168,11 @@ static const struct apple_key_translation swapped_option_cmd_keys[] = {
162168
{ }
163169
};
164170

171+
static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
172+
{ KEY_FN, KEY_LEFTCTRL },
173+
{ }
174+
};
175+
165176
static const struct apple_key_translation *apple_find_translation(
166177
const struct apple_key_translation *table, u16 from)
167178
{
@@ -183,9 +194,11 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
183194
bool do_translate;
184195
u16 code = 0;
185196

186-
if (usage->code == KEY_FN) {
197+
u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN);
198+
199+
if (usage->code == fn_keycode) {
187200
asc->fn_on = !!value;
188-
input_event(input, usage->type, usage->code, value);
201+
input_event(input, usage->type, KEY_FN, value);
189202
return 1;
190203
}
191204

@@ -270,6 +283,14 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
270283
}
271284
}
272285

286+
if (swap_fn_leftctrl) {
287+
trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
288+
if (trans) {
289+
input_event(input, usage->type, trans->to, value);
290+
return 1;
291+
}
292+
}
293+
273294
return 0;
274295
}
275296

@@ -333,6 +354,11 @@ static void apple_setup_input(struct input_dev *input)
333354

334355
for (trans = apple_iso_keyboard; trans->from; trans++)
335356
set_bit(trans->to, input->keybit);
357+
358+
if (swap_fn_leftctrl) {
359+
for (trans = swapped_fn_leftctrl_keys; trans->from; trans++)
360+
set_bit(trans->to, input->keybit);
361+
}
336362
}
337363

338364
static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,

0 commit comments

Comments
 (0)