[gtk/wip/matthiasc/shortcut: 18/91] Allow installing bindings bound to actions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/shortcut: 18/91] Allow installing bindings bound to actions
- Date: Sun, 15 Mar 2020 18:43:18 +0000 (UTC)
commit e3cac02664142a33361511268c24b2dfc39b490c
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Feb 5 17:08:37 2020 +0000
Allow installing bindings bound to actions
This is just convenience code around GtkShortcut, just like bindings for
signal emission and callback invocation.
gtk/gtkwidget.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkwidget.h | 8 ++++++++
2 files changed, 57 insertions(+)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f6513b3b97..f2d0d2967e 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4418,6 +4418,55 @@ gtk_widget_class_add_binding_signal (GtkWidgetClass *widget_class,
g_object_unref (shortcut);
}
+/**
+ * gtk_widget_class_add_binding_action: (skip)
+ * @widget_class: the class to add the binding to
+ * @keyval: key value of binding to install
+ * @mods: key modifier of binding to install
+ * @action_name: the action to activate
+ * @format_string: GVariant format string for arguments or %NULL for
+ * no arguments
+ * @...: arguments, as given by format string.
+ *
+ * Creates a new shortcut for @widget_class that activates the given
+ * @action_name with arguments read according to @format_string.
+ * The arguments and format string must be provided in the same way as
+ * with g_variant_new().
+ *
+ * This function is a convenience wrapper around
+ * gtk_widget_class_add_shortcut() and must be called during class
+ * initialization.
+ */
+void
+gtk_widget_class_add_binding_action (GtkWidgetClass *widget_class,
+ guint keyval,
+ GdkModifierType mods,
+ const gchar *action_name,
+ const gchar *format_string,
+ ...)
+{
+ GtkShortcut *shortcut;
+
+ g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
+ /* XXX: validate variant format for action */
+
+ shortcut = gtk_shortcut_new ();
+ gtk_shortcut_set_trigger (shortcut, gtk_keyval_trigger_new (keyval, mods));
+ gtk_shortcut_set_action (shortcut, action_name);
+ if (format_string)
+ {
+ va_list args;
+ va_start (args, format_string);
+ gtk_shortcut_set_arguments (shortcut,
+ g_variant_new_va (format_string, NULL, &args));
+ va_end (args);
+ }
+
+ gtk_widget_class_add_shortcut (widget_class, shortcut);
+
+ g_object_unref (shortcut);
+}
+
/**
* gtk_widget_class_add_shortcut:
* @widget_class: the class to add the shortcut to
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 40af2c6a18..d9d0a30932 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -390,6 +390,14 @@ void gtk_widget_class_add_binding_signal
const gchar *format_string,
...);
GDK_AVAILABLE_IN_ALL
+void gtk_widget_class_add_binding_action
+ (GtkWidgetClass *widget_class,
+ GdkModifierType mods,
+ guint keyval,
+ const gchar *action_name,
+ const gchar *format_string,
+ ...);
+GDK_AVAILABLE_IN_ALL
void gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class,
GtkShortcut *shortcut);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]