Behaviors: Update last_listener_index before running event handler
An event can be captured and released in the same event handler, before the last_listener_index would have been updated. This causes some handlers to be triggered multiple times. The solution is to update the last_listener_index before calling the next event handler, so capturing and releasing within an event handler is harmless. Also see discussion at https://github.com/zmkfirmware/zmk/pull/1401
This commit is contained in:
parent
0086ff99c5
commit
b6f987f12a
2 changed files with 2 additions and 2 deletions
|
@ -253,7 +253,7 @@ static int release_pressed_keys() {
|
|||
if (i == 0) {
|
||||
LOG_DBG("combo: releasing position event %d",
|
||||
as_zmk_position_state_changed(captured_event)->position);
|
||||
ZMK_EVENT_RAISE_AFTER(captured_event, combo);
|
||||
ZMK_EVENT_RELEASE(captured_event)
|
||||
} else {
|
||||
// reprocess events (see tests/combo/fully-overlapping-combos-3 for why this is needed)
|
||||
LOG_DBG("combo: reraising position event %d",
|
||||
|
|
|
@ -25,6 +25,7 @@ int zmk_event_manager_handle_from(zmk_event_t *event, uint8_t start_index) {
|
|||
if (ev_sub->event_type != event->event) {
|
||||
continue;
|
||||
}
|
||||
event->last_listener_index = i;
|
||||
ret = ev_sub->listener->callback(event);
|
||||
switch (ret) {
|
||||
case ZMK_EV_EVENT_BUBBLE:
|
||||
|
@ -35,7 +36,6 @@ int zmk_event_manager_handle_from(zmk_event_t *event, uint8_t start_index) {
|
|||
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue