mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-29 20:26:56 +06:00
29f64d7a93
This reworks how the tap-dance feature works: instead of one global state, we have a state for each tap-dance key, so we can cancel them when another tap-dance key is in flight. This fixes #527. Since we have a state for each key, we can avoid situation where a keyup would mess with our global state. This fixes #563. And while here, we also make sure to fire events only once, and this fixes #574. There is one breaking change, though: tap-dance debugging support was removed, because dumping the whole state would increase the firmware size too much. Any keymap that made use of this, will have to be updated (but there's no such keymap in the repo). Also, there's a nice trick used in this rework: we need to iterate through tap_dance_actions in a few places, to check for timeouts, and so on. For this, we'd need to know the size of the array. We can't discover that at compile-time, because tap-dance gets compiled separately. We'd like to avoid having to terminate the list with a sentinel value, because that would require updates to all keymaps that use the feature. So, we keep track of the highest tap-dance code seen so far, and iterate until that index. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
71 lines
1.6 KiB
C
71 lines
1.6 KiB
C
#ifndef PROCESS_TAP_DANCE_H
|
|
#define PROCESS_TAP_DANCE_H
|
|
|
|
#ifdef TAP_DANCE_ENABLE
|
|
|
|
#include <stdbool.h>
|
|
#include <inttypes.h>
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t count;
|
|
uint16_t keycode;
|
|
uint16_t timer;
|
|
bool interrupted;
|
|
bool pressed;
|
|
bool finished;
|
|
} qk_tap_dance_state_t;
|
|
|
|
#define TD(n) (QK_TAP_DANCE + n)
|
|
|
|
typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data);
|
|
|
|
typedef struct
|
|
{
|
|
struct {
|
|
qk_tap_dance_user_fn_t on_each_tap;
|
|
qk_tap_dance_user_fn_t on_dance_finished;
|
|
qk_tap_dance_user_fn_t on_reset;
|
|
} fn;
|
|
qk_tap_dance_state_t state;
|
|
void *user_data;
|
|
} qk_tap_dance_action_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t kc1;
|
|
uint16_t kc2;
|
|
} qk_tap_dance_pair_t;
|
|
|
|
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
|
|
.fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
|
|
.user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }) \
|
|
}
|
|
|
|
#define ACTION_TAP_DANCE_FN(user_fn) { \
|
|
.fn = { NULL, user_fn, NULL } \
|
|
}
|
|
|
|
#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \
|
|
.fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \
|
|
}
|
|
|
|
extern qk_tap_dance_action_t tap_dance_actions[];
|
|
|
|
/* To be used internally */
|
|
|
|
bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
|
|
void matrix_scan_tap_dance (void);
|
|
void reset_tap_dance (qk_tap_dance_state_t *state);
|
|
|
|
void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
|
|
void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
|
|
|
|
#else
|
|
|
|
#define TD(n) KC_NO
|
|
|
|
#endif
|
|
|
|
#endif
|