Re: Determine current mouse cursor position
Re: Determine current mouse cursor position
- Subject: Re: Determine current mouse cursor position
- From: Quincey Morris <email@hidden>
- Date: Sun, 31 Oct 2010 10:21:35 -0700
On Oct 31, 2010, at 09:16, eveningnick eveningnick wrote:
> I need to implement a functionality like Microsoft Word does for popup
> windows - display a semi transparent popup window with the alpha value
> calculated by the distance from the mouse cursor to the edge of the window.
> It is a requirement for me, not just a decoration to look in a neat mac
> style :)
>
> How can it be done? Is it possible to do that without installing a system
> wide even tap that watches mouse movements (i believe such a tap can
> decrease the overall system performance)?
If you want the *current* mouse location at the time you decide to display the window, use +[NSEvent mouseLocation] or -[NSWindow mouseLocationOutsideOfEventStream].
However, it's more than possible that you should be using the mouse location *synchronized with the application's event stream*. AFAIK there's no way to do that directly, or 100% reliably. The best way I know of is to monitor the mouse location in every mouse event as your application processes it. In 10.6, you can use +[addLocalMonitorForEventsMatchingMask:handler:] to do this. In 10.5, you have to subclass NSApplication and override 'sendEvent:'. In both cases, you won't see any events consumed by modal event loops -- at least, those consumed in frameworks -- but it doesn't sound like this would matter for you.
Why would you want to do the second (harder) thing? Consider what would happen, assuming for example that the window pops up where you right click, if the mouse is moving fast away from the window. If there's a slight delay between the click and the display of the window, the mouse might have already moved a long way from the click site before the window position is calculated.
_______________________________________________
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