add license text to implementation files
[staging/windowmanager.git] / src / layers.hpp
1 /*
2  * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
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 //
18 // Created by m on 7/27/17.
19 //
20
21 #ifndef TMCAGLWM_LAYERS_H
22 #define TMCAGLWM_LAYERS_H
23
24 #include <json.hpp>
25 #include <set>
26 #include <string>
27
28 #include "result.hpp"
29 #include "wayland.hpp"
30
31 namespace wm {
32
33 struct layer {
34    using json = nlohmann::json;
35
36    // Min and max surface ID mapped to this layer
37    int id_min = -1;
38    int id_max = -1;
39    // A more or less descriptive name?
40    std::string name = "";
41    // The actual layer ID
42    int layer_id = -1;
43    // The rectangular region surfaces are allowed to draw on
44    // this layer, note however, width and hieght of the rect
45    // can be negative, in which case they specify that
46    // the actual value is computed using MAX + 1 - w
47    // That is; allow us to specify dimensions dependent on
48    // e.g. screen dimension, w/o knowing the actual screen size.
49    genivi::rect rect;
50    // XXX perhaps a zorder is needed here?
51
52    explicit layer(nlohmann::json const &j);
53
54    bool operator<(struct layer const &rhs) const {
55       return this->id_max < rhs.id_max;
56    }
57
58    json to_json() const;
59 };
60
61 // Actually, we shouldn't need a struct here ... but let's just keep it at that
62 // for now, to contain its mapping type and the _single_ useful method.
63 struct layer_map {
64    using json = nlohmann::json;
65
66    typedef std::set<struct layer> storage_type;
67    typedef std::vector<unsigned int> layers_type;
68
69    storage_type mapping;
70    layers_type layers;
71
72    optional<int> get_layer_id(int surface_id);
73    optional<genivi::rect> get_layer_rect(int surface_id);
74    layers_type::size_type get_layers_count() const {
75       return this->layers.size();
76    }
77
78    json to_json() const;
79 };
80
81 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
82
83 }  // namespace wm
84
85 #endif  // TMCAGLWM_LAYERS_H