diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index b3a3a59764..ba2f1ba5a0 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -8,6 +8,7 @@ /** @file misc_cmd.cpp Some misc functions that are better fitted in other files, but never got moved there... */ #include "stdafx.h" +#include "openttd.h" #include "command_func.h" #include "economy_func.h" #include "window_func.h" @@ -22,6 +23,7 @@ #include "texteff.hpp" #include "core/backup_type.hpp" #include "misc_cmd.h" +#include "video/video_driver.hpp" #include "table/strings.h" @@ -204,6 +206,9 @@ CommandCost CmdPause(DoCommandFlags flags, PauseMode mode, bool pause) } NetworkHandlePauseChange(prev_mode, mode); + + /* Screensaver should always be inhibited unless we're paused. */ + VideoDriver::GetInstance()->SetScreensaverInhibited(_pause_mode.None()); } SetWindowDirty(WC_STATUS_BAR, 0); diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index e31afce540..0de7c8802c 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -754,3 +754,12 @@ void VideoDriver_SDL_Base::UnlockVideoBuffer() this->buffer_locked = false; } + +void VideoDriver_SDL_Base::SetScreensaverInhibited(bool inhibited) +{ + if (inhibited) { + SDL_DisableScreenSaver(); + } else { + SDL_EnableScreenSaver(); + } +} diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h index 08f657dee5..596498997a 100644 --- a/src/video/sdl2_v.h +++ b/src/video/sdl2_v.h @@ -43,6 +43,8 @@ public: std::string_view GetInfoString() const override { return this->driver_info; } + void SetScreensaverInhibited(bool inhibited) override; + protected: struct SDL_Window *sdl_window = nullptr; ///< Main SDL window. Palette local_palette{}; ///< Current palette to use for drawing. diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index 7aafcbdb3f..66df76dba2 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -186,6 +186,13 @@ public: void GameLoopPause(); + /** + * Prevents the system from going to sleep. + * + * @param inhibited If true, sleep will be disabled. If false, sleep will be enabled. + */ + virtual void SetScreensaverInhibited([[maybe_unused]] bool inhibited) {} + /** * Get the currently active instance of the video driver. */