Thread (3 messages) 3 messages, 1 author, 2025-02-13
DORMANTno replies

[PATCH RESEND 3/3] HID: apple: simplify logic for swapping only left sided option and command keys

From: Aditya Garg <hidden>
Date: 2025-02-13 16:07:43
Also in: lkml
Subsystem: hid core layer, the rest · Maintainers: Jiri Kosina, Benjamin Tissoires, Linus Torvalds

From: Aditya Garg <redacted>

In order to swap only left sided option and command keys a separate table
was in use. This commit makes use of the APPLE_FLAG_DONT_TRANSLATE flag to
remove the need of such separate tables.

Signed-off-by: Aditya Garg <redacted>
---
 drivers/hid/hid-apple.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index ca462e483..c672ffc97 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -285,14 +285,8 @@ static const struct apple_key_translation apple_iso_keyboard[] = {
 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 },
-	{ }
-};
-
-static const struct apple_key_translation swapped_option_cmd_left_keys[] = {
-	{ KEY_LEFTALT,	KEY_LEFTMETA },
-	{ KEY_LEFTMETA,	KEY_LEFTALT },
+	{ KEY_RIGHTALT,	KEY_RIGHTMETA, APPLE_FLAG_DONT_TRANSLATE },
+	{ KEY_RIGHTMETA, KEY_RIGHTALT, APPLE_FLAG_DONT_TRANSLATE },
 	{ }
 };
 
@@ -399,12 +393,9 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
 	}
 
 	if (swap_opt_cmd) {
-		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);
+		trans = apple_find_translation(swapped_option_cmd_keys, code);
 
-		if (trans)
+		if (trans && !(swap_opt_cmd == 2 && trans->flags & APPLE_FLAG_DONT_TRANSLATE))
 			code = trans->to;
 	}
 
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help