summaryrefslogtreecommitdiffstats
path: root/src/layers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/layers.cpp')
-rw-r--r--src/layers.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/layers.cpp b/src/layers.cpp
index 5e7256e..013c16a 100644
--- a/src/layers.cpp
+++ b/src/layers.cpp
@@ -13,7 +13,7 @@ namespace wm {
using json = nlohmann::json;
surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) {
- // DB(j);
+ DB(j);
if (j["type"] == "range") {
this->id_min = get<int>(j["first_surface_id"]);
this->id_max = get<int>(j["last_surface_id"]);
@@ -22,6 +22,16 @@ surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) {
}
this->name = j["name"].get<std::string>();
this->layer_id = get<int>(j["layer_id"]);
+ this->rect = genivi::rect{-1, -1, 0, 0};
+ if (j["area"]["type"] == "rect") {
+ auto jr = j["area"]["rect"];
+ this->rect = genivi::rect{
+ get<int32_t>(jr["width"]),
+ get<int32_t>(jr["height"]),
+ get<int32_t>(jr["x"]),
+ get<int32_t>(jr["y"]),
+ };
+ }
}
struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
@@ -87,19 +97,31 @@ inline bool
return a.id_max < b;
}
-optional<int> surface_id_to_layer_map::get_layer_for_surface(int surface_id) {
- auto i = std::lower_bound(std::cbegin(this->mapping),
- std::cend(this->mapping), surface_id);
+namespace {
+optional<surface_id_to_layer> get_surface_id_to_layer(struct surface_id_to_layer_map const *s2l, int surface_id) {
+ auto i = std::lower_bound(std::cbegin(s2l->mapping),
+ std::cend(s2l->mapping), surface_id);
- if (i != this->mapping.end()) {
+ if (i != s2l->mapping.end()) {
// std::less only checks for surface_id_to_layer::id_max, so check
// that we are actually inside of an interval here.
if (i->id_min <= surface_id) {
- return optional<int>(i->layer_id);
+ return optional<surface_id_to_layer>(*i);
}
}
return nullopt;
}
+}
+
+optional<int> surface_id_to_layer_map::get_layer_for_surface(int surface_id) {
+ auto e = get_surface_id_to_layer(this, surface_id);
+ return e ? optional<int>(e->layer_id) : nullopt;
+}
+
+optional<genivi::rect> surface_id_to_layer_map::get_rect_for_surface(int surface_id) {
+ auto e = get_surface_id_to_layer(this, surface_id);
+ return e ? optional<genivi::rect>(e->rect) : nullopt;
+}
} // namespace wm