[gtkmm/gtkmm-3-4] Application: run(): Do not show the window until activation.



commit a2b0b27f832d3f2082874334a0e23a2637f52ff5
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jun 12 13:17:51 2012 +0200

    Application: run(): Do not show the window until activation.
    
    * gtk/src/application.[hg|ccg]: run(window): Only show the window in
    an activate signal handler, to fix a crash caused by the application not
    being registered when the GtkApplicationWindow tries to realize itself.

 ChangeLog               |    8 ++++++++
 gtk/src/application.ccg |   23 +++++++++++++++++++++--
 gtk/src/application.hg  |    3 ++-
 3 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2f7e3f7..8cba689 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-06-12  Murray Cumming  <murrayc murrayc com>
+
+	Application: run(): Do not show the window until activation.
+
+	* gtk/src/application.[hg|ccg]: run(window): Only show the window in 
+	an activate signal handler, to fix a crash caused by the application not
+	being registered when the GtkApplicationWindow tries to realize itself.
+
 2012-05-28  Murray Cumming  <murrayc murrayc com>
 
 	Container: Slight improvements to the vfunc documentation.
diff --git a/gtk/src/application.ccg b/gtk/src/application.ccg
index 4769eb0..a2f120f 100644
--- a/gtk/src/application.ccg
+++ b/gtk/src/application.ccg
@@ -128,19 +128,32 @@ int Application::run(int argc, char** argv)
 int Application::run(Window& window, int argc, char** argv)
 {
   add_window(window);
-  window.show();
+  
+  //We cannot show the window until GApplication::activate has been
+  //called, or we will crash because the application has not been "registered".
+  signal_activate().connect(
+    sigc::bind(
+      sigc::mem_fun(*this, &Application::on_activate_show_main_window),
+      &window));
 
   const int result = Gio::Application::run(argc, argv);
   return result;
 }
 
+
 int Application::run(Window& window)
 {
   g_assert(m_argc);
   g_assert(m_argv);
 
   add_window(window);
-  window.show();
+
+  //We cannot show the window until GApplication::activate has been
+  //called, or we will crash because the application has not been "registered".
+  signal_activate().connect(
+    sigc::bind(
+      sigc::mem_fun(*this, &Application::on_activate_show_main_window),
+      &window));
 
   const int result = Gio::Application::run(m_argc, m_argv);
   return result;
@@ -155,5 +168,11 @@ int Application::run()
   return result;
 }
 
+void Application::on_activate_show_main_window(Window* window)
+{
+  if(window)
+    window->show();
+}
+
 
 } // namespace Gtk
diff --git a/gtk/src/application.hg b/gtk/src/application.hg
index 3f3a47b..7f42c98 100644
--- a/gtk/src/application.hg
+++ b/gtk/src/application.hg
@@ -200,7 +200,8 @@ private:
    */
   const Glib::Class& custom_class_init();
   
-  void on_window_hide(Window*);
+  void on_activate_show_main_window(Window* window);
+  void on_window_hide(Window* 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]