2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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
22 #include "../include/json.hpp"
25 #include "wayland_ivi_wm.hpp"
33 std::string main_match;
34 std::string sub_match;
39 using json = nlohmann::json;
41 // A more or less descriptive name?
42 std::string name = "";
43 // The actual layer ID
45 // The rectangular region surfaces are allowed to draw on
46 // this layer, note however, width and hieght of the rect
47 // can be negative, in which case they specify that
48 // the actual value is computed using MAX + 1 - w
49 // That is; allow us to specify dimensions dependent on
50 // e.g. screen dimension, w/o knowing the actual screen size.
51 compositor::rect rect;
52 // Specify a role prefix for surfaces that should be
55 // TODO: perhaps a zorder is needed here?
56 std::vector<struct split_layout> layouts;
58 mutable struct LayoutState state;
60 // Flag of normal layout only
61 bool is_normal_layout_only;
63 explicit layer(nlohmann::json const &j);
69 * WMLayer is the logical container of application/system application(such like HomeScreen)
70 * This is handled by Window Manager to classify the application.
81 explicit WMLayer(const std::string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end);
84 const std::string& layerName();
85 MANAGEMENT_TYPE layerType();
86 void appendRole(const std::string& name);
87 void appendArea(const std::string& area);
89 /* unsigned getNewID(const std::string& role);
90 void remove(unsigned ivi_layer_id);
92 bool attach(unsigned ivi_layer_id, const std::string& area);
93 void stack(unsigned ivi_layer_id, const std::string& area);
94 bool updateRenderOrder(const std::vector<unsigned> list); */
97 std::string _name = ""; // Layer name
98 MANAGEMENT_TYPE _type;
99 std::vector<std::string> _roles;
102 // current holding apps. This dynamically changes.
103 std::vector<unsigned> _ivi_layer_id_list;
104 // std::map<std::string, unsigned> _render_order;
110 void setRenderOrder(const std::vector<unsigned> layer_render_order);
111 std::vector<unsigned> getAllRenderOrder();
112 std::vector<std::shared_ptr<WMLayer>>& getAllLayers();
113 std::vector<unsigned> getRenderOrder(const std::string& layer_name);
118 using json = nlohmann::json;
120 using storage_type = std::map<int, struct layer>;
121 using layers_type = std::vector<uint32_t>;
122 using role_to_layer_map = std::vector<std::pair<std::string, int>>;
123 using addsurf_layer_map = std::map<int, int>;
125 storage_type mapping; // map surface_id to layer
126 layers_type layers; // the actual layer IDs we have
128 std::string main_surface_name;
129 role_to_layer_map roles;
130 addsurf_layer_map surfaces; // additional surfaces on layers
132 optional<int> get_layer_id(int surface_id);
133 optional<int> get_layer_id(std::string const &role);
134 optional<struct LayoutState *> get_layout_state(int surface_id)
136 int layer_id = *this->get_layer_id(surface_id);
137 auto i = this->mapping.find(layer_id);
138 return i == this->mapping.end()
140 : optional<struct LayoutState *>(&i->second.state);
142 optional<struct layer> get_layer(int layer_id)
144 auto i = this->mapping.find(layer_id);
145 return i == this->mapping.end() ? nullopt
146 : optional<struct layer>(i->second);
149 layers_type::size_type get_layers_count() const
151 return this->layers.size();
154 void add_surface(int surface_id, int layer_id)
156 this->surfaces[surface_id] = layer_id;
159 void remove_surface(int surface_id)
161 this->surfaces.erase(surface_id);
164 json to_json() const;
165 void setupArea(double scaling);
166 compositor::rect getAreaSize(const std::string &area);
170 std::unordered_map<std::string, compositor::rect> area2size;
172 static const char *kDefaultAreaDb;
175 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
177 static const nlohmann::json default_layers_json = {
179 {"surface_role", "HomeScreen"}
183 {"role", "^HomeScreen$"},
184 {"name", "HomeScreen"},
191 {"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"},
205 {"role", "^OnScreen.*"},
222 #endif // TMCAGLWM_LAYERS_H