2 * Copyright © 2011 Canonical Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Author: Ryan Lortie <desrt@desrt.ca>
24 #include "gtkapplicationwindow.h"
26 #include "gtkseparatormenuitem.h"
27 #include "gtkcheckmenuitem.h"
28 #include "gtkmenubar.h"
29 #include "gactionmuxer.h"
33 * SECTION:gtkapplicationwindow
34 * @title: GtkApplicationWindow
35 * @short_description: GtkWindow subclass with GtkApplication support
37 * GtkApplicationWindow is a #GtkWindow subclass that offers some extra
38 * functionality for better integration with #GtkApplication features.
39 * It implements the #GActionGroup and #GActionMap interfaces, to let
40 * you add window-specific actions that will be exported by the associated
41 * #GtkApplication, together with its application-wide actions.
42 * Window-specific actions are prefixed with the "win." prefix and
43 * application-wide actions are prefixed with the "app." prefix.
44 * Actions must be addressed with the prefixed name when referring
45 * to them from a #GMenuModel.
47 * If the desktop environment does not display the application menu
48 * as part of the desktop shell, then #GApplicationWindow will
49 * automatically show the menu as part of a menubar. This behaviour
50 * can be overridden with the #GtkApplicationWindow:show-app-menu
54 struct _GtkApplicationWindowPrivate
56 GSimpleActionGroup *actions;
59 guint initialized_app_menu : 1;
60 guint default_show_app_menu : 1;
61 guint did_override_show_app_menu : 1;
62 guint override_show_app_menu : 1;
66 recalculate_app_menu_state (GtkApplicationWindow *window);
69 on_shell_shows_app_menu_changed (GtkSettings *settings,
73 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (user_data);
76 g_object_get (settings, "gtk-shell-shows-app-menu", &val, NULL);
77 window->priv->default_show_app_menu = !val;
78 recalculate_app_menu_state (window);
82 gtk_application_window_list_actions (GActionGroup *group)
84 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
86 return g_action_group_list_actions (G_ACTION_GROUP (window->priv->actions));
90 gtk_application_window_query_action (GActionGroup *group,
91 const gchar *action_name,
93 const GVariantType **parameter_type,
94 const GVariantType **state_type,
95 GVariant **state_hint,
98 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
100 return g_action_group_query_action (G_ACTION_GROUP (window->priv->actions),
101 action_name, enabled, parameter_type, state_type, state_hint, state);
105 gtk_application_window_activate_action (GActionGroup *group,
106 const gchar *action_name,
109 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
111 return g_action_group_activate_action (G_ACTION_GROUP (window->priv->actions), action_name, parameter);
115 gtk_application_window_change_action_state (GActionGroup *group,
116 const gchar *action_name,
119 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
121 return g_action_group_change_action_state (G_ACTION_GROUP (window->priv->actions), action_name, state);
125 gtk_application_window_lookup_action (GActionMap *action_map,
126 const gchar *action_name)
128 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
130 return g_action_map_lookup_action (G_ACTION_MAP (window->priv->actions), action_name);
134 gtk_application_window_add_action (GActionMap *action_map,
137 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
139 g_action_map_add_action (G_ACTION_MAP (window->priv->actions), action);
143 gtk_application_window_remove_action (GActionMap *action_map,
144 const gchar *action_name)
146 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
148 g_action_map_remove_action (G_ACTION_MAP (window->priv->actions), action_name);
152 gtk_application_window_group_iface_init (GActionGroupInterface *iface)
154 iface->list_actions = gtk_application_window_list_actions;
155 iface->query_action = gtk_application_window_query_action;
156 iface->activate_action = gtk_application_window_activate_action;
157 iface->change_action_state = gtk_application_window_change_action_state;
161 gtk_application_window_map_iface_init (GActionMapInterface *iface)
163 iface->lookup_action = gtk_application_window_lookup_action;
164 iface->add_action = gtk_application_window_add_action;
165 iface->remove_action = gtk_application_window_remove_action;
168 G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindow, gtk_application_window, GTK_TYPE_WINDOW,
169 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, gtk_application_window_group_iface_init)
170 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, gtk_application_window_map_iface_init))
177 static GParamSpec *gtk_application_window_properties[N_PROPS];
180 gtk_application_window_real_get_preferred_height (GtkWidget *widget,
181 gint *minimum_height,
182 gint *natural_height)
184 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
186 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
187 ->get_preferred_height (widget, minimum_height, natural_height);
189 if (window->priv->menubar != NULL)
191 gint menubar_min_height, menubar_nat_height;
193 gtk_widget_get_preferred_height (GTK_WIDGET (window->priv->menubar), &menubar_min_height, &menubar_nat_height);
194 *minimum_height += menubar_min_height;
195 *natural_height += menubar_nat_height;
200 gtk_application_window_real_get_preferred_height_for_width (GtkWidget *widget,
202 gint *minimum_height,
203 gint *natural_height)
205 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
207 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
208 ->get_preferred_height_for_width (widget, width, minimum_height, natural_height);
210 if (window->priv->menubar != NULL)
212 gint menubar_min_height, menubar_nat_height;
214 gtk_widget_get_preferred_height_for_width (GTK_WIDGET (window->priv->menubar), width, &menubar_min_height, &menubar_nat_height);
215 *minimum_height += menubar_min_height;
216 *natural_height += menubar_nat_height;
221 gtk_application_window_real_get_preferred_width (GtkWidget *widget,
225 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
227 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
228 ->get_preferred_width (widget, minimum_width, natural_width);
230 if (window->priv->menubar != NULL)
232 gint menubar_min_width, menubar_nat_width;
234 gtk_widget_get_preferred_width (GTK_WIDGET (window->priv->menubar), &menubar_min_width, &menubar_nat_width);
235 *minimum_width = MAX (*minimum_width, menubar_min_width);
236 *natural_width = MAX (*natural_width, menubar_nat_width);
241 gtk_application_window_real_get_preferred_width_for_height (GtkWidget *widget,
246 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
248 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
249 ->get_preferred_width_for_height (widget, height, minimum_width, natural_width);
251 if (window->priv->menubar != NULL)
253 gint menubar_min_width, menubar_nat_width;
255 gtk_widget_get_preferred_width_for_height (GTK_WIDGET (window->priv->menubar), height, &menubar_min_width, &menubar_nat_width);
256 *minimum_width = MAX (*minimum_width, menubar_min_width);
257 *natural_width = MAX (*natural_width, menubar_nat_width);
262 gtk_application_window_real_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation)
265 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
267 if (window->priv->menubar != NULL)
269 GtkAllocation menubar_allocation = *allocation;
270 gint menubar_min_height, menubar_nat_height;
273 gtk_widget_get_preferred_height_for_width (GTK_WIDGET (window->priv->menubar), allocation->width, &menubar_min_height, &menubar_nat_height);
275 menubar_allocation.height = menubar_min_height;
276 gtk_widget_size_allocate (GTK_WIDGET (window->priv->menubar), &menubar_allocation);
278 child = gtk_bin_get_child (GTK_BIN (window));
279 if (child != NULL && gtk_widget_get_visible (child))
281 GtkAllocation child_allocation = *allocation;
284 child_allocation.height = MAX (1, child_allocation.height - menubar_min_height);
286 border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
287 child_allocation.x += border_width;
288 child_allocation.y += border_width + menubar_min_height;
289 child_allocation.width -= border_width * 2;
290 child_allocation.height -= border_width * 2 - menubar_min_height;
291 gtk_widget_size_allocate (child, &child_allocation);
294 gtk_widget_set_allocation (widget, allocation);
297 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
298 ->size_allocate (widget, allocation);
302 gtk_application_window_real_realize (GtkWidget *widget)
304 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
306 if (!window->priv->initialized_app_menu)
308 window->priv->initialized_app_menu = TRUE;
309 g_signal_connect (gtk_widget_get_settings ((GtkWidget*)window),
310 "notify::gtk-shell-shows-app-menu",
311 G_CALLBACK (on_shell_shows_app_menu_changed),
313 on_shell_shows_app_menu_changed (gtk_widget_get_settings ((GtkWidget*)window), NULL, window);
316 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
321 gtk_application_window_real_map (GtkWidget *widget)
323 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
325 /* XXX could eliminate this by tweaking gtk_window_map */
326 if (window->priv->menubar)
327 gtk_widget_map (GTK_WIDGET (window->priv->menubar));
329 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
334 gtk_application_window_real_forall_internal (GtkContainer *container,
335 gboolean include_internal,
336 GtkCallback callback,
339 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (container);
341 if (window->priv->menubar)
342 callback (GTK_WIDGET (window->priv->menubar), user_data);
344 GTK_CONTAINER_CLASS (gtk_application_window_parent_class)
345 ->forall (container, include_internal, callback, user_data);
350 gtk_application_window_get_property (GObject *object,
355 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
359 case PROP_SHOW_APP_MENU:
360 g_value_set_boolean (value, window->priv->override_show_app_menu);
364 g_assert_not_reached ();
369 gtk_application_window_set_property (GObject *object,
374 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
378 case PROP_SHOW_APP_MENU:
379 gtk_application_window_set_show_app_menu (window, g_value_get_boolean (value));
383 g_assert_not_reached ();
388 gtk_application_window_dispose (GObject *object)
390 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
392 g_clear_object (&window->priv->menubar);
393 g_clear_object (&window->priv->actions);
395 G_OBJECT_CLASS (gtk_application_window_parent_class)
400 gtk_application_window_init (GtkApplicationWindow *window)
402 window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window, GTK_TYPE_APPLICATION_WINDOW, GtkApplicationWindowPrivate);
404 window->priv->actions = g_simple_action_group_new ();
406 /* window->priv->actions is the one and only ref on the group, so when
407 * we dispose, the action group will die, disconnecting all signals.
409 g_signal_connect_swapped (window->priv->actions, "action-added",
410 G_CALLBACK (g_action_group_action_added), window);
411 g_signal_connect_swapped (window->priv->actions, "action-enabled-changed",
412 G_CALLBACK (g_action_group_action_enabled_changed), window);
413 g_signal_connect_swapped (window->priv->actions, "action-state-changed",
414 G_CALLBACK (g_action_group_action_state_changed), window);
415 g_signal_connect_swapped (window->priv->actions, "action-removed",
416 G_CALLBACK (g_action_group_action_removed), window);
420 gtk_application_window_class_init (GtkApplicationWindowClass *class)
422 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
423 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
424 GObjectClass *object_class = G_OBJECT_CLASS (class);
426 container_class->forall = gtk_application_window_real_forall_internal;
427 widget_class->get_preferred_height = gtk_application_window_real_get_preferred_height;
428 widget_class->get_preferred_height_for_width = gtk_application_window_real_get_preferred_height_for_width;
429 widget_class->get_preferred_width = gtk_application_window_real_get_preferred_width;
430 widget_class->get_preferred_width_for_height = gtk_application_window_real_get_preferred_width_for_height;
431 widget_class->size_allocate = gtk_application_window_real_size_allocate;
432 widget_class->realize = gtk_application_window_real_realize;
433 widget_class->map = gtk_application_window_real_map;
434 object_class->get_property = gtk_application_window_get_property;
435 object_class->set_property = gtk_application_window_set_property;
436 object_class->dispose = gtk_application_window_dispose;
438 gtk_application_window_properties[PROP_SHOW_APP_MENU] =
439 g_param_spec_boolean ("show-app-menu",
440 P_("Show application menu"),
441 P_("TRUE if the application menu should be included "
442 "in the menubar at the top of the window"),
443 FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
444 g_object_class_install_properties (object_class, N_PROPS, gtk_application_window_properties);
445 g_type_class_add_private (class, sizeof (GtkApplicationWindowPrivate));
449 * gtk_application_window_new:
450 * @application: a #GtkApplication
452 * Creates a new #GtkApplicationWindow.
454 * Returns: a newly created #GtkApplicationWindow
459 gtk_application_window_new (GtkApplication *application)
461 g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
463 return g_object_new (GTK_TYPE_APPLICATION_WINDOW,
464 "application", application,
469 gtk_application_window_get_show_app_menu (GtkApplicationWindow *window)
471 return window->priv->override_show_app_menu;
475 recalculate_app_menu_state (GtkApplicationWindow *window)
477 if ((window->priv->did_override_show_app_menu
478 && window->priv->override_show_app_menu)
479 || window->priv->default_show_app_menu)
484 item = gtk_menu_item_new_with_label (_("Application"));
485 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), gtk_application_window_get_app_menu (window));
487 menubar = gtk_menu_bar_new ();
488 window->priv->menubar = g_object_ref_sink (menubar);
489 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), item);
490 gtk_widget_set_parent (menubar, GTK_WIDGET (window));
491 gtk_widget_show_all (menubar);
495 if (window->priv->menubar)
496 gtk_widget_unparent (GTK_WIDGET (window->priv->menubar));
497 g_clear_object (&window->priv->menubar);
502 gtk_application_window_set_show_app_menu (GtkApplicationWindow *window,
503 gboolean show_app_menu)
505 show_app_menu = !!show_app_menu;
506 window->priv->did_override_show_app_menu = TRUE;
507 if (window->priv->override_show_app_menu != show_app_menu)
509 window->priv->override_show_app_menu = show_app_menu;
510 recalculate_app_menu_state (window);
511 g_object_notify_by_pspec (G_OBJECT (window), gtk_application_window_properties[PROP_SHOW_APP_MENU]);
515 /* GtkMenu construction {{{1 */
521 gulong enabled_changed_id;
522 gulong state_changed_id;
523 gulong activate_handler;
527 action_data_free (gpointer data)
529 ActionData *a = data;
531 if (a->enabled_changed_id)
532 g_signal_handler_disconnect (a->group, a->enabled_changed_id);
534 if (a->state_changed_id)
535 g_signal_handler_disconnect (a->group, a->state_changed_id);
537 g_object_unref (a->group);
545 enabled_changed (GActionGroup *group,
546 const gchar *action_name,
550 gtk_widget_set_sensitive (widget, enabled);
554 item_activated (GtkWidget *w,
560 a = g_object_get_data (G_OBJECT (w), "action");
562 parameter = g_variant_ref_sink (g_variant_new_string (a->target));
565 g_action_group_activate_action (a->group, a->name, parameter);
567 g_variant_unref (parameter);
571 toggle_state_changed (GActionGroup *group,
578 a = g_object_get_data (G_OBJECT (w), "action");
579 g_signal_handler_block (w, a->activate_handler);
580 gtk_check_menu_item_set_active (w, g_variant_get_boolean (state));
581 g_signal_handler_unblock (w, a->activate_handler);
585 radio_state_changed (GActionGroup *group,
593 a = g_object_get_data (G_OBJECT (w), "action");
594 g_signal_handler_block (w, a->activate_handler);
595 b = g_strcmp0 (a->target, g_variant_get_string (state, NULL)) == 0;
596 gtk_check_menu_item_set_active (w, b);
597 g_signal_handler_unblock (w, a->activate_handler);
601 create_menuitem_from_model (GMenuModel *model,
611 const GVariantType *type;
615 g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_LABEL, "s", &label);
618 g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_ACTION, "s", &action);
621 type = g_action_group_get_action_state_type (group, action);
626 w = gtk_menu_item_new_with_label (label);
627 else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
628 w = gtk_check_menu_item_new_with_label (label);
629 else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
631 w = gtk_check_menu_item_new_with_label (label);
632 gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (w), TRUE);
635 g_assert_not_reached ();
637 gtk_menu_item_set_use_underline (GTK_MENU_ITEM (w), TRUE);
641 a = g_new0 (ActionData, 1);
642 a->group = g_object_ref (group);
643 a->name = g_strdup (action);
644 g_object_set_data_full (G_OBJECT (w), "action", a, action_data_free);
646 if (!g_action_group_get_action_enabled (group, action))
647 gtk_widget_set_sensitive (w, FALSE);
649 s = g_strconcat ("action-enabled-changed::", action, NULL);
650 a->enabled_changed_id = g_signal_connect (group, s,
651 G_CALLBACK (enabled_changed), w);
653 a->activate_handler = g_signal_connect (w, "activate",
654 G_CALLBACK (item_activated), NULL);
660 else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
662 s = g_strconcat ("action-state-changed::", action, NULL);
663 a->state_changed_id = g_signal_connect (group, s,
664 G_CALLBACK (toggle_state_changed), w);
666 v = g_action_group_get_action_state (group, action);
667 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
668 g_variant_get_boolean (v));
671 else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
673 s = g_strconcat ("action-state-changed::", action, NULL);
674 a->state_changed_id = g_signal_connect (group, s,
675 G_CALLBACK (radio_state_changed), w);
677 g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_TARGET, "s", &target);
678 a->target = g_strdup (target);
679 v = g_action_group_get_action_state (group, action);
680 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
681 g_strcmp0 (g_variant_get_string (v, NULL), target) == 0);
686 g_assert_not_reached ();
695 static void populate_menu_from_model (GtkMenuShell *menu,
697 GActionGroup *group);
700 append_items_from_model (GtkMenuShell *menu,
703 gboolean *need_separator,
704 const gchar *heading)
714 n = g_menu_model_get_n_items (model);
716 if (*need_separator && n > 0)
718 w = gtk_separator_menu_item_new ();
720 gtk_menu_shell_append (menu, w);
721 *need_separator = FALSE;
726 w = gtk_menu_item_new_with_label (heading);
728 gtk_widget_set_sensitive (w, FALSE);
729 gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
732 for (i = 0; i < n; i++)
734 if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION)))
737 g_menu_model_get_item_attribute (model, i, G_MENU_ATTRIBUTE_LABEL, "s", &label);
738 append_items_from_model (menu, m, group, need_separator, label);
746 w = gtk_separator_menu_item_new ();
748 gtk_menu_shell_append (menu, w);
749 *need_separator = FALSE;
752 menuitem = create_menuitem_from_model (model, i, group);
754 if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU)))
756 submenu = gtk_menu_new ();
757 populate_menu_from_model (GTK_MENU_SHELL (submenu), m, group);
758 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
762 gtk_widget_show (menuitem);
763 gtk_menu_shell_append (menu, menuitem);
765 *need_separator = TRUE;
770 populate_menu_from_model (GtkMenuShell *menu,
774 gboolean need_separator;
776 need_separator = FALSE;
777 append_items_from_model (menu, model, group, &need_separator, NULL);
781 GtkApplication *application;
784 GHashTable *connected;
788 free_items_changed_data (gpointer data)
790 ItemsChangedData *d = data;
792 g_object_unref (d->application);
794 if (d->update_idle != 0)
795 g_source_remove (d->update_idle);
797 g_hash_table_unref (d->connected);
803 repopulate_menu (gpointer data)
805 ItemsChangedData *d = data;
810 /* remove current children */
811 children = gtk_container_get_children (GTK_CONTAINER (d->menu));
812 for (l = children; l; l = l->next)
815 gtk_container_remove (GTK_CONTAINER (d->menu), child);
817 g_list_free (children);
820 model = g_application_get_app_menu (G_APPLICATION (d->application));
821 populate_menu_from_model (d->menu, model, G_ACTION_GROUP (d->application));
829 connect_to_items_changed (GMenuModel *model,
833 ItemsChangedData *d = data;
838 if (!g_hash_table_lookup (d->connected, model))
840 g_signal_connect (model, "items-changed", callback, data);
841 g_hash_table_insert (d->connected, model, model);
844 for (i = 0; i < g_menu_model_get_n_items (model); i++)
846 iter = g_menu_model_iterate_item_links (model, i);
847 while (g_menu_link_iter_next (iter))
849 m = g_menu_link_iter_get_value (iter);
850 connect_to_items_changed (m, callback, data);
853 g_object_unref (iter);
858 items_changed (GMenuModel *model,
864 ItemsChangedData *d = data;
866 if (d->update_idle == 0)
867 d->update_idle = gdk_threads_add_idle (repopulate_menu, data);
868 connect_to_items_changed (model, G_CALLBACK (items_changed), data);
872 * gtk_application_window_get_app_menu:
873 * @window: a #GtkApplicationWindow
875 * Populates a menu widget from a menu model that is
876 * associated with @window. See g_application_set_menu().
877 * The menu items will be connected to actions of @window or
878 * its associated #GtkApplication, as indicated by the menu model.
879 * The menus contents will be updated automatically in response
880 * to menu model changes.
882 * It is the callers responsibility to add the menu at a
883 * suitable place in the widget hierarchy.
885 * This function returns %NULL if @window has no associated
888 * Returns: A #GtkMenu that has been populated from the
889 * #GMenuModel that is associated with @window, or %NULL
892 gtk_application_window_get_app_menu (GtkApplicationWindow *window)
894 GtkApplication *application;
897 ItemsChangedData *data;
900 application = gtk_window_get_application (GTK_WINDOW (window));
902 model = g_application_get_app_menu (G_APPLICATION (application));
907 menu = gtk_menu_new ();
909 muxer = g_action_muxer_new ();
910 g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (application));
911 g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
912 populate_menu_from_model (GTK_MENU_SHELL (menu), model, G_ACTION_GROUP (muxer));
913 g_object_unref (muxer);
915 data = g_new (ItemsChangedData, 1);
916 data->application = g_object_ref (application);
917 data->menu = GTK_MENU_SHELL (menu);
918 data->update_idle = 0;
919 data->connected = g_hash_table_new (NULL, NULL);
921 g_object_set_data_full (G_OBJECT (menu), "gtk-application-menu-data",
922 data, free_items_changed_data);
924 connect_to_items_changed (model, G_CALLBACK (items_changed), data);