From 8e38cd9b8f72c4d1491810f74f2ea053d2ff3e8d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Oct 2023 21:14:49 +1100 Subject: [PATCH] Correct potential error in recent Wayland/LIBDECOR window size change While the fix worked in my tests, the compositor is allowed to ignore a requested window state change which could have entered an eternal loop. Avoid this by limiting the while loop to 2x round-trips. --- intern/ghost/intern/GHOST_WindowWayland.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/intern/ghost/intern/GHOST_WindowWayland.cc b/intern/ghost/intern/GHOST_WindowWayland.cc index 197599fb3ec..8ccb8b73fa9 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.cc +++ b/intern/ghost/intern/GHOST_WindowWayland.cc @@ -1582,11 +1582,19 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system, xdg_toplevel *toplevel = libdecor_frame_get_xdg_toplevel(decor.frame); gwl_window_state_set_for_xdg(toplevel, state, gwl_window_state_get(window_)); + /* Needed for maximize to use the size of the maximized frame instead of the size * from `width` & `height`, see #113961 (follow up comments). */ + int roundtrip_count = 0; while (!decor.initial_state_seen) { - wl_display_flush(system->wl_display_get()); - wl_display_dispatch(system->wl_display_get()); + /* Use round-trip so as not to block in the case setting + * the state is ignored by the compositor. */ + wl_display_roundtrip(system_->wl_display_get()); + /* Avoid waiting continuously if the requested state is ignored + * (2x round-trips should be enough). */ + if (++roundtrip_count >= 2) { + break; + } } } else