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.
This commit is contained in:
Ryan Lortie 2013-07-09 22:33:22 -04:00
parent 3f0b9a7574
commit abcddd3ae0
4 changed files with 43 additions and 11 deletions

View File

@ -143,6 +143,7 @@ struct _GtkApplicationPrivate
GMenuModel *menubar;
gboolean register_session;
GtkActionMuxer *muxer;
#ifdef GDK_WINDOWING_X11
guint next_id;
@ -396,19 +397,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
}
@ -1688,3 +1694,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;
}

View File

@ -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__ */

View File

@ -64,6 +64,7 @@
#include "gtkplug.h"
#include "gtktypebuiltins.h"
#include "a11y/gtkwidgetaccessible.h"
#include "gtkapplicationprivate.h"
/* for the use of round() */
#include "fallback-c89.c"
@ -15457,18 +15458,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;
parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
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;
}
gtk_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
}

View File

@ -2958,8 +2958,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");
}