DSZone/DSWaylandTizenPolicy/DSWindowManager: add code to handle window stack 09/241909/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Thu, 20 Aug 2020 09:56:37 +0000 (18:56 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 23:58:37 +0000 (08:58 +0900)
Change-Id: Ifa1c05f98050d3f117b9fdeae027feb53b49ef8f

src/DSWaylandServer/DSWaylandTizenPolicy.cpp
src/DSWaylandServer/DSWaylandTizenPolicyPrivate.h
src/DSWindowManager/DSWindowManager.cpp
src/DSWindowManager/DSWindowManager.h
src/DSWindowManager/DSWindowManagerPrivate.h
src/DSZone/DSZone.cpp
src/DSZone/DSZone.h
tests/DSZone-test.cpp

index e589896..52f19e3 100644 (file)
@@ -39,11 +39,14 @@ DSWaylandTizenPolicyPrivate::DSWaylandTizenPolicyPrivate(DSWaylandTizenPolicy *p
          __p_ptr(p_ptr)
 {
        DSLOG_DBG("TizenPolicyPriv", "");
+       __wm = DSWindowManager::getInstance();
 }
 
 DSWaylandTizenPolicyPrivate::~DSWaylandTizenPolicyPrivate()
 {
        DSLOG_DBG("TizenPolicyPriv", "");
+       if (__wm)
+               DSWindowManager::releaseInstance();
 }
 
 void DSWaylandTizenPolicyPrivate::tizen_policy_initialize(DSWaylandCompositor *wlCompositor)
@@ -86,7 +89,12 @@ void DSWaylandTizenPolicyPrivate::tizen_policy_get_position(Resource *resource,
 
 void DSWaylandTizenPolicyPrivate::tizen_policy_activate(Resource *resource, struct ::wl_resource *surface)
 {
-       DSLOG_DBG("TizenPolicyPriv", "");
+       DSLOG_DBG("TizenPolicyPriv", "Request to activate. resource:%p, wl_surface:%p", resource, surface);
+       DSWaylandSurface *dswlSurface = DSWaylandSurface::fromWlResource(surface);
+       if (!dswlSurface) return;
+       if (!__wm) return;
+
+       __wm->activateWindow(dswlSurface);
 }
 
 void DSWaylandTizenPolicyPrivate::tizen_policy_activate_below_by_res_id(Resource *resource, uint32_t res_id, uint32_t below_res_id)
@@ -96,12 +104,22 @@ void DSWaylandTizenPolicyPrivate::tizen_policy_activate_below_by_res_id(Resource
 
 void DSWaylandTizenPolicyPrivate::tizen_policy_raise(Resource *resource, struct ::wl_resource *surface)
 {
-       DSLOG_DBG("TizenPolicyPriv", "");
+       DSLOG_DBG("TizenPolicyPriv", "Request to raise. resource:%p, wl_surface:%p", resource, surface);
+       DSWaylandSurface *dswlSurface = DSWaylandSurface::fromWlResource(surface);
+       if (!dswlSurface) return;
+       if (!__wm) return;
+
+       __wm->raiseWindow(dswlSurface);
 }
 
 void DSWaylandTizenPolicyPrivate::tizen_policy_lower(Resource *resource, struct ::wl_resource *surface)
 {
-       DSLOG_DBG("TizenPolicyPriv", "");
+       DSLOG_DBG("TizenPolicyPriv", "Request to lower. resource:%p, wl_surface:%p", resource, surface);
+       DSWaylandSurface *dswlSurface = DSWaylandSurface::fromWlResource(surface);
+       if (!dswlSurface) return;
+       if (!__wm) return;
+
+       __wm->lowerWindow(dswlSurface);
 }
 
 void DSWaylandTizenPolicyPrivate::tizen_policy_lower_by_res_id(Resource *resource, uint32_t res_id)
index 3484097..af39461 100644 (file)
@@ -25,6 +25,7 @@
 #define _DS_WAYLAND_TIZEN_POLICY_PRIVATE_H_
 
 #include "dswayland-server-tizen-extension.h"
+#include "DSWindowManager.h"
 #include "DSWaylandTizenPolicy.h"
 
 namespace display_server
@@ -90,6 +91,7 @@ protected:
        void tizen_policy_set_appid(Resource *resource, int32_t pid, const std::string &appid) override;
 
 private:
+       DSWindowManager *__wm;
        std::list<std::shared_ptr<DSWaylandTizenPosition>> __tzPosList;
 };
 
index acacdf2..4137305 100644 (file)
@@ -258,6 +258,36 @@ void DSWindowManagerPrivate::setWindowPosition(DSWaylandSurface *dsSurface, int
        }
 }
 
+void DSWindowManagerPrivate::activateWindow(DSWaylandSurface *dswlSurface)
+{
+       // find dswlSurface's window
+       DSZone *zone = __getZone(dswlSurface);
+       if (zone)
+       {
+               zone->activateWindow(dswlSurface);
+       }
+}
+
+void DSWindowManagerPrivate::raiseWindow(DSWaylandSurface *dswlSurface)
+{
+       // find dswlSurface's window
+       DSZone *zone = __getZone(dswlSurface);
+       if (zone)
+       {
+               zone->raiseWindow(dswlSurface);
+       }
+}
+
+void DSWindowManagerPrivate::lowerWindow(DSWaylandSurface *dswlSurface)
+{
+       // find dswlSurface's window
+       DSZone *zone = __getZone(dswlSurface);
+       if (zone)
+       {
+               zone->lowerWindow(dswlSurface);
+       }
+}
+
 DSWindowManager::DSWindowManager(DSObject *parent)
     : DS_INIT_PRIVATE_PTR(DSWindowManager)
 {
@@ -380,5 +410,23 @@ void DSWindowManager::setWindowPosition(DSWaylandSurface *dsSurface, int x, int
        priv->setWindowPosition(dsSurface, x, y);
 }
 
+void DSWindowManager::activateWindow(DSWaylandSurface *dswlSurface)
+{
+       DS_GET_PRIV(DSWindowManager);
+       priv->activateWindow(dswlSurface);
+}
+
+void DSWindowManager::raiseWindow(DSWaylandSurface *dswlSurface)
+{
+       DS_GET_PRIV(DSWindowManager);
+       priv->raiseWindow(dswlSurface);
+}
+
+void DSWindowManager::lowerWindow(DSWaylandSurface *dswlSurface)
+{
+       DS_GET_PRIV(DSWindowManager);
+       priv->lowerWindow(dswlSurface);
+}
+
 
 } // namespace display_server
index 08eb75d..6b6ce69 100644 (file)
@@ -60,6 +60,10 @@ public:
        void setWindowGeometry(DSWaylandSurface *dsSurface, int x, int y, unsigned int w, unsigned h);
        void setWindowPosition(DSWaylandSurface *dsSurface, int x, int y);
 
+       void activateWindow(DSWaylandSurface *dswlSurface);
+       void raiseWindow(DSWaylandSurface *dswlSurface);
+       void lowerWindow(DSWaylandSurface *dswlSurface);
+
 protected:
 
 private:
index 43acc3e..b42ad84 100644 (file)
@@ -55,6 +55,10 @@ public:
        void setWindowGeometry(DSWaylandSurface *dsSurface, int x, int y, unsigned int w, unsigned h);
        void setWindowPosition(DSWaylandSurface *dsSurface, int x, int y);
 
+       void activateWindow(DSWaylandSurface *dswlSurface);
+       void raiseWindow(DSWaylandSurface *dswlSurface);
+       void lowerWindow(DSWaylandSurface *dswlSurface);
+
 private:
        DSZone *__getZone(DSWindow *window);
        DSZone *__getZone(DSWaylandSurface *surface);
index fe5ab33..39ceafa 100644 (file)
@@ -36,7 +36,9 @@ DSZone::DSZone()
          __size{0, 0},
          __waylandCompositor(nullptr),
          __wm(nullptr),
-         __waylandShell(nullptr)
+         __eventLoop(nullptr),
+         __waylandShell(nullptr),
+         __stackChanged(false)
 {
        __waylandCompositor = DSWaylandCompositor::getInstance();
        if (__waylandCompositor)
@@ -48,6 +50,11 @@ DSZone::DSZone()
                if (__wm)
                        __wm->registerZone(this);
 
+               __eventLoop = DSEventLoop::getInstance();
+               if (__eventLoop)
+                       __eventLoop->registerCallbackIdleEnterer(this, std::bind(&DSZone::__onEventIdleEnterer, this, std::placeholders::_1));
+
+
                __waylandShell = __waylandCompositor->getShell();
                if (__waylandShell)
                        __waylandShell->registerCallbackShellSurfaceCreated(this, std::bind(&DSZone::__onShellSurfaceCreated, this, std::placeholders::_1));
@@ -58,9 +65,12 @@ DSZone::~DSZone()
 {
        if (__wm)
                __wm->unregisterZone(this);
-
-       DSWindowManager::releaseInstance();
-       DSWaylandCompositor::releaseInstance();
+       if (__eventLoop)
+               DSEventLoop::releaseInstance();
+       if (__wm)
+               DSWindowManager::releaseInstance();
+       if (__waylandCompositor)
+               DSWaylandCompositor::releaseInstance();
 }
 
 void DSZone::setPosition(stPosition &position)
@@ -113,6 +123,17 @@ void DSZone::callCallbackWindowCreated()
        __windowCreatedSignal.emit(nullptr);
 }
 
+void DSZone::__onEventIdleEnterer(void *data)
+{
+       if (__stackChanged)
+       {
+               DSLOG_DBG("DSZone", "Calculate Visibility...");
+
+               // calculate visibility?
+               __stackChanged = false;
+       }
+}
+
 void DSZone::__onSurfaceCreated(std::shared_ptr<DSWaylandSurface> waylandSurface)
 {
        DSLOG_DBG("DSZone", "waylandSurface:(shared:%p, pure:%p)", waylandSurface, waylandSurface.get());
@@ -170,9 +191,17 @@ void DSZone::__onShellSurfaceCreated(IDSWaylandShellSurface *waylandShellSurface
 }
 
 // for Test
-void DSZone::callCallbackWindowShellCreated()
+void DSZone::callCallbackWindowShellCreated(std::shared_ptr<DSWindowShell> winShell)
+{
+       __windowShellCreatedSignal.emit(winShell);
+}
+
+bool DSZone::testCreateWindow(std::shared_ptr<DSWaylandSurface> waylandSurface)
 {
-       __windowShellCreatedSignal.emit(nullptr);
+       std::shared_ptr<DSWindow> window = __createWindow(waylandSurface);
+       if (!window) return false;
+
+       return true;
 }
 
 std::list<std::shared_ptr<DSWindow>> DSZone::getWindowList()
@@ -185,6 +214,22 @@ std::list<std::shared_ptr<DSWindowShell>> DSZone::getWindowShellList()
        return __windowShellList;
 }
 
+void DSZone::__prependWindowList(std::shared_ptr<DSWindow> window)
+{
+       __windowList.remove(window);
+       __windowList.push_front(window);
+
+       __stackChanged = true;
+}
+
+void DSZone::__appendWindowList(std::shared_ptr<DSWindow> window)
+{
+       __windowList.remove(window);
+       __windowList.push_back(window);
+
+       __stackChanged = true;
+}
+
 std::shared_ptr<DSWindow> DSZone::__findWindow(DSWaylandSurface *dswlSurface)
 {
        std::list<std::shared_ptr<DSWindow>> wList = getWindowList();
@@ -221,7 +266,7 @@ DSWindowShell *DSZone::__findWindowShell(DSWaylandSurface *dswlSurface)
 std::shared_ptr<DSWindow> DSZone::__createWindow(std::shared_ptr<DSWaylandSurface> waylandSurface)
 {
        std::shared_ptr<DSWindow> window = std::make_shared<DSWindow>(waylandSurface);
-       __windowList.push_front(window);
+       __prependWindowList(window);
 
        // emit a signal of the surface committed
        __windowCreatedSignal.emit(window);
@@ -328,5 +373,44 @@ bool DSZone::setWindowPosition(DSWaylandSurface *dswSurface, int x, int y)
 */
 }
 
+void DSZone::activateWindow(DSWaylandSurface *dswlSurface)
+{
+       if (!dswlSurface) return;
+
+       std::shared_ptr<DSWindow> window = __findWindow(dswlSurface);
+       __prependWindowList(window);
+
+       DSWindowShell *wShell = __findWindowShell(dswlSurface);
+       if (!wShell) return;
+
+       wShell->activate();
+}
+
+void DSZone::raiseWindow(DSWaylandSurface* dswlSurface)
+{
+       if (!dswlSurface) return;
+
+       std::shared_ptr<DSWindow> window = __findWindow(dswlSurface);
+       __prependWindowList(window);
+
+       DSWindowShell *wShell = __findWindowShell(dswlSurface);
+       if (!wShell) return;
+
+       wShell->raise();
+}
+
+void DSZone::lowerWindow(DSWaylandSurface* dswlSurface)
+{
+       if (!dswlSurface) return;
+
+       std::shared_ptr<DSWindow> window = __findWindow(dswlSurface);
+       __appendWindowList(window);
+
+       DSWindowShell *wShell = __findWindowShell(dswlSurface);
+       if (!wShell) return;
+
+       wShell->lower();
+}
+
 
 } //  namespace display_server
index 7b37a6c..e115978 100644 (file)
@@ -30,6 +30,7 @@
 #include "DSWindowShell.h"
 #include "DSSignal.h"
 #include "DSStruct.h"
+#include "DSEventLoop.h"
 
 namespace display_server
 {
@@ -57,7 +58,9 @@ public:
 
        // emit functions for testing
        void callCallbackWindowCreated();
-       void callCallbackWindowShellCreated();
+       void callCallbackWindowShellCreated(std::shared_ptr<DSWindowShell> winShell);
+       // for test
+       bool testCreateWindow(std::shared_ptr<DSWaylandSurface> waylandSurface);
 
        // for window property
        bool setWindowTitle(DSWaylandSurface *dswSurface, const std::string &title);
@@ -65,10 +68,16 @@ public:
        bool setWindowGeometry(DSWaylandSurface *dswSurface, int x, int y, unsigned int w, unsigned h);
        bool setWindowPosition(DSWaylandSurface *dswSurface, int x, int y);
 
+       void activateWindow(DSWaylandSurface *dswlSurface);
+       void raiseWindow(DSWaylandSurface* dswlSurface);
+       void lowerWindow(DSWaylandSurface* dswlSurface);
+
        std::list<std::shared_ptr<DSWindow>> getWindowList();
        std::list<std::shared_ptr<DSWindowShell>> getWindowShellList();
 
 private:
+       void __onEventIdleEnterer(void *data);
+
        void __onSurfaceCreated(std::shared_ptr<DSWaylandSurface> waylandSurface);
        void __onSurfaceDestroy(std::shared_ptr<DSWaylandSurface> waylandSurface);
 
@@ -80,6 +89,9 @@ private:
        std::shared_ptr<DSWindowShell> __createWindowShell(std::shared_ptr<DSWindow> window);
        void __destroyWindowShell(DSWindowShell* windowShell, DSWaylandSurface *surface);
 
+       void __prependWindowList(std::shared_ptr<DSWindow> window);
+       void __appendWindowList(std::shared_ptr<DSWindow> window);
+
        std::shared_ptr<DSWindow> __findWindow(DSWaylandSurface *dswlSurface);
        DSWindowShell* __findWindowShell(DSWaylandSurface *dswlSurface);
 
@@ -89,7 +101,9 @@ private:
        std::list<std::shared_ptr<DSWindowShell>> __windowShellList;
        DSWaylandCompositor *__waylandCompositor;
        DSWindowManager *__wm;
+       DSEventLoop *__eventLoop;
        IDSWaylandShell *__waylandShell;
+       bool __stackChanged;
 
        std::map<DSWaylandSurface*, DSWindowShell*> __windowShellMap;
 
index e302e52..83a685b 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "libds-tests.h"
 #include "DSZone.h"
+#include "DSWaylandSurface.h"
+#include "DSWindow.h"
 #include "DSPolicyArea.h"
 #include "DSPolicyAreaPrivate.h"
 
@@ -45,7 +47,13 @@ public:
                  __boolOnWindowShellCreated(false)
        {
                zone->registerCallbackWindowCreated(this, std::bind(&TestZone::onWindowCreated, this, std::placeholders::_1));
+               zone->registerCallbackWindowShellCreated(this, std::bind(&TestZone::onWindowShellCreated, this, std::placeholders::_1));
                __zone = zone;
+
+               __countWindow = 0;
+
+               for (int i=0; i<5; i++)
+                       myWindow[i] = nullptr;
        }
 
        ~TestZone()
@@ -61,24 +69,39 @@ public:
 
        void onWindowCreated(std::shared_ptr<DSWindow> window) {
                __boolOnWindowCreated = true;
+
+               myWindow[__countWindow] = window.get();
+               __countWindow++;
        }
 
-       void callOnWindowShellCreated() {
-               __zone->callCallbackWindowShellCreated();
+       void callOnWindowShellCreated(std::shared_ptr<DSWindowShell> winShell) {
+               __zone->callCallbackWindowShellCreated(winShell);
        }
 
        bool getResultOnWindowShellCreated() {
                return __boolOnWindowShellCreated;
        }
 
-       void onWindowShellCreated(std::shared_ptr<DSWindow> window) {
+       void onWindowShellCreated(std::shared_ptr<DSWindowShell> windowShell) {
                __boolOnWindowShellCreated = true;
        }
 
+       std::list<std::shared_ptr<DSWindow>> getWindowList() {
+               return __zone->getWindowList();
+       }
+
+       int getWindowCount() {
+               return __countWindow;
+       }
+
+public:
+       DSWindow* myWindow[5];
+
 private:
        bool __boolOnWindowCreated;
        bool __boolOnWindowShellCreated;
        std::shared_ptr<DSZone> __zone;
+       int __countWindow;
 };
 
 TEST_F(DSZoneTest, NewDSZone)
@@ -136,8 +159,43 @@ TEST_F(DSZoneTest, registerCallbackWindowShellCreated)
        // before calling WindowShell created
        EXPECT_FALSE(testZone->getResultOnWindowShellCreated());
 
-       testZone->callOnWindowShellCreated();
+       testZone->callOnWindowShellCreated(nullptr);
 
        // after calling WindowShell created
        EXPECT_TRUE(testZone->getResultOnWindowShellCreated());
 }
+
+TEST_F(DSZoneTest, stackChanged)
+{
+       int count;
+
+       auto zone = std::make_shared<DSZone>();
+       EXPECT_TRUE(zone != nullptr);
+
+       auto testZone = std::make_shared<TestZone>(zone);
+
+       EXPECT_TRUE(testZone != nullptr);
+
+       auto dswlSurface1 = std::make_shared<DSWaylandSurface>();
+       EXPECT_TRUE(zone->testCreateWindow(dswlSurface1));
+
+       auto dswlSurface2 = std::make_shared<DSWaylandSurface>();
+       EXPECT_TRUE(zone->testCreateWindow(dswlSurface2));
+
+       count = testZone->getWindowCount();
+       for (std::shared_ptr<DSWindow> w : zone->getWindowList())
+       {
+               EXPECT_TRUE(w.get() == testZone->myWindow[count-1]);
+               count--;
+       }
+
+       zone->raiseWindow(dswlSurface1.get());
+
+       count = 0;
+       for (std::shared_ptr<DSWindow> w : zone->getWindowList())
+       {
+               EXPECT_TRUE(w.get() == testZone->myWindow[count]);
+               count++;
+       }
+}
+