From 45fb1680fc7a8e14e6d10ef52e011a073e23ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 26 Oct 2015 13:25:47 +0100 Subject: [PATCH] Consider all client in Workspace::packPositionFoo We need to use m_allClients (AbstractClient) instead of clients (just Client). Thus packing against another AbstractClient works. --- autotests/wayland/move_resize_window_test.cpp | 87 +++++++++++++++++++ placement.cpp | 8 +- 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/autotests/wayland/move_resize_window_test.cpp b/autotests/wayland/move_resize_window_test.cpp index 43b238dc58..19c54419e8 100644 --- a/autotests/wayland/move_resize_window_test.cpp +++ b/autotests/wayland/move_resize_window_test.cpp @@ -54,6 +54,8 @@ private Q_SLOTS: void testMove(); void testPackTo_data(); void testPackTo(); + void testPackAgainstClient_data(); + void testPackAgainstClient(); private: KWayland::Client::ConnectionThread *m_connection = nullptr; @@ -286,6 +288,91 @@ void MoveResizeWindowTest::testPackTo() QTEST(c->geometry(), "expectedGeometry"); } +void MoveResizeWindowTest::testPackAgainstClient_data() +{ + QTest::addColumn("methodCall"); + QTest::addColumn("expectedGeometry"); + + QTest::newRow("left") << QStringLiteral("slotWindowPackLeft") << QRect(10, 487, 100, 50); + QTest::newRow("up") << QStringLiteral("slotWindowPackUp") << QRect(590, 10, 100, 50); + QTest::newRow("right") << QStringLiteral("slotWindowPackRight") << QRect(1170, 487, 100, 50); + QTest::newRow("down") << QStringLiteral("slotWindowPackDown") << QRect(590, 964, 100, 50); +} + +void MoveResizeWindowTest::testPackAgainstClient() +{ + using namespace KWayland::Client; + + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + + QScopedPointer surface1(m_compositor->createSurface()); + QVERIFY(!surface1.isNull()); + QScopedPointer surface2(m_compositor->createSurface()); + QVERIFY(!surface2.isNull()); + QScopedPointer surface3(m_compositor->createSurface()); + QVERIFY(!surface3.isNull()); + QScopedPointer surface4(m_compositor->createSurface()); + QVERIFY(!surface4.isNull()); + + QScopedPointer shellSurface1(m_shell->createSurface(surface1.data())); + QVERIFY(!shellSurface1.isNull()); + QScopedPointer shellSurface2(m_shell->createSurface(surface2.data())); + QVERIFY(!shellSurface2.isNull()); + QScopedPointer shellSurface3(m_shell->createSurface(surface3.data())); + QVERIFY(!shellSurface3.isNull()); + QScopedPointer shellSurface4(m_shell->createSurface(surface4.data())); + QVERIFY(!shellSurface4.isNull()); + auto renderWindow = [this, &clientAddedSpy] (Surface *surface, const QString &methodCall, const QRect &expectedGeometry) { + // let's render + QImage img(QSize(10, 10), QImage::Format_ARGB32); + img.fill(Qt::blue); + surface->attachBuffer(m_shm->createBuffer(img)); + surface->damage(QRect(0, 0, 10, 10)); + surface->commit(Surface::CommitFlag::None); + + m_connection->flush(); + QVERIFY(clientAddedSpy.wait()); + AbstractClient *c = workspace()->activeClient(); + QVERIFY(c); + QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(c->geometry().size(), QSize(10, 10)); + clientAddedSpy.clear(); + // let's place it centered + Placement::self()->placeCentered(c, QRect(0, 0, 1280, 1024)); + QCOMPARE(c->geometry(), QRect(635, 507, 10, 10)); + QMetaObject::invokeMethod(workspace(), methodCall.toLocal8Bit().constData()); + QCOMPARE(c->geometry(), expectedGeometry); + }; + renderWindow(surface1.data(), QStringLiteral("slotWindowPackLeft"), QRect(0, 507, 10, 10)); + renderWindow(surface2.data(), QStringLiteral("slotWindowPackUp"), QRect(635, 0, 10, 10)); + renderWindow(surface3.data(), QStringLiteral("slotWindowPackRight"), QRect(1270, 507, 10, 10)); + renderWindow(surface4.data(), QStringLiteral("slotWindowPackDown"), QRect(635, 1014, 10, 10)); + + QScopedPointer surface(m_compositor->createSurface()); + QVERIFY(!surface.isNull()); + QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QVERIFY(!shellSurface.isNull()); + QImage img(QSize(100, 50), QImage::Format_ARGB32); + img.fill(Qt::blue); + surface->attachBuffer(m_shm->createBuffer(img)); + surface->damage(QRect(0, 0, 100, 50)); + surface->commit(Surface::CommitFlag::None); + + m_connection->flush(); + QVERIFY(clientAddedSpy.wait()); + AbstractClient *c = workspace()->activeClient(); + QVERIFY(c); + QCOMPARE(clientAddedSpy.first().first().value(), c); + // let's place it centered + Placement::self()->placeCentered(c, QRect(0, 0, 1280, 1024)); + QCOMPARE(c->geometry(), QRect(590, 487, 100, 50)); + + QFETCH(QString, methodCall); + QMetaObject::invokeMethod(workspace(), methodCall.toLocal8Bit().constData()); + QTEST(c->geometry(), "expectedGeometry"); +} + } WAYLANTEST_MAIN(KWin::MoveResizeWindowTest) diff --git a/placement.cpp b/placement.cpp index 89dfea2ace..4379963343 100644 --- a/placement.cpp +++ b/placement.cpp @@ -891,7 +891,7 @@ int Workspace::packPositionLeft(const AbstractClient* cl, int oldx, bool left_ed if (oldx <= newx) return oldx; const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop(); - for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) { + for (auto it = m_allClients.constBegin(), end = m_allClients.constEnd(); it != end; ++it) { if (isIrrelevant(*it, cl, desktop)) continue; int x = left_edge ? (*it)->geometry().right() + 1 : (*it)->geometry().left() - 1; @@ -919,7 +919,7 @@ int Workspace::packPositionRight(const AbstractClient* cl, int oldx, bool right_ if (oldx >= newx) return oldx; const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop(); - for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) { + for (auto it = m_allClients.constBegin(), end = m_allClients.constEnd(); it != end; ++it) { if (isIrrelevant(*it, cl, desktop)) continue; int x = right_edge ? (*it)->geometry().left() - 1 : (*it)->geometry().right() + 1; @@ -947,7 +947,7 @@ int Workspace::packPositionUp(const AbstractClient* cl, int oldy, bool top_edge) if (oldy <= newy) return oldy; const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop(); - for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) { + for (auto it = m_allClients.constBegin(), end = m_allClients.constEnd(); it != end; ++it) { if (isIrrelevant(*it, cl, desktop)) continue; int y = top_edge ? (*it)->geometry().bottom() + 1 : (*it)->geometry().top() - 1; @@ -975,7 +975,7 @@ int Workspace::packPositionDown(const AbstractClient* cl, int oldy, bool bottom_ if (oldy >= newy) return oldy; const int desktop = cl->desktop() == 0 || cl->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : cl->desktop(); - for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) { + for (auto it = m_allClients.constBegin(), end = m_allClients.constEnd(); it != end; ++it) { if (isIrrelevant(*it, cl, desktop)) continue; int y = bottom_edge ? (*it)->geometry().top() - 1 : (*it)->geometry().bottom() + 1;