From patchwork Fri Nov 4 11:55:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 15488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp358465wru; Fri, 4 Nov 2022 05:09:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7IfN4AHz0bd5yGK5AUMPK07VlitZwM2gPty4M1BdZa2jXoGqs97AJqWuOJLMBKVmxrFAXr X-Received: by 2002:a17:907:b07:b0:7a8:beb3:aa2a with SMTP id h7-20020a1709070b0700b007a8beb3aa2amr33924186ejl.459.1667563797348; Fri, 04 Nov 2022 05:09:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667563797; cv=pass; d=google.com; s=arc-20160816; b=LBtfwDnJlZS8B/Sg2uv+gyjVe3xWsnShXoSJ8v/TXI4z63UX2XHUyzPkeRXQGI/l00 6PHdfCv0Grool87LMEIZklkZEMDi0TcuTXZF43sEZirR8jsANj/19IRMaT+lRG76RX7I SD1VOKhoPo5CRptPmSIzt0XTBqxnk/O8nfFfia/Gt4kkkk1JsnxQmiThGL5yb+KpUV3+ rKShp+DNh8GEgvYV0cmQKLCN1MJJnrUnLC+oQu+vuJWAecZxJrHOzLBI2Svv/9lyaT3P 6LvNJgg4WccAiy6ZfH/ymDxoZa7ZEzkcnVNTa26zM8iLprnJqxex5czMiI3pHpBCQKf7 YvXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:message-id:date :thread-index:thread-topic:subject:to:from:dkim-signature; bh=+AxIPdXcsYQrskZVcz927dpHO7YXP1jH9jfHvT5geFs=; b=CciAfWn13iFGyPxDui6sSkpKBLv140LrjAugVovJFQvoov41S7ZVixm4JoETzTBI7a OJ2wkJ2nBTXjy3jL92G07jBUs8bIa0uVaD07xbLANYB6dLzZ8fhYSeZF8K0Rn8W9f/Bv A0HCCP/QHPhdlUFe+zvAwlDGMSVA9JJJkMUSISizaUbkQ/7Q68CCdNY7TYeVF+eYvdi5 z4B/HNrTY7GuhL9xaSXFPH3bpnR+2Bc93JWLFSTA/qVP3Aow69Dv6sSvFPfhLEyEjhwl OR7Aice86o5XKUeA1EKYpm8yBzXSvr6vVj6y1tle9RfaHb9Jm56oFRBWzHhO0zc/oJ+v rDsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@live.com header.s=selector1 header.b=JRZf7xn3; arc=pass (i=1); 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=NONE sp=QUARANTINE dis=NONE) header.from=live.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r24-20020a1709064d1800b0073d74bcac8dsi4040735eju.513.2022.11.04.05.09.27; Fri, 04 Nov 2022 05:09:57 -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=@live.com header.s=selector1 header.b=JRZf7xn3; arc=pass (i=1); 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=NONE sp=QUARANTINE dis=NONE) header.from=live.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231607AbiKDL4E (ORCPT + 99 others); Fri, 4 Nov 2022 07:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbiKDLzk (ORCPT ); Fri, 4 Nov 2022 07:55:40 -0400 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2075.outbound.protection.outlook.com [40.92.102.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38AE323EB2; Fri, 4 Nov 2022 04:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gJBURa4VJmHhM4b5jMMqc7dCdfarHFfqHlZnWVQAFnhS5wuYXf5H0gO+ZyZokSoSQlNHa4zgpe37RznogyRzFf7FAevRbQxpkAfGDVSOEChS/DV6t0yj3PkJHKarGbU6XV8rVOWTAR13EV0d/yxIPx21x78lM+LPMse8TyED/sMUQp4C4UjX+KXs8YTUpvySTitU+ndBAoi4xdjoWMTDXSC8zFGmrzMbF1kHzFsBkevhcg9088SLDyDuisByn4BsMVQ5V+NtHGTEppClXidEMI5dVr4B3QIbtdVh4MXmkpQzFp1hULZbFhuKZfx4Jfsr0pPVknEmsFtSv0SGrJDUFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+AxIPdXcsYQrskZVcz927dpHO7YXP1jH9jfHvT5geFs=; b=c2f4+AUzH8YOxYGq+H/aVDPCppGjTBbx+jnphPABcjc1jpHnhW0ewZb37Lx+HRjuukS6BGepGhHTuwhi5LSgP/mJJXONwjImsOaM8QLfZh+81PgqxSJVLis4o4yxrPNV0g+gggKP19ziMuWwi14FNRjEOsYPirIiWqx7IsYARTLOfsAOZmS6fkGc3zUQ7rtVvq9BgDG0pToA6TVy6k0EcrtWZTr7wDh3v0ws40kArcV1Cvv5hjNxXxSfwnjPuapi+n3K0QHPA02tdpdZrC8dy3XT5DJ4M19TpMarwF6kfMO4oxpTHWF9WqND/YWWiBz5lAE8awx/8PX5RredfKd0Lg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+AxIPdXcsYQrskZVcz927dpHO7YXP1jH9jfHvT5geFs=; b=JRZf7xn3nLY/nfwfUizMls4TwsLkEw/aJTrO8etM5W79t6fIvwRCRQvaNVzzakQ/oLzikogMl20ofgI8mdvQUvnSSbmOhCEG73EZKVmH5lMFpUA9lrMoOtYUBiMWkgshSjc8gi7iJvYHCipGGx+OeczLzPst+RCH/vxk2R1iLSX1BwVZbW/Uqof+hHvYPTwWNl1Y7EDZuDoh7TsuXLFx58TSX6/8bpxtwgmn+W4otklkI7UC3WYiNap9sDb5AguDZeCI/lawo5ToiDV3RGloyO2DYrWGubxKhiGtBNpyU7kXq5nQsnpomXeP1qcaNQJ7VfUDL9eZcZqNmsvw8U8tsA== Received: from BM1PR01MB0931.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:2::9) by MAZPR01MB7843.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:24::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Fri, 4 Nov 2022 11:55:35 +0000 Received: from BM1PR01MB0931.INDPRD01.PROD.OUTLOOK.COM ([fe80::3dc1:f6bc:49e4:b294]) by BM1PR01MB0931.INDPRD01.PROD.OUTLOOK.COM ([fe80::3dc1:f6bc:49e4:b294%9]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 11:55:35 +0000 From: Aditya Garg To: Jiri Kosina , "jkosina@suse.cz" , "benjamin.tissoires@redhat.com" , "linux-kernel@vger.kernel.org" , "linux-input@vger.kernel.org" Subject: [PATCH] HID: apple: Swap Control and Command keys on Apple keyboards Thread-Topic: [PATCH] HID: apple: Swap Control and Command keys on Apple keyboards Thread-Index: AQHY8ERZa3FoKSDxwkSesm/DJoXoaA== Date: Fri, 4 Nov 2022 11:55:35 +0000 Message-ID: <7AC64680-44F7-4605-95E9-B5FF97A78D2A@live.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [O0hB9y7RIPkVCcCO1Vy2KK5KnBzrGVR/] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BM1PR01MB0931:EE_|MAZPR01MB7843:EE_ x-ms-office365-filtering-correlation-id: 9dd6f6cf-cafd-4a2c-5cfd-08dabe5b7b98 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: JAl+VE5zpwasPoDcztDjSmqJgV83QJyzN3qQYE2DhxjXC9hHmFszBhaa0L4sT7CwdAzIz+QLlKRuwtkJlH6CebjCuonK3GFnlj5YUNv263ZBcVOoFFPfplBxUBAPzxLSER5mtxD0Maf3GT5NqIcO/vxwY6ACgsUebiADdatibOZ5jN77KWXKSOV1goWt0Wo0nN0onZXaQLl1pTg3/NcgypxdW3Pzu2Q1LcvdAy43Tm5MkHXIMTiC2egD/CGRWtY68z37BKZ0DRO4JprYXUuFkIX1xQJEih9OUqtkEjXdJd7nHeZgMqq9FLUanQH5M4w0MtfeZF1FXPHbCidzxV1B/aGrjsaLnT/TqH9bc9mlyo1eaWa6U57yPRqYxRQTGFO6f3R0XpYHojtNpGxvXNaIZrMezR1QH/n9zH24gTCFS8UI50Nf+DrELCgFq9SBb5Wf0dE5bvBAvPvcgcRC2GeqKtdy9WfRpEZI50DwUU/Xy6bIQLT7TOeA8ugNEXwiAuysw4/VHQ6TbgWXkr1nrAidXBlwGjRHuXMBFAkktXBbHQXMaz7Xs80wfLQ9OO6b+H/6UqYFa+tI00uPXh6R4eD3l0QIcalrd1qqIcBUvNwCUUJDSPEOFGle6m2MtzTEei6xEhOMKKkQbPSlQdGZcHGsig== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-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OOlVGmrdTd8rcKRm6qbm3ejvWVuasb44BIg8kY4YODNOwsqR7nmTVmtDcOZtezZJqU1aDm+BHlD1iuOmm8P1thSxzE7IoUqKFUOgdBXrCBSd+/nb72UXte/+NZ9P/zstEYRSbUC9Sp5oFNlyGhFZYg8yijTlUVMPpnMdQxUVBBWUoi4f9fbEu3HiA6NzgkLMsktgoXNyOQWNmn9IxUTeIxkWvgRsjJMBwzx/KWv+0x4eLvMoM5Eb3QsOYA== Content-ID: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-42ed3.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BM1PR01MB0931.INDPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 9dd6f6cf-cafd-4a2c-5cfd-08dabe5b7b98 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Nov 2022 11:55:35.0919 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MAZPR01MB7843 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748567376485305100?= X-GMAIL-MSGID: =?utf-8?q?1748567376485305100?= From: Aditya Garg This patch allows users to swap the control and command keys. This can be useful for the Mac users who are used to using Command instead of Control in macOS for various commonly used shortcuts. Signed-off-by: Aditya Garg --- drivers/hid/hid-apple.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index c671ce946..86188e803 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -59,6 +59,12 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") "(For people who want to keep Windows PC keyboard muscle memory. " "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)"); +static unsigned int swap_ctrl_cmd; +module_param(swap_ctrl_cmd, uint, 0644); +MODULE_PARM_DESC(swap_ctrl_cmd, "Swap the Control (\"Ctrl\") and Command (\"Flag\") keys. " + "(For people who are used to Mac shortcuts involving Command instead of Control. " + "[0] = No change. 1 = Swapped.)"); + static unsigned int swap_fn_leftctrl; module_param(swap_fn_leftctrl, uint, 0644); MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. " @@ -308,7 +314,15 @@ static const struct apple_key_translation swapped_option_cmd_keys[] = { { KEY_LEFTALT, KEY_LEFTMETA }, { KEY_LEFTMETA, KEY_LEFTALT }, { KEY_RIGHTALT, KEY_RIGHTMETA }, - { KEY_RIGHTMETA,KEY_RIGHTALT }, + { KEY_RIGHTMETA, KEY_RIGHTALT }, + { } +}; + +static const struct apple_key_translation swapped_ctrl_cmd_keys[] = { + { KEY_LEFTCTRL, KEY_LEFTMETA }, + { KEY_LEFTMETA, KEY_LEFTCTRL }, + { KEY_RIGHTCTRL, KEY_RIGHTMETA }, + { KEY_RIGHTMETA, KEY_RIGHTCTRL }, { } }; @@ -407,6 +421,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, code = trans->to; } + if (swap_ctrl_cmd) { + trans = apple_find_translation(swapped_ctrl_cmd_keys, code); + + if (trans) + code = trans->to; + } + if (code == KEY_FN) asc->fn_on = !!value;