Mouse-tracking over Cairo

Hi,

I need to track the mouse position over a cairo context (made from a
gtkDrawingArea). I need to do this for two features: 1) create a
“crosshairs” centered on the mouse position as the user moves it and 2)
a gimp-style select-area feature, where a box is drawn as the mouse
button is held down and dragged across the cairo area (and dissapears on
release - some other unrelated updates happen in response).

I think I’m ok on capturing the mouse events and figuring out the
coordinates (this was discussed in a pure gtk situation in a recent
thread here). What I’d like is a way to draw these fast moving features
that are responding to mouse movements (which are just simple black
lines) without having to have cairo redraw the entire widget. My cairo
drawing requires quite a bit of computation and I want to avoid having
to redraw every time the mouse moves a single pixel.

Is there a good way to do this? Here are the ways I can think of, but
I’m not that familiar with cairo or gtk and don’t know if the systems
actually would allow these:

  1. Draw on the gtk drawing area over the cairo context (somehow). If I
    call get_graphics_context (or whatever it’s called to get a gtk
    drawable) after I call create_cairo_context, will the gtk context be
    drawn on top of the cairo context?

  2. Have 2 cairo_contexts where one is transparent except for the black
    lines (either both from gtkDrawingArea, or one derived from the other),
    and only update the changing one. I’m not sure how I’d do this exactly
    but cairo seems to be built to allow a destination to become a source.
    But would I be able to only have the changing context be redrawn?

  3. I could draw my main cairo drawing onto an image buffer of some kind,
    then keep it around and just draw the black lines on top of it, but that
    seems to defeat the purpose of using a vector based graphics library.

Thanks for any help,
Peter