Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retro tapping support #55

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions features/achordion.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static uint16_t tap_hold_keycode = KC_NO;
static uint16_t hold_timer = 0;
// Eagerly applied mods, if any.
static uint8_t eager_mods = 0;
// Flag to determine whether another key is pressed within the timeout.
static bool pressed_another_key_before_release = false;

#ifdef ACHORDION_STREAK
// Timer for typing streak
Expand Down Expand Up @@ -87,6 +89,14 @@ bool process_achordion(uint16_t keycode, keyrecord_t* record) {
return true;
}

// If this is a keypress and if the key is different than the tap-hold key,
// this information is saved to a flag to be processed later when the tap-hold
// key is released.
if (!pressed_another_key_before_release && record->event.pressed &&
tap_hold_keycode != KC_NO && tap_hold_keycode != keycode) {
pressed_another_key_before_release = true;
}

// Determine whether the current event is for a mod-tap or layer-tap key.
const bool is_mt = IS_QK_MOD_TAP(keycode);
const bool is_tap_hold = is_mt || IS_QK_LAYER_TAP(keycode);
Expand Down Expand Up @@ -137,6 +147,15 @@ bool process_achordion(uint16_t keycode, keyrecord_t* record) {
tap_hold_record.event.pressed = false;
// Plumb hold release event.
recursively_process_record(&tap_hold_record, STATE_RELEASED);
} else if (!pressed_another_key_before_release) {
getreuer marked this conversation as resolved.
Show resolved Hide resolved
// No other key was pressed between the press and release of the tap-hold
// key, simulate a hold and then a release without waiting for Achordion
// timeout to end.
dprintln("Achordion: Key released. Simulating hold and release.");
settle_as_hold();
tap_hold_record.event.pressed = false;
// Plumb hold release event.
recursively_process_record(&tap_hold_record, STATE_RELEASED);
} else {
dprintf("Achordion: Key released.%s\n",
eager_mods ? " Clearing eager mods." : "");
Expand All @@ -146,6 +165,9 @@ bool process_achordion(uint16_t keycode, keyrecord_t* record) {
}

achordion_state = STATE_RELEASED;
// The tap-hold key is released, clear the related keycode and the flag.
tap_hold_keycode = KC_NO;
pressed_another_key_before_release = false;
return false;
}

Expand Down