diff options
author | Pavlos Vinieratos <pvinis@gmail.com> | 2016-07-13 16:47:45 +0200 |
---|---|---|
committer | Pavlos Vinieratos <pvinis@gmail.com> | 2016-07-16 00:04:12 +0200 |
commit | f3b56701ed7e6c622dc48e429780124ba5fde172 (patch) | |
tree | fa9ae933e8a5b67e17d7f41cf7bbc32c4e5f079e /quantum/process_keycode | |
parent | 1a7e954f9fc4d250ba1ae46e3bfc168aca2b5cce (diff) | |
download | qmk_firmware-f3b56701ed7e6c622dc48e429780124ba5fde172.tar.gz qmk_firmware-f3b56701ed7e6c622dc48e429780124ba5fde172.zip |
add an `anyway` and a `reset` callback
when using tap dance, we have the `regular` callback that is called on
the last tap. this commit adds an `anyway` callback that is called on
every tap, and a `reset` callback that is called on reset of the tap
dance taps.
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r-- | quantum/process_keycode/process_tap_dance.c | 36 | ||||
-rw-r--r-- | quantum/process_keycode/process_tap_dance.h | 28 |
2 files changed, 59 insertions, 5 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 186889bc2..40fba2a6a 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c | |||
@@ -40,7 +40,24 @@ void process_tap_dance_action (uint16_t keycode) | |||
40 | action.pair.kc1, action.pair.kc2); | 40 | action.pair.kc1, action.pair.kc2); |
41 | break; | 41 | break; |
42 | case QK_TAP_DANCE_TYPE_FN: | 42 | case QK_TAP_DANCE_TYPE_FN: |
43 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn); | 43 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.regular); |
44 | break; | ||
45 | |||
46 | default: | ||
47 | break; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | void process_tap_dance_action_anyway (uint16_t keycode) | ||
52 | { | ||
53 | uint16_t idx = keycode - QK_TAP_DANCE; | ||
54 | qk_tap_dance_action_t action; | ||
55 | |||
56 | action = tap_dance_actions[idx]; | ||
57 | |||
58 | switch (action.type) { | ||
59 | case QK_TAP_DANCE_TYPE_FN: | ||
60 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.anyway); | ||
44 | break; | 61 | break; |
45 | 62 | ||
46 | default: | 63 | default: |
@@ -53,6 +70,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
53 | 70 | ||
54 | switch(keycode) { | 71 | switch(keycode) { |
55 | case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: | 72 | case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: |
73 | process_tap_dance_action_anyway (qk_tap_dance_state.keycode); | ||
56 | if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) { | 74 | if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) { |
57 | process_tap_dance_action (qk_tap_dance_state.keycode); | 75 | process_tap_dance_action (qk_tap_dance_state.keycode); |
58 | } else { | 76 | } else { |
@@ -68,6 +86,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
68 | 86 | ||
69 | default: | 87 | default: |
70 | if (qk_tap_dance_state.keycode) { | 88 | if (qk_tap_dance_state.keycode) { |
89 | //process_tap_dance_action_anyway (qk_tap_dance_state.keycode); | ||
71 | process_tap_dance_action (qk_tap_dance_state.keycode); | 90 | process_tap_dance_action (qk_tap_dance_state.keycode); |
72 | 91 | ||
73 | reset_tap_dance (&qk_tap_dance_state); | 92 | reset_tap_dance (&qk_tap_dance_state); |
@@ -87,6 +106,21 @@ void matrix_scan_tap_dance () { | |||
87 | } | 106 | } |
88 | 107 | ||
89 | void reset_tap_dance (qk_tap_dance_state_t *state) { | 108 | void reset_tap_dance (qk_tap_dance_state_t *state) { |
109 | uint16_t idx = state->keycode - QK_TAP_DANCE; | ||
110 | qk_tap_dance_action_t action; | ||
111 | |||
112 | action = tap_dance_actions[idx]; | ||
113 | switch (action.type) { | ||
114 | case QK_TAP_DANCE_TYPE_FN: | ||
115 | if (action.fn.reset) { | ||
116 | action.fn.reset(); | ||
117 | } | ||
118 | break; | ||
119 | |||
120 | default: | ||
121 | break; | ||
122 | } | ||
123 | |||
90 | state->keycode = 0; | 124 | state->keycode = 0; |
91 | state->count = 0; | 125 | state->count = 0; |
92 | } | 126 | } |
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index b9d7c7fcf..bf925df0f 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h | |||
@@ -22,6 +22,7 @@ typedef enum | |||
22 | } qk_tap_dance_type_t; | 22 | } qk_tap_dance_type_t; |
23 | 23 | ||
24 | typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state); | 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); | ||
25 | 26 | ||
26 | typedef struct | 27 | typedef struct |
27 | { | 28 | { |
@@ -31,18 +32,37 @@ typedef struct | |||
31 | uint16_t kc1; | 32 | uint16_t kc1; |
32 | uint16_t kc2; | 33 | uint16_t kc2; |
33 | } pair; | 34 | } pair; |
34 | qk_tap_dance_user_fn_t fn; | 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; | ||
35 | }; | 40 | }; |
36 | } qk_tap_dance_action_t; | 41 | } qk_tap_dance_action_t; |
37 | 42 | ||
38 | #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ | 43 | #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \ |
39 | .type = QK_TAP_DANCE_TYPE_PAIR, \ | 44 | .type = QK_TAP_DANCE_TYPE_PAIR, \ |
40 | .pair = { kc1, kc2 } \ | 45 | .pair = { kc1, kc2 } \ |
41 | } | 46 | } |
42 | 47 | ||
43 | #define ACTION_TAP_DANCE_FN(user_fn) { \ | 48 | #define ACTION_TAP_DANCE_FN(user_fn) { \ |
44 | .type = QK_TAP_DANCE_TYPE_FN, \ | 49 | .type = QK_TAP_DANCE_TYPE_FN, \ |
45 | .fn = user_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 } \ | ||
46 | } | 66 | } |
47 | 67 | ||
48 | extern const qk_tap_dance_action_t tap_dance_actions[]; | 68 | extern const qk_tap_dance_action_t tap_dance_actions[]; |