@@ -35,7 +35,29 @@ static struct input_manager input_manager = {
3535 .screen = & screen ,
3636};
3737
38+ #if defined(__APPLE__ ) || defined(__WINDOWS__ )
39+ # define CONTINUOUS_RESIZING_WORKAROUND
40+ #endif
41+
42+ #ifdef CONTINUOUS_RESIZING_WORKAROUND
43+ // On Windows and MacOS, resizing blocks the event loop, so resizing events are
44+ // not triggered. As a workaround, handle them in an event handler.
45+ //
46+ // <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
47+ // <https://stackoverflow.com/a/40693139/1987178>
48+ static int event_watcher (void * data , SDL_Event * event ) {
49+ if (event -> type == SDL_WINDOWEVENT && event -> window .event == SDL_WINDOWEVENT_RESIZED ) {
50+ // called from another thread, not very safe, but it's a workaround!
51+ screen_render (& screen );
52+ }
53+ return 0 ;
54+ }
55+ #endif
56+
3857static void event_loop (void ) {
58+ #ifdef CONTINUOUS_RESIZING_WORKAROUND
59+ SDL_AddEventWatch (event_watcher , NULL );
60+ #endif
3961 SDL_Event event ;
4062 while (SDL_WaitEvent (& event )) {
4163 switch (event .type ) {
@@ -103,9 +125,9 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
103125 // managed by the event loop. This blocking call blocks the event loop, so
104126 // timeout the connection not to block indefinitely in case of SIGTERM.
105127#define SERVER_CONNECT_TIMEOUT_MS 2000
106- socket_t device_socket = server_connect_to (& server , serial , SERVER_CONNECT_TIMEOUT_MS );
128+ socket_t device_socket = server_connect_to (& server , SERVER_CONNECT_TIMEOUT_MS );
107129 if (device_socket == INVALID_SOCKET ) {
108- server_stop (& server , serial );
130+ server_stop (& server );
109131 ret = SDL_FALSE ;
110132 goto finally_destroy_server ;
111133 }
@@ -117,13 +139,13 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
117139 // therefore, we transmit the screen size before the video stream, to be able
118140 // to init the window immediately
119141 if (!device_read_info (device_socket , device_name , & frame_size )) {
120- server_stop (& server , serial );
142+ server_stop (& server );
121143 ret = SDL_FALSE ;
122144 goto finally_destroy_server ;
123145 }
124146
125147 if (!frames_init (& frames )) {
126- server_stop (& server , serial );
148+ server_stop (& server );
127149 ret = SDL_FALSE ;
128150 goto finally_destroy_server ;
129151 }
@@ -134,7 +156,7 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
134156 // start the decoder
135157 if (!decoder_start (& decoder )) {
136158 ret = SDL_FALSE ;
137- server_stop (& server , serial );
159+ server_stop (& server );
138160 goto finally_destroy_frames ;
139161 }
140162
@@ -165,7 +187,7 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
165187finally_stop_decoder :
166188 decoder_stop (& decoder );
167189 // stop the server before decoder_join() to wake up the decoder
168- server_stop (& server , serial );
190+ server_stop (& server );
169191 decoder_join (& decoder );
170192finally_destroy_frames :
171193 frames_destroy (& frames );
0 commit comments