• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Constraining a mouse cursor to a rect / window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Constraining a mouse cursor to a rect / window


  • Subject: Re: Constraining a mouse cursor to a rect / window
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 23 Jul 2013 12:30:07 -0500

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@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


References: 
 >Constraining a mouse cursor to a rect / window (From: Jorgen Tjerno <email@hidden>)

  • Prev by Date: Re: Non-sandboxed Cocoa app accessing current user preferences using NSTask fails when launched outside Xcode.
  • Next by Date: Re: custom fonts
  • Previous by thread: Constraining a mouse cursor to a rect / window
  • Next by thread: Re: Constraining a mouse cursor to a rect / window
  • Index(es):
    • Date
    • Thread