bugfix: sticky keys held for longer than release-after-ms get stuck

Sticky keys work to modify the next keypress, but also have utility in being held to achieve certain behaviours such as making multiple selections with a mouse.
The current implementation of sticky keys does not account for the case where a sticky key is held longer than `release-after-ms`. In this case, the sticky key gets stuck. 

This PR proposes releasing the sticky key 1ms after the key is released if `release-after-ms` has lapsed during the hold, so that the sticky key behaves like a momentary key for long holds. 

I have tested this for the past few days and have found it fixes my use cases.
This commit is contained in:
Harley Mellifont 2023-01-27 11:48:56 +11:00 committed by GitHub
parent 2a5e914a77
commit 72a1520a84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,9 +167,8 @@ static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding,
sticky_key->release_at = event.timestamp + sticky_key->config->release_after_ms;
// adjust timer in case this behavior was queued by a hold-tap
int32_t ms_left = sticky_key->release_at - k_uptime_get();
if (ms_left > 0) {
ms_left = ms_left > 0 ? ms_left : 1;
k_work_schedule(&sticky_key->release_timer, K_MSEC(ms_left));
}
return ZMK_BEHAVIOR_OPAQUE;
}