Merge notifyPointerPress() and notifyPointerRelease()

This brings the API of the SeatInterface class and the PointerInterface
class closer the corresponding Wayland API.
This commit is contained in:
Vlad Zahorodnii 2021-03-15 19:58:39 +02:00
parent 2af2ba6d4c
commit a50f84a868
9 changed files with 73 additions and 106 deletions

View file

@ -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();
}

View file

@ -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>(), 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>(), 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());

View file

@ -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<quint32>(), 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<quint32>(), 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<quint32>(), 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<KWayland::Client::Pointer::ButtonState>(), 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);

View file

@ -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());

View file

@ -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));
}
}

View file

@ -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();

View file

@ -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();
}
}

View file

@ -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
*/

View file

@ -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();
}