RE: Constraining a mouse cursor to a rect / window
RE: Constraining a mouse cursor to a rect / window
- Subject: RE: Constraining a mouse cursor to a rect / window
- From: Jorgen Tjerno <email@hidden>
- Date: Wed, 24 Jul 2013 01:09:37 +0000
- Thread-topic: Constraining a mouse cursor to a rect / window
Thanks for your responses, Seth & Ken.
Ken: I don't think we can use LGPL code in SDL2, as the license for v2 is MIT. Have you measured to see if using CGAssociateMouseAndMouseCursorPosition and CGWarpMouseCursorPosition incurs any latency on cursor movements? Our customers are very .. sensitive to mouse behavior. ;-)
Seth: Your approach works well for certain types of games (like FPS games), and that's what we use for those titles. It's not as robust when it comes to use cases like RTS games or visualizations that have UI. You want a responsive mouse cursor that behaves like normal, but the user should be able to use the window's edge as a boundary, e.g. to indicate that the game should scroll to the right. If we render our own cursor, I'm guessing there'll be 1-3 frames of latency on the cursor's movement relative to the mouse's movement (depending on how much buffering is done).
I implemented a way of constraining the mouse cursor using CGEventTaps. This approach is sadly not compatible with sandboxing (since CGEventTapCreate is a sandbox violation, even when you insert into kCGSessionEventTap (which doesn't require root or accessibility, AFAICT)), but otherwise seems to be pretty robust. If the cursor attempts to move outside the window, I use CGWarpMouseCursorPosition to move it back. I also keep the event tap in a separate thread, so that it's disconnected from the update rate of the main loop.
Updating the returned CGEventRef doesn't seem to have any impact on where the windowserver thinks the cursor is, nor does generating your own kCGEventMouseMoved and posting them to any location.
Here's the code (MIT licensed): https://gist.github.com/jorgenpt/6067362
For now, it'll be enabled using a compile-time flag in SDL2.
Any thoughts on problems or shortcomings?
- Jørgen.
________________________________________
From: Seth Willits [email@hidden]
Sent: Tuesday, July 23, 2013 12:02 PM
To: Jorgen Tjerno
Cc: email@hidden dev
Subject: Re: Constraining a mouse cursor to a rect / window
On Jul 22, 2013, at 2: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?
See my reply to your "Disabling Hot Corners" thread.
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden