logo

qmk_firmware

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

process_repeat_key.c (3673B)


  1. // Copyright 2022-2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "process_repeat_key.h"
  15. #include "repeat_key.h"
  16. #include "keycodes.h"
  17. #include "quantum_keycodes.h"
  18. #include "action_util.h"
  19. // Default implementation of remember_last_key_user().
  20. __attribute__((weak)) bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) {
  21. return true;
  22. }
  23. static bool remember_last_key(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) {
  24. switch (keycode) {
  25. // Ignore MO, TO, TG, TT, and TL layer switch keys.
  26. case QK_MOMENTARY ... QK_MOMENTARY_MAX:
  27. case QK_TO ... QK_TO_MAX:
  28. case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
  29. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  30. // Ignore mod keys.
  31. case KC_LCTL ... KC_RGUI:
  32. case KC_HYPR:
  33. case KC_MEH:
  34. #ifndef NO_ACTION_ONESHOT // Ignore one-shot keys.
  35. case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
  36. case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
  37. #endif // NO_ACTION_ONESHOT
  38. #ifdef TRI_LAYER_ENABLE // Ignore Tri Layer keys.
  39. case QK_TRI_LAYER_LOWER:
  40. case QK_TRI_LAYER_UPPER:
  41. #endif // TRI_LAYER_ENABLE
  42. #ifdef LAYER_LOCK_ENABLE // Ignore Layer Lock key.
  43. case QK_LAYER_LOCK:
  44. #endif // LAYER_LOCK_ENABLE
  45. return false;
  46. // Ignore hold events on tap-hold keys.
  47. #ifndef NO_ACTION_TAPPING
  48. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  49. # ifndef NO_ACTION_LAYER
  50. case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
  51. # endif // NO_ACTION_LAYER
  52. if (record->tap.count == 0) {
  53. return false;
  54. }
  55. break;
  56. #endif // NO_ACTION_TAPPING
  57. #ifdef SWAP_HANDS_ENABLE
  58. case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
  59. if (IS_SWAP_HANDS_KEYCODE(keycode) || record->tap.count == 0) {
  60. return false;
  61. }
  62. break;
  63. #endif // SWAP_HANDS_ENABLE
  64. case QK_REPEAT_KEY:
  65. #ifndef NO_ALT_REPEAT_KEY
  66. case QK_ALT_REPEAT_KEY:
  67. #endif // NO_ALT_REPEAT_KEY
  68. return false;
  69. }
  70. return remember_last_key_user(keycode, record, remembered_mods);
  71. }
  72. bool process_last_key(uint16_t keycode, keyrecord_t* record) {
  73. if (get_repeat_key_count()) {
  74. return true;
  75. }
  76. if (record->event.pressed) {
  77. uint8_t remembered_mods = get_mods() | get_weak_mods();
  78. #ifndef NO_ACTION_ONESHOT
  79. remembered_mods |= get_oneshot_mods();
  80. #endif // NO_ACTION_ONESHOT
  81. if (remember_last_key(keycode, record, &remembered_mods)) {
  82. set_last_record(keycode, record);
  83. set_last_mods(remembered_mods);
  84. }
  85. }
  86. return true;
  87. }
  88. bool process_repeat_key(uint16_t keycode, keyrecord_t* record) {
  89. if (get_repeat_key_count()) {
  90. return true;
  91. }
  92. if (keycode == QK_REPEAT_KEY) {
  93. repeat_key_invoke(&record->event);
  94. return false;
  95. #ifndef NO_ALT_REPEAT_KEY
  96. } else if (keycode == QK_ALT_REPEAT_KEY) {
  97. alt_repeat_key_invoke(&record->event);
  98. return false;
  99. #endif // NO_ALT_REPEAT_KEY
  100. }
  101. return true;
  102. }