doc: documentation update, more examples, some external links
[staging/windowmanager.git] / src / main.cpp
index d944c24..5b140f2 100644 (file)
@@ -30,7 +30,6 @@ extern "C" {
 }
 
 namespace {
-std::mutex binding_m;
 
 struct afb_instance {
    std::unique_ptr<wl::display> display;
@@ -51,9 +50,9 @@ int afb_instance::init() {
    return this->app.init();
 }
 
-int display_event_callback(sd_event_source *evs, int /*fd*/, uint32_t events,
+int display_event_callback(sd_event_source *evs, int  /*fd*/, uint32_t events,
                            void * /*data*/) {
-   std::lock_guard<std::mutex> guard(binding_m);
+   ST();
 
    if ((events & EPOLLHUP) != 0) {
       logerror("The compositor hung up, dying now.");
@@ -63,8 +62,20 @@ int display_event_callback(sd_event_source *evs, int /*fd*/, uint32_t events,
    }
 
    if ((events & EPOLLIN) != 0u) {
-      if (g_afb_instance->app.dispatch_events() == -1) {
-         goto error;
+      {
+         STN(display_read_events);
+         g_afb_instance->app.display->read_events();
+         g_afb_instance->app.set_pending_events();
+      }
+      {
+         // We want do dispatch pending wayland events from within
+         // the API context
+         STN(winman_ping_api_call);
+         afb_service_call("winman", "ping", json_object_new_object(),
+                          [](void *c, int st, json_object *j) {
+                             STN(winman_ping_api_call_return);
+                          },
+                          nullptr);
       }
    }
 
@@ -72,8 +83,9 @@ int display_event_callback(sd_event_source *evs, int /*fd*/, uint32_t events,
 
 error:
    sd_event_source_unref(evs);
-   if (getenv("WINMAN_EXIT_ON_HANGUP") != nullptr)
+   if (getenv("WINMAN_EXIT_ON_HANGUP") != nullptr) {
       exit(1);
+}
    return -1;
 }
 
@@ -144,7 +156,7 @@ void binding_api::send_event(char const *evname, char const *label) {
       logdebug("afb_event_broadcast failed: %m");
    }
 }
-}
+} // namespace wm
 
 extern "C" const struct afb_binding_v2 afbBindingV2 = {
-   "winman", nullptr, nullptr, winman_verbs, nullptr, binding_init, nullptr, 1};
+   "winman", nullptr, nullptr, winman_verbs, nullptr, binding_init, nullptr, 0};