From d33edcfe379fe4d86c8a4a0a2b02e8c6af104a71 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 7 May 2015 18:05:00 +0200 Subject: Fix the qscreen manual test for separate X screens It is fully possible to show a window on all the connected screens even when the screens are not virtual siblings, i.e. they do not form one big desktop. When X is configured to use a separate screen for each physical screen, it becomes essential to do setScreen() either directly or via QDesktopWidget in case of widgets. The original code attempting to call QWindow::setScreen() cannot succeed since there is no QWindow available before the widget is shown. This is easy to work around. The app now works identically in all cases. Change-Id: I519ca0c0109c68aac2f2d4e6972d14b55767b403 Reviewed-by: Gunnar Sletta --- tests/manual/qscreen/main.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'tests/manual/qscreen/main.cpp') 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 #include #include +#include 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 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()) -- cgit v1.2.3