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.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 947e5118f..33d920554 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -93,6 +93,7 @@ void action_exec(keyevent_t event)
93 93
94#ifdef SWAP_HANDS_ENABLE 94#ifdef SWAP_HANDS_ENABLE
95bool swap_hands = false; 95bool swap_hands = false;
96bool swap_held = false;
96 97
97void process_hand_swap(keyevent_t *event) { 98void process_hand_swap(keyevent_t *event) {
98 static swap_state_row_t swap_state[MATRIX_ROWS]; 99 static swap_state_row_t swap_state[MATRIX_ROWS];
@@ -132,6 +133,27 @@ bool process_record_quantum(keyrecord_t *record) {
132 return true; 133 return true;
133} 134}
134 135
136#ifndef NO_ACTION_TAPPING
137// Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress.
138void process_record_tap_hint(keyrecord_t *record)
139{
140 action_t action = layer_switch_get_action(record->event.key);
141
142 switch (action.kind.id) {
143#ifdef SWAP_HANDS_ENABLE
144 case ACT_SWAP_HANDS:
145 switch (action.swap.code) {
146 case OP_SH_TAP_TOGGLE:
147 default:
148 swap_hands = !swap_hands;
149 swap_held = true;
150 }
151 break;
152#endif
153 }
154}
155#endif
156
135void process_record(keyrecord_t *record) 157void process_record(keyrecord_t *record)
136{ 158{
137 if (IS_NOEVENT(record->event)) { return; } 159 if (IS_NOEVENT(record->event)) { return; }
@@ -551,23 +573,37 @@ void process_action(keyrecord_t *record, action_t action)
551 #ifndef NO_ACTION_TAPPING 573 #ifndef NO_ACTION_TAPPING
552 case OP_SH_TAP_TOGGLE: 574 case OP_SH_TAP_TOGGLE:
553 /* tap toggle */ 575 /* tap toggle */
554 if (tap_count > 0) { 576
555 if (!event.pressed) { 577 if (event.pressed) {
578 if (swap_held) {
579 swap_held = false;
580 } else {
556 swap_hands = !swap_hands; 581 swap_hands = !swap_hands;
557 } 582 }
558 } else { 583 } else {
559 swap_hands = event.pressed; 584 if (tap_count < TAPPING_TOGGLE) {
585 swap_hands = !swap_hands;
586 }
560 } 587 }
561 break; 588 break;
562 default: 589 default:
590 /* tap key */
563 if (tap_count > 0) { 591 if (tap_count > 0) {
592 if (swap_held) {
593 swap_hands = !swap_hands; // undo hold set up in _tap_hint
594 swap_held = false;
595 }
564 if (event.pressed) { 596 if (event.pressed) {
565 register_code(action.swap.code); 597 register_code(action.swap.code);
566 } else { 598 } else {
567 unregister_code(action.swap.code); 599 unregister_code(action.swap.code);
600 *record = (keyrecord_t){}; // hack: reset tap mode
568 } 601 }
569 } else { 602 } else {
570 swap_hands = event.pressed; 603 if (swap_held && !event.pressed) {
604 swap_hands = !swap_hands; // undo hold set up in _tap_hint
605 swap_held = false;
606 }
571 } 607 }
572 #endif 608 #endif
573 } 609 }