aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
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
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')
-rw-r--r--tmk_core/common/action.c44
-rw-r--r--tmk_core/common/action.h4
-rw-r--r--tmk_core/common/action_code.h8
-rw-r--r--tmk_core/common/action_tapping.c3
4 files changed, 50 insertions, 9 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 }
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index 87027dede..acc55c7d3 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -96,6 +96,10 @@ void clear_keyboard_but_mods(void);
96void layer_switch(uint8_t new_layer); 96void layer_switch(uint8_t new_layer);
97bool is_tap_key(keypos_t key); 97bool is_tap_key(keypos_t key);
98 98
99#ifndef NO_ACTION_TAPPING
100void process_record_tap_hint(keyrecord_t *record);
101#endif
102
99/* debug */ 103/* debug */
100void debug_event(keyevent_t event); 104void debug_event(keyevent_t event);
101void debug_record(keyrecord_t record); 105void debug_record(keyrecord_t record);
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h
index 05bc84573..fe2735b97 100644
--- a/tmk_core/common/action_code.h
+++ b/tmk_core/common/action_code.h
@@ -186,7 +186,7 @@ typedef union {
186 } func; 186 } func;
187 struct action_swap { 187 struct action_swap {
188 uint8_t code :8; 188 uint8_t code :8;
189 uint8_t opt :4; 189 uint8_t opt :4;
190 uint8_t kind :4; 190 uint8_t kind :4;
191 } swap; 191 } swap;
192} action_t; 192} action_t;
@@ -243,7 +243,7 @@ enum usage_pages {
243 243
244 244
245 245
246/* 246/*
247 * Layer Actions 247 * Layer Actions
248 */ 248 */
249enum layer_param_on { 249enum layer_param_on {
@@ -257,7 +257,7 @@ enum layer_param_bit_op {
257 OP_BIT_XOR = 2, 257 OP_BIT_XOR = 2,
258 OP_BIT_SET = 3, 258 OP_BIT_SET = 3,
259}; 259};
260enum layer_pram_tap_op { 260enum layer_param_tap_op {
261 OP_TAP_TOGGLE = 0xF0, 261 OP_TAP_TOGGLE = 0xF0,
262 OP_ON_OFF, 262 OP_ON_OFF,
263 OP_OFF_ON, 263 OP_OFF_ON,
@@ -329,7 +329,7 @@ enum function_opts {
329#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id)) 329#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
330#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id)) 330#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id))
331/* OneHand Support */ 331/* OneHand Support */
332enum swap_hands_pram_tap_op { 332enum swap_hands_param_tap_op {
333 OP_SH_TOGGLE = 0xF0, 333 OP_SH_TOGGLE = 0xF0,
334 OP_SH_TAP_TOGGLE, 334 OP_SH_TAP_TOGGLE,
335 OP_SH_ON_OFF, 335 OP_SH_ON_OFF,
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c
index 531a3ca34..6280c6c36 100644
--- a/tmk_core/common/action_tapping.c
+++ b/tmk_core/common/action_tapping.c
@@ -263,7 +263,7 @@ bool process_tapping(keyrecord_t *keyp)
263 return true; 263 return true;
264 } 264 }
265 } else { 265 } else {
266 // FIX: process_aciton here? 266 // FIX: process_action here?
267 // timeout. no sequential tap. 267 // timeout. no sequential tap.
268 debug("Tapping: End(Timeout after releasing last tap): "); 268 debug("Tapping: End(Timeout after releasing last tap): ");
269 debug_event(event); debug("\n"); 269 debug_event(event); debug("\n");
@@ -277,6 +277,7 @@ bool process_tapping(keyrecord_t *keyp)
277 if (event.pressed && is_tap_key(event.key)) { 277 if (event.pressed && is_tap_key(event.key)) {
278 debug("Tapping: Start(Press tap key).\n"); 278 debug("Tapping: Start(Press tap key).\n");
279 tapping_key = *keyp; 279 tapping_key = *keyp;
280 process_record_tap_hint(&tapping_key);
280 waiting_buffer_scan_tap(); 281 waiting_buffer_scan_tap();
281 debug_tapping_key(); 282 debug_tapping_key();
282 return true; 283 return true;