Refactor window system event dispatching.

Add QWindowSystemInterface::sendWindowSystemEvents,
which contains the canonical "empty and send queued
window system events" implementation.

Make the Cocoa, QPA, and GLIB dispatchers use the
new implementation. Cocoa now no longer inherits
from QPA.
bb10
Morten Sorvig 2011-06-23 09:05:34 +02:00
parent c359cf0017
commit 58d10c0bd7
6 changed files with 49 additions and 58 deletions

View File

@ -270,4 +270,37 @@ void QWindowSystemInterface::handleExposeEvent(QWindow *tlw, const QRegion &regi
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
bool QWindowSystemInterface::sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags)
{
int nevents = 0;
// handle gui and posted events
QCoreApplication::sendPostedEvents();
while (true) {
QWindowSystemInterfacePrivate::WindowSystemEvent *event;
if (!(flags & QEventLoop::ExcludeUserInputEvents)
&& QWindowSystemInterfacePrivate::windowSystemEventsQueued() > 0) {
// process a pending user input event
event = QWindowSystemInterfacePrivate::getWindowSystemEvent();
if (!event)
break;
} else {
break;
}
if (eventDispatcher->filterEvent(event)) {
delete event;
continue;
}
nevents++;
QGuiApplicationPrivate::processWindowSystemEvent(event);
delete event;
}
return (nevents > 0);
}
QT_END_NAMESPACE

View File

@ -44,10 +44,12 @@
#include <QtCore/QTime>
#include <QtGui/qwindowdefs.h>
#include <QtCore/QEvent>
#include <QtCore/QAbstractEventDispatcher>
#include <QtGui/QWindow>
#include <QtCore/QWeakPointer>
#include <QtCore/QMutex>
#include <QtGui/QTouchEvent>
#include <QtCore/QEventLoop>
QT_BEGIN_HEADER
@ -105,6 +107,9 @@ public:
static void handleScreenGeometryChange(int screenIndex);
static void handleScreenAvailableGeometryChange(int screenIndex);
static void handleScreenCountChange(int count);
// For event dispatcher implementations
static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags);
};
QT_END_NAMESPACE

View File

@ -74,26 +74,10 @@ static gboolean userEventSourceCheck(GSource *source)
static gboolean userEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
{
GUserEventSource * source = reinterpret_cast<GUserEventSource *>(s);
QWindowSystemInterfacePrivate::WindowSystemEvent * event;
while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
event = QWindowSystemInterfacePrivate::getWindowSystemEvent();
if (!event)
break;
// send through event filter
if (source->q->filterEvent(event)) {
delete event;
continue;
}
QGuiApplicationPrivate::processWindowSystemEvent(event);
delete event;
}
QWindowSystemInterface::sendWindowSystemEvents(source->q, flags);
return true;
}
static GSourceFuncs userEventSourceFuncs = {
userEventSourcePrepare,
userEventSourceCheck,

View File

@ -83,43 +83,14 @@ bool QEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags)
{
Q_D(QEventDispatcherQPA);
int nevents = 0;
bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(this, flags);
// handle gui and posted events
d->interrupt = false;
QCoreApplication::sendPostedEvents();
while (!d->interrupt) { // also flushes output buffer ###can be optimized
QWindowSystemInterfacePrivate::WindowSystemEvent *event;
if (!(flags & QEventLoop::ExcludeUserInputEvents)
&& QWindowSystemInterfacePrivate::windowSystemEventsQueued() > 0) {
// process a pending user input event
event = QWindowSystemInterfacePrivate::getWindowSystemEvent();
if (!event)
break;
} else {
break;
}
if (filterEvent(event)) {
delete event;
continue;
}
nevents++;
QGuiApplicationPrivate::processWindowSystemEvent(event);
delete event;
if (EVENTDISPATCHERBASE::processEvents(flags)) {
EVENTDISPATCHERBASE::processEvents(flags);
return true;
}
#ifdef Q_OS_MAC // (inverted inheritance on mac: QEventDispatcherMac calls QEventDispatcherQPA)
if (!d->interrupt) {
if (EVENTDISPATCHERBASE::processEvents(flags)) {
EVENTDISPATCHERBASE::processEvents(flags);
return true;
}
}
#endif
return (nevents > 0);
return didSendEvents;
}
bool QEventDispatcherQPA::hasPendingEvents()

View File

@ -90,7 +90,7 @@
#include <QtCore/qhash.h>
#include <QtCore/qstack.h>
#include <QtGui/qwindowdefs.h>
#include <QtPlatformSupport/private/qeventdispatcher_qpa_p.h>
#include <QtCore/private/qeventdispatcher_unix_p.h>
#include <CoreFoundation/CoreFoundation.h>
@ -115,7 +115,7 @@ public:
};
class QCocoaEventDispatcherPrivate;
class QCocoaEventDispatcher : public QEventDispatcherQPA
class QCocoaEventDispatcher : public QEventDispatcherUNIX
{
Q_OBJECT
Q_DECLARE_PRIVATE(QCocoaEventDispatcher)
@ -167,7 +167,7 @@ struct MacSocketInfo {
};
typedef QHash<int, MacSocketInfo *> MacSocketHash;
class QCocoaEventDispatcherPrivate : public QEventDispatcherQPAPrivate
class QCocoaEventDispatcherPrivate : public QEventDispatcherUNIXPrivate
{
Q_DECLARE_PUBLIC(QCocoaEventDispatcher)

View File

@ -910,7 +910,7 @@ QCocoaEventDispatcherPrivate::QCocoaEventDispatcherPrivate()
}
QCocoaEventDispatcher::QCocoaEventDispatcher(QObject *parent)
: QEventDispatcherQPA(*new QCocoaEventDispatcherPrivate, parent)
: QEventDispatcherUNIX(*new QCocoaEventDispatcherPrivate, parent)
{
Q_D(QCocoaEventDispatcher);
CFRunLoopSourceContext context;
@ -992,9 +992,7 @@ void processPostedEvents(QCocoaEventDispatcherPrivate *const d, const bool block
if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) {
d->lastSerial = d->serialNumber;
// Call down to the base class event handler, which will send
// the window system events.
d->q_func()->QEventDispatcherQPA::processEvents(QEventLoop::AllEvents);
QWindowSystemInterface::sendWindowSystemEvents(d->q_func(), QEventLoop::AllEvents);
}
}