process_tap_dance.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. void *user_data;
  42. } qk_tap_dance_action_t;
  43. typedef struct
  44. {
  45. uint16_t kc1;
  46. uint16_t kc2;
  47. } qk_tap_dance_pair_t;
  48. #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
  49. .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
  50. .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \
  51. }
  52. #define ACTION_TAP_DANCE_FN(user_fn) { \
  53. .fn = { NULL, user_fn, NULL }, \
  54. .user_data = NULL, \
  55. }
  56. #define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) { \
  57. .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset }, \
  58. .user_data = NULL, \
  59. }
  60. extern qk_tap_dance_action_t tap_dance_actions[];
  61. /* To be used internally */
  62. bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
  63. void matrix_scan_tap_dance (void);
  64. void reset_tap_dance (qk_tap_dance_state_t *state);
  65. void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
  66. void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
  67. #else
  68. #define TD(n) KC_NO
  69. #endif
  70. #endif