Skip to content

Commit 2a97472

Browse files
committed
DO NOT MERGE: HID: apple: Add fnmode which ignores function keys
This mode is added to ease adding new xkeyboard configs for Apple silicon Macbook keyboards. The existing ones have strange quirks [1] and as the keyboard sends a key code for the 'fn' there is desire to use it as additional modifier [2]. [1]: https://pagure.io/fedora-asahi/remix-bugs/issue/17 [2]: https://asahilinux.org/docs/project/help-wanted/ (Keyboard layout cleanup) Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 66e0c6a commit 2a97472

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

drivers/hid/hid-apple.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@
5252
#define APPLE_MAGIC_REPORT_ID_POWER 3
5353
#define APPLE_MAGIC_REPORT_ID_BRIGHTNESS 1
5454

55+
// DO NOT UPSTREAM:
56+
// temporary Fn key mode until xkeyboard-config has keyboard layouts with media
57+
// key mappings. At that point auto mode can drop function key mappings and this
58+
// mode can be dropped.
59+
#define FKEYS_IGNORE 4
60+
5561
static unsigned int fnmode = 3;
5662
module_param(fnmode, uint, 0644);
5763
MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
58-
"1 = fkeyslast, 2 = fkeysfirst, [3] = auto)");
64+
"1 = fkeyslast, 2 = fkeysfirst, [3] = auto, [4] = fkeysignore)");
5965

6066
static int iso_layout = -1;
6167
module_param(iso_layout, int, 0644);
@@ -276,6 +282,16 @@ static const struct apple_key_translation apple_fn_keys[] = {
276282
{ }
277283
};
278284

285+
static const struct apple_key_translation apple_fn_keys_minimal[] = {
286+
{ KEY_BACKSPACE, KEY_DELETE },
287+
{ KEY_ENTER, KEY_INSERT },
288+
{ KEY_UP, KEY_PAGEUP },
289+
{ KEY_DOWN, KEY_PAGEDOWN },
290+
{ KEY_LEFT, KEY_HOME },
291+
{ KEY_RIGHT, KEY_END },
292+
{ }
293+
};
294+
279295
static const struct apple_key_translation powerbook_fn_keys[] = {
280296
{ KEY_BACKSPACE, KEY_DELETE },
281297
{ KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
@@ -426,6 +442,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
426442

427443
if (fnmode == 3) {
428444
real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
445+
} else if (fnmode == FKEYS_IGNORE) {
446+
real_fnmode = 2;
429447
} else {
430448
real_fnmode = fnmode;
431449
}
@@ -505,7 +523,9 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
505523
table = macbookpro_dedicated_esc_fn_keys;
506524
break;
507525
default:
508-
table = apple2021_fn_keys;
526+
table = (fnmode == FKEYS_IGNORE) ?
527+
apple_fn_keys_minimal :
528+
apple2021_fn_keys;
509529
break;
510530
}
511531
else if (hid->product < 0x21d || hid->product >= 0x300)
@@ -687,6 +707,7 @@ static void apple_setup_input(struct input_dev *input)
687707

688708
/* Enable all needed keys */
689709
apple_setup_key_translation(input, apple_fn_keys);
710+
apple_setup_key_translation(input, apple_fn_keys_minimal);
690711
apple_setup_key_translation(input, powerbook_fn_keys);
691712
apple_setup_key_translation(input, powerbook_numlock_keys);
692713
apple_setup_key_translation(input, apple_iso_keyboard);
@@ -924,6 +945,11 @@ static int apple_probe(struct hid_device *hdev,
924945
hdev->type != HID_TYPE_SPI_KEYBOARD)
925946
return -ENODEV;
926947

948+
// key remapping will happen in xkeyboard-config so ignore
949+
// APPLE_ISO_TILDE_QUIRK
950+
if ((id->bus == BUS_SPI || id->bus == BUS_HOST) && fnmode == FKEYS_IGNORE)
951+
quirks &= ~APPLE_ISO_TILDE_QUIRK;
952+
927953
asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
928954
if (asc == NULL) {
929955
hid_err(hdev, "can't alloc apple descriptor\n");
@@ -1184,9 +1210,9 @@ static const struct hid_device_id apple_devices[] = {
11841210
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
11851211
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
11861212
{ HID_SPI_DEVICE(SPI_VENDOR_ID_APPLE, HID_ANY_ID),
1187-
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1213+
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK
11881214
{ HID_DEVICE(BUS_HOST, HID_GROUP_ANY, HOST_VENDOR_ID_APPLE, HID_ANY_ID),
1189-
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1215+
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK
11901216
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT),
11911217
.driver_data = APPLE_MAGIC_BACKLIGHT },
11921218

0 commit comments

Comments
 (0)