From c5006a6fe23195a977bfd84c61d715e0b19850a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Samuel=20R=C3=B8dal?= Date: Fri, 7 Oct 2011 20:21:41 +0200 Subject: [PATCH] Fixed potential issue in XCB plugin. Use the actual atom instead of the enum value of the atom when signaling that the event loop should exit. Change-Id: Ib98c6a46cadcecc727b28411b4c0c12c434ea828 Reviewed-on: http://codereview.qt-project.org/6265 Sanity-Review: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/plugins/platforms/xcb/qxcbconnection.cpp | 14 +++++++------- src/plugins/platforms/xcb/qxcbconnection.h | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index e90d74c..3d1a145 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -117,7 +117,7 @@ QXcbConnection::QXcbConnection(const char *displayName) if (m_connection) qDebug("Successfully connected to display %s", m_displayName.constData()); - m_reader = new QXcbEventReader(m_connection); + m_reader = new QXcbEventReader(this); #ifdef XCB_POLL_FOR_QUEUED_EVENT connect(m_reader, SIGNAL(eventPending()), this, SLOT(processXcbEvents()), Qt::QueuedConnection); m_reader->start(); @@ -559,10 +559,10 @@ void QXcbConnection::addPeekFunc(PeekFunc f) void QXcbEventReader::run() { xcb_generic_event_t *event; - while (m_connection && (event = xcb_wait_for_event(m_connection))) { + while (m_connection && (event = xcb_wait_for_event(m_connection->xcb_connection()))) { m_mutex.lock(); addEvent(event); - while (m_connection && (event = xcb_poll_for_queued_event(m_connection))) + while (m_connection && (event = xcb_poll_for_queued_event(m_connection->xcb_connection()))) addEvent(event); m_mutex.unlock(); emit eventPending(); @@ -576,7 +576,7 @@ void QXcbEventReader::run() void QXcbEventReader::addEvent(xcb_generic_event_t *event) { if ((event->response_type & ~0x80) == XCB_CLIENT_MESSAGE - && ((xcb_client_message_event_t *)event)->type == QXcbAtom::_QT_CLOSE_CONNECTION) + && ((xcb_client_message_event_t *)event)->type == m_connection->atom(QXcbAtom::_QT_CLOSE_CONNECTION)) m_connection = 0; m_events << event; } @@ -585,7 +585,7 @@ QList *QXcbEventReader::lock() { m_mutex.lock(); #ifndef XCB_POLL_FOR_QUEUED_EVENT - while (xcb_generic_event_t *event = xcb_poll_for_event(m_connection)) + while (xcb_generic_event_t *event = xcb_poll_for_event(m_connection->xcb_connection())) m_events << event; #endif return &m_events; @@ -596,7 +596,7 @@ void QXcbEventReader::unlock() m_mutex.unlock(); } -void QXcbConnection::sendConnectionEvent(QXcbAtom::Atom atom, uint id) +void QXcbConnection::sendConnectionEvent(QXcbAtom::Atom a, uint id) { xcb_client_message_event_t event; memset(&event, 0, sizeof(event)); @@ -605,7 +605,7 @@ void QXcbConnection::sendConnectionEvent(QXcbAtom::Atom atom, uint id) event.format = 32; event.sequence = 0; event.window = m_connectionEventListener; - event.type = atom; + event.type = atom(a); event.data.data32[0] = id; Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_connectionEventListener, XCB_EVENT_MASK_NO_EVENT, (const char *)&event)); diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index eb95326..769b2e7 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -229,11 +229,12 @@ namespace QXcbAtom { }; } +class QXcbConnection; class QXcbEventReader : public QThread { Q_OBJECT public: - QXcbEventReader(xcb_connection_t *connection) + QXcbEventReader(QXcbConnection *connection) : m_connection(connection) { } @@ -253,7 +254,7 @@ private: QMutex m_mutex; QList m_events; - xcb_connection_t *m_connection; + QXcbConnection *m_connection; }; class QAbstractEventDispatcher; -- 2.7.4