summaryrefslogtreecommitdiff
path: root/gtk/gtkgesturesingle.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2014-05-12 19:50:26 +0200
committerCarlos Garnacho <carlosg@gnome.org>2014-05-23 19:54:31 +0200
commit0b3f4d5555dd44d09e96f58aa6d72fe4b91f0745 (patch)
tree0f3aab90d3a859d5f15cb18e8777a81531695690 /gtk/gtkgesturesingle.c
parentfd9925141b38d464d2cc60a31ecf5f3b58953dc5 (diff)
downloadgtk+-0b3f4d5555dd44d09e96f58aa6d72fe4b91f0745.tar.gz
gesturesingle: Add an "exclusive" boolean property
All "exclusive" gestures listen for either pointer events, or "pointer emulating" touch events, so only a single sequence at a time can make these run.
Diffstat (limited to 'gtk/gtkgesturesingle.c')
-rw-r--r--gtk/gtkgesturesingle.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/gtk/gtkgesturesingle.c b/gtk/gtkgesturesingle.c
index 8d8f1188bd..ef95bd39cf 100644
--- a/gtk/gtkgesturesingle.c
+++ b/gtk/gtkgesturesingle.c
@@ -48,10 +48,12 @@ struct _GtkGestureSinglePrivate
guint button;
guint current_button;
guint touch_only : 1;
+ guint exclusive : 1;
};
enum {
PROP_TOUCH_ONLY = 1,
+ PROP_EXCLUSIVE,
PROP_BUTTON
};
@@ -73,6 +75,9 @@ gtk_gesture_single_get_property (GObject *object,
case PROP_TOUCH_ONLY:
g_value_set_boolean (value, priv->touch_only);
break;
+ case PROP_EXCLUSIVE:
+ g_value_set_boolean (value, priv->exclusive);
+ break;
case PROP_BUTTON:
g_value_set_uint (value, priv->button);
break;
@@ -93,6 +98,10 @@ gtk_gesture_single_set_property (GObject *object,
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (object),
g_value_get_boolean (value));
break;
+ case PROP_EXCLUSIVE:
+ gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (object),
+ g_value_get_boolean (value));
+ break;
case PROP_BUTTON:
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (object),
g_value_get_uint (value));
@@ -136,6 +145,9 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_END:
case GDK_TOUCH_UPDATE:
+ if (priv->exclusive && !event->touch.emulating_pointer)
+ return FALSE;
+
sequence = event->touch.sequence;
button = 1;
break;
@@ -227,6 +239,21 @@ gtk_gesture_single_class_init (GtkGestureSingleClass *klass)
TRUE,
GTK_PARAM_READWRITE));
/**
+ * GtkGestureSingle:exclusive:
+ *
+ * Whether the gesture is exclusive. Exclusive gestures only listen to pointer
+ * and pointer emulated events.
+ *
+ * Since: 3.14
+ */
+ g_object_class_install_property (object_class,
+ PROP_EXCLUSIVE,
+ g_param_spec_boolean ("exclusive",
+ P_("Whether the gesture is exclusive"),
+ P_("Whether the gesture is exclusive"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+ /**
* GtkGestureSingle:button:
*
* Mouse button number to listen to, or 0 to listen for any button.
@@ -326,6 +353,60 @@ gtk_gesture_single_set_touch_only (GtkGestureSingle *gesture,
}
/**
+ * gtk_gesture_single_get_exclusive:
+ * @gesture: a #GtkGestureSingle
+ *
+ * Gets whether a gesture is exclusive. For more information, see
+ * gtk_gesture_single_set_exclusive().
+ *
+ * Returns: Whether the gesture is exclusive
+ *
+ * Since: 3.14
+ **/
+gboolean
+gtk_gesture_single_get_exclusive (GtkGestureSingle *gesture)
+{
+ GtkGestureSinglePrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_GESTURE_SINGLE (gesture), FALSE);
+
+ priv = gtk_gesture_single_get_instance_private (gesture);
+
+ return priv->exclusive;
+}
+
+/**
+ * gtk_gesture_single_set_exclusive:
+ * @gesture: a #GtkGestureSingle
+ * @exclusive: #TRUE to make @gesture exclusive
+ *
+ * Sets whether @gesture is exclusive. An exclusive gesture will
+ * only handle pointer and "pointer emulated" touch events, so at
+ * any given time, there is only one sequence able to interact with
+ * those.
+ *
+ * Since: 3.14
+ **/
+void
+gtk_gesture_single_set_exclusive (GtkGestureSingle *gesture,
+ gboolean exclusive)
+{
+ GtkGestureSinglePrivate *priv;
+
+ g_return_if_fail (GTK_IS_GESTURE_SINGLE (gesture));
+
+ exclusive = exclusive != FALSE;
+ priv = gtk_gesture_single_get_instance_private (gesture);
+
+ if (priv->exclusive == exclusive)
+ return;
+
+ priv->exclusive = exclusive;
+ _gtk_gesture_single_update_evmask (gesture);
+ g_object_notify (G_OBJECT (gesture), "exclusive");
+}
+
+/**
* gtk_gesture_single_get_button:
* @gesture: a #GtkGestureSingle
*