It seems that setUsingNativeTitleBar(true); breaks window activation on Mac. If I don’t use native bar, isActiveWindow property is updated correctly and activeWindowStatusChanged method is called. When using native bar, I don’t receive these updates when clicking on title bar. Clicking on the form body updates its active state correctly.
Is it designed behavior? If yes, what’s the best approach to get the same behavior as with not-native bar?
Juce version is 2.0.27 (pulled from git 10 minutes ago). Mac is 10.8. I’ve not tested it on Windows yet.
Reinstalling your OS just to see whether that’s the reason seems a bit… hardcore. Maybe easier just to have a go at tracing the code and see what’s happening?
No, I have Parallels on my machine:)
I’m perfectly new to JUCE and thus it’s easier for me to set a breakpoint on two machines and compare stack traces to find out what’s happening.
Here is what happens on 10.8:
Inside Component::takeKeyboardFocus method peer->grabFocus () doesn’t make the window key window. So, this condition is never true and activeWindowStatusChanged method isn’t called:
Immediately after this the program receives a NSViewComponentPeer:becomeKeyWindow selector call. It calls grabFocus and the window indeed become key window.
Probably, we should also call
// call this after setting currentlyFocusedComponent so that the one that’s
// losing it has a chance to see where focus is going
if (componentLosingFocus != nullptr)
componentLosingFocus->internalFocusLoss (cause);
if (currentlyFocusedComponent == this)
internalFocusGain (cause, safePointer);[/code]
from the NSViewComponentPeer:becomeKeyWindow selector. Jules what do you think?
I don’t think you’re looking at the right code-path…
For me, becomeKeyWindow calls NSViewComponentPeer::grabFocus, which calls viewFocusGain, and that call ComponentPeer::handleFocusGain(), and from there it ends up in TopLevelWindow::focusOfChildComponentChanged. It never goes inside Component::takeKeyboardFocus… (?)
This happens earlier. takeKeyboardFocus is called from appFocusChanged. currentlyFocusedPeer is not null and its call handleFocusGain method. It calls grabKeyboardFocus method and it calls takeKeyboardFocus.
I’ve noticed that viewFocusLoss method is never called on my machine (currentlyFocusedPeer is never null). I get viewFocusGain call from the becomeFirstResponder method, but never viewFocusLost since resignFirstResponder is never called.
I can solve the problem by changing becomeKeyWindow to
If I could reproduce it, it’d be easy to fix… Are you sure this is an OS version thing, and not just a difference between the apps we’re testing? Can you reproduce this with the juce demo?
When I added your suggested callback method to MainDemoWindow, then I also saw it failing to get called.
But… When I added a call to the superclass (which you do need to do, because the superclasses do some significant stuff in there), then everything was fine:
I don’t know Jules… Calling base method doesn’t help on my mac. I need to click into window content to get it activated. You may need to activate/deactivate the window about 3 times to get wrong behavior.