summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app.cpp62
1 files changed, 48 insertions, 14 deletions
diff --git a/src/app.cpp b/src/app.cpp
index 9bd12ed..8a3abec 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -30,10 +30,8 @@ struct wm::area area_from_json(json const &j) {
return wm::area{
j["name"].get<std::string>(),
{
- get<uint32_t>(j["width"]),
- get<uint32_t>(j["height"]),
- get<int32_t>(j["x"]),
- get<int32_t>(j["y"]),
+ get<uint32_t>(j["width"]), get<uint32_t>(j["height"]),
+ get<int32_t>(j["x"]), get<int32_t>(j["y"]),
},
get<uint32_t>(j["zorder"]),
};
@@ -72,22 +70,58 @@ struct result<layouts_type> load_layout(char const *filename) {
return Ok(layouts);
}
+struct result<surface_id_to_layer_map>
+ load_layer_ids(char const *filename) {
+ DB("loading IDs from " << filename);
+
+ json jids;
+ std::ifstream i(filename);
+ i >> jids;
+
+ auto m = to_surface_id_to_layer_map(jids["mappings"]);
+
+ if (m.is_ok()) {
+ auto i = m.unwrap();
+
+ auto jtests = jids.value("tests", json());
+
+ std::vector<std::pair<int, int>> tests;
+ std::transform(std::cbegin(jtests), std::cend(jtests),
+ std::back_inserter(tests), [](json const &j) {
+ return std::make_pair(get<int>(j["surface_id"]),
+ get<int>(j["expect_layer_id"]));
+ });
+
+ for (auto sid : tests) {
+ DB("layer id for surface "
+ << sid.first << " is "
+ << i.get_layer_for_surface(sid.first).value_or(-1) << " expected "
+ << sid.second);
+ }
+ }
+
+ return m;
+}
+
} // namespace
App::App(wl::display *d)
- : api{this},
- display{d},
- controller{},
- outputs(),
- layouts() {
- // layouts(load_layout("../layout.json").unwrap()) {
+ : api{this}, display{d}, controller{}, outputs(), layouts() {
+ // layouts(load_layout("../layout.json").unwrap()) {
assert(g_app == nullptr);
g_app = this;
- auto l = load_layout("../layout.json");
- if (l.is_err()) {
- DB("Could not load layout: " << l.unwrap_err());
- }
+ auto a = load_layout("../layout.json");
+ auto b = a.map_err([](char const *e) -> char const * {
+ DB("Could not load layout: " << e);
+ return e;
+ });
+
+ auto c = load_layer_ids("../ids.json");
+ auto e = c.map_err([](char const *e) -> char const * {
+ DB("Could not load ids: " << e);
+ return e;
+ });
}
App::~App() { g_app = nullptr; }