diff options
| author | Xaver Hugl <xaver.hugl@gmail.com> | 2025-02-17 23:45:24 +0100 |
|---|---|---|
| committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2025-06-30 10:25:22 -0500 |
| commit | abc7451921d9a2daeb7d49a6ac17bebb43d94e8a (patch) | |
| tree | 3343a625965dd9af3ceb018da6a40924d82b78d4 | |
| parent | 55f6b39722978d0f46fd0b07d22fa4f3604378eb (diff) | |
| download | usermoji-abc7451921d9a2daeb7d49a6ac17bebb43d94e8a.tar.xz | |
cube: prefer Wayland over X11 when available
In Wayland sessions, X11 is still available through a compatibility layer, but should
effectively never be used over a native Wayland connection if the application is
capable of that.
| -rw-r--r-- | cube/cube.c | 48 | ||||
| -rw-r--r-- | cube/cube.cpp | 36 |
2 files changed, 42 insertions, 42 deletions
diff --git a/cube/cube.c b/cube/cube.c index 3a25dac4..a616af24 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -3745,6 +3745,30 @@ static const char *demo_init_wayland_connection(struct demo *demo) { // If the wsi_platform is AUTO, this function also sets wsi_platform to the first available WSI platform // Otherwise, it errors out if the specified wsi_platform isn't available static void demo_check_and_set_wsi_platform(struct demo *demo) { +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) + if (demo->wsi_platform == WSI_PLATFORM_WAYLAND || demo->wsi_platform == WSI_PLATFORM_AUTO) { + bool wayland_extension_available = false; + for (uint32_t i = 0; i < demo->enabled_extension_count; i++) { + if (strcmp(demo->extension_names[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { + wayland_extension_available = true; + break; + } + } + if (wayland_extension_available) { + const char *error_msg = demo_init_wayland_connection(demo); + if (error_msg != NULL) { + if (demo->wsi_platform == WSI_PLATFORM_WAYLAND) { + fprintf(stderr, "%s\nExiting ...\n", error_msg); + fflush(stdout); + exit(1); + } + } else { + demo->wsi_platform = WSI_PLATFORM_WAYLAND; + return; + } + } + } +#endif #if defined(VK_USE_PLATFORM_XCB_KHR) if (demo->wsi_platform == WSI_PLATFORM_XCB || demo->wsi_platform == WSI_PLATFORM_AUTO) { bool xcb_extension_available = false; @@ -3793,30 +3817,6 @@ static void demo_check_and_set_wsi_platform(struct demo *demo) { } } #endif -#if defined(VK_USE_PLATFORM_WAYLAND_KHR) - if (demo->wsi_platform == WSI_PLATFORM_WAYLAND || demo->wsi_platform == WSI_PLATFORM_AUTO) { - bool wayland_extension_available = false; - for (uint32_t i = 0; i < demo->enabled_extension_count; i++) { - if (strcmp(demo->extension_names[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { - wayland_extension_available = true; - break; - } - } - if (wayland_extension_available) { - const char *error_msg = demo_init_wayland_connection(demo); - if (error_msg != NULL) { - if (demo->wsi_platform == WSI_PLATFORM_WAYLAND) { - fprintf(stderr, "%s\nExiting ...\n", error_msg); - fflush(stdout); - exit(1); - } - } else { - demo->wsi_platform = WSI_PLATFORM_WAYLAND; - return; - } - } - } -#endif #if defined(VK_USE_PLATFORM_DIRECTFB_EXT) if (demo->wsi_platform == WSI_PLATFORM_DIRECTFB || demo->wsi_platform == WSI_PLATFORM_AUTO) { bool direftfb_extension_available = false; diff --git a/cube/cube.cpp b/cube/cube.cpp index e1d67e85..1522ba0c 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -1325,58 +1325,58 @@ const char *Demo::init_wayland_connection() { #endif void Demo::check_and_set_wsi_platform() { -#if defined(VK_USE_PLATFORM_XCB_KHR) - if (wsi_platform == WsiPlatform::xcb || wsi_platform == WsiPlatform::auto_) { +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) + if (wsi_platform == WsiPlatform::wayland || wsi_platform == WsiPlatform::auto_) { auto found = std::find_if(enabled_instance_extensions.begin(), enabled_instance_extensions.end(), - [](const char *str) { return 0 == strcmp(str, VK_KHR_XCB_SURFACE_EXTENSION_NAME); }); + [](const char *str) { return 0 == strcmp(str, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); }); if (found != enabled_instance_extensions.end()) { - const char *error_msg = init_xcb_connection(); + const char *error_msg = init_wayland_connection(); if (error_msg != NULL) { - if (wsi_platform == WsiPlatform::xcb) { + if (wsi_platform == WsiPlatform::wayland) { fprintf(stderr, "%s\nExiting ...\n", error_msg); fflush(stdout); exit(1); } } else { - wsi_platform = WsiPlatform::xcb; + wsi_platform = WsiPlatform::wayland; return; } } } #endif -#if defined(VK_USE_PLATFORM_XLIB_KHR) - if (wsi_platform == WsiPlatform::xlib || wsi_platform == WsiPlatform::auto_) { +#if defined(VK_USE_PLATFORM_XCB_KHR) + if (wsi_platform == WsiPlatform::xcb || wsi_platform == WsiPlatform::auto_) { auto found = std::find_if(enabled_instance_extensions.begin(), enabled_instance_extensions.end(), - [](const char *str) { return 0 == strcmp(str, VK_KHR_XLIB_SURFACE_EXTENSION_NAME); }); + [](const char *str) { return 0 == strcmp(str, VK_KHR_XCB_SURFACE_EXTENSION_NAME); }); if (found != enabled_instance_extensions.end()) { - const char *error_msg = init_xlib_connection(); + const char *error_msg = init_xcb_connection(); if (error_msg != NULL) { - if (wsi_platform == WsiPlatform::xlib) { + if (wsi_platform == WsiPlatform::xcb) { fprintf(stderr, "%s\nExiting ...\n", error_msg); fflush(stdout); exit(1); } } else { - wsi_platform = WsiPlatform::xlib; + wsi_platform = WsiPlatform::xcb; return; } } } #endif -#if defined(VK_USE_PLATFORM_WAYLAND_KHR) - if (wsi_platform == WsiPlatform::wayland || wsi_platform == WsiPlatform::auto_) { +#if defined(VK_USE_PLATFORM_XLIB_KHR) + if (wsi_platform == WsiPlatform::xlib || wsi_platform == WsiPlatform::auto_) { auto found = std::find_if(enabled_instance_extensions.begin(), enabled_instance_extensions.end(), - [](const char *str) { return 0 == strcmp(str, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); }); + [](const char *str) { return 0 == strcmp(str, VK_KHR_XLIB_SURFACE_EXTENSION_NAME); }); if (found != enabled_instance_extensions.end()) { - const char *error_msg = init_wayland_connection(); + const char *error_msg = init_xlib_connection(); if (error_msg != NULL) { - if (wsi_platform == WsiPlatform::wayland) { + if (wsi_platform == WsiPlatform::xlib) { fprintf(stderr, "%s\nExiting ...\n", error_msg); fflush(stdout); exit(1); } } else { - wsi_platform = WsiPlatform::wayland; + wsi_platform = WsiPlatform::xlib; return; } } |
