handle main window delete events sensibly
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 27 Jul 2015 14:50:35 +0000 (10:50 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 22 Feb 2016 20:31:23 +0000 (15:31 -0500)
gtk2_ardour/ardour_ui.h
gtk2_ardour/ardour_ui2.cc
gtk2_ardour/ardour_ui_dependents.cc

index 6a91b6415a69bf2c084f455a4e46ec6d3aabef56..d54063b782332b310bc3f71eb6047838b5e05aa1 100644 (file)
@@ -839,6 +839,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev, Gtkmm2ext::Bindings*);
        bool try_gtk_accel_binding (GtkWindow* win, GdkEventKey* ev, bool translate, GdkModifierType modifier);
        
+       bool main_window_delete_event (GdkEventAny*);
+       bool idle_ask_about_quit ();
 };
 
 #endif /* __ardour_gui_h__ */
index 925969869a7fc6b83b217c33dd2a380f75fea96b..eaae3c0e03a6e045e92dd8e4bb10c9e327938112 100644 (file)
@@ -184,9 +184,11 @@ ARDOUR_UI::setup_windows ()
        build_menu_bar ();
        setup_tooltips ();
 
+       _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::main_window_delete_event));
+       
        /* pack the main vpacker into the main window and show everything
         */
-       
+
        _main_window.add (main_vpacker);
        transport_frame.show_all ();
 
@@ -905,3 +907,4 @@ ARDOUR_UI::update_title ()
        }
 
 }
+
index 97c81f187af1a8142bea3f2fec6130e6776239c3..0d7b5a13532460febeb27f68a859990589598c11 100644 (file)
@@ -155,3 +155,41 @@ ARDOUR_UI::tab_window_root_drop (GtkNotebook* src,
        
        return 0; /* what was that? */
 }
+
+bool
+ARDOUR_UI::idle_ask_about_quit ()
+{
+       if (_session && _session->dirty()) {
+               finish ();
+       } else {
+               /* no session or session not dirty, but still ask anyway */
+
+               Gtk::MessageDialog msg (string_compose ("Quit %1?", PROGRAM_NAME),
+                                       false, /* no markup */
+                                       Gtk::MESSAGE_INFO,
+                                       Gtk::BUTTONS_YES_NO,
+                                       true); /* modal */
+               msg.set_default_response (Gtk::RESPONSE_YES);
+
+               if (msg.run() == Gtk::RESPONSE_YES) {
+                       finish ();
+               }
+       }
+
+       /* not reached but keep the compiler happy */
+
+       return false;
+}
+
+bool
+ARDOUR_UI::main_window_delete_event (GdkEventAny* ev)
+{
+       /* quit the application as soon as we go idle. If we call this here,
+        * the window manager/desktop can think we're taking too longer to
+        * handle the "delete" event
+        */
+       
+       Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_ask_about_quit));   
+       
+       return true;
+}