DialogWindow lanuchAsync and mouseEvents outside the window

I have a DialogWindow that holds my component (a coulour selector with a button), i launch the DialogWindow using launchAsync() (as suggested in the manual), i'd like to dismiss the window when a mouse click occurs outside the shown window, i can't register Desktop::getInstance().addGlobalMouseListener(this); in my component (it does not receive any mouse events) so i don't know when to exitModalState() within the component.

What is the correct way to achieve this behavior ?


Component::inputAttemptWhenModal()   ?


Well i tried that, witch component should have that callback implemented ? Alo i can't assume that the click outside the modal window will occur on ANY of my components, it might occur on the desktop or on some other application. I just need to know it occured.

Well i spent a lot of time today on that and got no solutions. Is that even possible ? How does the PopupMenu do it ? do i need to pass some special flags to the Window to receive mouse events outside it's boundries ?

The PopupMenu uses inputAttemptWhenModal, but if you can't make it modal, you could probably do it by using a FocusChangeListener and a timer that checks Process::isForegroundProcess to see whether another app has been selected.