LaurentGomila/SFML — pull request #614 by mantognini (2014-05-25 22:57:38+00:00)
Title: Feature/grab mouse

Related to #394.

Adds `sf::Window::setCursorGrabbed` implementations for Linux, Windows and Mac OS X. Android and iOS devices have a «not applicable» implementation.

**Requires testing on:**
- Linux
- Windows
- iOS (build check only)
- Android (build check only)

Here are a few scenarios to be tested:

1. Grabbing the cursor works when the window has the focus.
2. When grabbed, the cursor should not be able to leave the window.
3. Closing the window should release the cursor.
4. When grabbed, the window should not be resizable by dragging one of its sides.
5. When switching to another app, the cursor should be released and re-grabbed when reactivating the SFML app.
6. If the cursor is outside the view when it is grabbed the cursor should be projected into the window (and thus generate a mouse in event).
7. The user should not be able to move fast the cursor and click outside the window to activate another application.
8. The user should not be able to use the window bar to move, minimize, maximize or close the window.

[This code](https://gist.github.com/mantognini/20226256cbac2b138db0) can be usefull for testing.

**Regarding OS X:**
The current impl is not bad but still an approximation of the feature (test n° 7 is somewhat supported and n° 8 is not supported at all) . It seems really hard to do it on Mac. Other libs (e.g. SDL) have even more bugs or undesired behaviour than this implementation. However, a lot of tricks are used which is not nice at all for future modifications of `SFOpenGLView` (among other things).

Commit d16d38e contains a more detailed explanation of the known issues (in commit message and comments in the code itself). I'm reluctant to include this commit in SFML codebase because it will considerably increase the complexity of the code and make it really hard to maintain. All that to "only" workaround a stupid corner case... Please let me know what you think.

An alternative for games that need grabbing would be to hide the cursor and use relative motion, preventing the cursor to actually move. This would involve much less corner case for the implementations. Actually, SDL also provides this alternative.