Commit b6b22da5 authored by Martin Flöser's avatar Martin Flöser
Browse files

[server] Add a signal SeatInterface::focusedPointerChanged

Summary:
The signal gets emitted whenever the focused PointerInterfaces gets
newly set or reset to nullptr. This is needed to better track the
current cursor image in the compositor.

Reviewers: #plasma, sebas

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1007
parent 0c3c7142
......@@ -296,8 +296,13 @@ void TestWaylandSeat::testPointer()
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWayland::Server::SurfaceInterface*>();
QVERIFY(serverSurface);
QSignalSpy focusedPointerChangedSpy(m_seatInterface, &SeatInterface::focusedPointerChanged);
QVERIFY(focusedPointerChangedSpy.isValid());
m_seatInterface->setPointerPos(QPoint(20, 18));
m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(10, 15));
QCOMPARE(focusedPointerChangedSpy.count(), 1);
QVERIFY(!focusedPointerChangedSpy.first().first().value<PointerInterface*>());
// no pointer yet
QVERIFY(m_seatInterface->focusedPointerSurface());
QVERIFY(!m_seatInterface->focusedPointer());
......@@ -311,8 +316,12 @@ void TestWaylandSeat::testPointer()
QVERIFY(pointerCreatedSpy.wait());
QVERIFY(m_seatInterface->focusedPointer());
QCOMPARE(pointerCreatedSpy.first().first().value<PointerInterface*>(), m_seatInterface->focusedPointer());
QCOMPARE(focusedPointerChangedSpy.count(), 2);
QCOMPARE(focusedPointerChangedSpy.last().first().value<PointerInterface*>(), m_seatInterface->focusedPointer());
m_seatInterface->setFocusedPointerSurface(nullptr);
QCOMPARE(focusedPointerChangedSpy.count(), 3);
QVERIFY(!focusedPointerChangedSpy.last().first().value<PointerInterface*>());
serverSurface->client()->flush();
QTest::qWait(100);
......@@ -342,6 +351,8 @@ void TestWaylandSeat::testPointer()
QVERIFY(serverPointer);
QCOMPARE(p->enteredSurface(), s);
QCOMPARE(cp.enteredSurface(), s);
QCOMPARE(focusedPointerChangedSpy.count(), 4);
QCOMPARE(focusedPointerChangedSpy.last().first().value<PointerInterface*>(), serverPointer);
// test motion
m_seatInterface->setTimestamp(1);
......@@ -411,6 +422,7 @@ void TestWaylandSeat::testPointer()
// leave the surface
m_seatInterface->setFocusedPointerSurface(nullptr);
QCOMPARE(focusedPointerChangedSpy.count(), 5);
QVERIFY(leftSpy.wait());
QCOMPARE(leftSpy.first().first().value<quint32>(), m_display->serial());
QVERIFY(!p->enteredSurface());
......@@ -418,13 +430,15 @@ void TestWaylandSeat::testPointer()
// enter it again
m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(0, 0));
QCOMPARE(focusedPointerChangedSpy.count(), 6);
QVERIFY(enteredSpy.wait());
QCOMPARE(p->enteredSurface(), s);
QCOMPARE(cp.enteredSurface(), s);
delete s;
wl_display_flush(m_connection->display());
QTest::qWait(100);
QVERIFY(focusedPointerChangedSpy.wait());
QCOMPARE(focusedPointerChangedSpy.count(), 7);
QVERIFY(!m_seatInterface->focusedPointerSurface());
}
......
......@@ -322,6 +322,7 @@ void SeatInterface::Private::getPointer(wl_client *client, wl_resource *resource
if (!globalPointer.focus.pointer) {
globalPointer.focus.pointer = pointer;
pointer->setFocusedSurface(globalPointer.focus.surface, globalPointer.focus.serial);
emit q->focusedPointerChanged(pointer);
}
}
QObject::connect(pointer, &QObject::destroyed, q,
......@@ -329,6 +330,7 @@ void SeatInterface::Private::getPointer(wl_client *client, wl_resource *resource
pointers.removeAt(pointers.indexOf(pointer));
if (globalPointer.focus.pointer == pointer) {
globalPointer.focus.pointer = nullptr;
emit q->focusedPointerChanged(nullptr);
}
}
);
......@@ -514,12 +516,14 @@ void SeatInterface::setFocusedPointerSurface(SurfaceInterface *surface, const QM
[this] {
Q_D();
d->globalPointer.focus = Private::Pointer::Focus();
emit focusedPointerChanged(nullptr);
}
);
d->globalPointer.focus.offset = QPointF();
d->globalPointer.focus.transformation = transformation;
d->globalPointer.focus.serial = serial;
}
emit focusedPointerChanged(p);
if (!p) {
return;
}
......
......@@ -373,6 +373,12 @@ Q_SIGNALS:
void keyboardCreated(KWayland::Server::KeyboardInterface*);
void touchCreated(KWayland::Server::TouchInterface*);
/**
* Emitted whenever the focused pointer changes
* @since 5.6
**/
void focusedPointerChanged(KWayland::Server::PointerInterface*);
private:
friend class Display;
friend class DataDeviceManagerInterface;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment