aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r--tmk_core/common/action.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index be6dea2b7..08ef22eb9 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -41,6 +41,12 @@ void action_exec(keyevent_t event)
41 dprint("EVENT: "); debug_event(event); dprintln(); 41 dprint("EVENT: "); debug_event(event); dprintln();
42 } 42 }
43 43
44#ifdef ONEHAND_ENABLE
45 if (!IS_NOEVENT(event)) {
46 process_hand_swap(&event);
47 }
48#endif
49
44 keyrecord_t record = { .event = event }; 50 keyrecord_t record = { .event = event };
45 51
46#ifndef NO_ACTION_TAPPING 52#ifndef NO_ACTION_TAPPING
@@ -53,6 +59,26 @@ void action_exec(keyevent_t event)
53#endif 59#endif
54} 60}
55 61
62#ifdef ONEHAND_ENABLE
63bool swap_hands = false;
64
65void process_hand_swap(keyevent_t *event) {
66 static swap_state_row_t swap_state[MATRIX_ROWS];
67
68 keypos_t pos = event->key;
69 swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col;
70 bool do_swap = event->pressed ? swap_hands :
71 swap_state[pos.row] & (col_bit);
72
73 if (do_swap) {
74 event->key = hand_swap_config[pos.row][pos.col];
75 swap_state[pos.row] |= col_bit;
76 } else {
77 swap_state[pos.row] &= ~(col_bit);
78 }
79}
80#endif
81
56#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) 82#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
57bool disable_action_cache = false; 83bool disable_action_cache = false;
58 84
@@ -440,6 +466,54 @@ void process_action(keyrecord_t *record, action_t action)
440#endif 466#endif
441 case ACT_COMMAND: 467 case ACT_COMMAND:
442 break; 468 break;
469#ifdef ONEHAND_ENABLE
470 case ACT_SWAP_HANDS:
471 switch (action.swap.code) {
472 case OP_SH_TOGGLE:
473 if (event.pressed) {
474 swap_hands = !swap_hands;
475 }
476 break;
477 case OP_SH_ON_OFF:
478 swap_hands = event.pressed;
479 break;
480 case OP_SH_OFF_ON:
481 swap_hands = !event.pressed;
482 break;
483 case OP_SH_ON:
484 if (!event.pressed) {
485 swap_hands = true;
486 }
487 break;
488 case OP_SH_OFF:
489 if (!event.pressed) {
490 swap_hands = false;
491 }
492 break;
493 #ifndef NO_ACTION_TAPPING
494 case OP_SH_TAP_TOGGLE:
495 /* tap toggle */
496 if (tap_count > 0) {
497 if (!event.pressed) {
498 swap_hands = !swap_hands;
499 }
500 } else {
501 swap_hands = event.pressed;
502 }
503 break;
504 default:
505 if (tap_count > 0) {
506 if (event.pressed) {
507 register_code(action.swap.code);
508 } else {
509 unregister_code(action.swap.code);
510 }
511 } else {
512 swap_hands = event.pressed;
513 }
514 #endif
515 }
516#endif
443#ifndef NO_ACTION_FUNCTION 517#ifndef NO_ACTION_FUNCTION
444 case ACT_FUNCTION: 518 case ACT_FUNCTION:
445 action_function(record, action.func.id, action.func.opt); 519 action_function(record, action.func.id, action.func.opt);
@@ -652,6 +726,13 @@ bool is_tap_key(keypos_t key)
652 return true; 726 return true;
653 } 727 }
654 return false; 728 return false;
729 case ACT_SWAP_HANDS:
730 switch (action.swap.code) {
731 case 0x00 ... 0xdf:
732 case OP_SH_TAP_TOGGLE:
733 return true;
734 }
735 return false;
655 case ACT_MACRO: 736 case ACT_MACRO:
656 case ACT_FUNCTION: 737 case ACT_FUNCTION:
657 if (action.func.opt & FUNC_TAP) { return true; } 738 if (action.func.opt & FUNC_TAP) { return true; }
@@ -692,6 +773,7 @@ void debug_action(action_t action)
692 case ACT_MACRO: dprint("ACT_MACRO"); break; 773 case ACT_MACRO: dprint("ACT_MACRO"); break;
693 case ACT_COMMAND: dprint("ACT_COMMAND"); break; 774 case ACT_COMMAND: dprint("ACT_COMMAND"); break;
694 case ACT_FUNCTION: dprint("ACT_FUNCTION"); break; 775 case ACT_FUNCTION: dprint("ACT_FUNCTION"); break;
776 case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break;
695 default: dprint("UNKNOWN"); break; 777 default: dprint("UNKNOWN"); break;
696 } 778 }
697 dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff); 779 dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);