layers: provide a layers-only vector
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Fri, 28 Jul 2017 12:40:27 +0000 (14:40 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/app.cpp
src/layers.cpp
src/layers.hpp

index 84ebfba..96394c3 100644 (file)
@@ -192,19 +192,16 @@ int App::init_layout() {
    // Quick and dirty setup of layers
    // XXX: This likely needs to be sorted by order (note, we don't (yet?)
    // do any zorder arrangement).
-   std::vector<unsigned> ls;
-   ls.reserve(this->surface2layer.mapping.size());
    for (auto const &i: this->surface2layer.mapping) {
       c->layer_create(i.layer_id, o->width, o->height);
       auto &l = layers[i.layer_id];
       l->set_destination_rectangle(0, 0, o->width, o->height);
       l->set_visibility(1);
       logdebug("Setting up layer %s (%d) for surfaces %d-%d", i.name.c_str(), i.layer_id, i.id_min, i.id_max);
-      ls.push_back(unsigned(i.layer_id));
    }
 
-   // Add layers to screen
-   s->set_render_order(ls);
+   // Add layers to screen (XXX: are they sorted correctly?)
+   s->set_render_order(this->surface2layer.layers);
 
    c->commit_changes();
 
index f475556..0d01080 100644 (file)
@@ -30,10 +30,16 @@ struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
    try {
       surface_id_to_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()),
-         [](nlohmann::json const &j) { return surface_id_to_layer(j); });
+         [&stl](nlohmann::json const &j) {
+            auto k = surface_id_to_layer(j);
+            stl.layers.push_back(unsigned(k.layer_id));
+            return k;
+         });
+      // XXX need to sort layers?
       for (auto i : stl.mapping) {
          if (i.name.empty()) {
             return Err<struct surface_id_to_layer_map>(
index 9dd2036..ec24a74 100644 (file)
@@ -30,10 +30,15 @@ struct surface_id_to_layer {
 // to contain its mapping type and the _single_ useful method.
 struct surface_id_to_layer_map {
    typedef std::set<struct surface_id_to_layer> surface_to_layer_map_type;
+   typedef std::vector<unsigned int> layers_type;
 
    surface_to_layer_map_type mapping;
+   layers_type layers;
 
    optional<int> get_layer_for_surface(int surface_id);
+   layers_type::size_type get_layers_count() const {
+      return this->layers.size();
+   }
 };
 
 struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(