catching motion signals on a gtk text widget



hi,

I'm continuing my project to get words in a GtkTextView to highlight as
the mouse passes over them.

I cannot really find a signal that catches mouse motion on the
GtkTextView widget.

At first I tried the 'event' signal on GtkTextTags but that doesn't
catch motion events (except those that enter the widget).

Now I am simply connecting to widget signals on the GtkTextView widget.
I have tried the following events:
event
event-after
motion-notify-event

I connect my signal as follows:

        g_signal_connect (G_OBJECT (translation_view), "event", 
                          G_CALLBACK (highlight_text_cb), NULL); 

(I have also tried using connect_after)

My callback usually has stuff like this:
highlight_text_cb (GtkWidget *widget, GdkEvent *event, gpointer
user_data)
{
        gint buffer_x, buffer_y;

        /* Work out the coords. */
        gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW
(translation_view), GTK_TEXT_WINDOW_WIDGET, event->motion.x,
event->motion.y, &buffer_x, &buffer_y);
        g_print ("event:%f %f %i %i\n", event->motion.x, event->motion.y,
buffer_x, buffer_y);

[snipped]

What I find with a callback like this is that I get a whole lot of lines
printed to stdout when I do stuff like enter the widget, click, scroll
wheel, and sometimes a little bit of motion, but it doesn't seem to
capture all motion.

My function has extra code to get the iter at the location, then to get
the relevant text tag (there is one per word), and then to highlight
that tag. I also have a problem that setting tag attributes might make
the event trigger more callbacks...

How can I get a signal callback that will be called whenever there is
pointer motion?

I have been looking at the scribble example, but the way it uses signals
doesn't seem to help me. It uses a motion-notify-event. Could it be that
the motion-notify-event works better on the GtkDrawingArea widget than
it does on the TextView? 
Have the number of motion-notify-event emissions on a GtkTextView been
trimmed down to speed it up?

thanks,
wayne




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