[Scummvm-git-logs] scummvm master -> 38325bfb9467ca02bc3ad5c7f5ff793fb4be9f5f
Mataniko
mataniko at gmail.com
Sun May 10 04:35:41 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
38325bfb94 BACKENDS: Don't turn off screen when ScummVM is running a game
Commit: 38325bfb9467ca02bc3ad5c7f5ff793fb4be9f5f
https://github.com/scummvm/scummvm/commit/38325bfb9467ca02bc3ad5c7f5ff793fb4be9f5f
Author: mataniko (mataniko at gmail.com)
Date: 2020-05-10T00:35:29-04:00
Commit Message:
BACKENDS: Don't turn off screen when ScummVM is running a game
Changed paths:
backends/events/sdl/sdl-events.cpp
backends/events/sdl/sdl-events.h
backends/platform/sdl/sdl.cpp
common/events.h
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index f70f8c2ec8..11fcc9bded 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -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);
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 90454dad2e..136e56994f 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -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;
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 8ca6ae6e07..17ad54b5af 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -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() {
diff --git a/common/events.h b/common/events.h
index 2045e56a0c..55cfdd190e 100644
--- a/common/events.h
+++ b/common/events.h
@@ -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;
More information about the Scummvm-git-logs
mailing list