From c23c38f99dbed2776d9c0ec92b37da5788866df7 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 13 Apr 2021 22:14:09 +0200 Subject: [PATCH] Move resizing workaround to screen.c --- app/src/scrcpy.c | 29 ----------------------------- app/src/screen.c | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 6f803d23..7d47d016 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -128,30 +128,6 @@ sdl_init_and_configure(bool display, const char *render_driver, return true; } - -#if defined(__APPLE__) || defined(__WINDOWS__) -# define CONTINUOUS_RESIZING_WORKAROUND -#endif - -#ifdef CONTINUOUS_RESIZING_WORKAROUND -// On Windows and MacOS, resizing blocks the event loop, so resizing events are -// not triggered. As a workaround, handle them in an event handler. -// -// -// -static int -event_watcher(void *data, SDL_Event *event) { - (void) data; - if (event->type == SDL_WINDOWEVENT - && event->window.event == SDL_WINDOWEVENT_RESIZED) { - // In practice, it seems to always be called from the same thread in - // that specific case. Anyway, it's just a workaround. - screen_render(&screen, true); - } - return 0; -} -#endif - static bool is_apk(const char *file) { const char *ext = strrchr(file, '.'); @@ -209,11 +185,6 @@ end: static bool event_loop(const struct scrcpy_options *options) { -#ifdef CONTINUOUS_RESIZING_WORKAROUND - if (options->display) { - SDL_AddEventWatch(event_watcher, NULL); - } -#endif SDL_Event event; while (SDL_WaitEvent(&event)) { enum event_result result = handle_event(&event, options); diff --git a/app/src/screen.c b/app/src/screen.c index ed810264..934e418f 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -239,6 +239,29 @@ create_texture(struct screen *screen) { return texture; } +#if defined(__APPLE__) || defined(__WINDOWS__) +# define CONTINUOUS_RESIZING_WORKAROUND +#endif + +#ifdef CONTINUOUS_RESIZING_WORKAROUND +// On Windows and MacOS, resizing blocks the event loop, so resizing events are +// not triggered. As a workaround, handle them in an event handler. +// +// +// +static int +event_watcher(void *data, SDL_Event *event) { + struct screen *screen = data; + if (event->type == SDL_WINDOWEVENT + && event->window.event == SDL_WINDOWEVENT_RESIZED) { + // In practice, it seems to always be called from the same thread in + // that specific case. Anyway, it's just a workaround. + screen_render(screen, true); + } + return 0; +} +#endif + bool screen_init(struct screen *screen, struct video_buffer *vb, struct fps_counter *fps_counter, @@ -366,6 +389,10 @@ screen_init(struct screen *screen, struct video_buffer *vb, screen_switch_fullscreen(screen); } +#ifdef CONTINUOUS_RESIZING_WORKAROUND + SDL_AddEventWatch(event_watcher, screen); +#endif + return true; }