[gtk] gesturelongpress: Add getter/setter for delay-factor
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] gesturelongpress: Add getter/setter for delay-factor
- Date: Wed, 7 Aug 2019 16:52:58 +0000 (UTC)
commit e8f3b47bf3f85d8ff7e562f560c576422e352436
Author: Timm Bäder <mail baedert org>
Date: Wed Aug 7 14:09:33 2019 +0200
gesturelongpress: Add getter/setter for delay-factor
docs/reference/gtk/gtk4-sections.txt | 2 ++
gtk/gtkgesturelongpress.c | 55 ++++++++++++++++++++++++++++--------
gtk/gtkgesturelongpress.h | 9 ++++++
3 files changed, 55 insertions(+), 11 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index a20c4d302e..1159248bff 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -6737,6 +6737,8 @@ gtk_gesture_drag_get_type
<TITLE>GtkGestureLongPress</TITLE>
GtkGestureLongPress
gtk_gesture_long_press_new
+gtk_gesture_long_press_set_delay_factor
+gtk_gesture_long_press_get_delay_factor
<SUBSECTION Standard>
GTK_TYPE_GESTURE_LONG_PRESS
diff --git a/gtk/gtkgesturelongpress.c b/gtk/gtkgesturelongpress.c
index 6b5632d15f..fc28c32f57 100644
--- a/gtk/gtkgesturelongpress.c
+++ b/gtk/gtkgesturelongpress.c
@@ -227,14 +227,10 @@ gtk_gesture_long_press_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GtkGestureLongPressPrivate *priv;
-
- priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (object));
-
switch (property_id)
{
case PROP_DELAY_FACTOR:
- g_value_set_double (value, priv->delay_factor);
+ g_value_set_double (value, gtk_gesture_long_press_get_delay_factor (GTK_GESTURE_LONG_PRESS (object)));
break;
default:
@@ -249,14 +245,11 @@ gtk_gesture_long_press_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GtkGestureLongPressPrivate *priv;
-
- priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (object));
-
switch (property_id)
{
case PROP_DELAY_FACTOR:
- priv->delay_factor = g_value_get_double (value);
+ gtk_gesture_long_press_set_delay_factor (GTK_GESTURE_LONG_PRESS (object),
+ g_value_get_double (value));
break;
default:
@@ -288,7 +281,7 @@ gtk_gesture_long_press_class_init (GtkGestureLongPressClass *klass)
P_("Delay factor"),
P_("Factor by which to modify the default timeout"),
0.5, 2.0, 1.0,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkGestureLongPress::pressed:
@@ -339,3 +332,43 @@ gtk_gesture_long_press_new (void)
return g_object_new (GTK_TYPE_GESTURE_LONG_PRESS,
NULL);
}
+
+/**
+ * gtk_gesture_long_press_set_property:
+ * @gesture: A #GtkGestureLongPress
+ * @delay_factor: The delay factor to apply
+ *
+ * Applies the given delay factor. The default long press time will be
+ * multiplied by this value.
+ * Valid values are in the range [0.5..2.0].
+ */
+void
+gtk_gesture_long_press_set_delay_factor (GtkGestureLongPress *gesture,
+ double delay_factor)
+{
+ GtkGestureLongPressPrivate *priv = gtk_gesture_long_press_get_instance_private (gesture);
+
+ g_return_if_fail (GTK_IS_GESTURE_LONG_PRESS (gesture));
+ g_return_if_fail (delay_factor >= 0.5);
+ g_return_if_fail (delay_factor <= 2.0);
+
+ priv->delay_factor = delay_factor;
+
+ g_object_notify (G_OBJECT (gesture), "delay-factor");
+}
+
+/**
+ * gtk_gesture_long_press_get_property:
+ * @gesture: A #GtkGestureLongPress
+ *
+ * Returns the delay factor as set by gtk_gesture_long_press_set_delay_factor().
+ */
+double
+gtk_gesture_long_press_get_delay_factor (GtkGestureLongPress *gesture)
+{
+ GtkGestureLongPressPrivate *priv = gtk_gesture_long_press_get_instance_private (gesture);
+
+ g_return_val_if_fail (GTK_IS_GESTURE_LONG_PRESS (gesture), 0);
+
+ return priv->delay_factor;
+}
diff --git a/gtk/gtkgesturelongpress.h b/gtk/gtkgesturelongpress.h
index f42d78a010..da983355cd 100644
--- a/gtk/gtkgesturelongpress.h
+++ b/gtk/gtkgesturelongpress.h
@@ -44,6 +44,15 @@ GType gtk_gesture_long_press_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkGesture * gtk_gesture_long_press_new (void);
+GDK_AVAILABLE_IN_ALL
+void gtk_gesture_long_press_set_delay_factor (GtkGestureLongPress *gesture,
+ double delay_factor);
+
+GDK_AVAILABLE_IN_ALL
+double gtk_gesture_long_press_get_delay_factor (GtkGestureLongPress *gesture);
+
+
+
G_END_DECLS
#endif /* __GTK_GESTURE_LONG_PRESS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]