diff mbox series

hid: apple: disable Fn key handling on the Omoton KB066

Message ID 20250224053632.2800-1-alexhenrie24@gmail.com (mailing list archive)
State New
Delegated to: Jiri Kosina
Headers show
Series hid: apple: disable Fn key handling on the Omoton KB066 | expand

Commit Message

Alex Henrie Feb. 24, 2025, 5:36 a.m. UTC
Remove the fixup to make the Omoton KB066's F6 key F6 when not holding
Fn. That was really just a hack to allow typing F6 in fnmode>0, and it
didn't fix any of the other F keys that were likewise untypable in
fnmode>0. Instead, because the Omoton's Fn key is entirely internal to
the keyboard, completely disable Fn key translation when an Omoton is
detected, which will prevent the hid-apple driver from interfering with
the keyboard's built-in Fn key handling. All of the F keys, including
F6, are then typable when Fn is held.

The Omoton KB066 and the Apple A1255 both have HID product code
05ac:022c. The self-reported name of every original A1255 when they left
the factory was "Apple Wireless Keyboard". By default, Mac OS changes
the name to "<username>'s keyboard" when pairing with the keyboard, but
Mac OS allows the user to set the internal name of Apple keyboards to
anything they like. The Omoton KB066's name, on the other hand, is not
configurable: It is always "Bluetooth Keyboard". Because that name is so
generic that a user might conceivably use the same name for a real Apple
keyboard, detect Omoton keyboards based on both having that exact name
and having HID product code 022c.

Fixes: 819083cb6eed ("HID: apple: fix up the F6 key on the Omoton KB066 keyboard")
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 drivers/hid/hid-apple.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Aditya Garg Feb. 24, 2025, 5:40 a.m. UTC | #1
I was about to send something similar

> On 24 Feb 2025, at 11:07 AM, Alex Henrie <alexhenrie24@gmail.com> wrote:
> 
> Remove the fixup to make the Omoton KB066's F6 key F6 when not holding
> Fn. That was really just a hack to allow typing F6 in fnmode>0, and it
> didn't fix any of the other F keys that were likewise untypable in
> fnmode>0. Instead, because the Omoton's Fn key is entirely internal to
> the keyboard, completely disable Fn key translation when an Omoton is
> detected, which will prevent the hid-apple driver from interfering with
> the keyboard's built-in Fn key handling. All of the F keys, including
> F6, are then typable when Fn is held.
> 
> The Omoton KB066 and the Apple A1255 both have HID product code
> 05ac:022c. The self-reported name of every original A1255 when they left
> the factory was "Apple Wireless Keyboard". By default, Mac OS changes
> the name to "<username>'s keyboard" when pairing with the keyboard, but
> Mac OS allows the user to set the internal name of Apple keyboards to
> anything they like. The Omoton KB066's name, on the other hand, is not
> configurable: It is always "Bluetooth Keyboard". Because that name is so
> generic that a user might conceivably use the same name for a real Apple
> keyboard, detect Omoton keyboards based on both having that exact name
> and having HID product code 022c.
> 
> Fixes: 819083cb6eed ("HID: apple: fix up the F6 key on the Omoton KB066 keyboard")
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
> drivers/hid/hid-apple.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 49812a76b7ed..d900dd05c335 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -378,6 +378,12 @@ static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
>    return false;
> }
> 
> +static bool apple_is_omoton_kb066(struct hid_device *hdev)
> +{
> +    return hdev->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI &&
> +        strcmp(hdev->name, "Bluetooth Keyboard") == 0;
> +}
> +

Should be make a table here so that similar keyboards who want fn to be disabled can be put?

> static inline void apple_setup_key_translation(struct input_dev *input,
>        const struct apple_key_translation *table)
> {
> @@ -546,9 +552,6 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
>        }
>    }
> 
> -    if (usage->hid == 0xc0301) /* Omoton KB066 quirk */
> -        code = KEY_F6;
> -
>    if (usage->code != code) {
>        input_event_with_scancode(input, usage->type, code, usage->hid, value);
> 
> @@ -728,7 +731,7 @@ static int apple_input_configured(struct hid_device *hdev,
> {
>    struct apple_sc *asc = hid_get_drvdata(hdev);
> 
> -    if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
> +    if (((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) || apple_is_omoton_kb066(hdev)) {
>        hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");

Probably change the message here to Fn key not found or has internal handling

>        asc->quirks &= ~APPLE_HAS_FN;
>    }
> --
> 2.48.1
> 

Thanks
Aditya
Alex Henrie Feb. 24, 2025, 5:48 a.m. UTC | #2
On Sun, Feb 23, 2025 at 10:40 PM Aditya Garg <gargaditya08@live.com> wrote:

> > On 24 Feb 2025, at 11:07 AM, Alex Henrie <alexhenrie24@gmail.com> wrote:

> > +static bool apple_is_omoton_kb066(struct hid_device *hdev)
> > +{
> > +    return hdev->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI &&
> > +        strcmp(hdev->name, "Bluetooth Keyboard") == 0;
> > +}
> > +
>
> Should be make a table here so that similar keyboards who want fn to be disabled can be put?

Since there is only one known keyboard with this problem right now, a
table seems superfluous, but I would be happy to add one if the
maintainers want it.

> > -    if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
> > +    if (((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) || apple_is_omoton_kb066(hdev)) {
> >        hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");
>
> Probably change the message here to Fn key not found or has internal handling

In my opinion, we don't need to change the message. If we found an
Omoton keyboard, that means that the Fn key that we found in the HID
descriptor isn't real, so it's fair to say that we did not find an Fn
key.

Thanks for the feedback.

-Alex
Aditya Garg Feb. 24, 2025, 5:54 a.m. UTC | #3
> On 24 Feb 2025, at 11:18 AM, Alex Henrie <alexhenrie24@gmail.com> wrote:
> 
> On Sun, Feb 23, 2025 at 10:40 PM Aditya Garg <gargaditya08@live.com> wrote:
> 
>>> On 24 Feb 2025, at 11:07 AM, Alex Henrie <alexhenrie24@gmail.com> wrote:
> 
>>> +static bool apple_is_omoton_kb066(struct hid_device *hdev)
>>> +{
>>> +    return hdev->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI &&
>>> +        strcmp(hdev->name, "Bluetooth Keyboard") == 0;
>>> +}
>>> +
>> 
>> Should be make a table here so that similar keyboards who want fn to be disabled can be put?
> 
> Since there is only one known keyboard with this problem right now, a
> table seems superfluous, but I would be happy to add one if the
> maintainers want it.
> 
>>> -    if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
>>> +    if (((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) || apple_is_omoton_kb066(hdev)) {
>>>       hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");
>> 
>> Probably change the message here to Fn key not found or has internal handling
> 
> In my opinion, we don't need to change the message. If we found an
> Omoton keyboard, that means that the Fn key that we found in the HID
> descriptor isn't real, so it's fair to say that we did not find an Fn
> key.
> 

Fair enough, lets see what Jiri decides.
Aditya Garg Feb. 24, 2025, 6:22 a.m. UTC | #4
> On 24 Feb 2025, at 11:07 AM, Alex Henrie <alexhenrie24@gmail.com> wrote:
> 
> Remove the fixup to make the Omoton KB066's F6 key F6 when not holding
> Fn. That was really just a hack to allow typing F6 in fnmode>0, and it
> didn't fix any of the other F keys that were likewise untypable in
> fnmode>0. Instead, because the Omoton's Fn key is entirely internal to
> the keyboard, completely disable Fn key translation when an Omoton is
> detected, which will prevent the hid-apple driver from interfering with
> the keyboard's built-in Fn key handling. All of the F keys, including
> F6, are then typable when Fn is held.
> 
> The Omoton KB066 and the Apple A1255 both have HID product code
> 05ac:022c. The self-reported name of every original A1255 when they left
> the factory was "Apple Wireless Keyboard". By default, Mac OS changes
> the name to "<username>'s keyboard" when pairing with the keyboard, but
> Mac OS allows the user to set the internal name of Apple keyboards to
> anything they like. The Omoton KB066's name, on the other hand, is not
> configurable: It is always "Bluetooth Keyboard". Because that name is so
> generic that a user might conceivably use the same name for a real Apple
> keyboard, detect Omoton keyboards based on both having that exact name
> and having HID product code 022c.
> 
> Fixes: 819083cb6eed ("HID: apple: fix up the F6 key on the Omoton KB066 keyboard")
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---

Reviewed-by: Aditya Garg <gargaditya08@live.com>
diff mbox series

Patch

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 49812a76b7ed..d900dd05c335 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -378,6 +378,12 @@  static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
 	return false;
 }
 
+static bool apple_is_omoton_kb066(struct hid_device *hdev)
+{
+	return hdev->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI &&
+		strcmp(hdev->name, "Bluetooth Keyboard") == 0;
+}
+
 static inline void apple_setup_key_translation(struct input_dev *input,
 		const struct apple_key_translation *table)
 {
@@ -546,9 +552,6 @@  static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
 		}
 	}
 
-	if (usage->hid == 0xc0301) /* Omoton KB066 quirk */
-		code = KEY_F6;
-
 	if (usage->code != code) {
 		input_event_with_scancode(input, usage->type, code, usage->hid, value);
 
@@ -728,7 +731,7 @@  static int apple_input_configured(struct hid_device *hdev,
 {
 	struct apple_sc *asc = hid_get_drvdata(hdev);
 
-	if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
+	if (((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) || apple_is_omoton_kb066(hdev)) {
 		hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");
 		asc->quirks &= ~APPLE_HAS_FN;
 	}