2 * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef TMCAGLWM_LAYERS_H
18 #define TMCAGLWM_LAYERS_H
25 #include "wayland.hpp"
30 using json = nlohmann::json;
32 // Min and max surface ID mapped to this layer
35 // A more or less descriptive name?
36 std::string name = "";
37 // The actual layer ID
39 // The rectangular region surfaces are allowed to draw on
40 // this layer, note however, width and hieght of the rect
41 // can be negative, in which case they specify that
42 // the actual value is computed using MAX + 1 - w
43 // That is; allow us to specify dimensions dependent on
44 // e.g. screen dimension, w/o knowing the actual screen size.
46 // Specify a role prefix for surfaces that should be
49 // XXX perhaps a zorder is needed here?
51 explicit layer(nlohmann::json const &j);
53 bool operator<(struct layer const &rhs) const {
54 return this->id_max < rhs.id_max;
61 using json = nlohmann::json;
63 typedef std::set<struct layer> storage_type;
64 typedef std::vector<unsigned int> layers_type;
65 typedef std::vector<std::pair<std::string, int>> role_to_layer_map;
66 typedef std::map<unsigned, unsigned> addsurf_layer_map;
68 // XXX: we also will need a layer_id to layer map, perhaps
69 // make this the primary map, and the surface_id->layer a
72 storage_type mapping; // map surface_id to layer
73 layers_type layers; // the actual layer IDs we have
75 std::string main_surface_name;
76 role_to_layer_map roles;
77 addsurf_layer_map surfaces; // additional surfaces on layers
79 optional<int> get_layer_id(int surface_id);
80 optional<int> get_layer_id(std::string const &role);
81 optional<struct layer> get_layer(int layer_id) {
82 auto i = std::find_if(
83 std::cbegin(this->mapping), std::cend(this->mapping),
84 [layer_id](struct layer const &l) { return layer_id == l.layer_id; });
85 return i == this->mapping.end() ? nullopt : optional<struct layer>(*i);
88 optional<genivi::rect> get_layer_rect(int surface_id);
89 layers_type::size_type get_layers_count() const {
90 return this->layers.size();
93 void add_surface(unsigned surface_id, unsigned layer_id) {
94 this->surfaces[surface_id] = layer_id;
100 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
104 #endif // TMCAGLWM_LAYERS_H