From 86c09e193ed66420da48a7fd62678286b89dace2 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 10 Feb 2026 09:04:15 +0100 Subject: working on event loop --- src/events.h | 19 +++++++++++++++++++ src/utils.h | 10 ++++++++++ src/wayclock.cc | 8 ++++---- src/window.h | 5 +++++ src/wlstate.cc | 8 ++++---- src/wlstate.h | 8 ++++---- 6 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 src/events.h create mode 100644 src/window.h (limited to 'src') diff --git a/src/events.h b/src/events.h new file mode 100644 index 0000000..73efe55 --- /dev/null +++ b/src/events.h @@ -0,0 +1,19 @@ +#pragma once + +#include "utils.h" +#include "window.h" +#include "wlstate.h" + +enum event_kind_e { + EVENT_KIND_CLOSE, +}; + +struct event_s { + enum event_kind_e kind; + struct window_s *window; +}; + +struct eventloop_s { + struct wlstate_s state; + +}; diff --git a/src/utils.h b/src/utils.h index 5f9d1cb..59b5334 100644 --- a/src/utils.h +++ b/src/utils.h @@ -17,6 +17,16 @@ typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; +#if UINT64_MAX == UINTPTR_MAX +typedef u64 usize; +typedef i64 isize; +#elif UINT32_MAX == UINTPTR_MAX +typedef u32 usize; +typedef i32 isize; +#else +#error "Unsupported pointer size" +#endif + typedef struct wl_display *wl_display_t; typedef struct wl_registry *wl_registry_t; typedef struct wl_compositor *wl_compositor_t; diff --git a/src/wayclock.cc b/src/wayclock.cc index 3009f8d..7f46c40 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -1,14 +1,14 @@ #include "wlstate.h" int main() { - wl_state_s state; - if (!wayc_wl_state_init(&state)) + wlstate_s state; + if (!wayc_wlstate_init(&state)) wayc_panic("Failed to initialize Wayland state", nullptr); while (true) { - wayc_wl_state_update(&state); + wayc_wlstate_update(&state); } - wayc_wl_state_deinit(&state); + wayc_wlstate_deinit(&state); return 0; } \ No newline at end of file diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..3b676f5 --- /dev/null +++ b/src/window.h @@ -0,0 +1,5 @@ +#pragma once + +#include "utils.h" + +struct window_s {}; \ No newline at end of file diff --git a/src/wlstate.cc b/src/wlstate.cc index 1a02b5b..4b1a65f 100644 --- a/src/wlstate.cc +++ b/src/wlstate.cc @@ -25,7 +25,7 @@ static void wayc_registry_add(void *data, struct wl_registry *registry, wayc_notnull(registry); wayc_notnull(interface); - struct wl_state_s *state = (struct wl_state_s *)data; + struct wlstate_s *state = (struct wlstate_s *)data; if (!strcmp(interface, wl_compositor_interface.name)) { wl_compositor_t compositor = (wl_compositor_t)wl_registry_bind( @@ -57,7 +57,7 @@ static struct wl_registry_listener WAYC_REGISTRY_LISTENER = { wayc_registry_remove, }; -bool wayc_wl_state_init(struct wl_state_s *state) { +bool wayc_wlstate_init(struct wlstate_s *state) { wayc_assert(state != NULL); wl_display_t display = wl_display_connect(NULL); @@ -86,13 +86,13 @@ bool wayc_wl_state_init(struct wl_state_s *state) { return true; } -void wayc_wl_state_deinit(struct wl_state_s *state) { +void wayc_wlstate_deinit(struct wlstate_s *state) { wayc_assert(state != NULL); wl_display_disconnect(state->display); } -void wayc_wl_state_update(struct wl_state_s *state) { +void wayc_wlstate_update(struct wlstate_s *state) { wayc_assert(state != NULL); struct pollfd pfd = { diff --git a/src/wlstate.h b/src/wlstate.h index 9d962c2..7bb3499 100644 --- a/src/wlstate.h +++ b/src/wlstate.h @@ -2,7 +2,7 @@ #include "utils.h" -struct wl_state_s { +struct wlstate_s { wl_display_t display; wl_registry_t registry; wl_compositor_t compositor; @@ -10,6 +10,6 @@ struct wl_state_s { u32 eventfd; }; -bool wayc_wl_state_init(struct wl_state_s *state); -void wayc_wl_state_deinit(struct wl_state_s *state); -void wayc_wl_state_update(struct wl_state_s *state); +bool wayc_wlstate_init(struct wlstate_s *state); +void wayc_wlstate_deinit(struct wlstate_s *state); +void wayc_wlstate_update(struct wlstate_s *state); -- cgit v1.2.3