From 888ce66e186e2892bc30afb5bb97918d504e0ba1 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 10 Feb 2026 08:48:01 +0100 Subject: event loop --- src/wayclock.cc | 4 ++++ src/wlstate.cc | 23 ++++++++++++++++++++++- src/wlstate.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/wayclock.cc b/src/wayclock.cc index ecfb784..3009f8d 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -5,6 +5,10 @@ int main() { if (!wayc_wl_state_init(&state)) wayc_panic("Failed to initialize Wayland state", nullptr); + while (true) { + wayc_wl_state_update(&state); + } + wayc_wl_state_deinit(&state); return 0; } \ No newline at end of file diff --git a/src/wlstate.cc b/src/wlstate.cc index 9232843..1a02b5b 100644 --- a/src/wlstate.cc +++ b/src/wlstate.cc @@ -1,8 +1,8 @@ #include "wlstate.h" #include "utils.h" #include "xdg-shell.h" +#include #include -#include #include #define WAYC_VERSION 1 @@ -91,3 +91,24 @@ void wayc_wl_state_deinit(struct wl_state_s *state) { wl_display_disconnect(state->display); } + +void wayc_wl_state_update(struct wl_state_s *state) { + wayc_assert(state != NULL); + + struct pollfd pfd = { + (i32)state->eventfd, + POLLIN, + 0, + }; + + i32 rc = poll(&pfd, 1, 0); + if (rc == -1) + wayc_panic("Failed to poll Wayland eventfd"); + + if (!(pfd.revents & POLLIN)) + return; + + rc = wl_display_dispatch(state->display); + if (rc == -1) + wayc_panic("Failed to dispatch Wayland events"); +} diff --git a/src/wlstate.h b/src/wlstate.h index e4757f6..9d962c2 100644 --- a/src/wlstate.h +++ b/src/wlstate.h @@ -12,3 +12,4 @@ struct wl_state_s { 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); -- cgit v1.2.3