summaryrefslogtreecommitdiff
path: root/src/x11extras/qx11info_x11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/x11extras/qx11info_x11.cpp')
-rw-r--r--src/x11extras/qx11info_x11.cpp52
1 files changed, 44 insertions, 8 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