From fbf5e9403e15655bd479e4cc6b26bf1451e5b8c5 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 29 Feb 2016 14:30:14 -0800 Subject: Add QX11Info::isCompositingManagerRunning() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-41195 Change-Id: Id4b385478dad85dd02c484fe9c44666bae46268b Reviewed-by: Błażej Szczygieł Reviewed-by: Shawn Rutledge --- src/x11extras/qx11info_x11.cpp | 25 +++++++++++++++++++++++++ src/x11extras/qx11info_x11.h | 2 ++ tests/auto/qx11info/tst_qx11info.cpp | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/x11extras/qx11info_x11.cpp b/src/x11extras/qx11info_x11.cpp index e5aa678..a201547 100644 --- a/src/x11extras/qx11info_x11.cpp +++ b/src/x11extras/qx11info_x11.cpp @@ -376,4 +376,29 @@ xcb_connection_t *QX11Info::connection() return reinterpret_cast(connection); } +/*! + \since 5.7 + + Returns true if there is a compositing manager running for the connection + attached to \a screen. + + If \l -1, the application 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/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"; -- cgit v1.2.1