Children components in component added to desktop don't respond to mouseEnter and mouseExit in Mac

I made a pop-up window component that can be automatically hide when clicking outside it. However, when I use it in Mac, its children won’t respond to mouseEnter and mouseExit events, thus all mouse hovering logics not work. But if I made a click on this pop-up window, its children will work properly with mouse enter/leave.

This issue is Mac-specific, it works well in Windows.

The code below is how this component is created and shown:

PopUpWindow::PopUpWindow()
{
    setOpaque( false );
    setAlwaysOnTop(true);
}

void PopUpWindow::show()
{
    if ( !isOnDesktop() )
        addToDesktop( juce::ComponentPeer::StyleFlags::windowIsSemiTransparent );
    setVisible( true );
    broughtToFront();
    juce::Desktop::getInstance().addGlobalMouseListener( this );
}

It appears that on macOS the mouseEnter and mouseExit events can be triggered for Components only if the window they’re in is the one that currently has focus.

See this reply by Ed on similar topic:

1 Like

I don’t think this is a restriction of the OS though, XCode, Firefox and a few other apss I’ve just tested have widgets that show hover states even without having focus.

It looks like something has been done about this topic with the following commit: NSViewComponentPeer: Allow mouse events to reach unfocused windows · juce-framework/JUCE@4ca923a · GitHub

1 Like

Yep, thanks for updating this thread. I’ve updated the mouse handling in the NSViewComponentPeer so that it should behave a bit more like the mouse handling on Windows and Linux, so that mouse events will still reach unfocused windows.

1 Like