logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

action_tapping.h (6892B)


  1. /*
  2. Copyright 2013 Jun Wako <wakojun@gmail.com>
  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. #pragma once
  15. /* period of tapping(ms) */
  16. #ifndef TAPPING_TERM
  17. # define TAPPING_TERM 200
  18. #endif
  19. /* period of quick tap(ms) */
  20. #if !defined(QUICK_TAP_TERM) || QUICK_TAP_TERM > TAPPING_TERM
  21. # define QUICK_TAP_TERM TAPPING_TERM
  22. #endif
  23. /* tap count needed for toggling a feature */
  24. #ifndef TAPPING_TOGGLE
  25. # define TAPPING_TOGGLE 5
  26. #endif
  27. #define WAITING_BUFFER_SIZE 8
  28. #ifndef NO_ACTION_TAPPING
  29. uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
  30. uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
  31. void action_tapping_process(keyrecord_t record);
  32. #endif
  33. uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record);
  34. uint16_t get_quick_tap_term(uint16_t keycode, keyrecord_t *record);
  35. bool get_permissive_hold(uint16_t keycode, keyrecord_t *record);
  36. bool get_retro_tapping(uint16_t keycode, keyrecord_t *record);
  37. bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record);
  38. #ifdef CHORDAL_HOLD
  39. /**
  40. * Callback to say when a key chord before the tapping term may be held.
  41. *
  42. * In keymap.c, define the callback
  43. *
  44. * bool get_chordal_hold(uint16_t tap_hold_keycode,
  45. * keyrecord_t* tap_hold_record,
  46. * uint16_t other_keycode,
  47. * keyrecord_t* other_record) {
  48. * // Conditions...
  49. * }
  50. *
  51. * This callback is called when:
  52. *
  53. * 1. `tap_hold_keycode` is pressed.
  54. * 2. `other_keycode` is pressed while `tap_hold_keycode` is still held,
  55. * provided `other_keycode` is *not* also a tap-hold key and it is pressed
  56. * before the tapping term.
  57. *
  58. * If false is returned, this has the effect of immediately settling the
  59. * tap-hold key as tapped. If true is returned, the tap-hold key is still
  60. * unsettled, and may be settled as held depending on configuration and
  61. * subsequent events.
  62. *
  63. * @param tap_hold_keycode Keycode of the tap-hold key.
  64. * @param tap_hold_record Record from the tap-hold press event.
  65. * @param other_keycode Keycode of the other key.
  66. * @param other_record Record from the other key's press event.
  67. * @return True if the tap-hold key may be considered held; false if tapped.
  68. */
  69. bool get_chordal_hold(uint16_t tap_hold_keycode, keyrecord_t *tap_hold_record, uint16_t other_keycode, keyrecord_t *other_record);
  70. /**
  71. * Default "opposite hands rule" for whether a key chord may settle as held.
  72. *
  73. * This function returns true when the tap-hold key and other key are on
  74. * "opposite hands." In detail, handedness of the two keys are compared. If
  75. * handedness values differ, or if either handedness is '*', the function
  76. * returns true, indicating that it may be held. Otherwise, it returns false,
  77. * in which case the tap-hold key is immediately settled at tapped.
  78. *
  79. * @param tap_hold_record Record of the active tap-hold key press.
  80. * @param other_record Record of the other, interrupting key press.
  81. * @return True if the tap-hold key may be considered held; false if tapped.
  82. */
  83. bool get_chordal_hold_default(keyrecord_t *tap_hold_record, keyrecord_t *other_record);
  84. /**
  85. * Gets the handedness of a key.
  86. *
  87. * This function returns:
  88. * 'L' for keys pressed by the left hand,
  89. * 'R' for keys on the right hand,
  90. * '*' for keys exempt from the "opposite hands rule." This could be used
  91. * perhaps on thumb keys or keys that might be pressed by either hand.
  92. *
  93. * @param key A key matrix position.
  94. * @return Handedness value.
  95. */
  96. char chordal_hold_handedness(keypos_t key);
  97. extern const char chordal_hold_layout[MATRIX_ROWS][MATRIX_COLS] PROGMEM;
  98. #endif
  99. #ifdef FLOW_TAP_TERM
  100. /**
  101. * Callback to specify the keys where Flow Tap is enabled.
  102. *
  103. * Flow Tap is constrained to certain keys by the following rule: this callback
  104. * is called for both the tap-hold key *and* the key press immediately preceding
  105. * it. If the callback returns true for both keycodes, Flow Tap is enabled.
  106. *
  107. * The default implementation of this callback corresponds to
  108. *
  109. * bool is_flow_tap_key(uint16_t keycode) {
  110. * switch (get_tap_keycode(keycode)) {
  111. * case KC_SPC:
  112. * case KC_A ... KC_Z:
  113. * case KC_DOT:
  114. * case KC_COMM:
  115. * case KC_SCLN:
  116. * case KC_SLSH:
  117. * return true;
  118. * }
  119. * return false;
  120. * }
  121. *
  122. * @param keycode Keycode of the key.
  123. * @return Whether to enable Flow Tap for this key.
  124. */
  125. bool is_flow_tap_key(uint16_t keycode);
  126. /**
  127. * Callback to customize Flow Tap filtering.
  128. *
  129. * Flow Tap acts only when key events are closer together than this time.
  130. *
  131. * Return a time of 0 to disable filtering. In this way, Flow Tap may be
  132. * disabled for certain tap-hold keys, or when following certain previous keys.
  133. *
  134. * The default implementation of this callback is
  135. *
  136. * uint16_t get_flow_tap_term(uint16_t keycode, keyrecord_t* record,
  137. * uint16_t prev_keycode) {
  138. * if (is_flow_tap_key(keycode) && is_flow_tap_key(prev_keycode)) {
  139. * return g_flow_tap_term;
  140. * }
  141. * return 0;
  142. * }
  143. *
  144. * NOTE: If both `is_flow_tap_key()` and `get_flow_tap_term()` are defined, then
  145. * `get_flow_tap_term()` takes precedence.
  146. *
  147. * @param keycode Keycode of the tap-hold key.
  148. * @param record keyrecord_t of the tap-hold event.
  149. * @param prev_keycode Keycode of the previously pressed key.
  150. * @return Time in milliseconds.
  151. */
  152. uint16_t get_flow_tap_term(uint16_t keycode, keyrecord_t *record, uint16_t prev_keycode);
  153. /** Updates the Flow Tap last key and timer. */
  154. void flow_tap_update_last_event(keyrecord_t *record);
  155. #endif // FLOW_TAP_TERM
  156. #ifdef DYNAMIC_TAPPING_TERM_ENABLE
  157. extern uint16_t g_tapping_term;
  158. #endif
  159. #if defined(TAPPING_TERM_PER_KEY) && !defined(NO_ACTION_TAPPING)
  160. # define GET_TAPPING_TERM(keycode, record) get_tapping_term(keycode, record)
  161. #elif defined(DYNAMIC_TAPPING_TERM_ENABLE) && !defined(NO_ACTION_TAPPING)
  162. # define GET_TAPPING_TERM(keycode, record) g_tapping_term
  163. #else
  164. # define GET_TAPPING_TERM(keycode, record) (TAPPING_TERM)
  165. #endif
  166. #ifdef QUICK_TAP_TERM_PER_KEY
  167. # define GET_QUICK_TAP_TERM(keycode, record) get_quick_tap_term(keycode, record)
  168. #else
  169. # define GET_QUICK_TAP_TERM(keycode, record) (QUICK_TAP_TERM)
  170. #endif