3 static qk_tap_dance_state_t qk_tap_dance_state;
5 static void _process_tap_dance_action_pair (qk_tap_dance_state_t *state,
6 uint16_t kc1, uint16_t kc2) {
12 kc = (state->count == 1) ? kc1 : kc2;
17 if (state->count >= 2) {
18 reset_tap_dance (state);
22 static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
23 qk_tap_dance_user_fn_t fn)
30 void process_tap_dance_action_on_each_tap (uint16_t keycode)
32 uint16_t idx = keycode - QK_TAP_DANCE;
33 qk_tap_dance_action_t action;
35 action = tap_dance_actions[idx];
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);
47 void process_tap_dance_action_on_dance_finished (uint16_t keycode)
49 uint16_t idx = keycode - QK_TAP_DANCE;
50 qk_tap_dance_action_t action;
52 action = tap_dance_actions[idx];
54 switch (action.type) {
55 case QK_TAP_DANCE_TYPE_PAIR:
56 _process_tap_dance_action_pair (&qk_tap_dance_state,
57 action.pair.kc1, action.pair.kc2);
59 case QK_TAP_DANCE_TYPE_FN:
60 _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_dance_finished);
68 bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
72 case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
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) {
75 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
80 if (record->event.pressed) {
81 qk_tap_dance_state.keycode = keycode;
82 qk_tap_dance_state.timer = timer_read ();
83 qk_tap_dance_state.count++;
88 if (qk_tap_dance_state.keycode) {
89 // if we are here, the tap dance was interrupted by a different key
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);
92 reset_tap_dance (&qk_tap_dance_state);
100 void matrix_scan_tap_dance () {
101 if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
102 // if we are here, the tap dance was timed out
103 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
104 reset_tap_dance (&qk_tap_dance_state);
108 void 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;
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);