Skip to content

Commit

Permalink
Small Retro Shift bugfixes and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacElenbaas committed May 13, 2022
1 parent 12d1eb0 commit 3e11c13
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
16 changes: 10 additions & 6 deletions docs/feature_auto_shift.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Do not Auto Shift alpha characters, which include A through Z.
### Auto Shift Per Key
There are functions that allows you to determine which keys shold be autoshifted, much like the tap-hold keys.
There are functions that allows you to determine which keys should be autoshifted, much like the tap-hold keys.
The first of these, used to simply add a key to Auto Shift, is `get_custom_auto_shifted_key`:
Expand All @@ -166,15 +166,13 @@ For more granular control, there is `get_auto_shifted_key`. The default function
bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
# ifndef NO_AUTO_SHIFT_ALPHA
case KC_A ... KC_Z:
case AUTO_SHIFT_ALPHA:
# endif
# ifndef NO_AUTO_SHIFT_NUMERIC
case KC_1 ... KC_0:
case AUTO_SHIFT_NUMERIC:
# endif
# ifndef NO_AUTO_SHIFT_SPECIAL
case KC_TAB:
case KC_MINUS ... KC_SLASH:
case KC_NONUS_BACKSLASH:
case AUTO_SHIFT_SPECIAL:
# endif
return true;
}
Expand Down Expand Up @@ -271,10 +269,16 @@ generating taps on release. For example:
#define RETRO_SHIFT 500
```
Without a value set, holds of any length without an interrupting key will produce the shifted value.
This value (if set) must be greater than one's `TAPPING_TERM`, as the key press
must be designated as a 'hold' by `process_tapping` before we send the modifier.
[Per-key tapping terms](tap_hold.md#tapping-term) can be used as a workaround.
There is no such limitation in regards to `AUTO_SHIFT_TIMEOUT` for normal keys.
**Note:** Tap Holds must be added to Auto Shift, see [here.](feature_auto_shift.md#auto-shift-per-key)
`IS_RETRO` may be helpful if one wants all Tap Holds retro shifted.
### Retro Shift and Tap Hold Configurations
Tap Hold Configurations work a little differently when using Retro Shift.
Expand Down
21 changes: 16 additions & 5 deletions quantum/action_tapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,21 @@ bool process_tapping(keyrecord_t *keyp) {
if (WITHIN_TAPPING_TERM(event)
# if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
|| (
get_auto_shifted_key(tapping_keycode, keyp) &&
# ifdef RETRO_TAPPING_PER_KEY
get_retro_tapping(tapping_keycode, &tapping_key) &&
# endif
(RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0)
// extends TAPPING_TERM:
// indefinitely if RETRO_SHIFT does not have a value (+0 is to compile successfully)
// to RETRO_SHIFT if it is set
// for possibly retro shifted keys
((RETRO_SHIFT + 0) == 0 || TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0))
)
# endif
) {
// clang-format on
if (tapping_key.tap.count == 0) {
if (IS_TAPPING_RECORD(keyp) && !event.pressed) {
# if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
retroshift_swap_times();
# endif
// first tap!
debug("Tapping: First tap(0->1).\n");
tapping_key.tap.count = 1;
Expand Down Expand Up @@ -180,6 +182,7 @@ bool process_tapping(keyrecord_t *keyp) {
// unnecessarily and fixes them for Layer Taps.
# if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
|| (
get_auto_shifted_key(tapping_keycode, keyp) &&
# ifdef RETRO_TAPPING_PER_KEY
get_retro_tapping(tapping_keycode, &tapping_key) &&
# endif
Expand Down Expand Up @@ -306,6 +309,9 @@ bool process_tapping(keyrecord_t *keyp) {
} else {
if (!IS_NOEVENT(event)) {
debug("Tapping: key event while last tap(>0).\n");
# if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
retroshift_swap_times();
# endif
}
process_record(keyp);
return true;
Expand Down Expand Up @@ -363,10 +369,15 @@ bool process_tapping(keyrecord_t *keyp) {
if (WITHIN_TAPPING_TERM(event)
# if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
|| (
get_auto_shifted_key(tapping_keycode, keyp) &&
# ifdef RETRO_TAPPING_PER_KEY
get_retro_tapping(tapping_keycode, &tapping_key) &&
# endif
(RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0)
// extends TAPPING_TERM:
// indefinitely if RETRO_SHIFT does not have a value (+0 is to compile successfully)
// to RETRO_SHIFT if it is set
// for possibly retro shifted keys
((RETRO_SHIFT + 0) == 0 || TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0))
)
# endif
) {
Expand Down
3 changes: 3 additions & 0 deletions quantum/action_tapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define WAITING_BUFFER_SIZE 8

#ifndef NO_ACTION_TAPPING
# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record);
# endif
uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
void action_tapping_process(keyrecord_t record);
Expand Down
13 changes: 5 additions & 8 deletions quantum/process_keycode/process_auto_shift.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ __attribute__((weak)) bool get_custom_auto_shifted_key(uint16_t keycode, keyreco
return false;
}

/** \brief Called on physical press, returns whether is Auto Shift key */
/** \brief Called on physical press, returns whether key is an Auto Shift key */
__attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
# ifndef NO_AUTO_SHIFT_ALPHA
Expand Down Expand Up @@ -165,9 +165,8 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record)
}

// Store record to be sent to user functions if there's no release record then.
autoshift_lastrecord = *record;
autoshift_lastrecord.event.pressed = false;
autoshift_lastrecord.event.time = 0;
autoshift_lastrecord = *record;
autoshift_lastrecord.event.time = 0;
// clang-format off
# if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)
if (keycode == autoshift_lastkey &&
Expand Down Expand Up @@ -489,10 +488,8 @@ void retroshift_poll_time(keyevent_t *event) {
}
// Used to swap the times of Retro Shifted key and Auto Shift key that interrupted it.
void retroshift_swap_times() {
if (last_retroshift_time != 0 && autoshift_flags.in_progress) {
uint16_t temp = retroshift_time;
retroshift_time = last_retroshift_time;
last_retroshift_time = temp;
if (autoshift_flags.in_progress) {
autoshift_time = last_retroshift_time;
}
}
# endif
Expand Down
1 change: 1 addition & 0 deletions quantum/process_keycode/process_auto_shift.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ uint16_t (get_autoshift_timeout)(uint16_t keycode, keyrecord_t *record);
void set_autoshift_timeout(uint16_t timeout);
void autoshift_matrix_scan(void);
bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record);
bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record);
// clang-format on

0 comments on commit 3e11c13

Please sign in to comment.