From: "José Expósito" <jose.exposito89@gmail.com>
To: Hilton Chain <hako@ultrarare.space>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
Bryan Cain <bryancain3@gmail.com>, Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: Re: [PATCH v5] HID: apple: Properly handle function keys on non-Apple keyboard
Date: Fri, 3 Jun 2022 19:53:16 +0200 [thread overview]
Message-ID: <20220603175316.GA18086@elementary> (raw)
In-Reply-To: <20220602161219.152be32d@ultrarare.space>
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 <hako@ultrarare.space>
Minor change from V4, feel free to add my:
Reviewed-by: José Expósito <jose.exposito89@gmail.com>
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
>
next prev parent reply other threads:[~2022-06-03 17:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-29 10:02 [PATCH] HID: apple: Reset quirks when Fn key is not found Hilton Chain
2022-05-29 18:20 ` José Expósito
2022-05-30 0:42 ` Hilton Chain
2022-05-30 1:42 ` [PATCH] HID: apple: Properly handle function keys on misset non-apple keyboards Hilton Chain
2022-05-30 6:18 ` [PATCH] HID: apple: Reset quirks when Fn key is not found José Expósito
2022-05-31 14:11 ` Hilton Chain
2022-05-31 14:33 ` [PATCH v2] HID: apple: Workaround for non-Apple keyboards Hilton Chain
2022-05-31 17:20 ` José Expósito
2022-05-31 19:50 ` Bryan Cain
2022-05-31 23:13 ` hako
2022-05-31 23:26 ` [PATCH v3] HID: apple: Properly handle function keys on non-Apple keyboard Hilton Chain
2022-06-01 4:17 ` [PATCH v4] " Hilton Chain
2022-06-01 17:49 ` José Expósito
2022-06-02 8:12 ` [PATCH v5] " Hilton Chain
2022-06-02 21:00 ` Bryan Cain
2022-06-03 17:53 ` José Expósito [this message]
2022-06-08 9:54 ` Jiri Kosina
2022-06-18 13:51 ` [PATCH v6] " Hilton Chain
2022-06-02 0:35 ` [PATCH v3] " Bryan Cain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220603175316.GA18086@elementary \
--to=jose.exposito89@gmail.com \
--cc=benjamin.tissoires@redhat.com \
--cc=bryancain3@gmail.com \
--cc=hako@ultrarare.space \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).