* GtkApplicationWindow is a #GtkWindow subclass that offers some
* extra functionality for better integration with #GtkApplication
* features. Notably, it can handle both the application menu as well
- * as the menubar. See g_application_set_app_menu() and
+ * as the menubar. See g_application_set_app_menu() and
* g_application_set_menubar().
*
* This class implements the #GActionGroup and #GActionMap interfaces,
* prefix. Actions must be addressed with the prefixed name when
* referring to them from a #GMenuModel.
*
- * If the desktop environment does not display the application menu
- * as part of the desktop shell, then #GApplicationWindow will
- * automatically show the menu as part of a menubar. This behaviour
- * can be overridden with the #GtkApplicationWindow:show-menubar
- * property.
+ * The settings #GtkSettings:gtk-shell-shows-app-menu and
+ * #GtkSettings:gtk-shell-shows-menubar tell GTK+ whether the
+ * desktop environment is showing the application menu and menubar
+ * models outside the application as part of the desktop shell.
+ * For instance, on OS X, both menus will be displayed remotely;
+ * on Windows neither will be. gnome-shell (starting with version 3.4)
+ * will display the application menu, but not the menubar.
+ *
+ * If the desktop environment does not display the menubar, then
+ * #GApplicationWindow will automatically show a #GtkMenubar for it.
+ * This behaviour can be overridden with the #GtkApplicationWindow:show-menubar
+ * property. If the desktop environment does not display the application
+ * menu, then it will automatilly be included in the menubar.
*
* <example><title>A GtkApplicationWindow with a menubar</title>
* <programlisting><![CDATA[
struct _GtkApplicationWindowPrivate
{
GSimpleActionGroup *actions;
+ GActionObservable *muxer;
GtkWidget *menubar;
GtkAccelGroup *accels;
GSList *accel_closures;
if (!have_menubar && should_have_menubar)
{
- GActionMuxer *muxer;
GMenu *combined;
- muxer = g_action_muxer_new ();
- g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (gtk_window_get_application (GTK_WINDOW (window))));
- g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
-
combined = g_menu_new ();
g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->app_menu_section));
g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->menubar_section));
- window->priv->menubar = gtk_model_menu_create_menu_bar (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (muxer), window->priv->accels);
+ window->priv->menubar = gtk_model_menu_create_menu_bar (G_MENU_MODEL (combined), window->priv->muxer, window->priv->accels);
gtk_widget_set_parent (window->priv->menubar, GTK_WIDGET (window));
gtk_widget_show_all (window->priv->menubar);
g_object_unref (combined);
- g_object_unref (muxer);
gtk_widget_queue_resize (GTK_WIDGET (window));
}
static void
gtk_application_window_update_accels (GtkApplicationWindow *window)
{
- GtkApplication *application;
AccelData data;
- GActionMuxer *muxer;
-
- /* FIXME: we should keep the muxer around, and listen for changes.
- * Also, we should listen for accel map changes
- */
- application = gtk_window_get_application (GTK_WINDOW (window));
free_accel_closures (window);
- muxer = g_action_muxer_new ();
- g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (application));
- g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
-
data.window = window;
- data.actions = G_ACTION_GROUP (muxer);
+ data.actions = G_ACTION_GROUP (window->priv->muxer);
gtk_accel_map_foreach (&data, add_accel_closure);
-
- g_object_unref (muxer);
}
static void
g_signal_connect (settings, "notify::gtk-shell-shows-menubar",
G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window);
+ if (window->priv->muxer == NULL)
+ {
+ GtkApplication *application;
+ GActionMuxer *muxer;
+
+ application = gtk_window_get_application (GTK_WINDOW (window));
+
+ muxer = g_action_muxer_new ();
+ g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (application));
+ g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
+ window->priv->muxer = G_ACTION_OBSERVABLE (muxer);
+ }
+
gtk_application_window_update_shell_shows_app_menu (window, settings);
gtk_application_window_update_shell_shows_menubar (window, settings);
gtk_application_window_update_menubar (window);
g_clear_object (&window->priv->menubar_section);
g_clear_object (&window->priv->actions);
g_clear_object (&window->priv->accels);
+ g_clear_object (&window->priv->muxer);
G_OBJECT_CLASS (gtk_application_window_parent_class)
->dispose (object);