aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorNanno Langstraat <langstr@gmail.com>2013-10-14 10:07:15 -0400
committerJiri Kosina <jkosina@suse.cz>2013-10-14 10:07:18 -0400
commit43c831468b3d26dbe8f2e061ccaf1abaf9cc1b8b (patch)
tree616481b3370d9f6dbfd38dd089d66e02eed3afac /drivers/hid
parent403cfb53fb450d53751fdc7ee0cd6652419612cf (diff)
HID: apple: option to swap the 'Option' ("Alt") and 'Command' ("Flag") keys.
Use case: people who use both Apple and PC keyboards regularly, and desire to keep&use their PC muscle memory. A particular use case: an Apple compact external keyboard connected to a PC laptop. (This use case can't be covered well by X.org key remappings etc.) Signed-off-by: Nanno Langstraat <langstr@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-apple.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 881cf7b4f9a4..3b219b9553fb 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -46,6 +46,12 @@ module_param(iso_layout, uint, 0644);
46MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. " 46MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
47 "(0 = disabled, [1] = enabled)"); 47 "(0 = disabled, [1] = enabled)");
48 48
49static unsigned int swap_opt_cmd = 0;
50module_param(swap_opt_cmd, uint, 0644);
51MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
52 "(For people who want to keep Windows PC keyboard muscle memory. "
53 "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
54
49struct apple_sc { 55struct apple_sc {
50 unsigned long quirks; 56 unsigned long quirks;
51 unsigned int fn_on; 57 unsigned int fn_on;
@@ -150,6 +156,14 @@ static const struct apple_key_translation apple_iso_keyboard[] = {
150 { } 156 { }
151}; 157};
152 158
159static const struct apple_key_translation swapped_option_cmd_keys[] = {
160 { KEY_LEFTALT, KEY_LEFTMETA },
161 { KEY_LEFTMETA, KEY_LEFTALT },
162 { KEY_RIGHTALT, KEY_RIGHTMETA },
163 { KEY_RIGHTMETA,KEY_RIGHTALT },
164 { }
165};
166
153static const struct apple_key_translation *apple_find_translation( 167static const struct apple_key_translation *apple_find_translation(
154 const struct apple_key_translation *table, u16 from) 168 const struct apple_key_translation *table, u16 from)
155{ 169{
@@ -242,6 +256,14 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
242 } 256 }
243 } 257 }
244 258
259 if (swap_opt_cmd) {
260 trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
261 if (trans) {
262 input_event(input, usage->type, trans->to, value);
263 return 1;
264 }
265 }
266
245 return 0; 267 return 0;
246} 268}
247 269