aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-12 11:29:28 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-12 11:29:28 +0200
commit83555b0c53f0d59f42e9dcfaeb269948e65e0391 (patch)
tree22fddeac914640de0f9a47ed2cc9e90a2231e42b
parentb154238b7b9e0d21b60c08a1bec23920bff40e36 (diff)
binding: make the pending_events functionality nicer[tm]
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--src/app.cpp7
-rw-r--r--src/app.hpp9
-rw-r--r--src/main.cpp12
3 files changed, 19 insertions, 9 deletions
diff --git a/src/app.cpp b/src/app.cpp
index 7b2b69c..9b8f1fd 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -159,15 +159,12 @@ int App::dispatch_events() {
}
this->display->flush();
- // execute pending tasks, that is layout changes etc.
- // this->execute_pending();
-
return 0;
}
int App::dispatch_pending_events() {
- if (this->pending_events.load(std::memory_order_consume)) {
- this->pending_events.store(false, std::memory_order_release);
+ if (this->pop_pending_events()) {
+ assert(this->pending_events == false);
this->display->dispatch_pending();
return 0;
}
diff --git a/src/app.hpp b/src/app.hpp
index e295797..c4c0a81 100644
--- a/src/app.hpp
+++ b/src/app.hpp
@@ -148,7 +148,16 @@ struct App {
struct LayoutState state;
+ // Set by AFB API when wayland events need to be dispatched
std::atomic<bool> pending_events;
+ void set_pending_events() {
+ this->pending_events.store(true, std::memory_order_release);
+ }
+ bool pop_pending_events() {
+ bool x{true};
+ return this->pending_events.compare_exchange_strong(
+ x, false, std::memory_order_consume);
+ }
explicit App(wl::display *d);
~App();
diff --git a/src/main.cpp b/src/main.cpp
index aee2756..f14cf96 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -65,13 +65,17 @@ int display_event_callback(sd_event_source *evs, int fd, uint32_t events,
{
STN(display_read_events);
g_afb_instance->app.display->read_events();
- g_afb_instance->app.pending_events.store(true, std::memory_order_release);
+ 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);
+ afb_service_call("winman", "ping", json_object_new_object(),
+ [](void *c, int st, json_object *j) {
+ STN(winman_ping_api_call_return);
+ },
+ nullptr);
}
}