summaryrefslogtreecommitdiff
path: root/app/include/zmk/events/keycode_state_changed.h
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2021-01-18 00:35:56 -0500
committerPete Johanson <peter@peterjohanson.com>2021-01-20 07:06:11 -0500
commit3fe2acc2d191006fa6309191ee99b2e4e249ed08 (patch)
tree4994508fdc58daee4629c671e07e689b6332bd32 /app/include/zmk/events/keycode_state_changed.h
parent003db892adadb7b760f43411d7154fe60bf3556d (diff)
refactor(core): Extra event payloads to own types, refactor API.
* Make it easier to use *just* event payloads by defining the data, and then having event manager macros generate "wrapper structs" * Improve is_*/cast_* APIs to hide details of full event struct. * Create `zmk_event_t` typedef to pass to event handlers. * Bring event names inline w/ consistent `zmk_` prefix.
Diffstat (limited to 'app/include/zmk/events/keycode_state_changed.h')
-rw-r--r--app/include/zmk/events/keycode_state_changed.h22
1 files changed, 10 insertions, 12 deletions
diff --git a/app/include/zmk/events/keycode_state_changed.h b/app/include/zmk/events/keycode_state_changed.h
index 85b792b..031169d 100644
--- a/app/include/zmk/events/keycode_state_changed.h
+++ b/app/include/zmk/events/keycode_state_changed.h
@@ -12,8 +12,7 @@
#include <zmk/event_manager.h>
#include <zmk/keys.h>
-struct keycode_state_changed {
- struct zmk_event_header header;
+struct zmk_keycode_state_changed {
uint16_t usage_page;
uint32_t keycode;
uint8_t implicit_modifiers;
@@ -21,10 +20,10 @@ struct keycode_state_changed {
int64_t timestamp;
};
-ZMK_EVENT_DECLARE(keycode_state_changed);
+ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
-static inline struct keycode_state_changed *
-keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
+static inline struct zmk_keycode_state_changed_event *
+zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
uint16_t page = HID_USAGE_PAGE(encoded) & 0xFF;
uint16_t id = HID_USAGE_ID(encoded);
zmk_mod_flags_t implicit_mods = SELECT_MODS(encoded);
@@ -33,11 +32,10 @@ keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t times
page = HID_USAGE_KEY;
}
- struct keycode_state_changed *ev = new_keycode_state_changed();
- ev->usage_page = page;
- ev->keycode = id;
- ev->implicit_modifiers = implicit_mods;
- ev->state = pressed;
- ev->timestamp = timestamp;
- return ev;
+ return new_zmk_keycode_state_changed(
+ (struct zmk_keycode_state_changed){.usage_page = page,
+ .keycode = id,
+ .implicit_modifiers = implicit_mods,
+ .state = pressed,
+ .timestamp = timestamp});
}