Browse Source

refactor(sticky keys): rename timer_is_started to timer_started

xmkb
Okke Formsma 4 years ago committed by Pete Johanson
parent
commit
26af11b390
  1. 15
      app/src/behaviors/behavior_sticky_key.c

15
app/src/behaviors/behavior_sticky_key.c

@ -40,9 +40,9 @@ struct active_sticky_key {
const struct behavior_sticky_key_config *config; const struct behavior_sticky_key_config *config;
// timer data. // timer data.
bool timer_started; bool timer_started;
bool timer_cancelled;
int64_t release_at; int64_t release_at;
struct k_delayed_work release_timer; struct k_delayed_work release_timer;
bool timer_is_cancelled;
// usage page and keycode for the key that is being modified by this sticky key // usage page and keycode for the key that is being modified by this sticky key
uint8_t modified_key_usage_page; uint8_t modified_key_usage_page;
uint32_t modified_key_keycode; uint32_t modified_key_keycode;
@ -55,7 +55,7 @@ static struct active_sticky_key *store_sticky_key(uint32_t position, uint32_t pa
const struct behavior_sticky_key_config *config) { const struct behavior_sticky_key_config *config) {
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { 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) { active_sticky_keys[i].timer_cancelled) {
continue; continue;
} }
active_sticky_keys[i].position = position; active_sticky_keys[i].position = position;
@ -63,7 +63,7 @@ static struct active_sticky_key *store_sticky_key(uint32_t position, uint32_t pa
active_sticky_keys[i].param2 = param2; active_sticky_keys[i].param2 = param2;
active_sticky_keys[i].config = config; active_sticky_keys[i].config = config;
active_sticky_keys[i].release_at = 0; active_sticky_keys[i].release_at = 0;
active_sticky_keys[i].timer_is_cancelled = false; active_sticky_keys[i].timer_cancelled = false;
active_sticky_keys[i].timer_started = false; active_sticky_keys[i].timer_started = false;
active_sticky_keys[i].modified_key_usage_page = 0; active_sticky_keys[i].modified_key_usage_page = 0;
active_sticky_keys[i].modified_key_keycode = 0; active_sticky_keys[i].modified_key_keycode = 0;
@ -78,8 +78,7 @@ static void clear_sticky_key(struct active_sticky_key *sticky_key) {
static struct active_sticky_key *find_sticky_key(uint32_t position) { static struct active_sticky_key *find_sticky_key(uint32_t position) {
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { 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_cancelled) {
!active_sticky_keys[i].timer_is_cancelled) {
return &active_sticky_keys[i]; return &active_sticky_keys[i];
} }
} }
@ -120,7 +119,7 @@ static int stop_timer(struct active_sticky_key *sticky_key) {
int timer_cancel_result = k_delayed_work_cancel(&sticky_key->release_timer); int timer_cancel_result = k_delayed_work_cancel(&sticky_key->release_timer);
if (timer_cancel_result == -EINPROGRESS) { if (timer_cancel_result == -EINPROGRESS) {
// too late to cancel, we'll let the timer handler clear up. // too late to cancel, we'll let the timer handler clear up.
sticky_key->timer_is_cancelled = true; sticky_key->timer_cancelled = true;
} }
return timer_cancel_result; return timer_cancel_result;
} }
@ -235,8 +234,8 @@ void behavior_sticky_key_timer_handler(struct k_work *item) {
if (sticky_key->position == ZMK_BHV_STICKY_KEY_POSITION_NOT_USED) { if (sticky_key->position == ZMK_BHV_STICKY_KEY_POSITION_NOT_USED) {
return; return;
} }
if (sticky_key->timer_is_cancelled) { if (sticky_key->timer_cancelled) {
sticky_key->timer_is_cancelled = false; sticky_key->timer_cancelled = false;
} else { } else {
release_sticky_key_behavior(sticky_key, sticky_key->release_at); release_sticky_key_behavior(sticky_key, sticky_key->release_at);
} }

Loading…
Cancel
Save