[mutter/wip/carlosg/sanitize-gestures: 10/14] clutter: Carry accounting on double/triple clicks in ClutterText




commit 7555e40f66a1161997f60a86636afedca7e93142
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Sep 27 20:19:29 2021 +0200

    clutter: Carry accounting on double/triple clicks in ClutterText
    
    Instead of using the ClutterEvent information.

 clutter/clutter/clutter-text.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index 08d17f6ce8..4a23ee46f1 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -187,6 +187,11 @@ struct _ClutterTextPrivate
   ClutterInputContentHintFlags input_hints;
   ClutterInputContentPurpose input_purpose;
 
+  float last_click_x;
+  float last_click_y;
+  uint32_t last_click_time;
+  int click_count;
+
   /* bitfields */
   guint alignment               : 2;
   guint wrap                    : 1;
@@ -2151,6 +2156,39 @@ clutter_text_select_line (ClutterText *self)
   clutter_text_set_selection (self, start_pos, end_pos);
 }
 
+static int
+clutter_text_get_click_count (ClutterText        *self,
+                              const ClutterEvent *event)
+{
+  ClutterTextPrivate *priv = self->priv;
+  ClutterSettings *settings;
+  int double_click_time, double_click_distance;
+  uint32_t evtime;
+  float x, y;
+
+  settings = clutter_settings_get_default ();
+  clutter_event_get_coords (event, &x, &y);
+  evtime = clutter_event_get_time (event);
+
+  g_object_get (settings,
+                "double-click-distance", &double_click_distance,
+                "double-click-time", &double_click_time,
+                NULL);
+
+  if (evtime > (priv->last_click_time + double_click_time) ||
+      (ABS (x - priv->last_click_x) > double_click_distance) ||
+      (ABS (y - priv->last_click_y) > double_click_distance))
+    priv->click_count = 0;
+
+  priv->last_click_time = evtime;
+  priv->last_click_x = x;
+  priv->last_click_y = y;
+
+  priv->click_count = (priv->click_count % 3) + 1;
+
+  return priv->click_count;
+}
+
 static gboolean
 clutter_text_press (ClutterActor *actor,
                     ClutterEvent *event)
@@ -2207,7 +2245,7 @@ clutter_text_press (ClutterActor *actor,
        */
       if (type == CLUTTER_BUTTON_PRESS)
         {
-          gint click_count = clutter_event_get_click_count (event);
+          gint click_count = clutter_text_get_click_count (self, event);
 
           if (click_count == 1)
             {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]