diff --git a/abstract_client.cpp b/abstract_client.cpp index 8820e6d0fe..b3230300cf 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -1379,9 +1379,10 @@ void AbstractClient::layoutDecorationRects(QRect &left, QRect &top, QRect &right borderRight(), r.height() - top.height() - bottom.height()); } -void AbstractClient::processDecorationMove() +void AbstractClient::processDecorationMove(const QPoint &localPos, const QPoint &globalPos) { if (isMoveResizePointerButtonDown()) { + handleMoveResize(localPos.x(), localPos.y(), globalPos.x(), globalPos.y()); return; } // TODO: handle modifiers diff --git a/abstract_client.h b/abstract_client.h index fff6febf01..4a65c2f7f9 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -523,7 +523,7 @@ public: bool decorationHasAlpha() const; void triggerDecorationRepaint(); virtual void layoutDecorationRects(QRect &left, QRect &top, QRect &right, QRect &bottom) const; - void processDecorationMove(); + void processDecorationMove(const QPoint &localPos, const QPoint &globalPos); bool processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu = false); void processDecorationButtonRelease(QMouseEvent *event); diff --git a/autotests/wayland/decoration_input_test.cpp b/autotests/wayland/decoration_input_test.cpp index ec31d5f78b..07bee5201d 100644 --- a/autotests/wayland/decoration_input_test.cpp +++ b/autotests/wayland/decoration_input_test.cpp @@ -58,6 +58,7 @@ private Q_SLOTS: void testAxis(); void testDoubleClick(); void testHover(); + void testPressToMove_data(); void testPressToMove(); private: @@ -325,46 +326,63 @@ void DecorationInputTest::testHover() QCOMPARE(c->cursor(), Qt::ArrowCursor); } +void DecorationInputTest::testPressToMove_data() +{ + QTest::addColumn("offset"); + QTest::addColumn("offset2"); + QTest::addColumn("offset3"); + + QTest::newRow("To right") << QPoint(10, 0) << QPoint(20, 0) << QPoint(30, 0); + QTest::newRow("To left") << QPoint(-10, 0) << QPoint(-20, 0) << QPoint(-30, 0); + QTest::newRow("To bottom") << QPoint(0, 10) << QPoint(0, 20) << QPoint(0, 30); + QTest::newRow("To top") << QPoint(0, -10) << QPoint(0, -20) << QPoint(0, -30); +} + void DecorationInputTest::testPressToMove() { AbstractClient *c = showWindow(); QVERIFY(c); QVERIFY(c->isDecorated()); QVERIFY(!c->noBorder()); + c->move(screens()->geometry(0).center() - QPoint(c->width()/2, c->height()/2)); QSignalSpy startMoveResizedSpy(c, &AbstractClient::clientStartUserMovedResized); QVERIFY(startMoveResizedSpy.isValid()); QSignalSpy clientFinishUserMovedResizedSpy(c, &AbstractClient::clientFinishUserMovedResized); QVERIFY(clientFinishUserMovedResizedSpy.isValid()); quint32 timestamp = 1; - MOTION(QPoint(c->geometry().center().x(), c->clientPos().y() / 2)); + MOTION(QPoint(c->geometry().center().x(), c->y() + c->clientPos().y() / 2)); QCOMPARE(c->cursor(), Qt::ArrowCursor); PRESS; QVERIFY(!c->isMove()); - MOTION(QPoint(c->geometry().center().x() + 10, c->clientPos().y() / 2)); - const int oldX = c->x(); - QTRY_VERIFY(c->isMove()); + QFETCH(QPoint, offset); + MOTION(QPoint(c->geometry().center().x(), c->y() + c->clientPos().y() / 2) + offset); + const QPoint oldPos = c->pos(); + QVERIFY(c->isMove()); QCOMPARE(startMoveResizedSpy.count(), 1); RELEASE; QTRY_VERIFY(!c->isMove()); QCOMPARE(clientFinishUserMovedResizedSpy.count(), 1); QEXPECT_FAIL("", "Just trigger move doesn't move the window", Continue); - QCOMPARE(c->x(), oldX + 10); + QCOMPARE(c->pos(), oldPos + offset); // again PRESS; QVERIFY(!c->isMove()); - MOTION(QPoint(c->geometry().center().x() + 20, c->clientPos().y() / 2)); - QTRY_VERIFY(c->isMove()); + QFETCH(QPoint, offset2); + MOTION(QPoint(c->geometry().center().x(), c->y() + c->clientPos().y() / 2) + offset2); + QVERIFY(c->isMove()); QCOMPARE(startMoveResizedSpy.count(), 2); - MOTION(QPoint(c->geometry().center().x() + 30, c->clientPos().y() / 2)); + QFETCH(QPoint, offset3); + MOTION(QPoint(c->geometry().center().x(), c->y() + c->clientPos().y() / 2) + offset3); RELEASE; QTRY_VERIFY(!c->isMove()); QCOMPARE(clientFinishUserMovedResizedSpy.count(), 2); - QCOMPARE(c->x(), oldX + 20); + // TODO: the offset should also be included + QCOMPARE(c->pos(), oldPos + offset2 + offset3); } } diff --git a/input.cpp b/input.cpp index e216b78106..5405bf3c50 100644 --- a/input.cpp +++ b/input.cpp @@ -432,7 +432,7 @@ public: } QHoverEvent e(QEvent::HoverMove, p, p); QCoreApplication::instance()->sendEvent(decoration->decoration(), &e); - decoration->client()->processDecorationMove(); + decoration->client()->processDecorationMove(p.toPoint(), event->globalPos()); return true; } case QEvent::MouseButtonPress: diff --git a/pointer_input.cpp b/pointer_input.cpp index 229c738292..5a91a7ce60 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -396,7 +396,7 @@ void PointerInputRedirection::updateDecoration(Toplevel *t) const QPointF p = m_pos - t->pos(); QHoverEvent event(QEvent::HoverMove, p, p); QCoreApplication::instance()->sendEvent(m_decoration->decoration(), &event); - m_decoration->client()->processDecorationMove(); + m_decoration->client()->processDecorationMove(p.toPoint(), m_pos.toPoint()); } }