1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-27 14:14:27 +01:00

Fix #12937: Allow the computer to go to sleep while the game is paused

This commit is contained in:
Max
2025-12-20 17:54:42 -06:00
committed by rubidium42
parent 07353973a1
commit c918a29e49
4 changed files with 23 additions and 0 deletions

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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.

View File

@@ -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.
*/