Skip to content

Commit 07f8eb0

Browse files
committed
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 <#6754>
1 parent c527bc7 commit 07f8eb0

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

app/src/scrcpy.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ static BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
9999
}
100100
return FALSE;
101101
}
102+
103+
static void
104+
sdl_configure_ctrl_c_windows(void) {
105+
// Clean up properly on Ctrl+C on Windows
106+
bool ok = SetConsoleCtrlHandler(windows_ctrl_handler, TRUE);
107+
if (!ok) {
108+
LOGW("Could not set Ctrl+C handler");
109+
}
110+
}
102111
#endif // _WIN32
103112

104113
static void
@@ -144,17 +153,6 @@ sdl_set_hints(const char *render_driver, bool disable_screensaver) {
144153
}
145154
}
146155

147-
static void
148-
sdl_configure(void) {
149-
#ifdef _WIN32
150-
// Clean up properly on Ctrl+C on Windows
151-
bool ok = SetConsoleCtrlHandler(windows_ctrl_handler, TRUE);
152-
if (!ok) {
153-
LOGW("Could not set Ctrl+C handler");
154-
}
155-
#endif // _WIN32
156-
}
157-
158156
static enum scrcpy_exit_code
159157
event_loop(struct scrcpy *s, bool has_screen) {
160158
SDL_Event event;
@@ -480,6 +478,10 @@ scrcpy(struct scrcpy_options *options) {
480478
return SCRCPY_EXIT_FAILURE;
481479
}
482480

481+
#ifdef _WIN32
482+
sdl_configure_ctrl_c_windows();
483+
#endif
484+
483485
// Set hints before starting the server thread to avoid race conditions in
484486
// SDL
485487
sdl_set_hints(options->render_driver, options->disable_screensaver);
@@ -531,8 +533,6 @@ scrcpy(struct scrcpy_options *options) {
531533
}
532534
}
533535

534-
sdl_configure();
535-
536536
// Await for server without blocking Ctrl+C handling
537537
bool connected;
538538
if (!await_for_server(&connected)) {

0 commit comments

Comments
 (0)