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 1094

Summary: SDL_SetRelativeMouseMode AND SDL_WarpMouseInWindow do not work on MacOS X
Product: SDL Reporter: Vern Jensen <vern>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: Mac OS X 10.6   

Description Vern Jensen 2011-01-19 11:53:58 UTC
SDL_SetRelativeMouseMode and SDL_WarpMouseInWindow both fail to have any effect on MacOS X (10.6.6). I have not tested them on Windows or iOS.

Having these broken makes it impossible to get mouse motion events that go across the entire screen, as the events stop as soon as the mouse moves outside the window, and there is no way to keep it inside the window. This severely hampers mouse-based games unless they go fullscreen.

-Vern
Comment 1 Vern Jensen 2011-01-19 23:05:45 UTC
By the way, I'm not sure exactly what version I have from the SVN. It's possible it's a checkout from about 6 months ago.
Comment 2 Sam Lantinga 2011-01-19 23:11:05 UTC
It's still not implemented, and pretty high on my TODO list.  Unfortunately it'll take a few days to fix.
Comment 3 Vern Jensen 2011-01-20 00:21:21 UTC
No worries. Great to hear it's going to get implemented!
Comment 4 Sam Lantinga 2011-02-21 22:54:26 UTC
These should work in the latest snapshot, can you take a look?
http://www.libsdl.org/tmp/SDL-1.3.zip

Thanks!
Comment 5 Vern Jensen 2011-02-23 13:45:38 UTC
They aren't working as described in the documentation I'm afraid. According to the docs:

"While the mouse is in relative mode, the cursor is hidden, and the driver will try to report continuous motion in the current window. Only relative motion events will be delivered, the mouse position will not change."

But in my program, even when relative mouse mode is activated, the cursor's location *is* still affected by the mouse's movement. I know, because as soon as the mouse is moved outside the window, I stop getting mouse-moved events, even with relative mode activated.
Comment 6 Vern Jensen 2011-02-23 13:48:46 UTC
Also, not sure if this is a bug, but setting the relative mouse mode to true hides the cursor, but setting it to false doesn't show it again. It is still hidden.
Comment 7 Vern Jensen 2011-02-23 14:12:14 UTC
Since SDL_SetRelativeMouseMode isn't working for me, I tried testing SDL_WarpMouseInWindow to see if I could simulate the ssame behavior on my own. In other words, after each mouse-motion event, I re-center the mouse in the window myself.

This doesn't really work though, mainly because of problem B below. But I'm wondering if problem A is solvable too?  If not, this function will have pretty limited use.

A) The event system is much slower if I call SDL_WarpMouseImWindow in response to every mouse motion event, to "re-center" the cursor. Instead of a smooth stream of mouse motion events -- one instantly appearing for each mouse movement -- they come much slower and choppy -- I'd say about two events every second, at most. Unless this can be fixed, I can't use this technique to simulate SDL_SetRelativeMouseMode.


B) The second problem is that SDL_WarpMouseInWindow generates a mouse motion event -- an event that "undoes" the motion previously captured from the user's movement of the mouse. This results in the thing I'm trying to control with the mouse moving in the direction the user moved it, then instantly jerking back to its former position. 

For instance, if the former location of the mouse was 400,400 and I use SDL_WarpMouseInWindow to move it to 200,200, I get a "mouse motion" event of -200,-200. 

I tried adding code to flush all mouse motion events, right after calling SDL_WarpMouseInWindow, but for some reason this isn't working. I am calling:

	SDL_WarpMouseInWindow(myWindow, 200, 200);
	SDL_FlushEvents( SDL_MOUSEMOTIONMASK );

and yet I still get a mouse motion event in response to the SDL_WarpMouseInWindow call.
Comment 8 Sam Lantinga 2011-02-23 15:10:46 UTC
Whoops sorry, I meant to say SDL_WarpMouseInWindow() is implemented.  SDL_SetRelativeMouseMode() isn't done yet.
Comment 9 Sam Lantinga 2011-02-27 22:08:27 UTC
SDL_SetRelativeMouseMode() is implemented in this revision:
http://hg.libsdl.org/SDL/rev/1517da4ab6b1