[gtk+/wip/action-descriptions: 2/7] GtkWindow: change muxer setup with application



commit 106772050cf7cb04455b2c3128f39a68452a9ba1
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Jul 9 22:33:22 2013 -0400

    GtkWindow: change muxer setup with application
    
    Previously, GtkWindow would add the "app" action group to its own
    toplevel muxer.
    
    Change the setup so that GtkApplication creates the toplevel muxer and
    adds itself to it as "app".  Use this muxer as the parent muxer of any
    GtkWindow associated with the application.
    
    This saves a small amount of memory and will allow for accels to be
    propagated from the application through to all of the windows.

 gtk/gtkapplication.c        |   28 ++++++++++++++++++++++++----
 gtk/gtkapplicationprivate.h |    5 +++++
 gtk/gtkwidget.c             |   19 ++++++++++++++-----
 gtk/gtkwindow.c             |    3 +--
 4 files changed, 44 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index ed638a7..1adf7e7 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -146,6 +146,8 @@ struct _GtkApplicationPrivate
   GMenuModel      *app_menu;
   GMenuModel      *menubar;
 
+  GtkActionMuxer  *muxer;
+
 #ifdef GDK_WINDOWING_X11
   GDBusConnection *session_bus;
   const gchar     *application_id;
@@ -398,19 +400,24 @@ gtk_application_focus_in_event_cb (GtkWindow      *window,
 }
 
 static void
-gtk_application_startup (GApplication *application)
+gtk_application_startup (GApplication *g_application)
 {
+  GtkApplication *application = GTK_APPLICATION (g_application);
+
   G_APPLICATION_CLASS (gtk_application_parent_class)
-    ->startup (application);
+    ->startup (g_application);
+
+  application->priv->muxer = gtk_action_muxer_new ();
+  gtk_action_muxer_insert (application->priv->muxer, "app", G_ACTION_GROUP (application));
 
   gtk_init (0, 0);
 
 #ifdef GDK_WINDOWING_X11
-  gtk_application_startup_x11 (GTK_APPLICATION (application));
+  gtk_application_startup_x11 (application);
 #endif
 
 #ifdef GDK_WINDOWING_QUARTZ
-  gtk_application_startup_quartz (GTK_APPLICATION (application));
+  gtk_application_startup_quartz (application);
 #endif
 }
 
@@ -1684,3 +1691,16 @@ gtk_application_is_inhibited (GtkApplication             *application,
 }
 
 #endif
+
+GtkActionMuxer *
+gtk_application_get_parent_muxer_for_window (GtkWindow *window)
+{
+  GtkApplication *application;
+
+  application = gtk_window_get_application (window);
+
+  if (!application)
+    return NULL;
+
+  return application->priv->muxer;
+}
diff --git a/gtk/gtkapplicationprivate.h b/gtk/gtkapplicationprivate.h
index bd84b1a..e0c278a 100644
--- a/gtk/gtkapplicationprivate.h
+++ b/gtk/gtkapplicationprivate.h
@@ -23,6 +23,8 @@
 
 #include "gtkapplicationwindow.h"
 
+#include "gtkactionmuxer.h"
+
 G_GNUC_INTERNAL
 gboolean                gtk_application_window_publish                  (GtkApplicationWindow *window,
                                                                          GDBusConnection      *session,
@@ -40,4 +42,7 @@ const gchar *           gtk_application_get_app_menu_object_path        (GtkAppl
 G_GNUC_INTERNAL
 const gchar *           gtk_application_get_menubar_object_path         (GtkApplication       *application);
 
+G_GNUC_INTERNAL
+GtkActionMuxer *        gtk_application_get_parent_muxer_for_window     (GtkWindow                *window);
+
 #endif /* __GTK_APPLICATION_PRIVATE_H__ */
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 865892a..05c654c 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -65,6 +65,7 @@
 #include "gtkplug.h"
 #include "gtktypebuiltins.h"
 #include "a11y/gtkwidgetaccessible.h"
+#include "gtkapplicationprivate.h"
 
 /* for the use of round() */
 #include "fallback-c89.c"
@@ -15472,18 +15473,26 @@ _gtk_widget_set_style (GtkWidget *widget,
 void
 _gtk_widget_update_parent_muxer (GtkWidget *widget)
 {
-  GtkWidget *parent;
   GtkActionMuxer *parent_muxer;
 
   if (widget->priv->muxer == NULL)
     return;
 
-  if (GTK_IS_MENU (widget))
-    parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+  if (GTK_IS_WINDOW (widget))
+    {
+      parent_muxer = gtk_application_get_parent_muxer_for_window (GTK_WINDOW (widget));
+    }
   else
-    parent = gtk_widget_get_parent (widget);
+    {
+      GtkWidget *parent;
+
+      if (GTK_IS_MENU (widget))
+        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+      else
+        parent = gtk_widget_get_parent (widget);
 
-  parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+      parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+    }
 
   gtk_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
 }
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 3d0847c..49b3df3 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2949,8 +2949,7 @@ gtk_window_set_application (GtkWindow      *window,
           gtk_application_add_window (priv->application, window);
         }
 
-      /* don't use a normal cast: application may be NULL */
-      gtk_widget_insert_action_group (GTK_WIDGET (window), "app", (GActionGroup *) application);
+      _gtk_widget_update_parent_muxer (GTK_WIDGET (window));
 
       g_object_notify (G_OBJECT (window), "application");
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]