diff options
author | Okke Formsma <okke@formsma.nl> | 2021-02-27 22:25:07 +0100 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-03-10 20:12:23 -0500 |
commit | 8ebe0cd0c88a8ffbb323784f03229889cecc4b52 (patch) | |
tree | e65aa117c42e4d7b2f864e155cd7d87122d04fea /app/src/event_manager.c | |
parent | c01243d1c6e0c84556f248fbc1d83496222209c3 (diff) |
refactor(core): make the event manager a bit easier to read
Diffstat (limited to 'app/src/event_manager.c')
-rw-r--r-- | app/src/event_manager.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/app/src/event_manager.c b/app/src/event_manager.c index 0399ca8..eef5d83 100644 --- a/app/src/event_manager.c +++ b/app/src/event_manager.c @@ -22,24 +22,25 @@ int zmk_event_manager_handle_from(zmk_event_t *event, uint8_t start_index) { uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = start_index; i < len; i++) { struct zmk_event_subscription *ev_sub = __event_subscriptions_start + i; - if (ev_sub->event_type == event->event) { - ret = ev_sub->listener->callback(event); - if (ret < 0) { - LOG_DBG("Listener returned an error: %d", ret); - goto release; - } else if (ret > 0) { - switch (ret) { - case ZMK_EV_EVENT_HANDLED: - LOG_DBG("Listener handled the event"); - ret = 0; - goto release; - case ZMK_EV_EVENT_CAPTURED: - LOG_DBG("Listener captured the event"); - event->last_listener_index = i; - // Listeners are expected to free events they capture - return 0; - } - } + if (ev_sub->event_type != event->event) { + continue; + } + ret = ev_sub->listener->callback(event); + switch (ret) { + case ZMK_EV_EVENT_BUBBLE: + continue; + case ZMK_EV_EVENT_HANDLED: + LOG_DBG("Listener handled the event"); + ret = 0; + goto release; + case ZMK_EV_EVENT_CAPTURED: + LOG_DBG("Listener captured the event"); + event->last_listener_index = i; + // Listeners are expected to free events they capture + return 0; + default: + LOG_DBG("Listener returned an error: %d", ret); + goto release; } } |