diff --git a/features/caps_word.c b/features/caps_word.c index 88e8177..f205700 100644 --- a/features/caps_word.c +++ b/features/caps_word.c @@ -65,22 +65,17 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { keycode &= 0xff; break; #endif // NO_ACTION_TAPPING - } - - switch (keycode) { - // Letter keys should be shifted. - case KC_A ... KC_Z: - add_weak_mods(MOD_BIT(KC_LSFT)); - return true; - // Keycodes that continue Caps Word but shouldn't get shifted. - case KC_1 ... KC_0: - case KC_BSPC: - case KC_MINS: - case KC_UNDS: - return true; +#ifdef SWAP_HANDS_ENABLE + case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: + if (keycode > 0x56F0 || record->tap.count == 0) { return true; } + keycode &= 0xff; + break; +#endif // SWAP_HANDS_ENABLE + } - // Any other keycode deactivates Caps Word. + if (caps_word_press_user(keycode)) { + return true; } } @@ -106,3 +101,22 @@ bool caps_word_get(void) { return caps_word_active; } __attribute__((weak)) void caps_word_set_user(bool active) {} +__attribute__((weak)) bool caps_word_press_user(uint16_t keycode) { + switch (keycode) { + // Keycodes that continue Caps Word, with shift applied. + case KC_A ... KC_Z: + 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_MINS: + case KC_UNDS: + return true; + + default: + return false; // Deactivate Caps Word. + } +} + diff --git a/features/caps_word.h b/features/caps_word.h index ef5a2b8..5080849 100644 --- a/features/caps_word.h +++ b/features/caps_word.h @@ -67,3 +67,36 @@ bool caps_word_get(void); // } void caps_word_set_user(bool active); +// An optional callback which is called on every key press while Caps Word is +// active. When the key should be shifted (that is, a letter key), the callback +// should call `add_weak_mods(MOD_BIT(KC_LSFT))` to shift the key. The callback +// also determines whether the key should continue Caps Word. Returning true +// continues the current "word", while returning false is "word breaking" and +// deactivates Caps Word. The default callback is +// +// bool caps_word_press_user(uint16_t keycode) { +// switch (keycode) { +// // Keycodes that continue Caps Word, with shift applied. +// case KC_A ... KC_Z: +// 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_MINS: +// case KC_UNDS: +// return true; +// +// default: +// return false; // Deactivate Caps Word. +// } +// } +// +// To customize, copy the above function into your keymap and add/remove +// keycodes to the above cases. +// +// NOTE: Outside of this callback, you can use `caps_word_set(false)` to +// deactivate Caps Word. +bool caps_word_press_user(uint16_t keycode); +