clutter: Carry accounting on double/triple clicks in ClutterText

Instead of using the ClutterEvent information.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2024>
This commit is contained in:
Carlos Garnacho 2021-09-27 20:19:29 +02:00
parent 6d0b7381da
commit a235d03550

View File

@ -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)
{