From 12477a66fc68278aa24393856ce767ecafdf8abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 25 Nov 2014 14:24:52 +0100 Subject: [PATCH] [server] Move pointer position from PointerInterface to SeatInterface PointerInterface should only wrap a Resource. In order to do so all global state needs to move into the Global. --- src/wayland/autotests/server/test_seat.cpp | 29 ++++++++++++++++----- src/wayland/pointer_interface.cpp | 30 ++++++++++------------ src/wayland/pointer_interface.h | 20 ++++++++++++--- src/wayland/seat_interface.cpp | 19 ++++++++++++++ src/wayland/seat_interface.h | 6 +++++ 5 files changed, 78 insertions(+), 26 deletions(-) diff --git a/src/wayland/autotests/server/test_seat.cpp b/src/wayland/autotests/server/test_seat.cpp index 8698d9d3cc..dc1681b6ff 100644 --- a/src/wayland/autotests/server/test_seat.cpp +++ b/src/wayland/autotests/server/test_seat.cpp @@ -144,19 +144,36 @@ void TestWaylandServerSeat::testPointerPos() display.setSocketName(s_socketName); display.start(); SeatInterface *seat = display.createSeat(); + QSignalSpy seatPosSpy(seat, SIGNAL(pointerPosChanged(QPointF))); + QVERIFY(seatPosSpy.isValid()); PointerInterface *pointer = seat->pointer(); - QSignalSpy posSpy(pointer, SIGNAL(globalPosChanged(QPoint))); + QSignalSpy posSpy(pointer, SIGNAL(globalPosChanged(QPointF))); QVERIFY(posSpy.isValid()); - QCOMPARE(pointer->globalPos(), QPoint()); + QCOMPARE(pointer->globalPos(), QPointF()); + QCOMPARE(seat->pointerPos(), QPointF()); - pointer->setGlobalPos(QPoint(10, 15)); - QCOMPARE(pointer->globalPos(), QPoint(10, 15)); + pointer->setGlobalPos(QPointF(10, 15)); + QCOMPARE(pointer->globalPos(), QPointF(10, 15)); + QCOMPARE(seat->pointerPos(), QPointF(10, 15)); QCOMPARE(posSpy.count(), 1); - QCOMPARE(posSpy.first().first().toPoint(), QPoint(10, 15)); + QCOMPARE(posSpy.first().first().toPointF(), QPointF(10, 15)); + QCOMPARE(seatPosSpy.count(), 1); + QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15)); - pointer->setGlobalPos(QPoint(10, 15)); + pointer->setGlobalPos(QPointF(10, 15)); QCOMPARE(posSpy.count(), 1); + 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)); } void TestWaylandServerSeat::testDestroyThroughTerminate() diff --git a/src/wayland/pointer_interface.cpp b/src/wayland/pointer_interface.cpp index 5d68ac79c7..a794d34edc 100644 --- a/src/wayland/pointer_interface.cpp +++ b/src/wayland/pointer_interface.cpp @@ -55,7 +55,6 @@ public: }; QList resources; quint32 eventTime = 0; - QPoint globalPos; struct FocusedSurface { SurfaceInterface *surface = nullptr; QPoint offset = QPoint(); @@ -97,6 +96,14 @@ PointerInterface::PointerInterface(SeatInterface *parent) : QObject(parent) , d(new Private(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_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); + } + }); + connect(parent, &SeatInterface::pointerPosChanged, this, &PointerInterface::globalPosChanged); } PointerInterface::~PointerInterface() @@ -157,10 +164,10 @@ void PointerInterface::setFocusedSurface(SurfaceInterface *surface, const QPoint d->focusedSurface.serial = serial; d->destroyConnection = connect(d->focusedSurface.surface, &QObject::destroyed, this, [this] { d->surfaceDeleted(); }); - const QPoint pos = d->globalPos - surfacePosition; + const QPointF pos = d->seat->pointerPos() - surfacePosition; wl_pointer_send_enter(d->focusedSurface.pointer, d->focusedSurface.serial, d->focusedSurface.surface->resource(), - wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y())); + wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); } void PointerInterface::Private::surfaceDeleted() @@ -176,18 +183,9 @@ void PointerInterface::setFocusedSurfacePosition(const QPoint &surfacePosition) d->focusedSurface.offset = surfacePosition; } -void PointerInterface::setGlobalPos(const QPoint &pos) +void PointerInterface::setGlobalPos(const QPointF &pos) { - if (d->globalPos == pos) { - return; - } - d->globalPos = pos; - if (d->focusedSurface.surface && d->focusedSurface.pointer) { - const QPoint pos = d->globalPos - d->focusedSurface.offset; - wl_pointer_send_motion(d->focusedSurface.pointer, d->eventTime, - wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y())); - } - emit globalPosChanged(d->globalPos); + d->seat->setPointerPos(pos); } void PointerInterface::updateTimestamp(quint32 time) @@ -357,9 +355,9 @@ void PointerInterface::Private::releaseCallback(wl_client *client, wl_resource * unbind(resource); } -QPoint PointerInterface::globalPos() const +QPointF PointerInterface::globalPos() const { - return d->globalPos; + return d->seat->pointerPos(); } SurfaceInterface *PointerInterface::focusedSurface() const diff --git a/src/wayland/pointer_interface.h b/src/wayland/pointer_interface.h index 2064de77f5..b7da71d805 100644 --- a/src/wayland/pointer_interface.h +++ b/src/wayland/pointer_interface.h @@ -39,15 +39,23 @@ class SurfaceInterface; class KWAYLANDSERVER_EXPORT PointerInterface : public QObject { Q_OBJECT - Q_PROPERTY(QPoint globalPos READ globalPos WRITE setGlobalPos NOTIFY globalPosChanged) + Q_PROPERTY(QPointF globalPos READ globalPos WRITE setGlobalPos NOTIFY globalPosChanged) public: virtual ~PointerInterface(); void createInterface(wl_client *client, wl_resource *parentResource, uint32_t id); void updateTimestamp(quint32 time); - void setGlobalPos(const QPoint &pos); - QPoint globalPos() const; + /** + * Convenient method to set the pointer position of the SeatInterface. + * @see SeatInterface::setPointerPos + **/ + void setGlobalPos(const QPointF &pos); + /** + * Convenient method to get the pointer position of the SeatInterface. + * @see SeatInterface::pointerPos + **/ + QPointF globalPos() const; void buttonPressed(quint32 button); void buttonPressed(Qt::MouseButton button); void buttonReleased(quint32 button); @@ -64,7 +72,11 @@ public: QPoint focusedSurfacePosition() const; Q_SIGNALS: - void globalPosChanged(const QPoint &pos); + /** + * Convenient signal emitted when the SeatInterface's pointer position changes. + * @see SeatInterface::pointerPosChanged + **/ + void globalPosChanged(const QPointF &pos); private: friend class SeatInterface; diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index df46f63c76..e7c92f695a 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -55,6 +55,9 @@ public: PointerInterface *pointerInterface = nullptr; KeyboardInterface *keyboardInterface = nullptr; + // Pointer related members + QPointF pointerPos; + static SeatInterface *get(wl_resource *native) { auto s = cast(native); return s ? s->q : nullptr; @@ -267,5 +270,21 @@ SeatInterface::Private *SeatInterface::d_func() const return reinterpret_cast(d.data()); } +QPointF SeatInterface::pointerPos() const +{ + Q_D(); + return d->pointerPos; +} + +void SeatInterface::setPointerPos(const QPointF &pos) +{ + Q_D(); + if (d->pointerPos == pos) { + return; + } + d->pointerPos = pos; + emit pointerPosChanged(pos); +} + } } diff --git a/src/wayland/seat_interface.h b/src/wayland/seat_interface.h index deada594f3..fa852b1a51 100644 --- a/src/wayland/seat_interface.h +++ b/src/wayland/seat_interface.h @@ -46,6 +46,7 @@ class KWAYLANDSERVER_EXPORT SeatInterface : public Global Q_PROPERTY(bool pointer READ hasPointer WRITE setHasPointer NOTIFY hasPointerChanged) 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) public: virtual ~SeatInterface(); @@ -61,6 +62,10 @@ public: void setHasKeyboard(bool has); void setHasTouch(bool has); + // pointer related methods + void setPointerPos(const QPointF &pos); + QPointF pointerPos() const; + static SeatInterface *get(wl_resource *native); Q_SIGNALS: @@ -68,6 +73,7 @@ Q_SIGNALS: void hasPointerChanged(bool); void hasKeyboardChanged(bool); void hasTouchChanged(bool); + void pointerPosChanged(const QPointF &pos); private: friend class Display;