Find the topmost window under a mouse cursor

Artem Ananiev artem.ananiev at oracle.com
Tue Mar 27 04:04:39 PDT 2012


On 3/27/2012 1:26 PM, Anthony Petrov wrote:
> Hi Alexander,
>
> I suggest to track the MouseIsOver state with a boolean flag per window,
> and send a synthetic Entered event upon receiving any other mouse event
> (Moved, Clicked, etc.) if the flag indicates we haven't yet sent an
> Entered event for this window. The flag should be set/reset in the
> Entered/Exited mouse handlers.

Alexander's question is exactly about how to implement such MouseIsOver 
flag. The problem is when a window is shown, even if its bounds include 
current mouse position, it may not be the window under cursor (e.g. if 
another always-on-top window is there, or the window is blocked by a 
modal dialog). So for every window size/location/visibility change we 
need to query for a window under cursor to generate Entered/Exited events.

Thanks,

Artem

> We use this approach in FX and everyone seems to be happy about that.
>
> --
> best regards,
> Anthony
>
> On 3/27/2012 12:08 PM, Alexander Scherbatiy wrote:
>>
>> Hello,
>>
>> Does the Mac OS X contains a method that allows to find the topmost
>> window under a mouse cursor?
>>
>> There is the issue when a window is created under a mouse cursor or it
>> is moved under a mouse cursor the system does not generate the
>> NSMouseEntered event.
>>
>> It is possible to synthetically generate the MouseEntered event for
>> window creation and moving in Java because we need that a window
>> behavior on Mac OS X was the same as on others platforms.
>> But it is necessary to have a way to know is this window the topmost
>> under a mouse cursor.
>>
>> Thanks,
>> Alexandr.
>>
>>
>>


More information about the macosx-port-dev mailing list