Display and control your Android device
Extract function to dequeue events
Romain Vimontac1f479d5389
diff --git a/app/src/events.c b/app/src/events.cindex b7a3a7a3..eb40500d 100644--- a/app/src/events.c+++ b/app/src/events.c@@ -25,6 +25,11 @@ sc_push_event_impl(uint32_t type, void *ptr, const char *name) {return true;}+bool+sc_dequeue_event(uint32_t type, SDL_Event *event) {+ return SDL_PeepEvents(event, 1, SDL_GETEVENT, type, type) == 1;+}+boolsc_main_thread_init(void) {stopped = false;diff --git a/app/src/events.h b/app/src/events.hindex 0c7b4c37..d71d8f0d 100644--- a/app/src/events.h+++ b/app/src/events.h@@ -29,6 +29,8 @@ sc_push_event_impl(uint32_t type, void *ptr, const char *name);#define sc_push_event(TYPE) sc_push_event_impl(TYPE, NULL, # TYPE)#define sc_push_event_with_data(TYPE, PTR) sc_push_event_impl(TYPE, PTR, # TYPE)+bool sc_dequeue_event(uint32_t type, SDL_Event *event);+typedef SDL_MainThreadCallback sc_runnable_fn;booldiff --git a/app/src/screen.c b/app/src/screen.cindex 5c280c7f..add2a8e2 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -811,10 +811,9 @@ sc_screen_destroy(struct sc_screen *screen) {sc_mutex_destroy(&screen->mutex);SDL_Event event;- int nevents = SDL_PeepEvents(&event, 1, SDL_GETEVENT,- SC_EVENT_DISCONNECTED_ICON_LOADED,- SC_EVENT_DISCONNECTED_ICON_LOADED);- if (nevents == 1) {+ bool has_event =+ sc_dequeue_event(SC_EVENT_DISCONNECTED_ICON_LOADED, &event);+ if (has_event) {assert(event.type == SC_EVENT_DISCONNECTED_ICON_LOADED);// The event was posted, but not handled, the icon must be freedSDL_Surface *dangling_icon = event.user.data1;