#include #include #include static void die(char const* s) { perror(s); exit(EXIT_FAILURE); } static void on_release_shm(struct wl_client* client, struct wl_resource* resource) { fprintf(stderr, "Releasing shm %p\n", (void*)resource); wl_resource_destroy(resource); } static const struct wl_shm_interface shm_impl = { .release = on_release_shm, }; static void on_destroy_shm(struct wl_resource* resource) { fprintf(stderr, "Destroyed shm %p\n", (void*)resource); } static void on_bind_shm(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource* resource = wl_resource_create(client, &wl_shm_interface, wl_shm_interface.version, id); fprintf(stderr, "Bound shm %p\n", (void*)resource); wl_resource_set_implementation(resource, &shm_impl, NULL, on_destroy_shm); } int main(int argc, char** argv) { struct wl_display* disp = wl_display_create(); if (!disp) { die("wl_display_create"); } char const* sock = wl_display_add_socket_auto(disp); if (!sock) { die("wl_display_add_socket_auto"); } printf("Compositor running on %s\n", sock); wl_global_create(disp, &wl_shm_interface, wl_shm_interface.version, NULL, on_bind_shm); wl_display_run(disp); wl_display_destroy(disp); return EXIT_SUCCESS; }