Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling screensaver when game is running #86

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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