@@ -59,6 +59,12 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\")
59
59
"(For people who want to keep Windows PC keyboard muscle memory. "
60
60
"[0] = as-is, Mac layout. 1 = swapped, Windows layout.)" );
61
61
62
+ static unsigned int swap_ctrl_cmd ;
63
+ module_param (swap_ctrl_cmd , uint , 0644 );
64
+ MODULE_PARM_DESC (swap_ctrl_cmd , "Swap the Control (\"Ctrl\") and Command (\"Flag\") keys. "
65
+ "(For people who are used to Mac shortcuts involving Command instead of Control. "
66
+ "[0] = No change. 1 = Swapped.)" );
67
+
62
68
static unsigned int swap_fn_leftctrl ;
63
69
module_param (swap_fn_leftctrl , uint , 0644 );
64
70
MODULE_PARM_DESC (swap_fn_leftctrl , "Swap the Fn and left Control keys. "
@@ -308,12 +314,21 @@ static const struct apple_key_translation swapped_option_cmd_keys[] = {
308
314
{ KEY_LEFTALT , KEY_LEFTMETA },
309
315
{ KEY_LEFTMETA , KEY_LEFTALT },
310
316
{ KEY_RIGHTALT , KEY_RIGHTMETA },
311
- { KEY_RIGHTMETA ,KEY_RIGHTALT },
317
+ { KEY_RIGHTMETA , KEY_RIGHTALT },
318
+ { }
319
+ };
320
+
321
+ static const struct apple_key_translation swapped_ctrl_cmd_keys [] = {
322
+ { KEY_LEFTCTRL , KEY_LEFTMETA },
323
+ { KEY_LEFTMETA , KEY_LEFTCTRL },
324
+ { KEY_RIGHTCTRL , KEY_RIGHTMETA },
325
+ { KEY_RIGHTMETA , KEY_RIGHTCTRL },
312
326
{ }
313
327
};
314
328
315
329
static const struct apple_key_translation swapped_fn_leftctrl_keys [] = {
316
330
{ KEY_FN , KEY_LEFTCTRL },
331
+ { KEY_LEFTCTRL , KEY_FN },
317
332
{ }
318
333
};
319
334
@@ -375,24 +390,47 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
375
390
struct apple_sc * asc = hid_get_drvdata (hid );
376
391
const struct apple_key_translation * trans , * table ;
377
392
bool do_translate ;
378
- u16 code = 0 ;
393
+ u16 code = usage -> code ;
379
394
unsigned int real_fnmode ;
380
395
381
- u16 fn_keycode = (swap_fn_leftctrl ) ? (KEY_LEFTCTRL ) : (KEY_FN );
382
-
383
- if (usage -> code == fn_keycode ) {
384
- asc -> fn_on = !!value ;
385
- input_event_with_scancode (input , usage -> type , KEY_FN ,
386
- usage -> hid , value );
387
- return 1 ;
388
- }
389
-
390
396
if (fnmode == 3 ) {
391
397
real_fnmode = (asc -> quirks & APPLE_IS_NON_APPLE ) ? 2 : 1 ;
392
398
} else {
393
399
real_fnmode = fnmode ;
394
400
}
395
401
402
+ if (swap_fn_leftctrl ) {
403
+ trans = apple_find_translation (swapped_fn_leftctrl_keys , code );
404
+
405
+ if (trans )
406
+ code = trans -> to ;
407
+ }
408
+
409
+ if (iso_layout > 0 || (iso_layout < 0 && (asc -> quirks & APPLE_ISO_TILDE_QUIRK ) &&
410
+ hid -> country == HID_COUNTRY_INTERNATIONAL_ISO )) {
411
+ trans = apple_find_translation (apple_iso_keyboard , code );
412
+
413
+ if (trans )
414
+ code = trans -> to ;
415
+ }
416
+
417
+ if (swap_opt_cmd ) {
418
+ trans = apple_find_translation (swapped_option_cmd_keys , code );
419
+
420
+ if (trans )
421
+ code = trans -> to ;
422
+ }
423
+
424
+ if (swap_ctrl_cmd ) {
425
+ trans = apple_find_translation (swapped_ctrl_cmd_keys , code );
426
+
427
+ if (trans )
428
+ code = trans -> to ;
429
+ }
430
+
431
+ if (code == KEY_FN )
432
+ asc -> fn_on = !!value ;
433
+
396
434
if (real_fnmode ) {
397
435
if (hid -> product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
398
436
hid -> product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
@@ -430,15 +468,18 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
430
468
else
431
469
table = apple_fn_keys ;
432
470
433
- trans = apple_find_translation (table , usage -> code );
471
+ trans = apple_find_translation (table , code );
434
472
435
473
if (trans ) {
436
- if (test_bit (trans -> from , input -> key ))
474
+ bool from_is_set = test_bit (trans -> from , input -> key );
475
+ bool to_is_set = test_bit (trans -> to , input -> key );
476
+
477
+ if (from_is_set )
437
478
code = trans -> from ;
438
- else if (test_bit ( trans -> to , input -> key ) )
479
+ else if (to_is_set )
439
480
code = trans -> to ;
440
481
441
- if (!code ) {
482
+ if (!( from_is_set || to_is_set ) ) {
442
483
if (trans -> flags & APPLE_FLAG_FKEY ) {
443
484
switch (real_fnmode ) {
444
485
case 1 :
@@ -455,62 +496,31 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
455
496
do_translate = asc -> fn_on ;
456
497
}
457
498
458
- code = do_translate ? trans -> to : trans -> from ;
499
+ if (do_translate )
500
+ code = trans -> to ;
459
501
}
460
-
461
- input_event_with_scancode (input , usage -> type , code ,
462
- usage -> hid , value );
463
- return 1 ;
464
502
}
465
503
466
504
if (asc -> quirks & APPLE_NUMLOCK_EMULATION &&
467
- (test_bit (usage -> code , asc -> pressed_numlock ) ||
505
+ (test_bit (code , asc -> pressed_numlock ) ||
468
506
test_bit (LED_NUML , input -> led ))) {
469
- trans = apple_find_translation (powerbook_numlock_keys ,
470
- usage -> code );
507
+ trans = apple_find_translation (powerbook_numlock_keys , code );
471
508
472
509
if (trans ) {
473
510
if (value )
474
- set_bit (usage -> code ,
475
- asc -> pressed_numlock );
511
+ set_bit (code , asc -> pressed_numlock );
476
512
else
477
- clear_bit (usage -> code ,
478
- asc -> pressed_numlock );
513
+ clear_bit (code , asc -> pressed_numlock );
479
514
480
- input_event_with_scancode (input , usage -> type ,
481
- trans -> to , usage -> hid , value );
515
+ code = trans -> to ;
482
516
}
483
-
484
- return 1 ;
485
- }
486
- }
487
-
488
- if (iso_layout > 0 || (iso_layout < 0 && (asc -> quirks & APPLE_ISO_TILDE_QUIRK ) &&
489
- hid -> country == HID_COUNTRY_INTERNATIONAL_ISO )) {
490
- trans = apple_find_translation (apple_iso_keyboard , usage -> code );
491
- if (trans ) {
492
- input_event_with_scancode (input , usage -> type ,
493
- trans -> to , usage -> hid , value );
494
- return 1 ;
495
517
}
496
518
}
497
519
498
- if (swap_opt_cmd ) {
499
- trans = apple_find_translation (swapped_option_cmd_keys , usage -> code );
500
- if (trans ) {
501
- input_event_with_scancode (input , usage -> type ,
502
- trans -> to , usage -> hid , value );
503
- return 1 ;
504
- }
505
- }
520
+ if (usage -> code != code ) {
521
+ input_event_with_scancode (input , usage -> type , code , usage -> hid , value );
506
522
507
- if (swap_fn_leftctrl ) {
508
- trans = apple_find_translation (swapped_fn_leftctrl_keys , usage -> code );
509
- if (trans ) {
510
- input_event_with_scancode (input , usage -> type ,
511
- trans -> to , usage -> hid , value );
512
- return 1 ;
513
- }
523
+ return 1 ;
514
524
}
515
525
516
526
return 0 ;
@@ -640,9 +650,6 @@ static void apple_setup_input(struct input_dev *input)
640
650
apple_setup_key_translation (input , apple2021_fn_keys );
641
651
apple_setup_key_translation (input , macbookpro_no_esc_fn_keys );
642
652
apple_setup_key_translation (input , macbookpro_dedicated_esc_fn_keys );
643
-
644
- if (swap_fn_leftctrl )
645
- apple_setup_key_translation (input , swapped_fn_leftctrl_keys );
646
653
}
647
654
648
655
static int apple_input_mapping (struct hid_device * hdev , struct hid_input * hi ,
@@ -1011,21 +1018,21 @@ static const struct hid_device_id apple_devices[] = {
1011
1018
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRING9_JIS ),
1012
1019
.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
1013
1020
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ),
1014
- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1021
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
1015
1022
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ),
1016
- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1023
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
1017
1024
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ),
1018
- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1025
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
1019
1026
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213 ),
1020
- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
1027
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
1021
1028
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ),
1022
- .driver_data = APPLE_HAS_FN },
1029
+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1023
1030
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ),
1024
- .driver_data = APPLE_HAS_FN },
1031
+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1025
1032
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K ),
1026
- .driver_data = APPLE_HAS_FN },
1033
+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1027
1034
{ HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F ),
1028
- .driver_data = APPLE_HAS_FN },
1035
+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
1029
1036
{ HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ),
1030
1037
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
1031
1038
{ HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ),
0 commit comments