We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 956 - DIB_GenerateMouseMotionEvent generates erroneous mouse motion events
Summary: DIB_GenerateMouseMotionEvent generates erroneous mouse motion events
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 1.2.14
Hardware: All Windows 7
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-20 12:46 UTC by maf6
Modified: 2011-03-07 14:12 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description maf6 2010-02-20 12:46:13 UTC
This occurs when the openmsx emulator is running full screen and the user reverts to the desktop by hitting Win+D.

In this case, the screen size reverts to the original size (in my case, 1920x1200) instead of 1024x768.  However, in this scenario, the SDL window is now off-screen, and Windows returns some rather odd values for the physical position of the middle of the window (e.g. center.x = -31520, center.y = -31640).

Long story short, we created an SDL patch for openmsx builds that causes DIB_GenerateMouseMotionEvent to only post a new event if (after calling SetCursorPos) the cursor's position actually changed from the original position (in the scenario I describe, it actually doesn't:  it was 0,0 before and it remains 0,0 after calling SetCursorPos).

In other words:

diff -ru SDL-1.2.14.org/src/video/windib/SDL_dibevents.c SDL-1.2.14/src/video/windib/SDL_dibevents.c
--- SDL-1.2.14.org/src/video/windib/SDL_dibevents.c	Mon Feb 15 11:49:09 2010
+++ SDL-1.2.14/src/video/windib/SDL_dibevents.c	Mon Feb 15 11:51:15 2010
@@ -328,12 +328,13 @@
 	extern int mouse_relative;
 	extern int posted;
 
-	POINT mouse;
+	POINT mouse, originalMouse;
 #ifdef _WIN32_WCE
 	if ( !GetCursorPos(&mouse) && !GetLastStylusPos(&mouse) ) return;
 #else
 	if ( !GetCursorPos(&mouse) ) return;
 #endif
+	originalMouse = mouse;
 
 	if ( mouse_relative ) {
 		POINT center;
@@ -345,7 +346,11 @@
 		mouse.y -= center.y;
 		if ( mouse.x || mouse.y ) {
 			SetCursorPos(center.x, center.y);
-			posted = SDL_PrivateMouseMotion(0, 1, (Sint16)mouse.x, (Sint16)mouse.y);
+			GetCursorPos(&mouse);
+			// Make sure the mouse position actually changed
+			if (mouse.x != originalMouse.x || mouse.y != originalMouse.y) {
+				posted = SDL_PrivateMouseMotion(0, 1, (Sint16)mouse.x, (Sint16)mouse.y);
+			}
 		}
 	} else {
 		ScreenToClient(SDL_Window, &mouse);
Comment 1 Sam Lantinga 2011-03-07 14:12:09 UTC
I believe this is fixed by the patch mentioned in bug 1158.