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"
32 using json = nlohmann::json;
34 // A more or less descriptive name?
35 std::string name = "";
36 // The actual layer ID
38 // The rectangular region surfaces are allowed to draw on
40 compositor::rect rect;
41 // Specify a role prefix for surfaces that should be
45 mutable struct LayoutState state;
47 explicit layer(nlohmann::json const &j);
54 using json = nlohmann::json;
56 using storage_type = std::map<int, struct layer>;
57 using layers_type = std::vector<uint32_t>;
58 using role_to_layer_map = std::vector<std::pair<std::string, int>>;
59 using addsurf_layer_map = std::map<int, int>;
61 storage_type mapping; // map surface_id to layer
62 layers_type layers; // the actual layer IDs we have
64 std::string main_surface_name;
65 role_to_layer_map roles;
66 addsurf_layer_map surfaces; // additional surfaces on layers
68 optional<int> get_layer_id(int surface_id);
69 optional<int> get_layer_id(std::string const &role);
70 optional<struct LayoutState *> get_layout_state(int surface_id)
72 int layer_id = *this->get_layer_id(surface_id);
73 auto i = this->mapping.find(layer_id);
74 return i == this->mapping.end()
76 : optional<struct LayoutState *>(&i->second.state);
78 optional<struct layer> get_layer(int layer_id)
80 auto i = this->mapping.find(layer_id);
81 return i == this->mapping.end() ? nullopt
82 : optional<struct layer>(i->second);
85 layers_type::size_type get_layers_count() const
87 return this->layers.size();
90 void add_surface(int surface_id, int layer_id)
92 this->surfaces[surface_id] = layer_id;
95 void remove_surface(int surface_id)
97 this->surfaces.erase(surface_id);
100 json to_json() const;
101 void setupArea(double scaling);
102 compositor::rect getAreaSize(const std::string &area);
106 std::unordered_map<std::string, compositor::rect> area2size;
108 static const char *kDefaultAreaDb;
111 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
113 static const nlohmann::json default_layers_json = {
115 {"surface_role", "HomeScreen"}
119 {"role", "^HomeScreen$"},
120 {"name", "HomeScreen"},
127 {"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"},
141 {"role", "^OnScreen.*"},
158 #endif // TMCAGLWM_LAYERS_H