From 34af4b1cf882ecb23810e26ca6888aff4092cc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 7 Nov 2014 17:07:48 +0100 Subject: [PATCH] Fix check whether there is already a ShellSurface for a given Surface Incorrect logic prevented that more than one ShellSurface could be created. --- .../autotests/client/test_wayland_shell.cpp | 38 +++++++++++++++++++ src/wayland/server/shell_interface.cpp | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/wayland/autotests/client/test_wayland_shell.cpp b/src/wayland/autotests/client/test_wayland_shell.cpp index 813ceea126..7e5963d100 100644 --- a/src/wayland/autotests/client/test_wayland_shell.cpp +++ b/src/wayland/autotests/client/test_wayland_shell.cpp @@ -43,6 +43,7 @@ private Q_SLOTS: void init(); void cleanup(); + void testCreateMultiple(); void testFullscreen(); void testPing(); void testTitle(); @@ -169,6 +170,43 @@ void TestWaylandShell::cleanup() m_display = nullptr; } +void TestWaylandShell::testCreateMultiple() +{ + using namespace KWayland::Server; + using namespace KWayland::Client; + + QScopedPointer s1(m_compositor->createSurface()); + QScopedPointer s2(m_compositor->createSurface()); + QVERIFY(!s1.isNull()); + QVERIFY(s1->isValid()); + QVERIFY(!s2.isNull()); + QVERIFY(s2->isValid()); + + QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); + QVERIFY(serverSurfaceSpy.isValid()); + QScopedPointer surface1(m_shell->createSurface(s1.data())); + QVERIFY(!surface1.isNull()); + QVERIFY(surface1->isValid()); + + QVERIFY(serverSurfaceSpy.wait()); + QCOMPARE(serverSurfaceSpy.count(), 1); + + QScopedPointer surface2(m_shell->createSurface(s2.data())); + QVERIFY(!surface2.isNull()); + QVERIFY(surface2->isValid()); + + QVERIFY(serverSurfaceSpy.wait()); + QCOMPARE(serverSurfaceSpy.count(), 2); + + // try creating for one which already exist should not be possible + QScopedPointer surface3(m_shell->createSurface(s2.data())); + QVERIFY(!surface3.isNull()); + QVERIFY(surface3->isValid()); + + QVERIFY(!serverSurfaceSpy.wait(100)); + QCOMPARE(serverSurfaceSpy.count(), 2); +} + void TestWaylandShell::testFullscreen() { using namespace KWayland::Server; diff --git a/src/wayland/server/shell_interface.cpp b/src/wayland/server/shell_interface.cpp index 069efa3bdf..13afb8220a 100644 --- a/src/wayland/server/shell_interface.cpp +++ b/src/wayland/server/shell_interface.cpp @@ -176,7 +176,7 @@ void ShellInterface::Private::createSurface(wl_client *client, uint32_t version, return surface == s->surface(); } ); - if (it != surfaces.constBegin()) { + if (it != surfaces.constEnd()) { wl_resource_post_error(surface->surface(), WL_DISPLAY_ERROR_INVALID_OBJECT, "ShellSurface already created"); return; }