參考資訊:
https://jan.newmarch.name/Wayland/index.html
https://wayland.freedesktop.org/docs/html/apa.html
https://bugaevc.gitbooks.io/writing-wayland-clients/content/
main.c
#include <stdio.h> #include <string.h> #include <wayland-client.h> struct wl_compositor *comp = NULL; void cb_handle(void *dat, struct wl_registry *reg, uint32_t id, const char *intf, uint32_t ver) { if (strcmp(intf, "wl_compositor") == 0) { comp = wl_registry_bind(reg, id, &wl_compositor_interface, 3); } } void cb_remove(void *dat, struct wl_registry *reg, uint32_t id) { } int main(int argc, char **argv) { struct wl_display *dis = wl_display_connect(NULL); struct wl_registry *reg = wl_display_get_registry(dis); struct wl_registry_listener cb = { .global = cb_handle, .global_remove = cb_remove }; wl_registry_add_listener(reg, &cb, NULL); wl_display_dispatch(dis); wl_display_roundtrip(dis); printf("comp=0x%08x\n", comp); wl_registry_destroy(reg); wl_compositor_destroy(comp); wl_display_disconnect(dis); return 0; }
編譯、執行
$ gcc main.c -o main -lwayland-client $ ./main comp=0x016a4b18