diff options
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbconnection.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 134 |
1 files changed, 73 insertions, 61 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index c533a2a5f5..05107932f9 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -162,9 +168,9 @@ static int ioErrorHandler(Display *dpy) } #endif -QXcbScreen* QXcbConnection::findScreenForCrtc(xcb_window_t rootWindow, xcb_randr_crtc_t crtc) +QXcbScreen* QXcbConnection::findScreenForCrtc(xcb_window_t rootWindow, xcb_randr_crtc_t crtc) const { - foreach (QXcbScreen *screen, m_screens) { + for (QXcbScreen *screen : m_screens) { if (screen->root() == rootWindow && screen->crtc() == crtc) return screen; } @@ -172,9 +178,9 @@ QXcbScreen* QXcbConnection::findScreenForCrtc(xcb_window_t rootWindow, xcb_randr return 0; } -QXcbScreen* QXcbConnection::findScreenForOutput(xcb_window_t rootWindow, xcb_randr_output_t output) +QXcbScreen* QXcbConnection::findScreenForOutput(xcb_window_t rootWindow, xcb_randr_output_t output) const { - foreach (QXcbScreen *screen, m_screens) { + for (QXcbScreen *screen : m_screens) { if (screen->root() == rootWindow && screen->output() == output) return screen; } @@ -182,9 +188,9 @@ QXcbScreen* QXcbConnection::findScreenForOutput(xcb_window_t rootWindow, xcb_ran return 0; } -QXcbVirtualDesktop* QXcbConnection::virtualDesktopForRootWindow(xcb_window_t rootWindow) +QXcbVirtualDesktop* QXcbConnection::virtualDesktopForRootWindow(xcb_window_t rootWindow) const { - foreach (QXcbVirtualDesktop *virtualDesktop, m_virtualDesktops) { + for (QXcbVirtualDesktop *virtualDesktop : m_virtualDesktops) { if (virtualDesktop->screen()->root == rootWindow) return virtualDesktop; } @@ -241,7 +247,8 @@ void QXcbConnection::updateScreens(const xcb_randr_notify_event_t *event) xcb_randr_get_output_info_reply(xcb_connection(), outputInfoCookie, NULL)); // Find a fake screen - foreach (QPlatformScreen *scr, virtualDesktop->screens()) { + const auto scrs = virtualDesktop->screens(); + for (QPlatformScreen *scr : scrs) { QXcbScreen *xcbScreen = (QXcbScreen *)scr; if (xcbScreen->output() == XCB_NONE) { screen = xcbScreen; @@ -284,7 +291,7 @@ void QXcbConnection::updateScreens(const xcb_randr_notify_event_t *event) } } - qCDebug(lcQpaScreen) << "primary output is" << m_screens.first()->name(); + qCDebug(lcQpaScreen) << "primary output is" << qAsConst(m_screens).first()->name(); } } @@ -319,7 +326,7 @@ void QXcbConnection::updateScreen(QXcbScreen *screen, const xcb_randr_output_cha // If the screen became primary, reshuffle the order in QGuiApplicationPrivate const int idx = m_screens.indexOf(screen); if (idx > 0) { - m_screens.first()->setPrimary(false); + qAsConst(m_screens).first()->setPrimary(false); m_screens.swap(0, idx); } screen->virtualDesktop()->setPrimaryScreen(screen); @@ -339,7 +346,7 @@ QXcbScreen *QXcbConnection::createScreen(QXcbVirtualDesktop *virtualDesktop, if (screen->isPrimary()) { if (!m_screens.isEmpty()) - m_screens.first()->setPrimary(false); + qAsConst(m_screens).first()->setPrimary(false); m_screens.prepend(screen); } else { @@ -518,7 +525,7 @@ void QXcbConnection::initializeScreens() ++xcbScreenNumber; } // for each xcb screen - foreach (QXcbVirtualDesktop *virtualDesktop, m_virtualDesktops) + for (QXcbVirtualDesktop *virtualDesktop : qAsConst(m_virtualDesktops)) virtualDesktop->subscribeToXFixesSelectionNotify(); if (m_virtualDesktops.isEmpty()) { @@ -526,19 +533,19 @@ void QXcbConnection::initializeScreens() } else { // Ensure the primary screen is first on the list if (primaryScreen) { - if (m_screens.first() != primaryScreen) { + if (qAsConst(m_screens).first() != primaryScreen) { m_screens.removeOne(primaryScreen); m_screens.prepend(primaryScreen); } } // Push the screens to QGuiApplication - foreach (QXcbScreen *screen, m_screens) { + for (QXcbScreen *screen : qAsConst(m_screens)) { qCDebug(lcQpaScreen) << "adding" << screen << "(Primary:" << screen->isPrimary() << ")"; QXcbIntegration::instance()->screenAdded(screen, screen->isPrimary()); } - qCDebug(lcQpaScreen) << "primary output is" << m_screens.first()->name(); + qCDebug(lcQpaScreen) << "primary output is" << qAsConst(m_screens).first()->name(); } } @@ -584,7 +591,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreenNumber); #endif //XCB_USE_XLIB - if (!m_connection || xcb_connection_has_error(m_connection)) + if (Q_UNLIKELY(!m_connection || xcb_connection_has_error(m_connection))) qFatal("QXcbConnection: Could not connect to display %s", m_displayName.constData()); @@ -645,7 +652,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra glIntegrationNames << QStringLiteral("xcb_glx") << QStringLiteral("xcb_egl"); QString glIntegrationName = QString::fromLocal8Bit(qgetenv("QT_XCB_GL_INTEGRATION")); if (!glIntegrationName.isEmpty()) { - qCDebug(QT_XCB_GLINTEGRATION) << "QT_XCB_GL_INTEGRATION is set to" << glIntegrationName; + qCDebug(lcQpaGl) << "QT_XCB_GL_INTEGRATION is set to" << glIntegrationName; if (glIntegrationName != QLatin1String("none")) { glIntegrationNames.removeAll(glIntegrationName); glIntegrationNames.prepend(glIntegrationName); @@ -654,17 +661,19 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra } } - qCDebug(QT_XCB_GLINTEGRATION) << "Choosing xcb gl-integration based on following priority\n" << glIntegrationNames; - for (int i = 0; i < glIntegrationNames.size() && !m_glIntegration; i++) { - m_glIntegration = QXcbGlIntegrationFactory::create(glIntegrationNames.at(i)); - if (m_glIntegration && !m_glIntegration->initialize(this)) { - qCDebug(QT_XCB_GLINTEGRATION) << "Failed to initialize xcb gl-integration" << glIntegrationNames.at(i); - delete m_glIntegration; - m_glIntegration = Q_NULLPTR; + if (!glIntegrationNames.isEmpty()) { + qCDebug(lcQpaGl) << "Choosing xcb gl-integration based on following priority\n" << glIntegrationNames; + for (int i = 0; i < glIntegrationNames.size() && !m_glIntegration; i++) { + m_glIntegration = QXcbGlIntegrationFactory::create(glIntegrationNames.at(i)); + if (m_glIntegration && !m_glIntegration->initialize(this)) { + qCDebug(lcQpaGl) << "Failed to initialize xcb gl-integration" << glIntegrationNames.at(i); + delete m_glIntegration; + m_glIntegration = Q_NULLPTR; + } } + if (!m_glIntegration) + qCDebug(lcQpaGl) << "Failed to create xcb gl-integration"; } - if (!m_glIntegration) - qCDebug(QT_XCB_GLINTEGRATION) << "Failed to create xcb gl-integration"; sync(); } @@ -997,17 +1006,20 @@ void QXcbConnection::handleXcbError(xcb_generic_error_t *error) int i = 0; for (; i < m_callLog.size(); ++i) { if (m_callLog.at(i).sequence == error->sequence) { - qDebug("Caused by: %s:%d", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line); + qDebug("Caused by: %s:%d", m_callLog.at(i).file.constData(), m_callLog.at(i).line); break; } else if (m_callLog.at(i).sequence > error->sequence) { - qDebug("Caused some time before: %s:%d", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line); + qDebug("Caused some time before: %s:%d", m_callLog.at(i).file.constData(), + m_callLog.at(i).line); if (i > 0) - qDebug("and after: %s:%d", qPrintable(m_callLog.at(i-1).file), m_callLog.at(i-1).line); + qDebug("and after: %s:%d", m_callLog.at(i-1).file.constData(), + m_callLog.at(i-1).line); break; } } if (i == m_callLog.size() && !m_callLog.isEmpty()) - qDebug("Caused some time after: %s:%d", qPrintable(m_callLog.first().file), m_callLog.first().line); + qDebug("Caused some time after: %s:%d", qAsConst(m_callLog).first().file.constData(), + qAsConst(m_callLog).first().line); #endif } @@ -1230,7 +1242,7 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event) #ifndef QT_NO_CLIPBOARD m_clipboard->handleXFixesSelectionRequest(notify_event); #endif - foreach (QXcbVirtualDesktop *virtualDesktop, m_virtualDesktops) + for (QXcbVirtualDesktop *virtualDesktop : qAsConst(m_virtualDesktops)) virtualDesktop->handleXFixesSelectionNotify(notify_event); handled = true; @@ -1239,7 +1251,7 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event) handled = true; } else if (has_randr_extension && response_type == xrandr_first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { xcb_randr_screen_change_notify_event_t *change_event = (xcb_randr_screen_change_notify_event_t *)event; - foreach (QXcbScreen *s, m_screens) { + for (QXcbScreen *s : qAsConst(m_screens)) { if (s->root() == change_event->root ) s->handleScreenChange(change_event); } @@ -1707,7 +1719,8 @@ void QXcbConnection::processXcbEvents() continue; } - if (compressEvent(event, i, eventqueue)) + if (Q_LIKELY(QCoreApplication::testAttribute(Qt::AA_CompressHighFrequencyEvents)) && + compressEvent(event, i, eventqueue)) continue; bool accepted = false; @@ -1716,15 +1729,14 @@ void QXcbConnection::processXcbEvents() if (accepted) continue; - QVector<PeekFunc>::iterator it = m_peekFuncs.begin(); - while (it != m_peekFuncs.end()) { + auto isWaitingFor = [=](PeekFunc peekFunc) { // These callbacks return true if the event is what they were // waiting for, remove them from the list in that case. - if ((*it)(this, event)) - it = m_peekFuncs.erase(it); - else - ++it; - } + return peekFunc(this, event); + }; + m_peekFuncs.erase(std::remove_if(m_peekFuncs.begin(), m_peekFuncs.end(), + isWaitingFor), + m_peekFuncs.end()); m_reader->unlock(); handleXcbEvent(event); m_reader->lock(); @@ -1736,7 +1748,7 @@ void QXcbConnection::processXcbEvents() // Indicate with a null event that the event the callbacks are waiting for // is not in the queue currently. - Q_FOREACH (PeekFunc f, m_peekFuncs) + for (PeekFunc f : qAsConst(m_peekFuncs)) f(this, 0); m_peekFuncs.clear(); @@ -2187,7 +2199,7 @@ void QXcbConnection::initializeXKB() #ifndef QT_NO_XKB const xcb_query_extension_reply_t *reply = xcb_get_extension_data(m_connection, &xcb_xkb_id); if (!reply || !reply->present) { - qWarning() << "Qt: XKEYBOARD extension not present on the X server."; + qWarning("Qt: XKEYBOARD extension not present on the X server."); xkb_first_event = 0; return; } @@ -2241,7 +2253,7 @@ void QXcbConnection::initializeXKB() xcb_generic_error_t *error = xcb_request_check(c, select); if (error) { free(error); - qWarning() << "Qt: failed to select notify events from xcb-xkb"; + qWarning("Qt: failed to select notify events from xcb-xkb"); return; } #endif @@ -2258,7 +2270,7 @@ bool QXcbConnection::xi2MouseEvents() const #endif #if defined(XCB_USE_XINPUT2) -static int xi2ValuatorOffset(unsigned char *maskPtr, int maskLen, int number) +static int xi2ValuatorOffset(const unsigned char *maskPtr, int maskLen, int number) { int offset = 0; for (int i = 0; i < maskLen; i++) { @@ -2277,11 +2289,11 @@ static int xi2ValuatorOffset(unsigned char *maskPtr, int maskLen, int number) return -1; } -bool QXcbConnection::xi2GetValuatorValueIfSet(void *event, int valuatorNum, double *value) +bool QXcbConnection::xi2GetValuatorValueIfSet(const void *event, int valuatorNum, double *value) { - xXIDeviceEvent *xideviceevent = static_cast<xXIDeviceEvent *>(event); - unsigned char *buttonsMaskAddr = (unsigned char*)&xideviceevent[1]; - unsigned char *valuatorsMaskAddr = buttonsMaskAddr + xideviceevent->buttons_len * 4; + const xXIDeviceEvent *xideviceevent = static_cast<const xXIDeviceEvent *>(event); + const unsigned char *buttonsMaskAddr = (const unsigned char*)&xideviceevent[1]; + const unsigned char *valuatorsMaskAddr = buttonsMaskAddr + xideviceevent->buttons_len * 4; FP3232 *valuatorsValuesAddr = (FP3232*)(valuatorsMaskAddr + xideviceevent->valuators_len * 4); int valuatorOffset = xi2ValuatorOffset(valuatorsMaskAddr, xideviceevent->valuators_len, valuatorNum); |