From 8743bd00d4c42156e37434cc2648b83881ec0602 Mon Sep 17 00:00:00 2001 From: Evan Travers Date: Wed, 6 Jul 2022 11:58:14 -0500 Subject: [PATCH] Remove old capsword and install new one - remove old capsword feature - upgrade tapping term to new macro - add new capword References - https://getreuer.info/posts/keyboards/caps-word/index.html - https://github.com/qmk/qmk_firmware/pull/16681#issuecomment-1098204587 - https://docs.qmk.fm/#/feature_caps_word --- users/evantravers/evantravers.c | 9 +- users/evantravers/evantravers.h | 3 +- users/evantravers/features/caps_word.c | 151 ------------------------- users/evantravers/features/caps_word.h | 128 --------------------- users/evantravers/rules.mk | 2 +- users/evantravers/wrappers.h | 2 +- 6 files changed, 4 insertions(+), 291 deletions(-) delete mode 100644 users/evantravers/features/caps_word.c delete mode 100644 users/evantravers/features/caps_word.h diff --git a/users/evantravers/evantravers.c b/users/evantravers/evantravers.c index 3e860bf7c7bd..8d43037b72ae 100644 --- a/users/evantravers/evantravers.c +++ b/users/evantravers/evantravers.c @@ -16,10 +16,8 @@ along with this program. If not, see . */ #include "evantravers.h" -#include "features/caps_word.h" uint32_t user_key_timer; -uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record); qk_tap_dance_action_t tap_dance_actions[] = { [TD_CTRL_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_LCTL, KC_ESC), @@ -37,8 +35,6 @@ float qwerty[][2] = SONG(UNICODE_LINUX); bool process_record_user(uint16_t keycode, keyrecord_t *record) { - if (!process_caps_word(keycode, record)) { return false; } - switch (keycode) { case TO(_GAMING): #ifdef AUDIO_ENABLE @@ -50,16 +46,13 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { PLAY_SONG (qwerty); #endif return true; break; - case CAPS: - caps_word_set(true); - return false; break; case ESC_F19: if (record->event.pressed) { user_key_timer = timer_read(); register_code(KC_F19); } else { unregister_code(KC_F19); - if (timer_elapsed(user_key_timer) < get_tapping_term(keycode, record)) { + if (timer_elapsed(user_key_timer) < TAPPING_TERM) { tap_code(KC_ESC); } } diff --git a/users/evantravers/evantravers.h b/users/evantravers/evantravers.h index 91e7a1505f84..d08e779a949c 100644 --- a/users/evantravers/evantravers.h +++ b/users/evantravers/evantravers.h @@ -60,8 +60,7 @@ enum userspace_tapdances { }; enum userspace_custom_keycodes { - ESC_F19 = SAFE_RANGE, - CAPS + ESC_F19 = SAFE_RANGE }; /* Define layer names */ diff --git a/users/evantravers/features/caps_word.c b/users/evantravers/features/caps_word.c deleted file mode 100644 index fa5bc92a1051..000000000000 --- a/users/evantravers/features/caps_word.c +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2021-2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// -// For full documentation, see -// https://getreuer.info/posts/keyboards/caps-word - -#include "caps_word.h" - -static bool caps_word_active = false; - -#if CAPS_WORD_IDLE_TIMEOUT > 0 -#if CAPS_WORD_IDLE_TIMEOUT < 100 || CAPS_WORD_IDLE_TIMEOUT > 30000 -// Constrain timeout to a sensible range. With the 16-bit timer, the longest -// representable timeout is 32768 ms, rounded here to 30000 ms = half a minute. -#error "caps_word: CAPS_WORD_IDLE_TIMEOUT must be between 100 and 30000 ms" -#endif - -static uint16_t idle_timer = 0; - -void caps_word_task(void) { - if (caps_word_active && timer_expired(timer_read(), idle_timer)) { - caps_word_set(false); - } -} -#endif // CAPS_WORD_IDLE_TIMEOUT > 0 - -bool process_caps_word(uint16_t keycode, keyrecord_t* record) { -#ifndef NO_ACTION_ONESHOT - const uint8_t mods = get_mods() | get_oneshot_mods(); -#else - const uint8_t mods = get_mods(); -#endif // NO_ACTION_ONESHOT - - if (!caps_word_active) { - // Pressing both shift keys at the same time enables caps word. - if ((mods & MOD_MASK_SHIFT) == MOD_MASK_SHIFT) { - caps_word_set(true); // Activate Caps Word. - return false; - } - return true; - } else { -#if CAPS_WORD_IDLE_TIMEOUT > 0 - idle_timer = record->event.time + CAPS_WORD_IDLE_TIMEOUT; -#endif // CAPS_WORD_IDLE_TIMEOUT > 0 - } - - if (!record->event.pressed) { return true; } - - if (!(mods & ~MOD_MASK_SHIFT)) { - switch (keycode) { - // Ignore MO, TO, TG, TT, and OSL layer switch keys. - 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: - return true; - -#ifndef NO_ACTION_TAPPING - case QK_MOD_TAP ... QK_MOD_TAP_MAX: - if (record->tap.count == 0) { - // Deactivate if a mod becomes active through holding a mod-tap key. - caps_word_set(false); - return true; - } - keycode &= 0xff; - break; - -#ifndef NO_ACTION_LAYER - case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: -#endif // NO_ACTION_LAYER - if (record->tap.count == 0) { return true; } - keycode &= 0xff; - break; -#endif // NO_ACTION_TAPPING - -#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 - } - - if (caps_word_press_user(keycode)) { - return true; - } - } - - caps_word_set(false); // Deactivate Caps Word. - return true; -} - -void caps_word_set(bool active) { - if (active != caps_word_active) { - if (active) { - clear_mods(); -#ifndef NO_ACTION_ONESHOT - clear_oneshot_mods(); -#endif // NO_ACTION_ONESHOT -#if CAPS_WORD_IDLE_TIMEOUT > 0 - idle_timer = timer_read() + CAPS_WORD_IDLE_TIMEOUT; -#endif // CAPS_WORD_IDLE_TIMEOUT > 0 - } else if ((get_weak_mods() & MOD_BIT(KC_LSFT)) != 0) { - // If the weak shift mod is still on, turn it off and send an update to - // the host computer. - del_weak_mods(MOD_BIT(KC_LSFT)); - send_keyboard_report(); - } - - caps_word_active = active; - caps_word_set_user(active); - } -} - -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/users/evantravers/features/caps_word.h b/users/evantravers/features/caps_word.h deleted file mode 100644 index 986fca4f02a3..000000000000 --- a/users/evantravers/features/caps_word.h +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2021-2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// -// Caps Word, activated by pressing both shift keys at the same time. -// -// This library implements "Caps Word", which is like conventional Caps Lock, -// but automatically disables itself at the end of the word. This is useful for -// typing all-caps identifiers like `MOD_MASK_ALT`. -// -// Caps Word is activated by pressing the left and right shift keys at the same -// time. This way you don't need a dedicated key for using Caps Word. I've -// tested that this works as expected with one-shot mods and Space Cadet Shift. -// If your shift keys are mod-taps, activate Caps Word by holding both shift -// mod-tap keys until the tapping term, release them, then begin typing. -// -// Optionally, Caps Word may be configured to deactivate if the keyboard is idle -// for some time. This is useful to mitigate unintended shifting when you get -// interrupted or switch to the mouse while Caps Word is active. In your -// config.h, define `CAPS_WORD_IDLE_TIMEOUT` with a time in milliseconds: -// -// #define CAPS_WORD_IDLE_TIMEOUT 5000 // Turn off Caps Word after 5 seconds. -// -// and in your keymap.c, define (or add to) `matrix_scan_user()` as -// -// void matrix_scan_user(void) { -// caps_word_task(); -// // Other tasks... -// } -// -// For full documentation, see -// https://getreuer.info/posts/keyboards/caps-word - -#pragma once - -#include QMK_KEYBOARD_H - -// Call this function from `process_record_user()` to implement Caps Word. -bool process_caps_word(uint16_t keycode, keyrecord_t* record); - -// If CAPS_WORD_IDLE_TIMEOUT is set, call `caps_word_task()` from -// `matrix_scan_user()` as described above. -// -// If CAPS_WORD_IDLE_TIMEOUT isn't set, calling this function has no effect (but -// will still compile). -#if CAPS_WORD_IDLE_TIMEOUT > 0 -void caps_word_task(void); -#else -static inline void caps_word_task(void) {} -#endif - -// Activates or deactivates Caps Word. For instance activate Caps Word with a -// combo by defining a `COMBO_ACTION` that calls `caps_word_set(true)`: -// -// void process_combo_event(uint16_t combo_index, bool pressed) { -// switch(combo_index) { -// case CAPS_COMBO: -// if (pressed) { -// caps_word_set(true); // Activate Caps Word. -// } -// break; -// -// // Other combos... -// } -// } -void caps_word_set(bool active); - -// Returns whether Caps Word is currently active. -bool caps_word_get(void); - -// An optional callback that gets called when Caps Word turns on or off. This is -// useful to represent the current Caps Word state, e.g. by setting an LED or -// playing a sound. In your keymap, define -// -// void caps_word_set_user(bool active) { -// if (active) { -// // Do something when Caps Word activates. -// } else { -// // Do something when Caps Word deactivates. -// } -// } -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); - - diff --git a/users/evantravers/rules.mk b/users/evantravers/rules.mk index f43d03ec93c9..62edea8859fd 100644 --- a/users/evantravers/rules.mk +++ b/users/evantravers/rules.mk @@ -1,5 +1,4 @@ SRC += evantravers.c -SRC += features/caps_word.c TAP_DANCE_ENABLE = yes @@ -15,5 +14,6 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = no # Console for debug(+400) COMMAND_ENABLE = no # Commands for debug and configuration MACROS_ENABLED = no +CAPS_WORD_ENABLE = yes DEBOUNCE_TYPE = sym_eager_pk diff --git a/users/evantravers/wrappers.h b/users/evantravers/wrappers.h index c543c130860a..86a99f9d4ba7 100644 --- a/users/evantravers/wrappers.h +++ b/users/evantravers/wrappers.h @@ -44,7 +44,7 @@ #define _________________SYMBL_L2__________________ KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV #define _________________SYMBL_L3__________________ KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD -#define _________________SYMBL_R1__________________ KC_CIRC, KC_UNDS, KC_PLUS, KC_SLSH, CAPS +#define _________________SYMBL_R1__________________ KC_CIRC, KC_UNDS, KC_PLUS, KC_SLSH, CAPS_WORD #define _________________SYMBL_R2__________________ KC_SLSH, KC_MINS, KC_EQL, KC_ASTR, KC_COLN #define _________________SYMBL_R3__________________ KC_AMPR, KC_QUES, KC_LT, KC_GT, KC_BSLS