Steward
分享是一種喜悅、更是一種幸福
程式語言 - Wayland - Client - Add Listener
參考資訊:
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> #include <wayland-client.h> void cb_handle ( void *dat, struct wl_registry *reg, uint32_t id, const char *intf, uint32_t ver) { printf ( "%s, intf:%s, ver:%u, id:%u\n" , __func__ , intf, ver, id); } void cb_remove ( void *dat, struct wl_registry *reg, uint32_t id) { printf ( "%s, %u\n" , __func__ , 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); wl_registry_destroy (reg); wl_display_disconnect (dis); return 0; } |
編譯、執行
$ gcc main.c -o main -lwayland-client $ ./main cb_handle, intf:wl_compositor, ver:3, id:1 cb_handle, intf:wl_data_device_manager, ver:1, id:2 cb_handle, intf:wl_shm, ver:1, id:3 cb_handle, intf:qt_hardware_integration, ver:1, id:4 cb_handle, intf:android_wlegl, ver:2, id:5 cb_handle, intf:qt_surface_extension, ver:1, id:6 cb_handle, intf:qt_touch_extension, ver:1, id:7 cb_handle, intf:qt_windowmanager, ver:1, id:8 cb_handle, intf:wl_seat, ver:3, id:9 cb_handle, intf:wl_output, ver:2, id:10 cb_handle, intf:wl_shell, ver:1, id:11 cb_handle, intf:lipstick_recorder_manager, ver:1, id:12 cb_handle, intf:alien_manager, ver:1, id:13