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