process_tap_dance.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright 2016 Jack Humbert
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef PROCESS_TAP_DANCE_H
  17. #define PROCESS_TAP_DANCE_H
  18. #ifdef TAP_DANCE_ENABLE
  19. #include <stdbool.h>
  20. #include <inttypes.h>
  21. typedef struct
  22. {
  23. uint8_t count;
  24. uint8_t oneshot_mods;
  25. uint16_t keycode;
  26. uint16_t timer;
  27. bool interrupted;
  28. bool pressed;
  29. bool finished;
  30. } qk_tap_dance_state_t;
  31. #define TD(n) (QK_TAP_DANCE + n)
  32. typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data);
  33. typedef struct
  34. {
  35. struct {
  36. qk_tap_dance_user_fn_t on_each_tap;
  37. qk_tap_dance_user_fn_t on_dance_finished;
  38. qk_tap_dance_user_fn_t on_reset;
  39. } fn;
  40. qk_tap_dance_state_t state;
  41. uint16_t custom_tapping_term;
  42. void *user_data;
  43. } qk_tap_dance_action_t;
  44. typedef struct
  45. {
  46. uint16_t kc1;
  47. uint16_t kc2;
  48. } qk_tap_dance_pair_t;
  49. #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
  50. .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
  51. .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \
  52. }
  53. #define ACTION_TAP_DANCE_FN(user_fn) { \
  54. .fn = { NULL, user_fn, NULL }, \
  55. .user_data = NULL, \
  56. }
  57. #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \
  58. .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
  59. .user_data = NULL, \
  60. }
  61. #define ACTION_TAP_DANCE_FN_ADVANCED_TIME(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, tap_specific_tapping_term) { \
  62. .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
  63. .user_data = NULL, \
  64. .custom_tapping_term = tap_specific_tapping_term, \
  65. }
  66. extern qk_tap_dance_action_t tap_dance_actions[];
  67. /* To be used internally */
  68. bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
  69. void matrix_scan_tap_dance (void);
  70. void reset_tap_dance (qk_tap_dance_state_t *state);
  71. void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
  72. void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
  73. #else
  74. #define TD(n) KC_NO
  75. #endif
  76. #endif