Skip to content

Commit d7a8482

Browse files
committed
refact
1 parent e26ee30 commit d7a8482

1 file changed

Lines changed: 51 additions & 32 deletions

File tree

app/src/behaviors/behavior_hold_tap.c

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -426,44 +426,63 @@ static bool is_first_other_key_released_trigger_key(struct active_hold_tap *hold
426426
return false;
427427
}
428428

429-
// Force a tap decision if the positional conditions for a hold decision are not met.
429+
430430
static void decide_positional_hold(struct active_hold_tap *hold_tap) {
431+
432+
// Positional conditions is not active?
431433
if (!(hold_tap->config->hold_trigger_key_positions_len > 0)) {
432-
return;
434+
return; // apply flavour
435+
}
436+
437+
// Pressed key is not set?
438+
if (hold_tap->position_of_first_other_key_pressed == -1) {
439+
return; // apply flavor
440+
}
441+
442+
// Pressed key is included in positions?
443+
if (is_first_other_key_pressed_trigger_key(hold_tap)) {
444+
return; // apply flavor
433445
}
434446

435-
if (undecided_hold_tap->config->hold_trigger_on_release) {
436-
if (hold_tap->position_of_first_other_key_pressed == -1) {
437-
return;
438-
}
439-
440-
if (is_first_other_key_pressed_trigger_key(hold_tap)) {
441-
return;
442-
}
443-
444-
if (hold_tap->position_of_first_other_key_released == -1)
445-
{
446-
if (hold_tap->status == STATUS_HOLD_INTERRUPT) {
447-
hold_tap->status = STATUS_UNDECIDED;
448-
}
449-
450-
return;
451-
}
452-
453-
if (is_first_other_key_released_trigger_key(hold_tap)) {
454-
return;
455-
}
456-
447+
// Pressed key is not included in positions.
448+
// We act on press?
449+
if (undecided_hold_tap->config->hold_trigger_on_release == false) {
457450
hold_tap->status = STATUS_TAP;
458-
} else {
459-
if (hold_tap->position_of_first_other_key_pressed == -1) {
460-
return;
451+
return; // ignore flavor, set TAP
452+
}
453+
454+
// We act on release.
455+
// Released key is not set?
456+
if (hold_tap->position_of_first_other_key_released == -1)
457+
{
458+
// Is current decision hold based on key pressed?
459+
if (hold_tap->status == STATUS_HOLD_INTERRUPT) {
460+
461+
// We can't decide yet if key which will be released:
462+
// - not in positions
463+
// - be released before timer
464+
// So we can't decide yet if we should overwrite decision to TAP.
465+
// We have to wait for key release.
466+
467+
hold_tap->status = STATUS_UNDECIDED;
468+
return; // remove flavor
461469
}
462-
if (is_first_other_key_pressed_trigger_key(hold_tap)) {
463-
return;
464-
}
465-
hold_tap->status = STATUS_TAP;
466-
}
470+
471+
// There decision is decision:
472+
// - STATUS_HOLD_TIMER - tapping term reached, apply flavor
473+
// - STATUS_TAP - even if we set TAP later it will not change decision
474+
return; // apply flavor
475+
}
476+
477+
478+
// Released key is included in positions?
479+
if (is_first_other_key_released_trigger_key(hold_tap)) {
480+
return; // apply flavor
481+
}
482+
483+
// Released key is not included in positions.
484+
hold_tap->status = STATUS_TAP;
485+
return; // ignore flavor, set TAP
467486
}
468487

469488
static void decide_hold_tap(struct active_hold_tap *hold_tap,

0 commit comments

Comments
 (0)