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 1836

Summary: Work around cocoa relative mouse jump on first event
Product: SDL Reporter: Kevin Shanahan <kmshanah>
Component: videoAssignee: (disabled) Jørgen Tjernø <jorgen>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 Keywords: target-2.0.0
Version: HG 2.0   
Hardware: All   
OS: Mac OS X (All)   
See Also: https://bugzilla.libsdl.org/show_bug.cgi?id=2867
Attachments: Simple workaround for cocoa relative mouse jump
Test case to reproduce

Description Kevin Shanahan 2013-05-03 01:07:34 UTC
Created attachment 1128 [details]
Simple workaround for cocoa relative mouse jump

Sent this to the mailing list a while ago:

After setting relative mouse mode on OS X, the first time the mouse is
moved a big delta is given (I guess some delta from the mouse position
at the time to the fixed point it then reports delta from).

In my case, an FPS with mouse controlling the view angle, this means
the view jumps to some crazy orientation the first time you touch the
mouse.

I tried working around it in various ways, but the only solution I
found that worked was to simply ignore the first event the comes in
after setting relative mouse mode.

Does the attached seem like a reasonable workaround?
Comment 1 Kevin Shanahan 2013-05-06 00:28:39 UTC
I noticed some recent activity in this area in hg, but just wanted to confirm that I still get a big relative mouse event the first time the mouse is touched after setting relative mode as of hg changeset: 7152:e9ed46195235
Comment 2 (disabled) Jørgen Tjernø 2013-06-04 18:09:25 UTC
This should be fixed at this point - I am unable to reproduce it. Test after http://hg.libsdl.org/SDL/rev/963d2ba35cfe and reopen this issue if it's still a problem.
Comment 3 Kevin Shanahan 2013-06-05 19:40:16 UTC
Still able to reproduce here with hg version 7279:f7805b13b485.

I'll try and write a simple test case for you.
Comment 4 Kevin Shanahan 2013-06-05 20:13:26 UTC
Okay, that was actually educational.

I couldn't reproduce with simply setting relative mouse mode, but have discovered the problem lies with setting a mouse grab.  When the mouse is grabbed, mouse motion is queued up but the event is not generated until the next time the mouse is moved.  This only seems to affect OSX - Windows and Linux don't have the same issue.
Comment 5 Kevin Shanahan 2013-06-05 20:14:25 UTC
Created attachment 1175 [details]
Test case to reproduce
Comment 6 Kevin Shanahan 2013-06-05 20:16:15 UTC
I also note that the cursor doesn't un-hide properly if you quit while the mouse is grabbed.  Should that be a separate bug?
Comment 7 Ryan C. Gordon 2013-07-12 22:15:47 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 2.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 8 (disabled) Jørgen Tjernø 2013-07-16 04:18:01 UTC
Kevin, are you still seeing the issue with the cursor not unhiding? That's not reproducing here, but I did fix some cursor hiding issues previously.
Comment 9 (disabled) Jørgen Tjernø 2013-07-16 04:18:29 UTC
And other than the "jump", does the grabbed mode behave like it does on Windows and Linux?
Comment 10 Kevin Shanahan 2013-07-21 21:55:27 UTC
I still see some problems, but definitely not every time (which is a bit frustrating!)

Most of the time the problem is reproducible with these steps:

* run ./test-relative-mouse
* hit space to grab the mouse
* hit q to quit the app

You may need to run the test several times to reproduce the problem.
I haven't been able to spot any pattern to the failures as yet.
Comment 11 Kevin Shanahan 2013-07-21 21:56:57 UTC
To answer the other question - yes, apart from the jump on first movement of the mouse, the grabbed mode appears to work the same on OS X as it does Windows and Linux.
Comment 12 Kevin Shanahan 2013-07-21 21:59:11 UTC
I should have mentioned, SDL framework compiled from tip 7497:109f37bca7cc for my comments 10 and 11.
Comment 13 (disabled) Jørgen Tjernø 2014-02-26 19:36:35 UTC
(In reply to Kevin Shanahan from comment #12)
> I should have mentioned, SDL framework compiled from tip 7497:109f37bca7cc
> for my comments 10 and 11.

Sorry for not looking at this again sooner, but it should be fixed in the upcoming 2.0.2. Would you be able to test the fix that I committed here? https://hg.libsdl.org/SDL/rev/841b66e4397a
Comment 14 Kevin Shanahan 2014-02-28 00:36:39 UTC
(In reply to Jørgen Tjernø from comment #13)
> Sorry for not looking at this again sooner, but it should be fixed in the
> upcoming 2.0.2. Would you be able to test the fix that I committed here?
> https://hg.libsdl.org/SDL/rev/841b66e4397a

Fix works well - no more jumps! Thanks :)

Cheers,
Kevin.
Comment 15 (disabled) Jørgen Tjernø 2014-02-28 00:37:41 UTC
Marking as FIXED with https://hg.libsdl.org/SDL/rev/841b66e4397a