From e3ecc39da57a5ed15ec8de67f136273ee54b78be Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Sat, 20 Sep 2025 15:22:07 +0200 Subject: cube: Resize surface after configure --- cube/cube.c | 21 ++++++++++++++++----- cube/cube.cpp | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'cube') diff --git a/cube/cube.c b/cube/cube.c index 63fc07b2..5797ca51 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -443,6 +443,7 @@ struct demo { struct wl_seat *seat; struct wl_pointer *pointer; struct wl_keyboard *keyboard; + int pending_width, pending_height; #endif #if defined(VK_USE_PLATFORM_DIRECTFB_EXT) IDirectFB *dfb; @@ -1372,6 +1373,12 @@ static void demo_prepare_swapchain(struct demo *demo) { VkResult U_ASSERT_ONLY err; VkSwapchainKHR oldSwapchain = demo->swapchain; +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) + if (demo->wsi_platform == WSI_PLATFORM_WAYLAND && !demo->xdg_surface_has_been_configured) { + return; + } +#endif + // Check the surface capabilities and formats VkSurfaceCapabilitiesKHR surfCapabilities; err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(demo->gpu, demo->surface, &surfCapabilities); @@ -3055,10 +3062,14 @@ static void demo_run(struct demo *demo) { static void handle_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) { struct demo *demo = (struct demo *)data; xdg_surface_ack_configure(xdg_surface, serial); - if (demo->xdg_surface_has_been_configured) { - demo_resize(demo); - } demo->xdg_surface_has_been_configured = 1; + if (demo->pending_width > 0) { + demo->width = demo->pending_width; + } + if (demo->pending_height > 0) { + demo->height = demo->pending_height; + } + demo_resize(demo); } static const struct xdg_surface_listener xdg_surface_listener = {handle_surface_configure}; @@ -3069,10 +3080,10 @@ static void handle_toplevel_configure(void *data, struct xdg_toplevel *xdg_tople /* zero values imply the program may choose its own size, so in that case * stay with the existing value (which on startup is the default) */ if (width > 0) { - demo->width = width; + demo->pending_width = width; } if (height > 0) { - demo->height = height; + demo->pending_height = height; } /* This should be followed by a surface configure */ } diff --git a/cube/cube.cpp b/cube/cube.cpp index 7f4b45d2..04ba3150 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -442,6 +442,7 @@ struct Demo { wl_seat *seat = nullptr; wl_pointer *pointer = nullptr; wl_keyboard *keyboard = nullptr; + int pending_width, pending_height; #endif #if defined(VK_USE_PLATFORM_DIRECTFB_EXT) IDirectFB *dfb = nullptr; @@ -2197,6 +2198,12 @@ void Demo::prepare() { void Demo::prepare_swapchain() { vk::SwapchainKHR oldSwapchain = swapchain; +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) + if (wsi_platform == WsiPlatform::wayland && !xdg_surface_has_been_configured) { + return; + } +#endif + // Check the surface capabilities and formats auto surface_capabilities_return = gpu.getSurfaceCapabilitiesKHR(surface); VERIFY(surface_capabilities_return.result == vk::Result::eSuccess); @@ -3419,10 +3426,14 @@ void Demo::run() { static void handle_surface_configure(void *data, xdg_surface *xdg_surface, uint32_t serial) { Demo &demo = *static_cast(data); xdg_surface_ack_configure(xdg_surface, serial); - if (demo.xdg_surface_has_been_configured) { - demo.resize(); - } demo.xdg_surface_has_been_configured = true; + if (demo.pending_width > 0) { + demo.width = demo.pending_width; + } + if (demo.pending_height > 0) { + demo.height = demo.pending_height; + } + demo.resize(); } static const xdg_surface_listener surface_listener = {handle_surface_configure}; @@ -3433,10 +3444,10 @@ static void handle_toplevel_configure(void *data, xdg_toplevel *xdg_toplevel, in /* zero values imply the program may choose its own size, so in that case * stay with the existing value (which on startup is the default) */ if (width > 0) { - demo.width = static_cast(width); + demo.pending_width = static_cast(width); } if (height > 0) { - demo.height = static_cast(height); + demo.pending_height = static_cast(height); } // This will be followed by a surface configure } -- cgit v1.2.3