From abc7451921d9a2daeb7d49a6ac17bebb43d94e8a Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 17 Feb 2025 23:45:24 +0100 Subject: 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. --- cube/cube.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'cube/cube.c') 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; -- cgit v1.2.3