[gtk/shortcuts-rebased-again: 6/135] bindings: Add gtk_binding_entry_add_signal_variant()



commit 96861dd8e454c3564e31df7b485275fdde8fbb19
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jul 31 21:32:34 2018 +0200

    bindings: Add gtk_binding_entry_add_signal_variant()
    
    This function is the replacement for
    gtk_binding_entry_add_signall().
    
    The GVariant will be demarshalled and passed to the action signal upon
    binding activation. The same rules apply as used to apply for
    GtkBindingArg, in that long, double and string args are now replaced by
    "x", "d" and "s" variant types.

 docs/reference/gtk/gtk4-sections.txt |  1 +
 gtk/gtkbindings.c                    | 56 ++++++++++++++++++++++--------------
 gtk/gtkbindings.h                    |  6 ++++
 3 files changed, 42 insertions(+), 21 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 6d93fc0ebf..e1edea3f3a 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5207,6 +5207,7 @@ gtk_binding_set_find
 gtk_bindings_activate
 gtk_bindings_activate_event
 gtk_binding_set_activate
+gtk_binding_entry_add_signal_variant
 gtk_binding_entry_add_signal
 gtk_binding_entry_add_signal_from_string
 gtk_binding_entry_skip
diff --git a/gtk/gtkbindings.c b/gtk/gtkbindings.c
index dfdf5ff8d1..294fd43c22 100644
--- a/gtk/gtkbindings.c
+++ b/gtk/gtkbindings.c
@@ -860,18 +860,44 @@ gtk_binding_entry_remove (GtkBindingSet  *binding_set,
     binding_entry_destroy (entry);
 }
 
-/*
- * gtk_binding_entry_add_signall:
+/**
+ * gtk_binding_entry_add_signal_variant:
  * @binding_set:  a #GtkBindingSet to add a signal to
  * @keyval:       key value
  * @modifiers:    key modifier
  * @signal_name:  signal name to be bound
- * @binding_args: (transfer none) (element-type GtkBindingArg):
- *     list of #GtkBindingArg signal arguments
+ * @binding_args: a #GVariant containing a struct with the arguments to pass.
  *
  * Override or install a new key binding for @keyval with @modifiers on
  * @binding_set.
  */
+void
+gtk_binding_entry_add_signal_variant (GtkBindingSet  *binding_set,
+                                      guint           keyval,
+                                      GdkModifierType modifiers,
+                                      const gchar    *signal_name,
+                                      GVariant       *binding_args)
+{
+  GtkBindingEntry *entry;
+  GtkBindingSignal *signal, **signal_p;
+
+  keyval = gdk_keyval_to_lower (keyval);
+  modifiers = modifiers & BINDING_MOD_MASK ();
+
+  signal = binding_signal_new (signal_name, binding_args);
+
+  entry = binding_ht_lookup_entry (binding_set, keyval, modifiers);
+  if (!entry)
+    {
+      gtk_binding_entry_clear_internal (binding_set, keyval, modifiers);
+      entry = binding_ht_lookup_entry (binding_set, keyval, modifiers);
+    }
+  signal_p = &entry->signals;
+  while (*signal_p)
+    signal_p = &(*signal_p)->next;
+  *signal_p = signal;
+}
+
 static void
 gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
                                guint           keyval,
@@ -879,8 +905,6 @@ gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
                                const gchar    *signal_name,
                                GSList         *binding_args)
 {
-  GtkBindingEntry *entry;
-  GtkBindingSignal *signal, **signal_p;
   GSList *slist;
   guint n = 0;
   GVariantBuilder builder;
@@ -888,9 +912,6 @@ gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
   g_return_if_fail (binding_set != NULL);
   g_return_if_fail (signal_name != NULL);
 
-  keyval = gdk_keyval_to_lower (keyval);
-  modifiers = modifiers & BINDING_MOD_MASK ();
-
   g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
 
   for (slist = binding_args; slist; slist = slist->next)
@@ -928,18 +949,11 @@ gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
         }
     }
 
-  signal = binding_signal_new (signal_name, g_variant_builder_end (&builder));
-
-  entry = binding_ht_lookup_entry (binding_set, keyval, modifiers);
-  if (!entry)
-    {
-      gtk_binding_entry_clear_internal (binding_set, keyval, modifiers);
-      entry = binding_ht_lookup_entry (binding_set, keyval, modifiers);
-    }
-  signal_p = &entry->signals;
-  while (*signal_p)
-    signal_p = &(*signal_p)->next;
-  *signal_p = signal;
+  gtk_binding_entry_add_signal_variant (binding_set,
+                                        keyval,
+                                        modifiers,
+                                        signal_name,
+                                        g_variant_builder_end (&builder));
 }
 
 /**
diff --git a/gtk/gtkbindings.h b/gtk/gtkbindings.h
index 887869f981..4b02b144c9 100644
--- a/gtk/gtkbindings.h
+++ b/gtk/gtkbindings.h
@@ -65,6 +65,12 @@ void           gtk_binding_entry_skip        (GtkBindingSet       *binding_set,
                                               guint                keyval,
                                               GdkModifierType      modifiers);
 GDK_AVAILABLE_IN_ALL
+void           gtk_binding_entry_add_signal_variant (GtkBindingSet*binding_set,
+                                              guint                keyval,
+                                              GdkModifierType      modifiers,
+                                              const gchar         *signal_name,
+                                              GVariant            *binding_args);
+GDK_AVAILABLE_IN_ALL
 void           gtk_binding_entry_add_signal  (GtkBindingSet       *binding_set,
                                               guint                keyval,
                                               GdkModifierType      modifiers,


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