process_tap_dance.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef PROCESS_TAP_DANCE_H
  2. #define PROCESS_TAP_DANCE_H
  3. #ifdef TAP_DANCE_ENABLE
  4. #include <stdbool.h>
  5. #include <inttypes.h>
  6. typedef struct
  7. {
  8. uint8_t count;
  9. uint16_t keycode;
  10. uint16_t timer;
  11. bool active:1;
  12. bool pressed:1;
  13. } qk_tap_dance_state_t;
  14. #define TD(n) (QK_TAP_DANCE + n)
  15. typedef enum
  16. {
  17. QK_TAP_DANCE_TYPE_PAIR,
  18. QK_TAP_DANCE_TYPE_FN,
  19. } qk_tap_dance_type_t;
  20. typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state);
  21. typedef struct
  22. {
  23. qk_tap_dance_type_t type;
  24. union {
  25. struct {
  26. uint16_t kc1;
  27. uint16_t kc2;
  28. } pair;
  29. struct {
  30. qk_tap_dance_user_fn_t on_each_tap;
  31. qk_tap_dance_user_fn_t on_dance_finished;
  32. qk_tap_dance_user_fn_t on_reset;
  33. } fn;
  34. };
  35. } qk_tap_dance_action_t;
  36. #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
  37. .type = QK_TAP_DANCE_TYPE_PAIR, \
  38. .pair = { kc1, kc2 } \
  39. }
  40. #define ACTION_TAP_DANCE_FN(user_fn) { \
  41. .type = QK_TAP_DANCE_TYPE_FN, \
  42. .fn = { NULL, user_fn, NULL } \
  43. }
  44. #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \
  45. .type = QK_TAP_DANCE_TYPE_FN, \
  46. .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \
  47. }
  48. extern const qk_tap_dance_action_t tap_dance_actions[];
  49. /* To be used internally */
  50. bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
  51. void matrix_scan_tap_dance (void);
  52. void reset_tap_dance (qk_tap_dance_state_t *state);
  53. #else
  54. #define TD(n) KC_NO
  55. #endif
  56. #endif