BACKENDS: Don't turn off screen when ScummVM is running a game

This commit is contained in:
mataniko 2020-05-10 00:35:29 -04:00
parent dbf404b786
commit 38325bfb94
4 changed files with 44 additions and 7 deletions

View File

@ -61,7 +61,7 @@ void SdlEventSource::loadGameControllerMappingFile() {
Common::FSNode file = Common::FSNode(ConfMan.get("controller_map_db"));
if (file.exists()) {
if (SDL_GameControllerAddMappingsFromFile(file.getPath().c_str()) < 0)
error("File %s not valid: %s", file.getPath().c_str(), SDL_GetError());
error("File %s not valid: %s", file.getPath().c_str(), SDL_GetError());
else {
loaded = true;
debug("Game controller DB file loaded: %s", file.getPath().c_str());
@ -74,7 +74,7 @@ void SdlEventSource::loadGameControllerMappingFile() {
Common::FSNode file = dir.getChild(GAMECONTROLLERDB_FILE);
if (file.exists()) {
if (SDL_GameControllerAddMappingsFromFile(file.getPath().c_str()) < 0)
error("File %s not valid: %s", file.getPath().c_str(), SDL_GetError());
error("File %s not valid: %s", file.getPath().c_str(), SDL_GetError());
else
debug("Game controller DB file loaded: %s", file.getPath().c_str());
}
@ -84,7 +84,7 @@ void SdlEventSource::loadGameControllerMappingFile() {
SdlEventSource::SdlEventSource()
: EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false),
_lastHatPosition(SDL_HAT_CENTERED), _mouseX(0), _mouseY(0)
_lastHatPosition(SDL_HAT_CENTERED), _mouseX(0), _mouseY(0), _engineRunning(false)
#if SDL_VERSION_ATLEAST(2, 0, 0)
, _queuedFakeKeyUp(false), _fakeKeyUp(), _controller(nullptr)
#endif
@ -522,6 +522,25 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
//case SDL_WINDOWEVENT_RESIZED:
return handleResizeEvent(event, ev.window.data1, ev.window.data2);
case SDL_WINDOWEVENT_FOCUS_GAINED: {
// When we gain focus, we to update whether the display can turn off
// dependingif a game isn't running or not
event.type = Common::EVENT_FOCUS_GAINED;
if (_engineRunning) {
SDL_DisableScreenSaver();
} else {
SDL_EnableScreenSaver();
}
return true;
}
case SDL_WINDOWEVENT_FOCUS_LOST: {
// Always allow the display to turn off if ScummVM is out of focus
event.type = Common::EVENT_FOCUS_LOST;
SDL_EnableScreenSaver();
return true;
}
default:
return false;
}
@ -931,6 +950,10 @@ bool SdlEventSource::isJoystickConnected() const {
;
}
void SdlEventSource::setEngineRunning(const bool value) {
_engineRunning = value;
}
bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
if (_graphicsManager) {
_graphicsManager->notifyResize(w, h);

View File

@ -59,10 +59,15 @@ public:
/** Returns whether a joystick is currently connected */
bool isJoystickConnected() const;
/** Sets whether a game is currently running */
void setEngineRunning(bool value);
protected:
/** Scroll lock state - since SDL doesn't track it */
bool _scrollLock;
bool _engineRunning;
int _mouseX;
int _mouseY;

View File

@ -145,14 +145,14 @@ void OSystem_SDL::init() {
#if !SDL_VERSION_ATLEAST(2, 0, 0)
// Enable unicode support if possible
SDL_EnableUNICODE(1);
// Allow the screen to turn off
SDL_EnableScreenSaver();
#endif
// Disable OS cursor
SDL_ShowCursor(SDL_DISABLE);
// Allow the screen to turn off
SDL_EnableScreenSaver();
// Creates the early needed managers, if they don't exist yet
// (we check for this to allow subclasses to provide their own).
if (_mutexManager == 0)
@ -300,6 +300,8 @@ void OSystem_SDL::initBackend() {
void OSystem_SDL::engineInit() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
// Disable screen saver when engine starts
SDL_DisableScreenSaver();
#endif
#ifdef USE_TASKBAR
// Add the started engine to the list of recent tasks
@ -308,16 +310,19 @@ void OSystem_SDL::engineInit() {
// Set the overlay icon the current running engine
_taskbarManager->setOverlayIcon(ConfMan.getActiveDomainName(), ConfMan.get("description"));
#endif
_eventSource->setEngineRunning(true);
}
void OSystem_SDL::engineDone() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
SDL_EnableScreenSaver();
#endif
#ifdef USE_TASKBAR
// Remove overlay icon
_taskbarManager->setOverlayIcon("", "");
#endif
_eventSource->setEngineRunning(false);
}
void OSystem_SDL::initSDL() {

View File

@ -108,7 +108,11 @@ enum EventType {
EVENT_X1BUTTONDOWN = 30,
EVENT_X1BUTTONUP = 31,
EVENT_X2BUTTONDOWN = 32,
EVENT_X2BUTTONUP = 33
EVENT_X2BUTTONUP = 33,
/** ScummVM has gained or lost focus */
EVENT_FOCUS_GAINED = 36,
EVENT_FOCUS_LOST = 37
};
const int16 JOYAXIS_MIN = -32768;