summaryrefslogtreecommitdiff
path: root/app/include
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2021-01-19 14:21:00 -0500
committerPete Johanson <peter@peterjohanson.com>2021-01-20 07:06:11 -0500
commit3368a81057d4981aa259c5548050d95739d99d51 (patch)
treea2feaed6f49eb25949a64c9c3cafe574f43fe23d /app/include
parent3fe2acc2d191006fa6309191ee99b2e4e249ed08 (diff)
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.
Diffstat (limited to 'app/include')
-rw-r--r--app/include/zmk/event_manager.h9
1 files changed, 4 insertions, 5 deletions
diff --git a/app/include/zmk/event_manager.h b/app/include/zmk/event_manager.h
index 8fc3f19..5acb26e 100644
--- a/app/include/zmk/event_manager.h
+++ b/app/include/zmk/event_manager.h
@@ -39,8 +39,7 @@ struct zmk_event_subscription {
struct event_type data; \
}; \
struct event_type##_event *new_##event_type(struct event_type); \
- bool is_##event_type(const zmk_event_t *eh); \
- struct event_type *cast_##event_type(const zmk_event_t *eh); \
+ struct event_type *as_##event_type(const zmk_event_t *eh); \
extern const struct zmk_event_type zmk_event_##event_type;
#define ZMK_EVENT_IMPL(event_type) \
@@ -54,9 +53,9 @@ struct zmk_event_subscription {
ev->data = data; \
return ev; \
}; \
- bool is_##event_type(const zmk_event_t *eh) { return eh->event == &zmk_event_##event_type; }; \
- struct event_type *cast_##event_type(const zmk_event_t *eh) { \
- return &((struct event_type##_event *)eh)->data; \
+ struct event_type *as_##event_type(const zmk_event_t *eh) { \
+ return (eh->event == &zmk_event_##event_type) ? &((struct event_type##_event *)eh)->data \
+ : NULL; \
};
#define ZMK_LISTENER(mod, cb) const struct zmk_listener zmk_listener_##mod = {.callback = cb};