From f1215e44d448a78224b80f386f0581cb5593d9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 26 Oct 2015 15:49:03 +0100 Subject: [PATCH] Move implementation of (shrow|grow)(Horizontal|Vertical) to AbstractClient Methods are no longer virtual. The only x11 specific usage in these methods (resizeInc) is replaced by a virtual method. Default resize increments is QSize(1,1) for AbstractClient. --- abstract_client.cpp | 21 ++---- abstract_client.h | 10 ++- autotests/wayland/move_resize_window_test.cpp | 75 +++++++++++++++++++ client.cpp | 5 ++ client.h | 6 +- placement.cpp | 16 ++-- 6 files changed, 100 insertions(+), 33 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index 562384c858..c101c55b87 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -93,22 +93,6 @@ bool AbstractClient::isCurrentTab() const return true; } -void AbstractClient::growHorizontal() -{ -} - -void AbstractClient::growVertical() -{ -} - -void AbstractClient::shrinkHorizontal() -{ -} - -void AbstractClient::shrinkVertical() -{ -} - xcb_timestamp_t AbstractClient::userTime() const { return XCB_TIME_CURRENT_TIME; @@ -1302,4 +1286,9 @@ void AbstractClient::keyPressEvent(uint key_code) Cursor::setPos(pos); } +QSize AbstractClient::resizeIncrements() const +{ + return QSize(1, 1); +} + } diff --git a/abstract_client.h b/abstract_client.h index 1048bb7ece..0deab5b213 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -359,10 +359,10 @@ public: virtual xcb_timestamp_t userTime() const; virtual void updateWindowRules(Rules::Types selection) = 0; - virtual void growHorizontal(); - virtual void shrinkHorizontal(); - virtual void growVertical(); - virtual void shrinkVertical(); + void growHorizontal(); + void shrinkHorizontal(); + void growVertical(); + void shrinkVertical(); void updateMoveResize(const QPointF ¤tGlobalCursor); void keyPressEvent(uint key_code); @@ -746,6 +746,8 @@ protected: void handleMoveResize(int x, int y, int x_root, int y_root); void handleMoveResize(const QPoint &local, const QPoint &global); + virtual QSize resizeIncrements() const; + static bool haveResizeEffect() { return s_haveResizeEffect; } diff --git a/autotests/wayland/move_resize_window_test.cpp b/autotests/wayland/move_resize_window_test.cpp index 19c54419e8..152dc987a1 100644 --- a/autotests/wayland/move_resize_window_test.cpp +++ b/autotests/wayland/move_resize_window_test.cpp @@ -56,6 +56,8 @@ private Q_SLOTS: void testPackTo(); void testPackAgainstClient_data(); void testPackAgainstClient(); + void testGrowShrink_data(); + void testGrowShrink(); private: KWayland::Client::ConnectionThread *m_connection = nullptr; @@ -373,6 +375,79 @@ void MoveResizeWindowTest::testPackAgainstClient() QTEST(c->geometry(), "expectedGeometry"); } +void MoveResizeWindowTest::testGrowShrink_data() +{ + QTest::addColumn("methodCall"); + QTest::addColumn("expectedGeometry"); + + QTest::newRow("grow vertical") << QStringLiteral("slotWindowGrowVertical") << QRect(590, 487, 100, 537); + QTest::newRow("grow horizontal") << QStringLiteral("slotWindowGrowHorizontal") << QRect(590, 487, 690, 50); + QTest::newRow("shrink vertical") << QStringLiteral("slotWindowShrinkVertical") << QRect(590, 487, 100, 23); + QTest::newRow("shrink horizontal") << QStringLiteral("slotWindowShrinkHorizontal") << QRect(590, 487, 40, 50); +} + +void MoveResizeWindowTest::testGrowShrink() +{ + using namespace KWayland::Client; + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + + // block geometry helper + QScopedPointer surface1(m_compositor->createSurface()); + QVERIFY(!surface1.isNull()); + QScopedPointer shellSurface1(m_shell->createSurface(surface1.data())); + QVERIFY(!shellSurface1.isNull()); + QImage img1(QSize(650, 514), QImage::Format_ARGB32); + img1.fill(Qt::blue); + surface1->attachBuffer(m_shm->createBuffer(img1)); + surface1->damage(QRect(0, 0, 650, 514)); + surface1->commit(Surface::CommitFlag::None); + m_connection->flush(); + QVERIFY(clientAddedSpy.wait()); + clientAddedSpy.clear(); + workspace()->slotWindowPackRight(); + workspace()->slotWindowPackDown(); + + QScopedPointer surface(m_compositor->createSurface()); + QVERIFY(!surface.isNull()); + + QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QVERIFY(!shellSurface.isNull()); + QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); + QVERIFY(sizeChangeSpy.isValid()); + // let's render + 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()); + QVERIFY(sizeChangeSpy.wait()); + QImage img2(shellSurface->size(), QImage::Format_ARGB32); + img2.fill(Qt::red); + surface->attachBuffer(m_shm->createBuffer(img2)); + surface->damage(QRect(QPoint(0, 0), shellSurface->size())); + surface->commit(Surface::CommitFlag::None); + + QSignalSpy geometryChangedSpy(c, &AbstractClient::geometryChanged); + QVERIFY(geometryChangedSpy.isValid()); + m_connection->flush(); + QVERIFY(geometryChangedSpy.wait()); + QTEST(c->geometry(), "expectedGeometry"); +} + } WAYLANTEST_MAIN(KWin::MoveResizeWindowTest) diff --git a/client.cpp b/client.cpp index ee1f37cc46..dbadafee98 100644 --- a/client.cpp +++ b/client.cpp @@ -2250,6 +2250,11 @@ void Client::updateTabGroupStates(TabGroup::States states) } } +QSize Client::resizeIncrements() const +{ + return m_geometryHints.resizeIncrements(); +} + } // namespace #include "client.moc" diff --git a/client.h b/client.h index cb72f06888..0bdc0e9e6c 100644 --- a/client.h +++ b/client.h @@ -263,11 +263,6 @@ public: void resizeWithChecks(const QSize& s, xcb_gravity_t gravity, ForceGeometry_t force = NormalGeometrySet); QSize sizeForClientSize(const QSize&, Sizemode mode = SizemodeAny, bool noframe = false) const override; - void growHorizontal() override; - void shrinkHorizontal() override; - void growVertical() override; - void shrinkVertical() override; - bool providesContextHelp() const; const QKeySequence &shortcut() const override; void setShortcut(const QString& cut) override; @@ -468,6 +463,7 @@ protected: void doPerformMoveResize() override; bool isWaitingForMoveResizeSync() const override; void doResizeSync() override; + QSize resizeIncrements() const override; private Q_SLOTS: void delayedSetShortcut(); diff --git a/placement.cpp b/placement.cpp index 4379963343..da8121aeb7 100644 --- a/placement.cpp +++ b/placement.cpp @@ -721,15 +721,15 @@ void Workspace::slotWindowGrowHorizontal() active_client->growHorizontal(); } -void Client::growHorizontal() +void AbstractClient::growHorizontal() { if (!isResizable() || isShade()) return; QRect geom = geometry(); geom.setRight(workspace()->packPositionRight(this, geom.right(), true)); QSize adjsize = adjustedSize(geom.size(), SizemodeFixedW); - if (geometry().size() == adjsize && geom.size() != adjsize && m_geometryHints.resizeIncrements().width() > 1) { // take care of size increments - int newright = workspace()->packPositionRight(this, geom.right() + m_geometryHints.resizeIncrements().width() - 1, true); + if (geometry().size() == adjsize && geom.size() != adjsize && resizeIncrements().width() > 1) { // take care of size increments + int newright = workspace()->packPositionRight(this, geom.right() + resizeIncrements().width() - 1, true); // check that it hasn't grown outside of the area, due to size increments // TODO this may be wrong? if (workspace()->clientArea(MovementArea, @@ -748,7 +748,7 @@ void Workspace::slotWindowShrinkHorizontal() active_client->shrinkHorizontal(); } -void Client::shrinkHorizontal() +void AbstractClient::shrinkHorizontal() { if (!isResizable() || isShade()) return; @@ -769,15 +769,15 @@ void Workspace::slotWindowGrowVertical() active_client->growVertical(); } -void Client::growVertical() +void AbstractClient::growVertical() { if (!isResizable() || isShade()) return; QRect geom = geometry(); geom.setBottom(workspace()->packPositionDown(this, geom.bottom(), true)); QSize adjsize = adjustedSize(geom.size(), SizemodeFixedH); - if (geometry().size() == adjsize && geom.size() != adjsize && m_geometryHints.resizeIncrements().height() > 1) { // take care of size increments - int newbottom = workspace()->packPositionDown(this, geom.bottom() + m_geometryHints.resizeIncrements().height() - 1, true); + if (geometry().size() == adjsize && geom.size() != adjsize && resizeIncrements().height() > 1) { // take care of size increments + int newbottom = workspace()->packPositionDown(this, geom.bottom() + resizeIncrements().height() - 1, true); // check that it hasn't grown outside of the area, due to size increments if (workspace()->clientArea(MovementArea, QPoint(geometry().center().x(), (y() + newbottom) / 2), desktop()).bottom() >= newbottom) @@ -795,7 +795,7 @@ void Workspace::slotWindowShrinkVertical() active_client->shrinkVertical(); } -void Client::shrinkVertical() +void AbstractClient::shrinkVertical() { if (!isResizable() || isShade()) return;