diff mbox series

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

Message ID 1C1C6D41-70E7-431A-850D-A5A1C15F88BE@live.com
State Superseded
Headers show
Series [RESEND,1/3] HID: apple: Use common table for MacBook Pro fn mapping | expand

Commit Message

Aditya Garg Feb. 13, 2025, 4:07 p.m. UTC
From: Aditya Garg <gargaditya08@live.com>

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 <gargaditya08@live.com>
---
 drivers/hid/hid-apple.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
diff mbox series

Patch

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;
 	}