[gtk/wip/ebassi/shortcut: 174/267] bindings: Add gtk_binding_entry_add_signal_variant()



commit 350559ad5fa45de7ecdb17381f51674fc3c6048b
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                    | 57 ++++++++++++++++++++++--------------
 gtk/gtkbindings.h                    |  6 ++++
 3 files changed, 42 insertions(+), 22 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index c59c2e6692..6d6c7fcff9 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4955,6 +4955,7 @@ gtk_binding_entry_add_action_variant
 GtkBindingCallback
 gtk_binding_entry_add_callback
 gtk_binding_entry_add_signal
+gtk_binding_entry_add_signal_variant
 gtk_binding_entry_add_signal_from_string
 gtk_binding_entry_skip
 gtk_binding_entry_remove
diff --git a/gtk/gtkbindings.c b/gtk/gtkbindings.c
index 048fde19f9..48d42c2629 100644
--- a/gtk/gtkbindings.c
+++ b/gtk/gtkbindings.c
@@ -1078,18 +1078,44 @@ gtk_binding_entry_add_binding_signal (GtkBindingSet    *binding_set,
   *signal_p = signal;
 }
 
-/*
- * 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 (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,
@@ -1097,19 +1123,13 @@ gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
                                const gchar    *signal_name,
                                GSList         *binding_args)
 {
-  GtkBindingSignal *signal;
   GSList *slist;
   guint n = 0;
   GVariantBuilder builder;
-  GtkBindingEntry *entry;
-  GtkBindingSignal **signal_p;
 
   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)
@@ -1148,18 +1168,11 @@ gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
         }
     }
 
-  signal = binding_signal_new_signal (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 20df806ae3..611ef8731d 100644
--- a/gtk/gtkbindings.h
+++ b/gtk/gtkbindings.h
@@ -79,6 +79,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]