From 58fdbbc44413a7f1affd6d730b3adc73acc99b0b Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 23 Jan 2023 16:35:30 +0100 Subject: [PATCH] autotests/integration: test restoration of window states on moveresize cancel --- autotests/integration/kwin_wayland_test.h | 1 + .../integration/move_resize_window_test.cpp | 72 +++++++++++++++++++ autotests/integration/test_helpers.cpp | 6 ++ 3 files changed, 79 insertions(+) diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 40468c26dd..e98ea565b3 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -553,6 +553,7 @@ void pointerAxisVertical(qreal delta, void pointerButtonPressed(quint32 button, quint32 time); void pointerButtonReleased(quint32 button, quint32 time); void pointerMotion(const QPointF &position, quint32 time); +void pointerMotionRelative(const QPointF &delta, quint32 time); void touchCancel(); void touchDown(qint32 id, const QPointF &pos, quint32 time); void touchMotion(qint32 id, const QPointF &pos, quint32 time); diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp index 31bc49cc64..e244774e22 100644 --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -70,6 +70,8 @@ private Q_SLOTS: void testResizeForVirtualKeyboardWithFullScreen(); void testDestroyMoveClient(); void testDestroyResizeClient(); + void testCancelInteractiveMoveResize_data(); + void testCancelInteractiveMoveResize(); private: KWayland::Client::ConnectionThread *m_connection = nullptr; @@ -1074,6 +1076,76 @@ void MoveResizeWindowTest::testDestroyResizeClient() QCOMPARE(workspace()->moveResizeWindow(), nullptr); } +void MoveResizeWindowTest::testCancelInteractiveMoveResize_data() +{ + QTest::addColumn("quickTileMode"); + QTest::addColumn("maximizeMode"); + + QTest::newRow("quicktile_bottom") << QuickTileMode(QuickTileFlag::Bottom) << MaximizeMode::MaximizeRestore; + QTest::newRow("quicktile_top") << QuickTileMode(QuickTileFlag::Top) << MaximizeMode::MaximizeRestore; + QTest::newRow("quicktile_left") << QuickTileMode(QuickTileFlag::Left) << MaximizeMode::MaximizeRestore; + QTest::newRow("quicktile_right") << QuickTileMode(QuickTileFlag::Right) << MaximizeMode::MaximizeRestore; + QTest::newRow("maximize_vertical") << QuickTileMode(QuickTileFlag::None) << MaximizeMode::MaximizeVertical; + QTest::newRow("maximize_horizontal") << QuickTileMode(QuickTileFlag::None) << MaximizeMode::MaximizeHorizontal; + QTest::newRow("maximize_full") << QuickTileMode(QuickTileFlag::Maximize) << MaximizeMode::MaximizeFull; +} + +void MoveResizeWindowTest::testCancelInteractiveMoveResize() +{ + // This test verifies that after moveresize is cancelled, all relevant window states are restored + // to what they were before moveresize began + + // Create the test client. + std::unique_ptr surface(Test::createSurface()); + QVERIFY(surface != nullptr); + std::unique_ptr shellSurface(Test::createXdgToplevelSurface(surface.get())); + QVERIFY(shellSurface != nullptr); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue); + QVERIFY(window); + + // tile / maximize window + QFETCH(QuickTileMode, quickTileMode); + QFETCH(MaximizeMode, maximizeMode); + if (maximizeMode) { + window->setMaximize(maximizeMode & MaximizeMode::MaximizeVertical, maximizeMode & MaximizeMode::MaximizeHorizontal); + } else { + window->setQuickTileMode(quickTileMode, true); + } + QCOMPARE(window->quickTileMode(), quickTileMode); + QCOMPARE(window->requestedMaximizeMode(), maximizeMode); + + QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested); + QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); + QVERIFY(surfaceConfigureRequestedSpy.wait()); + Test::render(surface.get(), toplevelConfigureRequestedSpy.last().first().toSize(), Qt::blue); + + const QRectF geometry = window->moveResizeGeometry(); + const QRectF geometryRestore = window->geometryRestore(); + + // Start resizing the client. + QSignalSpy clientStartMoveResizedSpy(window, &Window::clientStartUserMovedResized); + QSignalSpy clientFinishUserMovedResizedSpy(window, &Window::clientFinishUserMovedResized); + + QCOMPARE(workspace()->moveResizeWindow(), nullptr); + QCOMPARE(window->isInteractiveMove(), false); + QCOMPARE(window->isInteractiveResize(), false); + workspace()->slotWindowResize(); + QCOMPARE(clientStartMoveResizedSpy.count(), 1); + QCOMPARE(workspace()->moveResizeWindow(), window); + QCOMPARE(window->isInteractiveMove(), false); + QCOMPARE(window->isInteractiveResize(), true); + + Test::pointerMotionRelative(QPoint(1, 1), 1); + QCOMPARE(window->quickTileMode(), QuickTileMode()); + QCOMPARE(window->requestedMaximizeMode(), MaximizeMode::MaximizeRestore); + + // cancel moveresize, all state from before should be restored + window->keyPressEvent(Qt::Key::Key_Escape); + QCOMPARE(window->moveResizeGeometry(), geometry); + QCOMPARE(window->quickTileMode(), quickTileMode); + QCOMPARE(window->requestedMaximizeMode(), maximizeMode); + QCOMPARE(window->geometryRestore(), geometryRestore); +} } WAYLANDTEST_MAIN(KWin::MoveResizeWindowTest) diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 70c2b472b5..9321d17978 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -1423,6 +1423,12 @@ void pointerMotion(const QPointF &position, quint32 time) Q_EMIT virtualPointer->pointerMotionAbsolute(position, std::chrono::milliseconds(time), virtualPointer); } +void pointerMotionRelative(const QPointF &delta, quint32 time) +{ + auto virtualPointer = static_cast(kwinApp())->virtualPointer(); + Q_EMIT virtualPointer->pointerMotion(delta, delta, std::chrono::milliseconds(time), virtualPointer); +} + void touchCancel() { auto virtualTouch = static_cast(kwinApp())->virtualTouch();