From 6ba476b3bdcd709574750f56fe7c002b9a55bfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 28 Feb 2020 18:43:33 +0100 Subject: [PATCH] wayland: configure: work around GNOME/mutter weirdness When resizing the window under mutter, mutter seems to expect a configure ack *and* a surface commit *right* away, or things get out of sync. Unlike kwin, which is requires a commit for each configure ack, but is fine with having the commit arrive later (after we've rendered it), mutter is not. I even tried delaying the configure ack until just before the commit, but still no go. So for now, detect when we're running under mutter and always do a surface commit right away. This can *not* be done on any other compositor as it breaks the CSD and main surface synchronization; we've resized the CSDs, but not the main surface. I.e. this *should* not work, but for some reason is the *only* way to make things work on mutter. Interestingly, doing it any other way on mutter causes visual glitches; window jumping around when resizing, or de-synchronized CSDs/main surface. --- wayland.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/wayland.c b/wayland.c index 979c3bd7..9b8cb258 100644 --- a/wayland.c +++ b/wayland.c @@ -595,11 +595,41 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, else term_visual_focus_out(term); - if (!resized) { + static bool desktop_is_gnome = false; + static bool desktop_is_initialized = false; + + if (!desktop_is_initialized) { + const char *current_desktop = getenv("XDG_CURRENT_DESKTOP"); + + desktop_is_gnome = current_desktop != NULL && + strcasestr(current_desktop, "gnome") != NULL; + + if (desktop_is_gnome) + LOG_WARN("applying wl_surface_commit() workaround for mutter"); + + desktop_is_initialized = true; + } + + if (desktop_is_gnome) { /* - * kwin seems to need a commit for each configure ack, or it - * will get stuck. Since we'll get a "real" commit soon if we - * resized, only commit here if size did *not* change + * Resizing the window under mutter causes the "other" side to + * jump back and forth, *even* if we re-render and commit a + * properly resized frame immediately. + * + * For that reason, the code path below also does not work, + * since in case we *did* resize, it appears the commit + * happens "too late" after the ack. + * + * Finally, doing this on any other compositor breaks the CSD + * synchronization with the main surface. Hence we only do + * this when running under mutter. + */ + wl_surface_commit(win->surface); + } else if (!resized) { + /* + * If we didn't resize, we won't be commit a new surface + * anytime soon. Some compositors require a commit in + * combination with an ack - make them happy. */ wl_surface_commit(win->surface); }