Re: Disable Alt+F4
- From: Milosz Derezynski <internalerror gmail com>
- To: gtkmm-list gnome org
- Subject: Re: Disable Alt+F4
- Date: Mon, 14 Dec 2009 04:10:12 +0100
That problem is simple to solve but a little difficult to explain and expand on depending on how your setup works.
If you use this mechanism in your app:
Gtk::Main kit (argc, argc);
Gtk::Window my_toplevel ;
// some other code to setup the app in between
kit.run( my_toplevel );
then the ALT+F4 will be handled by the Gtk::Main instance.
Let me expand on this:
What happens when you press ALT+F4 on a window, or click the 'x' in the titlebar, or use any other mechanism the window manager employs for "closing" a window is that you cause a "delete" event to be emitted for that particular window. That event in itself does nothing, but Gtk::Main run with a window as argument is coded so that it hides the window, possibly even destroys (unrefs?) the main window instance and exits the Gtk+ main loop.
If you don't do it like above, but like this:
Gtk::Main kit (argc, argc);
Gtk::Window my_toplevel ;
// some other code to setup the app in between
my_toplevel.show();
kit.run();
You have two ways of dealing with this and avoiding the window to be hidden or actually anything happening at all.
The first is, you derive from Gtk::Window and override on_delete_event:
class MyOwnWindow : public Gtk::Window
{
protected:
virtual bool
on_delete_event( GdkEventAny* G_GNUC_UNUSED )
{
/* do whatever you want to do when the user presses ALT+F4, clicks 'x' or whatever other means the user uses to close the window*/
return true; // important
}
};
bool
on_my_toplevel_delete_handler( GdkEventAny* G_GNUC_UNUSED )
{
/* do whatever you want to do when the user presses ALT+F4, clicks 'x' or whatever other means the user uses to close the window*/
}
int main( int argc, char* argv[])
{
Gtk::Main kit (argc, argc);
Gtk::Window my_toplevel ;
// some other code to setup the app in between
my_toplevel.signal_delete_event().connect( sigc::ptr_fun( &on_my_toplevel_delete_handler ), true /* important! */ );
my_toplevel.show();
kit.run();
}
That is basically it.
--
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]