Blame SOURCES/0038-client-Simplify-round-trip-behavior.patch

f38a11
From 971dbf2d5be743ddeb998f7461ff3e06ccb892c4 Mon Sep 17 00:00:00 2001
b814f0
From: David Edmundson <davidedmundson@kde.org>
b814f0
Date: Wed, 9 Feb 2022 17:20:48 +0000
f38a11
Subject: [PATCH 38/40] client: Simplify round trip behavior
b814f0
b814f0
The custom event queue was removed in
b814f0
302d4ffb8549214eb4028dc3e47ec4ee4e12ffbd (2015) so the comment about not
b814f0
being able to use the inbuilt round trip method no longer applies.
b814f0
b814f0
This fixes a real world problem. Use of a blocking round trip should not
b814f0
process non wayland events. Doing so can lead to misbehaviour client
b814f0
side as things happen out of order. The move to the event thread created
b814f0
several regressions as we now get events before the QGuiApplication is
b814f0
fully constructed.
b814f0
b814f0
Change-Id: I650481f49a47ed1a9778c7e1bc3c48db6e8f0031
b814f0
Reviewed-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
b814f0
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
b814f0
(cherry picked from commit 62646d9122845d7bd9104b610478cebde3e769c7)
b814f0
---
b814f0
 src/client/qwaylanddisplay.cpp | 43 +---------------------------------
b814f0
 1 file changed, 1 insertion(+), 42 deletions(-)
b814f0
b814f0
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
b814f0
index 6f1bada5..86045a35 100644
b814f0
--- a/src/client/qwaylanddisplay.cpp
b814f0
+++ b/src/client/qwaylanddisplay.cpp
b814f0
@@ -611,50 +611,9 @@ uint32_t QWaylandDisplay::currentTimeMillisec()
b814f0
     return 0;
b814f0
 }
b814f0
 
b814f0
-static void
b814f0
-sync_callback(void *data, struct wl_callback *callback, uint32_t serial)
b814f0
-{
b814f0
-    Q_UNUSED(serial)
b814f0
-    bool *done = static_cast<bool *>(data);
b814f0
-
b814f0
-    *done = true;
b814f0
-
b814f0
-    // If the wl_callback done event is received after the condition check in the while loop in
b814f0
-    // forceRoundTrip(), but before the call to processEvents, the call to processEvents may block
b814f0
-    // forever if no more events are posted (eventhough the callback is handled in response to the
b814f0
-    // aboutToBlock signal). Hence, we wake up the event dispatcher so forceRoundTrip may return.
b814f0
-    // (QTBUG-64696)
b814f0
-    if (auto *dispatcher = QThread::currentThread()->eventDispatcher())
b814f0
-        dispatcher->wakeUp();
b814f0
-
b814f0
-    wl_callback_destroy(callback);
b814f0
-}
b814f0
-
b814f0
-static const struct wl_callback_listener sync_listener = {
b814f0
-    sync_callback
b814f0
-};
b814f0
-
b814f0
 void QWaylandDisplay::forceRoundTrip()
b814f0
 {
b814f0
-    // wl_display_roundtrip() works on the main queue only,
b814f0
-    // but we use a separate one, so basically reimplement it here
b814f0
-    int ret = 0;
b814f0
-    bool done = false;
b814f0
-    wl_callback *callback = wl_display_sync(mDisplay);
b814f0
-    wl_callback_add_listener(callback, &sync_listener, &done);
b814f0
-    flushRequests();
b814f0
-    if (QThread::currentThread()->eventDispatcher()) {
b814f0
-        while (!done && ret >= 0) {
b814f0
-            QThread::currentThread()->eventDispatcher()->processEvents(QEventLoop::WaitForMoreEvents);
b814f0
-            ret = wl_display_dispatch_pending(mDisplay);
b814f0
-        }
b814f0
-    } else {
b814f0
-        while (!done && ret >= 0)
b814f0
-            ret = wl_display_dispatch(mDisplay);
b814f0
-    }
b814f0
-
b814f0
-    if (ret == -1 && !done)
b814f0
-        wl_callback_destroy(callback);
b814f0
+     wl_display_roundtrip(mDisplay);
b814f0
 }
b814f0
 
b814f0
 bool QWaylandDisplay::supportsWindowDecoration() const
b814f0
-- 
b814f0
2.35.1
b814f0