Connect flushRequest after forceRoundTrip

If flushRequest is connected with aboutToBlock, the flushRequest
may consumes all events so that processEvents might be blocked in forceRoundTrip.

Change-Id: I12b2c506e8442bf0e75f6ab6e418d3e1eea6d68c
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Elvis Lee 2021-03-17 16:31:10 +09:00 committed by Eskil Abrahamsen Blomfeldt
parent bffa397f68
commit 0ccd3105ff

View File

@ -208,17 +208,20 @@ void QWaylandIntegration::initializePlatform()
void QWaylandIntegration::initialize()
{
QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher;
QObject::connect(dispatcher, SIGNAL(aboutToBlock()), mDisplay.data(), SLOT(flushRequests()));
QObject::connect(dispatcher, SIGNAL(awake()), mDisplay.data(), SLOT(flushRequests()));
int fd = wl_display_get_fd(mDisplay->wl_display());
QSocketNotifier *sn = new QSocketNotifier(fd, QSocketNotifier::Read, mDisplay.data());
QObject::connect(sn, SIGNAL(activated(QSocketDescriptor)), mDisplay.data(), SLOT(flushRequests()));
// Call after eventDispatcher is fully connected, for QWaylandDisplay::forceRoundTrip()
// Call this after eventDispatcher is connected with QSocketNotifier for QWaylandDisplay::forceRoundTrip()
initializePlatform();
// But the aboutToBlock() and awake() should be connected after initializePlatform().
// Otherwise the connected flushRequests() may consumes up all events before processEvents starts to wait,
// so that processEvents(QEventLoop::WaitForMoreEvents) may be blocked in the forceRoundTrip().
QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher;
QObject::connect(dispatcher, SIGNAL(aboutToBlock()), mDisplay.data(), SLOT(flushRequests()));
QObject::connect(dispatcher, SIGNAL(awake()), mDisplay.data(), SLOT(flushRequests()));
// Qt does not support running with no screens
mDisplay->ensureScreen();
}