DSWindowShell: add code to handle geometry 28/242328/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Tue, 25 Aug 2020 04:18:11 +0000 (13:18 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 25 Aug 2020 12:38:43 +0000 (21:38 +0900)
we add code to check DSWindow's allowUserGeometry property
before applying geometry

Change-Id: Id0bbe05e229eac683b7592f714ce138275697354

src/DSWindowShell/DSWindowShell.cpp
src/DSWindowShell/DSWindowShell.h
src/DSWindowShell/DSWindowShellPrivate.cpp
src/DSWindowShell/DSWindowShellPrivate.h
src/DSZone/DSZone.cpp
tests/DSWindowShell-test.cpp

index 6863736..8b9a78b 100644 (file)
@@ -55,6 +55,18 @@ void DSWindowShell::destroy(void)
 
 }
 
+bool DSWindowShell::setZone(DSZone *zone)
+{
+       DS_GET_PRIV(DSWindowShell);
+       return priv->setZone(zone);
+}
+
+DSZone *DSWindowShell::getZone(void)
+{
+       DS_GET_PRIV(DSWindowShell);
+       return priv->getZone();
+}
+
 void DSWindowShell::setShellSurface(IDSWaylandShellSurface *shellSurface)
 {
        DS_GET_PRIV(DSWindowShell);
index f5a76f2..7690094 100644 (file)
@@ -33,6 +33,7 @@ namespace display_server
 
 class DSWindow;
 class DSWindowShellPrivate;
+class DSZone;
 
 class DSWindowShell
 {
@@ -47,6 +48,9 @@ public:
 
        void destroy(void);
 
+       bool setZone(DSZone *zone);
+       DSZone *getZone(void);
+
        void setShellSurface(IDSWaylandShellSurface *zxdgSurface);
        IDSWaylandShellSurface *getShellSurface(void);
 
index 928bee4..f70ebf0 100644 (file)
@@ -21,6 +21,7 @@
 * DEALINGS IN THE SOFTWARE.
 */
 
+#include "DSZone.h"
 #include "DSWindowShell.h"
 #include "DSWindowShellPrivate.h"
 
@@ -63,6 +64,7 @@ DSWindowShellPrivate::DSWindowShellPrivate(DSWindowShell *p_ptr, DSWindow *windo
        : __p_ptr(p_ptr),
          __window(window),
          __shellSurface(nullptr),
+         __zone(nullptr),
          __x(0), __y(0),
          __w(0), __h(0),
          __reqX(0), __reqY(0),
@@ -155,10 +157,42 @@ void DSWindowShellPrivate::__handleAuxHint(stWindowAuxHint *hint)
                else
                        set = false;
 
-               __window->allowUserGeometry(set);
+               __handleUserGeometryHint(set);
        }
 }
 
+bool DSWindowShellPrivate::__handleUserGeometryHint(bool setUserGeometry)
+{
+       if (!__window) return false;
+
+       __window->allowUserGeometry(setUserGeometry);
+       if (setUserGeometry)
+       {
+               // reset windows geometry
+               __x = __y = __w = __h = 0;
+               __window->setPosition(__x, __y);
+               __window->setSize(__w, __h);
+       }
+       else
+       {
+               // apply zone's geometry
+               if (__zone)
+               {
+                       stPosition zPos = __zone->getPosition();
+                       stSize zSize = __zone->getSize();
+                       __x = zPos.x;
+                       __y = zPos.y;
+                       __w = zSize.w;
+                       __h = zSize.h;
+
+                       __window->setPosition(__x, __y);
+                       __window->setSize(__w, __h);
+               }
+       }
+
+       return true;
+}
+
 bool DSWindowShellPrivate::create(DSWindowShell *pParent)
 {
        return true;
@@ -186,6 +220,49 @@ void DSWindowShellPrivate::destroy(void)
 
 }
 
+bool DSWindowShellPrivate::setZone(DSZone *zone)
+{
+       if (__zone)
+       {
+               // unset information for old zone
+       }
+
+       __zone = zone;
+       if (__zone)
+       {
+               stPosition zPos = __zone->getPosition();
+               stSize zSize = __zone->getSize();
+
+               // check whether DSWindowShell's geometry has to change or not
+               if (__window)
+               {
+                       if (!__window->isAllowUserGeometry())
+                       {
+                               __x = zPos.x;
+                               __y = zPos.y;
+                               __w = zSize.w;
+                               __h = zSize.h;
+
+                               __window->setPosition(__x, __y);
+                               __window->setSize(__w, __h);
+                       }
+               }
+               else
+               {
+                       __x = zPos.x;
+                       __y = zPos.y;
+                       __w = zSize.w;
+                       __h = zSize.h;
+               }
+       }
+
+       return true;
+}
+
+DSZone *DSWindowShellPrivate::getZone(void)
+{
+       return __zone;
+}
 
 void DSWindowShellPrivate::setShellSurface(IDSWaylandShellSurface *shellSurface)
 {
@@ -247,11 +324,23 @@ bool DSWindowShellPrivate::setSkipFocus(bool set)
 
 bool DSWindowShellPrivate::setPosition(int x, int y)
 {
-       __x = x;
-       __y = y;
+       __reqX = x;
+       __reqY = y;
 
        if (__window)
-               __window->setPosition(__x, __y);
+       {
+               if (__window->isAllowUserGeometry())
+               {
+                       __x = x;
+                       __y = y;
+                       __window->setPosition(__x, __y);
+               }
+       }
+       else
+       {
+               __x = x;
+               __y = y;
+       }
 
        return true;
 }
@@ -268,26 +357,52 @@ stPosition DSWindowShellPrivate::getPosition(void)
 
 bool DSWindowShellPrivate::setSize(unsigned int w, unsigned int h)
 {
-       __w = w;
-       __h = h;
+       __reqW = w;
+       __reqH = h;
 
        if (__window)
-               __window->setSize(__w, __h);
+       {
+               if (__window->isAllowUserGeometry())
+               {
+                       __w = w;
+                       __h = h;
+                       __window->setSize(__w, __h);
+               }
+       }
+       else
+       {
+               __w = w;
+               __h = h;
+       }
 
        return true;
 }
 
 bool DSWindowShellPrivate::setGeometry(int x, int y, unsigned int w, unsigned int h)
 {
-       __x = x;
-       __y = y;
-       __w = w;
-       __h = h;
+       __reqX = x;
+       __reqY = y;
+       __reqW = w;
+       __reqH = h;
 
        if (__window)
        {
-               __window->setPosition(__x, __y);
-               __window->setSize(__w, __h);
+               if (__window->isAllowUserGeometry())
+               {
+                       __x = x;
+                       __y = y;
+                       __w = w;
+                       __h = h;
+                       __window->setPosition(__x, __y);
+                       __window->setSize(__w, __h);
+               }
+       }
+       else
+       {
+               __x = x;
+               __y = y;
+               __w = w;
+               __h = h;
        }
 
        return true;
index df1e9c8..25e27ae 100644 (file)
@@ -52,6 +52,9 @@ public:
 
        void destroy(void);
 
+       bool setZone(DSZone *zone);
+       DSZone *getZone(void);
+
        void setShellSurface(IDSWaylandShellSurface *shellSurface);
        IDSWaylandShellSurface *getShellSurface(void);
 
@@ -126,14 +129,16 @@ private:
 
        struct stWindowAuxHint* __findAuxHint(int32_t id);
        void __handleAuxHint(stWindowAuxHint *hint);
+       bool __handleUserGeometryHint(bool setUserGeometry);
 
 private:
        DSWindow *__window;
        IDSWaylandShellSurface *__shellSurface;
-       int __x, __y;
-       unsigned int __w, __h;
-       int __reqX, __reqY;
-       unsigned int __reqW, __reqH;
+       DSZone *__zone;
+       int __x, __y; // real (applied) position
+       unsigned int __w, __h; // real (applied) size
+       int __reqX, __reqY; // requested position by client
+       unsigned int __reqW, __reqH; // requested size by client
        DSWindowShell *__parent;
        int __layer;
        std::list<DSWindowShell*> __childList;
index 3af703e..c1027be 100644 (file)
@@ -325,6 +325,10 @@ std::shared_ptr<DSWindowShell> DSZone::__createWindowShell(std::shared_ptr<DSWin
        DSWindow *ptrWindow = window.get();
 
        std::shared_ptr<DSWindowShell> shell = std::make_shared<DSWindowShell>(ptrWindow);
+       if (!shell) return nullptr;
+
+       shell->setZone(this);
+
        __windowShellList.push_front(shell);
 
        __windowShellMap.insert(std::make_pair(ptrWindow->surface(), shell.get()));
index 01fba49..0ac8b4d 100644 (file)
@@ -104,7 +104,23 @@ TEST_F(DSWindowShellTest, getPosition_P1)
        std::unique_ptr<DSWindowShell> shell = std::make_unique<DSWindowShell>(window.get());
        EXPECT_TRUE(shell != nullptr);
 
-       EXPECT_TRUE(shell->create(0, 0, 720, 1280, nullptr) == true);
+       EXPECT_TRUE(shell->setPosition(100, 150) == true);
+       pos = shell->getPosition();
+
+       EXPECT_TRUE(pos.x == 0);
+       EXPECT_TRUE(pos.y == 0);
+}
+
+TEST_F(DSWindowShellTest, getPosition_P2)
+{
+       stPosition pos;
+       auto window = std::make_shared<DSWindow>();
+       std::unique_ptr<DSWindowShell> shell = std::make_unique<DSWindowShell>(window.get());
+       EXPECT_TRUE(shell != nullptr);
+
+       // set user geometry
+       shell->addAuxHint(1, "wm.policy.win.user.geometry", "1");
+
        EXPECT_TRUE(shell->setPosition(100, 150) == true);
 
        pos = shell->getPosition();
@@ -131,7 +147,25 @@ TEST_F(DSWindowShellTest, Geometry_P1)
        std::unique_ptr<DSWindowShell> shell = std::make_unique<DSWindowShell>(window.get());
        EXPECT_TRUE(shell != nullptr);
 
-       EXPECT_TRUE(shell->create(0, 0, 720, 1280, nullptr) == true);
+       shell->setGeometry(100, 150, 480, 800);
+       geo = shell->getGeometry();
+
+       EXPECT_TRUE(geo.x == 0);
+       EXPECT_TRUE(geo.y == 0);
+       EXPECT_TRUE(geo.w == 0);
+       EXPECT_TRUE(geo.h == 0);
+}
+
+TEST_F(DSWindowShellTest, Geometry_P2)
+{
+       stGeometry geo;
+
+       auto window = std::make_shared<DSWindow>();
+       std::unique_ptr<DSWindowShell> shell = std::make_unique<DSWindowShell>(window.get());
+       EXPECT_TRUE(shell != nullptr);
+
+       // set user geometry
+       shell->addAuxHint(1, "wm.policy.win.user.geometry", "1");
 
        shell->setGeometry(100, 150, 480, 800);
        geo = shell->getGeometry();