rust-windowing / glutin

A low-level library for OpenGL context creation, written in pure Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Command Q to quit on Mac OS X

neon64 opened this issue · comments

Most native Cocoa apps will quit when you press Command-Q (or whatever keyboard shortcut you have set globally I think).

I'm not an expert in windowing systems for Mac OS X so I ask if it possible to implement this functionality with glutin as well. I understand I should be able to implement this myself in application code but I believe it would be better as part of glutin as it is a system-wide convention.

Also, when trying to implement this myself, I couldn't find a way to manually close the glutin window. I have a loop like so:

while !window.is_closed() {
    // stuff
}

And it will exit when I click the close button, but I can't find a function like window.close or window.set_closed anywhere where I can manually close the window. What is the recommended way of doing this?

And it will exit when I click the close button, but I can't find a function like window.close or window.set_closed anywhere where I can manually close the window. What is the recommended way of doing this?

For the moment the only way to destroy the window is to destroy the Window object associated to it. You can also call hide() instead, to hide it.

I don't know if it makes sense to add closed() in addition to hide().

@tomaka The ⌘Q behavior is defined by the shortcut for Quit Application in the toolbar.

Quit application

Right now glutin doesn't have anything of the sort, and while it could be added programmatically, it would also be hardcoded. Alternatively it could use a .xib file to define the toolbar options. But that would mean glutin gets a local file dependency for a specific platform which is not ideal. How about checking if say, Menu.xib is in the bundle path (The normal place for it to be) and if it's not, fall back on programmatically defining the menu.

xib file

Added in this branch, but I'm not keen on merging since there's still the issue with how we process events on osx (currently it blocks ⌘Q and similar key combinations).