diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2018-07-28 14:40:12 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-08-16 04:42:55 +0000 |
commit | b7dcc3455f1270cef3b21699e909ef502374db97 (patch) | |
tree | 1a81cb096d9a2d8b2ab34c55f6405dd578a39525 /src/plugins/platforms/xcb/qxcbconnection.h | |
parent | c5bde010eabb79b10cea630d366d94ff5981fa57 (diff) |
xcb: Use functors in QXcbConnection::checkEvent()
... to check for buffered events. This makes the code less verbose and
easier to read. Changed the filter signature to pass an event type in addition
to the actual event, for the convenience of API user. And do not pass worthless
nullptr-s to the filter.
The only reason why KeyChecker from qxcbkeyboard.cpp was not converted
to lambda expression is that the code looks suspicious - KeyChecker::m_release
default value is 'true' and I don't see where it would ever be assigned
'false' (ref. QTBUG-69679) and the code is known to be buggy (ref. QTBUG-57335).
Those issues are out-of-scope for this patch.
Change-Id: If2fdd60fbb93eb983f3c9ad616aaf04834fede9f
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbconnection.h')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 0b31e9c3e7..24719a6c31 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -440,8 +440,8 @@ public: QXcbWindowEventListener *windowEventListenerFromId(xcb_window_t id); QXcbWindow *platformWindowFromId(xcb_window_t id); - template<typename T> - inline xcb_generic_event_t *checkEvent(T &checker); + template<typename Functor> + inline xcb_generic_event_t *checkEvent(Functor &&filter); typedef bool (*PeekFunc)(QXcbConnection *, xcb_generic_event_t *); void addPeekFunc(PeekFunc f); @@ -734,21 +734,21 @@ Q_DECLARE_TYPEINFO(QXcbConnection::TabletData, Q_MOVABLE_TYPE); #endif #endif -template<typename T> -xcb_generic_event_t *QXcbConnection::checkEvent(T &checker) +template<typename Functor> +xcb_generic_event_t *QXcbConnection::checkEvent(Functor &&filter) { QXcbEventArray *eventqueue = m_reader->lock(); for (int i = 0; i < eventqueue->size(); ++i) { xcb_generic_event_t *event = eventqueue->at(i); - if (checker.checkEvent(event)) { - (*eventqueue)[i] = 0; + if (event && filter(event, event->response_type & ~0x80)) { + (*eventqueue)[i] = nullptr; m_reader->unlock(); return event; } } m_reader->unlock(); - return 0; + return nullptr; } class QXcbConnectionGrabber |