From nobody Tue Apr 28 09:09:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44627C43334 for ; Thu, 2 Jun 2022 08:12:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232089AbiFBIMw (ORCPT ); Thu, 2 Jun 2022 04:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbiFBIMt (ORCPT ); Thu, 2 Jun 2022 04:12:49 -0400 Received: from mail.boiledscript.com (unknown [192.151.158.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46554235103; Thu, 2 Jun 2022 01:12:42 -0700 (PDT) Received: from localhost (unknown [192.168.203.1]) by mail.boiledscript.com (Postfix) with ESMTP id 2A9B1300A0B; Thu, 2 Jun 2022 08:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ultrarare.space; s=dkim; t=1654157556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9MTqppfgRAlAl0ocM4Vnd0OF+AaNkKzf3y9bMt+MpcY=; b=WUk9MDOHtCN/SOtKX+PmZ4BO/nW+bPTVqbpA13pSCvKugr1v4+VUvWlBKHLLMD8kLeGz0p NZWt/bw1DOkF5H1aJ4gB617dO4N3JNQTCWtg3OypAHptdctFVmPZfzvLMOT0gjNy1EuZSX wqAbFTeSso8aY7TDhm4mvd13jY+B2E0cpSK3ApWc94p9WljA00/LuyOq+iAn/vX4k9tthK uqj+HcyB1OCQzpVDkJ8U3RQGLMUx52qyhsZ71UVFHz/AFblgdE7ciQA5m+22jDfWtIP2be CNa8Fst9VSypiCTtUwczdDKvwVRA9wJ66RpROI8TcFtQlW6GM4E43DLAzGnWKw== Date: Thu, 2 Jun 2022 16:12:19 +0800 From: Hilton Chain To: =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Bryan Cain , Jiri Kosina , Benjamin Tissoires Subject: [PATCH v5] HID: apple: Properly handle function keys on non-Apple keyboard Message-ID: <20220602161219.152be32d@ultrarare.space> In-Reply-To: <20220601174956.GA10418@elementary> References: <20220529182036.10226-1-jose.exposito89@gmail.com> <20220530083752.1973a905@ultrarare.space> <20220530061812.GA10391@elementary> <20220531221102.7bd7da7d@ultrarare.space> <20220531223330.3d63e2fe@ultrarare.space> <20220531172053.GA10651@elementary> <7f67ac07b8bd37d5817cd151674cc6b0@ultrarare.space> <20220601072651.242ce08a@ultrarare.space> <20220601121737.1226ffea@ultrarare.space> <20220601174956.GA10418@elementary> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: + Authentication-Results: mail.boiledscript.com; none Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Bryan Cain Reviewed-by: Jos=C3=A9 Exp=C3=B3sito Tested-by: Bryan Cain --- 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) =20 #define APPLE_FLAG_FKEY 0x01 =20 @@ -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] =3D as-is, Mac layout, 1 =3D swapped, PC layout)"); =20 +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_l= eftctrl_keys[] =3D { { } }; =20 +static const struct apple_non_apple_keyboard non_apple_keyboards[] =3D { + { "SONiX USB DEVICE" }, + { "Keychron" }, + { "AONE" } +}; + +static bool apple_is_non_apple_keyboard(struct hid_device *hdev) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(non_apple_keyboards); i++) { + char *non_apple =3D non_apple_keyboards[i].name; + + if (strncmp(hdev->name, non_apple, strlen(non_apple)) =3D=3D 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, } =20 if (fnmode =3D=3D 3) { - real_fnmode =3D (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1; + real_fnmode =3D (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1; } else { real_fnmode =3D fnmode; } @@ -669,9 +693,9 @@ static int apple_input_configured(struct hid_device *hd= ev, asc->quirks &=3D ~APPLE_HAS_FN; } =20 - if (strncmp(hdev->name, "Keychron", 8) =3D=3D 0) { - hid_info(hdev, "Keychron keyboard detected; function keys will default t= o fnmode=3D2 behavior\n"); - asc->quirks |=3D APPLE_IS_KEYCHRON; + if (apple_is_non_apple_keyboard(hdev)) { + hid_info(hdev, "Non-apple keyboard detected; function keys will default = to fnmode=3D2 behavior\n"); + asc->quirks |=3D APPLE_IS_NON_APPLE; } =20 return 0; base-commit: d1dc87763f406d4e67caf16dbe438a5647692395 --=20 2.36.1