@@ -102,7 +102,7 @@ static BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
102102#endif // _WIN32
103103
104104static void
105- sdl_set_hints (const char * render_driver ) {
105+ sdl_set_hints (const char * render_driver , bool disable_screensaver ) {
106106 if (render_driver && !SDL_SetHint (SDL_HINT_RENDER_DRIVER , render_driver )) {
107107 LOGW ("Could not set render driver" );
108108 }
@@ -137,29 +137,22 @@ sdl_set_hints(const char *render_driver) {
137137 if (!SDL_SetHint (SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS , "1" )) {
138138 LOGW ("Could not allow joystick background events" );
139139 }
140+
141+ if (!disable_screensaver
142+ && !SDL_SetHint (SDL_HINT_VIDEO_ALLOW_SCREENSAVER , "1" )) {
143+ LOGW ("Could not enable screensaver" );
144+ }
140145}
141146
142147static void
143- sdl_configure (bool disable_screensaver ) {
148+ sdl_configure (void ) {
144149#ifdef _WIN32
145150 // Clean up properly on Ctrl+C on Windows
146151 bool ok = SetConsoleCtrlHandler (windows_ctrl_handler , TRUE);
147152 if (!ok ) {
148153 LOGW ("Could not set Ctrl+C handler" );
149154 }
150155#endif // _WIN32
151-
152- if (disable_screensaver ) {
153- bool ok = SDL_DisableScreenSaver ();
154- if (!ok ) {
155- LOGW ("Could not disable screen saver" );
156- }
157- } else {
158- bool ok = SDL_EnableScreenSaver ();
159- if (!ok ) {
160- LOGW ("Could not enable screen saver" );
161- }
162- }
163156}
164157
165158static enum scrcpy_exit_code
@@ -489,7 +482,7 @@ scrcpy(struct scrcpy_options *options) {
489482
490483 // Set hints before starting the server thread to avoid race conditions in
491484 // SDL
492- sdl_set_hints (options -> render_driver );
485+ sdl_set_hints (options -> render_driver , options -> disable_screensaver );
493486
494487 if (!sc_server_start (& s -> server )) {
495488 goto end ;
@@ -538,7 +531,7 @@ scrcpy(struct scrcpy_options *options) {
538531 }
539532 }
540533
541- sdl_configure (options -> disable_screensaver );
534+ sdl_configure ();
542535
543536 // Await for server without blocking Ctrl+C handling
544537 bool connected ;
0 commit comments