From f0e400e1bca13176e56cf7bb323cd0a6393a85ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 2 Sep 2013 20:51:57 +0200 Subject: Properly get X screen application is running on in appScreen QDesktopWidget does not provide the X screen number. No matter on which X screen an application is started, QDesktopWidget returns 0. Therefore resolve the X screen through the native interface's x11 screen resource. The documentation is improved to make it more obvious that this is about the X screen and not the RandR screen. Change-Id: I0f78a728769cbdfcac8b67b4fd5de0934f498027 Reviewed-by: Richard J. Moore Reviewed-by: David Faure --- src/x11extras/qx11info_x11.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/x11extras/qx11info_x11.cpp b/src/x11extras/qx11info_x11.cpp index 85aa9e1..8bea591 100644 --- a/src/x11extras/qx11info_x11.cpp +++ b/src/x11extras/qx11info_x11.cpp @@ -178,14 +178,27 @@ unsigned long QX11Info::appRootWindow(int screen) Returns the number of the screen where the application is being displayed. + This method refers to screens in the original X11 meaning with a + different DISPLAY environment variable per screen. + This information is only useful if your application needs to know + on which X screen it is running. + + In a typical multi-head configuration, multiple physical monitors + are combined in one X11 screen. This means this method returns the + same number for each of the physical monitors. In such a setup you + are interested in the monitor information as provided by the X11 + RandR extension. This is available through QDesktopWidget and QScreen. + \sa display(), screen() */ int QX11Info::appScreen() { if (!qApp) return 0; - QDesktopWidget *desktop = QApplication::desktop(); - return desktop->primaryScreen(); + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return 0; + return reinterpret_cast(native->nativeResourceForIntegration(QByteArrayLiteral("x11screen"))); } /*! -- cgit v1.2.1