[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.
This commit is contained in:
Martin Gräßlin 2014-11-25 14:24:52 +01:00
parent 8f9a9fedb1
commit 12477a66fc
5 changed files with 78 additions and 26 deletions

View file

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

View file

@ -55,7 +55,6 @@ public:
};
QList<ResourceData> 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

View file

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

View file

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

View file

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