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: 13031673 X-Patchwork-Delegate: jikos@jikos.cz 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 CCD34C433FE for ; Fri, 4 Nov 2022 11:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbiKDL4D (ORCPT ); Fri, 4 Nov 2022 07:56:03 -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/vxwY6ACgsUebiADdatibOZ5jN77KWX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bJfRzf+zxsWzSOAstPRyJjVtvETZfbnnl+Yk7v7bsbp/l9YYEKUwUcQjGV1Iy2Y9IqqrfP3GetOfOBxfZqW/Z/0VhaRdUENtc0fY+lGw0Hn5tCQZzUtM40OqiJv/hEd3I0W+qEywCc8C7s+gcBAA647PxhzYOtAHrDIIt13qXi6nn8lotCwML8f0PXycLvWt0G0XVFSdKYvCM9jyVcp+2lMiN8f7pdr3Lix5OBKeTsVPufjzEOoaGnq8fokv/YNCayNcErLnekwW71x4zcR8368ORCpX9miIvatXRkLe+Xjbj2/z4sJ1VbHgSlrSuRxB22KmqOE4oXPJUm0lnQIgh+8XKRX/5yOiB6/tS9Qp13f9+Nx7LYS097Qk5NA6vUw/gW+S9Vy2FVFeAzWyUz2V6zDElMh3Nv2rwyJDgWsCyAXajlpoLuVL/glUqRTTmz2ciDkwq/rMRD4oov8dbJCTqX5tpl57WTJr8c0xYg3rlG7/b7QaUBESWGIrjSBRg+CHGztuyOw3v52ipmOOlVGmrdTd8rcKRm6qbm3ejvWVuasb44BIg8kY4YODNOwsqR7nmTVmtDcOZtezZJqU1aDm+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 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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;