From 861cc59d3c9fef41cfd91ddc66243822265cded7 Mon Sep 17 00:00:00 2001 From: Doyoun Kang Date: Tue, 18 Aug 2020 16:36:24 +0900 Subject: [PATCH] add sample code to handle request (set title) Change-Id: I6e95c415675585ea4188df166644610413d6298d --- src/DSWaylandServer/DSWaylandZxdgShellV6.cpp | 6 +++++- src/DSWindow/DSWindow.cpp | 27 ++++++++++++++++++++++- src/DSWindow/DSWindow.h | 3 +++ src/DSWindow/DSWindowPrivate.h | 4 ++++ src/DSWindowManager/DSWindowManager.cpp | 20 +++++++++++++++++ src/DSWindowManager/DSWindowManager.h | 2 ++ src/DSWindowManager/DSWindowManagerPrivate.h | 2 ++ src/DSZone/DSZone.cpp | 6 ++++++ src/DSZone/DSZone.h | 3 +++ tests/DSWindow-test.cpp | 32 ++++++++++++++++++++-------- 10 files changed, 94 insertions(+), 11 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandZxdgShellV6.cpp b/src/DSWaylandServer/DSWaylandZxdgShellV6.cpp index 47d3b0d..76b3758 100644 --- a/src/DSWaylandServer/DSWaylandZxdgShellV6.cpp +++ b/src/DSWaylandServer/DSWaylandZxdgShellV6.cpp @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include "DSWindowManager.h" #include "DSWaylandZxdgShellV6.h" #include "DSWaylandZxdgShellV6Private.h" #include "DSWaylandCompositor.h" @@ -420,8 +421,11 @@ void DSWaylandZxdgSurfaceV6Private::zxdg_surface_v6_ack_configure(zxdg_surface_v void DSWaylandZxdgSurfaceV6Private::setWindowTitle(const std::string &title) { // TODO: needs DSWindow title set method - //__window->setTitle(title); __title = title; + + DSWindowManager *wm = DSWindowManager::getInstance(); + wm->setWindowTitle(__dsSurface, __title); + DSWindowManager::releaseInstance(); } void DSWaylandZxdgSurfaceV6Private::setAppID(const std::string &appId) diff --git a/src/DSWindow/DSWindow.cpp b/src/DSWindow/DSWindow.cpp index d210e16..434d134 100644 --- a/src/DSWindow/DSWindow.cpp +++ b/src/DSWindow/DSWindow.cpp @@ -42,7 +42,8 @@ DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr) __hasFocus(false), __waylandSurface(nullptr), __winShell(nullptr), - __firstCommit(true) + __firstCommit(true), + __title("") { } @@ -79,6 +80,17 @@ int DSWindowPrivate::showState(void) return 0; } +bool DSWindowPrivate::setTitle(const std::string &title) +{ + __title.replace(__title.begin(), __title.end(), title); + return true; +} + +const std::string DSWindowPrivate::getTitle(void) +{ + return __title; +} + bool DSWindowPrivate::setLayer(int layer) { return true; @@ -219,6 +231,19 @@ int DSWindow::showState(void) return priv->showState(); } +bool DSWindow::setTitle(const std::string &title) +{ + DSLOG_DBG("DSWindow", "title:%s", title.c_str()); + + DS_GET_PRIV(DSWindow); + return priv->setTitle(title); +} + +const std::string DSWindow::getTitle(void) +{ + DS_GET_PRIV(DSWindow); + return priv->getTitle(); +} bool DSWindow::setLayer(int layer) { diff --git a/src/DSWindow/DSWindow.h b/src/DSWindow/DSWindow.h index ec94e12..04bfa9f 100644 --- a/src/DSWindow/DSWindow.h +++ b/src/DSWindow/DSWindow.h @@ -53,6 +53,9 @@ public: bool hide(bool autoFocus = true); int showState(void); + bool setTitle(const std::string &title); + const std::string getTitle(void); + bool setLayer(int layer); bool raise(void); bool lower(void); diff --git a/src/DSWindow/DSWindowPrivate.h b/src/DSWindow/DSWindowPrivate.h index 249c5b0..d532ad0 100644 --- a/src/DSWindow/DSWindowPrivate.h +++ b/src/DSWindow/DSWindowPrivate.h @@ -50,6 +50,9 @@ public: bool hide(bool autoFocus); int showState(void); + bool setTitle(const std::string &title); + const std::string getTitle(void); + bool setLayer(int layer); bool raise(void); bool lower(void); @@ -74,6 +77,7 @@ private: std::shared_ptr __waylandSurface; DSWindowShell *__winShell; bool __firstCommit; + std::string __title; }; } diff --git a/src/DSWindowManager/DSWindowManager.cpp b/src/DSWindowManager/DSWindowManager.cpp index 5eaa293..4a5761c 100644 --- a/src/DSWindowManager/DSWindowManager.cpp +++ b/src/DSWindowManager/DSWindowManager.cpp @@ -202,6 +202,20 @@ DSZone *DSWindowManagerPrivate::getZone(DSWaylandSurface *surface) } +void DSWindowManagerPrivate::setWindowTitle(DSWaylandSurface *dsSurface, const std::string &title) +{ + // find dsSurface's window + DSZone *zone = __getZone(dsSurface); + if (zone) + { + zone->setWindowTitle(dsSurface, title); + } + else + { + // Do something if there is no zone + } +} + DSWindowManager::DSWindowManager(DSObject *parent) : DS_INIT_PRIVATE_PTR(DSWindowManager) @@ -301,5 +315,11 @@ DSZone *DSWindowManager::getZone(DSWaylandSurface *surface) return priv->getZone(surface); } +void DSWindowManager::setWindowTitle(DSWaylandSurface *dsSurface, const std::string &title) +{ + DS_GET_PRIV(DSWindowManager); + priv->setWindowTitle(dsSurface, title); +} + } // namespace display_server diff --git a/src/DSWindowManager/DSWindowManager.h b/src/DSWindowManager/DSWindowManager.h index 7ad2f0d..9ae0af6 100644 --- a/src/DSWindowManager/DSWindowManager.h +++ b/src/DSWindowManager/DSWindowManager.h @@ -55,6 +55,8 @@ public: void unregisterSurface(DSZone *zone, DSWaylandSurface *surface); DSZone *getZone(DSWaylandSurface *surface); + void setWindowTitle(DSWaylandSurface *dsSurface, const std::string &title); + protected: private: diff --git a/src/DSWindowManager/DSWindowManagerPrivate.h b/src/DSWindowManager/DSWindowManagerPrivate.h index f92b0d7..9f6bed1 100644 --- a/src/DSWindowManager/DSWindowManagerPrivate.h +++ b/src/DSWindowManager/DSWindowManagerPrivate.h @@ -50,6 +50,8 @@ public: void unregisterSurface(DSZone *zone, DSWaylandSurface *surface); DSZone *getZone(DSWaylandSurface *surface); + void setWindowTitle(DSWaylandSurface *dsSurface, const std::string &title); + private: DSZone *__getZone(DSWindow *window); DSZone *__getZone(DSWaylandSurface *surface); diff --git a/src/DSZone/DSZone.cpp b/src/DSZone/DSZone.cpp index a838a28..0b0f043 100644 --- a/src/DSZone/DSZone.cpp +++ b/src/DSZone/DSZone.cpp @@ -261,4 +261,10 @@ void DSZone::__destroyWindowShell(DSWindowShell* windowShell, DSWaylandSurface * } } +bool DSZone::setWindowTitle(DSWaylandSurface *dswSurface, const std::string &title) +{ + std::shared_ptr window = __findWindow(dswSurface); + return window->setTitle(title); +} + } // namespace display_server diff --git a/src/DSZone/DSZone.h b/src/DSZone/DSZone.h index 5bbf38f..f89893b 100644 --- a/src/DSZone/DSZone.h +++ b/src/DSZone/DSZone.h @@ -58,6 +58,9 @@ public: void callCallbackWindowCreated(); void callCallbackWindowShellCreated(); + // for window property + bool setWindowTitle(DSWaylandSurface *dswSurface, const std::string &title); + std::list> getWindowList(); std::list> getWindowShellList(); diff --git a/tests/DSWindow-test.cpp b/tests/DSWindow-test.cpp index e10385e..7f33bd3 100644 --- a/tests/DSWindow-test.cpp +++ b/tests/DSWindow-test.cpp @@ -40,7 +40,7 @@ public: TEST_F(DSWindowTest, NewDSWindow) { - DSWindow *win = new DSWindow(); + auto win = std::make_shared(); EXPECT_TRUE(win != nullptr); } @@ -54,7 +54,7 @@ TEST_F(DSWindowTest, NewDSWindowWithDSWaylandSurface) TEST_F(DSWindowTest, BasicMethods) { - auto win = new DSWindow(); + auto win = std::make_shared(); EXPECT_TRUE(win != nullptr); EXPECT_TRUE(win->show() == true); @@ -66,13 +66,13 @@ TEST_F(DSWindowTest, BasicMethods) EXPECT_TRUE(win->raise() == true); EXPECT_TRUE(win->lower() == true); + EXPECT_TRUE(win->hasFocus() == false); EXPECT_TRUE(win->setFocus() == true); - EXPECT_TRUE(win->hasFocus() == true); } TEST_F(DSWindowTest, SizeTest) { - auto win = new DSWindow(); + auto win = std::make_shared(); EXPECT_TRUE(win != nullptr); stSize size = win->getSize(); @@ -96,7 +96,7 @@ TEST_F(DSWindowTest, SizeTest) TEST_F(DSWindowTest, PositionTest) { - auto win = new DSWindow(); + auto win = std::make_shared(); EXPECT_TRUE(win != nullptr); stPosition pos = win->getPosition(); @@ -111,15 +111,29 @@ TEST_F(DSWindowTest, PositionTest) TEST_F(DSWindowTest, WindowShellTest) { - auto win = new DSWindow(); + auto win = std::make_shared(); EXPECT_TRUE(win != nullptr); - auto winShell = new DSWindowShell(win); + auto winShell = std::make_shared(win.get()); EXPECT_TRUE(winShell != nullptr); - EXPECT_TRUE(win->setWindowShell(winShell) == true); + EXPECT_TRUE(win->setWindowShell(winShell.get()) == true); DSWindowShell *getWinShell = nullptr; getWinShell = win->getWindowShell(); - EXPECT_TRUE(winShell == getWinShell); + EXPECT_TRUE(winShell.get() == getWinShell); } + +TEST_F(DSWindowTest, TitleTest) +{ + auto win = std::make_shared(); + EXPECT_TRUE(win != nullptr); + + bool ret = false; + ret = win->setTitle("test title"); + EXPECT_TRUE(ret == true); + + std::string title = win->getTitle(); + EXPECT_TRUE(title.compare("test title") == 0); +} + -- 2.7.4