[gnome-control-center] display: Fix mouse events not working in preview



commit c1857b0f9c80434890679ace83865db5d2565fa6
Author: Benjamin Berg <benjamin sipsolutions net>
Date:   Wed Aug 8 21:49:00 2012 +0200

    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

 panels/display/scrollarea.c |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/panels/display/scrollarea.c b/panels/display/scrollarea.c
index 6946c64..d705f02 100644
--- a/panels/display/scrollarea.c
+++ b/panels/display/scrollarea.c
@@ -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;



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