summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libwindowmanager.cpp102
-rw-r--r--src/libwindowmanager.h23
2 files changed, 123 insertions, 2 deletions
diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp
index 515fea1..3aefdfc 100644
--- a/src/libwindowmanager.cpp
+++ b/src/libwindowmanager.cpp
@@ -33,6 +33,10 @@ extern "C" {
#define UNUSED(x) (void)(x)
+using std::string;
+using std::vector;
+using std::unordered_map;
+
namespace {
/* Key for json obejct */
static const char g_kKeyDrawingName[] = "drawing_name";
@@ -59,6 +63,8 @@ class LibWindowmanager::Impl {
int activateWindow(json_object *object);
int deactivateWindow(json_object *object);
int endDraw(json_object *object);
+ int getAreaList(ChangeAreaReq* req);
+ int changeAreaSize(json_object* object);
int getDisplayInfo(json_object *object);
int getAreaInfo(json_object *in_obj, json_object *out_obj);
@@ -376,6 +382,75 @@ int LibWindowmanager::Impl::endDraw(json_object *object) {
});
}
+int LibWindowmanager::Impl::getAreaList(ChangeAreaReq* req) {
+ TRACE();
+ int rc = -1;
+ /* send the request */
+ int rc2 =
+ this->api_call("getAreaList", nullptr,
+ [req, &rc](bool ok, json_object *j) {
+ if (ok) {
+ json_object *val, *jarea;
+ if (json_object_object_get_ex(j, g_kKeyResponse, &val)) {
+ HMI_DEBUG("libwm", "responce:%s", json_object_get_string(val));
+ if (json_object_object_get_ex(val, "areas", &jarea)) {
+ int size = json_object_array_length(jarea);
+ for(int i = 0; i < size; i++)
+ {
+ json_object* elem = json_object_array_get_idx(jarea, i);
+ Rect rect;
+ json_object *_val, *jrect;
+ std::string name;
+ json_object_object_get_ex(elem, "name", &_val);
+ name = json_object_get_string(_val);
+ if(json_object_object_get_ex(elem, "rect", &jrect)) {
+ if(json_object_object_get_ex(jrect, "x", &_val))
+ rect.set_left(json_object_get_int(_val));
+ if(json_object_object_get_ex(jrect, "y", &_val))
+ rect.set_top(json_object_get_int(_val));
+ if(json_object_object_get_ex(jrect, "w", &_val))
+ rect.set_width(json_object_get_int(_val));
+ if(json_object_object_get_ex(jrect, "h", &_val))
+ rect.set_height(json_object_get_int(_val));
+ }
+ req->addAreaList(name, rect);
+ }
+ rc = 0;
+ }
+ }
+ else {
+ HMI_ERROR("libwm", "Not found key \"response\"");
+ rc = -EINVAL;
+ return;
+ }
+ } else {
+ HMI_ERROR("libwm", "Windowmanager-service is not initialized: %s",
+ j != nullptr ? json_object_to_json_string_ext(
+ j, JSON_C_TO_STRING_PRETTY)
+ : "no-info");
+ rc = -EPERM;
+ }
+ });
+
+ if (0 > rc2) {
+ HMI_ERROR("libwm", "api_call() failed");
+ rc = rc2;
+ }
+
+ return rc;
+}
+
+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");
@@ -630,6 +705,7 @@ int LibWindowmanager::Impl::api_call(
int rc = 0;
if ((0 == strcmp("RequestSurface", verb)) ||
(0 == strcmp("GetDisplayInfo", verb)) ||
+ (0 == strcmp("getAreaList", verb)) ||
(0 == strcmp("GetAreaInfo", verb))) {
// We need to wrap the actual onReply call once in order to
// *look* like a normal functions pointer (std::functions<>
@@ -1020,6 +1096,32 @@ int LibWindowmanager::getAreaInfo(const char *label, json_object *out_obj) {
return this->d->getAreaInfo(object, out_obj);
}
+int LibWindowmanager::getAreaList(ChangeAreaReq* req)
+{
+ return this->d->getAreaList(req);
+}
+
+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 cc65136..c9da4ca 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,23 @@ class WMHandler {
screen_updated_handler on_screen_updated;
};
+class ChangeAreaReq {
+ public:
+ ChangeAreaReq() {}
+ ~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; }
+ void addAreaList(const std::string& area_name, const Rect& area_size){ this->_area_list[area_name] = area_size; }
+ const std::unordered_map<std::string, Rect>& getReq() const { return this->_area_req; }
+ const std::unordered_map<std::string, Rect>& getList() const { return this->_area_list; }
+ private:
+ std::unordered_map<std::string, Rect> _area_req;
+ std::unordered_map<std::string, Rect> _area_list;
+ bool _save = false;
+};
+
class LibWindowmanager {
public:
LibWindowmanager();
@@ -122,6 +139,8 @@ public:
int deactivateWindow(const char* role);
int endDraw(const char* role);
struct Screen getScreenInfo();
+ int getAreaList(ChangeAreaReq* req);
+ int changeAreaSize(const ChangeAreaReq& req);
int getAreaInfo(const char* role, Rect *out_rect);
void setEventHandler(const WMHandler& wmh);