From 0b1e59186f1fb75d74f2929f636128958b067ab4 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 13 Mar 2018 21:26:05 +0100 Subject: [PATCH] Workaround continuous resizing on Windows/MacOS On Windows and MacOS, resizing blocks the event loop, so resizing events are not triggered: - - As a workaround, register an event watcher to render the screen from another thread. Since the whole event loop is blocked during resizing, the screen content is not refreshed (on Windows and MacOS) until resizing ends. --- app/src/scrcpy.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 66badb06..cc4528df 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -35,7 +35,29 @@ static struct input_manager input_manager = { .screen = &screen, }; +#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) { + if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_RESIZED) { + // called from another thread, not very safe, but it's a workaround! + screen_render(&screen); + } + return 0; +} +#endif + static void event_loop(void) { +#ifdef CONTINUOUS_RESIZING_WORKAROUND + SDL_AddEventWatch(event_watcher, screen.window); +#endif SDL_Event event; while (SDL_WaitEvent(&event)) { switch (event.type) {