tap_dances.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Copyright 2021-2022 Rocco Meli <@RMeli>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "keyrecords/tap_dances.h"
  15. // + ---------- +
  16. // + TAP DANCES |
  17. // + ---------- +
  18. // Tap dances definitions
  19. // Need to needs to be defined in a .c file to avoid a linker error (multiple definitions)
  20. qk_tap_dance_action_t tap_dance_actions[] = {
  21. [TD_LSPO_CAPS] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, LSPO_CAPS_finished, LSPO_CAPS_reset),
  22. [TD_RSPC_CAPS] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, RSPC_CAPS_finished, RSPC_CAPS_reset),
  23. [TD_ESC_DEL] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_DEL),
  24. };
  25. // + ------ +
  26. // + DANCES |
  27. // + ------ +
  28. // https://github.com/qmk/qmk_firmware/blob/9294258c02d3e025e01935a06c4d9f1997535bda/users/gordon/gordon.c#L112-L135
  29. td_state_t hold_cur_dance(qk_tap_dance_state_t *state) {
  30. if (state->count == 1) {
  31. if (state->interrupted) {
  32. if (!state->pressed)
  33. return TD_SINGLE_TAP;
  34. else
  35. return TD_SINGLE_HOLD;
  36. } else {
  37. if (!state->pressed)
  38. return TD_SINGLE_TAP;
  39. else
  40. return TD_SINGLE_HOLD;
  41. }
  42. } else if (state->count == 2) {
  43. if (state->pressed)
  44. return TD_NONE;
  45. else
  46. return TD_DOUBLE_TAP;
  47. } else
  48. return TD_NONE;
  49. }
  50. // + ------------------------------------------------ +
  51. // + LEFT SHIFT PARENTHESIS OPEN (LSPO) AND CAPS LOCK |
  52. // + ------------------------------------------------ +
  53. // Create an instance of 'td_tap_t' for the 'LSPO_CAPS' tap dance.
  54. static td_tap_t LSPO_CAPS_state = {.is_press_action = true, .state = TD_NONE};
  55. void LSPO_CAPS_finished(qk_tap_dance_state_t *state, void *user_data) {
  56. LSPO_CAPS_state.state = hold_cur_dance(state);
  57. switch (LSPO_CAPS_state.state) {
  58. case TD_SINGLE_TAP:
  59. register_code16(KC_LPRN);
  60. break;
  61. case TD_SINGLE_HOLD:
  62. register_code16(KC_LSFT);
  63. break;
  64. case TD_DOUBLE_TAP:
  65. register_code16(KC_CAPS);
  66. break;
  67. case TD_NONE:
  68. break;
  69. }
  70. }
  71. void LSPO_CAPS_reset(qk_tap_dance_state_t *state, void *user_data) {
  72. switch (LSPO_CAPS_state.state) {
  73. case TD_SINGLE_TAP:
  74. unregister_code16(KC_LPRN);
  75. break;
  76. case TD_SINGLE_HOLD:
  77. unregister_code16(KC_LSFT);
  78. break;
  79. case TD_DOUBLE_TAP:
  80. unregister_code16(KC_CAPS);
  81. break;
  82. case TD_NONE:
  83. break;
  84. }
  85. LSPO_CAPS_state.state = TD_NONE;
  86. }
  87. // + -------------------------------------------------- +
  88. // + RIGHT SHIFT PARENTHESIS CLOSE (RSPC) AND CAPS LOCK |
  89. // + -------------------------------------------------- +
  90. // Create an instance of 'td_tap_t' for the 'RSPC_CAPS' tap dance.
  91. static td_tap_t RSPC_CAPS_state = {.is_press_action = true, .state = TD_NONE};
  92. void RSPC_CAPS_finished(qk_tap_dance_state_t *state, void *user_data) {
  93. RSPC_CAPS_state.state = hold_cur_dance(state);
  94. switch (RSPC_CAPS_state.state) {
  95. case TD_SINGLE_TAP:
  96. register_code16(KC_RPRN);
  97. break;
  98. case TD_SINGLE_HOLD:
  99. register_code16(KC_RSFT);
  100. break;
  101. case TD_DOUBLE_TAP:
  102. register_code16(KC_CAPS);
  103. break;
  104. case TD_NONE:
  105. break;
  106. }
  107. }
  108. void RSPC_CAPS_reset(qk_tap_dance_state_t *state, void *user_data) {
  109. switch (RSPC_CAPS_state.state) {
  110. case TD_SINGLE_TAP:
  111. unregister_code16(KC_RPRN);
  112. break;
  113. case TD_SINGLE_HOLD:
  114. unregister_code16(KC_RSFT);
  115. break;
  116. case TD_DOUBLE_TAP:
  117. unregister_code16(KC_CAPS);
  118. break;
  119. case TD_NONE:
  120. break;
  121. }
  122. RSPC_CAPS_state.state = TD_NONE;
  123. }