aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
authorJoe Wasson <jwasson+github@gmail.com>2018-03-12 10:22:49 -0700
committerJack Humbert <jack.humb@gmail.com>2018-03-16 16:33:43 -0400
commit5d771039adf23fe9cb8de5843a3d799dc73a2fc7 (patch)
tree043471b02358c3f7cbe848886fc5bcd850049fa7 /tmk_core/common/action.c
parent23ac2a02ef870dce91318a4d98e3c8ec5749bced (diff)
downloadqmk_firmware-5d771039adf23fe9cb8de5843a3d799dc73a2fc7.tar.gz
qmk_firmware-5d771039adf23fe9cb8de5843a3d799dc73a2fc7.zip
Fix swap-hands tapping.
This is an inelegant hack for #2522 but makes things work. Basically we give `action.c` a chance to handle the hold event early so that we can swap the keyboard for later keys. Later, to allow the hold to happen again quickly we nuke the key record so that tapping is reset. I tried to find a cleaner way, honestly.
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 }