]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/process_keycode/process_tap_dance.h
add an `anyway` and a `reset` callback
[qmk_firmware.git] / quantum / process_keycode / process_tap_dance.h
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 } qk_tap_dance_state_t;
15
16 #define TD(n) (QK_TAP_DANCE + n)
17
18 typedef enum
19 {
20   QK_TAP_DANCE_TYPE_PAIR,
21   QK_TAP_DANCE_TYPE_FN,
22 } qk_tap_dance_type_t;
23
24 typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state);
25 typedef void (*qk_tap_dance_user_fn_reset_t) (void);
26
27 typedef struct
28 {
29   qk_tap_dance_type_t type;
30   union {
31     struct {
32       uint16_t kc1;
33       uint16_t kc2;
34     } pair;
35     struct {
36       qk_tap_dance_user_fn_t regular;
37       qk_tap_dance_user_fn_t anyway;
38       qk_tap_dance_user_fn_reset_t reset;
39     } fn;
40   };
41 } qk_tap_dance_action_t;
42
43 #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
44     .type = QK_TAP_DANCE_TYPE_PAIR, \
45     .pair = { kc1, kc2 }            \
46   }
47
48 #define ACTION_TAP_DANCE_FN(user_fn) { \
49     .type = QK_TAP_DANCE_TYPE_FN, \
50     .fn = { user_fn, NULL, NULL } \
51   }
52
53 #define ACTION_TAP_DANCE_FN_ANYWAY(user_fn, user_fn_anyway) { \
54     .type = QK_TAP_DANCE_TYPE_FN,           \
55     .fn = { user_fn, user_fn_anyway, NULL } \
56   }
57
58 #define ACTION_TAP_DANCE_FN_RESET(user_fn, user_fn_reset) { \
59     .type = QK_TAP_DANCE_TYPE_FN,          \
60     .fn = { user_fn, NULL, user_fn_reset } \
61   }
62
63 #define ACTION_TAP_DANCE_FN_ANYWAY_RESET(user_fn, user_fn_anyway, user_fn_reset) { \
64     .type = QK_TAP_DANCE_TYPE_FN,                    \
65     .fn = { user_fn, user_fn_anyway, user_fn_reset } \
66   }
67
68 extern const qk_tap_dance_action_t tap_dance_actions[];
69
70 /* To be used internally */
71
72 bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
73 void matrix_scan_tap_dance (void);
74 void reset_tap_dance (qk_tap_dance_state_t *state);
75
76 #else
77
78 #define TD(n) KC_NO
79
80 #endif
81
82 #endif