Browse Source

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

xmkb
Okke Formsma 4 years ago committed by Pete Johanson
parent
commit
caa285852a
  1. 1
      app/include/zmk/event_manager.h
  2. 14
      app/src/behaviors/behavior_hold_tap.c
  3. 4
      app/src/behaviors/behavior_sticky_key.c
  4. 2
      app/src/display/widgets/battery_status.c
  5. 2
      app/src/display/widgets/output_status.c
  6. 2
      app/src/split_listener.c

1
app/include/zmk/event_manager.h

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

14
app/src/behaviors/behavior_hold_tap.c

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

4
app/src/behaviors/behavior_sticky_key.c

@ -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) { static int sticky_key_keycode_state_changed_listener(const struct zmk_event_header *eh) {
if (!is_keycode_state_changed(eh)) { if (!is_keycode_state_changed(eh)) {
return 0; return ZMK_EV_EVENT_BUBBLE;
} }
struct keycode_state_changed *ev = cast_keycode_state_changed(eh); struct keycode_state_changed *ev = cast_keycode_state_changed(eh);
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { 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); ZMK_LISTENER(behavior_sticky_key, sticky_key_keycode_state_changed_listener);

2
app/src/display/widgets/battery_status.c

@ -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) { int battery_status_listener(const struct zmk_event_header *eh) {
struct zmk_widget_battery_status *widget; struct zmk_widget_battery_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_battery_symbol(widget->obj); } 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) ZMK_LISTENER(widget_battery_status, battery_status_listener)

2
app/src/display/widgets/output_status.c

@ -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) { int output_status_listener(const struct zmk_event_header *eh) {
struct zmk_widget_output_status *widget; struct zmk_widget_output_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); } 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) ZMK_LISTENER(widget_output_status, output_status_listener)

2
app/src/split_listener.c

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

Loading…
Cancel
Save