3308cf6b1d716fdb22f1f6112d2c3ff1346eeb8e
[staging/windowmanager.git] / src / layout.hpp
1 //
2 // Created by mfritzsc on 6/27/17.
3 //
4
5 #ifndef TMCAGLWM_LAYOUT_HPP
6 #define TMCAGLWM_LAYOUT_HPP
7
8 #include <cstdint>
9 #include <experimental/optional>
10 #include <set>
11 #include <string>
12
13 #include <json.hpp>
14
15 #include "result.hpp"
16 #include "wayland.hpp"
17
18 namespace wm {
19
20 // Areas and layouts are defined to have a name, let's just keep it this way,
21 // we will not copy them around anyway.
22 struct area {
23    std::string name;
24    genivi::rect rect;
25    uint32_t layer;  // i.e. zorder?
26 };
27
28 struct layout {
29    static constexpr unsigned MAX_N_AREAS = 2;
30
31    std::string name;
32    uint32_t n_areas;
33    struct area areas[MAX_N_AREAS];
34 };
35
36 typedef std::vector<struct layout> layouts_type;
37
38 struct surface_id_to_layer {
39    int id_min = -1;
40    int id_max = -1;
41    std::string name = "";
42    int layer_id = -1;
43
44    explicit surface_id_to_layer(nlohmann::json const &j);
45
46    bool operator<(struct surface_id_to_layer const &rhs) const {
47       return this->id_max < rhs.id_max;
48    }
49 };
50
51 inline bool operator<(struct surface_id_to_layer const &a, int b) {
52    return a.id_max < b;
53 }
54
55 struct surface_id_to_layer_map {
56    typedef std::set<struct surface_id_to_layer> map_type;
57
58    map_type mapping;
59
60    std::experimental::optional<int> get_layer_for_surface(int surface_id) {
61       auto i = std::lower_bound(std::cbegin(this->mapping),
62                                 std::cend(this->mapping), surface_id);
63
64       if (i != this->mapping.end()) {
65          if (i->id_min <= surface_id) {
66             return std::experimental::optional<int>(i->layer_id);
67          }
68       }
69
70       return std::experimental::nullopt;
71    }
72 };
73
74 struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
75    nlohmann::json const &j);
76
77 }  // namespace wm
78
79 #endif  // TMCAGLWM_LAYOUT_HPP