summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-09-16 12:52:46 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-16 15:22:40 +0200
commit4bae7158d379acb15a4eae02a4fc3d3e6103a7f9 (patch)
tree5329c28c59f104015d1b4b465a1634c59267cd3f
parent4c19055cb1b077cf161d9cd5c031d711f42a3f25 (diff)
Don't send posted events from QWindowSystemInterface::sendWindowSystemEvents
The responsibility of sendWindowSystemEvents() is to process events from the window system. Historially that logic was part of the QPA/QWS event dispatcher, which naturally also sent posted events. Through refactoring, the code at some point ended up in in the QWindowSystemInterface class, still with the posting of events in place. This resulted in QPA event dispatchers adopting a pattern of just calling sendWindowSystemEvents(), as that would cover both posted and window system events. Other event dispatchers would call sendWindowSystemEvents(), and then use a base-class implementation from QtCore for processing events, resulting in two calls to QCoreApplication::sendPostedEvents() per iteration of processEvents(). This breaks the contract that processEvents will only process posted events that has been queued up until then. We fix this entanglement by removing the sendPostedEvents() call from QWindowSystemInterface::sendWindowSystemEvents() and move it to the respective event dispatchers. For some EDs it means an explicit call to sendPostedEvents, while others were already doing sendPostedEvents though a separate source (GLib), or using a base-class (UNIX/BB), and did not need an extra call. We still keep the ordering of the original sendWindowSystemEvents() function of first sending posted events, and then processing any window system events. Task-number: QTBUG-33485 Change-Id: I8b069e76cea1f37875e72a034c11d09bf3fe166a Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp18
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h3
-rw-r--r--src/platformsupport/eventdispatchers/qeventdispatcher_cf.mm4
-rw-r--r--src/platformsupport/eventdispatchers/qunixeventdispatcher.cpp9
-rw-r--r--src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm1
-rw-r--r--src/plugins/platforms/offscreen/qoffscreenintegration.cpp4
-rw-r--r--src/plugins/platforms/qnx/qqnxeventdispatcher_blackberry.cpp8
-rw-r--r--src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp2
-rw-r--r--tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp45
9 files changed, 64 insertions, 30 deletions
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 7b57313645..d62330083e 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -553,23 +553,12 @@ void QWindowSystemInterface::flushWindowSystemEvents()
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
} else {
- sendWindowSystemEventsImplementation(QEventLoop::AllEvents);
+ sendWindowSystemEvents(QEventLoop::AllEvents);
}
}
bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
{
- QCoreApplication::sendPostedEvents(); // handle gui and posted events
- return sendWindowSystemEventsImplementation(flags);
-}
-
-void QWindowSystemInterface::setSynchronousWindowsSystemEvents(bool enable)
-{
- QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = enable;
-}
-
-bool QWindowSystemInterface::sendWindowSystemEventsImplementation(QEventLoop::ProcessEventsFlags flags)
-{
int nevents = 0;
while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
@@ -587,6 +576,11 @@ bool QWindowSystemInterface::sendWindowSystemEventsImplementation(QEventLoop::Pr
return (nevents > 0);
}
+void QWindowSystemInterface::setSynchronousWindowsSystemEvents(bool enable)
+{
+ QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = enable;
+}
+
int QWindowSystemInterface::windowSystemEventsQueued()
{
return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index cac943cda1..c8e464f985 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -193,9 +193,6 @@ public:
static void flushWindowSystemEvents();
static void deferredFlushWindowSystemEvents();
static int windowSystemEventsQueued();
-
-private:
- static bool sendWindowSystemEventsImplementation(QEventLoop::ProcessEventsFlags flags);
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_cf.mm b/src/platformsupport/eventdispatchers/qeventdispatcher_cf.mm
index 6442df715a..ed86a33782 100644
--- a/src/platformsupport/eventdispatchers/qeventdispatcher_cf.mm
+++ b/src/platformsupport/eventdispatchers/qeventdispatcher_cf.mm
@@ -388,6 +388,10 @@ void QEventDispatcherCoreFoundation::processPostedEvents()
m_processEvents.processedPostedEvents = true;
+ qEventDispatcherDebug() << "Sending posted events for " << m_processEvents.flags; qIndent();
+ QCoreApplication::sendPostedEvents();
+ qUnIndent();
+
qEventDispatcherDebug() << "Sending window system events for " << m_processEvents.flags; qIndent();
QWindowSystemInterface::sendWindowSystemEvents(m_processEvents.flags);
qUnIndent();
diff --git a/src/platformsupport/eventdispatchers/qunixeventdispatcher.cpp b/src/platformsupport/eventdispatchers/qunixeventdispatcher.cpp
index 20ef91c7d8..5e07832c07 100644
--- a/src/platformsupport/eventdispatchers/qunixeventdispatcher.cpp
+++ b/src/platformsupport/eventdispatchers/qunixeventdispatcher.cpp
@@ -67,13 +67,8 @@ QUnixEventDispatcherQPA::~QUnixEventDispatcherQPA()
bool QUnixEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags)
{
- const bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(flags);
-
- if (QEventDispatcherUNIX::processEvents(flags)) {
- return true;
- }
-
- return didSendEvents;
+ const bool didSendEvents = QEventDispatcherUNIX::processEvents(flags);
+ return QWindowSystemInterface::sendWindowSystemEvents(flags) || didSendEvents;
}
bool QUnixEventDispatcherQPA::hasPendingEvents()
diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
index 9a661ffe5a..8dfaacdf13 100644
--- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
+++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
@@ -876,6 +876,7 @@ void QCocoaEventDispatcherPrivate::processPostedEvents()
int serial = serialNumber.load();
if (!threadData->canWait || (serial != lastSerial)) {
lastSerial = serial;
+ QCoreApplication::sendPostedEvents();
QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
}
}
diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
index 5b74ad3b8d..bce52963df 100644
--- a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
+++ b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
@@ -73,9 +73,9 @@ public:
bool processEvents(QEventLoop::ProcessEventsFlags flags)
{
- bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(flags);
+ bool didSendEvents = BaseEventDispatcher::processEvents(flags);
- return BaseEventDispatcher::processEvents(flags) || didSendEvents;
+ return QWindowSystemInterface::sendWindowSystemEvents(flags) || didSendEvents;
}
bool hasPendingEvents()
diff --git a/src/plugins/platforms/qnx/qqnxeventdispatcher_blackberry.cpp b/src/plugins/platforms/qnx/qqnxeventdispatcher_blackberry.cpp
index 87ce64da5e..42fd0ed8bf 100644
--- a/src/plugins/platforms/qnx/qqnxeventdispatcher_blackberry.cpp
+++ b/src/plugins/platforms/qnx/qqnxeventdispatcher_blackberry.cpp
@@ -58,12 +58,8 @@ QQnxEventDispatcherBlackberry::~QQnxEventDispatcherBlackberry()
bool QQnxEventDispatcherBlackberry::processEvents(QEventLoop::ProcessEventsFlags flags)
{
- const bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(flags);
-
- if (QEventDispatcherBlackberry::processEvents(flags))
- return true;
-
- return didSendEvents;
+ const bool didSendEvents = QEventDispatcherBlackberry::processEvents(flags);
+ return QWindowSystemInterface::sendWindowSystemEvents(flags) || didSendEvents;
}
bool QQnxEventDispatcherBlackberry::hasPendingEvents()
diff --git a/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp b/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp
index 0d7de2da39..6be71999f6 100644
--- a/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp
+++ b/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp
@@ -44,6 +44,7 @@
#include <qpa/qwindowsysteminterface.h>
+#include <QtCore/QCoreApplication>
#include <QtCore/QStack>
#include <QtCore/QDebug>
@@ -83,6 +84,7 @@ bool QWindowsGuiEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags fl
void QWindowsGuiEventDispatcher::sendPostedEvents()
{
+ QCoreApplication::sendPostedEvents();
QWindowSystemInterface::sendWindowSystemEvents(m_flags);
}
diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
index 93cf799982..8ca785836a 100644
--- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
+++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
@@ -78,6 +78,7 @@ private slots:
/* void registerEventNotifiier(); */ // Not implemented here, see tst_QWinEventNotifier instead
void sendPostedEvents_data();
void sendPostedEvents();
+ void processEventsOnlySendsQueuedEvents();
};
bool tst_QEventDispatcher::event(QEvent *e)
@@ -207,5 +208,49 @@ void tst_QEventDispatcher::sendPostedEvents()
}
}
+class ProcessEventsOnlySendsQueuedEvents : public QObject
+{
+ Q_OBJECT
+public:
+ int eventsReceived;
+
+ inline ProcessEventsOnlySendsQueuedEvents() : eventsReceived(0) {}
+
+ bool event(QEvent *event)
+ {
+ ++eventsReceived;
+
+ if (event->type() == QEvent::User)
+ QCoreApplication::postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1)));
+
+ return QObject::event(event);
+ }
+public slots:
+ void timerFired()
+ {
+ QCoreApplication::postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1)));
+ }
+};
+
+void tst_QEventDispatcher::processEventsOnlySendsQueuedEvents()
+{
+ ProcessEventsOnlySendsQueuedEvents object;
+
+ // Posted events during event processing should be handled on
+ // the next processEvents iteration.
+ QCoreApplication::postEvent(&object, new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+ QCOMPARE(object.eventsReceived, 1);
+ QCoreApplication::processEvents();
+ QCOMPARE(object.eventsReceived, 2);
+
+ // The same goes for posted events during timer processing
+ QTimer::singleShot(0, &object, SLOT(timerFired()));
+ QCoreApplication::processEvents();
+ QCOMPARE(object.eventsReceived, 3);
+ QCoreApplication::processEvents();
+ QCOMPARE(object.eventsReceived, 4);
+}
+
QTEST_MAIN(tst_QEventDispatcher)
#include "tst_qeventdispatcher.moc"