clang-format
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Thu, 17 Aug 2017 15:03:00 +0000 (17:03 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Mon, 4 Sep 2017 14:53:57 +0000 (16:53 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/app.cpp
src/app.hpp
src/layers.cpp
src/layers.hpp

index c38a7f4..fbeb4fd 100644 (file)
 
 #include <json-c/json.h>
 
+#include <algorithm>
 #include <bits/signum.h>
 #include <csignal>
 #include <fstream>
-#include <algorithm>
 #include <json.hpp>
 
 namespace wm {
@@ -129,8 +129,7 @@ App::App(wl::display *d)
      layers(),
      pending(),
      name_mapping(),
-     id_alloc{}
-{
+     id_alloc{} {
    assert(g_app == nullptr);
    g_app = this;
 
@@ -284,7 +283,8 @@ void App::surface_set_layout(uint32_t surface_id) {
    }
 
    uint32_t layer_id = o_layer_id.value();
-   logdebug("surface_set_layout for surface %u on layer %u", surface_id, layer_id);
+   logdebug("surface_set_layout for surface %u on layer %u", surface_id,
+            layer_id);
 
    auto const &layer = this->layers.get_layer(layer_id);
    auto rect = layer.value().rect;
@@ -390,7 +390,7 @@ result<int> App::request_surface(char const *drawing_name) {
    }
 
    auto rname = this->id_alloc[drawing_name];
-   if (! rname) {
+   if (!rname) {
       // name does not exist yet, allocate surface id...
       // XXX: how to allocate surface IDs?
       // * allocate by running a counter for each layer?
@@ -400,10 +400,9 @@ result<int> App::request_surface(char const *drawing_name) {
       auto id = int(this->id_alloc(drawing_name));
       this->layers.add_surface(id, lid.value());
 
-      // XXX: setup the main_surface id if we registered HomeScreen
       // XXX: you should fix this!
       if (!this->layers.main_surface_name.empty() &&
-           this->layers.main_surface_name == drawing_name) {
+          this->layers.main_surface_name == drawing_name) {
          this->layers.main_surface = id;
          this->activate_surface(id);
          logdebug("Set main_surface id to %u", id);
@@ -416,11 +415,12 @@ result<int> App::request_surface(char const *drawing_name) {
    return Err<int>("Surface already present");
 }
 
-char constApp::activate_surface(char const *drawing_name) {
+char const *App::activate_surface(char const *drawing_name) {
    auto osid = this->id_alloc[drawing_name];
 
    if (osid) {
-      logdebug("ativate surface with name %s and id %u", drawing_name, osid.value());
+      logdebug("ativate surface with name %s and id %u", drawing_name,
+               osid.value());
       this->activate_surface(osid.value());
       return nullptr;
    }
@@ -439,7 +439,7 @@ binding_api::result_type binding_api::request_surface(
    char const *drawing_name) {
    auto r = this->app->request_surface(drawing_name);
    if (r.is_err()) {
-      return Err<json_object*>(r.unwrap_err());
+      return Err<json_object *>(r.unwrap_err());
    }
    return Ok(json_object_new_int(r.unwrap()));
 }
index 12d26b4..a35be27 100644 (file)
@@ -71,7 +71,8 @@ struct id_allocator {
 
    optional<std::string> operator[](unsigned id) {
       auto i = this->surfaces.find(id);
-      return i == this->surfaces.end() ? nullopt : optional<std::string>(i->second);
+      return i == this->surfaces.end() ? nullopt
+                                       : optional<std::string>(i->second);
    }
 };
 
index 464e20b..931fd5e 100644 (file)
@@ -39,8 +39,7 @@ layer::layer(nlohmann::json const &j) {
    if (j["area"]["type"] == "rect") {
       auto jr = j["area"]["rect"];
       this->rect = genivi::rect{
-         jr["width"], jr["height"],
-         jr["x"], jr["y"],
+         jr["width"], jr["height"], jr["x"], jr["y"],
       };
    }
 }
@@ -52,21 +51,19 @@ struct result<struct layer_map> to_layer_map(nlohmann::json const &j) {
 
       std::transform(std::cbegin(m), std::cend(m),
                      std::inserter(stl.mapping, stl.mapping.end()),
-                     [](nlohmann::json const &j) {
-                        return layer(j);
-                     });
+                     [](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);
-                     });
+      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) {
@@ -80,8 +77,9 @@ 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", "");
+         stl.main_surface =
+            stl.main_surface_name.empty() ? int((*msi)["surface_id"]) : -1;
       }
 
       // Check lookup
@@ -93,9 +91,8 @@ struct result<struct layer_map> to_layer_map(nlohmann::json const &j) {
          tests.reserve(jtests.size());
          std::transform(std::cbegin(jtests), std::cend(jtests),
                         std::back_inserter(tests), [](json const &j) {
-                           return std::make_pair(
-                              j["surface_id"],
-                              j["expect_layer_id"]);
+                           return std::make_pair(j["surface_id"],
+                                                 j["expect_layer_id"]);
                         });
 
          for (auto sid : tests) {
@@ -139,7 +136,7 @@ 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);
-   if (! e) {
+   if (!e) {
       auto i = this->surfaces.find(surface_id);
       if (i != this->surfaces.end()) {
          return optional<int>(int(i->second));
index ae609fc..a33f24a 100644 (file)
@@ -69,21 +69,19 @@ struct layer_map {
    // make this the primary map, and the surface_id->layer a
    // secondary map.
 
-   storage_type mapping; // map surface_id to layer
-   layers_type layers; // the actual layer IDs we have
+   storage_type mapping;  // map surface_id to layer
+   layers_type layers;    // the actual layer IDs we have
    int main_surface;
    std::string main_surface_name;
    role_to_layer_map roles;
-   addsurf_layer_map surfaces; // additional surfaces on layers
+   addsurf_layer_map surfaces;  // additional surfaces on layers
 
    optional<int> get_layer_id(int surface_id);
    optional<int> get_layer_id(std::string const &role);
    optional<struct layer> get_layer(int layer_id) {
-      auto i = std::find_if(std::cbegin(this->mapping),
-                            std::cend(this->mapping),
-                            [layer_id](struct layer const &l) {
-                               return layer_id == l.layer_id;
-                            });
+      auto i = std::find_if(
+         std::cbegin(this->mapping), std::cend(this->mapping),
+         [layer_id](struct layer const &l) { return layer_id == l.layer_id; });
       return i == this->mapping.end() ? nullopt : optional<struct layer>(*i);
    }