diff options
Diffstat (limited to 'quantum/process_keycode/process_tap_dance.h')
| -rw-r--r-- | quantum/process_keycode/process_tap_dance.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h new file mode 100644 index 000000000..f753cbba6 --- /dev/null +++ b/quantum/process_keycode/process_tap_dance.h | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | #ifndef PROCESS_TAP_DANCE_H | ||
| 2 | #define PROCESS_TAP_DANCE_H | ||
| 3 | |||
| 4 | #ifdef TAP_DANCE_ENABLE | ||
| 5 | |||
| 6 | #include <stdbool.h> | ||
| 7 | #include <inttypes.h> | ||
| 8 | |||
| 9 | typedef struct | ||
| 10 | { | ||
| 11 | uint8_t count; | ||
| 12 | uint16_t keycode; | ||
| 13 | uint16_t timer; | ||
| 14 | bool interrupted; | ||
| 15 | bool pressed; | ||
| 16 | bool finished; | ||
| 17 | } qk_tap_dance_state_t; | ||
| 18 | |||
| 19 | #define TD(n) (QK_TAP_DANCE + n) | ||
| 20 | |||
| 21 | typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data); | ||
| 22 | |||
| 23 | typedef struct | ||
| 24 | { | ||
| 25 | struct { | ||
| 26 | qk_tap_dance_user_fn_t on_each_tap; | ||
| 27 | qk_tap_dance_user_fn_t on_dance_finished; | ||
| 28 | qk_tap_dance_user_fn_t on_reset; | ||
| 29 | } fn; | ||
| 30 | qk_tap_dance_state_t state; | ||
| 31 | void *user_data; | ||
| 32 | } qk_tap_dance_action_t; | ||
| 33 | |||
| 34 | typedef struct | ||
| 35 | { | ||
| 36 | uint16_t kc1; | ||
| 37 | uint16_t kc2; | ||
| 38 | } qk_tap_dance_pair_t; | ||
| 39 | |||
| 40 | #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ | ||
| 41 | .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \ | ||
| 42 | .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \ | ||
| 43 | } | ||
| 44 | |||
| 45 | #define ACTION_TAP_DANCE_FN(user_fn) { \ | ||
| 46 | .fn = { NULL, user_fn, NULL }, \ | ||
| 47 | .user_data = NULL, \ | ||
| 48 | } | ||
| 49 | |||
| 50 | #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \ | ||
| 51 | .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \ | ||
| 52 | .user_data = NULL, \ | ||
| 53 | } | ||
| 54 | |||
| 55 | extern qk_tap_dance_action_t tap_dance_actions[]; | ||
| 56 | |||
| 57 | /* To be used internally */ | ||
| 58 | |||
| 59 | bool process_tap_dance(uint16_t keycode, keyrecord_t *record); | ||
| 60 | void matrix_scan_tap_dance (void); | ||
| 61 | void reset_tap_dance (qk_tap_dance_state_t *state); | ||
| 62 | |||
| 63 | void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data); | ||
| 64 | void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data); | ||
| 65 | |||
| 66 | #else | ||
| 67 | |||
| 68 | #define TD(n) KC_NO | ||
| 69 | |||
| 70 | #endif | ||
| 71 | |||
| 72 | #endif | ||
