Skip to content

Commit

Permalink
refact
Browse files Browse the repository at this point in the history
  • Loading branch information
celejewski committed Mar 18, 2023
1 parent e26ee30 commit d7a8482
Showing 1 changed file with 51 additions and 32 deletions.
83 changes: 51 additions & 32 deletions app/src/behaviors/behavior_hold_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,44 +426,63 @@ static bool is_first_other_key_released_trigger_key(struct active_hold_tap *hold
return false;
}

// Force a tap decision if the positional conditions for a hold decision are not met.

static void decide_positional_hold(struct active_hold_tap *hold_tap) {

// Positional conditions is not active?
if (!(hold_tap->config->hold_trigger_key_positions_len > 0)) {
return;
return; // apply flavour
}

// Pressed key is not set?
if (hold_tap->position_of_first_other_key_pressed == -1) {
return; // apply flavor
}

// Pressed key is included in positions?
if (is_first_other_key_pressed_trigger_key(hold_tap)) {
return; // apply flavor
}

if (undecided_hold_tap->config->hold_trigger_on_release) {
if (hold_tap->position_of_first_other_key_pressed == -1) {
return;
}

if (is_first_other_key_pressed_trigger_key(hold_tap)) {
return;
}

if (hold_tap->position_of_first_other_key_released == -1)
{
if (hold_tap->status == STATUS_HOLD_INTERRUPT) {
hold_tap->status = STATUS_UNDECIDED;
}

return;
}

if (is_first_other_key_released_trigger_key(hold_tap)) {
return;
}

// Pressed key is not included in positions.
// We act on press?
if (undecided_hold_tap->config->hold_trigger_on_release == false) {
hold_tap->status = STATUS_TAP;
} else {
if (hold_tap->position_of_first_other_key_pressed == -1) {
return;
return; // ignore flavor, set TAP
}

// We act on release.
// Released key is not set?
if (hold_tap->position_of_first_other_key_released == -1)
{
// Is current decision hold based on key pressed?
if (hold_tap->status == STATUS_HOLD_INTERRUPT) {

// We can't decide yet if key which will be released:
// - not in positions
// - be released before timer
// So we can't decide yet if we should overwrite decision to TAP.
// We have to wait for key release.

hold_tap->status = STATUS_UNDECIDED;
return; // remove flavor
}
if (is_first_other_key_pressed_trigger_key(hold_tap)) {
return;
}
hold_tap->status = STATUS_TAP;
}

// There decision is decision:
// - STATUS_HOLD_TIMER - tapping term reached, apply flavor
// - STATUS_TAP - even if we set TAP later it will not change decision
return; // apply flavor
}


// Released key is included in positions?
if (is_first_other_key_released_trigger_key(hold_tap)) {
return; // apply flavor
}

// Released key is not included in positions.
hold_tap->status = STATUS_TAP;
return; // ignore flavor, set TAP
}

static void decide_hold_tap(struct active_hold_tap *hold_tap,
Expand Down

0 comments on commit d7a8482

Please sign in to comment.