summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorOkke Formsma <okke@formsma.nl>2020-11-30 21:40:26 +0100
committerPete Johanson <peter@peterjohanson.com>2020-12-06 00:33:20 -0500
commit37946ff57ba044abff8a22741042fe602208d3a1 (patch)
tree5b407aa95ae9d9fa8564e365bbb507be02f3b275 /app
parent2f9e8ea3c178a735b8132a656d69f06dfbdcdb71 (diff)
fix(sticky keys): simplify timer management
Diffstat (limited to 'app')
-rw-r--r--app/src/behaviors/behavior_sticky_key.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c
index 5c4c7cb..e6c96eb 100644
--- a/app/src/behaviors/behavior_sticky_key.c
+++ b/app/src/behaviors/behavior_sticky_key.c
@@ -53,7 +53,8 @@ struct active_sticky_key active_sticky_keys[ZMK_BHV_STICKY_KEY_MAX_HELD] = {};
static struct active_sticky_key *store_sticky_key(u32_t position, u32_t param1, u32_t param2,
const struct behavior_sticky_key_config *config) {
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
- if (active_sticky_keys[i].position != ZMK_BHV_STICKY_KEY_POSITION_NOT_USED) {
+ if (active_sticky_keys[i].position != ZMK_BHV_STICKY_KEY_POSITION_NOT_USED ||
+ active_sticky_keys[i].timer_is_cancelled) {
continue;
}
active_sticky_keys[i].position = position;
@@ -76,7 +77,8 @@ static void clear_sticky_key(struct active_sticky_key *sticky_key) {
static struct active_sticky_key *find_sticky_key(u32_t position) {
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
- if (active_sticky_keys[i].position == position) {
+ if (active_sticky_keys[i].position == position &&
+ !active_sticky_keys[i].timer_is_cancelled) {
return &active_sticky_keys[i];
}
}
@@ -191,9 +193,8 @@ static int sticky_key_keycode_state_changed_listener(const struct zmk_event_head
// Release the sticky key if the timer should've run out in the meantime.
if (sticky_key->release_at != 0 && ev->timestamp > sticky_key->release_at) {
release_sticky_key_behavior(sticky_key, sticky_key->release_at);
- if (stop_timer(sticky_key)) {
- clear_sticky_key(sticky_key);
- }
+ stop_timer(sticky_key);
+ clear_sticky_key(sticky_key);
continue;
}
@@ -230,10 +231,12 @@ void behavior_sticky_key_timer_handler(struct k_work *item) {
if (sticky_key->position == ZMK_BHV_STICKY_KEY_POSITION_NOT_USED) {
return;
}
- if (!sticky_key->timer_is_cancelled) {
+ if (sticky_key->timer_is_cancelled) {
+ sticky_key->timer_is_cancelled = false;
+ } else {
release_sticky_key_behavior(sticky_key, k_uptime_get());
+ clear_sticky_key(sticky_key);
}
- clear_sticky_key(sticky_key);
}
static int behavior_sticky_key_init(struct device *dev) {