123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #include "process_caps_word.h"
- bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
- if (keycode == CAPSWRD) {
- if (record->event.pressed) {
- caps_word_toggle();
- }
- return false;
- }
- #ifndef NO_ACTION_ONESHOT
- const uint8_t mods = get_mods() | get_oneshot_mods();
- #else
- const uint8_t mods = get_mods();
- #endif
- if (!is_caps_word_on()) {
-
-
-
-
- #ifdef BOTH_SHIFTS_TURNS_ON_CAPS_WORD
-
-
-
-
- # if defined(COMMAND_ENABLE) && !defined(IS_COMMAND)
- # 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)."
- # else
- if (mods == MOD_MASK_SHIFT
- # ifdef COMMAND_ENABLE
-
- && !(IS_COMMAND())
- # endif
- ) {
- caps_word_on();
- }
- # endif
- #endif
- #ifdef DOUBLE_TAP_SHIFT_TURNS_ON_CAPS_WORD
-
-
-
-
-
- if (record->event.pressed) {
- static bool tapped = false;
- static uint16_t timer = 0;
- if (keycode == KC_LSFT || keycode == OSM(MOD_LSFT)) {
- if (tapped && !timer_expired(record->event.time, timer)) {
-
- caps_word_on();
- }
- tapped = true;
- timer = record->event.time + GET_TAPPING_TERM(keycode, record);
- } else {
- tapped = false;
- }
- }
- #endif
- return true;
- }
- #if CAPS_WORD_IDLE_TIMEOUT > 0
- caps_word_reset_idle_timer();
- #endif
-
- if (!record->event.pressed) {
- return true;
- }
- if (!(mods & ~(MOD_MASK_SHIFT | MOD_BIT(KC_RALT)))) {
- switch (keycode) {
-
- case QK_MOMENTARY ... QK_MOMENTARY_MAX:
- case QK_TO ... QK_TO_MAX:
- case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
- case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
- case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
-
- case KC_RALT:
- case OSM(MOD_RALT):
- return true;
- #ifndef NO_ACTION_TAPPING
-
-
-
-
-
-
- case QK_MOD_TAP ... QK_MOD_TAP_MAX:
- if (record->tap.count == 0) {
- const uint8_t mods = (keycode >> 8) & 0x1f;
- switch (mods) {
- case MOD_LSFT:
- keycode = KC_LSFT;
- break;
- case MOD_RSFT:
- keycode = KC_RSFT;
- break;
- case MOD_RSFT | MOD_RALT:
- keycode = RSFT(KC_RALT);
- break;
- case MOD_RALT:
- return true;
- default:
- caps_word_off();
- return true;
- }
- } else {
- keycode &= 0xff;
- }
- break;
- # ifndef NO_ACTION_LAYER
- case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
- # endif
- if (record->tap.count == 0) {
- return true;
- }
- keycode &= 0xff;
- break;
- #endif
- #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
- }
- #ifdef AUTO_SHIFT_ENABLE
- del_weak_mods(get_autoshift_state() ? ~MOD_BIT(KC_LSFT) : 0xff);
- #else
- clear_weak_mods();
- #endif
- if (caps_word_press_user(keycode)) {
- send_keyboard_report();
- return true;
- }
- }
- caps_word_off();
- return true;
- }
- __attribute__((weak)) bool caps_word_press_user(uint16_t keycode) {
- switch (keycode) {
-
- case KC_A ... KC_Z:
- case KC_MINS:
- add_weak_mods(MOD_BIT(KC_LSFT));
- return true;
-
- case KC_1 ... KC_0:
- case KC_BSPC:
- case KC_DEL:
- case KC_UNDS:
- return true;
- default:
- return false;
- }
- }
|