diff options
Diffstat (limited to 'quantum/process_keycode/process_tap_dance.c')
| -rw-r--r-- | quantum/process_keycode/process_tap_dance.c | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 9b172e1b6..b9b836df2 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c | |||
| @@ -22,10 +22,29 @@ static void _process_tap_dance_action_pair (qk_tap_dance_state_t *state, | |||
| 22 | static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, | 22 | static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, |
| 23 | qk_tap_dance_user_fn_t fn) | 23 | qk_tap_dance_user_fn_t fn) |
| 24 | { | 24 | { |
| 25 | fn(state); | 25 | if (fn) { |
| 26 | fn(state); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | void process_tap_dance_action_on_each_tap (uint16_t keycode) | ||
| 31 | { | ||
| 32 | uint16_t idx = keycode - QK_TAP_DANCE; | ||
| 33 | qk_tap_dance_action_t action; | ||
| 34 | |||
| 35 | action = tap_dance_actions[idx]; | ||
| 36 | |||
| 37 | switch (action.type) { | ||
| 38 | case QK_TAP_DANCE_TYPE_FN: | ||
| 39 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_each_tap); | ||
| 40 | break; | ||
| 41 | |||
| 42 | default: | ||
| 43 | break; | ||
| 44 | } | ||
| 26 | } | 45 | } |
| 27 | 46 | ||
| 28 | void process_tap_dance_action (uint16_t keycode) | 47 | void process_tap_dance_action_on_dance_finished (uint16_t keycode) |
| 29 | { | 48 | { |
| 30 | uint16_t idx = keycode - QK_TAP_DANCE; | 49 | uint16_t idx = keycode - QK_TAP_DANCE; |
| 31 | qk_tap_dance_action_t action; | 50 | qk_tap_dance_action_t action; |
| @@ -38,7 +57,7 @@ void process_tap_dance_action (uint16_t keycode) | |||
| 38 | action.pair.kc1, action.pair.kc2); | 57 | action.pair.kc1, action.pair.kc2); |
| 39 | break; | 58 | break; |
| 40 | case QK_TAP_DANCE_TYPE_FN: | 59 | case QK_TAP_DANCE_TYPE_FN: |
| 41 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn); | 60 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.on_dance_finished); |
| 42 | break; | 61 | break; |
| 43 | 62 | ||
| 44 | default: | 63 | default: |
| @@ -51,8 +70,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
| 51 | 70 | ||
| 52 | switch(keycode) { | 71 | switch(keycode) { |
| 53 | case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: | 72 | case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: |
| 73 | process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode); | ||
| 54 | 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) { |
| 55 | process_tap_dance_action (qk_tap_dance_state.keycode); | 75 | process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); |
| 56 | } else { | 76 | } else { |
| 57 | r = false; | 77 | r = false; |
| 58 | } | 78 | } |
| @@ -66,8 +86,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
| 66 | 86 | ||
| 67 | default: | 87 | default: |
| 68 | if (qk_tap_dance_state.keycode) { | 88 | if (qk_tap_dance_state.keycode) { |
| 69 | process_tap_dance_action (qk_tap_dance_state.keycode); | 89 | // if we are here, the tap dance was interrupted by a different key |
| 70 | 90 | process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode); | |
| 91 | process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); | ||
| 71 | reset_tap_dance (&qk_tap_dance_state); | 92 | reset_tap_dance (&qk_tap_dance_state); |
| 72 | } | 93 | } |
| 73 | break; | 94 | break; |
| @@ -78,13 +99,28 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
| 78 | 99 | ||
| 79 | void matrix_scan_tap_dance () { | 100 | void matrix_scan_tap_dance () { |
| 80 | if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { | 101 | if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { |
| 81 | process_tap_dance_action (qk_tap_dance_state.keycode); | 102 | // if we are here, the tap dance was timed out |
| 82 | 103 | process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); | |
| 83 | reset_tap_dance (&qk_tap_dance_state); | 104 | reset_tap_dance (&qk_tap_dance_state); |
| 84 | } | 105 | } |
| 85 | } | 106 | } |
| 86 | 107 | ||
| 87 | 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.on_reset) { | ||
| 116 | action.fn.on_reset(state); | ||
| 117 | } | ||
| 118 | break; | ||
| 119 | |||
| 120 | default: | ||
| 121 | break; | ||
| 122 | } | ||
| 123 | |||
| 88 | state->keycode = 0; | 124 | state->keycode = 0; |
| 89 | state->count = 0; | 125 | state->count = 0; |
| 90 | } | 126 | } |
