X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkapplicationwindow.c;h=271054b109cfa90d98391023e10b7c70b3fabaf8;hb=5d011386a69aa59d6eda1e3ef32005efd831c179;hp=1f045caa4d55f703e7a49e7c032c9dce68d9d3db;hpb=babd137e325931ee7b791dec8df825ad1262a320;p=~andy%2Fgtk diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c index 1f045caa4..271054b10 100644 --- a/gtk/gtkapplicationwindow.c +++ b/gtk/gtkapplicationwindow.c @@ -22,11 +22,11 @@ #include "gtkapplicationwindow.h" #include "gtkapplicationprivate.h" +#include "gtkwidgetprivate.h" #include "gtkwindowprivate.h" -#include "gtkmodelmenu.h" -#include "gactionmuxer.h" #include "gtkaccelgroup.h" #include "gtkaccelmap.h" +#include "gtkmenubar.h" #include "gtkintl.h" #include "gtksettings.h" @@ -75,7 +75,7 @@ * 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. + * #GtkApplicationWindow will automatically show a #GtkMenuBar for it. * (see the #GtkApplication docs for some screenshots of how this * looks on different platforms). * This behaviour can be overridden with the #GtkApplicationWindow:show-menubar @@ -107,6 +107,14 @@ * * * + * Handling fallback yourself + * + * + * FIXME: MISSING XINCLUDE CONTENT + * + * + * + * * The XML format understood by #GtkBuilder for #GMenuModel consists * of a toplevel menu element, which contains * one or more item elements. Each @@ -205,8 +213,6 @@ gtk_application_window_actions_new (GtkApplicationWindow *window) struct _GtkApplicationWindowPrivate { GSimpleActionGroup *actions; - GActionObservable *muxer; - gboolean muxer_initialised; GtkWidget *menubar; GtkAccelGroup *accels; GSList *accel_closures; @@ -218,6 +224,8 @@ struct _GtkApplicationWindowPrivate GDBusConnection *session; gchar *object_path; guint export_id; + + guint id; }; static void @@ -248,7 +256,7 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window) 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), window->priv->muxer, window->priv->accels); + window->priv->menubar = gtk_menu_bar_new_from_model (G_MENU_MODEL (combined)); gtk_widget_set_parent (window->priv->menubar, GTK_WIDGET (window)); gtk_widget_show_all (window->priv->menubar); g_object_unref (combined); @@ -410,11 +418,6 @@ free_accel_closures (GtkApplicationWindow *window) window->priv->accel_closures = NULL; } -typedef struct { - GtkApplicationWindow *window; - GActionGroup *actions; -} AccelData; - /* Hack. We iterate over the accel map instead of the actions, * in order to pull the parameters out of accel map entries */ @@ -425,9 +428,8 @@ add_accel_closure (gpointer data, GdkModifierType accel_mods, gboolean changed) { - AccelData *d = data; - GtkApplicationWindow *window = d->window; - GActionGroup *actions = d->actions; + GtkApplicationWindow *window = data; + GActionGroup *actions; const gchar *path; const gchar *p; gchar *action_name; @@ -455,6 +457,7 @@ add_accel_closure (gpointer data, parameter = NULL; } + actions = G_ACTION_GROUP (_gtk_widget_get_action_muxer (GTK_WIDGET (window))); if (g_action_group_has_action (actions, action_name)) { closure = (AccelClosure*) g_closure_new_object (sizeof (AccelClosure), g_object_ref (actions)); @@ -468,6 +471,10 @@ add_accel_closure (gpointer data, gtk_accel_group_connect_by_path (window->priv->accels, accel_path, &closure->closure); } + else if (parameter) + { + g_variant_unref (parameter); + } g_free (action_name); } @@ -475,14 +482,9 @@ add_accel_closure (gpointer data, static void gtk_application_window_update_accels (GtkApplicationWindow *window) { - AccelData data; - free_accel_closures (window); - data.window = window; - data.actions = G_ACTION_GROUP (window->priv->muxer); - - gtk_accel_map_foreach (&data, add_accel_closure); + gtk_accel_map_foreach (window, add_accel_closure); } static void @@ -747,13 +749,6 @@ gtk_application_window_real_realize (GtkWidget *widget) g_signal_connect (settings, "notify::gtk-shell-shows-menubar", G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window); - if (!window->priv->muxer_initialised) - { - g_action_muxer_insert (G_ACTION_MUXER (window->priv->muxer), "app", G_ACTION_GROUP (application)); - g_action_muxer_insert (G_ACTION_MUXER (window->priv->muxer), "win", G_ACTION_GROUP (window)); - window->priv->muxer_initialised = TRUE; - } - 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); @@ -777,7 +772,7 @@ gtk_application_window_real_realize (GtkWidget *widget) g_dbus_connection_get_unique_name (window->priv->session)); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_OBJECT_PATH", - gtk_application_get_dbus_object_path (application)); + g_application_get_dbus_object_path (G_APPLICATION (application))); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_WINDOW_OBJECT_PATH", window->priv->object_path); @@ -809,11 +804,13 @@ gtk_application_window_real_unrealize (GtkWidget *widget) gboolean gtk_application_window_publish (GtkApplicationWindow *window, GDBusConnection *session, - const gchar *object_path) + const gchar *object_path, + guint object_id) { g_assert (window->priv->session == NULL); g_assert (window->priv->export_id == 0); g_assert (window->priv->object_path == NULL); + g_assert (window->priv->id == 0); window->priv->export_id = g_dbus_connection_export_action_group (session, object_path, G_ACTION_GROUP (window->priv->actions), @@ -824,6 +821,7 @@ gtk_application_window_publish (GtkApplicationWindow *window, window->priv->session = session; window->priv->object_path = g_strdup (object_path); + window->priv->id = object_id; return TRUE; } @@ -834,10 +832,12 @@ gtk_application_window_unpublish (GtkApplicationWindow *window) g_assert (window->priv->session != NULL); g_assert (window->priv->export_id != 0); g_assert (window->priv->object_path != NULL); + g_assert (window->priv->id != 0); g_dbus_connection_unexport_action_group (window->priv->session, window->priv->export_id); window->priv->session = NULL; window->priv->export_id = 0; + window->priv->id = 0; g_free (window->priv->object_path); window->priv->object_path = NULL; @@ -871,7 +871,6 @@ gtk_application_window_real_forall_internal (GtkContainer *container, ->forall (container, include_internal, callback, user_data); } - static void gtk_application_window_get_property (GObject *object, guint prop_id, @@ -927,7 +926,6 @@ gtk_application_window_dispose (GObject *object) 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); @@ -944,6 +942,8 @@ gtk_application_window_init (GtkApplicationWindow *window) window->priv->accels = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accels); + gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (window->priv->actions)); + /* window->priv->actions is the one and only ref on the group, so when * we dispose, the action group will die, disconnecting all signals. */ @@ -955,8 +955,6 @@ gtk_application_window_init (GtkApplicationWindow *window) G_CALLBACK (g_action_group_action_state_changed), window); g_signal_connect_swapped (window->priv->actions, "action-removed", G_CALLBACK (g_action_group_action_removed), window); - - window->priv->muxer = G_ACTION_OBSERVABLE (g_action_muxer_new ()); } static void @@ -1065,24 +1063,28 @@ gtk_application_window_set_show_menubar (GtkApplicationWindow *window, } } -GSimpleActionObserver * -gtk_application_window_create_observer (GtkApplicationWindow *window, - const gchar *action_name, - GVariant *target) +GtkAccelGroup * +gtk_application_window_get_accel_group (GtkApplicationWindow *window) { - g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), NULL); - - return g_simple_action_observer_new (window->priv->muxer, action_name, target); + return window->priv->accels; } -GActionObservable * -gtk_application_window_get_observable (GtkApplicationWindow *window) +/** + * gtk_application_window_get_id: + * @window: a #GtkApplicationWindow + * + * Returns the unique ID of the window. If the window has not yet been added to + * a #GtkApplication, returns 0. + * + * Returns: the unique ID for @window, or 0 if the window + * has not yet been added to a #GtkApplication + * + * Since: 3.6 + */ +guint +gtk_application_window_get_id (GtkApplicationWindow *window) { - return G_ACTION_OBSERVABLE (window->priv->muxer); -} + g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), 0); -GtkAccelGroup * -gtk_application_window_get_accel_group (GtkApplicationWindow *window) -{ - return window->priv->accels; + return window->priv->id; }