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.

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