From 3368a81057d4981aa259c5548050d95739d99d51 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 19 Jan 2021 14:21:00 -0500 Subject: refactor(core): Combine `is_` and `cast_` event functions. * Use a single `as_foo` generated function to conditionally return a certain event type from a generic `zmk_event_t*` pointer. --- app/src/combo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/src/combo.c') diff --git a/app/src/combo.c b/app/src/combo.c index a08a2f5..82f6538 100644 --- a/app/src/combo.c +++ b/app/src/combo.c @@ -291,7 +291,7 @@ static void activate_combo(struct combo_cfg *combo) { } move_pressed_keys_to_active_combo(active_combo); press_combo_behavior( - combo, cast_zmk_position_state_changed(active_combo->key_positions_pressed[0])->timestamp); + combo, as_zmk_position_state_changed(active_combo->key_positions_pressed[0])->timestamp); } static void deactivate_combo(int active_combo_index) { @@ -315,7 +315,7 @@ static bool release_combo_key(int32_t position, int64_t timestamp) { for (int i = 0; i < active_combo->combo->key_position_len; i++) { if (active_combo->key_positions_pressed[i] == NULL) { all_keys_pressed = false; - } else if (cast_zmk_position_state_changed(active_combo->key_positions_pressed[i]) + } else if (as_zmk_position_state_changed(active_combo->key_positions_pressed[i]) ->position != position) { all_keys_released = false; } else { // not null and position matches @@ -418,11 +418,11 @@ static void combo_timeout_handler(struct k_work *item) { } static int position_state_changed_listener(const zmk_event_t *ev) { - if (!is_zmk_position_state_changed(ev)) { + struct zmk_position_state_changed *data = as_zmk_position_state_changed(ev); + if (data == NULL) { return 0; } - struct zmk_position_state_changed *data = cast_zmk_position_state_changed(ev); if (data->state) { // keydown return position_state_down(ev, data); } else { // keyup -- cgit v1.2.3