Skip to content

Commit 0fea6fe

Browse files
JoseExpositoJiri Kosina
authored andcommitted
HID: apple: Magic Keyboard first generation FN key mapping
The function key mapping for the Magic Keyboard first generation (2007, 2009 and 2011 aluminum wireless models) was not present and the default one was used instead. This caused two main issues: - The F5 and F6 keys were sending KEY_KBDILLUMDOWN and KEY_KBDILLUMUP; however, the keyboard is not backlited. - The keyboard has the APPLE_NUMLOCK_EMULATION quirk with F6 set as the KEY_NUMLOCK key by "powerbook_numlock_keys". However, because F6 was mapped to KEY_KBDILLUMUP by the default mapping it was not possible to switch the numlock status. This means that, if numlock was enabled on session startup, it was not possible to disable it without connecting another keyboard. Add a custom translation table for the device leaving F5 unassigned and using F6 as the KEY_NUMLOCK key. Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent f1d1b3a commit 0fea6fe

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

drivers/hid/hid-apple.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ struct apple_key_translation {
7676
u8 flags;
7777
};
7878

79+
static const struct apple_key_translation magic_keyboard_alu_fn_keys[] = {
80+
{ KEY_BACKSPACE, KEY_DELETE },
81+
{ KEY_ENTER, KEY_INSERT },
82+
{ KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
83+
{ KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
84+
{ KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
85+
{ KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
86+
{ KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
87+
{ KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
88+
{ KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
89+
{ KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
90+
{ KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
91+
{ KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
92+
{ KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
93+
{ KEY_UP, KEY_PAGEUP },
94+
{ KEY_DOWN, KEY_PAGEDOWN },
95+
{ KEY_LEFT, KEY_HOME },
96+
{ KEY_RIGHT, KEY_END },
97+
{ }
98+
};
99+
79100
static const struct apple_key_translation apple2021_fn_keys[] = {
80101
{ KEY_BACKSPACE, KEY_DELETE },
81102
{ KEY_ENTER, KEY_INSERT },
@@ -251,9 +272,19 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
251272
}
252273

253274
if (fnmode) {
254-
if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ||
255-
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
256-
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
275+
if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
276+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
277+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ||
278+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ||
279+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ||
280+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS ||
281+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI ||
282+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO ||
283+
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS)
284+
table = magic_keyboard_alu_fn_keys;
285+
else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ||
286+
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
287+
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
257288
table = apple2021_fn_keys;
258289
else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
259290
hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
@@ -468,6 +499,7 @@ static void apple_setup_input(struct input_dev *input)
468499
apple_setup_key_translation(input, powerbook_fn_keys);
469500
apple_setup_key_translation(input, powerbook_numlock_keys);
470501
apple_setup_key_translation(input, apple_iso_keyboard);
502+
apple_setup_key_translation(input, magic_keyboard_alu_fn_keys);
471503
apple_setup_key_translation(input, apple2021_fn_keys);
472504

473505
if (swap_fn_leftctrl)

0 commit comments

Comments
 (0)