From a50f84a86808fdb6e99101e2f9e28fc4e3de56c1 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 15 Mar 2021 19:58:39 +0200 Subject: [PATCH] Merge notifyPointerPress() and notifyPointerRelease() This brings the API of the SeatInterface class and the PointerInterface class closer the corresponding Wayland API. --- .../autotests/client/test_datadevice.cpp | 8 +-- .../autotests/client/test_drag_drop.cpp | 16 ++--- .../autotests/client/test_wayland_seat.cpp | 20 +++--- src/wayland/autotests/server/test_seat.cpp | 4 +- src/wayland/pointer_interface.cpp | 18 +---- src/wayland/pointer_interface.h | 4 +- src/wayland/seat_interface.cpp | 70 ++++++++----------- src/wayland/seat_interface.h | 35 ++++------ src/wayland/tests/renderingservertest.cpp | 4 +- 9 files changed, 73 insertions(+), 106 deletions(-) diff --git a/src/wayland/autotests/client/test_datadevice.cpp b/src/wayland/autotests/client/test_datadevice.cpp index a361f2b751..36914aba29 100644 --- a/src/wayland/autotests/client/test_datadevice.cpp +++ b/src/wayland/autotests/client/test_datadevice.cpp @@ -251,14 +251,14 @@ void TestDataDevice::testDrag() QFETCH(bool, success); if (!hasGrab) { // in case we don't have grab, still generate a pointer serial to make it more interesting - m_seatInterface->notifyPointerPress(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); } if (hasPointerFocus) { m_seatInterface->setFocusedPointerSurface(surfaceInterface); } if (hasGrab) { - m_seatInterface->notifyPointerPress(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); } @@ -332,14 +332,14 @@ void TestDataDevice::testDragInternally() QFETCH(bool, success); if (!hasGrab) { // in case we don't have grab, still generate a pointer serial to make it more interesting - m_seatInterface->notifyPointerPress(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); } if (hasPointerFocus) { m_seatInterface->setFocusedPointerSurface(surfaceInterface); } if (hasGrab) { - m_seatInterface->notifyPointerPress(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); } diff --git a/src/wayland/autotests/client/test_drag_drop.cpp b/src/wayland/autotests/client/test_drag_drop.cpp index 42cfb80ab1..a04fb1f81b 100644 --- a/src/wayland/autotests/client/test_drag_drop.cpp +++ b/src/wayland/autotests/client/test_drag_drop.cpp @@ -206,7 +206,7 @@ void TestDragAndDrop::testPointerDragAndDrop() QVERIFY(buttonPressSpy.isValid()); m_seatInterface->setFocusedPointerSurface(serverSurface); m_seatInterface->setTimestamp(2); - m_seatInterface->notifyPointerPress(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonPressSpy.wait()); QCOMPARE(buttonPressSpy.first().at(1).value(), quint32(2)); @@ -267,7 +267,7 @@ void TestDragAndDrop::testPointerDragAndDrop() QSignalSpy droppedSpy(m_dataDevice, &DataDevice::dropped); QVERIFY(droppedSpy.isValid()); m_seatInterface->setTimestamp(4); - m_seatInterface->notifyPointerRelease(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(sourceDropSpy.isEmpty()); QVERIFY(droppedSpy.wait()); @@ -405,7 +405,7 @@ void TestDragAndDrop::testDragAndDropWithCancelByDestroyDataSource() QVERIFY(buttonPressSpy.isValid()); m_seatInterface->setFocusedPointerSurface(serverSurface); m_seatInterface->setTimestamp(2); - m_seatInterface->notifyPointerPress(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonPressSpy.wait()); QCOMPARE(buttonPressSpy.first().at(1).value(), quint32(2)); @@ -474,7 +474,7 @@ void TestDragAndDrop::testDragAndDropWithCancelByDestroyDataSource() QSignalSpy droppedSpy(m_dataDevice, &DataDevice::dropped); QVERIFY(droppedSpy.isValid()); m_seatInterface->setTimestamp(4); - m_seatInterface->notifyPointerRelease(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(!droppedSpy.wait(500)); @@ -527,7 +527,7 @@ void TestDragAndDrop::testPointerEventsIgnored() // let's start the drag m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerPress(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.count(), 1); @@ -536,10 +536,10 @@ void TestDragAndDrop::testPointerEventsIgnored() // now simulate all the possible pointer interactions m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerPress(2); + m_seatInterface->notifyPointerButton(2, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerRelease(2); + m_seatInterface->notifyPointerButton(2, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); m_seatInterface->setTimestamp(timestamp++); m_seatInterface->notifyPointerAxis(Qt::Vertical, 5, 1, PointerAxisSource::Wheel); @@ -561,7 +561,7 @@ void TestDragAndDrop::testPointerEventsIgnored() QSignalSpy cancelledSpy(m_dataSource, &DataSource::cancelled); QVERIFY(cancelledSpy.isValid()); m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerRelease(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(cancelledSpy.wait()); diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index ae68a2401d..73f18ce0c7 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -437,25 +437,25 @@ void TestWaylandSeat::testPointer() // test button m_seatInterface->setTimestamp(4); - m_seatInterface->notifyPointerPress(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonSpy.wait()); QCOMPARE(frameSpy.count(), 8); QCOMPARE(buttonSpy.at(0).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(5); - m_seatInterface->notifyPointerPress(2); + m_seatInterface->notifyPointerButton(2, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonSpy.wait()); QCOMPARE(frameSpy.count(), 9); QCOMPARE(buttonSpy.at(1).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(6); - m_seatInterface->notifyPointerRelease(2); + m_seatInterface->notifyPointerButton(2, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonSpy.wait()); QCOMPARE(frameSpy.count(), 10); QCOMPARE(buttonSpy.at(2).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(7); - m_seatInterface->notifyPointerRelease(1); + m_seatInterface->notifyPointerButton(1, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(buttonSpy.wait()); QCOMPARE(frameSpy.count(), 11); @@ -698,7 +698,7 @@ void TestWaylandSeat::testPointerButton() QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false); QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false); m_seatInterface->setTimestamp(msec); - m_seatInterface->notifyPointerPress(qtButton); + m_seatInterface->notifyPointerButton(qtButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), true); QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), true); @@ -711,7 +711,7 @@ void TestWaylandSeat::testPointerButton() QCOMPARE(buttonChangedSpy.last().at(3).value(), Pointer::ButtonState::Pressed); msec = QDateTime::currentMSecsSinceEpoch(); m_seatInterface->setTimestamp(QDateTime::currentMSecsSinceEpoch()); - m_seatInterface->notifyPointerRelease(qtButton); + m_seatInterface->notifyPointerButton(qtButton, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false); QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false); @@ -1264,10 +1264,10 @@ void TestWaylandSeat::testKeyboardSubSurfaceTreeFromPointer() // let's click m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerPress(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerRelease(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(enterSpy.wait()); QCOMPARE(enterSpy.count(), 2); @@ -1276,10 +1276,10 @@ void TestWaylandSeat::testKeyboardSubSurfaceTreeFromPointer() // click on same surface should not trigger another enter m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerPress(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); m_seatInterface->notifyPointerFrame(); m_seatInterface->setTimestamp(timestamp++); - m_seatInterface->notifyPointerRelease(Qt::LeftButton); + m_seatInterface->notifyPointerButton(Qt::LeftButton, PointerButtonState::Released); m_seatInterface->notifyPointerFrame(); QVERIFY(!enterSpy.wait(200)); QCOMPARE(enterSpy.count(), 2); diff --git a/src/wayland/autotests/server/test_seat.cpp b/src/wayland/autotests/server/test_seat.cpp index ba767dafe9..718b89f272 100644 --- a/src/wayland/autotests/server/test_seat.cpp +++ b/src/wayland/autotests/server/test_seat.cpp @@ -112,7 +112,7 @@ void TestWaylandServerSeat::testPointerButton() QCOMPARE(seat->pointerButtonSerial(1), quint32(0)); // mark the button as pressed - seat->notifyPointerPress(0); + seat->notifyPointerButton(0, PointerButtonState::Pressed); seat->notifyPointerFrame(); QVERIFY(seat->isPointerButtonPressed(0)); QCOMPARE(seat->pointerButtonSerial(0), display.serial()); @@ -122,7 +122,7 @@ void TestWaylandServerSeat::testPointerButton() QCOMPARE(seat->pointerButtonSerial(1), quint32(0)); // release it again - seat->notifyPointerRelease(0); + seat->notifyPointerButton(0, PointerButtonState::Released); seat->notifyPointerFrame(); QVERIFY(!seat->isPointerButtonPressed(0)); QCOMPARE(seat->pointerButtonSerial(0), display.serial()); diff --git a/src/wayland/pointer_interface.cpp b/src/wayland/pointer_interface.cpp index ae7a1ffa31..dc7a5bd16a 100644 --- a/src/wayland/pointer_interface.cpp +++ b/src/wayland/pointer_interface.cpp @@ -190,7 +190,7 @@ void PointerInterface::setFocusedSurface(SurfaceInterface *surface, const QPoint emit focusedSurfaceChanged(); } -void PointerInterface::sendPress(quint32 button, quint32 serial) +void PointerInterface::sendButton(quint32 button, PointerButtonState state, quint32 serial) { if (!d->focusedSurface) { return; @@ -198,21 +198,7 @@ void PointerInterface::sendPress(quint32 button, quint32 serial) const auto pointerResources = d->pointersForClient(d->focusedSurface->client()); for (PointerInterfacePrivate::Resource *resource : pointerResources) { - d->send_button(resource->handle, serial, d->seat->timestamp(), button, - PointerInterfacePrivate::button_state_pressed); - } -} - -void PointerInterface::sendRelease(quint32 button, quint32 serial) -{ - if (!d->focusedSurface) { - return; - } - - const auto pointerResources = d->pointersForClient(d->focusedSurface->client()); - for (PointerInterfacePrivate::Resource *resource : pointerResources) { - d->send_button(resource->handle, serial, d->seat->timestamp(), button, - PointerInterfacePrivate::button_state_released); + d->send_button(resource->handle, serial, d->seat->timestamp(), button, quint32(state)); } } diff --git a/src/wayland/pointer_interface.h b/src/wayland/pointer_interface.h index 23f3be128d..d7b60151c2 100644 --- a/src/wayland/pointer_interface.h +++ b/src/wayland/pointer_interface.h @@ -23,6 +23,7 @@ class SeatInterface; class SurfaceInterface; enum class PointerAxisSource; +enum class PointerButtonState : quint32; /** * The PointerInterface class represents one or more input devices such as mice, which control @@ -59,8 +60,7 @@ public: */ static PointerInterface *get(wl_resource *native); - void sendPress(quint32 button, quint32 serial); - void sendRelease(quint32 button, quint32 serial); + void sendButton(quint32 button, PointerButtonState state, quint32 serial); void sendAxis(Qt::Orientation orientation, qreal delta, qint32 discreteDelta, PointerAxisSource source); void sendMotion(const QPointF &position); void sendFrame(); diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index baa17472aa..d1e0ee3641 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -724,65 +724,53 @@ void SeatInterface::notifyPointerAxis(Qt::Orientation orientation, qreal delta, d->pointer->sendAxis(orientation, delta, discreteDelta, source); } -void SeatInterface::notifyPointerPress(Qt::MouseButton button) +void SeatInterface::notifyPointerButton(Qt::MouseButton button, PointerButtonState state) { const quint32 nativeButton = qtToWaylandButton(button); if (nativeButton == 0) { return; } - notifyPointerPress(nativeButton); + notifyPointerButton(nativeButton, state); } -void SeatInterface::notifyPointerPress(quint32 button) +void SeatInterface::notifyPointerButton(quint32 button, PointerButtonState state) { if (!d->pointer) { return; } const quint32 serial = d->display->nextSerial(); - d->updatePointerButtonSerial(button, serial); - d->updatePointerButtonState(button, SeatInterfacePrivate::Pointer::State::Pressed); - if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) { - // ignore - return; - } - d->pointer->sendPress(button, serial); - if (focusedPointerSurface() == focusedKeyboardSurface()) { + if (state == PointerButtonState::Pressed) { + d->updatePointerButtonSerial(button, serial); + d->updatePointerButtonState(button, SeatInterfacePrivate::Pointer::State::Pressed); + if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) { + // ignore + return; + } + } else { + const quint32 currentButtonSerial = pointerButtonSerial(button); + d->updatePointerButtonSerial(button, serial); + d->updatePointerButtonState(button, SeatInterfacePrivate::Pointer::State::Released); + if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) { + if (d->drag.source->dragImplicitGrabSerial() != currentButtonSerial) { + // not our drag button - ignore + return; + } + d->endDrag(serial); + return; + } + } + + d->pointer->sendButton(button, state, serial); + + if (focusedPointerSurface() == focusedKeyboardSurface() && + state == PointerButtonState::Pressed) { if (d->keyboard) { d->keyboard->setFocusedSurface(d->pointer->focusedSurface(), serial); } } } -void SeatInterface::notifyPointerRelease(Qt::MouseButton button) -{ - const quint32 nativeButton = qtToWaylandButton(button); - if (nativeButton == 0) { - return; - } - notifyPointerRelease(nativeButton); -} - -void SeatInterface::notifyPointerRelease(quint32 button) -{ - if (!d->pointer) { - return; - } - const quint32 serial = d->display->nextSerial(); - const quint32 currentButtonSerial = pointerButtonSerial(button); - d->updatePointerButtonSerial(button, serial); - d->updatePointerButtonState(button, SeatInterfacePrivate::Pointer::State::Released); - if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Pointer) { - if (d->drag.source->dragImplicitGrabSerial() != currentButtonSerial) { - // not our drag button - ignore - return; - } - d->endDrag(serial); - return; - } - d->pointer->sendRelease(button, serial); -} - void SeatInterface::notifyPointerFrame() { if (!d->pointer) { @@ -1124,7 +1112,7 @@ void SeatInterface::notifyTouchUp(qint32 id) if (touchPrivate->touchesForClient(focusedTouchSurface()->client()).isEmpty()) { // Client did not bind touch, fall back to emulating with pointer events. const quint32 serial = display()->nextSerial(); - d->pointer->sendRelease(BTN_LEFT, serial); + d->pointer->sendButton(BTN_LEFT, PointerButtonState::Released, serial); d->pointer->sendFrame(); } } diff --git a/src/wayland/seat_interface.h b/src/wayland/seat_interface.h index 1db97f6a21..c753ff1de9 100644 --- a/src/wayland/seat_interface.h +++ b/src/wayland/seat_interface.h @@ -55,6 +55,15 @@ enum class PointerAxisSource { WheelTilt }; +/** + * This enum type is used to describe the state of a pointer button. It + * is equivalent to the @c wl_pointer.button_state enum. + */ +enum class PointerButtonState : quint32 { + Released = 0, + Pressed = 1, +}; + /** * @brief Represents a Seat on the Wayland Display. * @@ -90,10 +99,10 @@ enum class PointerAxisSource { * seat->notifyPointerMotion(QPointF(350, 210)); // global pos, local pos in surface: 250,10 * seat->notifyPointerFrame(); * seat->setTimestamp(110); - * seat->notifyPointerPress(Qt::LeftButton); + * seat->notifyPointerButton(Qt::LeftButton, PointerButtonState::Pressed); * seat->notifyPointerFrame(); * seat->setTimestamp(120); - * seat->notifyPointerRelease(Qt::LeftButton); + * seat->notifyPointerButton(Qt::LeftButton, PointerButtonState::Released); * seat->notifyPointerFrame(); * @endcode * @@ -318,30 +327,14 @@ public: */ QMatrix4x4 focusedPointerSurfaceTransformation() const; /** - * Marks the @p button as pressed. - * - * If there is a focused pointer surface a button pressed event is sent to it. - * - * @param button The Linux button code + * Marks the specified @a button as pressed or released based on @a state. */ - void notifyPointerPress(quint32 button); + void notifyPointerButton(quint32 button, PointerButtonState state); /** * @overload */ - void notifyPointerPress(Qt::MouseButton button); + void notifyPointerButton(Qt::MouseButton button, PointerButtonState state); void notifyPointerFrame(); - /** - * Marks the @p button as released. - * - * If there is a focused pointer surface a button release event is sent to it. - * - * @param button The Linux button code - */ - void notifyPointerRelease(quint32 button); - /** - * @overload - */ - void notifyPointerRelease(Qt::MouseButton button); /** * @returns whether the @p button is pressed */ diff --git a/src/wayland/tests/renderingservertest.cpp b/src/wayland/tests/renderingservertest.cpp index 6eb602438a..9fcfcae863 100644 --- a/src/wayland/tests/renderingservertest.cpp +++ b/src/wayland/tests/renderingservertest.cpp @@ -203,7 +203,7 @@ void CompositorWindow::mousePressEvent(QMouseEvent *event) } } m_seat->setTimestamp(event->timestamp()); - m_seat->notifyPointerPress(event->button()); + m_seat->notifyPointerButton(event->button(), KWaylandServer::PointerButtonState::Pressed); m_seat->notifyPointerFrame(); } @@ -211,7 +211,7 @@ void CompositorWindow::mouseReleaseEvent(QMouseEvent *event) { QWidget::mouseReleaseEvent(event); m_seat->setTimestamp(event->timestamp()); - m_seat->notifyPointerRelease(event->button()); + m_seat->notifyPointerButton(event->button(), KWaylandServer::PointerButtonState::Released); m_seat->notifyPointerFrame(); }