From 7b7a179396c4572764e9762e358752c99794f008 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 13 Sep 2022 10:43:17 +0300 Subject: [PATCH] autotests: Add more test cases in OutputChangesTest It adds more test cases in OutputChangesTest, particularly swapping outputs. Swapping outputs is an interesting case because outputs can temporarily overlap so workspace()->outputAt() can return wrong output and the window is going to stick to wrong output. --- autotests/integration/outputchanges_test.cpp | 68 ++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/autotests/integration/outputchanges_test.cpp b/autotests/integration/outputchanges_test.cpp index 7f2d95e626..f8ca460845 100644 --- a/autotests/integration/outputchanges_test.cpp +++ b/autotests/integration/outputchanges_test.cpp @@ -33,6 +33,8 @@ private Q_SLOTS: void testWindowSticksToOutputAfterOutputIsDisabled(); void testWindowSticksToOutputAfterAnotherOutputIsDisabled(); void testWindowSticksToOutputAfterOutputIsMoved(); + void testWindowSticksToOutputAfterOutputsAreSwappedLeftToRight(); + void testWindowSticksToOutputAfterOutputsAreSwappedRightToLeft(); }; void OutputChangesTest::initTestCase() @@ -149,7 +151,73 @@ void OutputChangesTest::testWindowSticksToOutputAfterOutputIsMoved() QCOMPARE(window->frameGeometry(), QRect(-10 + 42, 20 + 67, 100, 50)); } +void OutputChangesTest::testWindowSticksToOutputAfterOutputsAreSwappedLeftToRight() +{ + // This test verifies that a window placed on the left monitor sticks + // to that monitor even after the monitors are swapped horizontally. + + 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); + + // Move the window to the left output. + window->move(QPointF(0, 0)); + QCOMPARE(window->output(), outputs[0]); + QCOMPARE(window->frameGeometry(), QRectF(0, 0, 100, 50)); + + // Swap outputs. + OutputConfiguration config; + { + auto changeSet1 = config.changeSet(outputs[0]); + changeSet1->pos = QPoint(1280, 0); + auto changeSet2 = config.changeSet(outputs[1]); + changeSet2->pos = QPoint(0, 0); + } + workspace()->applyOutputConfiguration(config); + + // The window should be still on its original output. + QCOMPARE(window->output(), outputs[0]); + QCOMPARE(window->frameGeometry(), QRectF(1280, 0, 100, 50)); } +void OutputChangesTest::testWindowSticksToOutputAfterOutputsAreSwappedRightToLeft() +{ + // This test verifies that a window placed on the right monitor sticks + // to that monitor even after the monitors are swapped horizontally. + + 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); + + // Move the window to the right output. + window->move(QPointF(1280, 0)); + QCOMPARE(window->output(), outputs[1]); + QCOMPARE(window->frameGeometry(), QRectF(1280, 0, 100, 50)); + + // Swap outputs. + OutputConfiguration config; + { + auto changeSet1 = config.changeSet(outputs[0]); + changeSet1->pos = QPoint(1280, 0); + auto changeSet2 = config.changeSet(outputs[1]); + changeSet2->pos = QPoint(0, 0); + } + workspace()->applyOutputConfiguration(config); + + // The window should be still on its original output. + QCOMPARE(window->output(), outputs[1]); + QCOMPARE(window->frameGeometry(), QRectF(0, 0, 100, 50)); +} + +} // namespace KWin + WAYLANDTEST_MAIN(KWin::OutputChangesTest) #include "outputchanges_test.moc"