-#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());
- }
-}
-
-void debug_surfaces(afb_req req) noexcept {
- CHECK_WAYLAND();
-
- auto a = json_object_new_array();
-
- if (!g_wayland->controller->surfaces.empty()) {
- for (auto const &i : g_wayland->controller->surfaces) {
- json_object_array_add(a, json_object_new_int(i.first));
- }
- }
-
- afb_req_success(req, a, "surfaces");
-}
-
-void debug_layers(afb_req req) noexcept {
- CHECK_WAYLAND();