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.

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