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 2718 - [OS X 10.9] Cmd+Tab app switching breaks out of relative mouse mode
Summary: [OS X 10.9] Cmd+Tab app switching breaks out of relative mouse mode
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: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.4, triage-2.0.4
Depends on:
Blocks:
 
Reported: 2014-09-05 01:22 UTC by Eric Wasylishen
Modified: 2015-05-26 15:49 UTC (History)
2 users (show)

See Also:


Attachments
Proposed fix (841 bytes, patch)
2015-01-24 02:34 UTC, Eric Wasylishen
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Wasylishen 2014-09-05 01:22:59 UTC
Steps to reproduce:

- launch testdraw2 or testgl2 with the default settings (windowed mode)
- press Ctrl+R to enter relative mouse mode. The cursor hides and is locked inside the sdl window.
- switch to another app with command+tab. The cursor reappears and you can use the second application normally.
- switch back to the SDL test app with command+tab

- expected: the cursor re-hides and is locked inside the SDL windows since relative mouse mode is still enabled.
- actual: the cursor re-hides, but if you move the cursor you can move it out of the window and it re-appears - Relative mouse mode is broken. If you press Ctrl+R twice (once to disable, once to re-enable), relative mouse mode works again as expected.

I guess SDL needs to detect when a window regains focus and reacquire its grab on the mouse if needed?

Tested on sdl2 hg cd6696d55781 (Sept 2, 2014), on 15" macbook pro retina (2880x1800), OS X 10.9.4
Comment 1 Eric Wasylishen 2015-01-24 02:17:01 UTC
Still happening with OS X 10.10.1, SDL2 HG as of today (8d826bc39a45).

The same bug also affects SDL_WINDOW_FULLSCREEN_DESKTOP windows; if you switch to a different desktop Space using Control+Left/Right, or using Mission Control, and then return to the SDL fullscreen desktop space, the relative mouse mode is messed up (the cursor isn't really grabbed, so you stop getting relative mouse events when the cursor reaches the edge of the screen.) This can be seen using the "testrelative" sammple, and going into fullscreen-desktop mode with Alt+Enter.
Comment 2 Eric Wasylishen 2015-01-24 02:34:55 UTC
Created attachment 2001 [details]
Proposed fix

Ok, I think I have a fix.. 
In the -windowDidBecomeKey: method in SDL_cocoawindow.m, there was a call to mouse->SetRelativeMouseMode to restore relative mouse mode. But that was bailing out and not doing anything on SDL_cocoamouse.m:244, because SDL_GetMouseFocus() was returning NULL.

I moved the SDL_SetKeyboardFocus() call in -windowDidBecomeKey: to before the SetRelativeMouseMode() call, and this seemed to fix the issue.
Comment 3 Eric Wasylishen 2015-01-31 03:18:42 UTC
In addition to testing on 10.10, I just tried OS X 10.6, and my fix works there as well (the bug also affected 10.6).
Comment 4 Martijn Courteaux 2015-02-05 23:03:48 UTC
Thanks for this fix. It works for me as well! I'm on OS X 10.10.2. I'm not an SDL expert, but I think it's safe to merge this patch in the main source.
Comment 5 Ryan C. Gordon 2015-02-19 05:22:18 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 6 Ryan C. Gordon 2015-04-07 04:57:57 UTC
(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.
Comment 7 Ryan C. Gordon 2015-05-26 15:49:58 UTC
Your patch is now https://hg.libsdl.org/SDL/rev/065e4ddc8753, thanks!

--ryan.