From 07f8eb0ec66c8a878874fcd095fe302a344c99fa Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 6 Apr 2026 12:13:28 +0200 Subject: [PATCH] Move Ctrl+C handler configuration The function `sdl_configure()` now only sets the Ctrl+C handler on Windows. Define it only on Windows, and call it earlier. Refs #6754 --- app/src/scrcpy.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) 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)) {