Skip to content

Commit

Permalink
Add a way to filter window system events
Browse files Browse the repository at this point in the history
This change introduces the class QWindowSystemEventHandler
which can be used to hook into QWindowSystemInterfacePrivate to
filter and dispatch window system events.
One use case is to intercept key events from the underlying system
in QtCompositor and feed them into the xkbcommon state, and to modify
the events based on the resulting state.

Change-Id: I829eb7d960420135990fb0f6db54c14eea3e8e48
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
  • Loading branch information
giucam committed May 12, 2015
1 parent 4b71f8d commit 9900fca
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 9900fca

Please sign in to comment.