dancelayers.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright 2020 Stephen J. Bush
  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. #pragma once
  17. #ifdef TAP_DANCE_ENABLE
  18. # include QMK_KEYBOARD_H
  19. /*
  20. * TAP DANCE
  21. * https://docs.qmk.fm/#/feature_tap_dance
  22. */
  23. // Define a type for as many tap dance states as you need
  24. typedef enum {
  25. TD_NONE = 0,
  26. TD_UNKNOWN,
  27. TD_1X_TAP,
  28. TD_1X_HOLD,
  29. TD_2X_TAP,
  30. TD_3X_TAP,
  31. TD_4X_TAP,
  32. } td_state_t;
  33. // Our custom tap dance key; add any other tap dance keys to this enum
  34. enum {
  35. TD_LAYERS = 0, // NOTE: Start at 0 as this is also an array index
  36. };
  37. # define TD_LAYR TD(TD_LAYERS)
  38. typedef struct {
  39. bool is_press_action;
  40. td_state_t state;
  41. } td_tap_t;
  42. // Declare the functions to be used with your tap dance key(s)
  43. /* @brief Determine the current tap dance state
  44. * @param A tap dance state struct.
  45. * @return A struct.
  46. */
  47. td_state_t cur_dance(tap_dance_state_t *state);
  48. // Functions associated with individual tap dances
  49. /* @brief Associate tap actions with layers.
  50. *
  51. * NOTE: Weak attribute. Can (and should) be defined in keymap.c
  52. *
  53. * @param state Pointer to a tap dance state object.
  54. * @param user_data Pointer to user data.
  55. * @return None.
  56. */
  57. void td_layer_finished(tap_dance_state_t *state, void *user_data);
  58. /* @brief Reset tap dance actions.
  59. *
  60. * NOTE: Weak attribute. Can (and should) be defined in keymap.c
  61. *
  62. * @param state Pointer to a tap dance state object.
  63. * @param user_data Pointer to user data.
  64. * @return None.
  65. */
  66. void td_layer_reset(tap_dance_state_t *state, void *user_data);
  67. /* Define tap dance actions.
  68. */
  69. __attribute__((weak))
  70. tap_dance_action_t tap_dance_actions[1] = {[TD_LAYERS] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_layer_finished, td_layer_reset, 275)};
  71. #endif