[mutter] clutter/input-pointer-a11y: Trigger dwell detection in a timeout



commit 14e02635ff1136546ca5b482063200d4a69e5862
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Fri Aug 23 15:39:12 2019 +0300

    clutter/input-pointer-a11y: Trigger dwell detection in a timeout
    
    Restarting the dwell click immediately would result in a contant
    animation showing.
    
    Start dwell detection in its own timeout handler, which has the nice
    effect of not constantly showing a dwell animation and also making sure
    that the dwell click timeout is started when pointer movement stops.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/747

 clutter/clutter/clutter-device-manager-private.h |  1 +
 clutter/clutter/clutter-input-pointer-a11y.c     | 37 +++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)
---
diff --git a/clutter/clutter/clutter-device-manager-private.h 
b/clutter/clutter/clutter-device-manager-private.h
index 40a1c7691..7aaf79b4c 100644
--- a/clutter/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter/clutter-device-manager-private.h
@@ -80,6 +80,7 @@ typedef struct _ClutterPtrA11yData
   gboolean dwell_drag_started;
   gboolean dwell_gesture_started;
   guint dwell_timer;
+  guint dwell_position_timer;
 
   guint secondary_click_timer;
   gboolean secondary_click_triggered;
diff --git a/clutter/clutter/clutter-input-pointer-a11y.c b/clutter/clutter/clutter-input-pointer-a11y.c
index 0e7c5847b..e31cbb670 100644
--- a/clutter/clutter/clutter-input-pointer-a11y.c
+++ b/clutter/clutter/clutter-input-pointer-a11y.c
@@ -518,6 +518,36 @@ stop_dwell_timeout (ClutterInputDevice *device)
     }
 }
 
+static gboolean
+trigger_dwell_position_timeout (gpointer data)
+{
+  ClutterInputDevice *device = data;
+
+  device->ptr_a11y_data->dwell_position_timer = 0;
+
+  if (is_dwell_click_enabled (device))
+    {
+      if (!pointer_has_moved (device))
+        start_dwell_timeout (device);
+    }
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+start_dwell_position_timeout (ClutterInputDevice *device)
+{
+  device->ptr_a11y_data->dwell_position_timer =
+    clutter_threads_add_timeout (100, trigger_dwell_position_timeout, device);
+}
+
+static void
+stop_dwell_position_timeout (ClutterInputDevice *device)
+{
+  g_clear_handle_id (&device->ptr_a11y_data->dwell_position_timer,
+                     g_source_remove);
+}
+
 static void
 update_dwell_position (ClutterInputDevice *device)
 {
@@ -570,6 +600,7 @@ _clutter_input_pointer_a11y_remove_device (ClutterInputDevice *device)
   if (is_dwell_dragging (device))
     emit_dwell_click (device, CLUTTER_A11Y_DWELL_CLICK_TYPE_DRAG);
 
+  stop_dwell_position_timeout (device);
   stop_dwell_timeout (device);
   stop_secondary_click_timeout (device);
 
@@ -597,11 +628,13 @@ _clutter_input_pointer_a11y_on_motion_event (ClutterInputDevice *device,
 
   if (is_dwell_click_enabled (device))
     {
+      stop_dwell_position_timeout (device);
+
       if (should_stop_dwell (device))
         stop_dwell_timeout (device);
 
       if (should_start_dwell (device))
-        start_dwell_timeout (device);
+        start_dwell_position_timeout (device);
     }
 
   if (should_update_dwell_position (device))
@@ -623,6 +656,8 @@ _clutter_input_pointer_a11y_on_button_event (ClutterInputDevice *device,
     {
       device->ptr_a11y_data->n_btn_pressed++;
 
+      stop_dwell_position_timeout (device);
+
       if (is_dwell_click_enabled (device))
         stop_dwell_timeout (device);
 


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