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




commit d5703af7d7f08c3f07d9fc8999ee9675a6804457
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 | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
---
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index fe28a9730e..9244fc415b 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_ms;
+  int click_count;
+
   /* bitfields */
   guint alignment               : 2;
   guint wrap                    : 1;
@@ -2163,6 +2168,39 @@ clutter_text_select_line (ClutterText *self)
   clutter_text_set_selection (self, start_pos, end_pos);
 }
 
+static int
+clutter_text_update_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_ms + 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_ms = 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)
@@ -2219,7 +2257,9 @@ clutter_text_press (ClutterActor *actor,
        */
       if (type == CLUTTER_BUTTON_PRESS)
         {
-          gint click_count = clutter_event_get_click_count (event);
+          gint click_count;
+
+          click_count = clutter_text_update_click_count (self, event);
 
           if (click_count == 1)
             {


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