1 /* Copyright 2016 Jack Humbert
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #ifndef PROCESS_TAP_DANCE_H
17 #define PROCESS_TAP_DANCE_H
19 #ifdef TAP_DANCE_ENABLE
30 uint16_t interrupting_keycode;
35 } qk_tap_dance_state_t;
37 #define TD(n) (QK_TAP_DANCE + n)
39 typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data);
44 qk_tap_dance_user_fn_t on_each_tap;
45 qk_tap_dance_user_fn_t on_dance_finished;
46 qk_tap_dance_user_fn_t on_reset;
48 qk_tap_dance_state_t state;
49 uint16_t custom_tapping_term;
51 } qk_tap_dance_action_t;
57 } qk_tap_dance_pair_t;
63 } qk_tap_dance_dual_role_t;
65 #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
66 .fn = { qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
67 .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \
70 #define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) { \
71 .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, \
72 .user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer }), \
75 #define ACTION_TAP_DANCE_FN(user_fn) { \
76 .fn = { NULL, user_fn, NULL }, \
80 #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \
81 .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
85 #define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) { \
86 .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
88 .custom_tapping_term = tap_specific_tapping_term, \
91 extern qk_tap_dance_action_t tap_dance_actions[];
93 /* To be used internally */
95 void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
96 bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
97 void matrix_scan_tap_dance (void);
98 void reset_tap_dance (qk_tap_dance_state_t *state);
100 void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data);
101 void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
102 void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
104 void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data);
105 void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data);
106 void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data);