summaryrefslogtreecommitdiff
path: root/src/wlstate.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-10 08:24:06 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-10 08:24:06 +0100
commit5f861f0f0b81f77bd6ebf3d7e666af2fa0fca2b1 (patch)
tree6d944c2184f84cc9505b5df9e06cb23bcbb780e5 /src/wlstate.cc
parent5b5eb5a16969afc4862fac387940818efc26780a (diff)
wl state
Diffstat (limited to 'src/wlstate.cc')
-rw-r--r--src/wlstate.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/wlstate.cc b/src/wlstate.cc
index e78aad1..674c049 100644
--- a/src/wlstate.cc
+++ b/src/wlstate.cc
@@ -1,5 +1,58 @@
#include "wlstate.h"
#include "utils.h"
+#include <string.h>
+#include <wayland-client-core.h>
+#include <wayland-client-protocol.h>
+
+#define WAYC_VERSION 1
+
+static void wayc_registry_add(void *data, struct wl_registry *registry,
+ uint32_t name, const char *interface,
+ uint32_t version) {
+ (void)version;
+
+ wayc_notnull(data);
+ wayc_notnull(registry);
+ wayc_notnull(interface);
+
+ struct wl_state_s *state = (struct wl_state_s *)data;
+
+ if (!strcmp(interface, wl_compositor_interface.name)) {
+ wl_compositor_t compositor = (wl_compositor_t)wl_registry_bind(
+ registry, name, &wl_compositor_interface, WAYC_VERSION);
+
+ wayc_notnull(compositor);
+ state->compositor = compositor;
+ }
+
+ if (!strcmp(interface, wl_surface_interface.name)) {
+ wl_surface_t surface = (wl_surface_t)wl_registry_bind(
+ registry, name, &wl_surface_interface, WAYC_VERSION);
+
+ wayc_notnull(surface);
+ state->surface = surface;
+ }
+
+ if (!strcmp(interface, xdg_wm_base_interface.name)) {
+ xdg_wm_base_t wm_base = (xdg_wm_base_t)wl_registry_bind(
+ registry, name, &xdg_wm_base_interface, WAYC_VERSION);
+
+ wayc_notnull(wm_base);
+ state->wm_base = wm_base;
+ }
+}
+
+static void wayc_registry_remove(void *data, struct wl_registry *registry,
+ uint32_t name) {
+ wayc_assert(data != NULL);
+ wayc_assert(registry != NULL);
+ wayc_panic("Registry global removed: name=%u", name);
+}
+
+static struct wl_registry_listener WAYC_REGISTRY_LISTENER = {
+ wayc_registry_add,
+ wayc_registry_remove,
+};
bool wayc_wl_state_init(struct wl_state_s *state) {
wayc_assert(state != NULL);
@@ -8,7 +61,17 @@ bool wayc_wl_state_init(struct wl_state_s *state) {
if (display == NULL)
return false;
+ wl_registry_t registry = wl_display_get_registry(display);
+ if (registry == NULL) {
+ wl_display_disconnect(display);
+ return false;
+ }
+
+ wl_registry_add_listener(registry, &WAYC_REGISTRY_LISTENER, state);
+ wl_display_roundtrip(display);
+
state->display = display;
+ state->registry = registry;
return true;
}