[libdazzle] shortcuts: implement context merging



commit 80ff86cb20b8cf5ed625206174cdca0cd1ca8469
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 12 18:50:32 2017 -0700

    shortcuts: implement context merging

 src/shortcuts/dzl-shortcut-context.c |   33 +++++++++++++++++++++++++++++++++
 src/shortcuts/dzl-shortcut-private.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/src/shortcuts/dzl-shortcut-context.c b/src/shortcuts/dzl-shortcut-context.c
index c030dbd..81840e8 100644
--- a/src/shortcuts/dzl-shortcut-context.c
+++ b/src/shortcuts/dzl-shortcut-context.c
@@ -829,3 +829,36 @@ _dzl_shortcut_context_get_table (DzlShortcutContext *self)
 
   return priv->table;
 }
+
+void
+_dzl_shortcut_context_merge (DzlShortcutContext *self,
+                             DzlShortcutContext *layer)
+{
+  DzlShortcutContextPrivate *priv = dzl_shortcut_context_get_instance_private (self);
+  DzlShortcutContextPrivate *layer_priv = dzl_shortcut_context_get_instance_private (layer);
+  DzlShortcutChordTableIter iter;
+  const DzlShortcutChord *chord;
+  gpointer value;
+
+  g_return_if_fail (DZL_IS_SHORTCUT_CONTEXT (self));
+  g_return_if_fail (DZL_IS_SHORTCUT_CONTEXT (layer));
+  g_return_if_fail (layer != self);
+
+  if (layer_priv->use_binding_sets != -1)
+    priv->use_binding_sets = layer_priv->use_binding_sets;
+
+  _dzl_shortcut_chord_table_iter_init (&iter, layer_priv->table);
+  while (_dzl_shortcut_chord_table_iter_next (&iter, &chord, &value))
+    {
+      Shortcut *sc = value;
+
+      /* Make sure this doesn't exist in the base layer anymore */
+      dzl_shortcut_chord_table_remove (priv->table, chord);
+
+      /* Now add it to our table of chords */
+      dzl_shortcut_context_add (self, chord, sc);
+
+      /* Now we can safely steal this from the upper layer */
+      _dzl_shortcut_chord_table_iter_steal (&iter);
+    }
+}
diff --git a/src/shortcuts/dzl-shortcut-private.h b/src/shortcuts/dzl-shortcut-private.h
index 681d550..c009d9d 100644
--- a/src/shortcuts/dzl-shortcut-private.h
+++ b/src/shortcuts/dzl-shortcut-private.h
@@ -102,6 +102,8 @@ DzlShortcutMatch       _dzl_shortcut_theme_match                (DzlShortcutThem
                                                                  const DzlShortcutChord     *chord,
                                                                  DzlShortcutClosureChain   **chain);
 DzlShortcutChordTable *_dzl_shortcut_context_get_table          (DzlShortcutContext         *self);
+void                   _dzl_shortcut_context_merge              (DzlShortcutContext         *self,
+                                                                 DzlShortcutContext         *layer);
 void                   _dzl_shortcut_chord_table_iter_init      (DzlShortcutChordTableIter  *iter,
                                                                  DzlShortcutChordTable      *table);
 gboolean               _dzl_shortcut_chord_table_iter_next      (DzlShortcutChordTableIter  *iter,


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