diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/progs/dyecmd/client.cpp | 1 | ||||
-rw-r--r-- | src/progs/manaplus/client.cpp | 1 | ||||
-rw-r--r-- | src/utils/env.cpp | 5 | ||||
-rw-r--r-- | src/utils/sdl2helper.cpp | 15 | ||||
-rw-r--r-- | src/utils/sdl2helper.h | 2 | ||||
-rw-r--r-- | src/utils/sdlhelper.cpp | 9 | ||||
-rw-r--r-- | src/utils/sdlhelper.h | 2 |
7 files changed, 30 insertions, 5 deletions
diff --git a/src/progs/dyecmd/client.cpp b/src/progs/dyecmd/client.cpp index eb40fd9c5..b071eaf73 100644 --- a/src/progs/dyecmd/client.cpp +++ b/src/progs/dyecmd/client.cpp @@ -269,6 +269,7 @@ void Client::gameInit() #endif // defined(USE_OPENGL) updateEnv(); + SDL::allowScreenSaver(config.getBoolValue("allowscreensaver")); initGraphics(); #ifndef WIN32 diff --git a/src/progs/manaplus/client.cpp b/src/progs/manaplus/client.cpp index 33d099678..41afa2fe5 100644 --- a/src/progs/manaplus/client.cpp +++ b/src/progs/manaplus/client.cpp @@ -355,6 +355,7 @@ void Client::gameInit() Dirs::initScreenshotDir(); updateEnv(); + SDL::allowScreenSaver(config.getBoolValue("allowscreensaver")); dumpLibs(); dumpSizes(); diff --git a/src/utils/env.cpp b/src/utils/env.cpp index 0ffc9ce6b..e8808e238 100644 --- a/src/utils/env.cpp +++ b/src/utils/env.cpp @@ -35,11 +35,6 @@ void updateEnv() setEnv("SDL_VIDEO_CENTERED", "0"); #endif // defined(WIN32) || defined(__APPLE__) - if (config.getBoolValue("allowscreensaver")) - setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "1"); - else - setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "0"); - #ifndef WIN32 const int vsync = settings.options.test.empty() ? config.getIntValue("vsync") : 1; diff --git a/src/utils/sdl2helper.cpp b/src/utils/sdl2helper.cpp index 00893ce82..da86d2b41 100644 --- a/src/utils/sdl2helper.cpp +++ b/src/utils/sdl2helper.cpp @@ -31,6 +31,7 @@ PRAGMA48(GCC diagnostic push) PRAGMA48(GCC diagnostic ignored "-Wshadow") #include <SDL_events.h> +#include <SDL_hints.h> #include <SDL_syswm.h> PRAGMA48(GCC diagnostic pop) @@ -210,4 +211,18 @@ bool SDL::PollEvent(SDL_Event *event) SDL_LASTEVENT) > 0; } +void SDL::allowScreenSaver(const bool allow) +{ + if (allow) + { + SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); + SDL_EnableScreenSaver(); + } + else + { + SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "0"); + SDL_DisableScreenSaver(); + } +} + #endif // USE_SDL2 diff --git a/src/utils/sdl2helper.h b/src/utils/sdl2helper.h index 55d69a75d..4dbbad0f9 100644 --- a/src/utils/sdl2helper.h +++ b/src/utils/sdl2helper.h @@ -71,6 +71,8 @@ namespace SDL void WaitThread(SDL_Thread *const thread); bool PollEvent(SDL_Event *event); + + void allowScreenSaver(const bool allow); } // namespace SDL #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp index 85606f7f7..e30bdebaa 100644 --- a/src/utils/sdlhelper.cpp +++ b/src/utils/sdlhelper.cpp @@ -25,6 +25,7 @@ #include "logger.h" #include "utils/cast.h" +#include "utils/env.h" #include "utils/stringutils.h" #if defined(USE_X11) && defined(USE_OPENGL) @@ -205,4 +206,12 @@ bool SDL::PollEvent(SDL_Event *event) SDL_ALLEVENTS) > 0; } +void SDL::allowScreenSaver(const bool allow) +{ + if (allow) + setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "1"); + else + setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "0"); +} + #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.h b/src/utils/sdlhelper.h index d388fe7fb..f304036aa 100644 --- a/src/utils/sdlhelper.h +++ b/src/utils/sdlhelper.h @@ -77,6 +77,8 @@ namespace SDL void WaitThread(SDL_Thread *const thread); bool PollEvent(SDL_Event *event); + + void allowScreenSaver(const bool allow); } // namespace SDL #endif // USE_SDL2 |