Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5976732ioo; Wed, 1 Jun 2022 17:35:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPUj0m8JrvW5e9CASTpSsQNaSlOD1x9Cy23edZD7NcNGDg9Y1tg/FQD3mOzv4SMdlZroZY X-Received: by 2002:a17:903:288:b0:15f:a13:dfd5 with SMTP id j8-20020a170903028800b0015f0a13dfd5mr2095453plr.55.1654130157826; Wed, 01 Jun 2022 17:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654130157; cv=none; d=google.com; s=arc-20160816; b=v6IL0MK8DcqmgTv1aBShVgoZc+7M+vPUAijZYSDivF9WIzJceKkk/lYa+Oo8ggaBFV FS8ErY5PR9JQEsMpcbRDUO8+AwxaTo66U9ZHrn14D6SVcdDkxVK6fkcAs7iW1ikEJEGP uXHv6AXcj+kiA+CPqrfxoTyzlEXfbzj4jCoViGrhSdbaA0/GScy1rFfcTjyCujZ7v+M2 pW8zs1mraeK7jQXiXqqYVh2GY0rV+I1z7uD+dVsZV3NJy658bRsYRg/q7LaiDhjN4E3r JOL2Yuyq3OkaMEvbUa3YnOhcd13qf9oHQsCfY7a8rYR+Fr8dBEKu10N53kzYFltvym9Y b04Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qGfyFYtQBkhs1bsnCGTcxZHUxBKDfuhR4+aet0HmgBo=; b=q9y5VmG694zWT1BZO4KHzn76tiYJBex50nBuW9nL6/8NtbDtlWuZU6iZlLPSZWtxE1 NgEgyUKpVdGBNXYUsvU2Mgn0YMLTnVXetf05N2c/uNenL6kOPRDQddVGIk/tXlviMXZk t4pFnU/QvJgaJTyp09RgfG5wQ6VZT3PhOTfibt9Wn3qFRW1wiRSatWFFlGY+b6EjxqL1 h5t4ggSpN0JIZ3BEMzlyuCUtmHeOdImrHIFA9JsSQYwmkbUAE7QCWXQv/TwIp003Yqeu H5Rv+lapu8ZynjnRDkuJvdIp4YCZHQfEbR/NkZipcf5XYu51k0eGDdIACXowBZg/6Hf6 P7Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="VeHJrgo/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y18-20020a637d12000000b003fc2d54a867si4779777pgc.180.2022.06.01.17.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="VeHJrgo/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 70A8529C126; Wed, 1 Jun 2022 17:35:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232791AbiFBAf0 (ORCPT + 99 others); Wed, 1 Jun 2022 20:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbiFBAfZ (ORCPT ); Wed, 1 Jun 2022 20:35:25 -0400 Received: from mail-vs1-xe2c.google.com (mail-vs1-xe2c.google.com [IPv6:2607:f8b0:4864:20::e2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83CA929B2F6; Wed, 1 Jun 2022 17:35:22 -0700 (PDT) Received: by mail-vs1-xe2c.google.com with SMTP id k4so3239771vsp.3; Wed, 01 Jun 2022 17:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qGfyFYtQBkhs1bsnCGTcxZHUxBKDfuhR4+aet0HmgBo=; b=VeHJrgo/y8ZGDzRNHgPEjLU52Wlr0JxZdvtA61TLoXo+5gojdFkUd8Oz7UYSRhJ7He Fi4VybCUB9O1dDdFMKyGZ9FfBG2F2yiA8IYdLGMwB4xx31ZHyQOpT0TRI7VZ6DmmR8Oi MUC0CQLYeUjEp3do+v3NjwSqYfFIUUTCm3g9mFdmpt3jgfPNXsZfPztBpEH1HmvAmD3z QCfoUCek/rC1B2I72UJMRhsLRmOEJ2+Oy9Ysw/cRjvU6xykRbgNLbxj+IY2kupMWpRw0 Qhxj06Y9sc1eVRCMFgKc56V+lOkaJq4h3kHXBTzcObalgQHEr65O4bzFtLCn4WJ841B8 ye3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qGfyFYtQBkhs1bsnCGTcxZHUxBKDfuhR4+aet0HmgBo=; b=BJMe9IBtq0SZKUvi76P4TQYiZWFc6erGdJ3buCyv5yc9abssWIiJHdlr4fiERQ0K+H Q+p+XNCJCDhExw5uTiQdYgg19Jp7ph3EgjuchsbQAEwniLkTfcrpbtYbUqbVu2eykCB3 fIjlgdKvcPOVX6bQY24ETcXqvB5Kiw2Mb6ra5SulEYkyYNqc5I5KVSvEMmJ1tN1x9fGP sqrDdsP+0PrKz4o1Ue2OnKAZOjAKEpoR6pVIHFrQMfq6bkUQ+NisaT5OyZuH6er8E8Vk ZOGsIjKAz8dn4rxKaRzAVr9LeiLODX8qFvEcDJSQ67LBmgYKxzB6OZZ8a2nvsdXl+O7c Lzew== X-Gm-Message-State: AOAM531efdcodByRGiD3xYAwcQLcGRYPHpcZ5YviciZ8SkxWAgLuhOtM Vbpx3/l/5HZsLAwsTSbbdTnfagU11DaZ718c1F0= X-Received: by 2002:a67:8cc8:0:b0:349:e357:c679 with SMTP id o191-20020a678cc8000000b00349e357c679mr980534vsd.61.1654130121601; Wed, 01 Jun 2022 17:35:21 -0700 (PDT) MIME-Version: 1.0 References: <20220529180230.17e9a0f9@ultrarare.space> <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> In-Reply-To: <20220601072651.242ce08a@ultrarare.space> From: Bryan Cain Date: Wed, 1 Jun 2022 18:35:10 -0600 Message-ID: Subject: Re: [PATCH v3] HID: apple: Properly handle function keys on non-Apple keyboard To: Hilton Chain Cc: =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I can't reply to v4 since I wasn't cc'd on that one and I'm not subscribed to the mailing list, but while I haven't tested it yet, it looks good. The only feedback I have is that according to my searching[1][2][3], Varmilo keyboards pretending to be Apple devices report themselves as "AONE Varmilo Keyboard", so it might be a good idea to add "AONE" to the list of clone vendors. Regards, Bryan [1] https://geekhack.org/index.php?topic=110250.msg3013629#msg3013629 [2] https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1750654.html [3] https://forums.servethehome.com/index.php?threads/varmilo-keyboard-fn-keys-under-linux.29041/ On Tue, May 31, 2022 at 5:27 PM 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 > --- > 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..7d56530d9e3a 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 (strlen(non_apple) && 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: e1cbc3b96a9974746b2a80c3a6c8a0f7eff7b1b5 > -- > 2.36.1 >