diff options
author | Gergely Nagy <algernon@madhouse-project.org> | 2016-07-20 11:34:45 +0200 |
---|---|---|
committer | Gergely Nagy <algernon@madhouse-project.org> | 2016-07-22 09:10:17 +0200 |
commit | ce8cc9219fca5dde077f1142d03d011b38d27479 (patch) | |
tree | 01991fe739a7fd2702e010f0132033672a5d9d45 /quantum/process_keycode/process_tap_dance.h | |
parent | 70e42489dec375e558d8e81ed5ebfb69b4f3dbd9 (diff) | |
download | qmk_firmware-ce8cc9219fca5dde077f1142d03d011b38d27479.tar.gz qmk_firmware-ce8cc9219fca5dde077f1142d03d011b38d27479.zip |
tap-dance: Support user_data for the callbacks
Refactored the code a little, so all callbacks now receive a `user_data`
pointer, which can be anything. As an example, the key pairs from
`ACTION_TAP_DANCE_DOUBLE` now use this, and custom, built-in functions.
This makes it easier to extend the tap dance functionality, and also
simplifies the code a little.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 'quantum/process_keycode/process_tap_dance.h')
-rw-r--r-- | quantum/process_keycode/process_tap_dance.h | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index d457db9b3..e2c74efe9 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h | |||
@@ -17,42 +17,34 @@ typedef struct | |||
17 | 17 | ||
18 | #define TD(n) (QK_TAP_DANCE + n) | 18 | #define TD(n) (QK_TAP_DANCE + n) |
19 | 19 | ||
20 | typedef enum | 20 | typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data); |
21 | { | ||
22 | QK_TAP_DANCE_TYPE_PAIR, | ||
23 | QK_TAP_DANCE_TYPE_FN, | ||
24 | } qk_tap_dance_type_t; | ||
25 | |||
26 | typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state); | ||
27 | 21 | ||
28 | typedef struct | 22 | typedef struct |
29 | { | 23 | { |
30 | qk_tap_dance_type_t type; | 24 | struct { |
31 | union { | 25 | qk_tap_dance_user_fn_t on_each_tap; |
32 | struct { | 26 | qk_tap_dance_user_fn_t on_dance_finished; |
33 | uint16_t kc1; | 27 | qk_tap_dance_user_fn_t on_reset; |
34 | uint16_t kc2; | 28 | } fn; |
35 | } pair; | 29 | void *user_data; |
36 | struct { | ||
37 | qk_tap_dance_user_fn_t on_each_tap; | ||
38 | qk_tap_dance_user_fn_t on_dance_finished; | ||
39 | qk_tap_dance_user_fn_t on_reset; | ||
40 | } fn; | ||
41 | }; | ||
42 | } qk_tap_dance_action_t; | 30 | } qk_tap_dance_action_t; |
43 | 31 | ||
32 | typedef struct | ||
33 | { | ||
34 | uint16_t kc1; | ||
35 | uint16_t kc2; | ||
36 | } qk_tap_dance_pair_t; | ||
37 | |||
44 | #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ | 38 | #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ |
45 | .type = QK_TAP_DANCE_TYPE_PAIR, \ | 39 | .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \ |
46 | .pair = { kc1, kc2 } \ | 40 | .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }) \ |
47 | } | 41 | } |
48 | 42 | ||
49 | #define ACTION_TAP_DANCE_FN(user_fn) { \ | 43 | #define ACTION_TAP_DANCE_FN(user_fn) { \ |
50 | .type = QK_TAP_DANCE_TYPE_FN, \ | ||
51 | .fn = { NULL, user_fn, NULL } \ | 44 | .fn = { NULL, user_fn, NULL } \ |
52 | } | 45 | } |
53 | 46 | ||
54 | #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \ | 47 | #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \ |
55 | .type = QK_TAP_DANCE_TYPE_FN, \ | ||
56 | .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \ | 48 | .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \ |
57 | } | 49 | } |
58 | 50 | ||
@@ -64,6 +56,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record); | |||
64 | void matrix_scan_tap_dance (void); | 56 | void matrix_scan_tap_dance (void); |
65 | void reset_tap_dance (qk_tap_dance_state_t *state); | 57 | void reset_tap_dance (qk_tap_dance_state_t *state); |
66 | 58 | ||
59 | void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data); | ||
60 | void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data); | ||
61 | |||
67 | #else | 62 | #else |
68 | 63 | ||
69 | #define TD(n) KC_NO | 64 | #define TD(n) KC_NO |