diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ChangeLog/20250831/pr25415.md | 47 | ||||
| -rw-r--r-- | docs/features/tap_dance.md | 12 |
2 files changed, 56 insertions, 3 deletions
diff --git a/docs/ChangeLog/20250831/pr25415.md b/docs/ChangeLog/20250831/pr25415.md new file mode 100644 index 0000000000..54eb8c737e --- /dev/null +++ b/docs/ChangeLog/20250831/pr25415.md @@ -0,0 +1,47 @@ +# Tap dance state removed from `tap_dance_action_t` + +The tap dance state has been separated from the action structure. Custom tap dance functions now receive the state as a separate parameter instead of accessing it through `action->state`. + +## User Action Required + +If your keymap uses custom tap dance functions that access the tap dance state, you need to update your code. + + - You can't use `action->state`. Instead you need to call `tap_dance_state_t *tap_dance_get_state(uint8_t tap_dance_idx)` to get the state. + - You now get a pointer to the state, so use `->` notation rather than `.` notation to get fields from it. + +### Before: +```c +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + tap_dance_action_t *action; + + switch (keycode) { + case TD(CT_CLN): + action = tap_dance_get(QK_TAP_DANCE_GET_INDEX(keycode)); + if (!record->event.pressed && action->state.count && !action->state.finished) { + tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; + tap_code16(tap_hold->tap); + } + + } + return true; +} +``` + +### After: +```c +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + tap_dance_action_t *action; + tap_dance_state_t* state; + + switch (keycode) { + case TD(CT_CLN): + action = tap_dance_get(QK_TAP_DANCE_GET_INDEX(keycode)); + state = tap_dance_get_state(QK_TAP_DANCE_GET_INDEX(keycode)); + if (!record->event.pressed && state != NULL && state->count && !state->finished) { + tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; + tap_code16(tap_hold->tap); + } + } + return true; +} +``` diff --git a/docs/features/tap_dance.md b/docs/features/tap_dance.md index d533e41aaa..688241a16b 100644 --- a/docs/features/tap_dance.md +++ b/docs/features/tap_dance.md @@ -40,6 +40,10 @@ Similar to the first option, the second and third option are good for simple lay For more complicated cases, like blink the LEDs, fiddle with the backlighting, and so on, use the fourth or fifth option. Examples of each are listed below. +::: tip +If too many tap dances are active at the same time, later ones won't have any effect. You need to increase `TAP_DANCE_MAX_SIMULTANEOUS` by adding `#define TAP_DANCE_MAX_SIMULTANEOUS 5` (or higher) to your keymap's `config.h` file if you expect that users may hold down many tap dance keys simultaneously. By default, only 3 tap dance keys can be used together at the same time. +::: + ## Implementation Details {#implementation} Well, that's the bulk of it! You should now be able to work through the examples below, and to develop your own Tap Dance functionality. But if you want a deeper understanding of what's going on behind the scenes, then read on for the explanation of how it all works! @@ -209,11 +213,13 @@ tap_dance_action_t tap_dance_actions[] = { bool process_record_user(uint16_t keycode, keyrecord_t *record) { tap_dance_action_t *action; + tap_dance_state_t* state; switch (keycode) { - case TD(CT_CLN): // list all tap dance keycodes with tap-hold configurations - action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)]; - if (!record->event.pressed && action->state.count && !action->state.finished) { + case TD(CT_CLN): + action = tap_dance_get(QK_TAP_DANCE_GET_INDEX(keycode)); + state = tap_dance_get_state(QK_TAP_DANCE_GET_INDEX(keycode)); + if (!record->event.pressed && state != NULL && state->count && !state->finished) { tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; tap_code16(tap_hold->tap); } |