diff --git a/src/wayland/autotests/client/test_wayland_shell.cpp b/src/wayland/autotests/client/test_wayland_shell.cpp index 2f24c2b830..75295bf72a 100644 --- a/src/wayland/autotests/client/test_wayland_shell.cpp +++ b/src/wayland/autotests/client/test_wayland_shell.cpp @@ -43,6 +43,7 @@ class TestWaylandShell : public QObject public: explicit TestWaylandShell(QObject *parent = nullptr); private Q_SLOTS: + void initTestCase(); void init(); void cleanup(); @@ -58,6 +59,8 @@ private Q_SLOTS: void testDestroy(); void testCast(); void testMove(); + void testResize_data(); + void testResize(); private: KWayland::Server::Display *m_display; @@ -91,6 +94,11 @@ TestWaylandShell::TestWaylandShell(QObject *parent) { } +void TestWaylandShell::initTestCase() +{ + qRegisterMetaType(); +} + void TestWaylandShell::init() { using namespace KWayland::Server; @@ -631,5 +639,65 @@ void TestWaylandShell::testMove() QCOMPARE(moveRequestedSpy.first().at(1).value(), m_seatInterface->pointerButtonSerial(Qt::LeftButton)); } +void TestWaylandShell::testResize_data() +{ + QTest::addColumn("resizeEdge"); + QTest::addColumn("expectedEdge"); + + QTest::newRow("None") << Qt::Edges() << Qt::Edges(); + + QTest::newRow("Top") << Qt::Edges(Qt::TopEdge) << Qt::Edges(Qt::TopEdge); + QTest::newRow("Bottom") << Qt::Edges(Qt::BottomEdge) << Qt::Edges(Qt::BottomEdge); + QTest::newRow("Left") << Qt::Edges(Qt::LeftEdge) << Qt::Edges(Qt::LeftEdge); + QTest::newRow("Right") << Qt::Edges(Qt::RightEdge) << Qt::Edges(Qt::RightEdge); + + QTest::newRow("Top Left") << Qt::Edges(Qt::TopEdge | Qt::LeftEdge) << Qt::Edges(Qt::TopEdge | Qt::LeftEdge); + QTest::newRow("Top Right") << Qt::Edges(Qt::TopEdge | Qt::RightEdge) << Qt::Edges(Qt::TopEdge | Qt::RightEdge); + QTest::newRow("Bottom Left") << Qt::Edges(Qt::BottomEdge | Qt::LeftEdge) << Qt::Edges(Qt::BottomEdge | Qt::LeftEdge); + QTest::newRow("Bottom Right") << Qt::Edges(Qt::BottomEdge | Qt::RightEdge) << Qt::Edges(Qt::BottomEdge | Qt::RightEdge); + + // invalid combinations + QTest::newRow("Top Bottom") << Qt::Edges(Qt::TopEdge | Qt::BottomEdge) << Qt::Edges(); + QTest::newRow("Left Right") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge) << Qt::Edges(); + QTest::newRow("Top Bottom Right") << Qt::Edges(Qt::TopEdge | Qt::BottomEdge | Qt::RightEdge) << Qt::Edges(); + QTest::newRow("Top Bottom Left") << Qt::Edges(Qt::TopEdge | Qt::BottomEdge | Qt::LeftEdge) << Qt::Edges(); + QTest::newRow("Left Right Top") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge | Qt::TopEdge) << Qt::Edges(); + QTest::newRow("Left Right Bottom") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge | Qt::BottomEdge) << Qt::Edges(); + QTest::newRow("All") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge | Qt::BottomEdge | Qt::TopEdge) << Qt::Edges(); +} + +void TestWaylandShell::testResize() +{ + using namespace KWayland::Client; + using namespace KWayland::Server; + QScopedPointer s(m_compositor->createSurface()); + QVERIFY(!s.isNull()); + QVERIFY(s->isValid()); + ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); + + QSignalSpy serverSurfaceSpy(m_shellInterface, &ShellInterface::surfaceCreated); + QVERIFY(serverSurfaceSpy.isValid()); + QVERIFY(serverSurfaceSpy.wait()); + ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); + QVERIFY(serverSurface); + QSignalSpy resizeRequestedSpy(serverSurface, &ShellSurfaceInterface::resizeRequested); + QVERIFY(resizeRequestedSpy.isValid()); + + QSignalSpy pointerButtonChangedSpy(m_pointer, &Pointer::buttonStateChanged); + QVERIFY(pointerButtonChangedSpy.isValid()); + + m_seatInterface->setFocusedPointerSurface(serverSurface->surface()); + m_seatInterface->pointerButtonPressed(Qt::LeftButton); + QVERIFY(pointerButtonChangedSpy.wait()); + + QFETCH(Qt::Edges, resizeEdge); + surface->requestResize(m_seat, pointerButtonChangedSpy.first().first().value(), resizeEdge); + QVERIFY(resizeRequestedSpy.wait()); + QCOMPARE(resizeRequestedSpy.count(), 1); + QCOMPARE(resizeRequestedSpy.first().at(0).value(), m_seatInterface); + QCOMPARE(resizeRequestedSpy.first().at(1).value(), m_seatInterface->pointerButtonSerial(Qt::LeftButton)); + QTEST(resizeRequestedSpy.first().at(2).value(), "expectedEdge"); +} + QTEST_GUILESS_MAIN(TestWaylandShell) #include "test_wayland_shell.moc" diff --git a/src/wayland/server/shell_interface.cpp b/src/wayland/server/shell_interface.cpp index 173384c460..2988e226f9 100644 --- a/src/wayland/server/shell_interface.cpp +++ b/src/wayland/server/shell_interface.cpp @@ -259,12 +259,38 @@ void ShellSurfaceInterface::Private::moveCallback(wl_client *client, wl_resource void ShellSurfaceInterface::Private::resizeCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, uint32_t edges) { - Q_UNUSED(seat) - Q_UNUSED(serial) - Q_UNUSED(edges) auto s = cast(resource); Q_ASSERT(client == *s->client); - // TODO: implement + Qt::Edges qtEdges; + switch (edges) { + case WL_SHELL_SURFACE_RESIZE_TOP: + qtEdges = Qt::TopEdge; + break; + case WL_SHELL_SURFACE_RESIZE_BOTTOM: + qtEdges = Qt::BottomEdge; + break; + case WL_SHELL_SURFACE_RESIZE_LEFT: + qtEdges = Qt::LeftEdge; + break; + case WL_SHELL_SURFACE_RESIZE_TOP_LEFT: + qtEdges = Qt::TopEdge | Qt::LeftEdge; + break; + case WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT: + qtEdges = Qt::BottomEdge | Qt::LeftEdge; + break; + case WL_SHELL_SURFACE_RESIZE_RIGHT: + qtEdges = Qt::RightEdge; + break; + case WL_SHELL_SURFACE_RESIZE_TOP_RIGHT: + qtEdges = Qt::TopEdge | Qt::RightEdge; + break; + case WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT: + qtEdges = Qt::BottomEdge | Qt::RightEdge; + break; + default: + break; + } + emit s->q_func()->resizeRequested(SeatInterface::get(seat), serial, qtEdges); } void ShellSurfaceInterface::Private::setToplevelCallback(wl_client *client, wl_resource *resource) diff --git a/src/wayland/server/shell_interface.h b/src/wayland/server/shell_interface.h index 42df1e426a..d31e27fabf 100644 --- a/src/wayland/server/shell_interface.h +++ b/src/wayland/server/shell_interface.h @@ -280,6 +280,15 @@ Q_SIGNALS: * @since 5.5 **/ void moveRequested(KWayland::Server::SeatInterface *seat, quint32 serial); + /** + * The surface requested a window resize. + * + * @param seat The SeatInterface on which the surface requested the resize + * @param serial The serial of the implicit mouse grab which triggered the resize + * @param edges A hint which edges are involved in the resize + * @since 5.5 + **/ + void resizeRequested(KWayland::Server::SeatInterface *seat, quint32 serial, Qt::Edges edges); private: friend class ShellInterface;