1 #include "json_helper.hpp"
10 #include <afb/afb-binding.h>
11 #include <systemd/sd-event.h>
16 std::unique_ptr<wl::display> display;
19 afb_instance() : display{new wl::display}, app{this->display.get()} {}
24 struct afb_instance *g_afb_instance;
26 int afb_instance::init() {
27 if (!this->display->ok()) {
31 return this->app.init();
34 int display_event_callback(sd_event_source *evs, int fd, uint32_t events,
36 if ((events & EPOLLHUP) != 0) {
37 logerror("The compositor hung up, dying now.");
38 delete g_afb_instance;
39 g_afb_instance = nullptr;
43 if (events & EPOLLIN) {
44 if (g_afb_instance->app.dispatch_events() == -1) {
52 sd_event_source_unref(evs);
57 // | |__ (_)_ __ __| (_)_ __ __ _ (_)_ __ (_) |_ / /\ \
58 // | '_ \| | '_ \ / _` | | '_ \ / _` | | | '_ \| | __| | | |
59 // | |_) | | | | | (_| | | | | | (_| | | | | | | | |_| | | |
60 // |_.__/|_|_| |_|\__,_|_|_| |_|\__, |___|_|_| |_|_|\__| | | |
63 lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
65 if (g_afb_instance != nullptr) {
66 logerror("Wayland context already initialized?");
70 if (getenv("XDG_RUNTIME_DIR") == nullptr) {
71 logerror("Environment variable XDG_RUNTIME_DIR not set");
75 g_afb_instance = new afb_instance;
76 if (g_afb_instance->init() == -1) {
77 logerror("Could not connect to compositor");
82 int ret = sd_event_add_io(afb_daemon_get_event_loop(), nullptr,
83 g_afb_instance->display->get_fd(), EPOLLIN,
84 display_event_callback, g_afb_instance);
86 logerror("Could not initialize afb_instance event handler: %d", -ret);
91 atexit([] { delete g_afb_instance; });
96 delete g_afb_instance;
97 g_afb_instance = nullptr;
101 int binding_init() noexcept {
103 return binding_init_();
104 } catch (std::exception &e) {
105 logerror("Uncaught exception in binding_init(): %s", e.what());
112 #include "afb_binding.inl"
114 extern "C" const struct afb_binding_v2 afbBindingV2 = {
115 "winman", NULL, NULL, winman_verbs, NULL, binding_init, NULL, 1};