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:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user