This commit extends fa33382c7f74 ("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]>
---
V3 -> V4: Removed unnecessary strlen()
drivers/hid/hid-apple.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 42a568902f49..4ec39c5e762a 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -36,7 +36,7 @@
#define APPLE_NUMLOCK_EMULATION BIT(8)
#define APPLE_RDESC_BATTERY BIT(9)
#define APPLE_BACKLIGHT_CTL BIT(10)
-#define APPLE_IS_KEYCHRON BIT(11)
+#define APPLE_IS_NON_APPLE BIT(11)
#define APPLE_FLAG_FKEY 0x01
@@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
"(For people who want to keep PC keyboard muscle memory. "
"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
+struct apple_non_apple_keyboard {
+ char *name;
+};
+
struct apple_sc_backlight {
struct led_classdev cdev;
struct hid_device *hdev;
@@ -313,6 +317,25 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
{ }
};
+static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
+ { "SONiX USB DEVICE" },
+ { "Keychron" },
+};
+
+static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
+ char *non_apple = non_apple_keyboards[i].name;
+
+ if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
+ return true;
+ }
+
+ return false;
+}
+
static inline void apple_setup_key_translation(struct input_dev *input,
const struct apple_key_translation *table)
{
@@ -363,7 +386,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
}
if (fnmode == 3) {
- real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
+ real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
} else {
real_fnmode = fnmode;
}
@@ -669,9 +692,9 @@ static int apple_input_configured(struct hid_device *hdev,
asc->quirks &= ~APPLE_HAS_FN;
}
- if (strncmp(hdev->name, "Keychron", 8) == 0) {
- hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
- asc->quirks |= APPLE_IS_KEYCHRON;
+ if (apple_is_non_apple_keyboard(hdev)) {
+ hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
+ asc->quirks |= APPLE_IS_NON_APPLE;
}
return 0;
base-commit: 700170bf6b4d773e328fa54ebb70ba444007c702
--
2.36.1
On Wed, Jun 01, 2022 at 12:17:37PM +0800, Hilton Chain wrote:
> This commit extends fa33382c7f74 ("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]>
v4 looks good to me, thanks for adding the suggested changes!
Reviewed-by: Jos? Exp?sito <[email protected]>
> ---
>
> V3 -> V4: Removed unnecessary strlen()
>
> drivers/hid/hid-apple.c | 33 ++++++++++++++++++++++++++++-----
> 1 file changed, 28 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 42a568902f49..4ec39c5e762a 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -36,7 +36,7 @@
> #define APPLE_NUMLOCK_EMULATION BIT(8)
> #define APPLE_RDESC_BATTERY BIT(9)
> #define APPLE_BACKLIGHT_CTL BIT(10)
> -#define APPLE_IS_KEYCHRON BIT(11)
> +#define APPLE_IS_NON_APPLE BIT(11)
>
> #define APPLE_FLAG_FKEY 0x01
>
> @@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
> "(For people who want to keep PC keyboard muscle memory. "
> "[0] = as-is, Mac layout, 1 = swapped, PC layout)");
>
> +struct apple_non_apple_keyboard {
> + char *name;
> +};
> +
> struct apple_sc_backlight {
> struct led_classdev cdev;
> struct hid_device *hdev;
> @@ -313,6 +317,25 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
> { }
> };
>
> +static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
> + { "SONiX USB DEVICE" },
> + { "Keychron" },
> +};
> +
> +static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
> + char *non_apple = non_apple_keyboards[i].name;
> +
> + if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
> + return true;
> + }
> +
> + return false;
> +}
> +
> static inline void apple_setup_key_translation(struct input_dev *input,
> const struct apple_key_translation *table)
> {
> @@ -363,7 +386,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
> }
>
> if (fnmode == 3) {
> - real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
> + real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
> } else {
> real_fnmode = fnmode;
> }
> @@ -669,9 +692,9 @@ static int apple_input_configured(struct hid_device *hdev,
> asc->quirks &= ~APPLE_HAS_FN;
> }
>
> - if (strncmp(hdev->name, "Keychron", 8) == 0) {
> - hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
> - asc->quirks |= APPLE_IS_KEYCHRON;
> + if (apple_is_non_apple_keyboard(hdev)) {
> + hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
> + asc->quirks |= APPLE_IS_NON_APPLE;
> }
>
> return 0;
>
> base-commit: 700170bf6b4d773e328fa54ebb70ba444007c702
> --
> 2.36.1
>
This commit extends fa33382c7f74 ("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]>
---
V4 -> V5: Add Varmilo keyboards' name "AONE" to the exception list
V3 -> V4: Remove unnecessary strlen()
drivers/hid/hid-apple.c | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 42a568902f49..7fbde58e1219 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -36,7 +36,7 @@
#define APPLE_NUMLOCK_EMULATION BIT(8)
#define APPLE_RDESC_BATTERY BIT(9)
#define APPLE_BACKLIGHT_CTL BIT(10)
-#define APPLE_IS_KEYCHRON BIT(11)
+#define APPLE_IS_NON_APPLE BIT(11)
#define APPLE_FLAG_FKEY 0x01
@@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
"(For people who want to keep PC keyboard muscle memory. "
"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
+struct apple_non_apple_keyboard {
+ char *name;
+};
+
struct apple_sc_backlight {
struct led_classdev cdev;
struct hid_device *hdev;
@@ -313,6 +317,26 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
{ }
};
+static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
+ { "SONiX USB DEVICE" },
+ { "Keychron" },
+ { "AONE" }
+};
+
+static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
+ char *non_apple = non_apple_keyboards[i].name;
+
+ if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
+ return true;
+ }
+
+ return false;
+}
+
static inline void apple_setup_key_translation(struct input_dev *input,
const struct apple_key_translation *table)
{
@@ -363,7 +387,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
}
if (fnmode == 3) {
- real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
+ real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
} else {
real_fnmode = fnmode;
}
@@ -669,9 +693,9 @@ static int apple_input_configured(struct hid_device *hdev,
asc->quirks &= ~APPLE_HAS_FN;
}
- if (strncmp(hdev->name, "Keychron", 8) == 0) {
- hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
- asc->quirks |= APPLE_IS_KEYCHRON;
+ if (apple_is_non_apple_keyboard(hdev)) {
+ hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
+ asc->quirks |= APPLE_IS_NON_APPLE;
}
return 0;
base-commit: d1dc87763f406d4e67caf16dbe438a5647692395
--
2.36.1
This version looks good, and works without issue on my Keychron C1.
Thanks for implementing it!
Reviewed-by: Bryan Cain <[email protected]>
Tested-by: Bryan Cain <[email protected]>
Regards,
Bryan
On Thu, Jun 2, 2022 at 2:12 AM Hilton Chain <[email protected]> wrote:
>
> This commit extends fa33382c7f74 ("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]>
> ---
>
> V4 -> V5: Add Varmilo keyboards' name "AONE" to the exception list
> V3 -> V4: Remove unnecessary strlen()
>
> drivers/hid/hid-apple.c | 34 +++++++++++++++++++++++++++++-----
> 1 file changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 42a568902f49..7fbde58e1219 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -36,7 +36,7 @@
> #define APPLE_NUMLOCK_EMULATION BIT(8)
> #define APPLE_RDESC_BATTERY BIT(9)
> #define APPLE_BACKLIGHT_CTL BIT(10)
> -#define APPLE_IS_KEYCHRON BIT(11)
> +#define APPLE_IS_NON_APPLE BIT(11)
>
> #define APPLE_FLAG_FKEY 0x01
>
> @@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
> "(For people who want to keep PC keyboard muscle memory. "
> "[0] = as-is, Mac layout, 1 = swapped, PC layout)");
>
> +struct apple_non_apple_keyboard {
> + char *name;
> +};
> +
> struct apple_sc_backlight {
> struct led_classdev cdev;
> struct hid_device *hdev;
> @@ -313,6 +317,26 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
> { }
> };
>
> +static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
> + { "SONiX USB DEVICE" },
> + { "Keychron" },
> + { "AONE" }
> +};
> +
> +static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
> + char *non_apple = non_apple_keyboards[i].name;
> +
> + if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
> + return true;
> + }
> +
> + return false;
> +}
> +
> static inline void apple_setup_key_translation(struct input_dev *input,
> const struct apple_key_translation *table)
> {
> @@ -363,7 +387,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
> }
>
> if (fnmode == 3) {
> - real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
> + real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
> } else {
> real_fnmode = fnmode;
> }
> @@ -669,9 +693,9 @@ static int apple_input_configured(struct hid_device *hdev,
> asc->quirks &= ~APPLE_HAS_FN;
> }
>
> - if (strncmp(hdev->name, "Keychron", 8) == 0) {
> - hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
> - asc->quirks |= APPLE_IS_KEYCHRON;
> + if (apple_is_non_apple_keyboard(hdev)) {
> + hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
> + asc->quirks |= APPLE_IS_NON_APPLE;
> }
>
> return 0;
>
> base-commit: d1dc87763f406d4e67caf16dbe438a5647692395
> --
> 2.36.1
>
On Thu, Jun 02, 2022 at 04:12:19PM +0800, Hilton Chain wrote:
> This commit extends fa33382c7f74 ("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]>
Minor change from V4, feel free to add my:
Reviewed-by: Jos? Exp?sito <[email protected]>
Jose
> ---
>
> V4 -> V5: Add Varmilo keyboards' name "AONE" to the exception list
> V3 -> V4: Remove unnecessary strlen()
>
> drivers/hid/hid-apple.c | 34 +++++++++++++++++++++++++++++-----
> 1 file changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 42a568902f49..7fbde58e1219 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -36,7 +36,7 @@
> #define APPLE_NUMLOCK_EMULATION BIT(8)
> #define APPLE_RDESC_BATTERY BIT(9)
> #define APPLE_BACKLIGHT_CTL BIT(10)
> -#define APPLE_IS_KEYCHRON BIT(11)
> +#define APPLE_IS_NON_APPLE BIT(11)
>
> #define APPLE_FLAG_FKEY 0x01
>
> @@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
> "(For people who want to keep PC keyboard muscle memory. "
> "[0] = as-is, Mac layout, 1 = swapped, PC layout)");
>
> +struct apple_non_apple_keyboard {
> + char *name;
> +};
> +
> struct apple_sc_backlight {
> struct led_classdev cdev;
> struct hid_device *hdev;
> @@ -313,6 +317,26 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
> { }
> };
>
> +static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
> + { "SONiX USB DEVICE" },
> + { "Keychron" },
> + { "AONE" }
> +};
> +
> +static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
> + char *non_apple = non_apple_keyboards[i].name;
> +
> + if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
> + return true;
> + }
> +
> + return false;
> +}
> +
> static inline void apple_setup_key_translation(struct input_dev *input,
> const struct apple_key_translation *table)
> {
> @@ -363,7 +387,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
> }
>
> if (fnmode == 3) {
> - real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
> + real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
> } else {
> real_fnmode = fnmode;
> }
> @@ -669,9 +693,9 @@ static int apple_input_configured(struct hid_device *hdev,
> asc->quirks &= ~APPLE_HAS_FN;
> }
>
> - if (strncmp(hdev->name, "Keychron", 8) == 0) {
> - hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
> - asc->quirks |= APPLE_IS_KEYCHRON;
> + if (apple_is_non_apple_keyboard(hdev)) {
> + hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
> + asc->quirks |= APPLE_IS_NON_APPLE;
> }
>
> return 0;
>
> base-commit: d1dc87763f406d4e67caf16dbe438a5647692395
> --
> 2.36.1
>
On Thu, 2 Jun 2022, Hilton Chain wrote:
> This commit extends fa33382c7f74 ("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]>
> ---
>
> V4 -> V5: Add Varmilo keyboards' name "AONE" to the exception list
> V3 -> V4: Remove unnecessary strlen()
Applied to hid.git, thank you.
--
Jiri Kosina
SUSE Labs
This commit extends fa33382c7f74 ("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]>
---
V5 -> V6: Add "GANSS" to the exception list.
I just found out my keyboard would use another name in bluetooth mode, as I
forgot to test this scenario... Sorry for the inconvenience!
drivers/hid/hid-apple.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 42a568902f492..3cf8eafe00b7b 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -36,7 +36,7 @@
#define APPLE_NUMLOCK_EMULATION BIT(8)
#define APPLE_RDESC_BATTERY BIT(9)
#define APPLE_BACKLIGHT_CTL BIT(10)
-#define APPLE_IS_KEYCHRON BIT(11)
+#define APPLE_IS_NON_APPLE BIT(11)
#define APPLE_FLAG_FKEY 0x01
@@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
"(For people who want to keep PC keyboard muscle memory. "
"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
+struct apple_non_apple_keyboard {
+ char *name;
+};
+
struct apple_sc_backlight {
struct led_classdev cdev;
struct hid_device *hdev;
@@ -313,6 +317,27 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
{ }
};
+static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
+ { "SONiX USB DEVICE" },
+ { "GANSS" },
+ { "Keychron" },
+ { "AONE" }
+};
+
+static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
+ char *non_apple = non_apple_keyboards[i].name;
+
+ if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
+ return true;
+ }
+
+ return false;
+}
+
static inline void apple_setup_key_translation(struct input_dev *input,
const struct apple_key_translation *table)
{
@@ -363,7 +388,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
}
if (fnmode == 3) {
- real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
+ real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
} else {
real_fnmode = fnmode;
}
@@ -669,9 +694,9 @@ static int apple_input_configured(struct hid_device *hdev,
asc->quirks &= ~APPLE_HAS_FN;
}
- if (strncmp(hdev->name, "Keychron", 8) == 0) {
- hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
- asc->quirks |= APPLE_IS_KEYCHRON;
+ if (apple_is_non_apple_keyboard(hdev)) {
+ hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
+ asc->quirks |= APPLE_IS_NON_APPLE;
}
return 0;
base-commit: 4b35035bcf80ddb47c0112c4fbd84a63a2836a18
--
2.36.1