diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index 7db5653121..1611fe6ab5 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -315,17 +315,17 @@ void TestWaylandSeat::testPointer() QCOMPARE(enteredSpy.first().last().toPoint(), QPoint(10, 3)); // test motion - serverPointer->updateTimestamp(1); + m_seatInterface->setTimestamp(1); serverPointer->setGlobalPos(QPoint(10, 16)); QVERIFY(motionSpy.wait()); QCOMPARE(motionSpy.first().first().toPoint(), QPoint(0, 1)); QCOMPARE(motionSpy.first().last().value(), quint32(1)); // test axis - serverPointer->updateTimestamp(2); + m_seatInterface->setTimestamp(2); serverPointer->axis(Qt::Horizontal, 10); QVERIFY(axisSpy.wait()); - serverPointer->updateTimestamp(3); + m_seatInterface->setTimestamp(3); serverPointer->axis(Qt::Vertical, 20); QVERIFY(axisSpy.wait()); QCOMPARE(axisSpy.first().at(0).value(), quint32(2)); @@ -337,19 +337,19 @@ void TestWaylandSeat::testPointer() QCOMPARE(axisSpy.last().at(2).value(), qreal(20)); // test button - serverPointer->updateTimestamp(4); + m_seatInterface->setTimestamp(4); serverPointer->buttonPressed(1); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(0).at(0).value(), m_display->serial()); - serverPointer->updateTimestamp(5); + m_seatInterface->setTimestamp(5); serverPointer->buttonPressed(2); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(1).at(0).value(), m_display->serial()); - serverPointer->updateTimestamp(6); + m_seatInterface->setTimestamp(6); serverPointer->buttonReleased(2); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(2).at(0).value(), m_display->serial()); - serverPointer->updateTimestamp(7); + m_seatInterface->setTimestamp(7); serverPointer->buttonReleased(1); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.count(), 4); @@ -461,7 +461,7 @@ void TestWaylandSeat::testPointerButton() quint32 msec = QDateTime::currentMSecsSinceEpoch(); QCOMPARE(serverPointer->isButtonPressed(waylandButton), false); QCOMPARE(serverPointer->isButtonPressed(qtButton), false); - serverPointer->updateTimestamp(msec); + m_seatInterface->setTimestamp(msec); serverPointer->buttonPressed(qtButton); QCOMPARE(serverPointer->isButtonPressed(waylandButton), true); QCOMPARE(serverPointer->isButtonPressed(qtButton), true); @@ -473,7 +473,7 @@ void TestWaylandSeat::testPointerButton() QCOMPARE(buttonChangedSpy.last().at(2).value(), waylandButton); QCOMPARE(buttonChangedSpy.last().at(3).value(), Pointer::ButtonState::Pressed); msec = QDateTime::currentMSecsSinceEpoch(); - serverPointer->updateTimestamp(QDateTime::currentMSecsSinceEpoch()); + m_seatInterface->setTimestamp(QDateTime::currentMSecsSinceEpoch()); serverPointer->buttonReleased(qtButton); QCOMPARE(serverPointer->isButtonPressed(waylandButton), false); QCOMPARE(serverPointer->isButtonPressed(qtButton), false); diff --git a/src/wayland/pointer_interface.cpp b/src/wayland/pointer_interface.cpp index a794d34edc..0060e21486 100644 --- a/src/wayland/pointer_interface.cpp +++ b/src/wayland/pointer_interface.cpp @@ -54,7 +54,6 @@ public: wl_resource *pointer = nullptr; }; QList resources; - quint32 eventTime = 0; struct FocusedSurface { SurfaceInterface *surface = nullptr; QPoint offset = QPoint(); @@ -99,7 +98,7 @@ PointerInterface::PointerInterface(SeatInterface *parent) connect(parent, &SeatInterface::pointerPosChanged, [this](const QPointF &pos) { if (d->focusedSurface.surface && d->focusedSurface.pointer) { const QPointF pos = d->seat->pointerPos() - d->focusedSurface.offset; - wl_pointer_send_motion(d->focusedSurface.pointer, d->eventTime, + wl_pointer_send_motion(d->focusedSurface.pointer, d->seat->timestamp(), wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); } }); @@ -188,11 +187,6 @@ void PointerInterface::setGlobalPos(const QPointF &pos) d->seat->setPointerPos(pos); } -void PointerInterface::updateTimestamp(quint32 time) -{ - d->eventTime = time; -} - static quint32 qtToWaylandButton(Qt::MouseButton button) { static const QHash s_buttons({ @@ -225,7 +219,7 @@ void PointerInterface::buttonPressed(quint32 button) if (!d->focusedSurface.surface || !d->focusedSurface.pointer) { return; } - wl_pointer_send_button(d->focusedSurface.pointer, serial, d->eventTime, button, WL_POINTER_BUTTON_STATE_PRESSED); + wl_pointer_send_button(d->focusedSurface.pointer, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_PRESSED); } void PointerInterface::buttonPressed(Qt::MouseButton button) @@ -245,7 +239,7 @@ void PointerInterface::buttonReleased(quint32 button) if (!d->focusedSurface.surface || !d->focusedSurface.pointer) { return; } - wl_pointer_send_button(d->focusedSurface.pointer, serial, d->eventTime, button, WL_POINTER_BUTTON_STATE_RELEASED); + wl_pointer_send_button(d->focusedSurface.pointer, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_RELEASED); } void PointerInterface::buttonReleased(Qt::MouseButton button) @@ -314,7 +308,7 @@ void PointerInterface::axis(Qt::Orientation orientation, quint32 delta) if (!d->focusedSurface.surface || !d->focusedSurface.pointer) { return; } - wl_pointer_send_axis(d->focusedSurface.pointer, d->eventTime, + wl_pointer_send_axis(d->focusedSurface.pointer, d->seat->timestamp(), (orientation == Qt::Vertical) ? WL_POINTER_AXIS_VERTICAL_SCROLL : WL_POINTER_AXIS_HORIZONTAL_SCROLL, wl_fixed_from_int(delta)); } diff --git a/src/wayland/pointer_interface.h b/src/wayland/pointer_interface.h index b7da71d805..cc5927f8b3 100644 --- a/src/wayland/pointer_interface.h +++ b/src/wayland/pointer_interface.h @@ -45,7 +45,6 @@ public: void createInterface(wl_client *client, wl_resource *parentResource, uint32_t id); - void updateTimestamp(quint32 time); /** * Convenient method to set the pointer position of the SeatInterface. * @see SeatInterface::setPointerPos diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index e7c92f695a..c20ec04dc7 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -54,6 +54,7 @@ public: QList resources; PointerInterface *pointerInterface = nullptr; KeyboardInterface *keyboardInterface = nullptr; + quint32 timestamp = 0; // Pointer related members QPointF pointerPos; @@ -286,5 +287,21 @@ void SeatInterface::setPointerPos(const QPointF &pos) emit pointerPosChanged(pos); } +quint32 SeatInterface::timestamp() const +{ + Q_D(); + return d->timestamp; +} + +void SeatInterface::setTimestamp(quint32 time) +{ + Q_D(); + if (d->timestamp == time) { + return; + } + d->timestamp = time; + emit timestampChanged(time); +} + } } diff --git a/src/wayland/seat_interface.h b/src/wayland/seat_interface.h index fa852b1a51..c9c9e1ab18 100644 --- a/src/wayland/seat_interface.h +++ b/src/wayland/seat_interface.h @@ -47,6 +47,7 @@ class KWAYLANDSERVER_EXPORT SeatInterface : public Global Q_PROPERTY(bool keyboard READ hasKeyboard WRITE setHasKeyboard NOTIFY hasKeyboardChanged) Q_PROPERTY(bool tourch READ hasTouch WRITE setHasTouch NOTIFY hasTouchChanged) Q_PROPERTY(QPointF pointerPos READ pointerPos WRITE setPointerPos NOTIFY pointerPosChanged) + Q_PROPERTY(quint32 timestamp READ timestamp WRITE setTimestamp NOTIFY timestampChanged) public: virtual ~SeatInterface(); @@ -62,6 +63,9 @@ public: void setHasKeyboard(bool has); void setHasTouch(bool has); + void setTimestamp(quint32 time); + quint32 timestamp() const; + // pointer related methods void setPointerPos(const QPointF &pos); QPointF pointerPos() const; @@ -74,6 +78,7 @@ Q_SIGNALS: void hasKeyboardChanged(bool); void hasTouchChanged(bool); void pointerPosChanged(const QPointF &pos); + void timestampChanged(quint32); private: friend class Display; diff --git a/src/wayland/tests/renderingservertest.cpp b/src/wayland/tests/renderingservertest.cpp index f6af3ed9ef..4276a18012 100644 --- a/src/wayland/tests/renderingservertest.cpp +++ b/src/wayland/tests/renderingservertest.cpp @@ -139,7 +139,7 @@ void CompositorWindow::mouseMoveEvent(QMouseEvent *event) pointer->setFocusedSurface(m_stackingOrder.last()->surface()); } } - pointer->updateTimestamp(event->timestamp()); + m_seat->setTimestamp(event->timestamp()); pointer->setGlobalPos(event->localPos().toPoint()); } @@ -152,7 +152,7 @@ void CompositorWindow::mousePressEvent(QMouseEvent *event) pointer->setFocusedSurface(m_stackingOrder.last()->surface()); } } - pointer->updateTimestamp(event->timestamp()); + m_seat->setTimestamp(event->timestamp()); pointer->buttonPressed(event->button()); } @@ -160,7 +160,7 @@ void CompositorWindow::mouseReleaseEvent(QMouseEvent *event) { QWidget::mouseReleaseEvent(event); const auto pointer = m_seat->pointer(); - pointer->updateTimestamp(event->timestamp()); + m_seat->setTimestamp(event->timestamp()); pointer->buttonReleased(event->button()); } @@ -168,7 +168,7 @@ void CompositorWindow::wheelEvent(QWheelEvent *event) { QWidget::wheelEvent(event); const auto pointer = m_seat->pointer(); - pointer->updateTimestamp(event->timestamp()); + m_seat->setTimestamp(event->timestamp()); const QPoint &angle = event->angleDelta() / (8 * 15); if (angle.x() != 0) { pointer->axis(Qt::Horizontal, angle.x());