From 1c42e6334e535dbd9015c20810a6560195803f1c Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 21 Apr 2009 12:06:14 +0100 Subject: [PATCH] [text] Emit ::cursor-event only on changes The documentation for the ::cursor-event says that the signal is emitted only when the cursor position changes. Right now it is being emitted every time we ensure the cursor position during the Text paint sequence. The clutter_text_ensure_cursor_position() function should check whether the stored cursor position has changed since the last paint, and emit the ::cursor-event signal only when there has been a change. --- clutter/clutter-text.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index eb7e42187..74d943f11 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -536,18 +536,31 @@ clutter_text_ensure_cursor_position (ClutterText *self) { ClutterTextPrivate *priv = self->priv; ClutterUnit x, y, cursor_height; + ClutterGeometry cursor_pos = { 0, }; + gboolean x_changed, y_changed; + gboolean width_changed, height_changed; x = y = cursor_height = 0; clutter_text_position_to_coords (self, priv->position, &x, &y, &cursor_height); - priv->cursor_pos.x = CLUTTER_UNITS_TO_DEVICE (x); - priv->cursor_pos.y = CLUTTER_UNITS_TO_DEVICE (y); - priv->cursor_pos.width = priv->cursor_size; - priv->cursor_pos.height = CLUTTER_UNITS_TO_DEVICE (cursor_height) - 2; + cursor_pos.x = CLUTTER_UNITS_TO_DEVICE (x); + cursor_pos.y = CLUTTER_UNITS_TO_DEVICE (y); + cursor_pos.width = priv->cursor_size; + cursor_pos.height = CLUTTER_UNITS_TO_DEVICE (cursor_height) - 2; - g_signal_emit (self, text_signals[CURSOR_EVENT], 0, &priv->cursor_pos); + x_changed = priv->cursor_pos.x != cursor_pos.x; + y_changed = priv->cursor_pos.y != cursor_pos.y; + width_changed = priv->cursor_pos.width != cursor_pos.width; + height_changed = priv->cursor_pos.height != cursor_pos.height; + + if (x_changed || y_changed || width_changed || height_changed) + { + priv->cursor_pos = cursor_pos; + + g_signal_emit (self, text_signals[CURSOR_EVENT], 0, &priv->cursor_pos); + } } static gboolean