forked from forks/qmk_firmware
Tap dance introspection (#24049)
This commit is contained in:
parent
b9e67347f1
commit
4ae0ca5a11
|
@ -109,3 +109,26 @@ __attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) {
|
|||
}
|
||||
|
||||
#endif // defined(COMBO_ENABLE)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Tap Dance
|
||||
|
||||
#if defined(TAP_DANCE_ENABLE)
|
||||
|
||||
uint16_t tap_dance_count_raw(void) {
|
||||
return sizeof(tap_dance_actions) / sizeof(tap_dance_action_t);
|
||||
}
|
||||
|
||||
uint16_t tap_dance_count(void) {
|
||||
return tap_dance_count_raw();
|
||||
}
|
||||
|
||||
tap_dance_action_t* tap_dance_get_raw(uint16_t tap_dance_idx) {
|
||||
return &tap_dance_actions[tap_dance_idx];
|
||||
}
|
||||
|
||||
tap_dance_action_t* tap_dance_get(uint16_t tap_dance_idx) {
|
||||
return tap_dance_get_raw(tap_dance_idx);
|
||||
}
|
||||
|
||||
#endif // defined(TAP_DANCE_ENABLE)
|
||||
|
|
|
@ -61,9 +61,30 @@ uint16_t combo_count_raw(void);
|
|||
// Get the number of combos defined in the user's keymap, potentially stored dynamically
|
||||
uint16_t combo_count(void);
|
||||
|
||||
// Get the keycode for the encoder mapping location, stored in firmware rather than any other persistent storage
|
||||
// Get the combo definition, stored in firmware rather than any other persistent storage
|
||||
combo_t* combo_get_raw(uint16_t combo_idx);
|
||||
// Get the keycode for the encoder mapping location, potentially stored dynamically
|
||||
// Get the combo definition, potentially stored dynamically
|
||||
combo_t* combo_get(uint16_t combo_idx);
|
||||
|
||||
#endif // defined(COMBO_ENABLE)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Tap Dance
|
||||
|
||||
#if defined(TAP_DANCE_ENABLE)
|
||||
|
||||
// Forward declaration of tap_dance_action_t so we don't need to deal with header reordering
|
||||
struct tap_dance_action_t;
|
||||
typedef struct tap_dance_action_t tap_dance_action_t;
|
||||
|
||||
// Get the number of tap dances defined in the user's keymap, stored in firmware rather than any other persistent storage
|
||||
uint16_t tap_dance_count_raw(void);
|
||||
// Get the number of tap dances defined in the user's keymap, potentially stored dynamically
|
||||
uint16_t tap_dance_count(void);
|
||||
|
||||
// Get the tap dance definitions, stored in firmware rather than any other persistent storage
|
||||
tap_dance_action_t* tap_dance_get_raw(uint16_t tap_dance_idx);
|
||||
// Get the tap dance definitions, potentially stored dynamically
|
||||
tap_dance_action_t* tap_dance_get(uint16_t tap_dance_idx);
|
||||
|
||||
#endif // defined(TAP_DANCE_ENABLE)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "action_util.h"
|
||||
#include "timer.h"
|
||||
#include "wait.h"
|
||||
#include "keymap_introspection.h"
|
||||
|
||||
static uint16_t active_td;
|
||||
static uint16_t last_tap_time;
|
||||
|
@ -133,7 +134,7 @@ bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
|||
|
||||
if (!active_td || keycode == active_td) return false;
|
||||
|
||||
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(active_td)];
|
||||
action = tap_dance_get(QK_TAP_DANCE_GET_INDEX(active_td));
|
||||
action->state.interrupted = true;
|
||||
action->state.interrupting_keycode = keycode;
|
||||
process_tap_dance_action_on_dance_finished(action);
|
||||
|
@ -150,11 +151,16 @@ bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
|||
}
|
||||
|
||||
bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
||||
int td_index;
|
||||
tap_dance_action_t *action;
|
||||
|
||||
switch (keycode) {
|
||||
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
|
||||
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)];
|
||||
td_index = QK_TAP_DANCE_GET_INDEX(keycode);
|
||||
if (td_index >= tap_dance_count()) {
|
||||
return false;
|
||||
}
|
||||
action = tap_dance_get(td_index);
|
||||
|
||||
action->state.pressed = record->event.pressed;
|
||||
if (record->event.pressed) {
|
||||
|
@ -182,7 +188,7 @@ void tap_dance_task(void) {
|
|||
|
||||
if (!active_td || timer_elapsed(last_tap_time) <= GET_TAPPING_TERM(active_td, &(keyrecord_t){})) return;
|
||||
|
||||
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(active_td)];
|
||||
action = tap_dance_get(QK_TAP_DANCE_GET_INDEX(active_td));
|
||||
if (!action->state.interrupted) {
|
||||
process_tap_dance_action_on_dance_finished(action);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef struct {
|
|||
|
||||
typedef void (*tap_dance_user_fn_t)(tap_dance_state_t *state, void *user_data);
|
||||
|
||||
typedef struct {
|
||||
typedef struct tap_dance_action_t {
|
||||
tap_dance_state_t state;
|
||||
struct {
|
||||
tap_dance_user_fn_t on_each_tap;
|
||||
|
@ -78,8 +78,6 @@ typedef struct {
|
|||
#define TD_INDEX(code) QK_TAP_DANCE_GET_INDEX(code)
|
||||
#define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions)
|
||||
|
||||
extern tap_dance_action_t tap_dance_actions[];
|
||||
|
||||
void reset_tap_dance(tap_dance_state_t *state);
|
||||
|
||||
/* To be used internally */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "quantum.h"
|
||||
#include "examples.h"
|
||||
#include "keymap_introspection.h"
|
||||
|
||||
// Example code from the tap dance documentation, adapted for testing
|
||||
|
||||
|
@ -83,7 +84,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|||
|
||||
switch (keycode) {
|
||||
case TD(CT_CLN):
|
||||
action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)];
|
||||
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);
|
||||
|
|
|
@ -7,4 +7,4 @@
|
|||
|
||||
TAP_DANCE_ENABLE = yes
|
||||
|
||||
SRC += tap_dance_defs.c
|
||||
INTROSPECTION_KEYMAP_C = tap_dance_defs.c
|
||||
|
|
|
@ -18,5 +18,4 @@
|
|||
# --------------------------------------------------------------------------------
|
||||
|
||||
TAP_DANCE_ENABLE = yes
|
||||
|
||||
SRC += examples.c
|
||||
INTROSPECTION_KEYMAP_C = examples.c
|
||||
|
|
Loading…
Reference in a new issue