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>
This commit is contained in:
parent
ccb059b0e2
commit
e309e7a3e8
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user