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 "gtkmodelmenu.h"
27 #include "gactionmuxer.h"
28 #include "gtkaccelgroup.h"
29 #include "gtkaccelmap.h"
33 * SECTION:gtkapplicationwindow
34 * @title: GtkApplicationWindow
35 * @short_description: GtkWindow subclass with GtkApplication support
37 * GtkApplicationWindow is a #GtkWindow subclass that offers some
38 * extra functionality for better integration with #GtkApplication
39 * features. Notably, it can handle both the application menu as well
40 * as the menubar. See g_application_set_app_menu() and
41 * g_application_set_menubar().
43 * This class implements the #GActionGroup and #GActionMap interfaces,
44 * to let you add window-specific actions that will be exported by the
45 * associated #GtkApplication, together with its application-wide
46 * actions. Window-specific actions are prefixed with the "win."
47 * prefix and application-wide actions are prefixed with the "app."
48 * prefix. Actions must be addressed with the prefixed name when
49 * referring to them from a #GMenuModel.
51 * The settings #GtkSettings:gtk-shell-shows-app-menu and
52 * #GtkSettings:gtk-shell-shows-menubar tell GTK+ whether the
53 * desktop environment is showing the application menu and menubar
54 * models outside the application as part of the desktop shell.
55 * For instance, on OS X, both menus will be displayed remotely;
56 * on Windows neither will be. gnome-shell (starting with version 3.4)
57 * will display the application menu, but not the menubar.
59 * If the desktop environment does not display the menubar, then
60 * #GApplicationWindow will automatically show a #GtkMenubar for it.
61 * This behaviour can be overridden with the #GtkApplicationWindow:show-menubar
62 * property. If the desktop environment does not display the application
63 * menu, then it will automatilly be included in the menubar.
65 * <example><title>A GtkApplicationWindow with a menubar</title>
66 * <programlisting><![CDATA[
67 * app = gtk_application_new ();
69 * builder = gtk_builder_new ();
70 * gtk_builder_add_from_string (builder,
72 * " <menu id='menubar'>"
73 * " <submenu label='_Edit'>"
74 * " <item label='_Copy' action='win.copy'/>"
75 * " <item label='_Paste' action='win.paste'/>"
79 * g_application_set_menubar (G_APPLICATION (app),
80 * G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
81 * g_object_unref (builder);
85 * window = gtk_application_window_new (app);
90 struct _GtkApplicationWindowPrivate
92 GSimpleActionGroup *actions;
94 GtkAccelGroup *accels;
95 GSList *accel_closures;
97 GMenu *app_menu_section;
98 GMenu *menubar_section;
99 gboolean show_menubar;
103 gtk_application_window_update_menubar (GtkApplicationWindow *window)
105 gboolean should_have_menubar;
106 gboolean have_menubar;
108 have_menubar = window->priv->menubar != NULL;
110 should_have_menubar = window->priv->show_menubar &&
111 (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) ||
112 g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)));
114 if (have_menubar && !should_have_menubar)
116 gtk_widget_unparent (window->priv->menubar);
117 window->priv->menubar = NULL;
119 gtk_widget_queue_resize (GTK_WIDGET (window));
122 if (!have_menubar && should_have_menubar)
127 muxer = g_action_muxer_new ();
128 g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (gtk_window_get_application (GTK_WINDOW (window))));
129 g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
131 combined = g_menu_new ();
132 g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->app_menu_section));
133 g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->menubar_section));
135 window->priv->menubar = gtk_model_menu_create_menu_bar (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (muxer), window->priv->accels);
136 gtk_widget_set_parent (window->priv->menubar, GTK_WIDGET (window));
137 gtk_widget_show_all (window->priv->menubar);
138 g_object_unref (combined);
139 g_object_unref (muxer);
141 gtk_widget_queue_resize (GTK_WIDGET (window));
146 gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window,
147 GtkSettings *settings)
149 gboolean shown_by_shell;
151 g_object_get (settings, "gtk-shell-shows-app-menu", &shown_by_shell, NULL);
155 /* the shell shows it, so don't show it locally */
156 if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) != 0)
157 g_menu_remove (window->priv->app_menu_section, 0);
161 /* the shell does not show it, so make sure we show it */
162 if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) == 0)
164 GMenuModel *app_menu;
166 app_menu = g_application_get_app_menu (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
168 if (app_menu != NULL)
169 g_menu_append_submenu (window->priv->app_menu_section, _("Application"), app_menu);
175 gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
176 GtkSettings *settings)
178 gboolean shown_by_shell;
180 g_object_get (settings, "gtk-shell-shows-menubar", &shown_by_shell, NULL);
184 /* the shell shows it, so don't show it locally */
185 if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)) != 0)
186 g_menu_remove (window->priv->menubar_section, 0);
190 /* the shell does not show it, so make sure we show it */
191 if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)) == 0)
195 menubar = g_application_get_menubar (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
198 g_menu_append_section (window->priv->menubar_section, NULL, menubar);
210 accel_activate (GClosure *closure,
211 GValue *return_value,
212 guint n_param_values,
213 const GValue *param_values,
214 gpointer invocation_hint,
215 gpointer marshal_data)
217 AccelClosure *aclosure = (AccelClosure*)closure;
218 GActionGroup *actions;
220 actions = G_ACTION_GROUP (closure->data);
221 if (g_action_group_get_action_enabled (actions, aclosure->action_name))
223 g_action_group_activate_action (actions, aclosure->action_name, aclosure->parameter);
225 /* we handled the accelerator */
226 g_value_set_boolean (return_value, TRUE);
231 free_accel_closures (GtkApplicationWindow *window)
235 for (l = window->priv->accel_closures; l; l = l->next)
237 AccelClosure *closure = l->data;
239 gtk_accel_group_disconnect (window->priv->accels, &closure->closure);
241 g_object_unref (closure->closure.data);
242 if (closure->parameter)
243 g_variant_unref (closure->parameter);
244 g_free (closure->action_name);
245 g_closure_invalidate (&closure->closure);
246 g_closure_unref (&closure->closure);
248 g_slist_free (window->priv->accel_closures);
249 window->priv->accel_closures = NULL;
253 GtkApplicationWindow *window;
254 GActionGroup *actions;
257 /* Hack. We iterate over the accel map instead of the actions,
258 * in order to pull the parameters out of accel map entries
261 add_accel_closure (gpointer data,
262 const gchar *accel_path,
264 GdkModifierType accel_mods,
268 GtkApplicationWindow *window = d->window;
269 GActionGroup *actions = d->actions;
274 AccelClosure *closure;
279 if (!g_str_has_prefix (accel_path, "<Actions>/"))
282 path = accel_path + strlen ("<Actions>/");
283 p = strchr (path, '/');
286 action_name = g_strndup (path, p - path);
287 parameter = g_variant_parse (NULL, p + 1, NULL, NULL, NULL);
289 g_warning ("Failed to parse parameter from '%s'\n", accel_path);
293 action_name = g_strdup (path);
297 if (g_action_group_has_action (actions, action_name))
299 closure = (AccelClosure*) g_closure_new_object (sizeof (AccelClosure), g_object_ref (actions));
300 g_closure_set_marshal (&closure->closure, accel_activate);
302 closure->action_name = g_strdup (action_name);
303 closure->parameter = parameter ? g_variant_ref_sink (parameter) : NULL;
305 window->priv->accel_closures = g_slist_prepend (window->priv->accel_closures, g_closure_ref (&closure->closure));
306 g_closure_sink (&closure->closure);
308 gtk_accel_group_connect_by_path (window->priv->accels, accel_path, &closure->closure);
311 g_free (action_name);
315 gtk_application_window_update_accels (GtkApplicationWindow *window)
317 GtkApplication *application;
321 /* FIXME: we should keep the muxer around, and listen for changes.
322 * Also, we should listen for accel map changes
324 application = gtk_window_get_application (GTK_WINDOW (window));
326 free_accel_closures (window);
328 muxer = g_action_muxer_new ();
329 g_action_muxer_insert (muxer, "app", G_ACTION_GROUP (application));
330 g_action_muxer_insert (muxer, "win", G_ACTION_GROUP (window));
332 data.window = window;
333 data.actions = G_ACTION_GROUP (muxer);
335 gtk_accel_map_foreach (&data, add_accel_closure);
337 g_object_unref (muxer);
341 gtk_application_window_shell_shows_app_menu_changed (GObject *object,
345 GtkApplicationWindow *window = user_data;
347 gtk_application_window_update_shell_shows_app_menu (window, GTK_SETTINGS (object));
348 gtk_application_window_update_menubar (window);
352 gtk_application_window_shell_shows_menubar_changed (GObject *object,
356 GtkApplicationWindow *window = user_data;
358 gtk_application_window_update_shell_shows_menubar (window, GTK_SETTINGS (object));
359 gtk_application_window_update_menubar (window);
363 gtk_application_window_list_actions (GActionGroup *group)
365 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
367 return g_action_group_list_actions (G_ACTION_GROUP (window->priv->actions));
371 gtk_application_window_query_action (GActionGroup *group,
372 const gchar *action_name,
374 const GVariantType **parameter_type,
375 const GVariantType **state_type,
376 GVariant **state_hint,
379 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
381 return g_action_group_query_action (G_ACTION_GROUP (window->priv->actions),
382 action_name, enabled, parameter_type, state_type, state_hint, state);
386 gtk_application_window_activate_action (GActionGroup *group,
387 const gchar *action_name,
390 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
392 return g_action_group_activate_action (G_ACTION_GROUP (window->priv->actions), action_name, parameter);
396 gtk_application_window_change_action_state (GActionGroup *group,
397 const gchar *action_name,
400 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
402 return g_action_group_change_action_state (G_ACTION_GROUP (window->priv->actions), action_name, state);
406 gtk_application_window_lookup_action (GActionMap *action_map,
407 const gchar *action_name)
409 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
411 return g_action_map_lookup_action (G_ACTION_MAP (window->priv->actions), action_name);
415 gtk_application_window_add_action (GActionMap *action_map,
418 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
420 g_action_map_add_action (G_ACTION_MAP (window->priv->actions), action);
424 gtk_application_window_remove_action (GActionMap *action_map,
425 const gchar *action_name)
427 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
429 g_action_map_remove_action (G_ACTION_MAP (window->priv->actions), action_name);
433 gtk_application_window_group_iface_init (GActionGroupInterface *iface)
435 iface->list_actions = gtk_application_window_list_actions;
436 iface->query_action = gtk_application_window_query_action;
437 iface->activate_action = gtk_application_window_activate_action;
438 iface->change_action_state = gtk_application_window_change_action_state;
442 gtk_application_window_map_iface_init (GActionMapInterface *iface)
444 iface->lookup_action = gtk_application_window_lookup_action;
445 iface->add_action = gtk_application_window_add_action;
446 iface->remove_action = gtk_application_window_remove_action;
449 G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindow, gtk_application_window, GTK_TYPE_WINDOW,
450 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, gtk_application_window_group_iface_init)
451 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, gtk_application_window_map_iface_init))
458 static GParamSpec *gtk_application_window_properties[N_PROPS];
461 gtk_application_window_real_get_preferred_height (GtkWidget *widget,
462 gint *minimum_height,
463 gint *natural_height)
465 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
467 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
468 ->get_preferred_height (widget, minimum_height, natural_height);
470 if (window->priv->menubar != NULL)
472 gint menubar_min_height, menubar_nat_height;
474 gtk_widget_get_preferred_height (window->priv->menubar, &menubar_min_height, &menubar_nat_height);
475 *minimum_height += menubar_min_height;
476 *natural_height += menubar_nat_height;
481 gtk_application_window_real_get_preferred_height_for_width (GtkWidget *widget,
483 gint *minimum_height,
484 gint *natural_height)
486 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
488 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
489 ->get_preferred_height_for_width (widget, width, minimum_height, natural_height);
491 if (window->priv->menubar != NULL)
493 gint menubar_min_height, menubar_nat_height;
495 gtk_widget_get_preferred_height_for_width (window->priv->menubar, width, &menubar_min_height, &menubar_nat_height);
496 *minimum_height += menubar_min_height;
497 *natural_height += menubar_nat_height;
502 gtk_application_window_real_get_preferred_width (GtkWidget *widget,
506 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
508 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
509 ->get_preferred_width (widget, minimum_width, natural_width);
511 if (window->priv->menubar != NULL)
513 gint menubar_min_width, menubar_nat_width;
515 gtk_widget_get_preferred_width (window->priv->menubar, &menubar_min_width, &menubar_nat_width);
516 *minimum_width = MAX (*minimum_width, menubar_min_width);
517 *natural_width = MAX (*natural_width, menubar_nat_width);
522 gtk_application_window_real_get_preferred_width_for_height (GtkWidget *widget,
527 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
529 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
530 ->get_preferred_width_for_height (widget, height, minimum_width, natural_width);
532 if (window->priv->menubar != NULL)
534 gint menubar_min_width, menubar_nat_width;
536 gtk_widget_get_preferred_width_for_height (window->priv->menubar, height, &menubar_min_width, &menubar_nat_width);
537 *minimum_width = MAX (*minimum_width, menubar_min_width);
538 *natural_width = MAX (*natural_width, menubar_nat_width);
543 gtk_application_window_real_size_allocate (GtkWidget *widget,
544 GtkAllocation *allocation)
546 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
548 if (window->priv->menubar != NULL)
550 GtkAllocation menubar_allocation = *allocation;
551 gint menubar_min_height, menubar_nat_height;
554 gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_min_height, &menubar_nat_height);
556 menubar_allocation.height = menubar_min_height;
557 gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation);
559 child = gtk_bin_get_child (GTK_BIN (window));
560 if (child != NULL && gtk_widget_get_visible (child))
562 GtkAllocation child_allocation = *allocation;
565 child_allocation.height = MAX (1, child_allocation.height - menubar_min_height);
567 border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
568 child_allocation.x += border_width;
569 child_allocation.y += border_width + menubar_min_height;
570 child_allocation.width -= border_width * 2;
571 child_allocation.height -= border_width * 2 - menubar_min_height;
572 gtk_widget_size_allocate (child, &child_allocation);
575 gtk_widget_set_allocation (widget, allocation);
578 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
579 ->size_allocate (widget, allocation);
583 gtk_application_window_real_realize (GtkWidget *widget)
585 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
586 GtkSettings *settings;
588 settings = gtk_widget_get_settings (widget);
590 g_signal_connect (settings, "notify::gtk-shell-shows-app-menu",
591 G_CALLBACK (gtk_application_window_shell_shows_app_menu_changed), window);
592 g_signal_connect (settings, "notify::gtk-shell-shows-menubar",
593 G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window);
595 gtk_application_window_update_shell_shows_app_menu (window, settings);
596 gtk_application_window_update_shell_shows_menubar (window, settings);
597 gtk_application_window_update_menubar (window);
598 gtk_application_window_update_accels (window);
600 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
605 gtk_application_window_real_unrealize (GtkWidget *widget)
607 GtkSettings *settings;
609 settings = gtk_widget_get_settings (widget);
611 g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_app_menu_changed, widget);
612 g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_menubar_changed, widget);
614 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
615 ->unrealize (widget);
619 gtk_application_window_real_map (GtkWidget *widget)
621 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
623 /* XXX could eliminate this by tweaking gtk_window_map */
624 if (window->priv->menubar)
625 gtk_widget_map (window->priv->menubar);
627 GTK_WIDGET_CLASS (gtk_application_window_parent_class)
632 gtk_application_window_real_forall_internal (GtkContainer *container,
633 gboolean include_internal,
634 GtkCallback callback,
637 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (container);
639 if (window->priv->menubar)
640 callback (window->priv->menubar, user_data);
642 GTK_CONTAINER_CLASS (gtk_application_window_parent_class)
643 ->forall (container, include_internal, callback, user_data);
648 gtk_application_window_get_property (GObject *object,
653 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
657 case PROP_SHOW_MENUBAR:
658 g_value_set_boolean (value, window->priv->show_menubar);
662 g_assert_not_reached ();
667 gtk_application_window_set_property (GObject *object,
672 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
676 case PROP_SHOW_MENUBAR:
677 gtk_application_window_set_show_menubar (window, g_value_get_boolean (value));
681 g_assert_not_reached ();
686 gtk_application_window_dispose (GObject *object)
688 GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
690 if (window->priv->menubar)
692 gtk_widget_unparent (window->priv->menubar);
693 window->priv->menubar = NULL;
696 free_accel_closures (window);
698 g_clear_object (&window->priv->app_menu_section);
699 g_clear_object (&window->priv->menubar_section);
700 g_clear_object (&window->priv->actions);
701 g_clear_object (&window->priv->accels);
703 G_OBJECT_CLASS (gtk_application_window_parent_class)
708 gtk_application_window_init (GtkApplicationWindow *window)
710 window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window, GTK_TYPE_APPLICATION_WINDOW, GtkApplicationWindowPrivate);
712 window->priv->actions = g_simple_action_group_new ();
713 window->priv->app_menu_section = g_menu_new ();
714 window->priv->menubar_section = g_menu_new ();
715 window->priv->accels = gtk_accel_group_new ();
716 gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accels);
718 /* window->priv->actions is the one and only ref on the group, so when
719 * we dispose, the action group will die, disconnecting all signals.
721 g_signal_connect_swapped (window->priv->actions, "action-added",
722 G_CALLBACK (g_action_group_action_added), window);
723 g_signal_connect_swapped (window->priv->actions, "action-enabled-changed",
724 G_CALLBACK (g_action_group_action_enabled_changed), window);
725 g_signal_connect_swapped (window->priv->actions, "action-state-changed",
726 G_CALLBACK (g_action_group_action_state_changed), window);
727 g_signal_connect_swapped (window->priv->actions, "action-removed",
728 G_CALLBACK (g_action_group_action_removed), window);
732 gtk_application_window_class_init (GtkApplicationWindowClass *class)
734 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
735 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
736 GObjectClass *object_class = G_OBJECT_CLASS (class);
738 container_class->forall = gtk_application_window_real_forall_internal;
739 widget_class->get_preferred_height = gtk_application_window_real_get_preferred_height;
740 widget_class->get_preferred_height_for_width = gtk_application_window_real_get_preferred_height_for_width;
741 widget_class->get_preferred_width = gtk_application_window_real_get_preferred_width;
742 widget_class->get_preferred_width_for_height = gtk_application_window_real_get_preferred_width_for_height;
743 widget_class->size_allocate = gtk_application_window_real_size_allocate;
744 widget_class->realize = gtk_application_window_real_realize;
745 widget_class->unrealize = gtk_application_window_real_unrealize;
746 widget_class->map = gtk_application_window_real_map;
747 object_class->get_property = gtk_application_window_get_property;
748 object_class->set_property = gtk_application_window_set_property;
749 object_class->dispose = gtk_application_window_dispose;
752 * GtkApplicationWindow:show-menubar:
754 * If this property is %TRUE, the window will display a menubar
755 * that includes the app menu and menubar, unless these are
756 * shown by the desktop shell. See g_application_set_app_menu()
757 * and g_application_set_menubar().
759 * If %FALSE, the window will not display a menubar, regardless
760 * of whether the desktop shell is showing the menus or not.
762 gtk_application_window_properties[PROP_SHOW_MENUBAR] =
763 g_param_spec_boolean ("show-menubar",
764 P_("Show a menubar"),
765 P_("TRUE if the window should show a "
766 "menubar at the top of the window"),
767 TRUE, G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
768 g_object_class_install_properties (object_class, N_PROPS, gtk_application_window_properties);
769 g_type_class_add_private (class, sizeof (GtkApplicationWindowPrivate));
773 * gtk_application_window_new:
774 * @application: a #GtkApplication
776 * Creates a new #GtkApplicationWindow.
778 * Returns: a newly created #GtkApplicationWindow
783 gtk_application_window_new (GtkApplication *application)
785 g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
787 return g_object_new (GTK_TYPE_APPLICATION_WINDOW,
788 "application", application,
793 * gtk_application_window_get_show_menubar:
794 * @window: a #GtkApplicationWindow
796 * Returns whether the window will display a menubar for the app menu
797 * and menubar as needed.
799 * Returns: %TRUE if @window will display a menubar when needed
804 gtk_application_window_get_show_menubar (GtkApplicationWindow *window)
806 return window->priv->show_menubar;
810 * gtk_application_window_set_show_menubar:
811 * @window: a #GtkApplicationWindow
812 * @show_menubar: whether to show a menubar when needed
814 * Sets whether the window will display a menubar for the app menu
815 * and menubar as needed.
820 gtk_application_window_set_show_menubar (GtkApplicationWindow *window,
821 gboolean show_menubar)
823 g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
825 show_menubar = !!show_menubar;
827 if (window->priv->show_menubar != show_menubar)
829 window->priv->show_menubar = show_menubar;
831 gtk_application_window_update_menubar (window);
833 g_object_notify_by_pspec (G_OBJECT (window), gtk_application_window_properties[PROP_SHOW_MENUBAR]);