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

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