[gtk/wip/ebassi/shortcut: 2/85] bindings: Add gtk_binding_entry_add_signal_variant()



commit f9dacc4d05776222f7d8d1b08f36a3e8b8415e6c
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 |  5 +--
 gtk/gtkbindings.c                    | 59 +++++++++++++++---------------------
 gtk/gtkbindings.h                    |  6 ++++
 3 files changed, 32 insertions(+), 38 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index b4a737d2f0..c71d13d37b 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4948,10 +4948,7 @@ gtk_binding_set_find
 gtk_bindings_activate
 gtk_bindings_activate_event
 gtk_binding_set_activate
-gtk_binding_entry_add_action
-gtk_binding_entry_add_action_variant
-GtkBindingCallback
-gtk_binding_entry_add_callback
+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 3a8b4f60ee..1c88074806 100644
--- a/gtk/gtkbindings.c
+++ b/gtk/gtkbindings.c
@@ -1012,18 +1012,32 @@ gtk_binding_entry_remove (GtkBindingSet  *binding_set,
     binding_entry_destroy (entry);
 }
 
-static void
-gtk_binding_entry_add_binding_signal (GtkBindingSet    *binding_set,
-                                      guint             keyval,
-                                      GdkModifierType   modifiers,
-                                      GtkBindingSignal *signal)
+/**
+ * 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: 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_p;
+  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)
     {
@@ -1036,18 +1050,6 @@ gtk_binding_entry_add_binding_signal (GtkBindingSet    *binding_set,
   *signal_p = signal;
 }
 
-/*
- * gtk_binding_entry_add_signall:
- * @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
- *
- * Override or install a new key binding for @keyval with @modifiers on
- * @binding_set.
- */
 static void
 gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
                                guint           keyval,
@@ -1055,7 +1057,6 @@ gtk_binding_entry_add_signall (GtkBindingSet  *binding_set,
                                const gchar    *signal_name,
                                GSList         *binding_args)
 {
-  GtkBindingSignal *signal;
   GSList *slist;
   guint n = 0;
   GVariantBuilder builder;
@@ -1063,9 +1064,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)
@@ -1103,18 +1101,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 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]