#include "wlstate.h" #include "utils.h" #include #include #include #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); wl_display_t display = wl_display_connect(NULL); 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; } void wayc_wl_state_deinit(struct wl_state_s *state) { wayc_assert(state != NULL); wl_display_disconnect(state->display); }