diff --git a/src/plugins/platforms/wayland/qwaylandscreen.cpp b/src/plugins/platforms/wayland/qwaylandscreen.cpp index fba75557711..1c9ce23ba43 100644 --- a/src/plugins/platforms/wayland/qwaylandscreen.cpp +++ b/src/plugins/platforms/wayland/qwaylandscreen.cpp @@ -138,8 +138,10 @@ QList QWaylandScreen::virtualSiblings() const QList list; const QList screens = mWaylandDisplay->screens(); list.reserve(screens.count()); - foreach (QWaylandScreen *screen, screens) - list << screen; + for (QWaylandScreen *screen : qAsConst(screens)) { + if (screen->screen()) + list << screen; + } return list; } diff --git a/tests/auto/wayland/client/tst_client.cpp b/tests/auto/wayland/client/tst_client.cpp index 981b8f129ec..e244de7f20b 100644 --- a/tests/auto/wayland/client/tst_client.cpp +++ b/tests/auto/wayland/client/tst_client.cpp @@ -164,6 +164,7 @@ public slots: private slots: void primaryScreen(); void screens(); + void addScreenWithGeometryChange(); void windowScreens(); void removePrimaryScreen(); void createDestroyWindow(); @@ -197,6 +198,29 @@ void tst_WaylandClient::screens() QTRY_COMPARE(QGuiApplication::screens().size(), 1); } +//QTBUG-62044 +void tst_WaylandClient::addScreenWithGeometryChange() +{ + QTRY_COMPARE(QGuiApplication::screens().size(), 1); + const QRect oldGeometry = QGuiApplication::primaryScreen()->geometry(); + compositor->sendAddOutput(); + + // Move the primary screen to the right + const QRect newGeometry(QPoint(screenSize.width(), 0), screenSize); + Q_ASSERT(oldGeometry != newGeometry); + compositor->sendOutputGeometry(compositor->output(0), newGeometry); + + QTRY_COMPARE(QGuiApplication::screens().size(), 2); + QTRY_COMPARE(QGuiApplication::primaryScreen()->geometry(), newGeometry); + + compositor->sendRemoveOutput(compositor->output(1)); + QTRY_COMPARE(QGuiApplication::screens().size(), 1); + + // Move the screen back + compositor->sendOutputGeometry(compositor->output(0), oldGeometry); + QTRY_COMPARE(QGuiApplication::primaryScreen()->geometry(), oldGeometry); +} + void tst_WaylandClient::windowScreens() { QSharedPointer firstOutput; @@ -255,6 +279,7 @@ void tst_WaylandClient::removePrimaryScreen() compositor->sendAddOutput(); QTRY_COMPARE(QGuiApplication::screens().size(), 2); + QTRY_COMPARE(QGuiApplication::primaryScreen()->virtualSiblings().size(), 2); QScreen *secondaryScreen = QGuiApplication::screens().at(1); QVERIFY(secondaryScreen); diff --git a/tests/auto/wayland/shared/mockcompositor.cpp b/tests/auto/wayland/shared/mockcompositor.cpp index e7c6e90d285..bdeca4e239f 100644 --- a/tests/auto/wayland/shared/mockcompositor.cpp +++ b/tests/auto/wayland/shared/mockcompositor.cpp @@ -196,6 +196,14 @@ void MockCompositor::sendRemoveOutput(const QSharedPointer &output) processCommand(command); } +void MockCompositor::sendOutputGeometry(const QSharedPointer &output, const QRect &geometry) +{ + Command command = makeCommand(Impl::Compositor::sendOutputGeometry, m_compositor); + command.parameters << QVariant::fromValue(output); + command.parameters << QVariant::fromValue(geometry); + processCommand(command); +} + void MockCompositor::sendSurfaceEnter(const QSharedPointer &surface, QSharedPointer &output) { Command command = makeCommand(Impl::Compositor::sendSurfaceEnter, m_compositor); diff --git a/tests/auto/wayland/shared/mockcompositor.h b/tests/auto/wayland/shared/mockcompositor.h index 9258b192623..d4cf5f3671c 100644 --- a/tests/auto/wayland/shared/mockcompositor.h +++ b/tests/auto/wayland/shared/mockcompositor.h @@ -89,6 +89,7 @@ public: static void setOutputMode(void *compositor, const QList ¶meters); static void sendAddOutput(void *data, const QList ¶meters); static void sendRemoveOutput(void *data, const QList ¶meters); + static void sendOutputGeometry(void *data, const QList ¶meters); static void sendSurfaceEnter(void *data, const QList ¶meters); static void sendSurfaceLeave(void *data, const QList ¶meters); @@ -181,6 +182,7 @@ public: void sendDataDeviceLeave(const QSharedPointer &surface); void sendAddOutput(); void sendRemoveOutput(const QSharedPointer &output); + void sendOutputGeometry(const QSharedPointer &output, const QRect &geometry); void sendSurfaceEnter(const QSharedPointer &surface, QSharedPointer &output); void sendSurfaceLeave(const QSharedPointer &surface, QSharedPointer &output); void waitForStartDrag(); diff --git a/tests/auto/wayland/shared/mockoutput.cpp b/tests/auto/wayland/shared/mockoutput.cpp index 7d7b7413a3e..13e0524ad1d 100644 --- a/tests/auto/wayland/shared/mockoutput.cpp +++ b/tests/auto/wayland/shared/mockoutput.cpp @@ -54,6 +54,16 @@ void Compositor::sendRemoveOutput(void *data, const QList ¶meters) delete output; } +void Compositor::sendOutputGeometry(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Q_ASSERT(compositor); + Output *output = resolveOutput(parameters.first()); + Q_ASSERT(output); + QRect geometry = parameters.at(1).toRect(); + output->sendGeometryAndMode(geometry); +} + void Compositor::setOutputMode(void *data, const QList ¶meters) { Compositor *compositor = static_cast(data); @@ -74,16 +84,29 @@ Output::Output(wl_display *display, const QSize &resolution, const QPoint &posit void Output::setCurrentMode(const QSize &size) { - qDebug() << Q_FUNC_INFO << size; m_size = size; - for (Resource *resource : resourceMap()) + for (Resource *resource : resourceMap()) { sendCurrentMode(resource); + send_done(resource->handle); + } +} + +void Output::sendGeometryAndMode(const QRect &geometry) +{ + m_size = geometry.size(); + m_position = geometry.topLeft(); + for (Resource *resource : resourceMap()) { + sendGeometry(resource); + sendCurrentMode(resource); + send_done(resource->handle); + } } void Output::output_bind_resource(QtWaylandServer::wl_output::Resource *resource) { sendGeometry(resource); sendCurrentMode(resource); + send_done(resource->handle); } void Output::sendGeometry(Resource *resource) diff --git a/tests/auto/wayland/shared/mockoutput.h b/tests/auto/wayland/shared/mockoutput.h index d5a2bb56b6e..9f261d5d7dd 100644 --- a/tests/auto/wayland/shared/mockoutput.h +++ b/tests/auto/wayland/shared/mockoutput.h @@ -44,6 +44,7 @@ public: QSharedPointer mockOutput() const { return m_mockOutput; } void setCurrentMode(const QSize &size); + void sendGeometryAndMode(const QRect &geometry); protected: void output_bind_resource(Resource *resource) override;