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 if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) {
74 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
79 if (record->event.pressed) {
80 qk_tap_dance_state.keycode = keycode;
81 qk_tap_dance_state.timer = timer_read ();
82 qk_tap_dance_state.count++;
83 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
88 if (qk_tap_dance_state.keycode) {
89 process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode);
90 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
91 reset_tap_dance (&qk_tap_dance_state);
99 void matrix_scan_tap_dance () {
100 if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
101 process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode);
102 reset_tap_dance (&qk_tap_dance_state);
106 void reset_tap_dance (qk_tap_dance_state_t *state) {
107 uint16_t idx = state->keycode - QK_TAP_DANCE;
108 qk_tap_dance_action_t action;
110 action = tap_dance_actions[idx];
111 switch (action.type) {
112 case QK_TAP_DANCE_TYPE_FN:
113 if (action.fn.on_reset) {
114 action.fn.on_reset(state);