X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fapp.cpp;h=871222f83115c916e1bb68c18aa2bb7b77a11043;hb=64ed0324fe01c76ba7ada09243228b5ec45c6cda;hp=b261c53087770d7353c1be6176c17289f539d2f1;hpb=b166f3512f5e426e60a4ff610a9f07239ac18ea1;p=staging%2Fwindowmanager.git diff --git a/src/app.cpp b/src/app.cpp index b261c53..871222f 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -4,44 +4,148 @@ #include "app.hpp" #include "json_helper.hpp" +#include "layers.hpp" +#include "layout.hpp" #include "util.hpp" #include "wayland.hpp" +#include +#include + #include #include +#include +#include + namespace wm { namespace { App *g_app; + +using json = nlohmann::json; + +struct wm::area area_from_json(json const &j) { + DB(j); + return wm::area{ + j["name"].get(), + { + get(j["width"]), get(j["height"]), + get(j["x"]), get(j["y"]), + }, + get(j["zorder"]), + }; +} + +result layout_from_json(json const &j) { + DB(j); + auto &ja = j["areas"]; + + auto l = wm::layout{j["name"].get(), uint32_t(ja.size()), {}}; + + if (ja.size() > layout::MAX_N_AREAS) { + return Err("Invalid number of areas in layout"); + } + + logdebug("Loading layout '%s' with %u areas", l.name.c_str(), + unsigned(ja.size())); + + std::transform(std::cbegin(ja), std::cend(ja), std::begin(l.areas), + area_from_json); + + return Ok(l); +} + +struct result load_layout(char const *filename) { + DB("loading layout from " << filename); + + json jlayouts; + std::ifstream i(filename); + i >> jlayouts; + + auto layouts = layouts_type(); + std::transform(std::cbegin(jlayouts), std::cend(jlayouts), + std::back_inserter(layouts), layout_from_json); + + return Ok(layouts); +} + +struct result + 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> tests; + std::transform(std::cbegin(jtests), std::cend(jtests), + std::back_inserter(tests), [](json const &j) { + return std::make_pair(get(j["surface_id"]), + get(j["expect_layer_id"])); + }); + + for (auto sid : tests) { + if (i.get_layer_for_surface(sid.first).value_or(-1) != sid.second) { + return Err("ID Map embedded test failed!"); + } + } + } + + return m; +} + } // namespace -App::App(wl::display *d) : api{this}, display{d}, controller{}, outputs() { +App::App(wl::display *d) + : api{this}, display{d}, controller{} { + // layouts(load_layout("../layout.json").unwrap()) { assert(g_app == nullptr); g_app = this; + + 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; } + int App::init() { if (!this->display->ok()) { return -1; } - this->display->r.add_global_handler( - "wl_output", [](wl_registry *r, uint32_t name, uint32_t v) { - g_app->outputs.emplace_back(std::make_unique(r, name, v)); + this->display->add_global_handler( + "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) { + this->outputs.emplace_back(std::make_unique(r, name, v)); }); - this->display->r.add_global_handler( - "ivi_controller", [](wl_registry *r, uint32_t name, uint32_t v) { - g_app->controller = std::make_unique(r, name, v); + this->display->add_global_handler( + "ivi_controller", [this](wl_registry *r, uint32_t name, uint32_t v) { + this->controller = std::make_unique(r, name, v); // XXX: This protocol needs the output, so lets just add our mapping // here... - g_app->controller->add_proxy_to_id_mapping( - g_app->outputs.back()->proxy.get(), + this->controller->add_proxy_to_id_mapping( + this->outputs.back()->proxy.get(), wl_proxy_get_id(reinterpret_cast( - g_app->outputs.back()->proxy.get()))); + this->outputs.back()->proxy.get()))); }); // First level objects