diff options
author | 2018-11-22 11:03:46 +0900 | |
---|---|---|
committer | 2018-11-22 11:03:46 +0900 | |
commit | aa4854b6b73e3d033f14671c0c2949e771184c4b (patch) | |
tree | 83c939c0fdd7176f410c86e3f5fe03ccc2427bed | |
parent | 0d13409db30964eaec8747b7eaf929f193672a0c (diff) |
Add new feature : changeAreaSize
Add new feature : changeAreaSize
This api is supposed to be used mainly homesceen/settings.
Application can change area setting of window manager.
The typical use case is that
the user can change application layout.
upper : split.main -> split.sub
lower : split.sub -> split.main
Change-Id: I06f8823bcc9fd151a1d3f6784b9905a811b6a05a
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r-- | src/libwindowmanager.cpp | 34 | ||||
-rw-r--r-- | src/libwindowmanager.h | 19 |
2 files changed, 51 insertions, 2 deletions
diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp index e03f638..db59dab 100644 --- a/src/libwindowmanager.cpp +++ b/src/libwindowmanager.cpp @@ -35,6 +35,7 @@ extern "C" { using std::string; using std::vector; +using std::unordered_map; namespace { /* Key for json obejct */ @@ -64,6 +65,7 @@ class LibWindowmanager::Impl { int deactivateWindow(json_object *object); int endDraw(json_object *object); int setRenderOrder(json_object* object); + int changeAreaSize(json_object* object); int getDisplayInfo(json_object *object); int getAreaInfo(json_object *in_obj, json_object *out_obj); @@ -451,6 +453,17 @@ int LibWindowmanager::Impl::setRenderOrder(json_object *object) { }); } +int LibWindowmanager::Impl::changeAreaSize(json_object* object) { + TRACE(); + return this->api_call(__func__, object, [](bool ok, json_object *j) { + if (!ok) { + HMI_ERROR("libwm", "API Call changeAreaSize() failed: %s", + j != nullptr ? json_object_to_json_string_ext(j, JSON_C_TO_STRING_PRETTY) + : "no-info"); + } + }); +} + int LibWindowmanager::Impl::getDisplayInfo(json_object *object) { TRACE(); HMI_DEBUG("libwm", "called"); @@ -1116,6 +1129,27 @@ int LibWindowmanager::setRenderOrder(const vector<string>& render_order) { return this->d->setRenderOrder(object); } +int LibWindowmanager::changeAreaSize(const ChangeAreaReq &req) { + json_object* object = json_object_new_object(); + json_object_object_add(object, "save", json_object_new_boolean(req.getSave())); + json_object *array = json_object_new_array(); + unordered_map<string, Rect> _req_area_size = req.getReq(); + + for(const auto& i: _req_area_size) { + json_object *elem = json_object_new_object(); + json_object_object_add(elem, "name", json_object_new_string(i.first.c_str())); + json_object *rect = json_object_new_object(); + json_object_object_add(rect, "x", json_object_new_int(i.second.left())); + json_object_object_add(rect, "y", json_object_new_int(i.second.top())); + json_object_object_add(rect, "w", json_object_new_int(i.second.width())); + json_object_object_add(rect, "h", json_object_new_int(i.second.height())); + json_object_object_add(elem, "rect", rect); + json_object_array_add(array, elem); + } + json_object_object_add(object, "areas", array); + return this->d->changeAreaSize(object); +} + void LibWindowmanager::set_event_handler(enum EventType et, handler_fun f) { return this->d->set_event_handler(et, std::move(f)); } diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h index d51b89a..df02c41 100644 --- a/src/libwindowmanager.h +++ b/src/libwindowmanager.h @@ -20,6 +20,7 @@ #include <functional> #include <vector> #include <string> +#include <unordered_map> #include <json-c/json.h> class Rect { @@ -43,8 +44,7 @@ class Rect { unsigned _h; }; -struct Screen -{ +struct Screen { unsigned long width_dp; unsigned long height_dp; unsigned long width_mm; @@ -70,6 +70,20 @@ class WMHandler { screen_updated_handler on_screen_updated; }; +class ChangeAreaReq { + public: + ChangeAreaReq() : _save(false) {} + ~ChangeAreaReq() = default; + void setAreaReq(const std::unordered_map<std::string, Rect> &area_req) { this->_area_req = area_req; } + void addAreaReq(const std::string& area_name, const Rect& area_size) { this->_area_req[area_name] = area_size; } + void setSaveReq(bool save) { this->_save = save; } + bool getSave() const { return this->_save; } + const std::unordered_map<std::string, Rect>& getReq() const { return this->_area_req; } + private: + std::unordered_map<std::string, Rect> _area_req; + bool _save; +}; + class LibWindowmanager { public: LibWindowmanager(); @@ -125,6 +139,7 @@ public: int endDraw(const char* role); int setRenderOrder(const std::vector<std::string>& render_order); struct Screen getScreenInfo(); + int changeAreaSize(const ChangeAreaReq& req); int getAreaInfo(const char* role, Rect *out_rect); void setEventHandler(const WMHandler& wmh); |