diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 9cdd3eb3..bc16b217 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -107,8 +107,12 @@ cvar_t *r_allowSoftwareGL; // don't abort out if the pixelformat claims software cvar_t *r_swapInterval; #ifndef USE_SDL cvar_t *r_glDriver; +#ifdef _WIN32 +cvar_t *r_allowScreenSaver; +#endif #else cvar_t *r_sdlDriver; +cvar_t *r_allowScreenSaver; #endif cvar_t *r_displayRefresh; cvar_t *r_fullscreen; @@ -4306,9 +4310,15 @@ static void CL_InitGLimp_Cvars( void ) #ifndef USE_SDL r_glDriver = Cvar_Get( "r_glDriver", OPENGL_DRIVER_NAME, CVAR_ARCHIVE_ND | CVAR_LATCH | CVAR_UNSAFE ); Cvar_SetDescription( r_glDriver, "Specifies the OpenGL driver to use, will revert back to default if driver name set is invalid" ); +#ifdef _WIN32 + r_allowScreenSaver = Cvar_Get( "r_allowScreenSaver", "0", CVAR_ARCHIVE_ND | CVAR_UNSAFE ); + Cvar_SetDescription( r_allowScreenSaver, "Allow screen to sleep while the game is running" ); +#endif #else r_sdlDriver = Cvar_Get( "r_sdlDriver", "", CVAR_ARCHIVE_ND | CVAR_LATCH | CVAR_UNSAFE ); Cvar_SetDescription( r_sdlDriver, "Override hint to SDL which video driver to use, example \"x11\" or \"wayland\"" ); + r_allowScreenSaver = Cvar_Get( "r_allowScreenSaver", "0", CVAR_ARCHIVE_ND | CVAR_LATCH | CVAR_UNSAFE ); + Cvar_SetDescription( r_allowScreenSaver, "Allow screen to sleep while the game is running, requires full restart" ); #endif r_displayRefresh = Cvar_Get( "r_displayRefresh", "0", CVAR_LATCH | CVAR_UNSAFE ); diff --git a/src/client/client.h b/src/client/client.h index 8478b2e1..c002b03c 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -520,8 +520,12 @@ extern cvar_t *r_allowSoftwareGL; extern cvar_t *r_swapInterval; #ifndef USE_SDL extern cvar_t *r_glDriver; +#ifdef _WIN32 +extern cvar_t *r_allowScreenSaver; +#endif #else extern cvar_t *r_sdlDriver; +extern cvar_t *r_allowScreenSaver; #endif extern cvar_t *r_displayRefresh; extern cvar_t *r_fullscreen; diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index a213208b..aadc5297 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -560,6 +560,11 @@ static rserr_t GLimp_StartDriverAndSetMode( int mode, const char *modeFS, qboole SDL_setenv("SDL_VIDEODRIVER", r_sdlDriver->string, 0 ); } + if ( r_allowScreenSaver->integer ) + { + SDL_SetHint( SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1" ); + } + /* Starting from SDL2 2.0.14 The default value for SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS is now false for better compatibility with modern window managers, however it diff --git a/src/win32/win_wndproc.c b/src/win32/win_wndproc.c index aad2bbd0..938d4eb1 100644 --- a/src/win32/win_wndproc.c +++ b/src/win32/win_wndproc.c @@ -990,7 +990,13 @@ LRESULT WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam return 0; if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER ) + { + if ( Cvar_VariableIntegerValue("r_allowScreenSaver") ) + { + break; + } return 0; + } if ( wParam == SC_MINIMIZE && CL_VideoRecording() != AVIDEMO_NONE && !( re.CanMinimize && re.CanMinimize() ) ) return 0;