diff mbox series

[1/1] HID: apple: Option to swap only left side mod keys

Message ID 20230522184013.42621-1-bruners@gmail.com
State Accepted
Commit 72e49cadea390556ca60fad973740ddc5587e408
Headers show
Series [1/1] HID: apple: Option to swap only left side mod keys | expand

Commit Message

Lasse Brun May 22, 2023, 6:40 p.m. UTC
On the Keychron K8 keyboard, and probably others, the right side keys
should not be swapped to maintain PC layout.

Swapping the right side keys moves 'Super' before 'Alt gr' which is not
intended by the default Keychron layout or the ISO layout.

Signed-off-by: Lasse Brun <bruners@gmail.com>
---
 drivers/hid/hid-apple.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Jiri Kosina June 9, 2023, 3:41 p.m. UTC | #1
On Mon, 22 May 2023, Lasse Brun wrote:

> On the Keychron K8 keyboard, and probably others, the right side keys
> should not be swapped to maintain PC layout.
> 
> Swapping the right side keys moves 'Super' before 'Alt gr' which is not
> intended by the default Keychron layout or the ISO layout.
> 
> Signed-off-by: Lasse Brun <bruners@gmail.com>

Applied, thanks, and sorry for the delay.
diff mbox series

Patch

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index cc535d2d6e8c..d7b932925730 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -58,7 +58,7 @@  static unsigned int swap_opt_cmd;
 module_param(swap_opt_cmd, uint, 0644);
 MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
 		"(For people who want to keep Windows PC keyboard muscle memory. "
-		"[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
+		"[0] = as-is, Mac layout. 1 = swapped, Windows layout., 2 = swapped, Swap only left side)");
 
 static unsigned int swap_ctrl_cmd;
 module_param(swap_ctrl_cmd, uint, 0644);
@@ -319,6 +319,12 @@  static const struct apple_key_translation swapped_option_cmd_keys[] = {
 	{ }
 };
 
+static const struct apple_key_translation swapped_option_cmd_left_keys[] = {
+	{ KEY_LEFTALT,	KEY_LEFTMETA },
+	{ KEY_LEFTMETA,	KEY_LEFTALT },
+	{ }
+};
+
 static const struct apple_key_translation swapped_ctrl_cmd_keys[] = {
 	{ KEY_LEFTCTRL,	KEY_LEFTMETA },
 	{ KEY_LEFTMETA,	KEY_LEFTCTRL },
@@ -416,7 +422,10 @@  static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
 	}
 
 	if (swap_opt_cmd) {
-		trans = apple_find_translation(swapped_option_cmd_keys, code);
+		if (swap_opt_cmd == 2)
+			trans = apple_find_translation(swapped_option_cmd_left_keys, code);
+		else
+			trans = apple_find_translation(swapped_option_cmd_keys, code);
 
 		if (trans)
 			code = trans->to;