[mutter/wip/carlosg/sanitize-gestures: 11/14] frames: Keep accounting of double clicks in place




commit 9333c176bdd8389e1ca0735b20ccd61960a73a29
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Sep 27 20:31:21 2021 +0200

    frames: Keep accounting of double clicks in place
    
    Instead of relying on ClutterEvent information.

 src/ui/frames.c | 40 +++++++++++++++++++++++++++++++++++++---
 src/ui/frames.h |  5 +++++
 2 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 48b2a361c2..eceef1f293 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -972,8 +972,42 @@ grab_op_from_resize_control (MetaFrameControl control)
     }
 }
 
+static int
+meta_ui_frame_get_click_count (MetaUIFrame        *frame,
+                               const ClutterEvent *event)
+{
+  MetaFrames *frames = frame->frames;
+  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 > (frames->last_click_time + double_click_time) ||
+      (ABS (x - frames->last_click_x) > double_click_distance) ||
+      (ABS (y - frames->last_click_y) > double_click_distance))
+    frames->click_count = 0;
+
+  frames->last_click_time = evtime;
+  frames->last_click_x = x;
+  frames->last_click_y = y;
+
+  frames->click_count = (frames->click_count % 3) + 1;
+
+  return frames->click_count;
+}
+
 static guint
-get_action (const ClutterEvent *event)
+get_action (MetaUIFrame        *frame,
+            const ClutterEvent *event)
 {
   if (event->type == CLUTTER_BUTTON_PRESS ||
       event->type == CLUTTER_BUTTON_RELEASE)
@@ -981,7 +1015,7 @@ get_action (const ClutterEvent *event)
       switch (event->button.button)
         {
         case CLUTTER_BUTTON_PRIMARY:
-          if (clutter_event_get_click_count (event) == 2)
+          if (meta_ui_frame_get_click_count (frame, event) == 2)
             return META_ACTION_DOUBLE_CLICK;
           else
             return META_ACTION_CLICK;
@@ -1138,7 +1172,7 @@ handle_press_event (MetaUIFrame        *frame,
   g_assert (event->type == CLUTTER_BUTTON_PRESS ||
             event->type == CLUTTER_TOUCH_BEGIN);
 
-  action = get_action (event);
+  action = get_action (frame, event);
   if (action == META_ACTION_IGNORE)
     return FALSE;
 
diff --git a/src/ui/frames.h b/src/ui/frames.h
index d81be1c726..89b3992650 100644
--- a/src/ui/frames.h
+++ b/src/ui/frames.h
@@ -105,6 +105,11 @@ struct _MetaFrames
   gdouble grab_y;
 
   ClutterEventSequence *grab_touch;
+
+  float last_click_x;
+  float last_click_y;
+  uint32_t last_click_time;
+  int click_count;
 };
 
 struct _MetaFramesClass


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