Skip to content

Display and control your Android device

Move Ctrl+C handler configuration

Romain Vimont07f8eb0ec66c
diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c
index 6b0d6d55..a83702e3 100644
--- a/app/src/scrcpy.c
+++ b/app/src/scrcpy.c
@@ -99,6 +99,15 @@ static BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
}
return FALSE;
}
+
+static void
+sdl_configure_ctrl_c_windows(void) {
+ // Clean up properly on Ctrl+C on Windows
+ bool ok = SetConsoleCtrlHandler(windows_ctrl_handler, TRUE);
+ if (!ok) {
+ LOGW("Could not set Ctrl+C handler");
+ }
+}
#endif // _WIN32
static void
@@ -144,17 +153,6 @@ sdl_set_hints(const char *render_driver, bool disable_screensaver) {
}
}
-static void
-sdl_configure(void) {
-#ifdef _WIN32
- // Clean up properly on Ctrl+C on Windows
- bool ok = SetConsoleCtrlHandler(windows_ctrl_handler, TRUE);
- if (!ok) {
- LOGW("Could not set Ctrl+C handler");
- }
-#endif // _WIN32
-}
-
static enum scrcpy_exit_code
event_loop(struct scrcpy *s, bool has_screen) {
SDL_Event event;
@@ -480,6 +478,10 @@ scrcpy(struct scrcpy_options *options) {
return SCRCPY_EXIT_FAILURE;
}
+#ifdef _WIN32
+ sdl_configure_ctrl_c_windows();
+#endif
+
// Set hints before starting the server thread to avoid race conditions in
// SDL
sdl_set_hints(options->render_driver, options->disable_screensaver);
@@ -531,8 +533,6 @@ scrcpy(struct scrcpy_options *options) {
}
}
- sdl_configure();
-
// Await for server without blocking Ctrl+C handling
bool connected;
if (!await_for_server(&connected)) {