diff --git a/autotests/integration/shell_client_test.cpp b/autotests/integration/shell_client_test.cpp --- a/autotests/integration/shell_client_test.cpp +++ b/autotests/integration/shell_client_test.cpp @@ -72,6 +72,8 @@ void testMinimizeActiveWindow(); void testFullscreen_data(); void testFullscreen(); + void testFullscreenRestore_data(); + void testFullscreenRestore(); void testUserCanSetFullscreen_data(); void testUserCanSetFullscreen(); void testUserSetFullscreenWlShell(); @@ -524,6 +526,60 @@ QCOMPARE(c->isDecorated(), decoMode == ServerSideDecoration::Mode::Server); } +void TestShellClient::testFullscreenRestore_data() +{ + QTest::addColumn("type"); + + QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; + QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; + QTest::newRow("xdgShellWmBase") << Test::ShellSurfaceType::XdgShellStable; +} + +void TestShellClient::testFullscreenRestore() +{ + // this test verifies that windows created fullscreen can be later properly restored + QScopedPointer surface(Test::createSurface()); + QFETCH(Test::ShellSurfaceType, type); + QScopedPointer shellSurface(Test::createShellSurface(type, surface.data())); + + XdgShellSurface *xdgShellSurface = nullptr; + // fullscreen the window + xdgShellSurface = qobject_cast(shellSurface.data()); + xdgShellSurface->setFullscreen(true); + + auto c = Test::renderAndWaitForShown(surface.data(), QSize(screens()->size(0)), Qt::blue); + QVERIFY(c); + QVERIFY(c->isFullScreen()); + + QSignalSpy fullscreenChangedSpy(c, &ShellClient::fullScreenChanged); + QVERIFY(fullscreenChangedSpy.isValid()); + QSignalSpy geometryChangedSpy(c, &ShellClient::geometryChanged); + QVERIFY(geometryChangedSpy.isValid()); + QSignalSpy sizeChangeRequestedSpy(shellSurface.data(), SIGNAL(sizeChanged(QSize))); + QVERIFY(sizeChangeRequestedSpy.isValid()); + QSignalSpy configureRequestedSpy(shellSurface.data(), SIGNAL(configureRequested(QSize, KWayland::Client::XdgShellSurface::States, quint32))); + QVERIFY(configureRequestedSpy.isValid()); + + // swap back to normal + xdgShellSurface->setFullscreen(false); + + QVERIFY(fullscreenChangedSpy.wait()); + QVERIFY(configureRequestedSpy.wait()); + QCOMPARE(configureRequestedSpy.count(), 4); + QCOMPARE(configureRequestedSpy.last().first().toSize(), QSize(0, 0)); + QVERIFY(!c->isFullScreen()); + + for (const auto &it: configureRequestedSpy) { + xdgShellSurface->ackConfigure(it[2].toInt()); + } + + Test::render(surface.data(), QSize(100, 50), Qt::red); + QVERIFY(geometryChangedSpy.wait()); + QCOMPARE(geometryChangedSpy.count(), 1); + QVERIFY(!c->isFullScreen()); + QCOMPARE(c->geometry(), QRect(QPoint(0, 0), QSize(100, 50))); +} + void TestShellClient::testUserCanSetFullscreen_data() { QTest::addColumn("type"); diff --git a/shell_client.cpp b/shell_client.cpp --- a/shell_client.cpp +++ b/shell_client.cpp @@ -973,14 +973,15 @@ if (isFullScreen()) { setGeometry(workspace()->clientArea(FullScreenArea, this)); } else { - if (!m_geomFsRestore.isNull()) { + if (m_geomFsRestore.isValid()) { int currentScreen = screen(); setGeometry(QRect(m_geomFsRestore.topLeft(), adjustedSize(m_geomFsRestore.size()))); if( currentScreen != screen()) workspace()->sendClientToScreen( this, currentScreen ); } else { - // does this ever happen? - setGeometry(workspace()->clientArea(MaximizeArea, this)); + // this can happen when the window was first shown already fullscreen, + // so let the client set the size by itself + setGeometry(QRect(QPoint(0, 0), QSize(0, 0))); } } updateWindowRules(Rules::Fullscreen|Rules::Position|Rules::Size);