diff --git a/egl_wayland_backend.cpp b/egl_wayland_backend.cpp
index f83d9a2a3b..b7dc0e624d 100644
--- a/egl_wayland_backend.cpp
+++ b/egl_wayland_backend.cpp
@@ -250,9 +250,6 @@ bool EglWaylandBackend::initBufferConfigs()
void EglWaylandBackend::present()
{
- // need to dispatch pending events as eglSwapBuffers can block
- m_wayland->dispatchEvents();
-
m_lastFrameRendered = false;
wl_callback *callback = wl_surface_frame(m_wayland->surface());
wl_callback_add_listener(callback, &s_surfaceFrameListener, this);
diff --git a/scene_qpainter.cpp b/scene_qpainter.cpp
index 0096ca8811..5fe91ef9d9 100644
--- a/scene_qpainter.cpp
+++ b/scene_qpainter.cpp
@@ -140,7 +140,6 @@ void WaylandQPainterBackend::present(int mask, const QRegion &damage)
wl_surface_damage(surface, rect.x(), rect.y(), rect.width(), rect.height());
}
wl_surface_commit(surface);
- wl->dispatchEvents();
}
void WaylandQPainterBackend::lastFrameRendered()
diff --git a/scene_xrender.cpp b/scene_xrender.cpp
index de01b125a6..a62e904219 100644
--- a/scene_xrender.cpp
+++ b/scene_xrender.cpp
@@ -349,7 +349,6 @@ void WaylandXRenderBackend::present(int mask, const QRegion &damage)
wl_surface_damage(surface, rect.x(), rect.y(), rect.width(), rect.height());
}
wl_surface_commit(surface);
- wl->dispatchEvents();
}
bool WaylandXRenderBackend::isLastFrameRendered() const
diff --git a/wayland_backend.cpp b/wayland_backend.cpp
index e19545947d..a89d532605 100644
--- a/wayland_backend.cpp
+++ b/wayland_backend.cpp
@@ -28,6 +28,8 @@ along with this program. If not, see .
#include "wayland_client/registry.h"
#include "wayland_client/shell.h"
// Qt
+#include
+#include
#include
#include
#include
@@ -571,6 +573,15 @@ WaylandBackend::WaylandBackend(QObject *parent)
, m_connectionThread(nullptr)
, m_fullscreenShell(new FullscreenShell(this))
{
+ QAbstractEventDispatcher *dispatcher = QCoreApplication::instance()->eventDispatcher();
+ connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, this,
+ [this]() {
+ if (!m_display) {
+ return;
+ }
+ wl_display_flush(m_display);
+ }
+ );
connect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady);
connect(m_registry, &Registry::compositorAnnounced, this,
[this](quint32 name) {
@@ -643,7 +654,6 @@ void WaylandBackend::initConnection()
m_registry->create(m_display);
wl_proxy_set_queue((wl_proxy*)m_registry->registry(), m_eventQueue);
m_registry->setup();
- wl_display_flush(m_display);
},
Qt::QueuedConnection);
connect(m_connectionThreadObject, &ConnectionThread::eventsRead, this,
@@ -757,12 +767,6 @@ void WaylandBackend::addOutput(wl_output *o)
connect(output, &Output::changed, this, &WaylandBackend::outputsChanged);
}
-void WaylandBackend::dispatchEvents()
-{
- // TODO: integrate into event loop to flush before going to block
- wl_display_flush(m_display);
-}
-
wl_registry *WaylandBackend::registry()
{
return m_registry->registry();
diff --git a/wayland_backend.h b/wayland_backend.h
index f9e9837565..e01d237864 100644
--- a/wayland_backend.h
+++ b/wayland_backend.h
@@ -190,8 +190,6 @@ public:
wl_surface *surface() const;
QSize shellSurfaceSize() const;
void installCursorImage(Qt::CursorShape shape);
-
- void dispatchEvents();
Q_SIGNALS:
void shellSurfaceSizeChanged(const QSize &size);
void systemCompositorDied();