summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2012-06-23 21:48:53 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-20 18:34:08 +0200
commit1603ba23656c8c31dc05fe9b3f1e12b22e29989a (patch)
tree5e507db7a34023b9236c982257923a2242c1693a /src/plugins
parent981ea7a1aa602cebfdd43b7dc6efd3abf5a1cba3 (diff)
Provide public API for native event filtering, moved up from QPA.
The previous API was hard to use (global function, no type safety, manual chaining), and confusing (app vs dispatcher split only made sense on Windows). Installing and removing out of order would have the risk of setting back a dangling pointer (crash). Meanwhile QPA added type safety, and this new API models the QObject::installEventFilter API for ease of use. The virtual method is in a new interface, QAbstractNativeEventFilter. QPA was even calling the dispatcher event filter with QPA-private event classes, which made no sense (refactoring leftover from when the code was in the dispatcher). Now the QPA plugins trigger the qcoreapp event filters with the actual native events directly. Change-Id: Ie35e47c59c862383bcaf857b28d54f7c72547882 Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/bearer/blackberry/qbbengine.cpp33
-rw-r--r--src/plugins/bearer/blackberry/qbbengine.h11
-rw-r--r--src/plugins/platforms/qnx/qqnxbpseventfilter.cpp22
-rw-r--r--src/plugins/platforms/qnx/qqnxbpseventfilter.h6
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp39
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.h3
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.cpp7
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.cpp16
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.h8
10 files changed, 26 insertions, 121 deletions
diff --git a/src/plugins/bearer/blackberry/qbbengine.cpp b/src/plugins/bearer/blackberry/qbbengine.cpp
index 7f8abd0e50..921d8f8040 100644
--- a/src/plugins/bearer/blackberry/qbbengine.cpp
+++ b/src/plugins/bearer/blackberry/qbbengine.cpp
@@ -122,7 +122,6 @@ QT_BEGIN_NAMESPACE
QBBEngine::QBBEngine(QObject *parent) :
QBearerEngineImpl(parent),
- previousEventFilter(0),
pollingRequired(false),
initialized(false)
{
@@ -130,7 +129,6 @@ QBBEngine::QBBEngine(QObject *parent) :
QBBEngine::~QBBEngine()
{
- QAbstractEventDispatcher::instance()->setEventFilter(previousEventFilter);
}
@@ -173,8 +171,7 @@ void QBBEngine::initialize()
const QMutexLocker locker(&pollingMutex);
pollingRequired = true;
} else {
- previousEventFilter =
- QAbstractEventDispatcher::instance()->setEventFilter(filterEvent);
+ QAbstractEventDispatcher::instance()->installEventFilter(this);
}
doRequestUpdate();
@@ -288,34 +285,23 @@ bool QBBEngine::requiresPolling() const
return pollingRequired;
}
-bool QBBEngine::filterEvent(void *message)
+bool QBBEngine::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
+ Q_UNUSED(eventType);
+ Q_UNUSED(result);
+
bps_event_t * const event = static_cast<bps_event_t *>(message);
Q_ASSERT(event);
- QBBEngine *self = instanceStorage()->localData()->instance;
-
- Q_ASSERT(self);
-
- if (bps_event_get_domain(event) == netstatus_get_domain())
- self->filterEvent(event);
-
- if (self->previousEventFilter)
- return self->previousEventFilter(message);
+ if (bps_event_get_domain(event) == netstatus_get_domain()) {
+ qBearerDebug() << Q_FUNC_INFO << "got update request.";
+ doRequestUpdate();
+ }
return false;
}
-void QBBEngine::filterEvent(bps_event_t *event)
-{
- Q_UNUSED(event);
-
- qBearerDebug() << Q_FUNC_INFO << "got update request.";
-
- doRequestUpdate();
-}
-
void QBBEngine::updateConfiguration(const char *interface)
{
netstatus_interface_details_t *details = 0;
@@ -421,4 +407,3 @@ void QBBEngine::removeConfiguration(const QString &id)
QT_END_NAMESPACE
#endif // QT_NO_BEARERMANAGEMENT
-
diff --git a/src/plugins/bearer/blackberry/qbbengine.h b/src/plugins/bearer/blackberry/qbbengine.h
index 1c9a5d4aa5..2ad0f1fc65 100644
--- a/src/plugins/bearer/blackberry/qbbengine.h
+++ b/src/plugins/bearer/blackberry/qbbengine.h
@@ -45,6 +45,7 @@
#include "../qbearerengine_impl.h"
#include <QAbstractEventDispatcher>
+#include <QAbstractNativeEventFilter>
#ifndef QT_NO_BEARERMANAGEMENT
@@ -55,7 +56,7 @@ QT_BEGIN_NAMESPACE
class QNetworkConfigurationPrivate;
class QNetworkSessionPrivate;
-class QBBEngine : public QBearerEngineImpl
+class QBBEngine : public QBearerEngineImpl, public QAbstractNativeEventFilter
{
Q_OBJECT
@@ -82,6 +83,8 @@ public:
bool requiresPolling() const Q_DECL_OVERRIDE;
+ bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
+
protected:
void updateConfiguration(const char *interface);
void removeConfiguration(const QString &id);
@@ -90,14 +93,8 @@ private Q_SLOTS:
void doRequestUpdate();
private:
- static bool filterEvent(void *message);
-
- void filterEvent(bps_event_t *event);
-
QHash<QString, QString> configurationInterface;
- QAbstractEventDispatcher::EventFilter previousEventFilter;
-
mutable QMutex pollingMutex;
bool pollingRequired;
diff --git a/src/plugins/platforms/qnx/qqnxbpseventfilter.cpp b/src/plugins/platforms/qnx/qqnxbpseventfilter.cpp
index 93bb2d3584..4ce38b9fdc 100644
--- a/src/plugins/platforms/qnx/qqnxbpseventfilter.cpp
+++ b/src/plugins/platforms/qnx/qqnxbpseventfilter.cpp
@@ -90,13 +90,7 @@ void QQnxBpsEventFilter::installOnEventDispatcher(QAbstractEventDispatcher *disp
if (navigator_request_events(0) != BPS_SUCCESS)
qWarning("QQNX: failed to register for navigator events");
- QAbstractEventDispatcher::EventFilter previousEventFilter = dispatcher->setEventFilter(dispatcherEventFilter);
-
- // the QPA plugin creates the event dispatcher so we are the first event
- // filter assert on that just in case somebody adds another event filter
- // in the QQnxIntegration constructor instead of adding a new section in here
- Q_ASSERT(previousEventFilter == 0);
- Q_UNUSED(previousEventFilter);
+ dispatcher->installNativeEventFilter(this);
}
void QQnxBpsEventFilter::registerForScreenEvents(QQnxScreen *screen)
@@ -137,19 +131,11 @@ void QQnxBpsEventFilter::unregisterForDialogEvents(QQnxFileDialogHelper *dialog)
qWarning("QQNX: attempting to unregister dialog that was not registered");
}
-bool QQnxBpsEventFilter::dispatcherEventFilter(void *message)
+bool QQnxBpsEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
- qBpsEventFilterDebug() << Q_FUNC_INFO;
-
- if (s_instance == 0)
- return false;
-
+ Q_UNUSED(eventType);
+ Q_UNUSED(result);
bps_event_t *event = static_cast<bps_event_t *>(message);
- return s_instance->bpsEventFilter(event);
-}
-
-bool QQnxBpsEventFilter::bpsEventFilter(bps_event_t *event)
-{
const int eventDomain = bps_event_get_domain(event);
qBpsEventFilterDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain;
diff --git a/src/plugins/platforms/qnx/qqnxbpseventfilter.h b/src/plugins/platforms/qnx/qqnxbpseventfilter.h
index aafca0f989..164cb0291b 100644
--- a/src/plugins/platforms/qnx/qqnxbpseventfilter.h
+++ b/src/plugins/platforms/qnx/qqnxbpseventfilter.h
@@ -44,6 +44,7 @@
#include <QObject>
#include <QHash>
+#include <QAbstractNativeEventFilter>
#include <bps/dialog.h>
@@ -58,7 +59,7 @@ class QQnxScreen;
class QQnxScreenEventHandler;
class QQnxVirtualKeyboardBps;
-class QQnxBpsEventFilter : public QObject
+class QQnxBpsEventFilter : public QObject, public QAbstractNativeEventFilter
{
Q_OBJECT
public:
@@ -76,8 +77,7 @@ public:
void unregisterForDialogEvents(QQnxFileDialogHelper *dialog);
private:
- static bool dispatcherEventFilter(void *message);
- bool bpsEventFilter(bps_event_t *event);
+ bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
bool handleNavigatorEvent(bps_event_t *event);
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 37493fe3db..b12975174f 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -240,13 +240,6 @@ QWindowsContext *QWindowsContext::m_instance = 0;
typedef QHash<HWND, QWindowsWindow *> HandleBaseWindowHash;
struct QWindowsContextPrivate {
- typedef QPlatformNativeInterface::EventFilter EventFilter;
-
- enum EventFilterType
- {
- GenericWindowsEventFilter,
- EventFilterTypeCount
- };
QWindowsContextPrivate();
@@ -262,7 +255,6 @@ struct QWindowsContextPrivate {
QSharedPointer<QWindowCreationContext> m_creationContext;
const HRESULT m_oleInitializeResult;
const QByteArray m_eventType;
- EventFilter m_eventFilters[EventFilterTypeCount];
QWindow *m_lastActiveWindow;
};
@@ -289,7 +281,6 @@ QWindowsContextPrivate::QWindowsContextPrivate() :
m_systemInfo |= QWindowsContext::SI_RTL_Extensions;
m_keyMapper.setUseRTLExtensions(true);
}
- qFill(m_eventFilters, m_eventFilters + EventFilterTypeCount, EventFilter(0));
}
QWindowsContext::QWindowsContext() :
@@ -695,27 +686,6 @@ QByteArray QWindowsContext::comErrorString(HRESULT hr)
}
/*!
- \brief Set event filter.
-
- \sa QWindowsNativeInterface
-*/
-
-QWindowsContext::EventFilter QWindowsContext::setEventFilter(const QByteArray &eventType, EventFilter filter)
-{
- int eventFilterType = -1;
- if (eventType == d->m_eventType)
- eventFilterType = QWindowsContextPrivate::GenericWindowsEventFilter;
- if (eventFilterType < 0) {
- qWarning("%s: Attempt to set unsupported event filter '%s'.",
- __FUNCTION__, eventType.constData());
- return 0;
- }
- const EventFilter previous = d->m_eventFilters[eventFilterType];
- d->m_eventFilters[eventFilterType] = filter;
- return previous;
-}
-
-/*!
\brief Main windows procedure registered for windows.
\sa QWindowsGuiEventDispatcher
@@ -736,11 +706,10 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
msg.pt.y = GET_Y_LPARAM(lParam);
long filterResult = 0;
- if (d->m_eventFilters[QWindowsContextPrivate::GenericWindowsEventFilter]) {
- if (d->m_eventFilters[QWindowsContextPrivate::GenericWindowsEventFilter](&msg, &filterResult)) {
- *result = LRESULT(filterResult);
- return true;
- }
+ QCoreApplication* coreApp = QCoreApplication::instance();
+ if (coreApp && coreApp->filterNativeEvent(d->m_eventType, &msg, &filterResult)) {
+ *result = LRESULT(filterResult);
+ return true;
}
// Events without an associated QWindow or events we are not interested in.
switch (et) {
diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h
index 0b18196abe..e4fde55464 100644
--- a/src/plugins/platforms/windows/qwindowscontext.h
+++ b/src/plugins/platforms/windows/qwindowscontext.h
@@ -107,7 +107,6 @@ class QWindowsContext
{
Q_DISABLE_COPY(QWindowsContext)
public:
- typedef bool (*EventFilter)(void *message, long *result);
enum SystemInfoFlags
{
@@ -143,8 +142,6 @@ public:
HDC displayContext() const;
int screenDepth() const;
- EventFilter setEventFilter(const QByteArray &eventType, EventFilter filter);
-
static QWindowsContext *instance();
static QString windowsErrorMessage(unsigned long errorCode);
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index 1ff142bc98..f32f8cd689 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -102,8 +102,6 @@ public:
#endif
virtual void *nativeResourceForWindow(const QByteArray &resource, QWindow *window);
virtual void *nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *bs);
- virtual EventFilter setEventFilter(const QByteArray &eventType, EventFilter filter)
- { return QWindowsContext::instance()->setEventFilter(eventType, filter); }
Q_INVOKABLE void *createMessageWindow(const QString &classNameTemplate,
const QString &windowName,
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index b808a74a83..7f197c8ad5 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -270,7 +270,6 @@ QXcbWindow *QXcbConnection::platformWindowFromId(xcb_window_t id)
{ \
event_t *e = (event_t *)event; \
if (QXcbWindow *platformWindow = platformWindowFromId(e->windowMember)) { \
- long result = 0; \
handled = QWindowSystemInterface::handleNativeEvent(platformWindow->window(), m_nativeInterface->genericEventFilterType(), event, &result); \
if (!handled) \
platformWindow->handler(e); \
@@ -282,7 +281,6 @@ break;
{ \
event_t *e = (event_t *)event; \
if (QXcbWindow *platformWindow = platformWindowFromId(e->event)) { \
- long result = 0; \
handled = QWindowSystemInterface::handleNativeEvent(platformWindow->window(), m_nativeInterface->genericEventFilterType(), event, &result); \
if (!handled) \
m_keyboard->handler(platformWindow, e); \
@@ -543,10 +541,9 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event)
m_callLog.remove(0, i);
}
#endif
- bool handled = false;
- if (QPlatformNativeInterface::EventFilter filter = m_nativeInterface->eventFilter(QXcbNativeInterface::GenericEventFilter))
- handled = filter(event, 0);
+ long result = 0;
+ bool handled = QCoreApplication::instance()->filterNativeEvent(m_nativeInterface->genericEventFilterType(), event, &result);
uint response_type = event->response_type & ~0x80;
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
index a6647da8be..2948ee6aae 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
@@ -80,7 +80,6 @@ QXcbNativeInterface::QXcbNativeInterface() :
m_genericEventFilterType(QByteArrayLiteral("xcb_generic_event_t"))
{
- qFill(m_eventFilters, m_eventFilters + EventFilterCount, EventFilter(0));
}
void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context)
@@ -142,21 +141,6 @@ QPlatformNativeInterface::NativeResourceForContextFunction QXcbNativeInterface::
return 0;
}
-QPlatformNativeInterface::EventFilter QXcbNativeInterface::setEventFilter(const QByteArray &eventType, QPlatformNativeInterface::EventFilter filter)
-{
- int type = -1;
- if (eventType == m_genericEventFilterType)
- type = GenericEventFilter;
- if (type == -1) {
- qWarning("QXcbNativeInterface: %s: Attempt to set invalid event filter type '%s'.",
- Q_FUNC_INFO, eventType.constData());
- return 0;
- }
- const EventFilter oldFilter = m_eventFilters[type];
- m_eventFilters[type] = filter;
- return oldFilter;
-}
-
QXcbScreen *QXcbNativeInterface::qPlatformScreenForWindow(QWindow *window)
{
QXcbScreen *screen;
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h
index 8221d9a36b..c91b4d7e88 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.h
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h
@@ -61,11 +61,6 @@ public:
EglContext
};
- enum EventFilterType {
- GenericEventFilter,
- EventFilterCount
- };
-
QXcbNativeInterface();
void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context);
@@ -74,8 +69,6 @@ public:
NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource);
inline const QByteArray &genericEventFilterType() const { return m_genericEventFilterType; }
- EventFilter setEventFilter(const QByteArray &eventType, EventFilter filter);
- EventFilter eventFilter(EventFilterType type) const { return m_eventFilters[type]; }
void *displayForWindow(QWindow *window);
void *eglDisplayForWindow(QWindow *window);
@@ -86,7 +79,6 @@ public:
private:
const QByteArray m_genericEventFilterType;
- EventFilter m_eventFilters[EventFilterCount];
static QXcbScreen *qPlatformScreenForWindow(QWindow *window);
};