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 1406 - Mouse jumps after warp
Summary: Mouse jumps after warp
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86 Mac OS X (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-29 21:57 UTC by Frank Becker
Modified: 2014-08-17 23:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Becker 2012-01-29 21:57:40 UTC
At program start I'm warping the mouse to center (after which I'm eating all events). However, the next time the mouse is moved the warped distance (from where the mouse was before the warp) is included in the move delta. This results in the mouse cursor jumping.

Also according to the docs SDL_WarpMouseInWindow generates a mouse motion event, which it doesn't on the mac.

CGWarpMouseCursorPosition doesn't generate events.

The patch below generates a motion event manually after a warp.

Having typed all this, I should probably be using SDL_SetRelativeMouseMode ...

--- a/src/video/cocoa/SDL_cocoamouse.m	Sat Jan 28 14:53:23 2012 -0500
+++ b/src/video/cocoa/SDL_cocoamouse.m	Sun Jan 29 21:55:18 2012 -0800
@@ -116,6 +116,12 @@
     point.x = (float)window->x + x;
     point.y = (float)window->y + y;
     CGWarpMouseCursorPosition(point);
+
+    /* CGWarpMouseCursorPosition doesn't create an event, so generate a move event manually */
+    /* If we don't do this, the warp will be included in the next motion event, which causes the mouse to jump */
+    CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, point, kCGMouseButtonLeft);
+    CGEventPost(kCGHIDEventTap, event);
+    CFRelease(event);
 }
 
 static int
Comment 1 Robotic-Brain 2014-08-17 23:09:50 UTC
I'm closing this since the bug is quite old and doesn't seem to be true anymore
Comment 2 Sam Lantinga 2014-08-17 23:35:25 UTC
This is fixed in the current SDL 2.0.3 release.