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.
This commit is contained in:
Benjamin Otte 2018-07-31 21:32:34 +02:00 committed by Matthias Clasen
parent 385c5e0569
commit 3b3a5c2d53
3 changed files with 42 additions and 22 deletions

View File

@ -4632,6 +4632,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

View File

@ -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));
}
/**

View File

@ -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,