From 2048e40d19debeab2659cc475d0fc4127220156a Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 4 Oct 2022 12:40:54 +0300 Subject: [PATCH] autotests: Extend OutputChangesTest with more cases This change extends the OutputChangesTest so it also covers the cases where a maximized and a fullscreen window is moved back to its original output when it's hotplugged. --- autotests/integration/outputchanges_test.cpp | 136 +++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/autotests/integration/outputchanges_test.cpp b/autotests/integration/outputchanges_test.cpp index f7543e965a..0c88c92f5b 100644 --- a/autotests/integration/outputchanges_test.cpp +++ b/autotests/integration/outputchanges_test.cpp @@ -37,6 +37,8 @@ private Q_SLOTS: void testWindowSticksToOutputAfterOutputsAreSwappedRightToLeft(); void testWindowRestoredAfterEnablingOutput(); + void testMaximizedWindowRestoredAfterEnablingOutput(); + void testFullScreenWindowRestoredAfterEnablingOutput(); void testWindowNotRestoredAfterMovingWindowAndEnablingOutput(); }; @@ -312,6 +314,140 @@ void OutputChangesTest::testWindowNotRestoredAfterMovingWindowAndEnablingOutput( QCOMPARE(window->frameGeometry(), QRectF(58, 100, 100, 50)); } +void OutputChangesTest::testMaximizedWindowRestoredAfterEnablingOutput() +{ + // This test verifies that a maximized window will be moved to its original + // output when it's re-enabled. + + const auto outputs = kwinApp()->platform()->outputs(); + + // Create a window. + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shellSurface(Test::createXdgToplevelSurface(surface.get())); + auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue); + QVERIFY(window); + + // kwin will send a configure event with the actived state. + QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested); + QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); + QVERIFY(surfaceConfigureRequestedSpy.wait()); + + // Move the window to the right monitor and make it maximized. + QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged); + window->move(QPointF(1280 + 50, 100)); + window->maximize(MaximizeFull); + QVERIFY(surfaceConfigureRequestedSpy.wait()); + QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value(), QSize(1280, 1024)); + shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value()); + Test::render(surface.get(), QSize(1280, 1024), Qt::blue); + QVERIFY(frameGeometryChangedSpy.wait()); + QCOMPARE(window->frameGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->moveResizeGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->output(), outputs[1]); + QCOMPARE(window->maximizeMode(), MaximizeFull); + QCOMPARE(window->requestedMaximizeMode(), MaximizeFull); + QCOMPARE(window->geometryRestore(), QRectF(1280 + 50, 100, 100, 50)); + + // Disable the right output. + OutputConfiguration config1; + { + auto changeSet = config1.changeSet(outputs[1]); + changeSet->enabled = false; + } + workspace()->applyOutputConfiguration(config1); + + // The window will be moved to the left monitor, the geometry restore will be updated too. + QCOMPARE(window->frameGeometry(), QRectF(0, 0, 1280, 1024)); + QCOMPARE(window->moveResizeGeometry(), QRectF(0, 0, 1280, 1024)); + QCOMPARE(window->output(), outputs[0]); + QCOMPARE(window->maximizeMode(), MaximizeFull); + QCOMPARE(window->requestedMaximizeMode(), MaximizeFull); + QCOMPARE(window->geometryRestore(), QRectF(50, 100, 100, 50)); + + // Enable the right monitor. + OutputConfiguration config2; + { + auto changeSet = config2.changeSet(outputs[1]); + changeSet->enabled = true; + } + workspace()->applyOutputConfiguration(config2); + + // The window will be moved back to the right monitor, the geometry restore will be updated too. + QCOMPARE(window->frameGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->moveResizeGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->output(), outputs[1]); + QCOMPARE(window->maximizeMode(), MaximizeFull); + QCOMPARE(window->requestedMaximizeMode(), MaximizeFull); + QCOMPARE(window->geometryRestore(), QRectF(1280 + 50, 100, 100, 50)); +} + +void OutputChangesTest::testFullScreenWindowRestoredAfterEnablingOutput() +{ + // This test verifies that a fullscreen window will be moved to its original + // output when it's re-enabled. + + const auto outputs = kwinApp()->platform()->outputs(); + + // Create a window. + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shellSurface(Test::createXdgToplevelSurface(surface.get())); + auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue); + QVERIFY(window); + + // kwin will send a configure event with the actived state. + QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested); + QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); + QVERIFY(surfaceConfigureRequestedSpy.wait()); + + // Move the window to the right monitor and make it fullscreen. + QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged); + window->move(QPointF(1280 + 50, 100)); + window->setFullScreen(true); + QVERIFY(surfaceConfigureRequestedSpy.wait()); + QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value(), QSize(1280, 1024)); + shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value()); + Test::render(surface.get(), QSize(1280, 1024), Qt::blue); + QVERIFY(frameGeometryChangedSpy.wait()); + QCOMPARE(window->frameGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->moveResizeGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->output(), outputs[1]); + QCOMPARE(window->isFullScreen(), true); + QCOMPARE(window->isRequestedFullScreen(), true); + QCOMPARE(window->fullscreenGeometryRestore(), QRectF(1280 + 50, 100, 100, 50)); + + // Disable the right output. + OutputConfiguration config1; + { + auto changeSet = config1.changeSet(outputs[1]); + changeSet->enabled = false; + } + workspace()->applyOutputConfiguration(config1); + + // The window will be moved to the left monitor, the geometry restore will be updated too. + QCOMPARE(window->frameGeometry(), QRectF(0, 0, 1280, 1024)); + QCOMPARE(window->moveResizeGeometry(), QRectF(0, 0, 1280, 1024)); + QCOMPARE(window->output(), outputs[0]); + QCOMPARE(window->isFullScreen(), true); + QCOMPARE(window->isRequestedFullScreen(), true); + QCOMPARE(window->fullscreenGeometryRestore(), QRectF(50, 100, 100, 50)); + + // Enable the right monitor. + OutputConfiguration config2; + { + auto changeSet = config2.changeSet(outputs[1]); + changeSet->enabled = true; + } + workspace()->applyOutputConfiguration(config2); + + // The window will be moved back to the right monitor, the geometry restore will be updated too. + QCOMPARE(window->frameGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->moveResizeGeometry(), QRectF(1280, 0, 1280, 1024)); + QCOMPARE(window->output(), outputs[1]); + QCOMPARE(window->isFullScreen(), true); + QCOMPARE(window->isRequestedFullScreen(), true); + QCOMPARE(window->fullscreenGeometryRestore(), QRectF(1280 + 50, 100, 100, 50)); +} + } // namespace KWin WAYLANDTEST_MAIN(KWin::OutputChangesTest)