[Mono-osx] Close GTK# application with apple+q

Michael Hutchinson m.j.hutchinson at gmail.com
Sun Sep 26 12:23:47 EDT 2010


On Fri, Sep 24, 2010 at 7:52 AM, ChristianManthey <info at manthey-it.de> wrote:
>
> After implementing the "Integrating a GTK# Application with the Mac" articel
> from Michael Hutchinson i was very much releaved that my GTK# application
> was able to react on the shutdown command from OSX. But my user like to use
> the CMD+Q (apple+q) Keyboard combination so i was searching for a way to
> implement this functionality.

That's odd, if you're using IGE and set the quit command correctly,
and it has the control-q binding, I thought IGE would map and handle
it for you.

Did you set IgeMainMenu.GlobalKeyHandlerEnabled = true?

> After some trial and error i came with the following solution, that might
> also help others. If someone has a better way of solving this, i'm also
> happy for comments on how to improve the below.
>
> 1. I used the KeyReleaseEvent from the GTK# application to check whether my
> user is trying to quit the application and call the following statement
> directly after the Build(); function
>
>             this.KeyReleaseEvent += new
> KeyReleaseEventHandler(this.checkKey);
>
> 2. As the above mentioned event will be raised two times for cmd+q i created
> the following 4 vars in my gtk.Window class.
>
>        private bool appleKey_clicked = false;
>        private bool q_clicked = false;
>        private int time_control_clicked = 0;
>        private int time_q_clicked = 0;

Alternatively you could just check for "q" and the "Mod1" modifier flag.

(yes, I don't know why the Meta key results in Mod1 modifier. There's
a bug open against GTK)

It's also possible to install a global key snooper for your
application so it works from all windows.

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Mono-osx mailing list