You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
9.4 KiB

Fix Caps Word to treat mod-taps more consistently. (#17463) * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Update quantum/process_keycode/process_caps_word.c Co-authored-by: Joel Challis <git@zvecr.com>
1 year ago
Fix Caps Word to treat mod-taps more consistently. (#17463) * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Update quantum/process_keycode/process_caps_word.c Co-authored-by: Joel Challis <git@zvecr.com>
1 year ago
Fix Caps Word to treat mod-taps more consistently. (#17463) * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Update quantum/process_keycode/process_caps_word.c Co-authored-by: Joel Challis <git@zvecr.com>
1 year ago
Fix Caps Word to treat mod-taps more consistently. (#17463) * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Update quantum/process_keycode/process_caps_word.c Co-authored-by: Joel Challis <git@zvecr.com>
1 year ago
Fix Caps Word to treat mod-taps more consistently. (#17463) * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Update quantum/process_keycode/process_caps_word.c Co-authored-by: Joel Challis <git@zvecr.com>
1 year ago
Fix Caps Word to treat mod-taps more consistently. (#17463) * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Fix Caps Word to treat mod-taps more consistently. Previously, holding any mod-tap key while Caps Word is active stops Caps Word, and this happens regardless of `caps_word_press_user()`. Yet for regular mod keys, AltGr (KC_RALT) is ignored, Shift keys are passed to `caps_word_press_user()` to determine whether to continue, and similarly, a key `RSFT(KC_RALT)` representing Right Shift + Alt is passed to `caps_word_press_user()` to determine whether to continue. This commit makes held mod-tap keys consistent with regular mod keys: * Holding a `RALT_T` mod-tap is ignored. * When holding a shift mod-tap key, `KC_LSFT` or `KC_RSFT` is passed to `caps_word_press_user()` to determine whether to continue. * When holding a Right Shift + Alt (`RSA_T`) mod-tap, `RSFT(KC_RALT)` is passed to `caps_word_press_user()`. Particularly, with this fix a user may choose to continue Caps Word when a shift mod-tap key is held by adding `KC_LSFT` and `KC_RSFT` cases in `caps_word_press_user()`. For instance as ``` bool caps_word_press_user(uint16_t keycode) { switch (keycode) { // Keycodes that continue Caps Word, with shift applied. case KC_A ... KC_Z: case KC_MINS: add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key. return true; // Keycodes that continue Caps Word, without shifting. case KC_1 ... KC_0: case KC_BSPC: case KC_DEL: case KC_UNDS: case KC_LSFT: // <<< Added here. case KC_RSFT: return true; default: return false; // Deactivate Caps Word. } } ``` * Update quantum/process_keycode/process_caps_word.c Co-authored-by: Joel Challis <git@zvecr.com>
1 year ago
  1. // Copyright 2021-2022 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_caps_word.h"
  15. #include "process_auto_shift.h"
  16. #include "process_space_cadet.h"
  17. #include "caps_word.h"
  18. #include "keycodes.h"
  19. #include "quantum_keycodes.h"
  20. #include "modifiers.h"
  21. #include "timer.h"
  22. #include "action_tapping.h"
  23. #include "action_util.h"
  24. #ifdef CAPS_WORD_INVERT_ON_SHIFT
  25. static uint8_t held_mods = 0;
  26. static bool handle_shift(uint16_t keycode, keyrecord_t* record) {
  27. switch (keycode) {
  28. case OSM(MOD_LSFT):
  29. keycode = KC_LSFT;
  30. break;
  31. case OSM(MOD_RSFT):
  32. keycode = KC_RSFT;
  33. break;
  34. # ifndef NO_ACTION_TAPPING
  35. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  36. if (record->tap.count == 0) { // Mod-tap key is held.
  37. switch (QK_MOD_TAP_GET_MODS(keycode)) {
  38. case MOD_LSFT:
  39. keycode = KC_LSFT;
  40. break;
  41. case MOD_RSFT:
  42. keycode = KC_RSFT;
  43. break;
  44. }
  45. }
  46. # endif // NO_ACTION_TAPPING
  47. }
  48. if (keycode == KC_LSFT || keycode == KC_RSFT) {
  49. const uint8_t mod = MOD_BIT(keycode);
  50. if (is_caps_word_on()) {
  51. if (record->event.pressed) {
  52. held_mods |= mod;
  53. } else {
  54. held_mods &= ~mod;
  55. }
  56. return false;
  57. } else if ((held_mods & mod) != 0) {
  58. held_mods &= ~mod;
  59. del_mods(mod);
  60. return record->event.pressed;
  61. }
  62. }
  63. return true;
  64. }
  65. #endif // CAPS_WORD_INVERT_ON_SHIFT
  66. bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
  67. if (keycode == QK_CAPS_WORD_TOGGLE) {
  68. if (record->event.pressed) {
  69. caps_word_toggle();
  70. }
  71. return false;
  72. }
  73. #ifdef CAPS_WORD_INVERT_ON_SHIFT
  74. if (!handle_shift(keycode, record)) {
  75. return false;
  76. }
  77. #endif // CAPS_WORD_INVERT_ON_SHIFT
  78. #ifndef NO_ACTION_ONESHOT
  79. const uint8_t mods = get_mods() | get_oneshot_mods();
  80. #else
  81. const uint8_t mods = get_mods();
  82. #endif // NO_ACTION_ONESHOT
  83. if (!is_caps_word_on()) {
  84. // The following optionally turns on Caps Word by holding left and
  85. // right shifts or by double tapping left shift. This way Caps Word
  86. // may be used without needing a dedicated key and also without
  87. // needing combos or tap dance.
  88. #ifdef BOTH_SHIFTS_TURNS_ON_CAPS_WORD
  89. // Many keyboards enable the Command feature by default, which also
  90. // uses left+right shift. It can be configured to use a different
  91. // key combination by defining IS_COMMAND(). We make a non-fatal
  92. // warning if Command is enabled but IS_COMMAND() is *not* defined.
  93. # if defined(COMMAND_ENABLE) && !defined(IS_COMMAND)
  94. # pragma message "BOTH_SHIFTS_TURNS_ON_CAPS_WORD and Command should not be enabled at the same time, since both use the Left Shift + Right Shift key combination. Please disable Command, or ensure that `IS_COMMAND` is not set to (get_mods() == MOD_MASK_SHIFT)."
  95. # else
  96. if (mods == MOD_MASK_SHIFT
  97. # ifdef COMMAND_ENABLE
  98. // Don't activate Caps Word at the same time as Command.
  99. && !(IS_COMMAND())
  100. # endif // COMMAND_ENABLE
  101. ) {
  102. caps_word_on();
  103. # ifdef SPACE_CADET_ENABLE
  104. reset_space_cadet();
  105. # endif // SPACE_CADET_ENABLE
  106. }
  107. # endif // defined(COMMAND_ENABLE) && !defined(IS_COMMAND)
  108. #endif // BOTH_SHIFTS_TURNS_ON_CAPS_WORD
  109. #ifdef DOUBLE_TAP_SHIFT_TURNS_ON_CAPS_WORD
  110. // Double tapping left shift turns on Caps Word.
  111. //
  112. // NOTE: This works with KC_LSFT and one-shot left shift. It
  113. // wouldn't make sense with mod-tap or Space Cadet shift since
  114. // double tapping would of course trigger the tapping action.
  115. if (record->event.pressed) {
  116. static bool tapped = false;
  117. static uint16_t timer = 0;
  118. if (keycode == KC_LSFT || keycode == OSM(MOD_LSFT)) {
  119. if (tapped && !timer_expired(record->event.time, timer)) {
  120. // Left shift was double tapped, activate Caps Word.
  121. caps_word_on();
  122. }
  123. tapped = true;
  124. timer = record->event.time + GET_TAPPING_TERM(keycode, record);
  125. } else {
  126. tapped = false; // Reset when any other key is pressed.
  127. }
  128. }
  129. #endif // DOUBLE_TAP_SHIFT_TURNS_ON_CAPS_WORD
  130. return true;
  131. }
  132. #if CAPS_WORD_IDLE_TIMEOUT > 0
  133. caps_word_reset_idle_timer();
  134. #endif // CAPS_WORD_IDLE_TIMEOUT > 0
  135. // From here on, we only take action on press events.
  136. if (!record->event.pressed) {
  137. return true;
  138. }
  139. if (!(mods & ~(MOD_MASK_SHIFT | MOD_BIT(KC_RALT)))) {
  140. switch (keycode) {
  141. // Ignore MO, TO, TG, TT, and OSL layer switch keys.
  142. case QK_MOMENTARY ... QK_MOMENTARY_MAX:
  143. case QK_TO ... QK_TO_MAX:
  144. case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
  145. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  146. case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
  147. case QK_TRI_LAYER_LOWER ... QK_TRI_LAYER_UPPER:
  148. // Ignore AltGr.
  149. case KC_RALT:
  150. case OSM(MOD_RALT):
  151. return true;
  152. #ifndef NO_ACTION_TAPPING
  153. // Corresponding to mod keys above, a held mod-tap is handled as:
  154. // * For shift mods, pass KC_LSFT or KC_RSFT to
  155. // caps_word_press_user() to determine whether to continue.
  156. // * For Shift + AltGr (MOD_RSFT | MOD_RALT), pass RSFT(KC_RALT).
  157. // * AltGr (MOD_RALT) is ignored.
  158. // * Otherwise stop Caps Word.
  159. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  160. if (record->tap.count == 0) { // Mod-tap key is held.
  161. const uint8_t mods = QK_MOD_TAP_GET_MODS(keycode);
  162. switch (mods) {
  163. # ifndef CAPS_WORD_INVERT_ON_SHIFT
  164. case MOD_LSFT:
  165. keycode = KC_LSFT;
  166. break;
  167. case MOD_RSFT:
  168. keycode = KC_RSFT;
  169. break;
  170. # endif // CAPS_WORD_INVERT_ON_SHIFT
  171. case MOD_RSFT | MOD_RALT:
  172. keycode = RSFT(KC_RALT);
  173. break;
  174. case MOD_RALT:
  175. return true;
  176. default:
  177. caps_word_off();
  178. # ifdef CAPS_WORD_INVERT_ON_SHIFT
  179. add_mods(held_mods);
  180. # endif // CAPS_WORD_INVERT_ON_SHIFT
  181. return true;
  182. }
  183. } else {
  184. keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
  185. }
  186. break;
  187. # ifndef NO_ACTION_LAYER
  188. case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
  189. # endif // NO_ACTION_LAYER
  190. if (record->tap.count == 0) {
  191. return true;
  192. }
  193. keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
  194. break;
  195. #endif // NO_ACTION_TAPPING
  196. #ifdef SWAP_HANDS_ENABLE
  197. case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
  198. // Note: IS_SWAP_HANDS_KEYCODE() actually tests for the special action keycodes like SH_TOGG, SH_TT, ...,
  199. // which currently overlap the SH_T(kc) range.
  200. if (IS_SWAP_HANDS_KEYCODE(keycode)
  201. # ifndef NO_ACTION_TAPPING
  202. || record->tap.count == 0
  203. # endif // NO_ACTION_TAPPING
  204. ) {
  205. return true;
  206. }
  207. keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode);
  208. break;
  209. #endif // SWAP_HANDS_ENABLE
  210. }
  211. #ifdef AUTO_SHIFT_ENABLE
  212. del_weak_mods(get_autoshift_state() ? ~MOD_BIT(KC_LSFT) : 0xff);
  213. #else
  214. clear_weak_mods();
  215. #endif // AUTO_SHIFT_ENABLE
  216. if (caps_word_press_user(keycode)) {
  217. #ifdef CAPS_WORD_INVERT_ON_SHIFT
  218. if (held_mods) {
  219. set_weak_mods(get_weak_mods() ^ MOD_BIT(KC_LSFT));
  220. }
  221. #endif // CAPS_WORD_INVERT_ON_SHIFT
  222. send_keyboard_report();
  223. return true;
  224. }
  225. }
  226. caps_word_off();
  227. #ifdef CAPS_WORD_INVERT_ON_SHIFT
  228. add_mods(held_mods);
  229. #endif // CAPS_WORD_INVERT_ON_SHIFT
  230. return true;
  231. }
  232. __attribute__((weak)) bool caps_word_press_user(uint16_t keycode) {
  233. switch (keycode) {
  234. // Keycodes that continue Caps Word, with shift applied.
  235. case KC_A ... KC_Z:
  236. case KC_MINS:
  237. add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key.
  238. return true;
  239. // Keycodes that continue Caps Word, without shifting.
  240. case KC_1 ... KC_0:
  241. case KC_BSPC:
  242. case KC_DEL:
  243. case KC_UNDS:
  244. return true;
  245. default:
  246. return false; // Deactivate Caps Word.
  247. }
  248. }