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 1841

Summary: Mac: buggy mouse click behaviour at edges of window with Window Grabbing enabled
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: videoAssignee: (disabled) Jørgen Tjernø <jorgen>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: jorgen
Version: HG 2.0   
Hardware: x86   
OS: Other   
Attachments: Test code demonstrating the issue

Description Alex Szpakowski 2013-05-07 21:16:37 UTC
Created attachment 1132 [details]
Test code demonstrating the issue

When window grabbing is enabled, the expected mouse behaviour when at the edges of the window is that all button input will be contained to the window and the SDL2 app.
However it seems that it's possible on Mac OS X for a mouse click to be registered outside the window bounds (bringing another window or program into the user's focus) when window grabbing is enabled, if the mouse position is at the edge of the window, the user is moving it away from the window, and there's at least some delay between SDL event polling calls. The chance of this accidental behaviour increases as the delay between SDL_PollEvent function calls increases.

I have attached code for a test program to demonstrate the issue: apply continuous mouse motion in one direction while clicking a mouse button.

The test code also demonstrates a related problem that's likely caused by the same issue; if a custom cursor is set, window grabbing is enabled, and the user applies enough mouse motion in the direction of the dock, the system will seem to notice that the dock has been highlighted and the cursor will become set back to the default one until the user alt-tabs out of the SDL app and back in.
Comment 1 (disabled) Jørgen Tjernø 2013-05-08 13:55:02 UTC
After investigating, this is not a regression - same bug exists in SDL1.2, and the cause is that we just warp the cursor into the window on mouse move events if the cursor is outside the window. When you don't poll the event loop often enough, it can manage to escape for a short period of time.

AFAIK there doesn't seem to be a good fix for Cocoa. 

This is a patch for winemac that's for a similar issue: http://markmail.org/thread/ldpujp7gok26rqj6

Not really sure we want to do all that, unless the event tap is executed separately from the main loop.
Comment 2 Sam Lantinga 2013-05-22 01:11:32 UTC
Please reopen this bug if someone finds a good fix.