Rename file names
[apps/agl-service-windowmanager.git] / src / wm_layer.hpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef WM_LAYERS_H
18 #define WM_LAYERS_H
19
20 #include <string>
21
22 #include "../include/json.hpp"
23 #include "layout.hpp"
24 #include "result.hpp"
25 #include "wayland_ivi_wm.hpp"
26
27 namespace wm
28 {
29
30 struct layer
31 {
32     using json = nlohmann::json;
33
34     // A more or less descriptive name?
35     std::string name = "";
36     // The actual layer ID
37     int layer_id = -1;
38     // The rectangular region surfaces are allowed to draw on
39     // this layer.
40     compositor::rect rect;
41     // Specify a role prefix for surfaces that should be
42     // put on this layer.
43     std::string role;
44
45     mutable struct LayoutState state;
46
47     explicit layer(nlohmann::json const &j);
48
49     json to_json() const;
50 };
51
52 struct layer_map
53 {
54     using json = nlohmann::json;
55
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>;
60
61     storage_type mapping; // map surface_id to layer
62     layers_type layers;   // the actual layer IDs we have
63     int main_surface;
64     std::string main_surface_name;
65     role_to_layer_map roles;
66     addsurf_layer_map surfaces; // additional surfaces on layers
67
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)
71     {
72         int layer_id = *this->get_layer_id(surface_id);
73         auto i = this->mapping.find(layer_id);
74         return i == this->mapping.end()
75                    ? nullopt
76                    : optional<struct LayoutState *>(&i->second.state);
77     }
78     optional<struct layer> get_layer(int layer_id)
79     {
80         auto i = this->mapping.find(layer_id);
81         return i == this->mapping.end() ? nullopt
82                                         : optional<struct layer>(i->second);
83     }
84
85     layers_type::size_type get_layers_count() const
86     {
87         return this->layers.size();
88     }
89
90     void add_surface(int surface_id, int layer_id)
91     {
92         this->surfaces[surface_id] = layer_id;
93     }
94
95     void remove_surface(int surface_id)
96     {
97         this->surfaces.erase(surface_id);
98     }
99
100     json to_json() const;
101     void setupArea(double scaling);
102     compositor::rect getAreaSize(const std::string &area);
103     int loadAreaDb();
104
105   private:
106     std::unordered_map<std::string, compositor::rect> area2size;
107
108     static const char *kDefaultAreaDb;
109 };
110
111 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
112
113 static const nlohmann::json default_layers_json = {
114    {"main_surface", {
115       {"surface_role", "HomeScreen"}
116    }},
117    {"mappings", {
118       {
119          {"role", "^HomeScreen$"},
120          {"name", "HomeScreen"},
121          {"layer_id", 1000},
122          {"area", {
123             {"type", "full"}
124          }}
125       },
126       {
127          {"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"},
128          {"name", "apps"},
129          {"layer_id", 1001},
130          {"area", {
131             {"type", "rect"},
132             {"rect", {
133                {"x", 0},
134                {"y", 218},
135                {"width", -1},
136                {"height", -433}
137             }}
138          }}
139       },
140       {
141          {"role", "^OnScreen.*"},
142          {"name", "popups"},
143          {"layer_id", 9999},
144          {"area", {
145             {"type", "rect"},
146             {"rect", {
147                {"x", 0},
148                {"y", 760},
149                {"width", -1},
150                {"height", 400}
151             }}
152          }}
153       }
154    }}
155 };
156 } // namespace wm
157
158 #endif // WM_LAYERS_H