From a235d03550b7a8b7c2b3e7a53bf69a4592a6c4fe Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 27 Sep 2021 20:19:29 +0200 Subject: [PATCH] clutter: Carry accounting on double/triple clicks in ClutterText Instead of using the ClutterEvent information. Part-of: --- 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 fe28a9730..9244fc415 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) {