diff options
-rw-r--r-- | src/x11extras/qx11info_x11.cpp | 52 | ||||
-rw-r--r-- | src/x11extras/qx11info_x11.h | 2 | ||||
-rw-r--r-- | src/x11extras/x11extras.pro | 6 | ||||
-rw-r--r-- | tests/auto/qx11info/tst_qx11info.cpp | 2 |
4 files changed, 51 insertions, 11 deletions
diff --git a/src/x11extras/qx11info_x11.cpp b/src/x11extras/qx11info_x11.cpp index c5914e4..0473fda 100644 --- a/src/x11extras/qx11info_x11.cpp +++ b/src/x11extras/qx11info_x11.cpp @@ -49,6 +49,7 @@ #include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformwindow.h> +#include <QtPlatformHeaders/qxcbscreenfunctions.h> #include <qscreen.h> #include <qwindow.h> #include <qguiapplication.h> @@ -56,6 +57,14 @@ QT_BEGIN_NAMESPACE +static QScreen *findScreenForVirtualDesktop(int virtualDesktopNumber) +{ + foreach (QScreen *screen, QGuiApplication::screens()) { + if (QXcbScreenFunctions::virtualDesktopNumber(screen) == virtualDesktopNumber) + return screen; + } + return Q_NULLPTR; +} /*! \class QX11Info @@ -109,11 +118,11 @@ int QX11Info::appDpiX(int screen) return qRound(scr->logicalDotsPerInchX()); } - QList<QScreen *> screens = QGuiApplication::screens(); - if (screen >= screens.size()) + QScreen *scr = findScreenForVirtualDesktop(screen); + if (!scr) return 0; - return screens[screen]->logicalDotsPerInchX(); + return scr->logicalDotsPerInchX(); } /*! @@ -136,11 +145,11 @@ int QX11Info::appDpiY(int screen) return qRound(scr->logicalDotsPerInchY()); } - QList<QScreen *> screens = QGuiApplication::screens(); - if (screen > screens.size()) + QScreen *scr = findScreenForVirtualDesktop(screen); + if (!scr) return 0; - return screens[screen]->logicalDotsPerInchY(); + return scr->logicalDotsPerInchY(); } /*! @@ -157,11 +166,13 @@ unsigned long QX11Info::appRootWindow(int screen) { if (!qApp) return 0; - Q_UNUSED(screen); QPlatformNativeInterface *native = qApp->platformNativeInterface(); if (!native) return 0; - return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(native->nativeResourceForIntegration(QByteArrayLiteral("rootwindow")))); + QScreen *scr = screen == -1 ? QGuiApplication::primaryScreen() : findScreenForVirtualDesktop(screen); + if (!scr) + return 0; + return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen(QByteArrayLiteral("rootwindow"), scr))); } /*! @@ -365,4 +376,29 @@ xcb_connection_t *QX11Info::connection() return reinterpret_cast<xcb_connection_t *>(connection); } +/*! + \since 5.7 + + Returns true if there is a compositing manager running for the connection + attached to \a screen. + + If \a screen equals -1, the application's primary screen is used. +*/ +bool QX11Info::isCompositingManagerRunning(int screen) +{ + if (!qApp) + return false; + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return false; + + QScreen *scr = screen == -1 ? QGuiApplication::primaryScreen() : findScreenForVirtualDesktop(screen); + if (!scr) { + qWarning() << "isCompositingManagerRunning: Could not find screen number" << screen; + return false; + } + + return native->nativeResourceForScreen(QByteArray("compositingEnabled"), scr); +} + QT_END_NAMESPACE diff --git a/src/x11extras/qx11info_x11.h b/src/x11extras/qx11info_x11.h index 620428d..ab72686 100644 --- a/src/x11extras/qx11info_x11.h +++ b/src/x11extras/qx11info_x11.h @@ -73,6 +73,8 @@ public: static Display *display(); static xcb_connection_t *connection(); + static bool isCompositingManagerRunning(int screen = -1); + private: QX11Info(); }; diff --git a/src/x11extras/x11extras.pro b/src/x11extras/x11extras.pro index 730a145..a400276 100644 --- a/src/x11extras/x11extras.pro +++ b/src/x11extras/x11extras.pro @@ -4,9 +4,9 @@ DEFINES += QT_NO_USING_NAMESPACE QMAKE_DOCS = $$PWD/doc/qtx11extras.qdocconf -load(qt_module) - -QT += gui-private +QT_PRIVATE += gui-private HEADERS += qx11info_x11.h SOURCES += qx11info_x11.cpp + +load(qt_module) diff --git a/tests/auto/qx11info/tst_qx11info.cpp b/tests/auto/qx11info/tst_qx11info.cpp index 0a19d7f..a27f443 100644 --- a/tests/auto/qx11info/tst_qx11info.cpp +++ b/tests/auto/qx11info/tst_qx11info.cpp @@ -96,6 +96,8 @@ void tst_QX11Info::staticFunctionsBeforeQApplication() appUserTime = QX11Info::appUserTime(); QCOMPARE(appTime, 0ul); QCOMPARE(appTime, 0ul); + + QX11Info::isCompositingManagerRunning(); } static const char idFromEnv[] = "startupid_TIME123456"; |