Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #38 from giucam/mer-stable
[qtbase] Add a way to filter window system events. Contributes to MER#960
  • Loading branch information
giucam committed May 12, 2015
2 parents 4b71f8d + 9900fca commit 69e9a05
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/gui/kernel/qwindowsysteminterface.cpp
Expand Up @@ -56,6 +56,7 @@ QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
bool QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = false;
QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed;
QMutex QWindowSystemInterfacePrivate::flushEventMutex;
QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;

//------------------------------------------------------------
//
Expand Down Expand Up @@ -571,14 +572,32 @@ bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFla
QWindowSystemInterfacePrivate::getWindowSystemEvent();
if (!event)
break;
nevents++;
QGuiApplicationPrivate::processWindowSystemEvent(event);

if (QWindowSystemInterfacePrivate::eventHandler) {
if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
nevents++;
} else {
nevents++;
QGuiApplicationPrivate::processWindowSystemEvent(event);
}
delete event;
}

return (nevents > 0);
}

void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler)
{
if (!eventHandler)
eventHandler = handler;
}

void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
{
if (eventHandler == handler)
eventHandler = 0;
}

void QWindowSystemInterface::setSynchronousWindowsSystemEvents(bool enable)
{
QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = enable;
Expand Down Expand Up @@ -776,4 +795,15 @@ Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, QTouchDevice *device,
QWindowSystemInterface::handleTouchEvent(w, device, touchPointList(points), mods);
}

QWindowSystemEventHandler::~QWindowSystemEventHandler()
{
QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(this);
}

bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
{
QGuiApplicationPrivate::processWindowSystemEvent(e);
return true;
}

QT_END_NAMESPACE
13 changes: 13 additions & 0 deletions src/gui/kernel/qwindowsysteminterface_p.h
Expand Up @@ -62,6 +62,8 @@

QT_BEGIN_NAMESPACE

class QWindowSystemEventHandler;

class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
public:
enum EventType {
Expand Down Expand Up @@ -483,6 +485,17 @@ class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
static QMutex flushEventMutex;

static QList<QTouchEvent::TouchPoint> convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type);

static void installWindowSystemEventHandler(QWindowSystemEventHandler *handler);
static void removeWindowSystemEventhandler(QWindowSystemEventHandler *handler);
static QWindowSystemEventHandler *eventHandler;
};

class Q_GUI_EXPORT QWindowSystemEventHandler
{
public:
virtual ~QWindowSystemEventHandler();
virtual bool sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *event);
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 69e9a05

Please sign in to comment.