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.
This commit is contained in:
Romain Vimont 2026-04-06 12:13:28 +02:00
parent 6f636fb2b5
commit d6ffa2dbc6

View file

@ -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;
@ -479,6 +477,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);
@ -530,8 +532,6 @@ scrcpy(struct scrcpy_options *options) {
}
}
sdl_configure();
// Await for server without blocking Ctrl+C handling
bool connected;
if (!await_for_server(&connected)) {