Skip to content

Commit c5f09b1

Browse files
AdityaGarg8Jiri Kosina
authored andcommitted
HID: apple: Add fn mapping for MacBook Pros with Touch Bar
This patch adds the Fn mapping for keyboards on certain T2 Macs. [jkosina@suse.cz: rebase on top of apple_setup_input() refactoring] Signed-off-by: Aditya Garg <gargaditya08@live.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 42f6a2d commit c5f09b1

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

drivers/hid/hid-apple.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,51 @@ static const struct apple_key_translation macbookair_fn_keys[] = {
183183
{ }
184184
};
185185

186+
static const struct apple_key_translation macbookpro_no_esc_fn_keys[] = {
187+
{ KEY_BACKSPACE, KEY_DELETE },
188+
{ KEY_ENTER, KEY_INSERT },
189+
{ KEY_GRAVE, KEY_ESC },
190+
{ KEY_1, KEY_F1 },
191+
{ KEY_2, KEY_F2 },
192+
{ KEY_3, KEY_F3 },
193+
{ KEY_4, KEY_F4 },
194+
{ KEY_5, KEY_F5 },
195+
{ KEY_6, KEY_F6 },
196+
{ KEY_7, KEY_F7 },
197+
{ KEY_8, KEY_F8 },
198+
{ KEY_9, KEY_F9 },
199+
{ KEY_0, KEY_F10 },
200+
{ KEY_MINUS, KEY_F11 },
201+
{ KEY_EQUAL, KEY_F12 },
202+
{ KEY_UP, KEY_PAGEUP },
203+
{ KEY_DOWN, KEY_PAGEDOWN },
204+
{ KEY_LEFT, KEY_HOME },
205+
{ KEY_RIGHT, KEY_END },
206+
{ }
207+
};
208+
209+
static const struct apple_key_translation macbookpro_dedicated_esc_fn_keys[] = {
210+
{ KEY_BACKSPACE, KEY_DELETE },
211+
{ KEY_ENTER, KEY_INSERT },
212+
{ KEY_1, KEY_F1 },
213+
{ KEY_2, KEY_F2 },
214+
{ KEY_3, KEY_F3 },
215+
{ KEY_4, KEY_F4 },
216+
{ KEY_5, KEY_F5 },
217+
{ KEY_6, KEY_F6 },
218+
{ KEY_7, KEY_F7 },
219+
{ KEY_8, KEY_F8 },
220+
{ KEY_9, KEY_F9 },
221+
{ KEY_0, KEY_F10 },
222+
{ KEY_MINUS, KEY_F11 },
223+
{ KEY_EQUAL, KEY_F12 },
224+
{ KEY_UP, KEY_PAGEUP },
225+
{ KEY_DOWN, KEY_PAGEDOWN },
226+
{ KEY_LEFT, KEY_HOME },
227+
{ KEY_RIGHT, KEY_END },
228+
{ }
229+
};
230+
186231
static const struct apple_key_translation apple_fn_keys[] = {
187232
{ KEY_BACKSPACE, KEY_DELETE },
188233
{ KEY_ENTER, KEY_INSERT },
@@ -332,6 +377,17 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
332377
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
333378
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
334379
table = apple2021_fn_keys;
380+
else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
381+
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
382+
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
383+
table = macbookpro_no_esc_fn_keys;
384+
else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
385+
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
386+
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
387+
table = macbookpro_dedicated_esc_fn_keys;
388+
else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
389+
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
390+
table = apple_fn_keys;
335391
else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
336392
hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
337393
table = macbookair_fn_keys;
@@ -548,6 +604,8 @@ static void apple_setup_input(struct input_dev *input)
548604
apple_setup_key_translation(input, magic_keyboard_alu_fn_keys);
549605
apple_setup_key_translation(input, magic_keyboard_2015_fn_keys);
550606
apple_setup_key_translation(input, apple2021_fn_keys);
607+
apple_setup_key_translation(input, macbookpro_no_esc_fn_keys);
608+
apple_setup_key_translation(input, macbookpro_dedicated_esc_fn_keys);
551609

552610
if (swap_fn_leftctrl)
553611
apple_setup_key_translation(input, swapped_fn_leftctrl_keys);

0 commit comments

Comments
 (0)