Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp6354876ioo; Thu, 2 Jun 2022 04:51:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3AfuZVIouH7RwZcN+M001pQJ2d0xTmaT4wyF7Q72/lTZOegfMKeJ96SxYGpTjAPGmVIhs X-Received: by 2002:a05:6402:524c:b0:42e:320:bfbc with SMTP id t12-20020a056402524c00b0042e0320bfbcmr5009292edd.65.1654170684919; Thu, 02 Jun 2022 04:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654170684; cv=none; d=google.com; s=arc-20160816; b=DNR0CujjE5YESO0j7zf0ZEP1lwI4EKoDMVzcbEsmFCOtg1kjBq+xDL5xVD0wuW5r8z vb/A4rRQvuXId5e7evROmK+UDFXyDQSgIJOWLa+PZFMgwA0HhlQPhMu+XymXraU+XMaQ GuE5fsZ2qEWwl8B8keQFEdocZtLZnG7WRddYY1LjD2YZMOLMP9jP9U7LQyJ7aaUd6LBI utLbJivvku4MQkzC3axnqcrbNL5O4Mh79um4Ct/ghi/oCg6X5Tq2F1dq5zMiuJGv0DPD XhUxmwIHaD1Kdwa1dxQqlHIiT9UjbS/Q9clsDkzthyJOkrzbBb7H4WmBkJ9/iYTuaK4K I2xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9MTqppfgRAlAl0ocM4Vnd0OF+AaNkKzf3y9bMt+MpcY=; b=dWG9gDLNxQNq2G+VqM9k2Q2Sqkq8EOCXIi/MtzcKF/wJ42EN3HH6KDT33SHjdbSvAs J/Ke6Mxjg++bFlNmd1NWxwGKemmq8Q+az8dJraNobQURxrlIOJ0diY/CTkEYFtaCpL8/ A9KNOrFzgSQQRcpxKE/Tr+0UEZpRpIr7hfJNNqWSpQRXk+j32EEcA8QUv1CINu3ds7M1 gSgVbRGvc8y5XPJqgIohO3JlbnX1NK2d6/rvL4596kFAX6J0TiHWhy+RVPwCwIVIwQb3 meqthcr5c0hq85PmxMFXBAyH37Y63U8l1Nmpm6hgdTQOgA+uJKLxj/CxHxsdJG2kU69l YH5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ultrarare.space header.s=dkim header.b=WUk9MDOH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=ultrarare.space Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a05640251cb00b0042bb1c099c5si4946575edd.399.2022.06.02.04.50.59; Thu, 02 Jun 2022 04:51:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ultrarare.space header.s=dkim header.b=WUk9MDOH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=ultrarare.space Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232087AbiFBIMv (ORCPT + 99 others); Thu, 2 Jun 2022 04:12:51 -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-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spamd-Bar: + Authentication-Results: mail.boiledscript.com; none X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 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 --- 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