-static struct wl_output_listener o_listener = {o_geometry, o_mode, o_done,
- o_scale};
-
-static void r_global(void *data, struct wl_registry *r, uint32_t name,
- char const *iface, uint32_t v) {
- struct conn *c = static_cast<conn *>(data);
-
- if (strcmp(iface, "ivi_controller") == 0) {
- c->c = static_cast<ivi_controller *>(
- wl_registry_bind(r, name, &ivi_controller_interface, v));
- ivi_controller_add_listener(c->c, &c_listener, c);
- } else if (strcmp(iface, "wl_output") == 0) {
- auto o = static_cast<wl_output *>(
- wl_registry_bind(r, name, &wl_output_interface, v));
- c->outputs.emplace_back(std::unique_ptr<wl_output, void (*)(wl_output *)>(
- o, wl_output_destroy));
- wl_output_add_listener(o, &o_listener, c);
- } else {
- lognotice("registry @ %p global n %u i %s v %u", r, name, iface, v);
+#define CHECK_WAYLAND() \
+ do { \
+ if (g_wayland == nullptr) { \
+ afb_req_fail(req, "failed", \
+ "Binding not initialized, did the compositor die?"); \
+ return; \
+ } \
+ } while (0)
+
+// _ _ _ _ ____
+// __| | ___| |__ _ _ __ _ ___| |_ __ _| |_ _ _ ___ / /\ \
+// / _` |/ _ \ '_ \| | | |/ _` | / __| __/ _` | __| | | / __| | | |
+// | (_| | __/ |_) | |_| | (_| | \__ \ || (_| | |_| |_| \__ \ | | |
+// \__,_|\___|_.__/ \__,_|\__, |___|___/\__\__,_|\__|\__,_|___/ | | |
+// |___/_____| \_\/_/
+void debug_status(struct afb_req req) noexcept {
+ // Quick and dirty, dump current surfaces and layers
+ AFB_REQ_DEBUG(req, "status");
+
+ CHECK_WAYLAND();
+
+ try {
+ using json = nlohmann::json;
+
+ json j;
+
+ if (!g_wayland->controller->surfaces.empty()) {
+ auto a = json::array();
+ for (auto const &i : g_wayland->controller->surfaces) {
+ auto const &r = i.second->dst_rect;
+ auto const &s = i.second->size;
+ a.push_back({{"id", i.first},
+ {"size", {s.w, s.h}},
+ {"dst_rect", {r.w, r.h, r.x, r.y}}});
+ }
+ j["surfaces"] = a;
+ }
+
+ if (!g_wayland->controller->layers.empty()) {
+ auto a = json::array();
+ for (auto const &i : g_wayland->controller->layers) {
+ auto const &r = i.second->dst_rect;
+ auto const &s = i.second->size;
+ a.push_back({{"id", i.first},
+ {"size", {s.w, s.h}},
+ {"dst_rect", {r.w, r.h, r.x, r.y}}});
+ }
+ j["layers"] = a;
+ }
+
+ afb_req_success(req, json_tokener_parse(j.dump().c_str()), "status");
+ } catch (std::exception &e) {
+ afb_req_fail_f(req, "failed", "Uncaught exception: %s", e.what());