aboutsummaryrefslogtreecommitdiff
path: root/backends/events/sdl
diff options
context:
space:
mode:
authorColin Snover2017-09-15 22:59:18 -0500
committerColin Snover2017-10-15 13:24:21 -0500
commitd1b77d4b68fbf1129fd84a8d411d1c12d57ba0ee (patch)
tree68c823dc0f1d81fb66234046aaced65514acbe2d /backends/events/sdl
parentcd538ffffab9e49443da4ee043916d8dc22c3c07 (diff)
downloadscummvm-rg350-d1b77d4b68fbf1129fd84a8d411d1c12d57ba0ee.tar.gz
scummvm-rg350-d1b77d4b68fbf1129fd84a8d411d1c12d57ba0ee.tar.bz2
scummvm-rg350-d1b77d4b68fbf1129fd84a8d411d1c12d57ba0ee.zip
BACKENDS: Fix missing mouse events when system cursor cannot be moved
Normally with SDL, a mouse motion event will be sent after the system mouse cursor has been moved by a call to SDL_WarpMouseInWindow, but if the system cursor cannot be moved (e.g. because the window does not have mouse focus), games still need to receive these mouse events so they can successfully update the mouse position internally. Otherwise, games continue to think the mouse is still in the original position and will continue to try to perform whatever action is associated with that mouse position. Refs Trac#9689.
Diffstat (limited to 'backends/events/sdl')
-rw-r--r--backends/events/sdl/sdl-events.cpp14
-rw-r--r--backends/events/sdl/sdl-events.h18
2 files changed, 31 insertions, 1 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 6f34420674..91ca0f5df6 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -75,7 +75,7 @@ static uint32 convUTF8ToUTF32(const char *src) {
#endif
SdlEventSource::SdlEventSource()
- : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0)
+ : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false)
#if SDL_VERSION_ATLEAST(2, 0, 0)
, _queuedFakeKeyUp(false), _fakeKeyUp()
#endif
@@ -508,6 +508,12 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
return true;
}
+ if (_queuedFakeMouseMove) {
+ event = _fakeMouseMove;
+ _queuedFakeMouseMove = false;
+ return true;
+ }
+
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
preprocessEvents(&ev);
@@ -1003,6 +1009,12 @@ void SdlEventSource::resetKeyboardEmulation(int16 x_max, int16 y_max) {
_km.joy_y = 0;
}
+void SdlEventSource::fakeWarpMouse(const int x, const int y) {
+ _queuedFakeMouseMove = true;
+ _fakeMouseMove.type = Common::EVENT_MOUSEMOVE;
+ _fakeMouseMove.mouse = Common::Point(x, y);
+}
+
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 1d701f5ecf..5fd3cb7ea5 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -51,6 +51,12 @@ public:
*/
virtual void resetKeyboardEmulation(int16 x_max, int16 y_max);
+ /**
+ * Emulates a mouse movement that would normally be caused by a mouse warp
+ * of the system mouse.
+ */
+ void fakeWarpMouse(const int x, const int y);
+
protected:
/** @name Keyboard mouse emulation
* Disabled by fingolfin 2004-12-18.
@@ -156,6 +162,18 @@ protected:
*/
SDLKey obtainKeycode(const SDL_keysym keySym);
+ /**
+ * Whether _fakeMouseMove contains an event we need to send.
+ */
+ bool _queuedFakeMouseMove;
+
+ /**
+ * A fake mouse motion event sent when the graphics manager is told to warp
+ * the mouse but the system mouse is unable to be warped (e.g. because the
+ * window is not focused).
+ */
+ Common::Event _fakeMouseMove;
+
#if SDL_VERSION_ATLEAST(2, 0, 0)
/**
* Whether _fakeKeyUp contains an event we need to send.