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

[server] Properly initialize Cursor

Summary:
The Cursor wasn't properly initialized. E.g. the damage signal didn't
get connected resulting in the server not noticing when the cursor
changes. The damage only got connected if a new cursor got instelled by
the client on the same pointer.

This change ensures that the Cursor is properly initialized by calling
into the same method as when the cursor changed.

The tests are extended by a new test case for damaging the surface.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1022
parent b6b22da5
......@@ -64,6 +64,7 @@ private Q_SLOTS:
void testPointerButton_data();
void testPointerButton();
void testCursor();
void testCursorDamage();
void testKeyboard();
void testCast();
void testDestroy();
......@@ -731,14 +732,80 @@ void TestWaylandSeat::testCursor()
QCOMPARE(surfaceChangedSpy.count(), 1);
QCOMPARE(cursor->surface()->buffer()->data(), img);
p->hideCursor();
QVERIFY(surfaceChangedSpy.wait());
// and add another image to the surface
QImage blue(QSize(10, 20), QImage::Format_ARGB32);
blue.fill(Qt::blue);
cursorSurface->attachBuffer(m_shm->createBuffer(blue));
cursorSurface->damage(QRect(0, 0, 10, 20));
cursorSurface->commit(Surface::CommitFlag::None);
QVERIFY(changedSpy.wait());
QCOMPARE(changedSpy.count(), 4);
QCOMPARE(cursorChangedSpy.count(), 5);
QCOMPARE(cursor->surface()->buffer()->data(), blue);
p->hideCursor();
QVERIFY(surfaceChangedSpy.wait());
QCOMPARE(changedSpy.count(), 5);
QCOMPARE(cursorChangedSpy.count(), 6);
QCOMPARE(surfaceChangedSpy.count(), 2);
QVERIFY(!cursor->surface());
}
void TestWaylandSeat::testCursorDamage()
{
// this test verifies that damaging a cursor surface triggers a cursor changed on the server
using namespace KWayland::Client;
using namespace KWayland::Server;
QSignalSpy pointerSpy(m_seat, &Seat::hasPointerChanged);
QVERIFY(pointerSpy.isValid());
m_seatInterface->setHasPointer(true);
QVERIFY(pointerSpy.wait());
// create pointer
QScopedPointer<Pointer> p(m_seat->createPointer());
QVERIFY(p->isValid());
QSignalSpy enteredSpy(p.data(), &Pointer::entered);
QVERIFY(enteredSpy.isValid());
// create surface
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
QVERIFY(surfaceCreatedSpy.isValid());
m_compositor->createSurface(m_compositor);
QVERIFY(surfaceCreatedSpy.wait());
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWayland::Server::SurfaceInterface*>();
QVERIFY(serverSurface);
// send enter to the surface
m_seatInterface->setFocusedPointerSurface(serverSurface);
QVERIFY(enteredSpy.wait());
// create a signal spy for the cursor changed signal
auto pointer = m_seatInterface->focusedPointer();
QSignalSpy cursorChangedSpy(pointer, &PointerInterface::cursorChanged);
QVERIFY(cursorChangedSpy.isValid());
// now let's set the cursor
Surface *cursorSurface = m_compositor->createSurface(m_compositor);
QVERIFY(cursorSurface);
QImage red(QSize(10, 10), QImage::Format_ARGB32);
red.fill(Qt::red);
cursorSurface->attachBuffer(m_shm->createBuffer(red));
cursorSurface->damage(QRect(0, 0, 10, 10));
cursorSurface->commit(Surface::CommitFlag::None);
p->setCursor(cursorSurface, QPoint(0, 0));
QVERIFY(cursorChangedSpy.wait());
QCOMPARE(pointer->cursor()->surface()->buffer()->data(), red);
// and damage the surface
QImage blue(QSize(10, 10), QImage::Format_ARGB32);
blue.fill(Qt::blue);
cursorSurface->attachBuffer(m_shm->createBuffer(blue));
cursorSurface->damage(QRect(0, 0, 10, 10));
cursorSurface->commit(Surface::CommitFlag::None);
QVERIFY(cursorChangedSpy.wait());
QCOMPARE(pointer->cursor()->surface()->buffer()->data(), blue);
}
void TestWaylandSeat::testKeyboard()
{
using namespace KWayland::Client;
......
......@@ -81,9 +81,7 @@ void PointerInterface::Private::setCursor(quint32 serial, SurfaceInterface *surf
if (!cursor) {
Q_Q(PointerInterface);
cursor = new Cursor(q);
cursor->d->enteredSerial = serial;
cursor->d->hotspot = hotspot;
cursor->d->surface = QPointer<SurfaceInterface>(surface);
cursor->d->update(QPointer<SurfaceInterface>(surface), serial, hotspot);
QObject::connect(cursor, &Cursor::changed, q, &PointerInterface::cursorChanged);
emit q->cursorChanged();
} else {
......
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