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

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