Skip to content

Commit a0a0505

Browse files
rakinoJiri Kosina
authored and
Jiri Kosina
committed
HID: apple: Properly handle function keys on non-Apple keyboard
This commit extends fa33382 ("HID: apple: Properly handle function keys on Keychron keyboards") by adding an array of known non-Apple keyboards' device names, and the function apple_is_non_apple_keyboard() to identify and create exception for them. Signed-off-by: Hilton Chain <[email protected]> Reviewed-by: Bryan Cain <[email protected]> Tested-by: Bryan Cain <[email protected]> Reviewed-by: José Expósito <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent aa051d3 commit a0a0505

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

drivers/hid/hid-apple.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define APPLE_NUMLOCK_EMULATION BIT(8)
3737
#define APPLE_RDESC_BATTERY BIT(9)
3838
#define APPLE_BACKLIGHT_CTL BIT(10)
39-
#define APPLE_IS_KEYCHRON BIT(11)
39+
#define APPLE_IS_NON_APPLE BIT(11)
4040

4141
#define APPLE_FLAG_FKEY 0x01
4242

@@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
6565
"(For people who want to keep PC keyboard muscle memory. "
6666
"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
6767

68+
struct apple_non_apple_keyboard {
69+
char *name;
70+
};
71+
6872
struct apple_sc_backlight {
6973
struct led_classdev cdev;
7074
struct hid_device *hdev;
@@ -313,6 +317,26 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
313317
{ }
314318
};
315319

320+
static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
321+
{ "SONiX USB DEVICE" },
322+
{ "Keychron" },
323+
{ "AONE" }
324+
};
325+
326+
static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
327+
{
328+
int i;
329+
330+
for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
331+
char *non_apple = non_apple_keyboards[i].name;
332+
333+
if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
334+
return true;
335+
}
336+
337+
return false;
338+
}
339+
316340
static inline void apple_setup_key_translation(struct input_dev *input,
317341
const struct apple_key_translation *table)
318342
{
@@ -363,7 +387,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
363387
}
364388

365389
if (fnmode == 3) {
366-
real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
390+
real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
367391
} else {
368392
real_fnmode = fnmode;
369393
}
@@ -669,9 +693,9 @@ static int apple_input_configured(struct hid_device *hdev,
669693
asc->quirks &= ~APPLE_HAS_FN;
670694
}
671695

672-
if (strncmp(hdev->name, "Keychron", 8) == 0) {
673-
hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
674-
asc->quirks |= APPLE_IS_KEYCHRON;
696+
if (apple_is_non_apple_keyboard(hdev)) {
697+
hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
698+
asc->quirks |= APPLE_IS_NON_APPLE;
675699
}
676700

677701
return 0;

0 commit comments

Comments
 (0)