beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.34k stars 670 forks source link

Cocoa Close Window shortcut is incorrect #2214

Closed mhsmith closed 11 months ago

mhsmith commented 11 months ago

Describe the bug

It should be Cmd-W, but the capital W is being translated into Cmd-Shift-W. Close All Windows is also affected.

We should add some shortcut tests to the testbed to cover this kind of thing.

Screenshot 2023-11-08 at 18 53 55

Environment

freakboy3742 commented 11 months ago

"Close" is definitely Cmd-W (seen on Numbers, Music, Maps, and Contacts); but those apps are (1) designed to be persistent (i.e, they are either document-based, or they run in the background when the window isn't present), (2) they don't have a "close all" option.

However, Safari has a "Close Window" and "Close All Windows" (also Close Tab), and the shortcut definitely includes a shift:

Screenshot 2023-11-09 at 5 50 31 am

So - I'm not sure what the right solution is here. We definitely want consistency... but consistency with what? The simple "Close" doesn't entirely make sense on a base Toga app, because the core app isn't persistent - there's no difference between "close" and "quit".

I guess another option would be to take out the "Close" altogether, except maybe for DocumentApps. Close can be synthesised by an end user, so users could add it back in if they want it - the only complication would be that the shortcut wouldn't necessarily be platform appropriate.

HalfWhitt commented 11 months ago

For what it's worth, there are non-persistent apps that use Cmd-w for close as well, such as Calculator, Find My, Dictionary, Clock, and Weather. I think the distinction is less persistent vs. non-persistent and more single-window vs. multi-window (or multi-tab).

mhsmith commented 11 months ago

Yes, the impression I get is that the default on macOS is for Cmd-W to close the current window, unless the app offers a tab interface, in which case it closes the current tab. Single-window apps offer both Cmd-W and Cmd-Q, but they're the same except possibly for whether they leave the app running in the background.

I don't remember seeing any app in which Cmd-W does nothing. So I'm so used to using it, that when it does nothing on Toga, it feels like a big surprise.

freakboy3742 commented 11 months ago

I hadn't made the connection that Safari's behavior is related to the tabs in the interface. On that basis, I agree that "Close (CMD-W)" is the better standard to follow here.

Interestingly, the code implementing this already explicitly mentions the discrepancy between Safari and other apps...