From 86c92c37d22eca0cb2bebe6a613865b897ec9248 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Wed, 10 Apr 2013 16:31:39 +0200 Subject: [PATCH] st-im-text: Override ClutterText's cursor_event to set cursor position This is both more efficient and accurate than doing it from the paint vfunc. https://bugzilla.gnome.org/show_bug.cgi?id=697722 --- src/st/st-im-text.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/st/st-im-text.c b/src/st/st-im-text.c index c0dfdc546..efe9dca15 100644 --- a/src/st/st-im-text.c +++ b/src/st/st-im-text.c @@ -74,27 +74,24 @@ st_im_text_dispose (GObject *object) } static void -update_im_cursor_location (StIMText *self) +st_im_text_cursor_event (ClutterText *self, + const ClutterGeometry *geometry) { - StIMTextPrivate *priv = self->priv; - ClutterText *clutter_text = CLUTTER_TEXT (self); - gint position; - gfloat cursor_x, cursor_y, cursor_height; + StIMTextPrivate *priv = ST_IM_TEXT (self)->priv; gfloat actor_x, actor_y; GdkRectangle area; - position = clutter_text_get_cursor_position (clutter_text); - clutter_text_position_to_coords (clutter_text, position, - &cursor_x, &cursor_y, &cursor_height); - clutter_actor_get_transformed_position (CLUTTER_ACTOR (self), &actor_x, &actor_y); - area.x = (int)(0.5 + cursor_x + actor_x); - area.y = (int)(0.5 + cursor_y + actor_y); - area.width = 0; - area.height = (int)(0.5 + cursor_height); + area.x = (int)(0.5 + geometry->x + actor_x); + area.y = (int)(0.5 + geometry->y + actor_y); + area.width = geometry->width; + area.height = geometry->height; gtk_im_context_set_cursor_location (priv->im_context, &area); + + if (CLUTTER_TEXT_CLASS (st_im_text_parent_class)->cursor_event) + CLUTTER_TEXT_CLASS (st_im_text_parent_class)->cursor_event (self, geometry); } static void @@ -190,20 +187,6 @@ reset_im_context (StIMText *self) } } -static void -st_im_text_paint (ClutterActor *actor) -{ - StIMText *self = ST_IM_TEXT (actor); - ClutterText *clutter_text = CLUTTER_TEXT (actor); - - /* This updates the cursor position as a side-effect */ - if (CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->paint) - CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->paint (actor); - - if (clutter_text_get_editable (clutter_text)) - update_im_cursor_location (self); -} - static gboolean st_im_text_get_paint_volume (ClutterActor *self, ClutterPaintVolume *volume) @@ -426,12 +409,12 @@ st_im_text_class_init (StIMTextClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); + ClutterTextClass *text_class = CLUTTER_TEXT_CLASS (klass); g_type_class_add_private (klass, sizeof (StIMTextPrivate)); object_class->dispose = st_im_text_dispose; - actor_class->paint = st_im_text_paint; actor_class->get_paint_volume = st_im_text_get_paint_volume; actor_class->realize = st_im_text_realize; actor_class->unrealize = st_im_text_unrealize; @@ -440,6 +423,8 @@ st_im_text_class_init (StIMTextClass *klass) actor_class->captured_event = st_im_text_captured_event; actor_class->key_focus_in = st_im_text_key_focus_in; actor_class->key_focus_out = st_im_text_key_focus_out; + + text_class->cursor_event = st_im_text_cursor_event; } static void