On Jul 22, 2013, at 4:42 PM, Jorgen Tjerno wrote: > Is there an API that allows an application to constrain a mouse cursor's > movement to a window or a rect?
Only for a specific special case: a 1x1 rect. You can disassociate the mouse from the cursor using CGAssociateMouseAndMouseCursorPosition(false). After that, you receive mouse move events whose absolute position is unchanging but which have valid delta values. > The use case for this is in SDL2, where windows created with > SDL_FULLSCREEN_DESKTOP create desktop-sized, borderless windows that are > topmost, similar to a fullscreen application (but without a mode change and > allowing quick Cmd-Tab etc). This works great, but on multi-monitor setups, > the mouse can be moved out of the window onto the other desktop. > > The current workaround is using CGWarpMouseCursorPosition to move the cursor > back if it leaves the window, but depending on the update rate of the > application, a user can still have a mouse click be delivered to another > application or the desktop, causing a focus loss. Not a great experience. If LGPLv2 code is safe for you, you can check out my implementation of the Win32 ClipCursor() function in Wine's Mac driver. It ain't pretty, though, because I want the cursor to still move (in keeping with the semantics of that function) so I warp it manually in response to the delta-only events I get. But the warp distance is then included in the next event's deltas, so I have to remember it and cancel it out. http://source.winehq.org/source/dlls/winemac.drv/cocoa_app.m#L928 Regards, Ken _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
