summaryrefslogtreecommitdiffstats
path: root/src/layers.cpp
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-17 16:45:56 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-04 16:53:49 +0200
commit6a4504b1fe5e17a09a019edf0377646cc5dd72aa (patch)
treee10f7da1767a327a017028e2d97f3214f68ac88e /src/layers.cpp
parent0c9c1107ad673bc9a4977d57041c936678429a1e (diff)
Implement surface names
* request_surface(name: string) -> id: int. * activate_surface(name: string). * names will be mapped to their respective layers by use of the layers' surface rola match, a regex. * the generated IDs are global and not reused. * allow wp-request to use -p, disable use of pygments even if found. Things missing: * surface removal does not remove already established mappings/names. * Mostly untested. Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src/layers.cpp')
-rw-r--r--src/layers.cpp47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/layers.cpp b/src/layers.cpp
index 8f79451..464e20b 100644
--- a/src/layers.cpp
+++ b/src/layers.cpp
@@ -15,6 +15,7 @@
*/
#include <algorithm>
+#include <regex>
#include "json_helper.hpp"
#include "layers.hpp"
@@ -31,7 +32,8 @@ layer::layer(nlohmann::json const &j) {
} else {
this->id_min = this->id_max = j["surface_id"];
}
- this->name = j["name"].get<std::string>();
+ this->role = j["role"];
+ this->name = j["name"];
this->layer_id = j["layer_id"];
this->rect = genivi::full_rect;
if (j["area"]["type"] == "rect") {
@@ -47,14 +49,25 @@ struct result<struct layer_map> to_layer_map(nlohmann::json const &j) {
try {
layer_map stl{};
auto m = j["mappings"];
- stl.layers.reserve(m.size());
+
std::transform(std::cbegin(m), std::cend(m),
std::inserter(stl.mapping, stl.mapping.end()),
- [&stl](nlohmann::json const &j) {
- auto k = layer(j);
- stl.layers.push_back(unsigned(k.layer_id));
- return k;
+ [](nlohmann::json const &j) {
+ return layer(j);
});
+
+ // XXX: 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](struct layer const &k) {
+ stl.roles.emplace_back(std::make_pair(k.role, k.layer_id));
+ return unsigned(k.layer_id);
+ });
+
// XXX need to sort layers?
for (auto i : stl.mapping) {
if (i.name.empty()) {
@@ -68,6 +81,7 @@ struct result<struct layer_map> to_layer_map(nlohmann::json const &j) {
auto msi = j.find("main_surface");
if (msi != j.end()) {
stl.main_surface = (*msi)["surface_id"];
+ stl.main_surface_name = msi->value("surface_role", "");
}
// Check lookup
@@ -125,7 +139,26 @@ optional<layer> get_surface_id_to_layer(struct layer_map const *s2l,
optional<int> layer_map::get_layer_id(int surface_id) {
auto e = get_surface_id_to_layer(this, surface_id);
- return e ? optional<int>(e->layer_id) : nullopt;
+ if (! e) {
+ auto i = this->surfaces.find(surface_id);
+ if (i != this->surfaces.end()) {
+ return optional<int>(int(i->second));
+ }
+ return nullopt;
+ }
+ return optional<int>(e->layer_id);
+}
+
+optional<int> layer_map::get_layer_id(std::string const &role) {
+ for (auto const &r : this->roles) {
+ auto re = std::regex(r.first);
+ if (std::regex_match(role, re)) {
+ logdebug("role %s matches layer %d", role.c_str(), r.second);
+ return optional<int>(r.second);
+ }
+ }
+ logdebug("role %s does NOT match any layer", role.c_str());
+ return nullopt;
}
optional<genivi::rect> layer_map::get_layer_rect(int surface_id) {