From 1be30e040169863006eb37d8ee2b8ad919febfa3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 27 Jul 2015 10:50:35 -0400 Subject: handle main window delete events sensibly --- gtk2_ardour/ardour_ui.h | 2 ++ gtk2_ardour/ardour_ui2.cc | 5 ++++- gtk2_ardour/ardour_ui_dependents.cc | 38 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 6a91b6415a..d54063b782 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -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__ */ diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index 925969869a..eaae3c0e03 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -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 () } } + diff --git a/gtk2_ardour/ardour_ui_dependents.cc b/gtk2_ardour/ardour_ui_dependents.cc index 97c81f187a..0d7b5a1353 100644 --- a/gtk2_ardour/ardour_ui_dependents.cc +++ b/gtk2_ardour/ardour_ui_dependents.cc @@ -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; +} -- cgit v1.2.3