Skip to content

Commit

Permalink
HID: apple: Add 2021 magic keyboard FN key mapping
Browse files Browse the repository at this point in the history
The new 2021 apple models have a different FN key assignment. Add a new
translation table and use that for the 2021 magic keyboard.

Signed-off-by: Benjamin Berg <bberg@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Benjamin Berg authored and Jiri Kosina committed Jan 6, 2022
1 parent 5768701 commit 531cb56
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion drivers/hid/hid-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ struct apple_key_translation {
u8 flags;
};

static const struct apple_key_translation apple2021_fn_keys[] = {
{ KEY_BACKSPACE, KEY_DELETE },
{ KEY_ENTER, KEY_INSERT },
{ KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
{ KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
{ KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
{ KEY_F4, KEY_SEARCH, APPLE_FLAG_FKEY },
{ KEY_F5, KEY_MICMUTE, APPLE_FLAG_FKEY },
{ KEY_F6, KEY_SLEEP, APPLE_FLAG_FKEY },
{ KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
{ KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
{ KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
{ KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
{ KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
{ KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
{ KEY_UP, KEY_PAGEUP },
{ KEY_DOWN, KEY_PAGEDOWN },
{ KEY_LEFT, KEY_HOME },
{ KEY_RIGHT, KEY_END },
{ }
};

static const struct apple_key_translation macbookair_fn_keys[] = {
{ KEY_BACKSPACE, KEY_DELETE },
{ KEY_ENTER, KEY_INSERT },
Expand Down Expand Up @@ -220,7 +242,9 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
}

if (fnmode) {
if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021)
table = apple2021_fn_keys;
else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
table = macbookair_fn_keys;
else if (hid->product < 0x21d || hid->product >= 0x300)
Expand Down Expand Up @@ -443,6 +467,9 @@ static void apple_setup_input(struct input_dev *input)
for (trans = apple_iso_keyboard; trans->from; trans++)
set_bit(trans->to, input->keybit);

for (trans = apple2021_fn_keys; trans->from; trans++)
set_bit(trans->to, input->keybit);

if (swap_fn_leftctrl) {
for (trans = swapped_fn_leftctrl_keys; trans->from; trans++)
set_bit(trans->to, input->keybit);
Expand Down

0 comments on commit 531cb56

Please sign in to comment.