[mutter/wip/carlosg/sanitize-gestures: 14/14] clutter: Drop click count from button events




commit 737e5253281054ce6b112714525f7984ca8c5185
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Sep 27 21:46:07 2021 +0200

    clutter: Drop click count from button events
    
    This does two things to frown upon:
    - Modifies ClutterEvent structs, while the effort is to have those
      completely opaque, and readonly after creation from the input
      thread side.
    - Stores state in the ClutterInputDevice struct, event though those
      are also considered static after creation, managed by the input
      thread, etc.
    
    Stop doing that. This makes all events just forwarded as-is in
    the ClutterStage/clutter-main.c code.
    
    Handling of click count sounds like material for a ClutterGestureAction
    (or perhaps ClutterClickAction), all of both callers now do it in place
    at the moment, while gestures lack a better state tracking and management.

 clutter/clutter/clutter-event.c                |  21 -----
 clutter/clutter/clutter-event.h                |   5 --
 clutter/clutter/clutter-input-device-private.h |  10 ---
 clutter/clutter/clutter-input-device.c         |   7 --
 clutter/clutter/clutter-main.c                 | 112 +------------------------
 5 files changed, 1 insertion(+), 154 deletions(-)
---
diff --git a/clutter/clutter/clutter-event.c b/clutter/clutter/clutter-event.c
index 8cfa983a42..4f6c7e0b3f 100644
--- a/clutter/clutter/clutter-event.c
+++ b/clutter/clutter/clutter-event.c
@@ -823,27 +823,6 @@ clutter_event_set_button (ClutterEvent *event,
   event->button.button = button;
 }
 
-/**
- * clutter_event_get_click_count:
- * @event: a #ClutterEvent of type %CLUTTER_BUTTON_PRESS or
- *   of type %CLUTTER_BUTTON_RELEASE
- *
- * Retrieves the number of clicks of @event
- *
- * Return value: the click count
- *
- * Since: 1.0
- */
-guint32
-clutter_event_get_click_count (const ClutterEvent *event)
-{
-  g_return_val_if_fail (event != NULL, 0);
-  g_return_val_if_fail (event->type == CLUTTER_BUTTON_PRESS ||
-                        event->type == CLUTTER_BUTTON_RELEASE, 0);
-
-  return event->button.click_count;
-}
-
 /* keys */
 
 /**
diff --git a/clutter/clutter/clutter-event.h b/clutter/clutter/clutter-event.h
index a14b2eca38..7595e83353 100644
--- a/clutter/clutter/clutter-event.h
+++ b/clutter/clutter/clutter-event.h
@@ -188,8 +188,6 @@ struct _ClutterKeyEvent
  * @y: event Y coordinate, relative to the stage
  * @modifier_state: button modifiers
  * @button: event button
- * @click_count: number of button presses within the default time
- *   and radius
  * @axes: reserved for future use
  * @device: the device that originated the event. If you want the physical
  * device the event originated from, use clutter_event_get_source_device()
@@ -214,7 +212,6 @@ struct _ClutterButtonEvent
   gfloat y;
   ClutterModifierType modifier_state;
   guint32 button;
-  guint click_count;
   gdouble *axes; /* Future use */
   ClutterInputDevice *device;
   uint32_t evdev_code;
@@ -740,8 +737,6 @@ void                    clutter_event_set_button                (ClutterEvent
 CLUTTER_EXPORT
 guint32                 clutter_event_get_button                (const ClutterEvent     *event);
 CLUTTER_EXPORT
-guint                   clutter_event_get_click_count           (const ClutterEvent     *event);
-CLUTTER_EXPORT
 void                    clutter_event_set_related               (ClutterEvent           *event,
                                                                  ClutterActor           *actor);
 CLUTTER_EXPORT
diff --git a/clutter/clutter/clutter-input-device-private.h b/clutter/clutter/clutter-input-device-private.h
index a2168cc071..91f6e8e1c0 100644
--- a/clutter/clutter/clutter-input-device-private.h
+++ b/clutter/clutter/clutter-input-device-private.h
@@ -59,16 +59,6 @@ struct _ClutterInputDevice
   GHashTable   *sequence_grab_actors;
   GHashTable   *inv_sequence_grab_actors;
 
-  /* the current click count */
-  int click_count;
-  int current_button_number;
-
-  /* the previous state, used for click count generation */
-  int previous_x;
-  int previous_y;
-  uint32_t previous_time;
-  int previous_button_number;
-
   /* Accessiblity */
   ClutterVirtualInputDevice *accessibility_virtual_device;
   ClutterPtrA11yData *ptr_a11y_data;
diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c
index 3a31cdc802..5a496f09c7 100644
--- a/clutter/clutter/clutter-input-device.c
+++ b/clutter/clutter/clutter-input-device.c
@@ -427,13 +427,6 @@ clutter_input_device_init (ClutterInputDevice *self)
     clutter_input_device_get_instance_private (self);
 
   priv->device_type = CLUTTER_POINTER_DEVICE;
-
-  self->click_count = 0;
-
-  self->previous_time = CLUTTER_CURRENT_TIME;
-  self->previous_x = -1;
-  self->previous_y = -1;
-  self->current_button_number = self->previous_button_number = -1;
 }
 
 /**
diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c
index 195c2e5cfc..c02b7695fb 100644
--- a/clutter/clutter/clutter-main.c
+++ b/clutter/clutter/clutter-main.c
@@ -1001,107 +1001,6 @@ _clutter_boolean_continue_accumulator (GSignalInvocationHint *ihint,
   return continue_emission;
 }
 
-static void
-event_click_count_generate (ClutterEvent *event)
-{
-  /* multiple button click detection */
-  static gint    click_count            = 0;
-  static gint    previous_x             = -1;
-  static gint    previous_y             = -1;
-  static guint32 previous_time          = 0;
-  static gint    previous_button_number = -1;
-
-  ClutterInputDevice *device = NULL;
-  ClutterSettings *settings;
-  guint double_click_time;
-  guint double_click_distance;
-
-  settings = clutter_settings_get_default ();
-
-  g_object_get (settings,
-                "double-click-distance", &double_click_distance,
-                "double-click-time", &double_click_time,
-                NULL);
-
-  device = clutter_event_get_device (event);
-  if (device != NULL)
-    {
-      click_count = device->click_count;
-      previous_x = device->previous_x;
-      previous_y = device->previous_y;
-      previous_time = device->previous_time;
-      previous_button_number = device->previous_button_number;
-
-      CLUTTER_NOTE (EVENT,
-                    "Restoring previous click count:%d (device:%s, time:%u)",
-                    click_count,
-                    clutter_input_device_get_device_name (device),
-                    previous_time);
-    }
-  else
-    {
-      CLUTTER_NOTE (EVENT,
-                    "Restoring previous click count:%d (time:%u)",
-                    click_count,
-                    previous_time);
-    }
-
-  switch (clutter_event_type (event))
-    {
-      case CLUTTER_BUTTON_PRESS:
-        /* check if we are in time and within distance to increment an
-         * existing click count
-         */
-        if (event->button.button == previous_button_number &&
-            event->button.time < (previous_time + double_click_time) &&
-            (ABS (event->button.x - previous_x) <= double_click_distance) &&
-            (ABS (event->button.y - previous_y) <= double_click_distance))
-          {
-            CLUTTER_NOTE (EVENT, "Increase click count (button: %d, time: %u)",
-                          event->button.button,
-                          event->button.time);
-
-            click_count += 1;
-          }
-        else /* start a new click count*/
-          {
-            CLUTTER_NOTE (EVENT, "Reset click count (button: %d, time: %u)",
-                          event->button.button,
-                          event->button.time);
-
-            click_count = 1;
-            previous_button_number = event->button.button;
-          }
-
-        previous_x = event->button.x;
-        previous_y = event->button.y;
-        previous_time = event->button.time;
-
-        G_GNUC_FALLTHROUGH;
-      case CLUTTER_BUTTON_RELEASE:
-        event->button.click_count = click_count;
-        break;
-
-      default:
-        g_assert_not_reached ();
-        break;
-    }
-
-  if (event->type == CLUTTER_BUTTON_PRESS && device != NULL)
-    {
-      CLUTTER_NOTE (EVENT, "Storing click count: %d (device:%s, time:%u)",
-                    click_count,
-                    clutter_input_device_get_device_name (device),
-                    previous_time);
-
-      device->click_count = click_count;
-      device->previous_x = previous_x;
-      device->previous_y = previous_y;
-      device->previous_time = previous_time;
-      device->previous_button_number = previous_button_number;
-    }
-}
-
 static inline void
 emit_event_chain (ClutterEvent *event)
 {
@@ -1116,7 +1015,7 @@ emit_event_chain (ClutterEvent *event)
 
 /*
  * Emits a pointer event after having prepared the event for delivery (setting
- * source, computing click_count, generating enter/leave etc.).
+ * source, generating enter/leave etc.).
  */
 
 static inline void
@@ -1593,7 +1492,6 @@ _clutter_process_event_details (ClutterActor        *stage,
                                     x, y);
 
                       event->button.source = stage;
-                      event->button.click_count = 1;
 
                       emit_pointer_event (event, device);
                     }
@@ -1638,14 +1536,6 @@ _clutter_process_event_details (ClutterActor        *stage,
                         x, y,
                         event->any.source);
 
-          /* button presses and releases need a click count */
-          if (event->type == CLUTTER_BUTTON_PRESS ||
-              event->type == CLUTTER_BUTTON_RELEASE)
-            {
-              /* Generate click count */
-              event_click_count_generate (event);
-            }
-
           emit_pointer_event (event, device);
           break;
         }


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