Add a way to filter window system events
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>
This commit is contained in:
parent
5891f90846
commit
1f03520a20
@ -48,6 +48,7 @@ QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
|
||||
bool QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = false;
|
||||
QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed;
|
||||
QMutex QWindowSystemInterfacePrivate::flushEventMutex;
|
||||
QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;
|
||||
|
||||
//------------------------------------------------------------
|
||||
//
|
||||
@ -605,14 +606,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::setSynchronousWindowSystemEvents(bool enable)
|
||||
{
|
||||
QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
|
||||
@ -836,4 +855,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
|
||||
|
@ -54,6 +54,8 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowSystemEventHandler;
|
||||
|
||||
class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
|
||||
public:
|
||||
enum EventType {
|
||||
@ -487,6 +489,17 @@ public:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user