summaryrefslogtreecommitdiffstats
path: root/tests/manual/qscreen
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/qscreen')
-rw-r--r--tests/manual/qscreen/README12
-rw-r--r--tests/manual/qscreen/main.cpp21
2 files changed, 14 insertions, 19 deletions
diff --git a/tests/manual/qscreen/README b/tests/manual/qscreen/README
index 5f5da17293..cd1324276d 100644
--- a/tests/manual/qscreen/README
+++ b/tests/manual/qscreen/README
@@ -20,14 +20,10 @@ create two windows, and will center one each screen, by setting the geometry.
Alternatively you can configure xorg.conf to create separate screens for each
graphics card; then the mouse cursor can move between the screens, but
-application windows cannot: each app needs to be started up on the screen that
-you want to run it on. In either case, ideally this test app ought to create
-two windows, one on each screen; but in fact, it can do that only if the
-screens are virtual siblings. If they are on different Displays, the second
-Display is not accessible to the QXcbConnection instance which was createad on
-the first Display. It can be considered a known bug that the API appears to
-make this possible (you would think QWindow::setScreen might work) but it
-isn't possible.
+application windows cannot: each app needs to be started on the screen that
+you want to run it on (by specifying e.g. DISPLAY=:0.1 for the second screen),
+or the application has to set the desired screen via QWindow::setScreen() before
+showing the window.
The physical size of the screen is considered to be a constant. This can create
discrepancies in DPI when orientation is changed, or when the screen is
diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp
index 6f672ee422..1047ffcdfc 100644
--- a/tests/manual/qscreen/main.cpp
+++ b/tests/manual/qscreen/main.cpp
@@ -38,6 +38,7 @@
#include <QDebug>
#include <QFormLayout>
#include <QLineEdit>
+#include <QDesktopWidget>
int i = 0;
@@ -66,19 +67,17 @@ void screenAdded(QScreen* screen)
w->layout()->insertRow(0, "virtualSiblings", siblingsField);
updateSiblings(w);
- // This doesn't work. If the multiple screens are part of
- // a virtual desktop (i.e. they are virtual siblings), then
- // setScreen has no effect, and we need the code below to
- // change the window geometry. If on the other hand the
- // screens are really separate, so that windows are not
- // portable between them, XCreateWindow needs to have not just
- // a different root Window but also a different Display, in order to
- // put the window on the other screen. That would require a
- // different QXcbConnection. So this setScreen call doesn't seem useful.
- //w->windowHandle()->setScreen(screen);
+ // Set the screen via QDesktopWidget. This corresponds to setScreen() for the underlying
+ // QWindow. This is essential when having separate X screens since the the positioning below is
+ // not sufficient to get the windows show up on the desired screen.
+ QList<QScreen *> screens = QGuiApplication::screens();
+ int screenNumber = screens.indexOf(screen);
+ Q_ASSERT(screenNumber >= 0);
+ w->setParent(qApp->desktop()->screen(screenNumber));
- // But this works as long as the screens are all virtual siblings
w->show();
+
+ // Position the windows so that they end up at the center of the corresponding screen.
QRect geom = w->geometry();
geom.setSize(w->sizeHint());
if (geom.height() > screen->geometry().height())