IDSWaylandShell/DSWaylandZxdgShellV6: send destroyed signal when DSWaylandSurface... 91/242491/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Thu, 27 Aug 2020 01:58:00 +0000 (10:58 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 27 Aug 2020 07:50:46 +0000 (16:50 +0900)
Change-Id: I994d1ca4e7292c4408d44473a963d52fcf2c51bf

src/DSWaylandServer/DSWaylandZxdgShellV6.cpp
src/DSWaylandServer/DSWaylandZxdgShellV6.h
src/DSWaylandServer/IDSWaylandShell.h
tests/DSWaylandZxdgShellV6-test.cpp

index f72a1e7..40ba862 100644 (file)
@@ -88,6 +88,10 @@ void DSWaylandZxdgShellV6::registerCallbackShellSurfaceCreated(DSObject *slot, s
        __zxdgSurfaceCreatedSignal.connect(slot, func);
 }
 
+void DSWaylandZxdgShellV6::registerCallbackShellSurfaceDestroyed(DSObject *slot, std::function<void(IDSWaylandShellSurface*)> func)
+{
+       __zxdgSurfaceDestroyedSignal.connect(slot, func);
+}
 
 DSWaylandZxdgShellV6Private::DSWaylandZxdgShellV6Private(DSWaylandZxdgShellV6 *p_ptr)
        : DSObjectPrivate(p_ptr), __p_ptr(p_ptr)
@@ -116,7 +120,7 @@ void DSWaylandZxdgShellV6Private::zxdg_shell_v6_get_xdg_surface(zxdg_shell_v6::R
        DSLOG_DBG("DSWaylandZxdgShell", "");
        DS_GET_PUB(DSWaylandZxdgShellV6);
 
-       DSWaylandZxdgSurfaceV6 *zxdgSurf = new DSWaylandZxdgSurfaceV6(resource->client(), id, ZXDG_SURFACE_V6_VERSION);
+       DSWaylandZxdgSurfaceV6 *zxdgSurf = new DSWaylandZxdgSurfaceV6(resource->client(), id, ZXDG_SURFACE_V6_VERSION, pub);
        if (zxdgSurf)
        {
                zxdgSurf->setWlSurface(surface);
@@ -130,8 +134,6 @@ void DSWaylandZxdgShellV6Private::zxdg_shell_v6_get_xdg_surface(zxdg_shell_v6::R
                DSLOG_DBG("DSWaylandZxdgShell", "DSWaylandZxdgSurface:%p, DSWaylandSurface:%p, wl_surface:%p", zxdgSurf, dswlSurface, surface);
 
                pub->addSurface(zxdgSurf);
-               // emit a signal of the zxdg surface created
-               pub->__zxdgSurfaceCreatedSignal.emit(zxdgSurf);
        }
 }
 void DSWaylandZxdgShellV6Private::zxdg_shell_v6_pong(zxdg_shell_v6::Resource *resource, uint32_t serial)
@@ -143,11 +145,17 @@ void DSWaylandZxdgShellV6Private::addSurface(DSWaylandZxdgSurfaceV6 *zxdgSurf)
        for (DSWaylandZxdgSurfaceV6 *surf : __surfList)
                if (surf == zxdgSurf) return;
 
+       DS_GET_PUB(DSWaylandZxdgShellV6);
+       pub->__zxdgSurfaceCreatedSignal.emit(zxdgSurf);
+
        __surfList.push_back(zxdgSurf);
 }
 
 void DSWaylandZxdgShellV6Private::delSurface(DSWaylandZxdgSurfaceV6 *zxdgSurf)
 {
+       DS_GET_PUB(DSWaylandZxdgShellV6);
+       pub->__zxdgSurfaceDestroyedSignal.emit(zxdgSurf);
+
        __surfList.remove(zxdgSurf);
 }
 
@@ -227,19 +235,23 @@ void DSWaylandZxdgPositionerV6Private::zxdg_positioner_v6_set_offset(zxdg_positi
           DSWaylandZxdgSurfaceV6
  *****************************************/
 
-DSWaylandZxdgSurfaceV6::DSWaylandZxdgSurfaceV6()
-       : IDSWaylandShellSurface(), DS_INIT_PRIVATE_PTR(DSWaylandZxdgSurfaceV6)
+DSWaylandZxdgSurfaceV6::DSWaylandZxdgSurfaceV6(DSWaylandZxdgShellV6 *xdgShell)
+       : IDSWaylandShellSurface(), DS_INIT_PRIVATE_PTR(DSWaylandZxdgSurfaceV6),
+         __xdgShell(xdgShell)
 {
 }
 
-DSWaylandZxdgSurfaceV6::DSWaylandZxdgSurfaceV6(struct ::wl_client *client, int id, int ver)
-       : IDSWaylandShellSurface(), DS_INIT_PRIVATE_PTR(DSWaylandZxdgSurfaceV6)
+DSWaylandZxdgSurfaceV6::DSWaylandZxdgSurfaceV6(struct ::wl_client *client, int id, int ver, DSWaylandZxdgShellV6 *xdgShell)
+       : IDSWaylandShellSurface(), DS_INIT_PRIVATE_PTR(DSWaylandZxdgSurfaceV6),
+         __xdgShell(xdgShell)
 {
        this->init(client, id, ver);
 }
 
 DSWaylandZxdgSurfaceV6::~DSWaylandZxdgSurfaceV6()
 {
+       if (__xdgShell)
+               __xdgShell->delSurface(this);
 }
 
 void DSWaylandZxdgSurfaceV6::init(struct ::wl_client *client, int id, int ver)
index 6eb6446..0ba2f2a 100644 (file)
@@ -61,9 +61,11 @@ public:
        std::list<DSWaylandZxdgSurfaceV6 *> getSurfaceList();
 
        void registerCallbackShellSurfaceCreated(DSObject *slot, std::function<void(IDSWaylandShellSurface*)> func);
+       void registerCallbackShellSurfaceDestroyed(DSObject *slot, std::function<void(IDSWaylandShellSurface*)> func);
 
 public:
        DSSignal<DSWaylandZxdgSurfaceV6*> __zxdgSurfaceCreatedSignal;
+       DSSignal<DSWaylandZxdgSurfaceV6*> __zxdgSurfaceDestroyedSignal;
 };
 
 class DSWaylandZxdgPositionerV6 : public DSObject
@@ -92,8 +94,8 @@ public:
        };
 
 public:
-       DSWaylandZxdgSurfaceV6();
-       DSWaylandZxdgSurfaceV6(struct ::wl_client *client, int id, int ver);
+       DSWaylandZxdgSurfaceV6(DSWaylandZxdgShellV6 *xdgShell);
+       DSWaylandZxdgSurfaceV6(struct ::wl_client *client, int id, int ver, DSWaylandZxdgShellV6 *xdgShell);
        virtual ~DSWaylandZxdgSurfaceV6();
 
        void init(struct ::wl_client *client, int id, int ver);
@@ -113,6 +115,9 @@ public:
        void getGeometry(int *x, int *y, int *w, int *h);
        std::string getWindowTitle();
        std::string getAppID();
+
+private:
+       DSWaylandZxdgShellV6 *__xdgShell;
 };
 
 class DSWaylandZxdgToplevelV6 : public DSObject
index 290efe0..d64a1bc 100644 (file)
@@ -41,6 +41,7 @@ public:
        virtual ~IDSWaylandShell() = default;
 
        virtual void registerCallbackShellSurfaceCreated(DSObject *slot, std::function<void(IDSWaylandShellSurface*)> func) = 0;
+       virtual void registerCallbackShellSurfaceDestroyed(DSObject *slot, std::function<void(IDSWaylandShellSurface*)> func) = 0;
 };
 
 
index a0b9bc0..aae14f2 100644 (file)
@@ -47,18 +47,21 @@ TEST_F(DSWaylandZxdgShellV6Test, NewDSWaylandZxdgShellV6)
 TEST_F(DSWaylandZxdgShellV6Test, ShellAddSurface)
 {
        DSWaylandZxdgShellV6 *zxdgShell = new DSWaylandZxdgShellV6;
-       DSWaylandZxdgSurfaceV6 *zxdgSurf = new DSWaylandZxdgSurfaceV6;
+       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6(zxdgShell);
        EXPECT_TRUE(zxdgShell != nullptr);
-       EXPECT_TRUE(zxdgSurf != nullptr);
+       EXPECT_TRUE(zxdgSurface != nullptr);
 
-       zxdgShell->addSurface(zxdgSurf);
+       zxdgShell->addSurface(zxdgSurface);
        EXPECT_TRUE(true);
+
+       if (zxdgSurface) delete zxdgSurface;
+       if (zxdgShell) delete zxdgShell;
 }
 
 TEST_F(DSWaylandZxdgShellV6Test, ShellGetSurfaceList)
 {
        DSWaylandZxdgShellV6 *zxdgShell = new DSWaylandZxdgShellV6;
-       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6;
+       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6(zxdgShell);
        EXPECT_TRUE(zxdgShell != nullptr);
        EXPECT_TRUE(zxdgSurface != nullptr);
 
@@ -70,10 +73,8 @@ TEST_F(DSWaylandZxdgShellV6Test, ShellGetSurfaceList)
                EXPECT_TRUE(*iter == zxdgSurface);
        }
 
-       if (zxdgShell)
-               delete zxdgShell;
-       if (zxdgSurface)
-               delete zxdgSurface;
+       if (zxdgSurface) delete zxdgSurface;
+       if (zxdgShell) delete zxdgShell;
 }
 
 TEST_F(DSWaylandZxdgShellV6Test, NewDSWaylandZxdgPositionerV6)
@@ -87,7 +88,7 @@ TEST_F(DSWaylandZxdgShellV6Test, NewDSWaylandZxdgPositionerV6)
 
 TEST_F(DSWaylandZxdgShellV6Test, NewDSWaylandZxdgSurfaceV6)
 {
-       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6;
+       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6(nullptr);
        EXPECT_TRUE(zxdgSurface != nullptr);
 
        if (zxdgSurface)
@@ -99,7 +100,7 @@ TEST_F(DSWaylandZxdgShellV6Test, SetSurface)
        auto dsSurface = std::make_shared<DSWaylandSurface>();
        EXPECT_TRUE(dsSurface != nullptr);
 
-       auto zxdgSurface = std::make_shared<DSWaylandZxdgSurfaceV6>();
+       auto zxdgSurface = std::make_shared<DSWaylandZxdgSurfaceV6>(nullptr);
        EXPECT_TRUE(zxdgSurface != nullptr);
 
        if (zxdgSurface && dsSurface)
@@ -114,7 +115,7 @@ TEST_F(DSWaylandZxdgShellV6Test, SetSurface)
 
 TEST_F(DSWaylandZxdgShellV6Test, SurfaceSetWindowTitle)
 {
-       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6;
+       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6(nullptr);
        std::string inputStr("test");
        EXPECT_TRUE(zxdgSurface != nullptr);
 
@@ -127,7 +128,7 @@ TEST_F(DSWaylandZxdgShellV6Test, SurfaceSetWindowTitle)
 
 TEST_F(DSWaylandZxdgShellV6Test, SurfaceSetAppID)
 {
-       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6;
+       DSWaylandZxdgSurfaceV6 *zxdgSurface = new DSWaylandZxdgSurfaceV6(nullptr);
        std::string inputStr("test");
        EXPECT_TRUE(zxdgSurface != nullptr);