As you may know, in Mac OSX, when you close a window, it usually won’t quit the application. Instead, it hides the window and you can show it later by clicking the dock icon. In JUCE, I can hide the window by overriding:
But I cannot find a place to show this window again upon dock window clicking. I tried focusGained but it won’t be called after the DocumentWindow is invisible. Any ideas? Thanks.
Yes, you could grab that event - it gets sent to your JUCEApplication object. Not sure if it’ll still get called if the app already has focus when you click on the icon though.
I am trying to achieve the same thing. Show the window after hiding it by clicking the dock icon. When the dock icon is clicked applicationDidBecomeActive is raised and focusChanged() is called. But the event is not reaching the window because it is not visible.
After digging a bit deeper it seems the correct way to do this is to call [NSApp hide] when the user clicks the close button. This will also make a different process the foreground process. Then if the user clicks the Dock icon a call to [NSApp unhide] will restore the window to its previous state.
The native mac menu has an entry which calls [NSApp hide] but I see no way to access this functionality. I see no way at all to call [NSApp unhide].
So in summary what’s needed to make this work is:
A way to call [NSApp hide]
A way to call [NSApp unhide]
forwarding of applicationDidBecomeActive to JUCEApplication::resumed()
What’s described above will work. The only missing piece in JUCE ist the Process::hide() method. I just double checked the tip and it seems Jules did not have time to add the method below:
If the user clicks the dock icon again Mac OS does the right thing by default, it brings the app to the foreground again.
Be careful if you want to use this in a Mac App Store App. If you do this and you do not have a tray icon as well your app will be rejected because it does not conform to the user interface guidelines.