- sigset_t sset{};
- sigemptyset(&sset);
- sigaddset(&sset, SIGINT);
- sigaddset(&sset, SIGTERM);
-
- auto sfd = unique_fd(signalfd(-1, &sset, SFD_NONBLOCK | SFD_CLOEXEC));
- sigprocmask(SIG_BLOCK, &sset, NULL);
- p.add_fd(sfd.fd, [](int fd) {
- struct signalfd_siginfo si;
- while (read(fd, &si, sizeof(si)) == sizeof(si)) {
- lognotice("Received signal %u", si.ssi_signo);
+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) noexcept {
+ // Quick and dirty, dump current surfaces and layers
+ AFB_REQ_DEBUG(req, "status");
+
+ CHECK_WAYLAND();
+
+ try {
+ json j;
+
+ if (!g_wayland->controller->surfaces.empty()) {
+ auto js = json::array();
+ for (auto const &i : g_wayland->controller->surfaces) {
+ auto const &r = i.second->dst_rect;
+ auto const &s = i.second->size;
+ js.push_back({{"id", i.first},
+ {"size", {s.w, s.h}},
+ {"dst_rect", {r.w, r.h, r.x, r.y}}});
+ }
+ j["surfaces"] = js;
+ }
+
+ if (!g_wayland->controller->layers.empty()) {
+ auto js = json::array();
+ for (auto const &i : g_wayland->controller->layers) {
+ auto const &r = i.second->dst_rect;
+ auto const &s = i.second->size;
+ js.push_back({{"id", i.first},
+ {"size", {s.w, s.h}},
+ {"dst_rect", {r.w, r.h, r.x, r.y}}});
+ }
+ j["layers"] = js;