From d425515a996223f1c97956ba10c1c34e946ffb0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 26 Nov 2014 11:50:52 +0100 Subject: [PATCH] Move pointer button handling from PointerInterface to SeatInterface The button state is a seat-global state and not a per pointer state. All pressed/released and axis events are moved to the SeatInterface and just invoke the related method on the focused surface pointer. --- .../autotests/client/test_datadevice.cpp | 4 +- .../autotests/client/test_wayland_seat.cpp | 40 +++--- src/wayland/autotests/server/test_seat.cpp | 43 ++---- src/wayland/pointer_interface.cpp | 130 +---------------- src/wayland/pointer_interface.h | 12 +- src/wayland/seat_interface.cpp | 135 ++++++++++++++++++ src/wayland/seat_interface.h | 9 ++ src/wayland/tests/renderingservertest.cpp | 16 +-- 8 files changed, 192 insertions(+), 197 deletions(-) diff --git a/src/wayland/autotests/client/test_datadevice.cpp b/src/wayland/autotests/client/test_datadevice.cpp index 14aa8eefec..2b3731aa07 100644 --- a/src/wayland/autotests/client/test_datadevice.cpp +++ b/src/wayland/autotests/client/test_datadevice.cpp @@ -237,7 +237,7 @@ void TestDataDevice::testDrag() // first we need to fake the pointer enter m_seatInterface->setFocusedPointerSurface(surfaceInterface); - m_seatInterface->focusedPointer()->buttonPressed(1); + m_seatInterface->pointerButtonPressed(1); QCoreApplication::processEvents(); @@ -289,7 +289,7 @@ void TestDataDevice::testDragInternally() // first we need to fake the pointer enter m_seatInterface->setFocusedPointerSurface(surfaceInterface); - m_seatInterface->focusedPointer()->buttonPressed(1); + m_seatInterface->pointerButtonPressed(1); QCoreApplication::processEvents(); diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index 9e04f067d8..3aeb2065e2 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -333,10 +333,10 @@ void TestWaylandSeat::testPointer() // test axis m_seatInterface->setTimestamp(2); - serverPointer->axis(Qt::Horizontal, 10); + m_seatInterface->pointerAxis(Qt::Horizontal, 10); QVERIFY(axisSpy.wait()); m_seatInterface->setTimestamp(3); - serverPointer->axis(Qt::Vertical, 20); + m_seatInterface->pointerAxis(Qt::Vertical, 20); QVERIFY(axisSpy.wait()); QCOMPARE(axisSpy.first().at(0).value(), quint32(2)); QCOMPARE(axisSpy.first().at(1).value(), Pointer::Axis::Horizontal); @@ -348,19 +348,19 @@ void TestWaylandSeat::testPointer() // test button m_seatInterface->setTimestamp(4); - serverPointer->buttonPressed(1); + m_seatInterface->pointerButtonPressed(1); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(0).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(5); - serverPointer->buttonPressed(2); + m_seatInterface->pointerButtonPressed(2); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(1).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(6); - serverPointer->buttonReleased(2); + m_seatInterface->pointerButtonReleased(2); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(2).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(7); - serverPointer->buttonReleased(1); + m_seatInterface->pointerButtonReleased(1); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.count(), 4); @@ -376,14 +376,14 @@ void TestWaylandSeat::testPointer() QCOMPARE(buttonSpy.at(1).at(2).value(), quint32(2)); QCOMPARE(buttonSpy.at(1).at(3).value(), KWayland::Client::Pointer::ButtonState::Pressed); - QCOMPARE(buttonSpy.at(2).at(0).value(), serverPointer->buttonSerial(2)); + QCOMPARE(buttonSpy.at(2).at(0).value(), m_seatInterface->pointerButtonSerial(2)); // timestamp QCOMPARE(buttonSpy.at(2).at(1).value(), quint32(6)); // button QCOMPARE(buttonSpy.at(2).at(2).value(), quint32(2)); QCOMPARE(buttonSpy.at(2).at(3).value(), KWayland::Client::Pointer::ButtonState::Released); - QCOMPARE(buttonSpy.at(3).at(0).value(), serverPointer->buttonSerial(1)); + QCOMPARE(buttonSpy.at(3).at(0).value(), m_seatInterface->pointerButtonSerial(1)); // timestamp QCOMPARE(buttonSpy.at(3).at(1).value(), quint32(7)); // button @@ -473,28 +473,28 @@ void TestWaylandSeat::testPointerButton() QFETCH(Qt::MouseButton, qtButton); QFETCH(quint32, waylandButton); quint32 msec = QDateTime::currentMSecsSinceEpoch(); - QCOMPARE(serverPointer->isButtonPressed(waylandButton), false); - QCOMPARE(serverPointer->isButtonPressed(qtButton), false); + QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false); + QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false); m_seatInterface->setTimestamp(msec); - serverPointer->buttonPressed(qtButton); - QCOMPARE(serverPointer->isButtonPressed(waylandButton), true); - QCOMPARE(serverPointer->isButtonPressed(qtButton), true); + m_seatInterface->pointerButtonPressed(qtButton); + QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), true); + QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), true); QVERIFY(buttonChangedSpy.wait()); QCOMPARE(buttonChangedSpy.count(), 1); - QCOMPARE(buttonChangedSpy.last().at(0).value(), serverPointer->buttonSerial(waylandButton)); - QCOMPARE(buttonChangedSpy.last().at(0).value(), serverPointer->buttonSerial(qtButton)); + QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(waylandButton)); + QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(qtButton)); QCOMPARE(buttonChangedSpy.last().at(1).value(), msec); QCOMPARE(buttonChangedSpy.last().at(2).value(), waylandButton); QCOMPARE(buttonChangedSpy.last().at(3).value(), Pointer::ButtonState::Pressed); msec = QDateTime::currentMSecsSinceEpoch(); m_seatInterface->setTimestamp(QDateTime::currentMSecsSinceEpoch()); - serverPointer->buttonReleased(qtButton); - QCOMPARE(serverPointer->isButtonPressed(waylandButton), false); - QCOMPARE(serverPointer->isButtonPressed(qtButton), false); + m_seatInterface->pointerButtonReleased(qtButton); + QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false); + QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false); QVERIFY(buttonChangedSpy.wait()); QCOMPARE(buttonChangedSpy.count(), 2); - QCOMPARE(buttonChangedSpy.last().at(0).value(), serverPointer->buttonSerial(waylandButton)); - QCOMPARE(buttonChangedSpy.last().at(0).value(), serverPointer->buttonSerial(qtButton)); + QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(waylandButton)); + QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(qtButton)); QCOMPARE(buttonChangedSpy.last().at(1).value(), msec); QCOMPARE(buttonChangedSpy.last().at(2).value(), waylandButton); QCOMPARE(buttonChangedSpy.last().at(3).value(), Pointer::ButtonState::Released); diff --git a/src/wayland/autotests/server/test_seat.cpp b/src/wayland/autotests/server/test_seat.cpp index a7921793f2..08064871ea 100644 --- a/src/wayland/autotests/server/test_seat.cpp +++ b/src/wayland/autotests/server/test_seat.cpp @@ -118,27 +118,25 @@ void TestWaylandServerSeat::testPointerButton() PointerInterface *pointer = seat->focusedPointer(); QVERIFY(!pointer); -#if 0 // no button pressed yet, should be released and no serial - QVERIFY(!pointer->isButtonPressed(0)); - QVERIFY(!pointer->isButtonPressed(1)); - QCOMPARE(pointer->buttonSerial(0), quint32(0)); - QCOMPARE(pointer->buttonSerial(1), quint32(0)); + QVERIFY(!seat->isPointerButtonPressed(0)); + QVERIFY(!seat->isPointerButtonPressed(1)); + QCOMPARE(seat->pointerButtonSerial(0), quint32(0)); + QCOMPARE(seat->pointerButtonSerial(1), quint32(0)); // mark the button as pressed - pointer->buttonPressed(0); - QVERIFY(pointer->isButtonPressed(0)); - QCOMPARE(pointer->buttonSerial(0), display.serial()); + seat->pointerButtonPressed(0); + QVERIFY(seat->isPointerButtonPressed(0)); + QCOMPARE(seat->pointerButtonSerial(0), display.serial()); // other button should still be unpressed - QVERIFY(!pointer->isButtonPressed(1)); - QCOMPARE(pointer->buttonSerial(1), quint32(0)); + QVERIFY(!seat->isPointerButtonPressed(1)); + QCOMPARE(seat->pointerButtonSerial(1), quint32(0)); // release it again - pointer->buttonReleased(0); - QVERIFY(!pointer->isButtonPressed(0)); - QCOMPARE(pointer->buttonSerial(0), display.serial()); -#endif + seat->pointerButtonReleased(0); + QVERIFY(!seat->isPointerButtonPressed(0)); + QCOMPARE(seat->pointerButtonSerial(0), display.serial()); } void TestWaylandServerSeat::testPointerPos() @@ -151,35 +149,22 @@ void TestWaylandServerSeat::testPointerPos() QVERIFY(seatPosSpy.isValid()); PointerInterface *pointer = seat->focusedPointer(); QVERIFY(!pointer); -#if 0 - QSignalSpy posSpy(pointer, SIGNAL(globalPosChanged(QPointF))); - QVERIFY(posSpy.isValid()); - QCOMPARE(pointer->globalPos(), QPointF()); QCOMPARE(seat->pointerPos(), QPointF()); - pointer->setGlobalPos(QPointF(10, 15)); - QCOMPARE(pointer->globalPos(), QPointF(10, 15)); + seat->setPointerPos(QPointF(10, 15)); QCOMPARE(seat->pointerPos(), QPointF(10, 15)); - QCOMPARE(posSpy.count(), 1); - QCOMPARE(posSpy.first().first().toPointF(), QPointF(10, 15)); QCOMPARE(seatPosSpy.count(), 1); QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15)); - pointer->setGlobalPos(QPointF(10, 15)); - QCOMPARE(posSpy.count(), 1); + seat->setPointerPos(QPointF(10, 15)); QCOMPARE(seatPosSpy.count(), 1); seat->setPointerPos(QPointF(5, 7)); - QCOMPARE(pointer->globalPos(), QPointF(5, 7)); QCOMPARE(seat->pointerPos(), QPointF(5, 7)); - QCOMPARE(posSpy.count(), 2); - QCOMPARE(posSpy.first().first().toPointF(), QPointF(10, 15)); - QCOMPARE(posSpy.last().first().toPointF(), QPointF(5, 7)); QCOMPARE(seatPosSpy.count(), 2); QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15)); QCOMPARE(seatPosSpy.last().first().toPointF(), QPointF(5, 7)); -#endif } void TestWaylandServerSeat::testDestroyThroughTerminate() diff --git a/src/wayland/pointer_interface.cpp b/src/wayland/pointer_interface.cpp index 153a440c3a..a12d8589d2 100644 --- a/src/wayland/pointer_interface.cpp +++ b/src/wayland/pointer_interface.cpp @@ -22,12 +22,8 @@ License along with this library. If not, see . #include "seat_interface.h" #include "display.h" #include "surface_interface.h" -// Qt -#include // Wayland #include -// linux -#include namespace KWayland { @@ -39,17 +35,9 @@ class PointerInterface::Private : public Resource::Private { public: Private(SeatInterface *parent, wl_resource *parentResource, PointerInterface *q); - void updateButtonSerial(quint32 button, quint32 serial); - enum class ButtonState { - Released, - Pressed - }; - void updateButtonState(quint32 button, ButtonState state); SeatInterface *seat; SurfaceInterface *focusedSurface = nullptr; - QHash buttonSerials; - QHash buttonStates; QMetaObject::Connection destroyConnection; private: @@ -122,132 +110,24 @@ void PointerInterface::setGlobalPos(const QPointF &pos) d->seat->setPointerPos(pos); } -static quint32 qtToWaylandButton(Qt::MouseButton button) -{ - static const QHash s_buttons({ - {Qt::LeftButton, BTN_LEFT}, - {Qt::RightButton, BTN_RIGHT}, - {Qt::MiddleButton, BTN_MIDDLE}, - {Qt::ExtraButton1, BTN_BACK}, // note: QtWayland maps BTN_SIDE - {Qt::ExtraButton2, BTN_FORWARD}, // note: QtWayland maps BTN_EXTRA - {Qt::ExtraButton3, BTN_TASK}, // note: QtWayland maps BTN_FORWARD - {Qt::ExtraButton4, BTN_EXTRA}, // note: QtWayland maps BTN_BACK - {Qt::ExtraButton5, BTN_SIDE}, // note: QtWayland maps BTN_TASK - {Qt::ExtraButton6, BTN_TASK + 1}, - {Qt::ExtraButton7, BTN_TASK + 2}, - {Qt::ExtraButton8, BTN_TASK + 3}, - {Qt::ExtraButton9, BTN_TASK + 4}, - {Qt::ExtraButton10, BTN_TASK + 5}, - {Qt::ExtraButton11, BTN_TASK + 6}, - {Qt::ExtraButton12, BTN_TASK + 7}, - {Qt::ExtraButton13, BTN_TASK + 8} - // further mapping not possible, 0x120 is BTN_JOYSTICK - }); - return s_buttons.value(button, 0); -}; - -void PointerInterface::buttonPressed(quint32 button) +void PointerInterface::buttonPressed(quint32 button, quint32 serial) { Q_D(); - const quint32 serial = d->seat->display()->nextSerial(); - d->updateButtonSerial(button, serial); - d->updateButtonState(button, Private::ButtonState::Pressed); - if (!d->focusedSurface) { - return; - } + Q_ASSERT(d->focusedSurface); wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_PRESSED); } -void PointerInterface::buttonPressed(Qt::MouseButton button) -{ - const quint32 nativeButton = qtToWaylandButton(button); - if (nativeButton == 0) { - return; - } - buttonPressed(nativeButton); -} - -void PointerInterface::buttonReleased(quint32 button) +void PointerInterface::buttonReleased(quint32 button, quint32 serial) { Q_D(); - const quint32 serial = d->seat->display()->nextSerial(); - d->updateButtonSerial(button, serial); - d->updateButtonState(button, Private::ButtonState::Released); - if (!d->focusedSurface) { - return; - } + Q_ASSERT(d->focusedSurface); wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_RELEASED); } -void PointerInterface::buttonReleased(Qt::MouseButton button) -{ - const quint32 nativeButton = qtToWaylandButton(button); - if (nativeButton == 0) { - return; - } - buttonReleased(nativeButton); -} - -void PointerInterface::Private::updateButtonSerial(quint32 button, quint32 serial) -{ - auto it = buttonSerials.find(button); - if (it == buttonSerials.end()) { - buttonSerials.insert(button, serial); - return; - } - it.value() = serial; -} - -quint32 PointerInterface::buttonSerial(quint32 button) const -{ - Q_D(); - auto it = d->buttonSerials.constFind(button); - if (it == d->buttonSerials.constEnd()) { - return 0; - } - return it.value(); -} - -quint32 PointerInterface::buttonSerial(Qt::MouseButton button) const -{ - return buttonSerial(qtToWaylandButton(button)); -} - -void PointerInterface::Private::updateButtonState(quint32 button, ButtonState state) -{ - auto it = buttonStates.find(button); - if (it == buttonStates.end()) { - buttonStates.insert(button, state); - return; - } - it.value() = state; -} - -bool PointerInterface::isButtonPressed(quint32 button) const -{ - Q_D(); - auto it = d->buttonStates.constFind(button); - if (it == d->buttonStates.constEnd()) { - return false; - } - return it.value() == Private::ButtonState::Pressed ? true : false; -} - -bool PointerInterface::isButtonPressed(Qt::MouseButton button) const -{ - const quint32 nativeButton = qtToWaylandButton(button); - if (nativeButton == 0) { - return false; - } - return isButtonPressed(nativeButton); -} - void PointerInterface::axis(Qt::Orientation orientation, quint32 delta) { Q_D(); - if (!d->focusedSurface) { - return; - } + Q_ASSERT(d->focusedSurface); wl_pointer_send_axis(d->resource, 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 bba06809ba..e9f13ea4b3 100644 --- a/src/wayland/pointer_interface.h +++ b/src/wayland/pointer_interface.h @@ -49,15 +49,6 @@ public: * @see SeatInterface::pointerPos **/ QPointF globalPos() const; - void buttonPressed(quint32 button); - void buttonPressed(Qt::MouseButton button); - void buttonReleased(quint32 button); - void buttonReleased(Qt::MouseButton button); - bool isButtonPressed(quint32 button) const; - bool isButtonPressed(Qt::MouseButton button) const; - quint32 buttonSerial(quint32 button) const; - quint32 buttonSerial(Qt::MouseButton button) const; - void axis(Qt::Orientation orientation, quint32 delta); Q_SIGNALS: /** @@ -69,6 +60,9 @@ Q_SIGNALS: private: void setFocusedSurface(SurfaceInterface *surface, quint32 serial); SurfaceInterface *focusedSurface() const; + void buttonPressed(quint32 button, quint32 serial); + void buttonReleased(quint32 button, quint32 serial); + void axis(Qt::Orientation orientation, quint32 delta); friend class SeatInterface; explicit PointerInterface(SeatInterface *parent, wl_resource *parentResource); class Private; diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index 270afac485..d7eef371ca 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -31,6 +31,8 @@ License along with this library. If not, see . #ifndef WL_SEAT_NAME_SINCE_VERSION #define WL_SEAT_NAME_SINCE_VERSION 2 #endif +// linux +#include namespace KWayland { @@ -68,6 +70,17 @@ public: // Pointer related members QPointF pointerPos; + struct Pointer { + enum class ButtonState { + Released, + Pressed + }; + QHash buttonSerials; + QHash buttonStates; + }; + Pointer globalPointer; + void updatePointerButtonSerial(quint32 button, quint32 serial); + void updatePointerButtonState(quint32 button, Pointer::ButtonState state); static SeatInterface *get(wl_resource *native) { auto s = cast(native); @@ -150,6 +163,26 @@ void SeatInterface::Private::unbind(wl_resource *r) cast(r)->resources.removeAll(r); } +void SeatInterface::Private::updatePointerButtonSerial(quint32 button, quint32 serial) +{ + auto it = globalPointer.buttonSerials.find(button); + if (it == globalPointer.buttonSerials.end()) { + globalPointer.buttonSerials.insert(button, serial); + return; + } + it.value() = serial; +} + +void SeatInterface::Private::updatePointerButtonState(quint32 button, Pointer::ButtonState state) +{ + auto it = globalPointer.buttonStates.find(button); + if (it == globalPointer.buttonStates.end()) { + globalPointer.buttonStates.insert(button, state); + return; + } + it.value() = state; +} + void SeatInterface::Private::sendName(wl_resource *r) { if (wl_resource_get_version(r) < WL_SEAT_NAME_SINCE_VERSION) { @@ -406,5 +439,107 @@ QPointF SeatInterface::focusedPointerSurfacePosition() const return d->focusedPointer.offset; } +static quint32 qtToWaylandButton(Qt::MouseButton button) +{ + static const QHash s_buttons({ + {Qt::LeftButton, BTN_LEFT}, + {Qt::RightButton, BTN_RIGHT}, + {Qt::MiddleButton, BTN_MIDDLE}, + {Qt::ExtraButton1, BTN_BACK}, // note: QtWayland maps BTN_SIDE + {Qt::ExtraButton2, BTN_FORWARD}, // note: QtWayland maps BTN_EXTRA + {Qt::ExtraButton3, BTN_TASK}, // note: QtWayland maps BTN_FORWARD + {Qt::ExtraButton4, BTN_EXTRA}, // note: QtWayland maps BTN_BACK + {Qt::ExtraButton5, BTN_SIDE}, // note: QtWayland maps BTN_TASK + {Qt::ExtraButton6, BTN_TASK + 1}, + {Qt::ExtraButton7, BTN_TASK + 2}, + {Qt::ExtraButton8, BTN_TASK + 3}, + {Qt::ExtraButton9, BTN_TASK + 4}, + {Qt::ExtraButton10, BTN_TASK + 5}, + {Qt::ExtraButton11, BTN_TASK + 6}, + {Qt::ExtraButton12, BTN_TASK + 7}, + {Qt::ExtraButton13, BTN_TASK + 8} + // further mapping not possible, 0x120 is BTN_JOYSTICK + }); + return s_buttons.value(button, 0); +}; + +bool SeatInterface::isPointerButtonPressed(Qt::MouseButton button) const +{ + return isPointerButtonPressed(qtToWaylandButton(button)); +} + +bool SeatInterface::isPointerButtonPressed(quint32 button) const +{ + Q_D(); + auto it = d->globalPointer.buttonStates.constFind(button); + if (it == d->globalPointer.buttonStates.constEnd()) { + return false; + } + return it.value() == Private::Pointer::ButtonState::Pressed ? true : false; +} + +void SeatInterface::pointerAxis(Qt::Orientation orientation, quint32 delta) +{ + Q_D(); + if (d->focusedPointer.pointer && d->focusedPointer.surface) { + d->focusedPointer.pointer->axis(orientation, delta); + } +} + +void SeatInterface::pointerButtonPressed(Qt::MouseButton button) +{ + const quint32 nativeButton = qtToWaylandButton(button); + if (nativeButton == 0) { + return; + } + pointerButtonPressed(nativeButton); +} + +void SeatInterface::pointerButtonPressed(quint32 button) +{ + Q_D(); + const quint32 serial = d->display->nextSerial(); + d->updatePointerButtonSerial(button, serial); + d->updatePointerButtonState(button, Private::Pointer::ButtonState::Pressed); + if (d->focusedPointer.pointer && d->focusedPointer.surface) { + d->focusedPointer.pointer->buttonPressed(button, serial); + } +} + +void SeatInterface::pointerButtonReleased(Qt::MouseButton button) +{ + const quint32 nativeButton = qtToWaylandButton(button); + if (nativeButton == 0) { + return; + } + pointerButtonReleased(nativeButton); +} + +void SeatInterface::pointerButtonReleased(quint32 button) +{ + Q_D(); + const quint32 serial = d->display->nextSerial(); + d->updatePointerButtonSerial(button, serial); + d->updatePointerButtonState(button, Private::Pointer::ButtonState::Released); + if (d->focusedPointer.pointer && d->focusedPointer.surface) { + d->focusedPointer.pointer->buttonReleased(button, serial); + } +} + +quint32 SeatInterface::pointerButtonSerial(Qt::MouseButton button) const +{ + return pointerButtonSerial(qtToWaylandButton(button)); +} + +quint32 SeatInterface::pointerButtonSerial(quint32 button) const +{ + Q_D(); + auto it = d->globalPointer.buttonSerials.constFind(button); + if (it == d->globalPointer.buttonSerials.constEnd()) { + return 0; + } + return it.value(); +} + } } diff --git a/src/wayland/seat_interface.h b/src/wayland/seat_interface.h index 06f0134b6b..f0e8bcb825 100644 --- a/src/wayland/seat_interface.h +++ b/src/wayland/seat_interface.h @@ -73,6 +73,15 @@ public: PointerInterface *focusedPointer() const; void setFocusedPointerSurfacePosition(const QPointF &surfacePosition); QPointF focusedPointerSurfacePosition() const; + void pointerButtonPressed(quint32 button); + void pointerButtonPressed(Qt::MouseButton button); + void pointerButtonReleased(quint32 button); + void pointerButtonReleased(Qt::MouseButton button); + bool isPointerButtonPressed(quint32 button) const; + bool isPointerButtonPressed(Qt::MouseButton button) const; + quint32 pointerButtonSerial(quint32 button) const; + quint32 pointerButtonSerial(Qt::MouseButton button) const; + void pointerAxis(Qt::Orientation orientation, quint32 delta); static SeatInterface *get(wl_resource *native); diff --git a/src/wayland/tests/renderingservertest.cpp b/src/wayland/tests/renderingservertest.cpp index 62d798fa25..78e006de55 100644 --- a/src/wayland/tests/renderingservertest.cpp +++ b/src/wayland/tests/renderingservertest.cpp @@ -151,34 +151,26 @@ void CompositorWindow::mousePressEvent(QMouseEvent *event) } } m_seat->setTimestamp(event->timestamp()); - if (auto pointer = m_seat->focusedPointer()) { - pointer->buttonPressed(event->button()); - } + m_seat->pointerButtonPressed(event->button()); } void CompositorWindow::mouseReleaseEvent(QMouseEvent *event) { QWidget::mouseReleaseEvent(event); m_seat->setTimestamp(event->timestamp()); - if (auto pointer = m_seat->focusedPointer()) { - pointer->buttonReleased(event->button()); - } + m_seat->pointerButtonReleased(event->button()); } void CompositorWindow::wheelEvent(QWheelEvent *event) { QWidget::wheelEvent(event); m_seat->setTimestamp(event->timestamp()); - const auto pointer = m_seat->focusedPointer(); - if (!pointer) { - return; - } const QPoint &angle = event->angleDelta() / (8 * 15); if (angle.x() != 0) { - pointer->axis(Qt::Horizontal, angle.x()); + m_seat->pointerAxis(Qt::Horizontal, angle.x()); } if (angle.y() != 0) { - pointer->axis(Qt::Vertical, angle.y()); + m_seat->pointerAxis(Qt::Vertical, angle.y()); } }