[gtkmm] Gtk::Application: Let run(window) actually return.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Gtk::Application: Let run(window) actually return.
- Date: Thu, 20 Jan 2011 08:46:25 +0000 (UTC)
commit a31c95ee834543b3598b62a50f2214cd9716309d
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jan 20 09:46:18 2011 +0100
Gtk::Application: Let run(window) actually return.
* gtk/src/application.[hg|ccg]: add_window(): Hand-code this, so we can
respond to the window's hide signal. This is because GtkApplication
actually responds to window destruction, not window closing.
ChangeLog | 8 ++++++++
gtk/src/application.ccg | 30 +++++++++++++++++++++++++++---
gtk/src/application.hg | 28 ++++++++++++++++++++++++----
3 files changed, 59 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 58dd407..37ecdb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2011-01-20 Murray Cumming <murrayc murrayc com>
+ Gtk::Application: Let run(window) actually return.
+
+ * gtk/src/application.[hg|ccg]: add_window(): Hand-code this, so we can
+ respond to the window's hide signal. This is because GtkApplication
+ actually responds to window destruction, not window closing.
+
+2011-01-20 Murray Cumming <murrayc murrayc com>
+
Gtk::Application: Try to make this a replacement for Gtk::Main.
* gtk/src/application.[hg|ccg]: Add a copy of init_gtkmm_internals() from
diff --git a/gtk/src/application.ccg b/gtk/src/application.ccg
index 3ef51ca..962d210 100644
--- a/gtk/src/application.ccg
+++ b/gtk/src/application.ccg
@@ -87,6 +87,31 @@ void Application::on_activate_showwindow()
{
if(m_main_window)
m_main_window->show();
+
+ m_main_window = 0; //We don't need to remember this anymore.
+}
+
+void Application::on_window_hide(Window* window)
+{
+ //Tell GtkApplication to forget the window.
+ //This can cause run() to return, if it is the last window.
+ //Otherwise, GtkApplication waits for the window to be _destroyed_,
+ //which is just not something that it should care about:
+ //See https://bugzilla.gnome.org/show_bug.cgi?id=639931
+ if(window && window->get_application()) //We check that it's still in an application anyway.
+ remove_window(*window);
+}
+
+void Application::add_window(Window& window)
+{
+ //Respond to window hiding, not destruction:
+ //See https://bugzilla.gnome.org/show_bug.cgi?id=639931
+ window.signal_hide().connect(
+ sigc::bind(
+ sigc::mem_fun(*this, &Application::on_window_hide),
+ &window));
+
+ gtk_application_add_window(gobj(), (window).gobj());
}
int Application::run(int argc, char** argv)
@@ -94,8 +119,7 @@ int Application::run(int argc, char** argv)
return Gio::Application::run(argc, argv);
}
-
-int Application::run(Gtk::Window& window, int argc, char** argv)
+int Application::run(Window& window, int argc, char** argv)
{
add_window(window);
@@ -112,7 +136,7 @@ int Application::run(Gtk::Window& window, int argc, char** argv)
return result;
}
-int Application::run(Gtk::Window& window)
+int Application::run(Window& window)
{
g_assert(m_argc);
g_assert(m_argv);
diff --git a/gtk/src/application.hg b/gtk/src/application.hg
index d662e01..2e9131d 100644
--- a/gtk/src/application.hg
+++ b/gtk/src/application.hg
@@ -76,7 +76,26 @@ public:
#m4 _CONVERSION(`GList*',`Glib::ListHandle<const Window*>',`$2($3, Glib::OWNERSHIP_NONE)')
_WRAP_METHOD(Glib::ListHandle<const Window*> get_windows() const, gtk_application_get_windows)
- _WRAP_METHOD(void add_window(Window& window), gtk_application_add_window)
+ /** Adds a window to the Gtk::Application.
+ *
+ * If all the windows managed by Gtk::Application are closed, the
+ * Gtk::Application will call quit(), and quit
+ * the application.
+ *
+ * If your application uses only a single toplevel window, you can
+ * use get_window(). If you are using a sub-class
+ * of Gtk::Application you should call create_window()
+ * to let the Gtk::Application instance create a Gtk::Window and add
+ * it to the list of toplevels of the application. You should call
+ * this function only to add Gtk::Window<!-- -->s that you created
+ * directly using new Gtk::Window.
+ *
+ * @newin{3,0}
+ * @param window A toplevel window to add to the application.
+ */
+ void add_window(Window& window);
+ _IGNORE(gtk_application_add_window)
+
_WRAP_METHOD(void remove_window(Window& window), gtk_application_remove_window)
/** Starts the application.
@@ -103,7 +122,7 @@ public:
*
* @newin{2,28}
*/
- int run(Gtk::Window& window, int argc, char** argv);
+ int run(Window& window, int argc, char** argv);
/** Starts the application.
*
@@ -117,7 +136,7 @@ public:
*
* @newin{2,28}
*/
- int run(Gtk::Window& window);
+ int run(Window& window);
private:
/** This is just a way to call Glib::init() (which calls g_type_init()) before
@@ -128,9 +147,10 @@ private:
const Glib::Class& custom_class_init();
void on_activate_showwindow();
+ void on_window_hide(Window*);
///We show the window in the activate signal handler.
- Gtk::Window* m_main_window;
+ Window* m_main_window;
//We need these to call g_application_run(),
//even if we have already called gtk_init().
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]