From f27489d66cc6d8263130451c26c7e4ae40acc6b4 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Wed, 22 Apr 2015 19:28:24 +0300 Subject: Properly get appDpiX, appDpiY and appRootWindow for X screen X screen is a virtual desktop in Qt terminology. So find the first QScreen which belongs to the requested virtual desktop and use it to get the values. Change-Id: If5c08ff6c3e19e1d49d17ae8e1c54e09ffeb97cf Reviewed-by: Friedemann Kleint Reviewed-by: Laszlo Agocs --- src/x11extras/qx11info_x11.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/x11extras/qx11info_x11.cpp b/src/x11extras/qx11info_x11.cpp index 8d8f337..2d4c5d2 100644 --- a/src/x11extras/qx11info_x11.cpp +++ b/src/x11extras/qx11info_x11.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,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 @@ -103,11 +112,11 @@ int QX11Info::appDpiX(int screen) return qRound(scr->logicalDotsPerInchX()); } - QList screens = QGuiApplication::screens(); - if (screen >= screens.size()) + QScreen *scr = findScreenForVirtualDesktop(screen); + if (!scr) return 0; - return screens[screen]->logicalDotsPerInchX(); + return scr->logicalDotsPerInchX(); } /*! @@ -130,11 +139,11 @@ int QX11Info::appDpiY(int screen) return qRound(scr->logicalDotsPerInchY()); } - QList screens = QGuiApplication::screens(); - if (screen > screens.size()) + QScreen *scr = findScreenForVirtualDesktop(screen); + if (!scr) return 0; - return screens[screen]->logicalDotsPerInchY(); + return scr->logicalDotsPerInchY(); } /*! @@ -151,11 +160,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(reinterpret_cast(native->nativeResourceForIntegration(QByteArrayLiteral("rootwindow")))); + QScreen *scr = screen == -1 ? QGuiApplication::primaryScreen() : findScreenForVirtualDesktop(screen); + if (!scr) + return 0; + return static_cast(reinterpret_cast(native->nativeResourceForScreen(QByteArrayLiteral("rootwindow"), scr))); } /*! -- cgit v1.2.1