refactor(events): return 'ZMK_EV_EVENT_BUBBLE' instead of magic number 0

This commit is contained in:
Okke Formsma 2020-12-16 19:41:53 +01:00 committed by Pete Johanson
parent 5a72662898
commit caa285852a
6 changed files with 13 additions and 12 deletions

View file

@ -19,6 +19,7 @@ struct zmk_event_header {
uint8_t last_listener_index;
};
#define ZMK_EV_EVENT_BUBBLE 0
#define ZMK_EV_EVENT_HANDLED 1
#define ZMK_EV_EVENT_CAPTURED 2

View file

@ -392,16 +392,16 @@ static int position_state_changed_listener(const struct zmk_event_header *eh) {
if (undecided_hold_tap == NULL) {
LOG_DBG("%d bubble (no undecided hold_tap active)", ev->position);
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
if (undecided_hold_tap->position == ev->position) {
if (ev->state) { // keydown
LOG_ERR("hold-tap listener should be called before before most other listeners!");
return 0;
return ZMK_EV_EVENT_BUBBLE;
} else { // keyup
LOG_DBG("%d bubble undecided hold-tap keyrelease event", undecided_hold_tap->position);
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
}
@ -418,7 +418,7 @@ static int position_state_changed_listener(const struct zmk_event_header *eh) {
// we'll catch modifiers later in modifier_state_changed_listener
LOG_DBG("%d bubbling %d %s event", undecided_hold_tap->position, ev->position,
ev->state ? "down" : "up");
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
LOG_DBG("%d capturing %d %s event", undecided_hold_tap->position, ev->position,
@ -439,12 +439,12 @@ static int keycode_state_changed_listener(const struct zmk_event_header *eh) {
if (undecided_hold_tap == NULL) {
// LOG_DBG("0x%02X bubble (no undecided hold_tap active)", ev->keycode);
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
if (!only_mods(ev)) {
// LOG_DBG("0x%02X bubble (not a mod)", ev->keycode);
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
// only key-up events will bubble through position_state_changed_listener
@ -461,7 +461,7 @@ int behavior_hold_tap_listener(const struct zmk_event_header *eh) {
} else if (is_keycode_state_changed(eh)) {
return keycode_state_changed_listener(eh);
}
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
ZMK_LISTENER(behavior_hold_tap, behavior_hold_tap_listener);

View file

@ -177,7 +177,7 @@ static const struct behavior_driver_api behavior_sticky_key_driver_api = {
static int sticky_key_keycode_state_changed_listener(const struct zmk_event_header *eh) {
if (!is_keycode_state_changed(eh)) {
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
struct keycode_state_changed *ev = cast_keycode_state_changed(eh);
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
@ -222,7 +222,7 @@ static int sticky_key_keycode_state_changed_listener(const struct zmk_event_head
}
}
}
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
ZMK_LISTENER(behavior_sticky_key, sticky_key_keycode_state_changed_listener);

View file

@ -78,7 +78,7 @@ lv_obj_t *zmk_widget_battery_status_obj(struct zmk_widget_battery_status *widget
int battery_status_listener(const struct zmk_event_header *eh) {
struct zmk_widget_battery_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_battery_symbol(widget->obj); }
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
ZMK_LISTENER(widget_battery_status, battery_status_listener)

View file

@ -82,7 +82,7 @@ lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget)
int output_status_listener(const struct zmk_event_header *eh) {
struct zmk_widget_output_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); }
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
ZMK_LISTENER(widget_output_status, output_status_listener)

View file

@ -29,7 +29,7 @@ int split_listener(const struct zmk_event_header *eh) {
return zmk_split_bt_position_released(ev->position);
}
}
return 0;
return ZMK_EV_EVENT_BUBBLE;
}
ZMK_LISTENER(split_listener, split_listener);