diff options
Diffstat (limited to 'quantum/process_keycode/process_tap_dance.c')
| -rw-r--r-- | quantum/process_keycode/process_tap_dance.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 94b6af130..d240dc2e6 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c | |||
| @@ -22,7 +22,7 @@ void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data) { | |||
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, | 25 | static inline void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, |
| 26 | void *user_data, | 26 | void *user_data, |
| 27 | qk_tap_dance_user_fn_t fn) | 27 | qk_tap_dance_user_fn_t fn) |
| 28 | { | 28 | { |
| @@ -31,34 +31,33 @@ static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state, | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void process_tap_dance_action_on_each_tap (uint16_t keycode) | 34 | static inline void process_tap_dance_action_on_each_tap (qk_tap_dance_action_t action) |
| 35 | { | 35 | { |
| 36 | uint16_t idx = keycode - QK_TAP_DANCE; | ||
| 37 | qk_tap_dance_action_t action; | ||
| 38 | |||
| 39 | action = tap_dance_actions[idx]; | ||
| 40 | |||
| 41 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_each_tap); | 36 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_each_tap); |
| 42 | } | 37 | } |
| 43 | 38 | ||
| 44 | void process_tap_dance_action_on_dance_finished (uint16_t keycode) | 39 | static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_action_t action) |
| 45 | { | 40 | { |
| 46 | uint16_t idx = keycode - QK_TAP_DANCE; | ||
| 47 | qk_tap_dance_action_t action; | ||
| 48 | |||
| 49 | action = tap_dance_actions[idx]; | ||
| 50 | |||
| 51 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_dance_finished); | 41 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_dance_finished); |
| 52 | } | 42 | } |
| 53 | 43 | ||
| 44 | static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t action) | ||
| 45 | { | ||
| 46 | _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_reset); | ||
| 47 | } | ||
| 48 | |||
| 54 | bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | 49 | bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { |
| 55 | bool r = true; | 50 | bool r = true; |
| 51 | uint16_t idx = keycode - QK_TAP_DANCE; | ||
| 52 | qk_tap_dance_action_t action; | ||
| 56 | 53 | ||
| 57 | switch(keycode) { | 54 | switch(keycode) { |
| 58 | case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: | 55 | case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: |
| 59 | process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode); | 56 | action = tap_dance_actions[idx]; |
| 57 | |||
| 58 | process_tap_dance_action_on_each_tap (action); | ||
| 60 | if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) { | 59 | if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) { |
| 61 | process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); | 60 | process_tap_dance_action_on_dance_finished (action); |
| 62 | } else if (qk_tap_dance_state.active && qk_tap_dance_state.pressed) { | 61 | } else if (qk_tap_dance_state.active && qk_tap_dance_state.pressed) { |
| 63 | reset_tap_dance (&qk_tap_dance_state); | 62 | reset_tap_dance (&qk_tap_dance_state); |
| 64 | } else { | 63 | } else { |
| @@ -77,8 +76,11 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
| 77 | default: | 76 | default: |
| 78 | if (qk_tap_dance_state.keycode) { | 77 | if (qk_tap_dance_state.keycode) { |
| 79 | // if we are here, the tap dance was interrupted by a different key | 78 | // if we are here, the tap dance was interrupted by a different key |
| 80 | process_tap_dance_action_on_each_tap (qk_tap_dance_state.keycode); | 79 | idx = qk_tap_dance_state.keycode - QK_TAP_DANCE; |
| 81 | process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); | 80 | action = tap_dance_actions[idx]; |
| 81 | |||
| 82 | process_tap_dance_action_on_each_tap (action); | ||
| 83 | process_tap_dance_action_on_dance_finished (action); | ||
| 82 | reset_tap_dance (&qk_tap_dance_state); | 84 | reset_tap_dance (&qk_tap_dance_state); |
| 83 | qk_tap_dance_state.active = false; | 85 | qk_tap_dance_state.active = false; |
| 84 | } | 86 | } |
| @@ -91,7 +93,10 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
| 91 | void matrix_scan_tap_dance () { | 93 | void matrix_scan_tap_dance () { |
| 92 | if (qk_tap_dance_state.active && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { | 94 | if (qk_tap_dance_state.active && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { |
| 93 | // if we are here, the tap dance was timed out | 95 | // if we are here, the tap dance was timed out |
| 94 | process_tap_dance_action_on_dance_finished (qk_tap_dance_state.keycode); | 96 | uint16_t idx = qk_tap_dance_state.keycode - QK_TAP_DANCE; |
| 97 | qk_tap_dance_action_t action = tap_dance_actions[idx]; | ||
| 98 | |||
| 99 | process_tap_dance_action_on_dance_finished (action); | ||
| 95 | reset_tap_dance (&qk_tap_dance_state); | 100 | reset_tap_dance (&qk_tap_dance_state); |
| 96 | } | 101 | } |
| 97 | } | 102 | } |
| @@ -104,9 +109,7 @@ void reset_tap_dance (qk_tap_dance_state_t *state) { | |||
| 104 | return; | 109 | return; |
| 105 | 110 | ||
| 106 | action = tap_dance_actions[idx]; | 111 | action = tap_dance_actions[idx]; |
| 107 | if (action.fn.on_reset) { | 112 | process_tap_dance_action_on_reset (action); |
| 108 | action.fn.on_reset(state, action.user_data); | ||
| 109 | } | ||
| 110 | 113 | ||
| 111 | state->keycode = 0; | 114 | state->keycode = 0; |
| 112 | state->count = 0; | 115 | state->count = 0; |
