+
+int binding_init() noexcept {
+ try {
+ return binding_init_();
+ } catch (std::exception &e) {
+ AFB_ERROR("Uncaught exception in binding_init(): %s", e.what());
+ }
+ return -1;
+}
+
+#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) {
+ // Quick and dirty, dump current surfaces and layers
+ AFB_REQ_DEBUG(req, "status");
+
+ auto o = json_object_new_object();
+ json_object_object_add(o, "surfaces",
+ to_json(g_wayland->controller->surfaces));
+ json_object_object_add(o, "layers", to_json(g_wayland->controller->layers));
+ json_object_object_add(o, "screens",
+ to_json(g_wayland->controller->screens));
+
+ afb_req_success(req, o, "status");
+}
+
+void debug_surfaces(afb_req req) {
+ afb_req_success(req, to_json(g_wayland->controller->surfaces), "surfaces");
+}
+
+void debug_layers(afb_req req) {
+ afb_req_success(req, to_json(g_wayland->controller->layers), "layers");
+}
+
+#define WRAP(F) \
+ [](afb_req req) noexcept { \
+ CHECK_WAYLAND(); \
+ try { \
+ F(req); \
+ } catch (std::exception & e) { \
+ afb_req_fail_f(req, "failed", "Uncaught exception: %s", e.what()); \
+ } \
+ }
+
+const struct afb_verb_v2 verbs[] = {
+ {"debug::status", WRAP(debug_status), NULL, NULL, AFB_SESSION_NONE_V2},
+ {"debug::layers", WRAP(debug_layers), NULL, NULL, AFB_SESSION_NONE_V2},
+ {"debug::surfaces", WRAP(debug_surfaces), NULL, NULL, AFB_SESSION_NONE_V2},
+ {},
+};
+} // namespace
+
+extern "C" const struct afb_binding_v2 afbBindingV2 = {
+ "winman", NULL, NULL, verbs, NULL, binding_init, NULL, 1};