Code

Change lcms transforms to match change of display buffer from RGB-24 to ARGB-32
[inkscape.git] / src / display / sp-canvas.cpp
index 104172b63a9a3f6df465492ff651b87d63f59f63..97713b18e1e69a557a6a998940d40f8b66792c86 100644 (file)
 
 #include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
+#include <gtk/gtkversion.h>
 
 #include <gtkmm.h>
 
 #include <helper/sp-marshal.h>
+#include <helper/recthull.h>
 #include <display/sp-canvas.h>
 #include "display-forward.h"
 #include <libnr/nr-matrix-fns.h>
 #include <libnr/nr-matrix-ops.h>
 #include <libnr/nr-convex-hull.h>
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "inkscape.h"
 #include "sodipodi-ctrlrect.h"
 #if ENABLE_LCMS
 #include "display/rendermode.h"
 #include "libnr/nr-blit.h"
 #include "display/inkscape-cairo.h"
+#include "debug/gdk-event-latency-tracker.h"
+#include "desktop.h"
+#include "sp-namedview.h"
+
+using Inkscape::Debug::GdkEventLatencyTracker;
+
+// GTK_CHECK_VERSION returns false on failure
+#define HAS_GDK_EVENT_REQUEST_MOTIONS GTK_CHECK_VERSION(2, 12, 0)
+
+// gtk_check_version returns non-NULL on failure
+static bool const HAS_BROKEN_MOTION_HINTS =
+  true || gtk_check_version(2, 12, 0) != NULL || !HAS_GDK_EVENT_REQUEST_MOTIONS;
 
 // Define this to visualize the regions to be redrawn
 //#define DEBUG_REDRAW 1;
@@ -94,6 +108,7 @@ enum {ITEM_EVENT, ITEM_LAST_SIGNAL};
 
 static void sp_canvas_request_update (SPCanvas *canvas);
 
+static void track_latency(GdkEvent const *event);
 static void sp_canvas_item_class_init (SPCanvasItemClass *klass);
 static void sp_canvas_item_init (SPCanvasItem *item);
 static void sp_canvas_item_dispose (GObject *object);
@@ -159,7 +174,7 @@ static void
 sp_canvas_item_init (SPCanvasItem *item)
 {
     item->flags |= SP_CANVAS_ITEM_VISIBLE;
-    item->xform = NR::Matrix(NR::identity());
+    item->xform = Geom::Matrix(Geom::identity());
 }
 
 /**
@@ -234,7 +249,7 @@ sp_canvas_item_dispose (GObject *object)
     // this redraws only the stroke of the rect to be deleted,
     // avoiding redraw of the entire area
     if (SP_IS_CTRLRECT(item)) {
-        SP_CTRLRECT(object)->setRectangle(NR::Rect(NR::Point(0,0),NR::Point(0,0)));
+        SP_CTRLRECT(object)->setRectangle(Geom::Rect(Geom::Point(0,0),Geom::Point(0,0)));
         SP_CTRLRECT(object)->update(item->xform, 0);
     } else {
         redraw_if_visible (item);
@@ -272,10 +287,10 @@ sp_canvas_item_dispose (GObject *object)
  * NB! affine is parent2canvas.
  */
 static void
-sp_canvas_item_invoke_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
+sp_canvas_item_invoke_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 {
     /* Apply the child item's transform */
-    NR::Matrix child_affine = item->xform * affine;
+    Geom::Matrix child_affine = item->xform * affine;
 
     /* apply object flags to child flags */
     int child_flags = flags & ~SP_CANVAS_UPDATE_REQUESTED;
@@ -303,7 +318,7 @@ sp_canvas_item_invoke_update (SPCanvasItem *item, NR::Matrix const &affine, unsi
  * maintaining the affine invariant.
  */
 static double
-sp_canvas_item_invoke_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
+sp_canvas_item_invoke_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item)
 {
     if (SP_CANVAS_ITEM_GET_CLASS (item)->point)
         return SP_CANVAS_ITEM_GET_CLASS (item)->point (item, p, actual_item);
@@ -319,7 +334,7 @@ sp_canvas_item_invoke_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **act
  * @affine: An affine transformation matrix.
  */
 void
-sp_canvas_item_affine_absolute (SPCanvasItem *item, NR::Matrix const &affine)
+sp_canvas_item_affine_absolute (SPCanvasItem *item, Geom::Matrix const &affine)
 {
     item->xform = affine;
 
@@ -531,6 +546,10 @@ sp_canvas_item_grab (SPCanvasItem *item, guint event_mask, GdkCursor *cursor, gu
     if (!(item->flags & SP_CANVAS_ITEM_VISIBLE))
         return -1;
 
+    if (HAS_BROKEN_MOTION_HINTS) {
+        event_mask &= ~GDK_POINTER_MOTION_HINT_MASK;
+    }
+
     /* fixme: Top hack (Lauris) */
     /* fixme: If we add key masks to event mask, Gdk will abort (Lauris) */
     /* fixme: But Canvas actualle does get key events, so all we need is routing these here */
@@ -570,11 +589,11 @@ sp_canvas_item_ungrab (SPCanvasItem *item, guint32 etime)
  * Returns the product of all transformation matrices from the root item down
  * to the item.
  */
-NR::Matrix sp_canvas_item_i2w_affine(SPCanvasItem const *item)
+Geom::Matrix sp_canvas_item_i2w_affine(SPCanvasItem const *item)
 {
     g_assert (SP_IS_CANVAS_ITEM (item)); // should we get this?
 
-    NR::Matrix affine = NR::identity();
+    Geom::Matrix affine = Geom::identity();
 
     while (item) {
         affine *= item->xform;
@@ -669,8 +688,8 @@ static void sp_canvas_group_class_init (SPCanvasGroupClass *klass);
 static void sp_canvas_group_init (SPCanvasGroup *group);
 static void sp_canvas_group_destroy (GtkObject *object);
 
-static void sp_canvas_group_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
-static double sp_canvas_group_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
+static void sp_canvas_group_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
+static double sp_canvas_group_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item);
 static void sp_canvas_group_render (SPCanvasItem *item, SPCanvasBuf *buf);
 
 static SPCanvasItemClass *group_parent_class;
@@ -754,10 +773,10 @@ sp_canvas_group_destroy (GtkObject *object)
  * Update handler for canvas groups
  */
 static void
-sp_canvas_group_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
+sp_canvas_group_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 {
     SPCanvasGroup const *group = SP_CANVAS_GROUP (item);
-    NR::ConvexHull corners(NR::Point(0, 0));
+    Geom::RectHull corners(Geom::Point(0, 0));
     bool empty=true;
 
     for (GList *list = group->items; list; list = list->next) {
@@ -767,21 +786,21 @@ sp_canvas_group_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
 
         if ( i->x2 > i->x1 && i->y2 > i->y1 ) {
             if (empty) {
-                corners = NR::ConvexHull(NR::Point(i->x1, i->y1));
+                corners = Geom::RectHull(Geom::Point(i->x1, i->y1));
                 empty = false;
             } else {
-                corners.add(NR::Point(i->x1, i->y1));
+                corners.add(Geom::Point(i->x1, i->y1));
             }
-            corners.add(NR::Point(i->x2, i->y2));
+            corners.add(Geom::Point(i->x2, i->y2));
         }
     }
 
-    NR::Maybe<NR::Rect> const bounds = corners.bounds();
+    Geom::OptRect const bounds = corners.bounds();
     if (bounds) {
-        item->x1 = bounds->min()[NR::X];
-        item->y1 = bounds->min()[NR::Y];
-        item->x2 = bounds->max()[NR::X];
-        item->y2 = bounds->max()[NR::Y];
+        item->x1 = bounds->min()[Geom::X];
+        item->y1 = bounds->min()[Geom::Y];
+        item->x2 = bounds->max()[Geom::X];
+        item->y2 = bounds->max()[Geom::Y];
     } else {
         // FIXME ?
         item->x1 = item->x2 = item->y1 = item->y2 = 0;
@@ -792,11 +811,11 @@ sp_canvas_group_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
  * Point handler for canvas groups.
  */
 static double
-sp_canvas_group_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
+sp_canvas_group_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item)
 {
     SPCanvasGroup const *group = SP_CANVAS_GROUP (item);
-    double const x = p[NR::X];
-    double const y = p[NR::Y];
+    double const x = p[Geom::X];
+    double const y = p[Geom::Y];
     int x1 = (int)(x - item->canvas->close_enough);
     int y1 = (int)(y - item->canvas->close_enough);
     int x2 = (int)(x + item->canvas->close_enough);
@@ -928,6 +947,10 @@ static void sp_canvas_dirty_rect(SPCanvas* canvas, int nl, int nt, int nr, int n
 static void sp_canvas_mark_rect(SPCanvas* canvas, int nl, int nt, int nr, int nb, uint8_t val);
 static int do_update (SPCanvas *canvas);
 
+static gboolean sp_canvas_snap_watchdog_callback(gpointer data); 
+static void sp_canvas_snap_watchdog_set(SPCanvas *canvas, GdkEventMotion *event); 
+static void sp_canvas_snap_watchdog_kill(SPCanvas *canvas);
+
 /**
  * Registers the SPCanvas class if necessary, and returns the type ID
  * associated to it.
@@ -1025,6 +1048,8 @@ sp_canvas_init (SPCanvas *canvas)
 
     canvas->is_scrolling = false;
 
+    canvas->watchdog_id = 0;
+    canvas->watchdog_event = NULL;
 }
 
 /**
@@ -1085,6 +1110,14 @@ sp_canvas_destroy (GtkObject *object)
         (* GTK_OBJECT_CLASS (canvas_parent_class)->destroy) (object);
 }
 
+static void track_latency(GdkEvent const *event) {
+    GdkEventLatencyTracker &tracker = GdkEventLatencyTracker::default_tracker();
+    boost::optional<double> latency = tracker.process(event);
+    if (latency && *latency > 2.0) {
+        //g_warning("Event latency reached %f sec (%1.4f)", *latency, tracker.getSkew());
+    }
+}
+
 /**
  * Returns new canvas as widget.
  */
@@ -1118,6 +1151,8 @@ sp_canvas_realize (GtkWidget *widget)
                              GDK_BUTTON_PRESS_MASK |
                              GDK_BUTTON_RELEASE_MASK |
                              GDK_POINTER_MOTION_MASK |
+                             ( HAS_BROKEN_MOTION_HINTS ?
+                               0 : GDK_POINTER_MOTION_HINT_MASK ) |
                              GDK_PROXIMITY_IN_MASK |
                              GDK_PROXIMITY_OUT_MASK |
                              GDK_KEY_PRESS_MASK |
@@ -1130,7 +1165,8 @@ sp_canvas_realize (GtkWidget *widget)
     widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
     gdk_window_set_user_data (widget->window, widget);
 
-    if ( prefs_get_int_attribute ("options.useextinput", "value", 1) )
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if ( prefs->getBool("/options/useextinput/value", true) )
         gtk_widget_set_events(widget, attributes.event_mask);
 
     widget->style = gtk_style_attach (widget->style, widget->window);
@@ -1395,7 +1431,7 @@ pick_current_item (SPCanvas *canvas, GdkEvent *event)
 
         /* find the closest item */
         if (canvas->root->flags & SP_CANVAS_ITEM_VISIBLE) {
-            sp_canvas_item_invoke_point (canvas->root, NR::Point(x, y), &canvas->new_current_item);
+            sp_canvas_item_invoke_point (canvas->root, Geom::Point(x, y), &canvas->new_current_item);
         } else {
             canvas->new_current_item = NULL;
         }
@@ -1461,6 +1497,7 @@ static gint
 sp_canvas_button (GtkWidget *widget, GdkEventButton *event)
 {
     SPCanvas *canvas = SP_CANVAS (widget);
+    SPDesktop *dt = SP_ACTIVE_DESKTOP;
 
     int retval = FALSE;
 
@@ -1495,7 +1532,13 @@ sp_canvas_button (GtkWidget *widget, GdkEventButton *event)
     case GDK_BUTTON_PRESS:
     case GDK_2BUTTON_PRESS:
     case GDK_3BUTTON_PRESS:
-        /* Pick the current item as if the button were not pressed, and
+       if (dt) { 
+                       // Snapping will be on hold if we're moving the mouse at high speeds. When starting
+               // drawing a new shape we really should snap though. 
+               dt->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
+               }
+       
+       /* Pick the current item as if the button were not pressed, and
          * then process the event.
          */
         canvas->state = event->state;
@@ -1505,7 +1548,9 @@ sp_canvas_button (GtkWidget *widget, GdkEventButton *event)
         break;
 
     case GDK_BUTTON_RELEASE:
-        /* Process the event as if the button were pressed, then repick
+       sp_canvas_snap_watchdog_callback(canvas); // If we have any pending snapping action, then invoke it now 
+        
+       /* Process the event as if the button were pressed, then repick
          * after the button has been released
          */
         canvas->state = event->state;
@@ -1514,6 +1559,7 @@ sp_canvas_button (GtkWidget *widget, GdkEventButton *event)
         canvas->state = event->state;
         pick_current_item (canvas, (GdkEvent *) event);
         event->state ^= mask;
+        
         break;
 
     default:
@@ -1534,33 +1580,143 @@ sp_canvas_scroll (GtkWidget *widget, GdkEventScroll *event)
     return emit_event (SP_CANVAS (widget), (GdkEvent *) event);
 }
 
+static inline void request_motions(GdkWindow *w, GdkEventMotion *event) {
+    gdk_window_get_pointer(w, NULL, NULL, NULL);
+#if HAS_GDK_EVENT_REQUEST_MOTIONS
+    gdk_event_request_motions(event);
+#endif
+}
+
 /**
  * Motion event handler for the canvas.
  */
 static int
 sp_canvas_motion (GtkWidget *widget, GdkEventMotion *event)
 {
+       static guint32 prev_time;
+       static boost::optional<Geom::Point> prev_pos;
+       
+       int status;
     SPCanvas *canvas = SP_CANVAS (widget);
 
+    track_latency((GdkEvent *)event);
+
     if (event->window != SP_CANVAS_WINDOW (canvas))
         return FALSE;
 
     if (canvas->pixmap_gc == NULL) // canvas being deleted
         return FALSE;
+    
+    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    
+    // Snap when speed drops below e.g. 0.02 px/msec, or when no motion events have occured for some period.
+       // i.e. snap when we're at stand still. A speed threshold enforces snapping for tablets, which might never
+       // be fully at stand still and might keep spitting out motion events.
+    if (dt) {
+           bool const c1 = event->type == GDK_MOTION_NOTIFY;
+           bool const c21 = event->state & GDK_BUTTON1_MASK; // Snapping only occurs when dragging with the left mouse button down
+           bool const c22 = event->state & GDK_BUTTON2_MASK; // We shouldn't hold back any events when other mouse buttons have been
+           bool const c23 = event->state & GDK_BUTTON3_MASK; // pressed, e.g. when scrolling with the middle mouse button; if we do then
+                                                                                                         // Inkscape will get stuck in an unresponsive state
+           bool const c3 = dt->namedview->snap_manager.snapprefs.getSnapEnabledGlobally();
+           if (c1 && c21 && (!c22) && (!c23) && c3) {          
+               Geom::Point event_pos(event->x, event->y);
+               guint32 event_t = gdk_event_get_time ( (GdkEvent *) event );
+                       
+               dt->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(true); // put snapping on hold
+                       
+               if (prev_pos) {
+                       Geom::Coord dist = Geom::L2(event_pos - *prev_pos);
+                       guint32 delta_t = event_t - prev_time;
+                       gdouble speed = delta_t > 0 ? dist/delta_t : 1000;
+                       // std::cout << "speed = " << speed << " px/msec " << "| time passed = " << delta_t << " msec" << std::endl;
+                       if (speed > 0.02) { // Jitter threshold, might be needed for tablets 
+                                       // We're moving fast, so postpone any snapping until the next GDK_MOTION_NOTIFY event. We
+                               // will keep on postponing the snapping as long as the speed is high.
+                                       // We must snap at some point in time though, so set a watchdog timer at some time from
+                                       // now, just in case there's no future motion event that drops under the speed limit (when 
+                               // stoppping abruptly)
+                               sp_canvas_snap_watchdog_kill(canvas);
+                               sp_canvas_snap_watchdog_set(canvas, event); // watchdog is reset, i.e. pushed forward in time
+                               // If the watchdog expires before a new motion event is received, we will snap (as explained
+                               // above). This means however that when the timer is too short, we will always snap and that the
+                               // speed threshold is ineffective. In the extreme case the delay is set to zero, and snapping will
+                               // be immediate, as it used to be in the old days ;-). 
+                               } else { // Speed is very low, so we're virtually at stand still
+                                       // But if we're really standing still, then we should snap now. We could use some low-pass filtering, 
+                                       // otherwise snapping occurs for each jitter movement. For this filtering we'll leave the watchdog to expire,
+                                       // snap, and set a new watchdog again. 
+                                       if (canvas->watchdog_id == 0) { // no watchdog has been set 
+                                               // it might have already expired, so we'll set a new one; the snapping frequency will be limited by this
+                                               sp_canvas_snap_watchdog_set(canvas, event);
+                                       } // else: watchdog has been set before and we'll wait for it to expire
+                               }
+                       } else {
+                               // This is the first GDK_MOTION_NOTIFY event, so postpone snapping and set the watchdog
+                               sp_canvas_snap_watchdog_set(canvas, event);
+                       }
+                               
+               prev_pos = event_pos;
+               prev_time = event_t;
+           }
+       }
+    
+    canvas->state = event->state;
+    pick_current_item (canvas, (GdkEvent *) event);
+
+    status = emit_event (canvas, (GdkEvent *) event);
 
-    if (canvas->grabbed_event_mask & GDK_POINTER_MOTION_HINT_MASK) {
-        gint x, y;
-        gdk_window_get_pointer (widget->window, &x, &y, NULL);
-        event->x = x;
-        event->y = y;
+    if (event->is_hint) {
+        request_motions(widget->window, event);
     }
 
-    canvas->state = event->state;
-    pick_current_item (canvas, (GdkEvent *) event);
+    return status;
+}
 
-    return emit_event (canvas, (GdkEvent *) event);
+gboolean sp_canvas_snap_watchdog_callback(gpointer data) 
+{
+       // Snap NOW! For this the "postponed" flag will be reset and an the last motion event will be repeated  
+       SPCanvas *canvas = reinterpret_cast<SPCanvas *>(data);
+       if (!canvas->watchdog_event) {
+               return FALSE;
+       }       
+       
+       SPDesktop *dt = SP_ACTIVE_DESKTOP;
+       if (dt) {
+               dt->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
+       }
+       
+       emit_event(canvas, canvas->watchdog_event);
+       gdk_event_free(canvas->watchdog_event);
+       canvas->watchdog_event = NULL;
+       canvas->watchdog_id = 0;
+    
+       return FALSE;
+}
+
+void sp_canvas_snap_watchdog_set(SPCanvas *canvas, GdkEventMotion *event) 
+{
+       Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+       double value = prefs->getDoubleLimited("/options/snapdelay/value", 0, 0, 1000);
+       g_assert(canvas->watchdog_id == 0);
+       canvas->watchdog_id = g_timeout_add(value, &sp_canvas_snap_watchdog_callback, canvas);
+       g_assert(canvas->watchdog_event == NULL);
+       canvas->watchdog_event = gdk_event_copy( (GdkEvent *) event); 
 }
 
+void sp_canvas_snap_watchdog_kill(SPCanvas *canvas) 
+{
+       if (canvas->watchdog_id) { 
+        g_source_remove(canvas->watchdog_id); // Kill the watchdog
+        canvas->watchdog_id = 0;
+    }
+       
+       if (canvas->watchdog_event) {
+               gdk_event_free(canvas->watchdog_event);
+               canvas->watchdog_event = NULL;
+       }
+}
+       
 static void
 sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1, int draw_x1, int draw_y1, int draw_x2, int draw_y2, int sw)
 {
@@ -1599,7 +1755,8 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
 
 #if ENABLE_LCMS
     cmsHTRANSFORM transf = 0;
-    long long int fromDisplay = prefs_get_int_attribute_limited( "options.displayprofile", "from_display", 0, 0, 1 );
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    bool fromDisplay = prefs->getBool( "/options/displayprofile/from_display");
     if ( fromDisplay ) {
         transf = Inkscape::colorprofile_get_display_per( canvas->cms_key ? *(canvas->cms_key) : "" );
     } else {
@@ -1624,7 +1781,7 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
 #if ENABLE_LCMS
         if ( transf && canvas->enable_cms_display_adj ) {
             for ( gint yy = 0; yy < (y1 - y0); yy++ ) {
-                guchar* p = buf.buf + (sw * 3) * yy;
+                guchar* p = buf.buf + (buf.buf_rowstride * yy);
                 cmsDoTransform( transf, p, p, (x1 - x0) );
             }
         }
@@ -1673,7 +1830,7 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
                                       x0 - canvas->x0, y0 - canvas->y0,
                                       x1 - x0, y1 - y0,
                                       GDK_RGB_DITHER_MAX,
-                                      b3.data.px,
+                                      NR_PIXBLOCK_PX(&b3),
                                       sw * 3,
                                       x0 - canvas->x0, y0 - canvas->y0);
 
@@ -1699,7 +1856,7 @@ struct PaintRectSetup {
     NRRectL big_rect;
     GTimeVal start_time;
     int max_pixels;
-    NR::Point mouse_loc;
+    Geom::Point mouse_loc;
 };
 
 /**
@@ -1786,7 +1943,7 @@ The default for now is the strips mode.
         lo.x1 = mid;
         hi.x0 = mid;
 
-        if (setup->mouse_loc[NR::X] < mid) {
+        if (setup->mouse_loc[Geom::X] < mid) {
             // Always paint towards the mouse first
             return sp_canvas_paint_rect_internal(setup, lo)
                 && sp_canvas_paint_rect_internal(setup, hi);
@@ -1803,7 +1960,7 @@ The default for now is the strips mode.
         lo.y1 = mid;
         hi.y0 = mid;
 
-        if (setup->mouse_loc[NR::Y] < mid) {
+        if (setup->mouse_loc[Geom::Y] < mid) {
             // Always paint towards the mouse first
             return sp_canvas_paint_rect_internal(setup, lo)
                 && sp_canvas_paint_rect_internal(setup, hi);
@@ -1855,7 +2012,7 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1)
     // Save the mouse location
     gint x, y;
     gdk_window_get_pointer (GTK_WIDGET(canvas)->window, &x, &y, NULL);
-    setup.mouse_loc = sp_canvas_window_to_world (canvas, NR::Point(x,y));
+    setup.mouse_loc = sp_canvas_window_to_world (canvas, Geom::Point(x,y));
 
     if (canvas->rendermode != Inkscape::RENDERMODE_OUTLINE) {
         // use 256K as a compromise to not slow down gradients
@@ -1994,7 +2151,7 @@ static int
 paint (SPCanvas *canvas)
 {
     if (canvas->need_update) {
-        sp_canvas_item_invoke_update (canvas->root, NR::identity(), 0);
+        sp_canvas_item_invoke_update (canvas->root, Geom::identity(), 0);
         canvas->need_update = FALSE;
     }
 
@@ -2051,7 +2208,7 @@ do_update (SPCanvas *canvas)
 
     /* Cause the update if necessary */
     if (canvas->need_update) {
-        sp_canvas_item_invoke_update (canvas->root, NR::identity(), 0);
+        sp_canvas_item_invoke_update (canvas->root, Geom::identity(), 0);
         canvas->need_update = FALSE;
     }
 
@@ -2234,50 +2391,48 @@ void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double wor
 /**
  * Converts point from win to world coordinates.
  */
-NR::Point sp_canvas_window_to_world(SPCanvas const *canvas, NR::Point const win)
+Geom::Point sp_canvas_window_to_world(SPCanvas const *canvas, Geom::Point const win)
 {
     g_assert (canvas != NULL);
     g_assert (SP_IS_CANVAS (canvas));
 
-    return NR::Point(canvas->x0 + win[0], canvas->y0 + win[1]);
+    return Geom::Point(canvas->x0 + win[0], canvas->y0 + win[1]);
 }
 
 /**
  * Converts point from world to win coordinates.
  */
-NR::Point sp_canvas_world_to_window(SPCanvas const *canvas, NR::Point const world)
+Geom::Point sp_canvas_world_to_window(SPCanvas const *canvas, Geom::Point const world)
 {
     g_assert (canvas != NULL);
     g_assert (SP_IS_CANVAS (canvas));
 
-    return NR::Point(world[0] - canvas->x0, world[1] - canvas->y0);
+    return Geom::Point(world[0] - canvas->x0, world[1] - canvas->y0);
 }
 
 /**
  * Returns true if point given in world coordinates is inside window.
  */
-bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, NR::Point const &world)
+bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, Geom::Point const &world)
 {
     g_assert( canvas != NULL );
     g_assert(SP_IS_CANVAS(canvas));
 
-    using NR::X;
-    using NR::Y;
     GtkWidget const &w = *GTK_WIDGET(canvas);
-    return ( ( canvas->x0 <= world[X] )  &&
-             ( canvas->y0 <= world[Y] )  &&
-             ( world[X] < canvas->x0 + w.allocation.width )  &&
-             ( world[Y] < canvas->y0 + w.allocation.height ) );
+    return ( ( canvas->x0 <= world[Geom::X] )  &&
+             ( canvas->y0 <= world[Geom::Y] )  &&
+             ( world[Geom::X] < canvas->x0 + w.allocation.width )  &&
+             ( world[Geom::Y] < canvas->y0 + w.allocation.height ) );
 }
 
 /**
- * Return canvas window coordinates as NR::Rect.
+ * Return canvas window coordinates as Geom::Rect.
  */
-NR::Rect SPCanvas::getViewbox() const
+Geom::Rect SPCanvas::getViewbox() const
 {
     GtkWidget const *w = GTK_WIDGET(this);
-    return NR::Rect(NR::Point(dx0, dy0),
-                    NR::Point(dx0 + w->allocation.width, dy0 + w->allocation.height));
+    return Geom::Rect(Geom::Point(dx0, dy0),
+                      Geom::Point(dx0 + w->allocation.width, dy0 + w->allocation.height));
 }
 
 /**