[gtk/shortcuts-rebased-again: 85/135] application: Replace accelerator handling with shortcuts



commit 06b2faff64cb40ad4029dd868fb63c4ff0a5748b
Author: Benjamin Otte <otte redhat com>
Date:   Thu Aug 23 01:23:24 2018 +0200

    application: Replace accelerator handling with shortcuts
    
    API remains the same, but activation is now done via a
    shortcutcontroller.
    
    The code uses a controller with global scope so that the shortcuts are
    managed with all the other global shortcuts.

 gtk/gtkapplicationaccels.c        | 520 ++++++++++++++------------------------
 gtk/gtkapplicationaccelsprivate.h |  10 +-
 gtk/gtkwindow.c                   |  44 +---
 3 files changed, 200 insertions(+), 374 deletions(-)
---
diff --git a/gtk/gtkapplicationaccels.c b/gtk/gtkapplicationaccels.c
index 22e20c1e76..4a2ef56d5d 100644
--- a/gtk/gtkapplicationaccels.c
+++ b/gtk/gtkapplicationaccels.c
@@ -22,135 +22,28 @@
 #include "config.h"
 
 #include "gtkapplicationaccelsprivate.h"
-#include "gtkactionmuxerprivate.h"
-
-#include <string.h>
 
-typedef struct
-{
-  guint           key;
-  GdkModifierType modifier;
-} AccelKey;
+#include "gtkactionmuxerprivate.h"
+#include "gtkshortcut.h"
+#include "gtkshortcutaction.h"
+#include "gtkshortcuttrigger.h"
 
 struct _GtkApplicationAccels
 {
   GObject parent;
 
-  GHashTable *action_to_accels;
-  GHashTable *accel_to_actions;
+  GListModel *shortcuts;
 };
 
 G_DEFINE_TYPE (GtkApplicationAccels, gtk_application_accels, G_TYPE_OBJECT)
 
-static AccelKey *
-accel_key_copy (const AccelKey *source)
-{
-  AccelKey *dest;
-
-  dest = g_slice_new (AccelKey);
-  dest->key = source->key;
-  dest->modifier = source->modifier;
-
-  return dest;
-}
-
-static void
-accel_key_free (gpointer data)
-{
-  AccelKey *key = data;
-
-  g_slice_free (AccelKey, key);
-}
-
-static guint
-accel_key_hash (gconstpointer data)
-{
-  const AccelKey *key = data;
-
-  return key->key + (key->modifier << 16);
-}
-
-static gboolean
-accel_key_equal (gconstpointer a,
-                 gconstpointer b)
-{
-  const AccelKey *ak = a;
-  const AccelKey *bk = b;
-
-  return ak->key == bk->key && ak->modifier == bk->modifier;
-}
-
-static void
-add_entry (GtkApplicationAccels *accels,
-           AccelKey             *key,
-           const gchar          *action_and_target)
-{
-  const gchar **old;
-  const gchar **new;
-  gint n;
-
-  old = g_hash_table_lookup (accels->accel_to_actions, key);
-  if (old != NULL)
-    for (n = 0; old[n]; n++)  /* find the length */
-      ;
-  else
-    n = 0;
-
-  new = g_new (const gchar *, n + 1 + 1);
-  memcpy (new, old, n * sizeof (const gchar *));
-  new[n] = action_and_target;
-  new[n + 1] = NULL;
-
-  g_hash_table_insert (accels->accel_to_actions, accel_key_copy (key), new);
-}
-
-static void
-remove_entry (GtkApplicationAccels *accels,
-              AccelKey             *key,
-              const gchar          *action_and_target)
-{
-  const gchar **old;
-  const gchar **new;
-  gint n, i;
-
-  /* if we can't find the entry then something has gone very wrong... */
-  old = g_hash_table_lookup (accels->accel_to_actions, key);
-  g_assert (old != NULL);
-
-  for (n = 0; old[n]; n++)  /* find the length */
-    ;
-  g_assert_cmpint (n, >, 0);
-
-  if (n == 1)
-    {
-      /* The simple case of removing the last action for an accel. */
-      g_assert_cmpstr (old[0], ==, action_and_target);
-      g_hash_table_remove (accels->accel_to_actions, key);
-      return;
-    }
-
-  for (i = 0; i < n; i++)
-    if (g_str_equal (old[i], action_and_target))
-      break;
-
-  /* We must have found it... */
-  g_assert_cmpint (i, <, n);
-
-  new = g_new (const gchar *, n - 1 + 1);
-  memcpy (new, old, i * sizeof (const gchar *));
-  memcpy (new + i, old + i + 1, (n - (i + 1)) * sizeof (const gchar *));
-  new[n - 1] = NULL;
-
-  g_hash_table_insert (accels->accel_to_actions, accel_key_copy (key), new);
-}
-
 static void
 gtk_application_accels_finalize (GObject *object)
 {
   GtkApplicationAccels *accels = GTK_APPLICATION_ACCELS (object);
 
-  g_hash_table_unref (accels->accel_to_actions);
-  g_hash_table_unref (accels->action_to_accels);
+  g_list_store_remove_all (G_LIST_STORE (accels->shortcuts));
+  g_object_unref (accels->shortcuts);
 
   G_OBJECT_CLASS (gtk_application_accels_parent_class)->finalize (object);
 }
@@ -166,9 +59,7 @@ gtk_application_accels_class_init (GtkApplicationAccelsClass *klass)
 static void
 gtk_application_accels_init (GtkApplicationAccels *accels)
 {
-  accels->accel_to_actions = g_hash_table_new_full (accel_key_hash, accel_key_equal,
-                                                    accel_key_free, g_free);
-  accels->action_to_accels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  accels->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
 }
 
 GtkApplicationAccels *
@@ -182,52 +73,99 @@ gtk_application_accels_set_accels_for_action (GtkApplicationAccels *accels,
                                               const gchar          *detailed_action_name,
                                               const gchar * const  *accelerators)
 {
-  gchar *action_and_target;
-  AccelKey *keys, *old_keys;
-  gint i, n;
+  gchar *action_name;
+  GVariant *target;
+  GtkShortcut *shortcut;
+  GtkShortcutTrigger *trigger = NULL;
+  GError *error = NULL;
+  guint i;
+
+  if (!g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error))
+    {
+      g_critical ("Error parsing action name: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  /* remove the accelerator if it already exists */
+  for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
+    {
+      GtkShortcut *s = g_list_model_get_item (accels->shortcuts, i);
+      GtkShortcutAction *action = gtk_shortcut_get_action (s);
+      GVariant *args = gtk_shortcut_get_arguments (s);
+
+      g_object_unref (s);
+
+      if (gtk_shortcut_action_get_action_type (action) != GTK_SHORTCUT_ACTION_ACTION ||
+          !g_str_equal (gtk_action_action_get_name (action), action_name))
+        continue;
 
-  action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
+      if ((target == NULL && args != NULL) ||
+          (target != NULL && (args == NULL || !g_variant_equal (target, args))))
+        continue;
+
+      g_list_store_remove (G_LIST_STORE (accels->shortcuts), i);
+      break;
+    }
 
-  n = accelerators ? g_strv_length ((gchar **) accelerators) : 0;
+  if (accelerators == NULL)
+    goto out;
 
-  if (n > 0)
+  for (i = 0; accelerators[i]; i++)
     {
-      keys = g_new0 (AccelKey, n + 1);
+      GtkShortcutTrigger *new_trigger;
+      guint key, modifier;
 
-      for (i = 0; i < n; i++)
+      if (!gtk_accelerator_parse (accelerators[i], &key, &modifier))
         {
-          if (!gtk_accelerator_parse (accelerators[i], &keys[i].key, &keys[i].modifier))
-            {
-              g_warning ("Unable to parse accelerator '%s': ignored request to install %d accelerators",
-                         accelerators[i], n);
-              g_free (action_and_target);
-              g_free (keys);
-              return;
-            }
+          g_critical ("Unable to parse accelerator '%s': ignored request to install accelerators",
+                      accelerators[i]);
+          if (trigger)
+            gtk_shortcut_trigger_unref (trigger);
+          goto out;;
         }
+      new_trigger = gtk_keyval_trigger_new (key, modifier);
+      if (trigger)
+        trigger = gtk_alternative_trigger_new (trigger, new_trigger);
+      else
+        trigger = new_trigger;
     }
-  else
-    keys = NULL;
+  if (trigger == NULL)
+    goto out;
+
+  shortcut = gtk_shortcut_new (trigger, gtk_action_action_new (action_name));
+  gtk_shortcut_set_arguments (shortcut, target);
+  g_list_store_append (G_LIST_STORE (accels->shortcuts), shortcut);
+  g_object_unref (shortcut);
+
+out:
+  g_free (action_name);
+  if (target)
+    g_variant_unref (target);
+}
 
-  old_keys = g_hash_table_lookup (accels->action_to_accels, action_and_target);
-  if (old_keys)
+static void
+append_accelerators (GPtrArray          *accels,
+                     GtkShortcutTrigger *trigger)
+{
+  switch (gtk_shortcut_trigger_get_trigger_type (trigger))
     {
-      /* We need to remove accel entries from existing keys */
-      for (i = 0; old_keys[i].key; i++)
-        remove_entry (accels, &old_keys[i], action_and_target);
-    }
+    case GTK_SHORTCUT_TRIGGER_KEYVAL:
+      g_ptr_array_add (accels,
+                       gtk_accelerator_name (gtk_keyval_trigger_get_keyval (trigger),
+                                             gtk_keyval_trigger_get_modifiers (trigger)));
+      return;
 
-  if (keys)
-    {
-      g_hash_table_replace (accels->action_to_accels, action_and_target, keys);
+    case GTK_SHORTCUT_TRIGGER_ALTERNATIVE:
+      append_accelerators (accels, gtk_alternative_trigger_get_first (trigger));
+      append_accelerators (accels, gtk_alternative_trigger_get_second (trigger));
+      return;
 
-      for (i = 0; i < n; i++)
-        add_entry (accels, &keys[i], action_and_target);
-    }
-  else
-    {
-      g_hash_table_remove (accels->action_to_accels, action_and_target);
-      g_free (action_and_target);
+    case GTK_SHORTCUT_TRIGGER_MNEMONIC:
+    case GTK_SHORTCUT_TRIGGER_NEVER:
+    default:
+      /* not an accelerator */
+      return;
     }
 }
 
@@ -235,221 +173,137 @@ gchar **
 gtk_application_accels_get_accels_for_action (GtkApplicationAccels *accels,
                                               const gchar          *detailed_action_name)
 {
-  gchar *action_and_target;
-  AccelKey *keys;
-  gchar **result;
-  gint n, i = 0;
+  GPtrArray *result;
+  char *action_name;
+  GVariant *target;
+  GError *error = NULL;
+  guint i;
 
-  action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
+  result = g_ptr_array_new ();
 
-  keys = g_hash_table_lookup (accels->action_to_accels, action_and_target);
-  if (!keys)
+  if (!g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error))
     {
-      g_free (action_and_target);
-      return g_new0 (gchar *, 0 + 1);
+      g_critical ("Error parsing action name: %s", error->message);
+      g_error_free (error);
+      g_ptr_array_add (result, NULL);
+      return (gchar **) g_ptr_array_free (result, FALSE);
     }
 
-  for (n = 0; keys[n].key; n++)
-    ;
+  for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
+    {
+      GtkShortcut *shortcut = g_list_model_get_item (accels->shortcuts, i);
+      GtkShortcutAction *action = gtk_shortcut_get_action (shortcut);
+      GVariant *args = gtk_shortcut_get_arguments (shortcut);
 
-  result = g_new0 (gchar *, n + 1);
+      if (gtk_shortcut_action_get_action_type (action) != GTK_SHORTCUT_ACTION_ACTION ||
+          !g_str_equal (gtk_action_action_get_name (action), action_name))
+        continue;
 
-  for (i = 0; i < n; i++)
-    result[i] = gtk_accelerator_name (keys[i].key, keys[i].modifier);
+      if ((target == NULL && args != NULL) ||
+          (target != NULL && (args == NULL || !g_variant_equal (target, args))))
+        continue;
 
-  g_free (action_and_target);
-  return result;
+      append_accelerators (result, gtk_shortcut_get_trigger (shortcut));
+      break;
+    }
+
+  g_free (action_name);
+  if (target)
+    g_variant_unref (target);
+  g_ptr_array_add (result, NULL);
+  return (gchar **) g_ptr_array_free (result, FALSE);
 }
 
-gchar **
-gtk_application_accels_get_actions_for_accel (GtkApplicationAccels *accels,
-                                              const gchar          *accel)
+static gboolean
+trigger_matches_accel (GtkShortcutTrigger *trigger,
+                       guint               keyval,
+                       GdkModifierType     modifiers)
 {
-  const gchar * const *actions_and_targets;
-  gchar **detailed_actions;
-  AccelKey accel_key;
-  guint i, n;
-
-  if (!gtk_accelerator_parse (accel, &accel_key.key, &accel_key.modifier))
+  switch (gtk_shortcut_trigger_get_trigger_type (trigger))
     {
-      g_critical ("invalid accelerator string '%s'", accel);
-      return NULL;
+    case GTK_SHORTCUT_TRIGGER_KEYVAL:
+      return gtk_keyval_trigger_get_keyval (trigger) == keyval
+          && gtk_keyval_trigger_get_modifiers (trigger) == modifiers;
+
+    case GTK_SHORTCUT_TRIGGER_ALTERNATIVE:
+      return trigger_matches_accel (gtk_alternative_trigger_get_first (trigger), keyval, modifiers)
+          || trigger_matches_accel (gtk_alternative_trigger_get_second (trigger), keyval, modifiers);
+
+    case GTK_SHORTCUT_TRIGGER_MNEMONIC:
+    case GTK_SHORTCUT_TRIGGER_NEVER:
+    default:
+      return FALSE;
     }
+}
 
-  actions_and_targets = g_hash_table_lookup (accels->accel_to_actions, &accel_key);
-  n = actions_and_targets ? g_strv_length ((gchar **) actions_and_targets) : 0;
-
-  detailed_actions = g_new0 (gchar *, n + 1);
-
-  for (i = 0; i < n; i++)
-    {
-      const gchar *action_and_target = actions_and_targets[i];
-      const gchar *sep;
-      GVariant *target;
-
-      sep = strrchr (action_and_target, '|');
-      target = g_variant_parse (NULL, action_and_target, sep, NULL, NULL);
-      detailed_actions[i] = g_action_print_detailed_name (sep + 1, target);
-      if (target)
-        g_variant_unref (target);
-    }
+static char *
+get_detailed_name_for_shortcut (GtkShortcut *shortcut)
+{
+  GtkShortcutAction *action = gtk_shortcut_get_action (shortcut);
 
-  detailed_actions[n] = NULL;
+  if (gtk_shortcut_action_get_action_type (action) != GTK_SHORTCUT_ACTION_ACTION)
+    return NULL;
 
-  return detailed_actions;
+  return g_action_print_detailed_name (gtk_action_action_get_name (action), gtk_shortcut_get_arguments 
(shortcut));
 }
 
 gchar **
-gtk_application_accels_list_action_descriptions (GtkApplicationAccels *accels)
+gtk_application_accels_get_actions_for_accel (GtkApplicationAccels *accels,
+                                              const gchar          *accel)
 {
-  GHashTableIter iter;
-  gchar **result;
-  gint n, i = 0;
-  gpointer key;
+  GPtrArray *result;
+  guint key, modifiers;
+  guint i;
 
-  n = g_hash_table_size (accels->action_to_accels);
-  result = g_new (gchar *, n + 1);
+  if (!gtk_accelerator_parse (accel, &key, &modifiers))
+    {
+      g_critical ("invalid accelerator string '%s'", accel);
+      return NULL;
+    }
 
-  g_hash_table_iter_init (&iter, accels->action_to_accels);
-  while (g_hash_table_iter_next (&iter, &key, NULL))
+  result = g_ptr_array_new ();
+  
+  for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
     {
-      const gchar *action_and_target = key;
-      const gchar *sep;
-      GVariant *target;
-
-      sep = strrchr (action_and_target, '|');
-      target = g_variant_parse (NULL, action_and_target, sep, NULL, NULL);
-      result[i++] = g_action_print_detailed_name (sep + 1, target);
-      if (target)
-        g_variant_unref (target);
+      GtkShortcut *shortcut = g_list_model_get_item (accels->shortcuts, i);
+      char *detailed_name;
+
+      if (!trigger_matches_accel (gtk_shortcut_get_trigger (shortcut), key, modifiers))
+        continue;
+      
+      detailed_name = get_detailed_name_for_shortcut (shortcut);
+      if (detailed_name)
+        g_ptr_array_add (result, detailed_name);
     }
-  g_assert_cmpint (i, ==, n);
-  result[i] = NULL;
 
-  return result;
+  g_ptr_array_add (result, NULL);
+  return (gchar **) g_ptr_array_free (result, FALSE);
 }
 
-void
-gtk_application_accels_foreach_key (GtkApplicationAccels     *accels,
-                                    GtkWindow                *window,
-                                    GtkWindowKeysForeachFunc  callback,
-                                    gpointer                  user_data)
+gchar **
+gtk_application_accels_list_action_descriptions (GtkApplicationAccels *accels)
 {
-  GHashTableIter iter;
-  gpointer key;
+  GPtrArray *result;
+  guint i;
 
-  g_hash_table_iter_init (&iter, accels->accel_to_actions);
-  while (g_hash_table_iter_next (&iter, &key, NULL))
+  result = g_ptr_array_new ();
+  
+  for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
     {
-      AccelKey *accel_key = key;
+      GtkShortcut *shortcut = g_list_model_get_item (accels->shortcuts, i);
+      char *detailed_name;
 
-      (* callback) (window, accel_key->key, accel_key->modifier, user_data);
+      detailed_name = get_detailed_name_for_shortcut (shortcut);
+      if (detailed_name)
+        g_ptr_array_add (result, detailed_name);
     }
+
+  g_ptr_array_add (result, NULL);
+  return (gchar **) g_ptr_array_free (result, FALSE);
 }
 
-gboolean
-gtk_application_accels_activate (GtkApplicationAccels *accels,
-                                 GActionGroup         *action_group,
-                                 guint                 key,
-                                 GdkModifierType       modifier)
+GListModel *
+gtk_application_accels_get_shortcuts (GtkApplicationAccels *accels)
 {
-  AccelKey accel_key = { key, modifier };
-  const gchar **actions;
-  gint i;
-
-  actions = g_hash_table_lookup (accels->accel_to_actions, &accel_key);
-
-  if (actions == NULL)
-    return FALSE;
-
-  /* We may have more than one action on a given accel.  This could be
-   * the case if we have different types of windows with different
-   * actions in each.
-   *
-   * Find the first one that will successfully activate and use it.
-   */
-  for (i = 0; actions[i]; i++)
-    {
-      const GVariantType *parameter_type;
-      const gchar *action_name;
-      const gchar *sep;
-      gboolean enabled;
-      GVariant *target;
-
-      sep = strrchr (actions[i], '|');
-      action_name = sep + 1;
-
-      if (!g_action_group_query_action (action_group, action_name, &enabled, &parameter_type, NULL, NULL, 
NULL))
-        continue;
-
-      if (!enabled)
-        continue;
-
-      /* We found an action with the correct name and it's enabled.
-       * This is the action that we are going to try to invoke.
-       *
-       * There is still the possibility that the target value doesn't
-       * match the expected parameter type.  In that case, we will print
-       * a warning.
-       *
-       * Note: we want to hold a ref on the target while we're invoking
-       * the action to prevent trouble if someone uninstalls the accel
-       * from the handler.  That's not a problem since we're parsing it.
-       */
-      if (actions[i] != sep) /* if it has a target... */
-        {
-          GError *error = NULL;
-
-          if (parameter_type == NULL)
-            {
-              gchar *accel_str = gtk_accelerator_name (key, modifier);
-              g_warning ("Accelerator '%s' tries to invoke action '%s' with target, but action has no 
parameter",
-                         accel_str, action_name);
-              g_free (accel_str);
-              return TRUE;
-            }
-
-          target = g_variant_parse (NULL, actions[i], sep, NULL, &error);
-          g_assert_no_error (error);
-          g_assert (target);
-
-          if (!g_variant_is_of_type (target, parameter_type))
-            {
-              gchar *accel_str = gtk_accelerator_name (key, modifier);
-              gchar *typestr = g_variant_type_dup_string (parameter_type);
-              gchar *targetstr = g_variant_print (target, TRUE);
-              g_warning ("Accelerator '%s' tries to invoke action '%s' with target '%s',"
-                         " but action expects parameter with type '%s'", accel_str, action_name, targetstr, 
typestr);
-              g_variant_unref (target);
-              g_free (targetstr);
-              g_free (accel_str);
-              g_free (typestr);
-              return TRUE;
-            }
-        }
-      else
-        {
-          if (parameter_type != NULL)
-            {
-              gchar *accel_str = gtk_accelerator_name (key, modifier);
-              gchar *typestr = g_variant_type_dup_string (parameter_type);
-              g_warning ("Accelerator '%s' tries to invoke action '%s' without target,"
-                         " but action expects parameter with type '%s'", accel_str, action_name, typestr);
-              g_free (accel_str);
-              g_free (typestr);
-              return TRUE;
-            }
-
-          target = NULL;
-        }
-
-      g_action_group_activate_action (action_group, action_name, target);
-
-      if (target)
-        g_variant_unref (target);
-
-      return TRUE;
-    }
-
-  return FALSE;
+  return accels->shortcuts;
 }
diff --git a/gtk/gtkapplicationaccelsprivate.h b/gtk/gtkapplicationaccelsprivate.h
index b126401a78..fbde7da368 100644
--- a/gtk/gtkapplicationaccelsprivate.h
+++ b/gtk/gtkapplicationaccelsprivate.h
@@ -47,15 +47,7 @@ gchar **        gtk_application_accels_get_actions_for_accel        (GtkApplicat
 
 gchar **        gtk_application_accels_list_action_descriptions     (GtkApplicationAccels *accels);
 
-void            gtk_application_accels_foreach_key                  (GtkApplicationAccels     *accels,
-                                                                     GtkWindow                *window,
-                                                                     GtkWindowKeysForeachFunc  callback,
-                                                                     gpointer                  user_data);
-
-gboolean        gtk_application_accels_activate                     (GtkApplicationAccels *accels,
-                                                                     GActionGroup         *action_group,
-                                                                     guint                 key,
-                                                                     GdkModifierType       modifier);
+GListModel *    gtk_application_accels_get_shortcuts                (GtkApplicationAccels *accels);
 
 G_END_DECLS
 
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 44a6058ac9..38838a0a77 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -270,6 +270,7 @@ typedef struct
   GtkGesture *drag_gesture;
   GtkGesture *bubble_drag_gesture;
   GtkEventController *key_controller;
+  GtkEventController *application_shortcut_controller;
 
   GdkSurface *hardcoded_surface;
 
@@ -3222,6 +3223,9 @@ gtk_window_release_application (GtkWindow *window)
       /* steal reference into temp variable */
       application = priv->application;
       priv->application = NULL;
+      gtk_widget_remove_controller (GTK_WIDGET (window),
+                                    priv->application_shortcut_controller);
+      priv->application_shortcut_controller = NULL;
 
       gtk_application_remove_window (application, window);
       g_object_unref (application);
@@ -3262,9 +3266,17 @@ gtk_window_set_application (GtkWindow      *window,
 
       if (priv->application != NULL)
         {
+          GtkApplicationAccels *app_accels;
+
           g_object_ref (priv->application);
 
           gtk_application_add_window (priv->application, window);
+
+          app_accels = gtk_application_get_application_accels (priv->application);
+          priv->application_shortcut_controller = gtk_shortcut_controller_new_for_model 
(gtk_application_accels_get_shortcuts (app_accels));
+          gtk_event_controller_set_propagation_phase (priv->application_shortcut_controller, 
GTK_PHASE_CAPTURE);
+          gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER 
(priv->application_shortcut_controller), GTK_SHORTCUT_SCOPE_GLOBAL);
+          gtk_widget_add_controller (GTK_WIDGET (window), priv->application_shortcut_controller);
         }
 
       _gtk_widget_update_parent_muxer (GTK_WIDGET (window));
@@ -8068,7 +8080,6 @@ _gtk_window_keys_foreach (GtkWindow                *window,
                          GtkWindowKeysForeachFunc func,
                          gpointer                 func_data)
 {
-  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
   GSList *groups;
 
   groups = gtk_accel_groups_from_object (G_OBJECT (window));
@@ -8087,14 +8098,6 @@ _gtk_window_keys_foreach (GtkWindow                *window,
       
       groups = groups->next;
     }
-
-  if (priv->application)
-    {
-      GtkApplicationAccels *app_accels;
-
-      app_accels = gtk_application_get_application_accels (priv->application);
-      gtk_application_accels_foreach_key (app_accels, window, func, func_data);
-    }
 }
 
 static void
@@ -8189,7 +8192,6 @@ gboolean
 gtk_window_activate_key (GtkWindow   *window,
                         GdkEventKey *event)
 {
-  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
   GtkKeyHash *key_hash;
   GtkWindowKeyEntry *found_entry = NULL;
   gboolean enable_accels;
@@ -8231,28 +8233,6 @@ gtk_window_activate_key (GtkWindow   *window,
         {
           if (gtk_accel_groups_activate (G_OBJECT (window), found_entry->keyval, found_entry->modifiers))
             return TRUE;
-
-          if (priv->application)
-            {
-              GtkWidget *focused_widget;
-              GtkActionMuxer *muxer;
-              GtkApplicationAccels *app_accels;
-
-              focused_widget = gtk_window_get_focus (window);
-
-              if (focused_widget)
-                muxer = _gtk_widget_get_action_muxer (focused_widget, FALSE);
-              else
-                muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (window), FALSE);
-
-              if (muxer == NULL)
-                return FALSE;
-
-              app_accels = gtk_application_get_application_accels (priv->application);
-              return gtk_application_accels_activate (app_accels,
-                                                      G_ACTION_GROUP (muxer),
-                                                      found_entry->keyval, found_entry->modifiers);
-            }
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]