aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_tap_dance.c52
-rw-r--r--quantum/process_keycode/process_tap_dance.h19
2 files changed, 58 insertions, 13 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index 9b172e1b6..b9b836df2 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -22,10 +22,29 @@ static void _process_tap_dance_action_pair (qk_tap_dance_state_t *state,
22static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, 22static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
23 qk_tap_dance_user_fn_t fn) 23 qk_tap_dance_user_fn_t fn)
24{ 24{
25 fn(state); 25 if (fn) {
26 fn(state);
27 }
28}
29
30void process_tap_dance_action_on_each_tap (uint16_t keycode)
31{
32 uint16_t idx = keycode - QK_TAP_DANCE;
33 qk_tap_dance_action_t action;
34
35 action = tap_dance_actions[idx];
36
37 switch (action.type) {
38 case QK_TAP_DANCE_TYPE_FN:
39 _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_each_tap);
40 break;
41
42 default:
43 break;
44 }
26} 45}
27 46
28void process_tap_dance_action (uint16_t keycode) 47void process_tap_dance_action_on_dance_finished (uint16_t keycode)
29{ 48{
30 uint16_t idx = keycode - QK_TAP_DANCE; 49 uint16_t idx = keycode - QK_TAP_DANCE;
31 qk_tap_dance_action_t action; 50 qk_tap_dance_action_t action;
@@ -38,7 +57,7 @@ void process_tap_dance_action (uint16_t keycode)
38 action.pair.kc1, action.pair.kc2); 57 action.pair.kc1, action.pair.kc2);
39 break; 58 break;
40 case QK_TAP_DANCE_TYPE_FN: 59 case QK_TAP_DANCE_TYPE_FN:
41 _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn); 60 _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_dance_finished);
42 break; 61 break;
43 62
44 default: 63 default:
@@ -51,8 +70,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
51 70
52 switch(keycode) { 71 switch(keycode) {
53 case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: 72 case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
73 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
54 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) {
55 process_tap_dance_action (qk_tap_dance_state.keycode); 75 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
56 } else { 76 } else {
57 r = false; 77 r = false;
58 } 78 }
@@ -66,8 +86,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
66 86
67 default: 87 default:
68 if (qk_tap_dance_state.keycode) { 88 if (qk_tap_dance_state.keycode) {
69 process_tap_dance_action (qk_tap_dance_state.keycode); 89 // if we are here, the tap dance was interrupted by a different key
70 90 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);
71 reset_tap_dance (&qk_tap_dance_state); 92 reset_tap_dance (&qk_tap_dance_state);
72 } 93 }
73 break; 94 break;
@@ -78,13 +99,28 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
78 99
79void matrix_scan_tap_dance () { 100void matrix_scan_tap_dance () {
80 if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { 101 if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
81 process_tap_dance_action (qk_tap_dance_state.keycode); 102 // if we are here, the tap dance was timed out
82 103 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
83 reset_tap_dance (&qk_tap_dance_state); 104 reset_tap_dance (&qk_tap_dance_state);
84 } 105 }
85} 106}
86 107
87void reset_tap_dance (qk_tap_dance_state_t *state) { 108void reset_tap_dance (qk_tap_dance_state_t *state) {
109 uint16_t idx = state->keycode - QK_TAP_DANCE;
110 qk_tap_dance_action_t action;
111
112 action = tap_dance_actions[idx];
113 switch (action.type) {
114 case QK_TAP_DANCE_TYPE_FN:
115 if (action.fn.on_reset) {
116 action.fn.on_reset(state);
117 }
118 break;
119
120 default:
121 break;
122 }
123
88 state->keycode = 0; 124 state->keycode = 0;
89 state->count = 0; 125 state->count = 0;
90} 126}
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h
index b9d7c7fcf..7b820584a 100644
--- a/quantum/process_keycode/process_tap_dance.h
+++ b/quantum/process_keycode/process_tap_dance.h
@@ -31,18 +31,27 @@ typedef struct
31 uint16_t kc1; 31 uint16_t kc1;
32 uint16_t kc2; 32 uint16_t kc2;
33 } pair; 33 } pair;
34 qk_tap_dance_user_fn_t fn; 34 struct {
35 qk_tap_dance_user_fn_t on_each_tap;
36 qk_tap_dance_user_fn_t on_dance_finished;
37 qk_tap_dance_user_fn_t on_reset;
38 } fn;
35 }; 39 };
36} qk_tap_dance_action_t; 40} qk_tap_dance_action_t;
37 41
38#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ 42#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
39 .type = QK_TAP_DANCE_TYPE_PAIR, \ 43 .type = QK_TAP_DANCE_TYPE_PAIR, \
40 .pair = { kc1, kc2 } \ 44 .pair = { kc1, kc2 } \
41 } 45 }
42 46
43#define ACTION_TAP_DANCE_FN(user_fn) { \ 47#define ACTION_TAP_DANCE_FN(user_fn) { \
44 .type = QK_TAP_DANCE_TYPE_FN, \ 48 .type = QK_TAP_DANCE_TYPE_FN, \
45 .fn = user_fn \ 49 .fn = { NULL, user_fn, NULL } \
50 }
51
52#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \
53 .type = QK_TAP_DANCE_TYPE_FN, \
54 .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \
46 } 55 }
47 56
48extern const qk_tap_dance_action_t tap_dance_actions[]; 57extern const qk_tap_dance_action_t tap_dance_actions[];