Skip to content

Commit

Permalink
Allow enabling screensaver when game is running (#86)
Browse files Browse the repository at this point in the history
* Allow enabling screensaver when running under SDL

* Move screensaver hint inside SLD_WasInit scope

* Support screensaver on Windows too, formatting

* revert wolf.sln

* Rename r_sdlAllowScreenSaver -> r_allowScreenSaver for consistency
  • Loading branch information
Aciz authored Nov 10, 2023
1 parent eb3ea1e commit 9a38daa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/sdl/sdl_glimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/win32/win_wndproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a38daa

Please sign in to comment.