Skip to content

Commit cd5a45c

Browse files
Make Wayland backend no longer crash.
Still does not display a window properly.
1 parent fd7e27a commit cd5a45c

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/hardcode_read.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,12 @@ const char* const* instance_extensions(lava_file_reader& reader, uint32_t& len)
903903
backing.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
904904
}
905905
#endif
906+
#ifdef VK_USE_PLATFORM_XCB_KHR
907+
if (strcmp(winsys, "wayland") == 0 && !is_noscreen())
908+
{
909+
backing.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
910+
}
911+
#endif
906912
#ifdef VK_USE_PLATFORM_XLIB_KHR
907913
if (strcmp(winsys, "x11") == 0 && !is_noscreen())
908914
{

src/window.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#endif
1414
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
1515
#include <wayland-client.h>
16+
#include <wayland-client-protocol.h>
1617
#endif
1718

1819
struct wsi
@@ -78,6 +79,42 @@ struct LWindow
7879
};
7980
static std::vector<LWindow> index_to_LWindow;
8081

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+
81118
#ifdef VK_USE_PLATFORM_XCB_KHR
82119
static const char* lavaxcb_strerror(int err)
83120
{
@@ -326,17 +363,24 @@ VkSurfaceKHR window_create(VkInstance instance, uint32_t index, int32_t x, int32
326363
if (!w.wayland.display) ABORT("Failed to connect to Wayland display server");
327364
w.wayland.registry = wl_display_get_registry(w.wayland.display);
328365
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);
330367
wl_display_roundtrip(w.wayland.display);
368+
if (!w.wayland.compositor) ABORT("Failed to bind Wayland compositor");
331369
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+
}
332376
VkWaylandSurfaceCreateInfoKHR pInfo = { VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR, nullptr };
333377
pInfo.display = w.wayland.display;
334378
pInfo.surface = w.wayland.surface;
335379
pInfo.flags = 0;
336380
VkResult result = wrap_vkCreateWaylandSurfaceKHR(instance, &pInfo, nullptr, &surface);
337381
if (result != VK_SUCCESS)
338382
{
339-
ABORT("Failed to create wayland surface");
383+
ABORT("Failed to create Wayland Vulkan surface object: %s", errorString(result));
340384
}
341385
#endif
342386
}

0 commit comments

Comments
 (0)