aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_tap_dance.c
diff options
context:
space:
mode:
authorGergely Nagy <algernon@madhouse-project.org>2016-07-20 10:22:52 +0200
committerGergely Nagy <algernon@madhouse-project.org>2016-07-22 09:10:17 +0200
commit70e42489dec375e558d8e81ed5ebfb69b4f3dbd9 (patch)
treee420a956ac4a09848eb5df5a766861cfbaca8de5 /quantum/process_keycode/process_tap_dance.c
parent8e1d96983aad19b3e4e72ece5db822e92d91342b (diff)
downloadqmk_firmware-70e42489dec375e558d8e81ed5ebfb69b4f3dbd9.tar.gz
qmk_firmware-70e42489dec375e558d8e81ed5ebfb69b4f3dbd9.zip
tap-dance: Support for holding keys
With this change, tap dance will now store the pressed state of the tap-dance key, and allow one to make an action sooner, while the key is still held, and only unregister when the key is released. The registration must happen in the `on_dance_finished` callback, while unregistering goes to `on_reset`. The surrounding code makes sure not to call either multiple times. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 'quantum/process_keycode/process_tap_dance.c')
-rw-r--r--quantum/process_keycode/process_tap_dance.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index b9b836df2..097440405 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -73,10 +73,14 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
73 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode); 73 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
74 if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) { 74 if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) {
75 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); 75 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
76 } else if (qk_tap_dance_state.active && qk_tap_dance_state.pressed) {
77 reset_tap_dance (&qk_tap_dance_state);
76 } else { 78 } else {
77 r = false; 79 r = false;
78 } 80 }
79 81
82 qk_tap_dance_state.active = true;
83 qk_tap_dance_state.pressed = record->event.pressed;
80 if (record->event.pressed) { 84 if (record->event.pressed) {
81 qk_tap_dance_state.keycode = keycode; 85 qk_tap_dance_state.keycode = keycode;
82 qk_tap_dance_state.timer = timer_read (); 86 qk_tap_dance_state.timer = timer_read ();
@@ -90,6 +94,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
90 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode); 94 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
91 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); 95 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
92 reset_tap_dance (&qk_tap_dance_state); 96 reset_tap_dance (&qk_tap_dance_state);
97 qk_tap_dance_state.active = false;
93 } 98 }
94 break; 99 break;
95 } 100 }
@@ -98,7 +103,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
98} 103}
99 104
100void matrix_scan_tap_dance () { 105void matrix_scan_tap_dance () {
101 if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { 106 if (qk_tap_dance_state.active && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
102 // if we are here, the tap dance was timed out 107 // if we are here, the tap dance was timed out
103 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); 108 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
104 reset_tap_dance (&qk_tap_dance_state); 109 reset_tap_dance (&qk_tap_dance_state);
@@ -109,6 +114,9 @@ void reset_tap_dance (qk_tap_dance_state_t *state) {
109 uint16_t idx = state->keycode - QK_TAP_DANCE; 114 uint16_t idx = state->keycode - QK_TAP_DANCE;
110 qk_tap_dance_action_t action; 115 qk_tap_dance_action_t action;
111 116
117 if (state->pressed)
118 return;
119
112 action = tap_dance_actions[idx]; 120 action = tap_dance_actions[idx];
113 switch (action.type) { 121 switch (action.type) {
114 case QK_TAP_DANCE_TYPE_FN: 122 case QK_TAP_DANCE_TYPE_FN:
@@ -123,4 +131,5 @@ void reset_tap_dance (qk_tap_dance_state_t *state) {
123 131
124 state->keycode = 0; 132 state->keycode = 0;
125 state->count = 0; 133 state->count = 0;
134 state->active = false;
126} 135}