Skip to content

Commit 892727d

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 c0cd2d1 commit 892727d

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 },
@@ -433,6 +449,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
433449
real_fnmode = 2;
434450
else
435451
real_fnmode = 1;
452+
} else if (fnmode == FKEYS_IGNORE) {
453+
real_fnmode = 2;
436454
} else {
437455
real_fnmode = fnmode;
438456
}
@@ -482,7 +500,10 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
482500
table = macbookpro_dedicated_esc_fn_keys;
483501
break;
484502
default:
485-
table = magic_keyboard_2021_and_2024_fn_keys;
503+
if (fnmode == FKEYS_IGNORE)
504+
table = apple_fn_keys_minimal;
505+
else
506+
table = magic_keyboard_2021_and_2024_fn_keys;
486507
break;
487508
}
488509
break;
@@ -719,6 +740,7 @@ static void apple_setup_input(struct input_dev *input)
719740

720741
/* Enable all needed keys */
721742
apple_setup_key_translation(input, apple_fn_keys);
743+
apple_setup_key_translation(input, apple_fn_keys_minimal);
722744
apple_setup_key_translation(input, powerbook_fn_keys);
723745
apple_setup_key_translation(input, powerbook_numlock_keys);
724746
apple_setup_key_translation(input, apple_iso_keyboard);
@@ -957,6 +979,11 @@ static int apple_probe(struct hid_device *hdev,
957979
hdev->type != HID_TYPE_SPI_KEYBOARD)
958980
return -ENODEV;
959981

982+
// key remapping will happen in xkeyboard-config so ignore
983+
// APPLE_ISO_TILDE_QUIRK
984+
if ((id->bus == BUS_SPI || id->bus == BUS_HOST) && fnmode == FKEYS_IGNORE)
985+
quirks &= ~APPLE_ISO_TILDE_QUIRK;
986+
960987
asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
961988
if (asc == NULL) {
962989
hid_err(hdev, "can't alloc apple descriptor\n");
@@ -1212,7 +1239,7 @@ static const struct hid_device_id apple_devices[] = {
12121239
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
12131240
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
12141241
{ HID_SPI_DEVICE(SPI_VENDOR_ID_APPLE, HID_ANY_ID),
1215-
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1242+
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK
12161243
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
12171244
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
12181245
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
@@ -1226,7 +1253,7 @@ static const struct hid_device_id apple_devices[] = {
12261253
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
12271254
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
12281255
{ HID_DEVICE(BUS_HOST, HID_GROUP_ANY, HOST_VENDOR_ID_APPLE, HID_ANY_ID),
1229-
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1256+
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK
12301257
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024),
12311258
.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
12321259
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024),

0 commit comments

Comments
 (0)