From 11ed192767f50ad5cd93f5c780a38c7a44238531 Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Sun, 24 Jun 2018 15:25:26 +0900 Subject: Format source codes Change-Id: I73ee650e65028493895144944f729005f927d872 Signed-off-by: Kazumasa Mitsunari --- src/json_helper.cpp | 152 +++++++++++++++++++++++++++------------------------- src/layers.cpp | 140 +++++++++++++++++++++++------------------------ src/layers.hpp | 44 ++++++++++++++- 3 files changed, 192 insertions(+), 144 deletions(-) diff --git a/src/json_helper.cpp b/src/json_helper.cpp index 193a187..2e49778 100644 --- a/src/json_helper.cpp +++ b/src/json_helper.cpp @@ -18,85 +18,93 @@ #include -json_object *to_json(compositor::surface_properties const &s) { - // auto j = json::object({ - auto j = json_object_new_object(); - - // {"id", s.id}, - json_object_object_add(j, "id", json_object_new_int(s.id)); - - // {"size", {{"width", s.size.w}, {"height", s.size.h}}}, - auto jsize = json_object_new_object(); - json_object_object_add(jsize, "width", json_object_new_int(s.size.w)); - json_object_object_add(jsize, "height", json_object_new_int(s.size.h)); - json_object_object_add(j, "size", jsize); - - // {"dst", - // {{"width", s.dst_rect.w}, - // {"height", s.dst_rect.h}, - // {"x", s.dst_rect.x}, - // {"y", s.dst_rect.y}}}, - auto jdst = json_object_new_object(); - json_object_object_add(jdst, "width", json_object_new_int(s.dst_rect.w)); - json_object_object_add(jdst, "height", json_object_new_int(s.dst_rect.h)); - json_object_object_add(jdst, "x", json_object_new_int(s.dst_rect.x)); - json_object_object_add(jdst, "y", json_object_new_int(s.dst_rect.y)); - json_object_object_add(j, "dst", jdst); - - // {"src", - // {{"width", s.src_rect.w}, - // {"height", s.src_rect.h}, - // {"x", s.src_rect.x}, - // {"y", s.src_rect.y}}}, - auto jsrc = json_object_new_object(); - json_object_object_add(jsrc, "width", json_object_new_int(s.src_rect.w)); - json_object_object_add(jsrc, "height", json_object_new_int(s.src_rect.h)); - json_object_object_add(jsrc, "x", json_object_new_int(s.src_rect.x)); - json_object_object_add(jsrc, "y", json_object_new_int(s.src_rect.y)); - json_object_object_add(j, "src", jsrc); - - // {"visibility", s.visibility}, - json_object_object_add( - j, "visibility", - json_object_new_boolean(static_cast(s.visibility == 1))); - - // {"opacity", s.opacity}, - json_object_object_add(j, "opacity", json_object_new_double(s.opacity)); - - // {"orientation", s.orientation}, - json_object_object_add(j, "orientation", json_object_new_int(s.orientation)); - - // }); - return j; +json_object *to_json(compositor::surface_properties const &s) +{ + // auto j = json::object({ + auto j = json_object_new_object(); + + // {"id", s.id}, + json_object_object_add(j, "id", json_object_new_int(s.id)); + + // {"size", {{"width", s.size.w}, {"height", s.size.h}}}, + auto jsize = json_object_new_object(); + json_object_object_add(jsize, "width", json_object_new_int(s.size.w)); + json_object_object_add(jsize, "height", json_object_new_int(s.size.h)); + json_object_object_add(j, "size", jsize); + + // {"dst", + // {{"width", s.dst_rect.w}, + // {"height", s.dst_rect.h}, + // {"x", s.dst_rect.x}, + // {"y", s.dst_rect.y}}}, + auto jdst = json_object_new_object(); + json_object_object_add(jdst, "width", json_object_new_int(s.dst_rect.w)); + json_object_object_add(jdst, "height", json_object_new_int(s.dst_rect.h)); + json_object_object_add(jdst, "x", json_object_new_int(s.dst_rect.x)); + json_object_object_add(jdst, "y", json_object_new_int(s.dst_rect.y)); + json_object_object_add(j, "dst", jdst); + + // {"src", + // {{"width", s.src_rect.w}, + // {"height", s.src_rect.h}, + // {"x", s.src_rect.x}, + // {"y", s.src_rect.y}}}, + auto jsrc = json_object_new_object(); + json_object_object_add(jsrc, "width", json_object_new_int(s.src_rect.w)); + json_object_object_add(jsrc, "height", json_object_new_int(s.src_rect.h)); + json_object_object_add(jsrc, "x", json_object_new_int(s.src_rect.x)); + json_object_object_add(jsrc, "y", json_object_new_int(s.src_rect.y)); + json_object_object_add(j, "src", jsrc); + + // {"visibility", s.visibility}, + json_object_object_add( + j, "visibility", + json_object_new_boolean(static_cast(s.visibility == 1))); + + // {"opacity", s.opacity}, + json_object_object_add(j, "opacity", json_object_new_double(s.opacity)); + + // {"orientation", s.orientation}, + json_object_object_add(j, "orientation", json_object_new_int(s.orientation)); + + // }); + return j; } -json_object *to_json(compositor::screen const *s) { - auto o = json_object_new_object(); - json_object_object_add(o, "id", json_object_new_int(s->id)); - return o; +json_object *to_json(compositor::screen const *s) +{ + auto o = json_object_new_object(); + json_object_object_add(o, "id", json_object_new_int(s->id)); + return o; } template -json_object *to_json_(T const &s) { - auto a = json_object_new_array(); - - if (!s.empty()) { - for (auto const &i : s) { - json_object_array_add(a, to_json(i.second)); - } - } - - return a; +json_object *to_json_(T const &s) +{ + auto a = json_object_new_array(); + + if (!s.empty()) + { + for (auto const &i : s) + { + json_object_array_add(a, to_json(i.second)); + } + } + + return a; } -json_object *to_json(compositor::controller::props_map const &s) { - return to_json_(s); +json_object *to_json(compositor::controller::props_map const &s) +{ + return to_json_(s); } -json_object *to_json(std::vector const &v) { - auto a = json_object_new_array(); - for (const auto i : v) { - json_object_array_add(a, json_object_new_int(i)); - } - return a; +json_object *to_json(std::vector const &v) +{ + auto a = json_object_new_array(); + for (const auto i : v) + { + json_object_array_add(a, json_object_new_int(i)); + } + return a; } diff --git a/src/layers.cpp b/src/layers.cpp index 6c6be55..b6244f8 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -26,80 +26,80 @@ using json = nlohmann::json; layer::layer(nlohmann::json const &j) { - this->role = j["role"]; - this->name = j["name"]; - this->layer_id = j["layer_id"]; - this->rect = compositor::full_rect; - if (j["area"]["type"] == "rect") - { - auto jr = j["area"]["rect"]; - this->rect = compositor::rect{ - jr["width"], - jr["height"], - jr["x"], - jr["y"], - }; - } - - // Init flag of normal layout only - this->is_normal_layout_only = true; - - auto split_layouts = j.find("split_layouts"); - if (split_layouts != j.end()) - { - - // Clear flag of normal layout only - this->is_normal_layout_only = false; - - auto &sls = j["split_layouts"]; - // this->layouts.reserve(sls.size()); - std::transform(std::cbegin(sls), std::cend(sls), - std::back_inserter(this->layouts), [this](json const &sl) { - struct split_layout l - { - sl["name"], sl["main_match"], sl["sub_match"] - }; - HMI_DEBUG("wm", - "layer %d add split_layout \"%s\" (main: \"%s\") (sub: " - "\"%s\")", - this->layer_id, - l.name.c_str(), l.main_match.c_str(), - l.sub_match.c_str()); - return l; - }); - } - HMI_DEBUG("wm", "layer_id:%d is_normal_layout_only:%d\n", - this->layer_id, this->is_normal_layout_only); + this->role = j["role"]; + this->name = j["name"]; + this->layer_id = j["layer_id"]; + this->rect = compositor::full_rect; + if (j["area"]["type"] == "rect") + { + auto jr = j["area"]["rect"]; + this->rect = compositor::rect{ + jr["width"], + jr["height"], + jr["x"], + jr["y"], + }; + } + + // Init flag of normal layout only + this->is_normal_layout_only = true; + + auto split_layouts = j.find("split_layouts"); + if (split_layouts != j.end()) + { + + // Clear flag of normal layout only + this->is_normal_layout_only = false; + + auto &sls = j["split_layouts"]; + // this->layouts.reserve(sls.size()); + std::transform(std::cbegin(sls), std::cend(sls), + std::back_inserter(this->layouts), [this](json const &sl) { + struct split_layout l + { + sl["name"], sl["main_match"], sl["sub_match"] + }; + HMI_DEBUG("wm", + "layer %d add split_layout \"%s\" (main: \"%s\") (sub: " + "\"%s\")", + this->layer_id, + l.name.c_str(), l.main_match.c_str(), + l.sub_match.c_str()); + return l; + }); + } + HMI_DEBUG("wm", "layer_id:%d is_normal_layout_only:%d\n", + this->layer_id, this->is_normal_layout_only); } struct result to_layer_map(nlohmann::json const &j) { - try - { - layer_map stl{}; - auto m = j["mappings"]; - - std::transform(std::cbegin(m), std::cend(m), - std::inserter(stl.mapping, stl.mapping.end()), - [](nlohmann::json const &j) { - return std::pair( - j.value("layer_id", -1), layer(j)); - }); - - // TODO: add sanity checks here? - // * check for double IDs - // * check for double names/roles - - stl.layers.reserve(m.size()); - std::transform(std::cbegin(stl.mapping), std::cend(stl.mapping), - std::back_inserter(stl.layers), - [&stl](std::pair const &k) { - stl.roles.emplace_back( - std::make_pair(k.second.role, k.second.layer_id)); - return unsigned(k.second.layer_id); - }); - - std::sort(stl.layers.begin(), stl.layers.end()); + try + { + layer_map stl{}; + auto m = j["mappings"]; + + std::transform(std::cbegin(m), std::cend(m), + std::inserter(stl.mapping, stl.mapping.end()), + [](nlohmann::json const &j) { + return std::pair( + j.value("layer_id", -1), layer(j)); + }); + + // TODO: add sanity checks here? + // * check for double IDs + // * check for double names/roles + + stl.layers.reserve(m.size()); + std::transform(std::cbegin(stl.mapping), std::cend(stl.mapping), + std::back_inserter(stl.layers), + [&stl](std::pair const &k) { + stl.roles.emplace_back( + std::make_pair(k.second.role, k.second.layer_id)); + return unsigned(k.second.layer_id); + }); + + std::sort(stl.layers.begin(), stl.layers.end()); for (auto i : stl.mapping) { diff --git a/src/layers.hpp b/src/layers.hpp index 5a18fad..a8ab2cc 100644 --- a/src/layers.hpp +++ b/src/layers.hpp @@ -124,8 +124,48 @@ struct layer_map struct result to_layer_map(nlohmann::json const &j); static const nlohmann::json default_layers_json = { - {"main_surface", {{"surface_role", "HomeScreen"}}}, - {"mappings", {{{"role", "^HomeScreen$"}, {"name", "HomeScreen"}, {"layer_id", 1000}, {"area", {{"type", "full"}}}}, {{"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"}, {"name", "apps"}, {"layer_id", 1001}, {"area", {{"type", "rect"}, {"rect", {{"x", 0}, {"y", 218}, {"width", -1}, {"height", -433}}}}}}, {{"role", "^OnScreen.*"}, {"name", "popups"}, {"layer_id", 9999}, {"area", {{"type", "rect"}, {"rect", {{"x", 0}, {"y", 760}, {"width", -1}, {"height", 400}}}}}}}}}; + {"main_surface", { + {"surface_role", "HomeScreen"} + }}, + {"mappings", { + { + {"role", "^HomeScreen$"}, + {"name", "HomeScreen"}, + {"layer_id", 1000}, + {"area", { + {"type", "full"} + }} + }, + { + {"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"}, + {"name", "apps"}, + {"layer_id", 1001}, + {"area", { + {"type", "rect"}, + {"rect", { + {"x", 0}, + {"y", 218}, + {"width", -1}, + {"height", -433} + }} + }} + }, + { + {"role", "^OnScreen.*"}, + {"name", "popups"}, + {"layer_id", 9999}, + {"area", { + {"type", "rect"}, + {"rect", { + {"x", 0}, + {"y", 760}, + {"width", -1}, + {"height", 400} + }} + }} + } + }} +}; } // namespace wm #endif // TMCAGLWM_LAYERS_H -- cgit 1.2.3-korg