Skip to content

Display and control your Android device

Move resizing workaround to screen.c

Romain Vimontc23c38f99dbe
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.
-//
-// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
-// <https://stackoverflow.com/a/40693139/1987178>
-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.
+//
+// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
+// <https://stackoverflow.com/a/40693139/1987178>
+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;
}