Skip to content

Commit cd79bb3

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 6058bc8 commit cd79bb3

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

drivers/hid/hid-apple.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@
5454
#define APPLE_MAGIC_REPORT_ID_POWER 3
5555
#define APPLE_MAGIC_REPORT_ID_BRIGHTNESS 1
5656

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

6268
static int iso_layout = -1;
6369
module_param(iso_layout, int, 0644);
@@ -277,6 +283,16 @@ static const struct apple_key_translation apple_fn_keys[] = {
277283
{ }
278284
};
279285

286+
static const struct apple_key_translation apple_fn_keys_minimal[] = {
287+
{ KEY_BACKSPACE, KEY_DELETE },
288+
{ KEY_ENTER, KEY_INSERT },
289+
{ KEY_UP, KEY_PAGEUP },
290+
{ KEY_DOWN, KEY_PAGEDOWN },
291+
{ KEY_LEFT, KEY_HOME },
292+
{ KEY_RIGHT, KEY_END },
293+
{ }
294+
};
295+
280296
static const struct apple_key_translation powerbook_fn_keys[] = {
281297
{ KEY_BACKSPACE, KEY_DELETE },
282298
{ KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
@@ -432,6 +448,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
432448
real_fnmode = 2;
433449
else
434450
real_fnmode = 1;
451+
} else if (fnmode == FKEYS_IGNORE) {
452+
real_fnmode = 2;
435453
} else {
436454
real_fnmode = fnmode;
437455
}
@@ -481,7 +499,10 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
481499
table = macbookpro_dedicated_esc_fn_keys;
482500
break;
483501
default:
484-
table = magic_keyboard_2021_and_2024_fn_keys;
502+
if (fnmode == FKEYS_IGNORE)
503+
table = apple_fn_keys_minimal;
504+
else
505+
table = magic_keyboard_2021_and_2024_fn_keys;
485506
break;
486507
}
487508
break;
@@ -718,6 +739,7 @@ static void apple_setup_input(struct input_dev *input)
718739

719740
/* Enable all needed keys */
720741
apple_setup_key_translation(input, apple_fn_keys);
742+
apple_setup_key_translation(input, apple_fn_keys_minimal);
721743
apple_setup_key_translation(input, powerbook_fn_keys);
722744
apple_setup_key_translation(input, powerbook_numlock_keys);
723745
apple_setup_key_translation(input, apple_iso_keyboard);
@@ -956,6 +978,11 @@ static int apple_probe(struct hid_device *hdev,
956978
hdev->type != HID_TYPE_SPI_KEYBOARD)
957979
return -ENODEV;
958980

981+
// key remapping will happen in xkeyboard-config so ignore
982+
// APPLE_ISO_TILDE_QUIRK
983+
if ((id->bus == BUS_SPI || id->bus == BUS_HOST) && fnmode == FKEYS_IGNORE)
984+
quirks &= ~APPLE_ISO_TILDE_QUIRK;
985+
959986
asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
960987
if (asc == NULL) {
961988
hid_err(hdev, "can't alloc apple descriptor\n");
@@ -1211,7 +1238,7 @@ static const struct hid_device_id apple_devices[] = {
12111238
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
12121239
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
12131240
{ HID_SPI_DEVICE(SPI_VENDOR_ID_APPLE, HID_ANY_ID),
1214-
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1241+
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK
12151242
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
12161243
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
12171244
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
@@ -1225,7 +1252,7 @@ static const struct hid_device_id apple_devices[] = {
12251252
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
12261253
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
12271254
{ HID_DEVICE(BUS_HOST, HID_GROUP_ANY, HOST_VENDOR_ID_APPLE, HID_ANY_ID),
1228-
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1255+
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK
12291256
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024),
12301257
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
12311258
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024),

0 commit comments

Comments
 (0)