DocumentWindow closeButton keyboard shortcut not working on macOS

Sorry if I’m misunderstanding how this works, but I have a blank GUI Application and am expecting Command + W to close the window (or call closeButtonPressed()) on macOS but it does not. It doesn’t seem to matter if the window has keyboard focus or not. Any idea why that doesn’t work?

I can see in the DocumentWindow code where it looks like this functionality was attempted:

   if (auto* b = getCloseButton())
      #if JUCE_MAC
       b->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));

Are you using a native title bar? The code above will only work with a non-native window

Yes, I’m using a native title bar. What’s the best way to provide keyboard shortcuts for native title bar buttons?

Well, in the projucer we just do it like all our other keys - search for “CommandIDs::closeDocument” and you’ll see how we did it there.

Or if you’re not using the ApplicationCommand system, you could just catch the keypress in your top level component’s keyPressed method and close the window directly.