diff options
| author | Pascal Getreuer <50221757+getreuer@users.noreply.github.com> | 2022-08-14 12:25:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-14 20:25:32 +0100 |
| commit | 95c43a275984fb57cdf6e5afd02190700e0205bc (patch) | |
| tree | a6bc77a909d48aa89c209a00cfd0cf4ca788d84c /tests | |
| parent | 6fc7c03e9581ddde68b32f2f76f8053628da6465 (diff) | |
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>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/caps_word/test_caps_word.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/tests/caps_word/test_caps_word.cpp b/tests/caps_word/test_caps_word.cpp index 0af4b0175d..3f59ed3744 100644 --- a/tests/caps_word/test_caps_word.cpp +++ b/tests/caps_word/test_caps_word.cpp | |||
| @@ -25,10 +25,47 @@ using ::testing::AnyOf; | |||
| 25 | using ::testing::InSequence; | 25 | using ::testing::InSequence; |
| 26 | using ::testing::TestParamInfo; | 26 | using ::testing::TestParamInfo; |
| 27 | 27 | ||
| 28 | namespace { | ||
| 29 | |||
| 30 | bool press_user_default(uint16_t keycode) { | ||
| 31 | switch (keycode) { | ||
| 32 | // Keycodes that continue Caps Word, with shift applied. | ||
| 33 | case KC_A ... KC_Z: | ||
| 34 | case KC_MINS: | ||
| 35 | add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key. | ||
| 36 | return true; | ||
| 37 | |||
| 38 | // Keycodes that continue Caps Word, without shifting. | ||
| 39 | case KC_1 ... KC_0: | ||
| 40 | case KC_BSPC: | ||
| 41 | case KC_DEL: | ||
| 42 | case KC_UNDS: | ||
| 43 | return true; | ||
| 44 | |||
| 45 | default: | ||
| 46 | return false; // Deactivate Caps Word. | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | uint16_t passed_keycode; | ||
| 51 | bool press_user_save_passed_keycode(uint16_t keycode) { | ||
| 52 | passed_keycode = keycode; | ||
| 53 | return true; | ||
| 54 | } | ||
| 55 | |||
| 56 | bool (*press_user_fun)(uint16_t) = press_user_default; | ||
| 57 | |||
| 58 | extern "C" { | ||
| 59 | bool caps_word_press_user(uint16_t keycode) { | ||
| 60 | return press_user_fun(keycode); | ||
| 61 | } | ||
| 62 | } // extern "C" | ||
| 63 | |||
| 28 | class CapsWord : public TestFixture { | 64 | class CapsWord : public TestFixture { |
| 29 | public: | 65 | public: |
| 30 | void SetUp() override { | 66 | void SetUp() override { |
| 31 | caps_word_off(); | 67 | caps_word_off(); |
| 68 | press_user_fun = press_user_default; | ||
| 32 | } | 69 | } |
| 33 | }; | 70 | }; |
| 34 | 71 | ||
| @@ -226,6 +263,126 @@ TEST_F(CapsWord, ShiftsAltGrSymbols) { | |||
| 226 | testing::Mock::VerifyAndClearExpectations(&driver); | 263 | testing::Mock::VerifyAndClearExpectations(&driver); |
| 227 | } | 264 | } |
| 228 | 265 | ||
| 266 | // Tests typing "AltGr + A" using a mod-tap key. | ||
| 267 | TEST_F(CapsWord, ShiftsModTapAltGrSymbols) { | ||
| 268 | TestDriver driver; | ||
| 269 | KeymapKey key_a(0, 0, 0, KC_A); | ||
| 270 | KeymapKey key_altgr_t(0, 1, 0, RALT_T(KC_B)); | ||
| 271 | set_keymap({key_a, key_altgr_t}); | ||
| 272 | |||
| 273 | // Allow any number of reports with no keys or only modifiers. | ||
| 274 | // clang-format off | ||
| 275 | EXPECT_CALL(driver, send_keyboard_mock(AnyOf( | ||
| 276 | KeyboardReport(), | ||
| 277 | KeyboardReport(KC_RALT), | ||
| 278 | KeyboardReport(KC_LSFT, KC_RALT)))) | ||
| 279 | .Times(AnyNumber()); | ||
| 280 | // Expect "Shift + AltGr + A". | ||
| 281 | EXPECT_REPORT(driver, (KC_LSFT, KC_RALT, KC_A)); | ||
| 282 | // clang-format on | ||
| 283 | |||
| 284 | // Turn on Caps Word and type "AltGr + A". | ||
| 285 | caps_word_on(); | ||
| 286 | |||
| 287 | key_altgr_t.press(); | ||
| 288 | idle_for(TAPPING_TERM + 1); | ||
| 289 | tap_key(key_a); | ||
| 290 | run_one_scan_loop(); | ||
| 291 | key_altgr_t.release(); | ||
| 292 | |||
| 293 | EXPECT_TRUE(is_caps_word_on()); | ||
| 294 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 295 | } | ||
| 296 | |||
| 297 | struct CapsWordPressUserParams { | ||
| 298 | std::string name; | ||
| 299 | uint16_t keycode; | ||
| 300 | uint16_t delay_ms; | ||
| 301 | uint16_t expected_passed_keycode; | ||
| 302 | bool continues_caps_word; | ||
| 303 | |||
| 304 | static const std::string& GetName(const TestParamInfo<CapsWordPressUserParams>& info) { | ||
| 305 | return info.param.name; | ||
| 306 | } | ||
| 307 | }; | ||
| 308 | |||
| 309 | class CapsWordPressUser : public ::testing::WithParamInterface<CapsWordPressUserParams>, public CapsWord { | ||
| 310 | void SetUp() override { | ||
| 311 | caps_word_on(); | ||
| 312 | passed_keycode = KC_NO; | ||
| 313 | press_user_fun = press_user_save_passed_keycode; | ||
| 314 | } | ||
| 315 | }; | ||
| 316 | |||
| 317 | // Tests keycodes passed to caps_word_press_user() function for various keys. | ||
| 318 | TEST_P(CapsWordPressUser, KeyCode) { | ||
| 319 | TestDriver driver; | ||
| 320 | KeymapKey key(0, 0, 0, GetParam().keycode); | ||
| 321 | set_keymap({key}); | ||
| 322 | |||
| 323 | EXPECT_ANY_REPORT(driver).Times(AnyNumber()); | ||
| 324 | tap_key(key, GetParam().delay_ms); | ||
| 325 | |||
| 326 | EXPECT_EQ(passed_keycode, GetParam().expected_passed_keycode); | ||
| 327 | EXPECT_EQ(is_caps_word_on(), GetParam().continues_caps_word); | ||
| 328 | clear_oneshot_mods(); | ||
| 329 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 330 | } | ||
| 331 | |||
| 332 | const uint16_t LT_1_KC_A = LT(1, KC_A); | ||
| 333 | // clang-format off | ||
| 334 | INSTANTIATE_TEST_CASE_P( | ||
| 335 | PressUser, | ||
| 336 | CapsWordPressUser, | ||
| 337 | ::testing::Values( | ||
| 338 | CapsWordPressUserParams{ | ||
| 339 | "KC_A", KC_A, 1, KC_A, true}, | ||
| 340 | CapsWordPressUserParams{ | ||
| 341 | "KC_HASH", KC_HASH, 1, KC_HASH, true}, | ||
| 342 | CapsWordPressUserParams{ | ||
| 343 | "KC_LSFT", KC_LSFT, 1, KC_LSFT, true}, | ||
| 344 | CapsWordPressUserParams{ | ||
| 345 | "KC_RSFT", KC_RSFT, 1, KC_RSFT, true}, | ||
| 346 | CapsWordPressUserParams{ | ||
| 347 | "LSFT_T_tapped", LSFT_T(KC_A), 1, KC_A, true}, | ||
| 348 | CapsWordPressUserParams{ | ||
| 349 | "LSFT_T_held", LSFT_T(KC_A), TAPPING_TERM + 1, KC_LSFT, true}, | ||
| 350 | CapsWordPressUserParams{ | ||
| 351 | "RSFT_T_held", RSFT_T(KC_A), TAPPING_TERM + 1, KC_RSFT, true}, | ||
| 352 | CapsWordPressUserParams{ | ||
| 353 | "RSA_T_held", RSA_T(KC_A), TAPPING_TERM + 1, RSFT(KC_RALT), true}, | ||
| 354 | // Holding a mod-tap other than Shift or AltGr stops Caps Word. | ||
| 355 | CapsWordPressUserParams{ | ||
| 356 | "LCTL_T_held", LCTL_T(KC_A), TAPPING_TERM + 1, KC_NO, false}, | ||
| 357 | CapsWordPressUserParams{ | ||
| 358 | "LALT_T_held", LALT_T(KC_A), TAPPING_TERM + 1, KC_NO, false}, | ||
| 359 | CapsWordPressUserParams{ | ||
| 360 | "LGUI_T_held", LGUI_T(KC_A), TAPPING_TERM + 1, KC_NO, false}, | ||
| 361 | // Layer keys are ignored and continue Caps Word. | ||
| 362 | CapsWordPressUserParams{ | ||
| 363 | "MO", MO(1), 1, KC_NO, true}, | ||
| 364 | CapsWordPressUserParams{ | ||
| 365 | "TO", TO(1), 1, KC_NO, true}, | ||
| 366 | CapsWordPressUserParams{ | ||
| 367 | "TG", TG(1), 1, KC_NO, true}, | ||
| 368 | CapsWordPressUserParams{ | ||
| 369 | "TT", TT(1), 1, KC_NO, true}, | ||
| 370 | CapsWordPressUserParams{ | ||
| 371 | "OSL", OSL(1), 1, KC_NO, true}, | ||
| 372 | CapsWordPressUserParams{ | ||
| 373 | "LT_held", LT_1_KC_A, TAPPING_TERM + 1, KC_NO, true}, | ||
| 374 | // AltGr keys are ignored and continue Caps Word. | ||
| 375 | CapsWordPressUserParams{ | ||
| 376 | "KC_RALT", KC_RALT, 1, KC_NO, true}, | ||
| 377 | CapsWordPressUserParams{ | ||
| 378 | "OSM_MOD_RALT", OSM(MOD_RALT), 1, KC_NO, true}, | ||
| 379 | CapsWordPressUserParams{ | ||
| 380 | "RALT_T_held", RALT_T(KC_A), TAPPING_TERM + 1, KC_NO, true} | ||
| 381 | ), | ||
| 382 | CapsWordPressUserParams::GetName | ||
| 383 | ); | ||
| 384 | // clang-format on | ||
| 385 | |||
| 229 | struct CapsWordBothShiftsParams { | 386 | struct CapsWordBothShiftsParams { |
| 230 | std::string name; | 387 | std::string name; |
| 231 | uint16_t left_shift_keycode; | 388 | uint16_t left_shift_keycode; |
| @@ -435,3 +592,5 @@ INSTANTIATE_TEST_CASE_P( | |||
| 435 | CapsWordDoubleTapShiftParams::GetName | 592 | CapsWordDoubleTapShiftParams::GetName |
| 436 | ); | 593 | ); |
| 437 | // clang-format on | 594 | // clang-format on |
| 595 | |||
| 596 | } // namespace | ||
