forked from kofal.net/zmk
fix(combos)Fix bug with overlapping combos timeouts (#1945)
* Fix bug with overlapping combos timeouts * Fix trailing whitespace * Fix log format
This commit is contained in:
@@ -204,22 +204,34 @@ static inline bool candidate_is_completely_pressed(struct combo_cfg *candidate)
|
||||
static int cleanup();
|
||||
|
||||
static int filter_timed_out_candidates(int64_t timestamp) {
|
||||
int num_candidates = 0;
|
||||
int remaining_candidates = 0;
|
||||
for (int i = 0; i < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY; i++) {
|
||||
struct combo_candidate *candidate = &candidates[i];
|
||||
if (candidate->combo == NULL) {
|
||||
break;
|
||||
}
|
||||
if (candidate->timeout_at > timestamp) {
|
||||
// reorder candidates so they're contiguous
|
||||
candidates[num_candidates].combo = candidate->combo;
|
||||
candidates[num_candidates].timeout_at = candidate->timeout_at;
|
||||
num_candidates++;
|
||||
bool need_to_bubble_up = remaining_candidates != i;
|
||||
if (need_to_bubble_up) {
|
||||
// bubble up => reorder candidates so they're contiguous
|
||||
candidates[remaining_candidates].combo = candidate->combo;
|
||||
candidates[remaining_candidates].timeout_at = candidate->timeout_at;
|
||||
// clear the previous location
|
||||
candidates[i].combo = NULL;
|
||||
candidates[i].timeout_at = 0;
|
||||
}
|
||||
|
||||
remaining_candidates++;
|
||||
} else {
|
||||
candidate->combo = NULL;
|
||||
}
|
||||
}
|
||||
return num_candidates;
|
||||
|
||||
LOG_DBG(
|
||||
"after filtering out timed out combo candidates: remaining_candidates=%d timestamp=%lld",
|
||||
remaining_candidates, timestamp);
|
||||
|
||||
return remaining_candidates;
|
||||
}
|
||||
|
||||
static int clear_candidates() {
|
||||
@@ -449,7 +461,7 @@ static void combo_timeout_handler(struct k_work *item) {
|
||||
// timer was cancelled or rescheduled.
|
||||
return;
|
||||
}
|
||||
if (filter_timed_out_candidates(timeout_task_timeout_at) < 2) {
|
||||
if (filter_timed_out_candidates(timeout_task_timeout_at) == 0) {
|
||||
cleanup();
|
||||
}
|
||||
update_timeout_task();
|
||||
|
||||
Reference in New Issue
Block a user