From 0d62b836f33bd7029e769ffe1a823d7fcec0a8ff Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 10 Feb 2026 11:40:59 +0100 Subject: use type decl --- src/events.h | 19 +++++++++++++------ src/vec.h | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/events.h b/src/events.h index db66571..16bf1d3 100644 --- a/src/events.h +++ b/src/events.h @@ -14,18 +14,25 @@ struct event_kind_resize_s { i32 width, height; }; +union event_kind_data_u { + struct event_kind_resize_s resize; +}; + struct event_s { enum event_kind_e kind; struct window_s *window; - union { - struct event_kind_resize_s resize; - }; + union event_kind_data_u data; }; -#define WAYC_EVENT_INIT(kind, window, ...) {kind, window, __VA_ARGS__} -#define WAYC_EVENT_CLOSE(window) WAYC_EVENT_INIT(EVENT_KIND_CLOSE, window, {}) +#define WAYC_EVENT_INIT(kind, window, ...) \ + event_s { kind, window, __VA_ARGS__ } + +#define WAYC_EVENT_CLOSE(window) \ + WAYC_EVENT_INIT(EVENT_KIND_CLOSE, window, event_kind_data_u{}) + #define WAYC_EVENT_RESIZE(window, width, height) \ - WAYC_EVENT_INIT(EVENT_KIND_RESIZE, window, {{width, height}}) + WAYC_EVENT_INIT(EVENT_KIND_RESIZE, window, \ + event_kind_data_u{event_kind_resize_s{width, height}}) struct eventloop_s; diff --git a/src/vec.h b/src/vec.h index 5cef8a3..6224574 100644 --- a/src/vec.h +++ b/src/vec.h @@ -11,7 +11,7 @@ struct raw_vec_s { usize len, cap; }; -#define WAYC_RAW_VEC_INIT(size) {nullptr, size, 0, 0} +#define WAYC_RAW_VEC_INIT(size) raw_vec_s{nullptr, size, 0, 0} void wayc_raw_vec_push(raw_vec_s *vec, const u8 *at); bool wayc_raw_vec_pop(raw_vec_s *vec, u8 *out); @@ -21,7 +21,8 @@ template struct vec_s { raw_vec_s raw; }; -#define WAYC_VEC_INIT(type) {WAYC_RAW_VEC_INIT(sizeof(type))} +#define WAYC_VEC_INIT(type) \ + vec_s { WAYC_RAW_VEC_INIT(sizeof(type)) } template static inline void wayc_vec_push(vec_s *vec, const T *at) { -- cgit v1.2.3