libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.52k stars 1.77k forks source link

macOS: shortcut CMD+W closes app instead of window #10944

Open DominusExult opened 3 days ago

DominusExult commented 3 days ago

On macOS you close an app with CMD-Q. And you close a window (or a tab in tabbable apps) with CMD-W, the usual behavior being that the app does not close down but does something else, mostly closing the window if that is applicable (e.g. if an app has multiple windows, it will close the active window) or just plain minimizes. This seems to be a bit of a mess on macOS.

Either way, SDL shuts down the app, which is not usual. I found no other app(1) that does this.

This was introduced with 1c9595b16f8f4a78aa8aebffd448c9632e36100a in response to #3093. Technically this looks correct but it seems something else is needed to be done. So when I hit the "about" menu item and the about window shows, it makes sense to close that with CMD-W (which it does) but not quit the app when there is no other window.

(1) meaning every app build against SDL2 and SDL3 since that commit will close the app on CMD-W.

kanjitalk755 commented 1 day ago

Try the following:

SDL_SetHint(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, "0");
DominusExult commented 1 day ago

That prevents the window from closing. Good that this exists.

My proposal would still be that this should be the default and if people want to have their apps behave different than what usually happens they should add this hint with 1. And currently with this hint set to 0, nothing happens. "Usually" the app minimizes.

slime73 commented 1 day ago

The behaviour of many modern macOS apps (including built-in ones like the App Store, System Settings, Preview, etc.) is to close the app when the last window owned by the app is closed, which matches SDL's current default behaviour I think.

There are some exceptions, like the Music app stays open, so I think it's sort of contextual for what the app is responsible for doing. Music playing in the background when the window is gone makes sense to me, as does the App Store app closing when it has no window because it's not doing anything useful by that point.

It's true that most apps used to stay open in older macOS versions though.

DominusExult commented 1 day ago

Trying my apps on macOS 15 it's a hit and miss. Almost all apps not from Apple (I have not tried all) do not close on CMD-W and the ones from Apple do not behave consistently. Some won't close, some others will - in the /Applications/Utilities folder it's 60/40. In the /Applications folder it's 50/50 with big ones like Mail or Notes not closing. Not built in Apple apps (Xcode, Pages, Remote Desktop...) all do not close.

So my observation does not match with yours regarding modern macOS apps. But, sorry, I seem to be more heated on this than I want to be. I observed this and found the difference to my experience noteworthy and discussable. For my own needs I can surely circumvent this either by setting the hint or reassigning the "close window" shortcut to something else in the system settings.

icculus commented 1 day ago

I think it depends on the app; we would expect Microsoft Word on macOS to stick around so you can optionally open a new document from the menu, but a game I'd probably want to terminate, since there's no reason to assume a window will pop back up.

Setting the hint is the right thing to do in this case, I think.