focusLost() behaves differently on Mac?

I am closing an about dialog when the user clicks out of the dialog. I have a focusLost() method in the dialog content component and I delete the parent dialog when focus is lost.

In Windows it works when I click another app or the main application window. On Mac it works if I click another app but if I click the main application the about dialog just goes to the background since focusLost() is not called.

Any idea why?

Ok, I’ll look into that. Focus on the mac is a bit more messy than on windows.

One thing: did you check that your window actually gets focus in the first place? If you haven’t used Comonent::setWantsKeyboardFocus() then it would be windows that was wrong in sending the focusLost message.

I did ask for focus and even added grab focus but it didn’t help. Anyway I won’t wait for this fix since it was a hack to simulate a modal about dialog that closes when host closes plug but I will change it to integrate the about in the main window like you did with the meter plug…


I’ve modified handleBoundsEvent() in juce_mac_Windowing.cpp thusly, to ensure that modal windows get the focus in this situation:

[code] else if (what == kEventWindowFocusAcquired)
lastFocusedWindow = ownerWindow;

    // make sure this hasn't come in front of a modal window
	Component* const winComp = ownerWindow->getComponent();

	if (winComp)
		Component* const cm = winComp->getCurrentlyModalComponent();

		if (cm != 0 && cm->getTopLevelComponent() != winComp->getTopLevelComponent())


Perhaps this will work for you.

Hey Randy, you’re getting the fixes out faster than me! Thanks for the minimisation tips too - I didn’t see that post when you first made it. I’ll definitely get all this stuff incorporated for the next build.

Hi Randy, I bypassed the focus problem but need the other thing so I guess I will wait for the next JUCE version. Good to see people with Mac knowledge around here since most people here develop on Windows only.


I was just looking at the focus thing, but it seems to behave correctly in my test app…

All I can think is that there’s nothing actually focused when you’re clicking on the other window - if you’re still interested in this, try a breakpoint in NativeDesktopWindow::handleFocusLoss() and see what happens. I think this may get called correctly, but not pass the message on because it doesn’t find a focused component within it to give the message to.

Also, a good workaround might be to make the about box modal and use the inputAttemptWhenModal() callback to tell you when to get rid of it.

I didn’t investigate much, it was just code that worked ok in Windows but not on the Mac. Anyway since its not a good idea to have dialog in VSTs I just put the about in another tab and bypassed the problem. I guess it will not be a big issue for anybody else.