From 13cf6abd4962497bbd1cf1cb372b82d8ca8472fb Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jul 2020 08:27:09 +0900 Subject: [PATCH] DSPolicyArea: move the DSZone from DSCanvasPrivate to DSPolicyAreaPrivate Change-Id: Ic5d391e18888e856db2784a7f6c4d9d8bc17da05 --- src/DSCanvas/DSCanvas.cpp | 24 ++++++++++--------- src/DSPolicyArea/DSPolicyArea.cpp | 42 +++++++++++++++------------------- src/DSPolicyArea/DSPolicyAreaPrivate.h | 7 +++--- src/DSZone/DSZone.cpp | 36 +++++++++++++++-------------- src/DSZone/DSZone.h | 16 +++++++------ tests/DSZone-test.cpp | 37 ++++++++++++++++++------------ 6 files changed, 85 insertions(+), 77 deletions(-) diff --git a/src/DSCanvas/DSCanvas.cpp b/src/DSCanvas/DSCanvas.cpp index e05c643..959facc 100644 --- a/src/DSCanvas/DSCanvas.cpp +++ b/src/DSCanvas/DSCanvas.cpp @@ -46,22 +46,22 @@ DSCanvasPrivate::~DSCanvasPrivate() bool DSCanvasPrivate::attachPolicyArea(std::shared_ptr policyArea) { - if (__zone) { - DSLOG_ERR("DSCanvasPrivate", "canvas has already policyArea."); + if (policyArea) { + DSLOG_ERR("DSCanvasPrivate", "canvas has already policyArea(%p).", __policyArea); return false; } - __zone = std::make_shared(policyArea); + __policyArea = policyArea; // add zone to DSDisplayAreaPrivate if (__displayArea) { DSDisplayAreaPrivate *displayAreaPriv = DSDisplayAreaPrivate::getPrivate(__displayArea.get()); - if (displayAreaPriv) - displayAreaPriv->addZone(__zone); + if (displayAreaPriv) { + DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); + displayAreaPriv->addZone(policyAreaPriv->getZone()); + } } - __policyArea = policyArea; - return true; } @@ -72,15 +72,17 @@ bool DSCanvasPrivate::attachDisplayArea(std::shared_ptr displayAr return false; } + __displayArea = displayArea; + // add zone to DSDisplayAreaPrivate if (__policyArea) { DSDisplayAreaPrivate *displayAreaPriv = DSDisplayAreaPrivate::getPrivate(__displayArea.get()); - if (displayAreaPriv) - displayAreaPriv->addZone(__zone); + if (displayAreaPriv) { + DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); + displayAreaPriv->addZone(policyAreaPriv->getZone()); + } } - __displayArea = displayArea; - return true; } diff --git a/src/DSPolicyArea/DSPolicyArea.cpp b/src/DSPolicyArea/DSPolicyArea.cpp index 3f63e14..3c39ca7 100644 --- a/src/DSPolicyArea/DSPolicyArea.cpp +++ b/src/DSPolicyArea/DSPolicyArea.cpp @@ -49,45 +49,35 @@ DSPolicyAreaPrivate::DSPolicyAreaPrivate(DSPolicyArea *p_ptr) __width(0), __height(0), __seat(nullptr) -{} +{ + __zone = std::make_shared(); +} DSPolicyAreaPrivate::~DSPolicyAreaPrivate() {} bool DSPolicyAreaPrivate::setPosition(int x, int y) { - __x = x; - __y = y; + stPosition position; - return true; -} + position.x = x; + position.y = y; -bool DSPolicyAreaPrivate::setSize(int width, int height) -{ - __width = width; - __height = height; + __zone->setPosition(position); return true; } -int DSPolicyAreaPrivate::getX() +bool DSPolicyAreaPrivate::setSize(int width, int height) { - return __x; -} + stSize size; -int DSPolicyAreaPrivate::getY() -{ - return __y; -} + size.w = width; + size.h = height; -int DSPolicyAreaPrivate::getWidth() -{ - return __width; -} + __zone->setSize(size); -int DSPolicyAreaPrivate::getHeight() -{ - return __height; + return true; } bool DSPolicyAreaPrivate::attachSeat(std::shared_ptr seat) @@ -97,4 +87,10 @@ bool DSPolicyAreaPrivate::attachSeat(std::shared_ptr seat) return true; } +std::shared_ptr DSPolicyAreaPrivate::getZone() +{ + return __zone; +} + + } // namespace display_server \ No newline at end of file diff --git a/src/DSPolicyArea/DSPolicyAreaPrivate.h b/src/DSPolicyArea/DSPolicyAreaPrivate.h index 903b3c0..e99666c 100644 --- a/src/DSPolicyArea/DSPolicyAreaPrivate.h +++ b/src/DSPolicyArea/DSPolicyAreaPrivate.h @@ -2,6 +2,7 @@ #define __DS_POLICY_AREA_PRIVATE_H__ #include "DSPolicyArea.h" +#include "DSZone.h" namespace display_server { @@ -17,16 +18,14 @@ public: static DSPolicyAreaPrivate *getPrivate(DSPolicyArea *q) { return q->__d_func(); } bool setPosition(int x, int y); bool setSize(int width, int height); - int getX(); - int getY(); - int getWidth(); - int getHeight(); bool attachSeat(std::shared_ptr seat); + std::shared_ptr getZone(); private: int __x, __y; int __width, __height; std::shared_ptr __seat; + std::shared_ptr __zone; }; } diff --git a/src/DSZone/DSZone.cpp b/src/DSZone/DSZone.cpp index 1dddd80..d26892e 100644 --- a/src/DSZone/DSZone.cpp +++ b/src/DSZone/DSZone.cpp @@ -1,13 +1,13 @@ #include "DSZone.h" -#include "DSPolicyAreaPrivate.h" #include "DSWaylandCompositor.h" #include "DSWaylandSurface.h" namespace display_server { -DSZone::DSZone(std::shared_ptr policyArea) - : __policyArea(policyArea), +DSZone::DSZone() + : __position{0, 0}, + __size{0, 0}, __waylandCompositor(nullptr) { __waylandCompositor = DSWaylandCompositor::getInstance(); @@ -19,32 +19,34 @@ DSZone::~DSZone() DSWaylandCompositor::releaseInstance(); } -int DSZone::getX() +void DSZone::setPosition(stPosition &position) { - DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); - - return policyAreaPriv->getX(); + __position.x = position.x; + __position.y = position.y; } -int DSZone::getY() +void DSZone::setSize(stSize &size) { - DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); - - return policyAreaPriv->getY(); + __size.w = size.w; + __size.h = size.h; } -int DSZone::getWidth() +stPosition DSZone::getPosition() { - DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); + stPosition position; + position.x = __position.x; + position.y = __position.y; - return policyAreaPriv->getWidth(); + return position; } -int DSZone::getHeight() +stSize DSZone::getSize() { - DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); + stSize size; + size.w = __size.w; + size.h = __size.h; - return policyAreaPriv->getHeight(); + return size; } void DSZone::registerCallbackWindowCreated(DSObject *slot, std::function)> func) diff --git a/src/DSZone/DSZone.h b/src/DSZone/DSZone.h index 58bea43..3e6d16d 100644 --- a/src/DSZone/DSZone.h +++ b/src/DSZone/DSZone.h @@ -3,7 +3,8 @@ #include #include "DSWindow.h" -#include "DSPolicyArea.h" +#include "DSSignal.h" +#include "DSStruct.h" namespace display_server { @@ -12,13 +13,13 @@ class DSWaylandSurface; class DSZone : public DSObject { public: - explicit DSZone(std::shared_ptr policyArea); + explicit DSZone(); virtual ~DSZone(); - int getX(); - int getY(); - int getWidth(); - int getHeight(); + void setPosition(stPosition &position); + void setSize(stSize &size); + stPosition getPosition(); + stSize getSize(); // Callback methods void registerCallbackWindowCreated(DSObject *slot, std::function)> func); @@ -29,7 +30,8 @@ public: private: void onSurfaceCreated(std::shared_ptr waylandSurface); - std::shared_ptr __policyArea; + stPosition __position; + stSize __size; std::list> __windowList; DSWaylandCompositor *__waylandCompositor; diff --git a/tests/DSZone-test.cpp b/tests/DSZone-test.cpp index c6e32da..9ab71db 100644 --- a/tests/DSZone-test.cpp +++ b/tests/DSZone-test.cpp @@ -46,32 +46,39 @@ private: TEST_F(DSZoneTest, NewDSZone) { - auto policyArea = std::make_shared(); - auto zone = std::make_unique(policyArea); + auto zone = std::make_unique(); EXPECT_TRUE(zone != nullptr); } TEST_F(DSZoneTest, BasicMethods) { - auto policyArea = std::make_shared(); - EXPECT_TRUE(policyArea->setPosition(10, 10) == true); - EXPECT_TRUE(policyArea->setSize(100, 100) == true); - - auto zone = std::make_unique(policyArea); + auto zone = std::make_unique(); EXPECT_TRUE(zone != nullptr); - EXPECT_TRUE(zone->getX() == 10); - EXPECT_TRUE(zone->getY() == 10); - EXPECT_TRUE(zone->getWidth() == 100); - EXPECT_TRUE(zone->getHeight() == 100); + stPosition position1; + position1.x = 10; + position1.y = 10; + zone->setPosition(position1); + + stPosition position2; + position2 = zone->getPosition(); + EXPECT_TRUE(position1.x == position2.x); + EXPECT_TRUE(position1.y == position2.y); + + stSize size1; + size1.w = 100; + size1.h = 100; + zone->setSize(size1); + + stSize size2; + size2 = zone->getSize(); + EXPECT_TRUE(size1.w == size2.w); + EXPECT_TRUE(size1.h == size2.h); } TEST_F(DSZoneTest, registerCallbackWindowCreated) { - auto policyArea = std::make_shared(); - EXPECT_TRUE(policyArea->setPosition(10, 10) == true); - EXPECT_TRUE(policyArea->setSize(100, 100) == true); - auto zone = std::make_shared(policyArea); + auto zone = std::make_shared(); EXPECT_TRUE(zone != nullptr); auto testZone = std::make_shared(zone); -- 2.7.4