summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wayclock.cc4
-rw-r--r--src/wlstate.cc23
-rw-r--r--src/wlstate.h1
3 files changed, 27 insertions, 1 deletions
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 <poll.h>
#include <string.h>
-#include <wayland-client-core.h>
#include <wayland-client-protocol.h>
#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);