|
13 | 13 | #endif |
14 | 14 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
15 | 15 | #include <wayland-client.h> |
| 16 | +#include <wayland-client-protocol.h> |
16 | 17 | #endif |
17 | 18 |
|
18 | 19 | struct wsi |
@@ -78,6 +79,42 @@ struct LWindow |
78 | 79 | }; |
79 | 80 | static std::vector<LWindow> index_to_LWindow; |
80 | 81 |
|
| 82 | +#ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 83 | +static void wayland_registry_handler(void* data, struct wl_registry* registry, uint32_t id, const char* interface, uint32_t version) |
| 84 | +{ |
| 85 | + LWindow* w = (LWindow*)data; |
| 86 | + if (strcmp(interface, wl_compositor_interface.name) == 0) |
| 87 | + { |
| 88 | + w->wayland.compositor = (wl_compositor*)wl_registry_bind(registry, id, &wl_compositor_interface, 1); |
| 89 | + } |
| 90 | + else if (strcmp(interface, wl_shell_interface.name) == 0) |
| 91 | + { |
| 92 | + w->wayland.shell = (wl_shell*)wl_registry_bind(registry, id, &wl_shell_interface, 1); |
| 93 | + } |
| 94 | + else if (strcmp(interface, wl_seat_interface.name) == 0) |
| 95 | + { |
| 96 | + w->wayland.seat = (wl_seat*)wl_registry_bind(registry, id, &wl_seat_interface, 1); |
| 97 | + } |
| 98 | + else if (strcmp(interface, wl_output_interface.name) == 0) |
| 99 | + { |
| 100 | + w->wayland.output = (wl_output*)wl_registry_bind(registry, id, &wl_output_interface, 1); |
| 101 | + } |
| 102 | + (void)version; |
| 103 | +} |
| 104 | + |
| 105 | +static void wayland_registry_remove(void* data, struct wl_registry* registry, uint32_t id) |
| 106 | +{ |
| 107 | + (void)data; |
| 108 | + (void)registry; |
| 109 | + (void)id; |
| 110 | +} |
| 111 | + |
| 112 | +static const struct wl_registry_listener wayland_registry_listener = { |
| 113 | + wayland_registry_handler, |
| 114 | + wayland_registry_remove |
| 115 | +}; |
| 116 | +#endif |
| 117 | + |
81 | 118 | #ifdef VK_USE_PLATFORM_XCB_KHR |
82 | 119 | static const char* lavaxcb_strerror(int err) |
83 | 120 | { |
@@ -326,17 +363,24 @@ VkSurfaceKHR window_create(VkInstance instance, uint32_t index, int32_t x, int32 |
326 | 363 | if (!w.wayland.display) ABORT("Failed to connect to Wayland display server"); |
327 | 364 | w.wayland.registry = wl_display_get_registry(w.wayland.display); |
328 | 365 | if (!w.wayland.registry) ABORT("Failed to connect to Wayland registry"); |
329 | | - //wl_registry_add_listener(w.wayland.registry, &vkDisplayWayland::registry_listener, this); |
| 366 | + wl_registry_add_listener(w.wayland.registry, &wayland_registry_listener, &w); |
330 | 367 | wl_display_roundtrip(w.wayland.display); |
| 368 | + if (!w.wayland.compositor) ABORT("Failed to bind Wayland compositor"); |
331 | 369 | w.wayland.surface = wl_compositor_create_surface(w.wayland.compositor); |
| 370 | + if (!w.wayland.surface) ABORT("Failed to create Wayland surface"); |
| 371 | + if (w.wayland.shell) |
| 372 | + { |
| 373 | + w.wayland.shell_surface = wl_shell_get_shell_surface(w.wayland.shell, w.wayland.surface); |
| 374 | + if (w.wayland.shell_surface) wl_shell_surface_set_toplevel(w.wayland.shell_surface); |
| 375 | + } |
332 | 376 | VkWaylandSurfaceCreateInfoKHR pInfo = { VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR, nullptr }; |
333 | 377 | pInfo.display = w.wayland.display; |
334 | 378 | pInfo.surface = w.wayland.surface; |
335 | 379 | pInfo.flags = 0; |
336 | 380 | VkResult result = wrap_vkCreateWaylandSurfaceKHR(instance, &pInfo, nullptr, &surface); |
337 | 381 | if (result != VK_SUCCESS) |
338 | 382 | { |
339 | | - ABORT("Failed to create wayland surface"); |
| 383 | + ABORT("Failed to create Wayland Vulkan surface object: %s", errorString(result)); |
340 | 384 | } |
341 | 385 | #endif |
342 | 386 | } |
|
0 commit comments