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"
32 * SECTION:gtkapplicationwindow
33 * @title: GtkApplicationWindow
34 * @short_description: GtkWindow subclass with GtkApplication support
36 * GtkApplicationWindow is a #GtkWindow subclass that offers some extra
37 * functionality for better integration with #GtkApplication features.
38 * It implements the #GActionGroup and #GActionMap interfaces, to let
39 * you add window-specific actions that will be exported by the associated
40 * #GtkApplication, together with its application-wide actions.
41 * Window-specific actions are prefixed with the "win." prefix and
42 * application-wide actions are prefixed with the "app." prefix.
43 * Actions must be addressed with the prefixed name when referring
44 * to them from a #GMenuModel.
46 * If the desktop environment does not display the application menu
47 * as part of the desktop shell, then #GApplicationWindow will
48 * automatically show the menu as part of a menubar. This behaviour
49 * can be overridden with the #GtkApplicationWindow:show-app-menu
53 struct _GtkApplicationWindowPrivate
55 GSimpleActionGroup *actions;
58 guint initialized_app_menu : 1;
59 guint default_show_app_menu : 1;
60 guint did_override_show_app_menu : 1;
61 guint override_show_app_menu : 1;
65 recalculate_app_menu_state (GtkApplicationWindow *window);
68 on_shell_shows_app_menu_changed (GtkSettings *settings,
72 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (user_data);
75 g_object_get (settings, "gtk-shell-shows-app-menu", &val, NULL);
76 window->priv->default_show_app_menu = !val;
77 recalculate_app_menu_state (window);
81 gtk_application_window_list_actions (GActionGroup *group)
83 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
85 return g_action_group_list_actions (G_ACTION_GROUP (window->priv->actions));
89 gtk_application_window_query_action (GActionGroup *group,
90 const gchar *action_name,
92 const GVariantType **parameter_type,
93 const GVariantType **state_type,
94 GVariant **state_hint,
97 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
99 return g_action_group_query_action (G_ACTION_GROUP (window->priv->actions),
100 action_name, enabled, parameter_type, state_type, state_hint, state);
104 gtk_application_window_activate_action (GActionGroup *group,
105 const gchar *action_name,
108 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
110 return g_action_group_activate_action (G_ACTION_GROUP (window->priv->actions), action_name, parameter);
114 gtk_application_window_change_action_state (GActionGroup *group,
115 const gchar *action_name,
118 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
120 return g_action_group_change_action_state (G_ACTION_GROUP (window->priv->actions), action_name, state);
124 gtk_application_window_lookup_action (GActionMap *action_map,
125 const gchar *action_name)
127 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
129 return g_action_map_lookup_action (G_ACTION_MAP (window->priv->actions), action_name);
133 gtk_application_window_add_action (GActionMap *action_map,
136 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
138 g_action_map_add_action (G_ACTION_MAP (window->priv->actions), action);
142 gtk_application_window_remove_action (GActionMap *action_map,
143 const gchar *action_name)
145 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
147 g_action_map_remove_action (G_ACTION_MAP (window->priv->actions), action_name);
151 gtk_application_window_group_iface_init (GActionGroupInterface *iface)
153 iface->list_actions = gtk_application_window_list_actions;
154 iface->query_action = gtk_application_window_query_action;
155 iface->activate_action = gtk_application_window_activate_action;
156 iface->change_action_state = gtk_application_window_change_action_state;
160 gtk_application_window_map_iface_init (GActionMapInterface *iface)
162 iface->lookup_action = gtk_application_window_lookup_action;
163 iface->add_action = gtk_application_window_add_action;
164 iface->remove_action = gtk_application_window_remove_action;
167 G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindow, gtk_application_window, GTK_TYPE_WINDOW,
168 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, gtk_application_window_group_iface_init)
169 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, gtk_application_window_map_iface_init))
176 static GParamSpec *gtk_application_window_properties[N_PROPS];
179 gtk_application_window_real_get_preferred_height (GtkWidget *widget,
180 gint *minimum_height,
181 gint *natural_height)
183 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
185 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
186 ->get_preferred_height (widget, minimum_height, natural_height);
188 if (window->priv->menubar != NULL)
190 gint menubar_min_height, menubar_nat_height;
192 gtk_widget_get_preferred_height (GTK_WIDGET (window->priv->menubar), &menubar_min_height, &menubar_nat_height);
193 *minimum_height += menubar_min_height;
194 *natural_height += menubar_nat_height;
199 gtk_application_window_real_get_preferred_height_for_width (GtkWidget *widget,
201 gint *minimum_height,
202 gint *natural_height)
204 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
206 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
207 ->get_preferred_height_for_width (widget, width, minimum_height, natural_height);
209 if (window->priv->menubar != NULL)
211 gint menubar_min_height, menubar_nat_height;
213 gtk_widget_get_preferred_height_for_width (GTK_WIDGET (window->priv->menubar), width, &menubar_min_height, &menubar_nat_height);
214 *minimum_height += menubar_min_height;
215 *natural_height += menubar_nat_height;
220 gtk_application_window_real_get_preferred_width (GtkWidget *widget,
224 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
226 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
227 ->get_preferred_width (widget, minimum_width, natural_width);
229 if (window->priv->menubar != NULL)
231 gint menubar_min_width, menubar_nat_width;
233 gtk_widget_get_preferred_width (GTK_WIDGET (window->priv->menubar), &menubar_min_width, &menubar_nat_width);
234 *minimum_width = MAX (*minimum_width, menubar_min_width);
235 *natural_width = MAX (*natural_width, menubar_nat_width);
240 gtk_application_window_real_get_preferred_width_for_height (GtkWidget *widget,
245 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
247 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
248 ->get_preferred_width_for_height (widget, height, minimum_width, natural_width);
250 if (window->priv->menubar != NULL)
252 gint menubar_min_width, menubar_nat_width;
254 gtk_widget_get_preferred_width_for_height (GTK_WIDGET (window->priv->menubar), height, &menubar_min_width, &menubar_nat_width);
255 *minimum_width = MAX (*minimum_width, menubar_min_width);
256 *natural_width = MAX (*natural_width, menubar_nat_width);
261 gtk_application_window_real_size_allocate (GtkWidget *widget,
262 GtkAllocation *allocation)
264 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
266 if (window->priv->menubar != NULL)
268 GtkAllocation menubar_allocation = *allocation;
269 gint menubar_min_height, menubar_nat_height;
272 gtk_widget_get_preferred_height_for_width (GTK_WIDGET (window->priv->menubar), allocation->width, &menubar_min_height, &menubar_nat_height);
274 menubar_allocation.height = menubar_min_height;
275 gtk_widget_size_allocate (GTK_WIDGET (window->priv->menubar), &menubar_allocation);
277 child = gtk_bin_get_child (GTK_BIN (window));
278 if (child != NULL && gtk_widget_get_visible (child))
280 GtkAllocation child_allocation = *allocation;
283 child_allocation.height = MAX (1, child_allocation.height - menubar_min_height);
285 border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
286 child_allocation.x += border_width;
287 child_allocation.y += border_width + menubar_min_height;
288 child_allocation.width -= border_width * 2;
289 child_allocation.height -= border_width * 2 - menubar_min_height;
290 gtk_widget_size_allocate (child, &child_allocation);
293 gtk_widget_set_allocation (widget, allocation);
296 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
297 ->size_allocate (widget, allocation);
301 gtk_application_window_real_realize (GtkWidget *widget)
303 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
305 if (!window->priv->initialized_app_menu)
307 window->priv->initialized_app_menu = TRUE;
308 g_signal_connect (gtk_widget_get_settings ((GtkWidget*)window),
309 "notify::gtk-shell-shows-app-menu",
310 G_CALLBACK (on_shell_shows_app_menu_changed),
312 on_shell_shows_app_menu_changed (gtk_widget_get_settings ((GtkWidget*)window), NULL, window);
315 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
320 gtk_application_window_real_map (GtkWidget *widget)
322 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
324 /* XXX could elimate this by tweaking gtk_window_map */
325 if (window->priv->menubar)
326 gtk_widget_map (GTK_WIDGET (window->priv->menubar));
328 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
333 gtk_application_window_real_forall_internal (GtkContainer *container,
334 gboolean include_internal,
335 GtkCallback callback,
338 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (container);
340 if (window->priv->menubar)
341 callback (GTK_WIDGET (window->priv->menubar), user_data);
343 GTK_CONTAINER_CLASS (gtk_application_window_parent_class)
344 ->forall (container, include_internal, callback, user_data);
349 gtk_application_window_get_property (GObject *object, guint prop_id,
350 GValue *value, GParamSpec *pspec)
352 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
356 case PROP_SHOW_APP_MENU:
357 g_value_set_boolean (value, window->priv->override_show_app_menu);
361 g_assert_not_reached ();
366 gtk_application_window_set_property (GObject *object, guint prop_id,
367 const GValue *value, GParamSpec *pspec)
369 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
373 case PROP_SHOW_APP_MENU:
374 gtk_application_window_set_show_app_menu (window, g_value_get_boolean (value));
378 g_assert_not_reached ();
383 gtk_application_window_dispose (GObject *object)
385 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
387 g_clear_object (&window->priv->menubar);
388 g_clear_object (&window->priv->actions);
390 G_OBJECT_CLASS (gtk_application_window_parent_class)
395 gtk_application_window_init (GtkApplicationWindow *window)
397 window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window, GTK_TYPE_APPLICATION_WINDOW, GtkApplicationWindowPrivate);
399 window->priv->actions = g_simple_action_group_new ();
401 /* window->priv->actions is the one and only ref on the group, so when
402 * we dispose, the action group will die, disconnecting all signals.
404 g_signal_connect_swapped (window->priv->actions, "action-added",
405 G_CALLBACK (g_action_group_action_added), window);
406 g_signal_connect_swapped (window->priv->actions, "action-enabled-changed",
407 G_CALLBACK (g_action_group_action_enabled_changed), window);
408 g_signal_connect_swapped (window->priv->actions, "action-state-changed",
409 G_CALLBACK (g_action_group_action_state_changed), window);
410 g_signal_connect_swapped (window->priv->actions, "action-removed",
411 G_CALLBACK (g_action_group_action_removed), window);
415 gtk_application_window_class_init (GtkApplicationWindowClass *class)
417 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
418 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
419 GObjectClass *object_class = G_OBJECT_CLASS (class);
421 container_class->forall = gtk_application_window_real_forall_internal;
422 widget_class->get_preferred_height = gtk_application_window_real_get_preferred_height;
423 widget_class->get_preferred_height_for_width = gtk_application_window_real_get_preferred_height_for_width;
424 widget_class->get_preferred_width = gtk_application_window_real_get_preferred_width;
425 widget_class->get_preferred_width_for_height = gtk_application_window_real_get_preferred_width_for_height;
426 widget_class->size_allocate = gtk_application_window_real_size_allocate;
427 widget_class->realize = gtk_application_window_real_realize;
428 widget_class->map = gtk_application_window_real_map;
429 object_class->get_property = gtk_application_window_get_property;
430 object_class->set_property = gtk_application_window_set_property;
431 object_class->dispose = gtk_application_window_dispose;
433 gtk_application_window_properties[PROP_SHOW_APP_MENU] =
434 g_param_spec_boolean ("show-app-menu", "show application menu",
435 "TRUE if the application menu should be included in the menubar at the top of the window",
436 FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
437 g_object_class_install_properties (object_class, N_PROPS, gtk_application_window_properties);
438 g_type_class_add_private (class, sizeof (GtkApplicationWindowPrivate));
442 gtk_application_window_new (GtkApplication *application)
444 g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
446 return g_object_new (GTK_TYPE_APPLICATION_WINDOW,
447 "application", application,
452 gtk_application_window_get_show_app_menu (GtkApplicationWindow *window)
454 return window->priv->override_show_app_menu;
458 recalculate_app_menu_state (GtkApplicationWindow *window)
460 if ((window->priv->did_override_show_app_menu
461 && window->priv->override_show_app_menu)
462 || window->priv->default_show_app_menu)
467 item = gtk_menu_item_new_with_label ("Application");
468 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), gtk_application_window_get_app_menu (window));
470 menubar = gtk_menu_bar_new ();
471 window->priv->menubar = g_object_ref_sink (menubar);
472 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), item);
473 gtk_widget_set_parent (menubar, GTK_WIDGET (window));
474 gtk_widget_show_all (menubar);
478 gtk_widget_unparent (GTK_WIDGET (window->priv->menubar));
479 g_object_unref (window->priv->menubar);
484 gtk_application_window_set_show_app_menu (GtkApplicationWindow *window,
485 gboolean show_app_menu)
487 show_app_menu = !!show_app_menu;
488 window->priv->did_override_show_app_menu = TRUE;
489 if (window->priv->override_show_app_menu != show_app_menu)
491 window->priv->override_show_app_menu = show_app_menu;
492 recalculate_app_menu_state (window);
493 g_object_notify_by_pspec (G_OBJECT (window), gtk_application_window_properties[PROP_SHOW_APP_MENU]);
497 /* GtkMenu construction {{{1 */
503 gulong enabled_changed_id;
504 gulong state_changed_id;
505 gulong activate_handler;
509 action_data_free (gpointer data)
511 ActionData *a = data;
513 if (a->enabled_changed_id)
514 g_signal_handler_disconnect (a->group, a->enabled_changed_id);
516 if (a->state_changed_id)
517 g_signal_handler_disconnect (a->group, a->state_changed_id);
519 g_object_unref (a->group);
527 enabled_changed (GActionGroup *group,
528 const gchar *action_name,
532 gtk_widget_set_sensitive (widget, enabled);
536 item_activated (GtkWidget *w,
542 a = g_object_get_data (G_OBJECT (w), "action");
544 parameter = g_variant_ref_sink (g_variant_new_string (a->target));
547 g_action_group_activate_action (a->group, a->name, parameter);
549 g_variant_unref (parameter);
553 toggle_state_changed (GActionGroup *group,
560 a = g_object_get_data (G_OBJECT (w), "action");
561 g_signal_handler_block (w, a->activate_handler);
562 gtk_check_menu_item_set_active (w, g_variant_get_boolean (state));
563 g_signal_handler_unblock (w, a->activate_handler);
567 radio_state_changed (GActionGroup *group,
575 a = g_object_get_data (G_OBJECT (w), "action");
576 g_signal_handler_block (w, a->activate_handler);
577 b = g_strcmp0 (a->target, g_variant_get_string (state, NULL)) == 0;
578 gtk_check_menu_item_set_active (w, b);
579 g_signal_handler_unblock (w, a->activate_handler);
583 create_menuitem_from_model (GMenuModel *model,
593 const GVariantType *type;
597 g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_LABEL, "s", &label);
600 g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_ACTION, "s", &action);
603 type = g_action_group_get_action_state_type (group, action);
608 w = gtk_menu_item_new_with_mnemonic (label);
609 else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
610 w = gtk_check_menu_item_new_with_label (label);
611 else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
613 w = gtk_check_menu_item_new_with_label (label);
614 gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (w), TRUE);
617 g_assert_not_reached ();
621 a = g_new0 (ActionData, 1);
622 a->group = g_object_ref (group);
623 a->name = g_strdup (action);
624 g_object_set_data_full (G_OBJECT (w), "action", a, action_data_free);
626 if (!g_action_group_get_action_enabled (group, action))
627 gtk_widget_set_sensitive (w, FALSE);
629 s = g_strconcat ("action-enabled-changed::", action, NULL);
630 a->enabled_changed_id = g_signal_connect (group, s,
631 G_CALLBACK (enabled_changed), w);
633 a->activate_handler = g_signal_connect (w, "activate",
634 G_CALLBACK (item_activated), NULL);
640 else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
642 s = g_strconcat ("action-state-changed::", action, NULL);
643 a->state_changed_id = g_signal_connect (group, s,
644 G_CALLBACK (toggle_state_changed), w);
646 v = g_action_group_get_action_state (group, action);
647 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
648 g_variant_get_boolean (v));
651 else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
653 s = g_strconcat ("action-state-changed::", action, NULL);
654 a->state_changed_id = g_signal_connect (group, s,
655 G_CALLBACK (radio_state_changed), w);
657 g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_TARGET, "s", &target);
658 a->target = g_strdup (target);
659 v = g_action_group_get_action_state (group, action);
660 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
661 g_strcmp0 (g_variant_get_string (v, NULL), target) == 0);
666 g_assert_not_reached ();
675 static void populate_menu_from_model (GtkMenuShell *menu,
677 GActionGroup *group);
680 append_items_from_model (GtkMenuShell *menu,
683 gboolean *need_separator,
684 const gchar *heading)
694 n = g_menu_model_get_n_items (model);
696 if (*need_separator && n > 0)
698 w = gtk_separator_menu_item_new ();
700 gtk_menu_shell_append (menu, w);
701 *need_separator = FALSE;
706 w = gtk_menu_item_new_with_label (heading);
708 gtk_widget_set_sensitive (w, FALSE);
709 gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
712 for (i = 0; i < n; i++)
714 if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION)))
717 g_menu_model_get_item_attribute (model, i, G_MENU_ATTRIBUTE_LABEL, "s", &label);
718 append_items_from_model (menu, m, group, need_separator, label);
726 w = gtk_separator_menu_item_new ();
728 gtk_menu_shell_append (menu, w);
729 *need_separator = FALSE;
732 menuitem = create_menuitem_from_model (model, i, group);
734 if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU)))
736 submenu = gtk_menu_new ();
737 populate_menu_from_model (GTK_MENU_SHELL (submenu), m, group);
738 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
742 gtk_widget_show (menuitem);
743 gtk_menu_shell_append (menu, menuitem);
745 *need_separator = TRUE;
750 populate_menu_from_model (GtkMenuShell *menu,
754 gboolean need_separator;
756 need_separator = FALSE;
757 append_items_from_model (menu, model, group, &need_separator, NULL);
761 GtkApplication *application;
764 GHashTable *connected;
768 free_items_changed_data (gpointer data)
770 ItemsChangedData *d = data;
772 g_object_unref (d->application);
774 if (d->update_idle != 0)
775 g_source_remove (d->update_idle);
777 g_hash_table_unref (d->connected);
783 repopulate_menu (gpointer data)
785 ItemsChangedData *d = data;
790 /* remove current children */
791 children = gtk_container_get_children (GTK_CONTAINER (d->menu));
792 for (l = children; l; l = l->next)
795 gtk_container_remove (GTK_CONTAINER (d->menu), child);
797 g_list_free (children);
800 model = g_application_get_menu (G_APPLICATION (d->application));
801 populate_menu_from_model (d->menu, model, G_ACTION_GROUP (d->application));
809 connect_to_items_changed (GMenuModel *model,
813 ItemsChangedData *d = data;
818 if (!g_hash_table_lookup (d->connected, model))
820 g_signal_connect (model, "items-changed", callback, data);
821 g_hash_table_insert (d->connected, model, model);
824 for (i = 0; i < g_menu_model_get_n_items (model); i++)
826 iter = g_menu_model_iterate_item_links (model, i);
827 while (g_menu_link_iter_next (iter))
829 m = g_menu_link_iter_get_value (iter);
830 connect_to_items_changed (m, callback, data);
833 g_object_unref (iter);
838 items_changed (GMenuModel *model,
844 ItemsChangedData *d = data;
846 if (d->update_idle == 0)
847 d->update_idle = gdk_threads_add_idle (repopulate_menu, data);
848 connect_to_items_changed (model, G_CALLBACK (items_changed), data);
852 * gtk_application_window_get_app_menu:
853 * @window: a #GtkApplicationWindow
855 * Populates a menu widget from a menu model that is
856 * associated with @window. See g_application_set_menu().
857 * The menu items will be connected to actions of @window or
858 * its associated #GtkApplication, as indicated by the menu model.
859 * The menus contents will be updated automatically in response
860 * to menu model changes.
862 * It is the callers responsibility to add the menu at a
863 * suitable place in the widget hierarchy.
865 * This function returns %NULL if @window has no associated
868 * @menu may be a #GtkMenu or a #GtkMenuBar.
870 * Returns: A #GtkMenu that has been populated from the
871 * #GMenuModel that is associated with @window, or %NULL
874 gtk_application_window_get_app_menu (GtkApplicationWindow *window)
876 GtkApplication *application;
879 ItemsChangedData *data;
882 application = gtk_window_get_application (GTK_WINDOW (window));
884 model = g_application_get_menu (G_APPLICATION (application));
889 menu = gtk_menu_new ();
891 muxer = g_action_muxer_new ();
892 g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (application));
893 g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
894 populate_menu_from_model (GTK_MENU_SHELL (menu), model, G_ACTION_GROUP (muxer));
895 g_object_unref (muxer);
897 data = g_new (ItemsChangedData, 1);
898 data->application = g_object_ref (application);
899 data->menu = GTK_MENU_SHELL (menu);
900 data->update_idle = 0;
901 data->connected = g_hash_table_new (NULL, NULL);
903 g_object_set_data_full (G_OBJECT (menu), "gtk-application-menu-data",
904 data, free_items_changed_data);
906 connect_to_items_changed (model, G_CALLBACK (items_changed), data);