From 81ff7ebd065eaf6917905e64e4e7017e9f83fc3b Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 21 Jan 2022 21:43:49 +0100 Subject: [PATCH] Simplify event loop Merge single event handling with the event loop function. --- app/src/scrcpy.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 0552a057..d7ba3670 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -148,39 +148,19 @@ sdl_configure(bool display, bool disable_screensaver) { } } -enum event_result { - EVENT_RESULT_CONTINUE, - EVENT_RESULT_STOPPED_BY_USER, - EVENT_RESULT_STOPPED_BY_EOS, -}; - -static enum event_result -handle_event(struct scrcpy *s, SDL_Event *event) { - switch (event->type) { - case EVENT_STREAM_STOPPED: - LOGD("Video stream stopped"); - return EVENT_RESULT_STOPPED_BY_EOS; - case SDL_QUIT: - LOGD("User requested to quit"); - return EVENT_RESULT_STOPPED_BY_USER; - } - - sc_screen_handle_event(&s->screen, event); - return EVENT_RESULT_CONTINUE; -} - static bool event_loop(struct scrcpy *s) { SDL_Event event; while (SDL_WaitEvent(&event)) { - enum event_result result = handle_event(s, &event); - switch (result) { - case EVENT_RESULT_STOPPED_BY_USER: - return true; - case EVENT_RESULT_STOPPED_BY_EOS: + switch (event.type) { + case EVENT_STREAM_STOPPED: LOGW("Device disconnected"); return false; - case EVENT_RESULT_CONTINUE: + case SDL_QUIT: + LOGD("User requested to quit"); + return true; + default: + sc_screen_handle_event(&s->screen, &event); break; } }