WIP split layouts, reading config, defining data layout.
[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 #ifndef TMCAGLWM_LAYERS_H
18 #define TMCAGLWM_LAYERS_H
19
20 #include <json.hpp>
21 #include <set>
22 #include <string>
23
24 #include "result.hpp"
25 #include "wayland.hpp"
26
27 namespace wm {
28
29 struct split_layout {
30    std::string name;
31    std::string main_match;
32    std::string sub_match;
33    int prio;
34 };
35
36 struct layer {
37    using json = nlohmann::json;
38
39    // Min and max surface ID mapped to this layer
40    int id_min = -1;
41    int id_max = -1;
42    // A more or less descriptive name?
43    std::string name = "";
44    // The actual layer ID
45    int layer_id = -1;
46    // The rectangular region surfaces are allowed to draw on
47    // this layer, note however, width and hieght of the rect
48    // can be negative, in which case they specify that
49    // the actual value is computed using MAX + 1 - w
50    // That is; allow us to specify dimensions dependent on
51    // e.g. screen dimension, w/o knowing the actual screen size.
52    genivi::rect rect;
53    // Specify a role prefix for surfaces that should be
54    // put on this layer.
55    std::string role;
56    // XXX perhaps a zorder is needed here?
57    std::vector<struct split_layout> layouts;
58
59    explicit layer(nlohmann::json const &j);
60
61    bool operator<(struct layer const &rhs) const {
62       return this->id_max < rhs.id_max;
63    }
64
65    json to_json() const;
66 };
67
68 struct layer_map {
69    using json = nlohmann::json;
70
71    using storage_type = std::set<struct layer>;
72    using layers_type = std::vector<unsigned int>;
73    using role_to_layer_map = std::vector<std::pair<std::string, int>>;
74    using addsurf_layer_map = std::map<unsigned, unsigned>;
75
76    // XXX: we also will need a layer_id to layer map, perhaps
77    // make this the primary map, and the surface_id->layer a
78    // secondary map.
79
80    storage_type mapping;  // map surface_id to layer
81    layers_type layers;    // the actual layer IDs we have
82    int main_surface;
83    std::string main_surface_name;
84    role_to_layer_map roles;
85    addsurf_layer_map surfaces;  // additional surfaces on layers
86
87    optional<int> get_layer_id(int surface_id);
88    optional<int> get_layer_id(std::string const &role);
89    optional<struct layer> get_layer(int layer_id) {
90       auto i = std::find_if(
91          std::cbegin(this->mapping), std::cend(this->mapping),
92          [layer_id](struct layer const &l) { return layer_id == l.layer_id; });
93       return i == this->mapping.end() ? nullopt : optional<struct layer>(*i);
94    }
95
96    optional<genivi::rect> get_layer_rect(int surface_id);
97    layers_type::size_type get_layers_count() const {
98       return this->layers.size();
99    }
100
101    void add_surface(unsigned surface_id, unsigned layer_id) {
102       this->surfaces[surface_id] = layer_id;
103    }
104
105    json to_json() const;
106 };
107
108 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
109
110 }  // namespace wm
111
112 #endif  // TMCAGLWM_LAYERS_H