summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-01-22 21:05:06 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-23 11:02:18 +0100
commite309e7a3e8227647f64b8c1e5eb3fa893c4a4b61 (patch)
tree13740827e890181ca5f10e898790567c8c43574a
parentccb059b0e20ee9c6a073b712b712105c534deae4 (diff)
XCB: Introduce enumeration for event filter types.
Remove QByteArray-construction and hash lookup in the event handling; use an enumeration indexing an array instead. Change-Id: I4d272b32a5ff71c8da58197cf3a0b38c1e61d489 Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.cpp22
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.h11
3 files changed, 25 insertions, 10 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index c77eae284b..3af6b5ad10 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -498,7 +498,7 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event)
#endif
bool handled = false;
- if (QPlatformNativeInterface::EventFilter filter = m_nativeInterface->eventFilterForEventType(QByteArrayLiteral("xcb_generic_event_t")))
+ if (QPlatformNativeInterface::EventFilter filter = m_nativeInterface->eventFilter(QXcbNativeInterface::GenericEventFilter))
handled = filter(event, 0);
uint response_type = event->response_type & ~0x80;
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
index bb95584bbf..556d173959 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
@@ -76,6 +76,11 @@ public:
Q_GLOBAL_STATIC(QXcbResourceMap, qXcbResourceMap)
+QXcbNativeInterface::QXcbNativeInterface()
+{
+ qFill(m_eventFilters, m_eventFilters + EventFilterCount, EventFilter(0));
+}
+
void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context)
{
QByteArray lowerCaseResource = resourceString.toLower();
@@ -120,16 +125,19 @@ void *QXcbNativeInterface::nativeResourceForWindow(const QByteArray &resourceStr
QPlatformNativeInterface::EventFilter QXcbNativeInterface::setEventFilter(const QByteArray &eventType, QPlatformNativeInterface::EventFilter filter)
{
- EventFilter oldFilter = m_eventFilters.value(eventType);
- m_eventFilters.insert(eventType, filter);
+ int type = -1;
+ if (eventType == QByteArrayLiteral("xcb_generic_event_t"))
+ type = GenericEventFilter;
+ if (type == -1) {
+ qWarning("%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;
}
-QPlatformNativeInterface::EventFilter QXcbNativeInterface::eventFilterForEventType(const QByteArray& eventType) const
-{
- return m_eventFilters.value(eventType);
-}
-
QXcbScreen *QXcbNativeInterface::qPlatformScreenForWindow(QWindow *window)
{
QXcbScreen *screen;
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h
index 1bb83fd031..521528670b 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.h
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h
@@ -61,11 +61,18 @@ public:
EglContext
};
+ enum EventFilterType {
+ GenericEventFilter,
+ EventFilterCount
+ };
+
+ QXcbNativeInterface();
+
void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context);
void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window);
EventFilter setEventFilter(const QByteArray &eventType, EventFilter filter);
- EventFilter eventFilterForEventType(const QByteArray& eventType) const;
+ EventFilter eventFilter(EventFilterType type) const { return m_eventFilters[type]; }
void *displayForWindow(QWindow *window);
void *eglDisplayForWindow(QWindow *window);
@@ -76,7 +83,7 @@ public:
void *eglContextForContext(QOpenGLContext *context);
private:
- QHash<QByteArray, EventFilter> m_eventFilters;
+ EventFilter m_eventFilters[EventFilterCount];
static QXcbScreen *qPlatformScreenForWindow(QWindow *window);
};