aboutsummaryrefslogtreecommitdiff
path: root/common/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/action.c')
-rw-r--r--common/action.c356
1 files changed, 209 insertions, 147 deletions
diff --git a/common/action.c b/common/action.c
index 246fd99d8..3703b4e8c 100644
--- a/common/action.c
+++ b/common/action.c
@@ -202,23 +202,6 @@ void action_exec(keyevent_t event)
202 } 202 }
203} 203}
204 204
205static action_t get_action(key_t key)
206{
207 action_t action;
208 action.code = ACTION_NO;
209
210 /* layer_switch */
211 action = layer_switch_get_action(key);
212 if (action.code != ACTION_TRANSPARENT) {
213 return action;
214 }
215
216 /* default layer */
217 //debug("get_aciton: default layer: "); debug_dec(default_layer); debug("\n");
218 action = action_for_key(default_layer, key);
219 return action;
220}
221
222static void process_action(keyrecord_t *record) 205static void process_action(keyrecord_t *record)
223{ 206{
224 keyevent_t event = record->event; 207 keyevent_t event = record->event;
@@ -226,9 +209,11 @@ static void process_action(keyrecord_t *record)
226 209
227 if (IS_NOEVENT(event)) { return; } 210 if (IS_NOEVENT(event)) { return; }
228 211
229 action_t action = get_action(event.key); 212 action_t action = layer_switch_get_action(event.key);
230 debug("ACTION: "); debug_action(action); debug(" "); 213 debug("ACTION: "); debug_action(action);
231 layer_switch_debug(); debug("["); debug_dec(default_layer); debug("]\n"); 214 debug(" overlays: "); overlay_debug();
215 debug(" keymaps: "); keymap_debug();
216 debug(" default_layer: "); debug_dec(default_layer); debug("\n");
232 217
233 switch (action.kind.id) { 218 switch (action.kind.id) {
234 /* Key and Mods */ 219 /* Key and Mods */
@@ -368,207 +353,292 @@ static void process_action(keyrecord_t *record)
368#endif 353#endif
369 break; 354 break;
370 355
371 /* Layer key */ 356 case ACT_KEYMAP:
372 case ACT_LAYER_SET:
373 switch (action.layer.code) { 357 switch (action.layer.code) {
374 case LAYER_MOMENTARY: /* momentary */ 358 /* Keymap Reset */
375 if (event.pressed) { 359 case OP_RESET:
376 layer_switch_move(action.layer.val); 360 default_layer_set(action.layer.val);
377 }
378 else {
379 // NOTE: This is needed by legacy keymap support
380 layer_switch_move(0);
381 }
382 break; 361 break;
383 case LAYER_ON_PRESS: 362 /* Keymap Reset default layer */
363 case (OP_RESET | ON_PRESS):
384 if (event.pressed) { 364 if (event.pressed) {
385 layer_switch_move(action.layer.val); 365 default_layer_set(action.layer.val);
366 overlay_clear();
386 } 367 }
387 break; 368 break;
388 case LAYER_ON_RELEASE: 369 case (OP_RESET | ON_RELEASE):
389 if (!event.pressed) { 370 if (!event.pressed) {
390 layer_switch_move(action.layer.val); 371 default_layer_set(action.layer.val);
372 overlay_clear();
391 } 373 }
392 break; 374 break;
393 case LAYER_ON_BOTH: 375 case (OP_RESET | ON_BOTH):
394 layer_switch_move(action.layer.val); 376 default_layer_set(action.layer.val);
377 overlay_clear();
395 break; 378 break;
396 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 379
380 /* Keymap Bit invert */
381 case OP_INV:
382 /* with tap toggle */
397 if (event.pressed) { 383 if (event.pressed) {
398 if (tap_count < TAPPING_TOGGLE) { 384 if (tap_count < TAPPING_TOGGLE) {
399 layer_switch_move(action.layer.val); 385 debug("KEYMAP_INV: tap toggle(press).\n");
386 keymap_invert(action.layer.val);
400 } 387 }
401 } else { 388 } else {
402 if (tap_count >= TAPPING_TOGGLE) { 389 if (tap_count <= TAPPING_TOGGLE) {
403 debug("LAYER_PRESSED: tap toggle.\n"); 390 debug("KEYMAP_INV: tap toggle(release).\n");
404 layer_switch_move(action.layer.val); 391 keymap_invert(action.layer.val);
405 } 392 }
406 } 393 }
407 break; 394 break;
408 case LAYER_SET_DEFAULT_ON_PRESS: 395 case (OP_INV | ON_PRESS):
409 if (event.pressed) { 396 if (event.pressed) {
410 default_layer = action.layer.val; 397 keymap_invert(action.layer.val);
411 layer_switch_move(0);
412 } 398 }
413 break; 399 break;
414 case LAYER_SET_DEFAULT_ON_RELEASE: 400 case (OP_INV | ON_RELEASE):
415 if (!event.pressed) { 401 if (!event.pressed) {
416 default_layer = action.layer.val; 402 keymap_invert(action.layer.val);
417 layer_switch_move(0);
418 } 403 }
419 break; 404 break;
420 case LAYER_SET_DEFAULT_ON_BOTH: 405 case (OP_INV | ON_BOTH):
421 default_layer = action.layer.val; 406 keymap_invert(action.layer.val);
422 layer_switch_move(0);
423 break; 407 break;
424 default: 408
425 /* tap key */ 409 /* Keymap Bit on */
410 case OP_ON:
426 if (event.pressed) { 411 if (event.pressed) {
427 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 412 keymap_on(action.layer.val);
428 debug("LAYER_SET: Tap: register_code\n");
429 register_code(action.layer.code);
430 } else {
431 debug("LAYER_SET: No tap: layer_set(on press)\n");
432 layer_switch_move(action.layer.val);
433 }
434 } else { 413 } else {
435 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 414 keymap_off(action.layer.val);
436 debug("LAYER_SET: Tap: unregister_code\n");
437 unregister_code(action.layer.code);
438 } else {
439 // NOTE: This is needed by legacy keymap support
440 debug("LAYER_SET: No tap: return to default layer(on release)\n");
441 layer_switch_move(0);
442 }
443 } 415 }
444 break; 416 break;
445 } 417 case (OP_ON | ON_PRESS):
446 break;
447 case ACT_LAYER_BIT:
448 switch (action.layer.code) {
449 case LAYER_MOMENTARY: /* momentary */
450 if (event.pressed) { 418 if (event.pressed) {
451 layer_switch_move(layer_switch_get_layer() | action.layer.val); 419 keymap_on(action.layer.val);
420 }
421 break;
422 case (OP_ON | ON_RELEASE):
423 if (!event.pressed) {
424 keymap_on(action.layer.val);
425 }
426 break;
427 case (OP_ON | ON_BOTH):
428 keymap_on(action.layer.val);
429 break;
430
431 /* Keymap Bit off */
432 case OP_OFF:
433 if (event.pressed) {
434 keymap_off(action.layer.val);
452 } else { 435 } else {
453 layer_switch_move(layer_switch_get_layer() & ~action.layer.val); 436 keymap_on(action.layer.val);
454 } 437 }
455 break; 438 break;
456 case LAYER_ON_PRESS: 439 case (OP_OFF | ON_PRESS):
457 if (event.pressed) { 440 if (event.pressed) {
458 layer_switch_move(layer_switch_get_layer() ^ action.layer.val); 441 keymap_off(action.layer.val);
459 } 442 }
460 break; 443 break;
461 case LAYER_ON_RELEASE: 444 case (OP_OFF | ON_RELEASE):
462 if (!event.pressed) { 445 if (!event.pressed) {
463 layer_switch_move(layer_switch_get_layer() ^ action.layer.val); 446 keymap_off(action.layer.val);
464 } 447 }
465 break; 448 break;
466 case LAYER_ON_BOTH: 449 case (OP_OFF | ON_BOTH):
467 layer_switch_move(layer_switch_get_layer() ^ action.layer.val); 450 keymap_off(action.layer.val);
468 break; 451 break;
469 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 452
453 /* Keymap Bit set */
454 case OP_SET:
470 if (event.pressed) { 455 if (event.pressed) {
471 if (tap_count < TAPPING_TOGGLE) { 456 keymap_set(action.layer.val);
472 debug("LAYER_BIT: tap toggle(press).\n");
473 layer_switch_move(layer_switch_get_layer() ^ action.layer.val);
474 }
475 } else { 457 } else {
476 if (tap_count <= TAPPING_TOGGLE) { 458 keymap_clear();
477 debug("LAYER_BIT: tap toggle(release).\n");
478 layer_switch_move(layer_switch_get_layer() ^ action.layer.val);
479 }
480 } 459 }
481 break; 460 break;
482 case LAYER_SET_DEFAULT_ON_PRESS: 461 case (OP_SET | ON_PRESS):
483 if (event.pressed) { 462 if (event.pressed) {
484 default_layer = default_layer ^ action.layer.val; 463 keymap_set(action.layer.val);
485 layer_switch_move(default_layer);
486 } 464 }
487 break; 465 break;
488 case LAYER_SET_DEFAULT_ON_RELEASE: 466 case (OP_SET | ON_RELEASE):
489 if (!event.pressed) { 467 if (!event.pressed) {
490 default_layer = default_layer ^ action.layer.val; 468 keymap_set(action.layer.val);
491 layer_switch_move(default_layer);
492 } 469 }
493 break; 470 break;
494 case LAYER_SET_DEFAULT_ON_BOTH: 471 case (OP_SET | ON_BOTH):
495 default_layer = default_layer ^ action.layer.val; 472 keymap_set(action.layer.val);
496 layer_switch_move(default_layer);
497 break; 473 break;
474
475 /* Keymap Bit invert with tap key */
498 default: 476 default:
499 // tap key
500 if (event.pressed) { 477 if (event.pressed) {
501 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 478 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
502 debug("LAYER_BIT: Tap: register_code\n"); 479 debug("KEYMAP_TAP_KEY: Tap: register_code\n");
503 register_code(action.layer.code); 480 register_code(action.layer.code);
504 } else { 481 } else {
505 debug("LAYER_BIT: No tap: layer_bit(on press)\n"); 482 debug("KEYMAP_TAP_KEY: No tap: invert on press\n");
506 layer_switch_move(layer_switch_get_layer() ^ action.layer.val); 483 keymap_invert(action.layer.val);
507 } 484 }
508 } else { 485 } else {
509 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 486 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
510 debug("LAYER_BIT: Tap: unregister_code\n"); 487 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
511 unregister_code(action.layer.code); 488 unregister_code(action.layer.code);
512 } else { 489 } else {
513 debug("LAYER_BIT: No tap: layer_bit(on release)\n"); 490 debug("KEYMAP_TAP_KEY: No tap: invert on release\n");
514 layer_switch_move(layer_switch_get_layer() ^ action.layer.val); 491 keymap_invert(action.layer.val);
515 } 492 }
516 } 493 }
517 break; 494 break;
518 } 495 }
519 break; 496 break;
520 case ACT_LAYER_SWITCH: 497
498 case ACT_OVERLAY:
521 switch (action.layer.code) { 499 switch (action.layer.code) {
522 case LAYER_MOMENTARY: /* momentary */ 500 // Overlay Invert bit4
523 if (event.pressed) { 501 case OP_INV4 | 0:
524 layer_switch_on(action.layer.val); 502 if (action.layer.val == 0) {
503 overlay_clear();
525 } else { 504 } else {
526 layer_switch_off(action.layer.val); 505 overlay_set(overlay_stat ^ action.layer.val);
527 } 506 }
528 break; 507 break;
529 case LAYER_ON_PRESS: 508 case OP_INV4 | 1:
530 if (event.pressed) { 509 if (action.layer.val == 0) {
531 layer_switch_invert(action.layer.val); 510 if (event.pressed) overlay_clear();
511 } else {
512 overlay_set(overlay_stat ^ action.layer.val<<4);
532 } 513 }
533 break; 514 break;
534 case LAYER_ON_RELEASE: 515 case OP_INV4 | 2:
535 if (!event.pressed) { 516 if (action.layer.val == 0) {
536 layer_switch_invert(action.layer.val); 517 if (!event.pressed) overlay_clear();
518 } else {
519 overlay_set(overlay_stat ^ action.layer.val<<8);
537 } 520 }
538 break; 521 break;
539 case LAYER_ON_BOTH: 522 case OP_INV4 | 3:
540 layer_switch_invert(action.layer.val); 523 if (action.layer.val == 0) {
524 overlay_clear();
525 } else {
526 overlay_set(overlay_stat ^ action.layer.val<<12);
527 }
541 break; 528 break;
542 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 529
530 /* Overlay Bit invert */
531 case OP_INV:
532 /* with tap toggle */
543 if (event.pressed) { 533 if (event.pressed) {
544 if (tap_count < TAPPING_TOGGLE) { 534 if (tap_count < TAPPING_TOGGLE) {
545 debug("LAYER_SWITCH: tap toggle(press).\n"); 535 debug("OVERLAY_INV: tap toggle(press).\n");
546 layer_switch_invert(action.layer.val); 536 overlay_invert(action.layer.val);
547 } 537 }
548 } else { 538 } else {
549 if (tap_count <= TAPPING_TOGGLE) { 539 if (tap_count <= TAPPING_TOGGLE) {
550 debug("LAYER_SWITCH: tap toggle(release).\n"); 540 debug("OVERLAY_INV: tap toggle(release).\n");
551 layer_switch_invert(action.layer.val); 541 overlay_invert(action.layer.val);
552 } 542 }
553 } 543 }
554 break; 544 break;
545 case (OP_INV | ON_PRESS):
546 if (event.pressed) {
547 overlay_invert(action.layer.val);
548 }
549 break;
550 case (OP_INV | ON_RELEASE):
551 if (!event.pressed) {
552 overlay_invert(action.layer.val);
553 }
554 break;
555 case (OP_INV | ON_BOTH):
556 overlay_invert(action.layer.val);
557 break;
558
559 /* Overlay Bit on */
560 case OP_ON:
561 if (event.pressed) {
562 overlay_on(action.layer.val);
563 } else {
564 overlay_off(action.layer.val);
565 }
566 break;
567 case (OP_ON | ON_PRESS):
568 if (event.pressed) {
569 overlay_on(action.layer.val);
570 }
571 break;
572 case (OP_ON | ON_RELEASE):
573 if (!event.pressed) {
574 overlay_on(action.layer.val);
575 }
576 break;
577 case (OP_ON | ON_BOTH):
578 overlay_on(action.layer.val);
579 break;
580
581 /* Overlay Bit off */
582 case OP_OFF:
583 if (event.pressed) {
584 overlay_off(action.layer.val);
585 } else {
586 overlay_on(action.layer.val);
587 }
588 break;
589 case (OP_OFF | ON_PRESS):
590 if (event.pressed) {
591 overlay_off(action.layer.val);
592 }
593 break;
594 case (OP_OFF | ON_RELEASE):
595 if (!event.pressed) {
596 overlay_off(action.layer.val);
597 }
598 break;
599 case (OP_OFF | ON_BOTH):
600 overlay_off(action.layer.val);
601 break;
602
603 /* Overlay Bit set */
604 case OP_SET:
605 if (event.pressed) {
606 overlay_move(action.layer.val);
607 } else {
608 overlay_clear();
609 }
610 break;
611 case (OP_SET | ON_PRESS):
612 if (event.pressed) {
613 overlay_move(action.layer.val);
614 }
615 break;
616 case (OP_SET | ON_RELEASE):
617 if (!event.pressed) {
618 overlay_move(action.layer.val);
619 }
620 break;
621 case (OP_SET | ON_BOTH):
622 overlay_move(action.layer.val);
623 break;
624
625 /* Overlay Bit invert with tap key */
555 default: 626 default:
556 // tap key
557 if (event.pressed) { 627 if (event.pressed) {
558 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 628 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
559 debug("LAYER_SWITCH: Tap: register_code\n"); 629 debug("OVERLAY_TAP_KEY: Tap: register_code\n");
560 register_code(action.layer.code); 630 register_code(action.layer.code);
561 } else { 631 } else {
562 debug("LAYER_SWITCH: No tap: layer_switch on press\n"); 632 debug("OVERLAY_TAP_KEY: No tap: invert on press\n");
563 layer_switch_invert(action.layer.val); 633 overlay_invert(action.layer.val);
564 } 634 }
565 } else { 635 } else {
566 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 636 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
567 debug("LAYER_SWITCH: Tap: unregister_code\n"); 637 debug("OVERLAY_TAP_KEY: Tap: unregister_code\n");
568 unregister_code(action.layer.code); 638 unregister_code(action.layer.code);
569 } else { 639 } else {
570 debug("LAYER_SWITCH: No tap: layer_switch on release\n"); 640 debug("OVERLAY_TAP_KEY: No tap: invert on release\n");
571 layer_switch_invert(action.layer.val); 641 overlay_invert(action.layer.val);
572 } 642 }
573 } 643 }
574 break; 644 break;
@@ -877,28 +947,21 @@ bool sending_anykey(void)
877 947
878bool is_tap_key(key_t key) 948bool is_tap_key(key_t key)
879{ 949{
880 action_t action = get_action(key); 950 action_t action = layer_switch_get_action(key);
881 951
882 switch (action.kind.id) { 952 switch (action.kind.id) {
883 case ACT_LMODS_TAP: 953 case ACT_LMODS_TAP:
884 case ACT_RMODS_TAP: 954 case ACT_RMODS_TAP:
885 return true; 955 return true;
886 case ACT_LAYER_SET: 956 case ACT_KEYMAP:
887 case ACT_LAYER_BIT: 957 case ACT_OVERLAY:
888 switch (action.layer.code) { 958 switch (action.layer.code) {
889 case LAYER_MOMENTARY: 959 case 0x04 ... 0xEF: /* tap key */
890 case LAYER_ON_PRESS: 960 case OP_INV:
891 case LAYER_ON_RELEASE:
892 case LAYER_ON_BOTH:
893 case LAYER_SET_DEFAULT_ON_PRESS:
894 case LAYER_SET_DEFAULT_ON_RELEASE:
895 case LAYER_SET_DEFAULT_ON_BOTH:
896 return false;
897 case LAYER_TAP_TOGGLE:
898 default: /* tap key */
899 return true; 961 return true;
962 default:
963 return false;
900 } 964 }
901 return false;
902 case ACT_FUNCTION: 965 case ACT_FUNCTION:
903 if (action.func.opt & FUNC_TAP) { return true; } 966 if (action.func.opt & FUNC_TAP) { return true; }
904 return false; 967 return false;
@@ -929,9 +992,8 @@ static void debug_action(action_t action)
929 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 992 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
930 case ACT_USAGE: debug("ACT_USAGE"); break; 993 case ACT_USAGE: debug("ACT_USAGE"); break;
931 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 994 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
932 case ACT_LAYER_SET: debug("ACT_LAYER_SET"); break; 995 case ACT_KEYMAP: debug("ACT_KEYMAP"); break;
933 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; 996 case ACT_OVERLAY: debug("ACT_OVERLAY"); break;
934 case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break;
935 case ACT_MACRO: debug("ACT_MACRO"); break; 997 case ACT_MACRO: debug("ACT_MACRO"); break;
936 case ACT_COMMAND: debug("ACT_COMMAND"); break; 998 case ACT_COMMAND: debug("ACT_COMMAND"); break;
937 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 999 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;