display: Fix mouse events not working in preview

We need to save event areas with the correct transformation.

The following things need to be take into account:
 * Current cairo matrix (translations)
 * Widget allocation because it is painting on the parents widgets window
 * Cairo device offset, which GTK+ sets (but not for a full window redraw)

https://bugzilla.gnome.org/show_bug.cgi?id=681475
This commit is contained in:
Benjamin Berg 2012-08-08 21:49:00 +02:00 committed by Bastien Nocera
parent 72cce6b89f
commit c1857b0f9c

View file

@ -1182,16 +1182,31 @@ foo_scroll_area_set_min_size (FooScrollArea *scroll_area,
gtk_widget_queue_resize (GTK_WIDGET (scroll_area));
}
typedef struct {
cairo_t *cr;
GtkAllocation allocation;
} user_to_device_data;
static void
user_to_device (double *x, double *y,
gpointer data)
gpointer user_data)
{
#if 0
cairo_t *cr = data;
gdouble ox, oy;
user_to_device_data* data = user_data;
/* FIXME: not set transform in first place? */
cairo_user_to_device (cr, x, y);
#endif
/* Required in case the user does transformations (eg. translates) */
cairo_user_to_device (data->cr, x, y);
/* The device offset is different for a full redraw.
* So we cannot make assumptions about it. */
cairo_surface_get_device_offset(cairo_get_target(data->cr), &ox, &oy);
*x -= ox;
*y -= oy;
/* The input_window does not of the allocation offset. */
*x -= data->allocation.x;
*y -= data->allocation.y;
}
static InputPath *
@ -1201,13 +1216,18 @@ make_path (FooScrollArea *area,
FooScrollAreaEventFunc func,
gpointer data)
{
user_to_device_data conversion_data;
InputPath *path = g_new0 (InputPath, 1);
conversion_data.cr = cr;
gtk_widget_get_allocation(GTK_WIDGET (area), &conversion_data.allocation);
path->is_stroke = is_stroke;
path->fill_rule = cairo_get_fill_rule (cr);
path->line_width = cairo_get_line_width (cr);
path->path = cairo_copy_path (cr);
path_foreach_point (path->path, user_to_device, cr);
path_foreach_point (path->path, user_to_device, &conversion_data);
path->func = func;
path->data = data;
path->next = area->priv->current_input->paths;