Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn before quitting with ⌘Q #2321

Closed
conath opened this issue Feb 19, 2021 · 9 comments
Closed

Warn before quitting with ⌘Q #2321

conath opened this issue Feb 19, 2021 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@conath
Copy link
Contributor

conath commented Feb 19, 2021

Describe the issue
I am running a macOS VM and I press the keyboard shortcut ⌘ Q to quit an application in the VM, or ⌘ W to close a window. However, the shortcut is not passed into the VM (even when the mouse is captured). Instead, UTM immediately exits. This is very annoying because you lose all unsaved data and pressing ⌘Q/W is extremely common for macOS users.

Configuration

  • UTM Version: latest
  • OS Version: latest
  • Intel or Apple Silicon? Intel

Suggestion

When ⌘ Q/W is encountered while a VM is still running, an alert should appear with the option to pause the VM, Exit and Cancel (continuing to run the VM as if ⌘ Q/W wasn't pressed).

@osy
Copy link
Contributor

osy commented Feb 21, 2021

@conath any idea how to do this? I know Chrome has something where you have to confirm Cmd+Q or hold it.

EDIT: Seems like I have to replace the whole menu and re-create the other items.

@osy osy added the enhancement New feature or request label Feb 21, 2021
@conath
Copy link
Contributor Author

conath commented Feb 21, 2021

@osy
Copy link
Contributor

osy commented Feb 22, 2021

@StupidRepo
Copy link

@osy I know Chrome has something where you have to confirm Cmd+Q or hold it.

It's actually Opera not Chrome.

@conath
Copy link
Contributor Author

conath commented Feb 22, 2021

Chrome does have it, it's an option in the "Chrome" menu ("Warn Before Quitting").

@utmapp utmapp deleted a comment from StupidRepo Feb 22, 2021
@osy
Copy link
Contributor

osy commented Feb 23, 2021

Reading more on this, seems like Key Equivalent Handling (menu/button shortcuts) are always handled before the event is sent to the key window -> first responder -> my view. So Cmd+Q, Cmd+W, Cmd+N for example won't be seen by the app. The way around it is to use https://developer.apple.com/documentation/appkit/nsevent/1534971-addlocalmonitorforeventsmatching which will require a bit of refactoring on the current window controller.

I'm thinking of the following rules:

  1. When mouse is captured, always send all keys to VM except the release key combo.
  2. When mouse is not captured, throw alert when Cmd+Q or Cmd+W prompting the user to either pause the VM (if available) or stop it.
  3. Any other Key Equivalents will still be handled when not captured. This makes us a good macOS citizen.

@osy osy added this to the v2.1 milestone Feb 23, 2021
@Oreilles
Copy link

@osy I know Chrome has something where you have to confirm Cmd+Q or hold it.

It's actually Opera not Chrome.

Chrome has it too, and it's beyond annoying - but can be disable fortunately. It should just show a confirmation window with the option to not ask ever again, like literally every mac app.

@JayBrown
Copy link

There's also this: https://commandqapp.com/

@osy osy mentioned this issue Apr 22, 2021
@osy osy closed this as completed in acddc0e Apr 25, 2021
osy added a commit that referenced this issue Apr 25, 2021
If mouse is captured, we always pass Cmd+Any to the Metal view.
If mouse is not captured, we always warn for Cmd+Q.
If mouse is not captured, Cmd+W is blocked if VM is busy, or a confirm will
show if VM is running, or window will close if VM is stopped.

Resolves #2321
@Aem1024
Copy link

Aem1024 commented May 17, 2021

Edge also has it, it seems like most chromium browsers do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants