#include "app.hpp"
#include "json_helper.hpp"
+#include "layers.hpp"
#include "layout.hpp"
#include "util.hpp"
#include "wayland.hpp"
namespace wm {
-#ifndef NDEBUG
-#define DB(expr) \
- do { \
- std::ostringstream o; \
- o << __FILE__ << ":" << __LINE__ << ":" << __func__ << ": " << expr; \
- logdebug(o.str().c_str()); \
- } while (0)
-#else
-#define DB(expr)
-#endif
-
namespace {
App *g_app;
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"]),
};
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) {
+ if (i.get_layer_for_surface(sid.first).value_or(-1) != sid.second) {
+ return Err<surface_id_to_layer_map>("ID Map embedded test failed!");
+ }
+ }
+ }
+
+ 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{} {
+ // 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; }