Using nativeTitleBar close button

I need my application to ask the user confirmation when the close button of the main window is pressed.

However, when enabling usingNativeTitleBar on OSX, clicking the “close” button of the main window will quit the application no matter what. The DocumentWindow::closeButtonPressed() virtual function is called, shows the confirmation popup, but I can’t avoid the closing of the application…
This does not happen when using the juce titlebar and the native titlebar on windows.

What’s required to prevent this unconditional application exit with the native OSX titlebar ?


Good question. It’s not the app that’s closed, of course, it’s just the window. I’ll need to have a look at this, but no time at the moment. Let me know if you find any clues before I get chance to investigate.

Hello !

It takes place in juce_Mac_Windowing.cpp , the handleWindowClassEvent() method always return an OSS status equal to “eventNotHandledErr”, but in certain case we would like it to return a different OSStatus (like 0), so that the event isn’t taken in consideration by OSX.

I think the handleUserClosingWindow() method should be able to return a boolean depending if we really want to close the app or not…

It’s the same case when trying to close the app by clicking ‘Quit’ in the OSX menuBar, AppEventHandlerProc() in juce_Mac_Messaging.h shouldn’t return systematically the same OSStatus…

Let me know if i’m wrong and sorry for my english :wink:

When the close button is pressed, the OS should never be allowed to actually delete the window - that should be done by the juce handler if it wants to. I didn’t realise that the OS would delete the window itself if you return eventNotHandled, so in fact it should just be changed to always return noErr.

Quit handling works the same way, relying on the app to decide whether to quit or not when sysemRequestedQuit is called. That works fine already though, I don’t think there’s a bug in it?

You’re right :

Working fine when closebutton pressed when changing noErr instead of eventNotHandled.
Working fine with quit handling too, no bug. It was a mistake by my side :oops:

Thanks again for your support !