From 9b05557a6325497485b582c3891367aa7dfee245 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 6 Feb 2019 09:30:09 +0100 Subject: Client: Don't send illegal wl_pointer.set_cursor requests When the cursor focus' wl_surface is destroyed, or the pointer leaves a surface, we have to reset the enter serial to avoid sending illegal set_cursor requests. Change-Id: I0c886e4123acb4aebd325b07bf15b9d3fa8589da Reviewed-by: Giulio Camuffo --- tests/auto/client/seatv4/tst_seatv4.cpp | 34 ++++++++++++++++++++++++++++++- tests/auto/client/shared/coreprotocol.cpp | 6 +++--- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/client/seatv4/tst_seatv4.cpp b/tests/auto/client/seatv4/tst_seatv4.cpp index 771307d7e..7dc2e727a 100644 --- a/tests/auto/client/seatv4/tst_seatv4.cpp +++ b/tests/auto/client/seatv4/tst_seatv4.cpp @@ -70,6 +70,7 @@ private slots: void createsPointer(); void setsCursorOnEnter(); void usesEnterSerial(); + void focusDestruction(); void mousePress(); void simpleAxis_data(); void simpleAxis(); @@ -147,12 +148,43 @@ void tst_seatv4::usesEnterSerial() uint enterSerial = exec([=] { return pointer()->sendEnter(xdgSurface()->m_surface, {32, 32}); }); - QCOMPOSITOR_TRY_VERIFY(pointer()->cursorSurface()); + QCOMPOSITOR_TRY_VERIFY(cursorSurface()); QTRY_COMPARE(setCursorSpy.count(), 1); QCOMPARE(setCursorSpy.takeFirst().at(0).toUInt(), enterSerial); } +void tst_seatv4::focusDestruction() +{ + QSignalSpy setCursorSpy(exec([=] { return pointer(); }), &Pointer::setCursor); + QRasterWindow window; + window.resize(64, 64); + window.show(); + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + // Setting a cursor now is not allowed since there has been no enter event + QCOMPARE(setCursorSpy.count(), 0); + + uint enterSerial = exec([=] { + return pointer()->sendEnter(xdgSurface()->m_surface, {32, 32}); + }); + QCOMPOSITOR_TRY_VERIFY(cursorSurface()); + QTRY_COMPARE(setCursorSpy.count(), 1); + QCOMPARE(setCursorSpy.takeFirst().at(0).toUInt(), enterSerial); + + // Destroy the focus + window.close(); + + QRasterWindow window2; + window2.resize(64, 64); + window2.show(); + window2.setCursor(Qt::WaitCursor); + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + + // Setting a cursor now is not allowed since there has been no enter event + xdgPingAndWaitForPong(); + QCOMPARE(setCursorSpy.count(), 0); +} + void tst_seatv4::mousePress() { class Window : public QRasterWindow { diff --git a/tests/auto/client/shared/coreprotocol.cpp b/tests/auto/client/shared/coreprotocol.cpp index c4dc3f341..729d481f8 100644 --- a/tests/auto/client/shared/coreprotocol.cpp +++ b/tests/auto/client/shared/coreprotocol.cpp @@ -261,6 +261,7 @@ uint Pointer::sendEnter(Surface *surface, const QPointF &position) uint serial = m_seat->m_compositor->nextSerial(); m_enterSerials << serial; + m_cursorRole = nullptr; // According to the protocol, the pointer image is undefined after enter wl_client *client = surface->resource()->client(); const auto pointerResources = resourceMap().values(client); @@ -320,9 +321,8 @@ void Pointer::pointer_set_cursor(Resource *resource, uint32_t serial, wl_resourc QVERIFY(s); if (s->m_role) { - auto *cursorRole = CursorRole::fromSurface(s); - QVERIFY(cursorRole); - QVERIFY(cursorRole == m_cursorRole); + m_cursorRole = CursorRole::fromSurface(s); + QVERIFY(m_cursorRole); } else { m_cursorRole = new CursorRole(s); //TODO: make sure we don't leak CursorRole s->m_role = m_cursorRole; -- cgit v1.2.3