From 6a483b13142fef24dc6bc364142b07879eaf9139 Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Sat, 18 Jul 2009 12:56:25 +0000 Subject: [PATCH] Make the snap delay mechanism easier to implement for the devs, and get rid of the related warning messages --- src/arc-context.cpp | 7 ++-- src/box3d-context.cpp | 5 +-- src/connector-context.cpp | 21 +++++----- src/desktop-events.cpp | 33 ++++----------- src/event-context.cpp | 85 +++++++++------------------------------ src/event-context.h | 4 +- src/gradient-context.cpp | 1 - src/knot.cpp | 21 ++-------- src/knotholder.cpp | 2 - src/node-context.cpp | 2 - src/nodepath.cpp | 2 - src/pen-context.cpp | 4 +- src/pencil-context.cpp | 12 ++---- src/rect-context.cpp | 7 ++-- src/select-context.cpp | 12 ++---- src/seltrans.cpp | 4 -- src/snap.cpp | 26 +----------- src/spiral-context.cpp | 7 ++-- src/star-context.cpp | 7 ++-- src/text-context.cpp | 5 +-- 20 files changed, 66 insertions(+), 201 deletions(-) diff --git a/src/arc-context.cpp b/src/arc-context.cpp index d47e22b1a..dcb326bcd 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -223,7 +223,6 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent if (event->button.button == 1 && !event_context->space_panning) { dragging = true; - sp_event_context_snap_window_open(event_context); ac->center = Inkscape::setup_for_drag_start(desktop, event_context, event); /* Snap center */ @@ -267,7 +266,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent event_context->xp = event_context->yp = 0; if (event->button.button == 1 && !event_context->space_panning) { dragging = false; - sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the arc sp_arc_finish(ac); @@ -324,7 +323,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent case GDK_Escape: if (dragging) { dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); // if drawing, cancel, otherwise pass it up for deselecting sp_arc_cancel(ac); ret = TRUE; @@ -335,7 +334,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the arc sp_arc_finish(ac); diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index d1b6d62fc..fd72e406b 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -276,7 +276,6 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, event->button.state & GDK_CONTROL_MASK); dragging = true; - sp_event_context_snap_window_open(event_context); /* */ Geom::Point button_dt(desktop->w2d(button_w)); @@ -373,7 +372,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven event_context->xp = event_context->yp = 0; if ( event->button.button == 1 && !event_context->space_panning) { dragging = false; - sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the box @@ -508,7 +507,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the box sp_box3d_finish(bc); diff --git a/src/connector-context.cpp b/src/connector-context.cpp index c8754972a..2131bdced 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -409,7 +409,7 @@ sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, G { spcc_reset_colors(cc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); } if (cc->state != SP_CONNECTOR_CONTEXT_IDLE) { // Doing simething else like rerouting. @@ -532,8 +532,6 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const // Test whether we clicked on a connection point cc->sid = conn_pt_handle_test(cc, p); - sp_event_context_snap_window_open(event_context); - if (!cc->sid) { // This is the first point, so just snap it to the grid // as there's no other points to go off. @@ -560,7 +558,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const } cc_set_active_conn(cc, cc->newconn); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); ret = TRUE; break; } @@ -579,7 +577,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const cc_connector_rerouting_finish(cc, &p); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); // Don't set ret to TRUE, so we drop through to the // parent handler which will open the context menu. @@ -587,7 +585,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const else if (cc->npoints != 0) { spcc_connector_finish(cc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); ret = TRUE; } } @@ -719,7 +717,7 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con } cc_set_active_conn(cc, cc->newconn); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); break; } case SP_CONNECTOR_CONTEXT_REROUTING: @@ -729,7 +727,7 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con sp_document_ensure_up_to_date(doc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); return TRUE; break; } @@ -757,7 +755,7 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval) if (cc->npoints != 0) { spcc_connector_finish(cc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(SP_EVENT_CONTEXT(cc)); + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(cc)); ret = TRUE; } break; @@ -772,7 +770,7 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval) sp_document_undo(doc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - sp_event_context_snap_window_closed(SP_EVENT_CONTEXT(cc)); + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(cc)); desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, _("Connector endpoint drag cancelled.")); ret = TRUE; @@ -780,7 +778,7 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval) else if (cc->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting cc->state = SP_CONNECTOR_CONTEXT_STOP; - sp_event_context_snap_window_closed(SP_EVENT_CONTEXT(cc)); + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(cc)); spcc_reset_colors(cc); ret = TRUE; } @@ -1089,7 +1087,6 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc) cc->clickedhandle = cc->active_handle; cc_clear_active_conn(cc); cc->state = SP_CONNECTOR_CONTEXT_REROUTING; - sp_event_context_snap_window_open(SP_EVENT_CONTEXT(cc)); // Disconnect from attached shape unsigned ind = (cc->active_handle == cc->endpt_handle[0]) ? 0 : 1; diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index d8fb9d8d5..1fae9367c 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -71,7 +71,6 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge static bool dragging = false; static SPCanvasItem *guide = NULL; static Geom::Point normal; - static bool snap_window_temporarily_open = false; int wx, wy; SPDesktop *desktop = dtw->desktop; @@ -88,21 +87,8 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge if (event->button.button == 1) { dragging = true; - // FIXME: The snap delay mechanism won't work here, because it has been implemented - // for the event context. Dragging guides off the ruler will send event to the ruler - // and not to the context, which bypasses sp_event_context_snap_delay_handler - // The snap manager will not notice the difference, so it'll check if the snap delay - // has been activated (This check is only needed for catching coding errors, i.e. - // to warn if the snap window has not been implemented properly in some context) - if (desktop->event_context->_snap_window_open == false) { - // A dt_ruler_event might be emitted when dragging a guide off the rulers - // while drawing a Bezier curve. In such a situation, we're already in that - // specific context and the snap delay is already active. We should not set - // the snap delay to active again, because that will trigger a similar warning - // to the one above - sp_event_context_snap_window_open(desktop->event_context); - snap_window_temporarily_open = true; - } + // FIXME: The snap delay mechanism won't work here, because it has been implemented for the event context. Dragging + // guides off the ruler will send event to the ruler and not to the context, which bypasses sp_event_context_snap_delay_handler Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win)); Geom::Point const event_dt(desktop->w2d(event_w)); @@ -186,11 +172,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge dragging = false; - // See the comments in GDK_BUTTON_PRESS - if (snap_window_temporarily_open) { - sp_event_context_snap_window_closed(desktop->event_context); - snap_window_temporarily_open = false; - } + sp_event_context_discard_delayed_snap_event(desktop->event_context); gtk_object_destroy(GTK_OBJECT(guide)); guide = NULL; @@ -209,7 +191,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge // A dt_ruler_event might be emitted when dragging a guide of the rulers // while drawing a Bezier curve. In such a situation, we're already in that // specific context and the snap delay is already active. We should interfere - // with that context and we should therefore leave the snap delay status + // with that context and we should therefore leave the snap delay status // as it is. So although it might have been set to active above on // GDK_BUTTON_PRESS, we should not set it back to inactive here. That must be // done by the context. @@ -246,7 +228,7 @@ static SPGuideDragType drag_type = SP_DRAG_NONE; // // drag origin to that location so that constrained movement is more intuitive // Min distance from anchor to initiate rotation, measured in screenpixels -#define tol 40.0 +#define tol 40.0 gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) { @@ -260,7 +242,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) case GDK_2BUTTON_PRESS: if (event->button.button == 1) { drag_type = SP_DRAG_NONE; - sp_event_context_snap_window_closed(desktop->event_context); + sp_event_context_discard_delayed_snap_event(desktop->event_context); sp_canvas_item_ungrab(item, event->button.time); Inkscape::UI::Dialogs::GuidelinePropertiesDialog::showDialog(guide, desktop); ret = TRUE; @@ -268,7 +250,6 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) break; case GDK_BUTTON_PRESS: if (event->button.button == 1) { - sp_event_context_snap_window_open(desktop->event_context); Geom::Point const event_w(event->button.x, event->button.y); Geom::Point const event_dt(desktop->w2d(event_w)); @@ -442,7 +423,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) desktop->setPosition (from_2geom(event_dt)); } drag_type = SP_DRAG_NONE; - sp_event_context_snap_window_closed(desktop->event_context); + sp_event_context_discard_delayed_snap_event(desktop->event_context); sp_canvas_item_ungrab(item, event->button.time); ret=TRUE; } diff --git a/src/event-context.cpp b/src/event-context.cpp index b1cfac518..753d0679a 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -374,7 +374,9 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context, switch (event->button.button) { case 1: if (event_context->space_panning) { - panning = 1; + // When starting panning, make sure there are no snap events pending because these might disable the panning again + sp_event_context_discard_delayed_snap_event(event_context); + panning = 1; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time-1); @@ -385,7 +387,9 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context, if (event->button.state == GDK_SHIFT_MASK) { zoom_rb = 2; } else { - panning = 2; + // When starting panning, make sure there are no snap events pending because these might disable the panning again + sp_event_context_discard_delayed_snap_event(event_context); + panning = 2; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time-1); @@ -395,7 +399,9 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context, case 3: if (event->button.state & GDK_SHIFT_MASK || event->button.state & GDK_CONTROL_MASK) { - panning = 3; + // When starting panning, make sure there are no snap events pending because these might disable the panning again + sp_event_context_discard_delayed_snap_event(event_context); + panning = 3; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time); @@ -415,7 +421,7 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context, || (panning == 3 && !(event->motion.state & GDK_BUTTON3_MASK)) ) { /* Gdk seems to lose button release for us sometimes :-( */ - panning = 0; + panning = 0; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); ret = TRUE; @@ -874,9 +880,8 @@ sp_event_context_activate(SPEventContext *ec) // Make sure no delayed snapping events are carried over after switching contexts // (this is only an additional safety measure against sloppy coding, because each - // context should take care of this by itself. It might be hard to get each and every - // context perfect though) - sp_event_context_snap_window_closed(ec, false); + // context should take care of this by itself. + sp_event_context_discard_delayed_snap_event(ec); if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->activate) ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->activate(ec); @@ -901,8 +906,7 @@ sp_event_context_deactivate(SPEventContext *ec) gint sp_event_context_root_handler(SPEventContext * event_context, GdkEvent * event) { - //std::cout << "sp_event_context_root_handler" << std::endl; - switch (event->type) { + switch (event->type) { case GDK_MOTION_NOTIFY: sp_event_context_snap_delay_handler(event_context, NULL, NULL, (GdkEventMotion *)event, DelayedSnapEvent::EVENTCONTEXT_ROOT_HANDLER); break; @@ -929,8 +933,6 @@ sp_event_context_root_handler(SPEventContext * event_context, GdkEvent * event) gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEvent * event) { - //std::cout << "sp_event_context_virtual_root_handler -> postponed: " << event_context->desktop->namedview->snap_manager.snapprefs.getSnapPostponedGlobally() << std::endl; - gint ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->root_handler(event_context, event); set_event_location(event_context->desktop, event); return ret; @@ -942,7 +944,6 @@ sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEvent * gint sp_event_context_item_handler(SPEventContext * event_context, SPItem * item, GdkEvent * event) { - //std::cout << "sp_event_context_item_handler" << std::endl; switch (event->type) { case GDK_MOTION_NOTIFY: sp_event_context_snap_delay_handler(event_context, item, NULL, (GdkEventMotion *)event, DelayedSnapEvent::EVENTCONTEXT_ITEM_HANDLER); @@ -1185,17 +1186,14 @@ void sp_event_context_snap_delay_handler(SPEventContext *ec, SPItem* const item, // Make sure that we don't send any pending snap events to a context if we know in advance // that we're not going to snap any way (e.g. while scrolling with middle mouse button) // Any motion event might affect the state of the context, leading to unexpected behavior - delete ec->_delayed_snap_event; - ec->_delayed_snap_event = NULL; - } - - if (ec->_snap_window_open && !c1 && !c2 && ec->desktop && ec->desktop->namedview->snap_manager.snapprefs.getSnapEnabledGlobally()) { - // Snap when speed drops below e.g. 0.02 px/msec, or when no motion events have occurred for some period. + sp_event_context_discard_delayed_snap_event(ec); + } else if (ec->desktop && ec->desktop->namedview->snap_manager.snapprefs.getSnapEnabledGlobally()) { + // Snap when speed drops below e.g. 0.02 px/msec, or when no motion events have occurred 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. - ec->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(true); // put snapping on hold + ec->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(true); // put snapping on hold - Geom::Point event_pos(event->x, event->y); + Geom::Point event_pos(event->x, event->y); guint32 event_t = gdk_event_get_time ( (GdkEvent *) event ); if (prev_pos) { @@ -1232,7 +1230,7 @@ void sp_event_context_snap_delay_handler(SPEventContext *ec, SPItem* const item, prev_pos = event_pos; prev_time = event_t; - } + } } gboolean sp_event_context_snap_watchdog_callback(gpointer data) @@ -1286,51 +1284,8 @@ gboolean sp_event_context_snap_watchdog_callback(gpointer data) return FALSE; //Kills the timer and stops it from executing this callback over and over again. } -void sp_event_context_snap_window_open(SPEventContext *ec, bool show_debug_warnings) +void sp_event_context_discard_delayed_snap_event(SPEventContext *ec) { - // Only when ec->_snap_window_open has been set, Inkscape will know that snapping is active - // and will delay any snapping events (but only when asked to through the preferences) - - // When snapping is being delayed, then that will also mean that at some point the last event - // might be re-triggered. This should only occur when Inkscape is still in the same tool or context, - // and even more specifically, the tool should even be in the same state. If for example snapping is being delayed while - // creating a rectangle, then the rect-context will be active and it will be in the "dragging" state - // (see the static boolean variable "dragging" in the sp_rect_context_root_handler). The procedure is - // as follows: call sp_event_context_snap_window_open(*, TRUE) when entering the "dragging" state, which will delay - // snapping from that moment on, and call sp_event_context_snap_window_open(*, FALSE) when leaving the "dragging" - // state. This last call will also make sure that any pending snap events will be canceled. - - //std::cout << "sp_event_context_snap_window_open" << std::endl; - if (!ec) { - if (show_debug_warnings) { - g_warning("sp_event_context_snap_window_open() has been called without providing an event context!"); - } - return; - } - - if (ec->_snap_window_open == true && show_debug_warnings) { - g_warning("Snap window was already open! This is a bug, please report it."); - } - - ec->_snap_window_open = true; -} - -void sp_event_context_snap_window_closed(SPEventContext *ec, bool show_debug_warnings) -{ - //std::cout << "sp_event_context_snap_window_closed" << std::endl; - if (!ec) { - if (show_debug_warnings) { - g_warning("sp_event_context_snap_window_closed() has been called without providing an event context!"); - } - return; - } - - if (ec->_snap_window_open == false && show_debug_warnings) { - g_warning("Snap window was already closed! This is a bug, please report it."); - } - - ec->_snap_window_open = false; - delete ec->_delayed_snap_event; ec->_delayed_snap_event = NULL; } diff --git a/src/event-context.h b/src/event-context.h index 638ac56f7..5285bdb87 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -40,8 +40,7 @@ namespace Inkscape { } gboolean sp_event_context_snap_watchdog_callback(gpointer data); -void sp_event_context_snap_window_open(SPEventContext *ec, bool show_debug_warnings = true); -void sp_event_context_snap_window_closed(SPEventContext *ec, bool show_debug_warnings = true); +void sp_event_context_discard_delayed_snap_event(SPEventContext *ec); class DelayedSnapEvent { @@ -123,7 +122,6 @@ struct SPEventContext : public GObject { bool space_panning; - bool _snap_window_open; DelayedSnapEvent *_delayed_snap_event; }; diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index b4eeda290..fc5c1af44 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -556,7 +556,6 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) if (!(event->button.state & GDK_CONTROL_MASK)) event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE); - sp_event_context_snap_window_open(event_context, false); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, button_dt, Inkscape::SNAPSOURCE_HANDLE); diff --git a/src/knot.cpp b/src/knot.cpp index 1ac5d887b..b17e41b24 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -284,8 +284,6 @@ void sp_knot_start_dragging(SPKnot *knot, Geom::Point const &p, gint x, gint y, */ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot) { - static bool snap_delay_temporarily_active = false; - g_assert(knot != NULL); g_assert(SP_IS_KNOT(knot)); @@ -317,11 +315,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot if (event->button.button == 1 && !knot->desktop->event_context->space_panning) { Geom::Point const p = knot->desktop->w2d(Geom::Point(event->button.x, event->button.y)); sp_knot_start_dragging(knot, p, (gint) event->button.x, (gint) event->button.y, event->button.time); - if (knot->desktop->event_context->_snap_window_open == false) { - sp_event_context_snap_window_open(knot->desktop->event_context); - snap_delay_temporarily_active = true; - } - consumed = TRUE; + consumed = TRUE; } break; case GDK_BUTTON_RELEASE: @@ -331,13 +325,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot sp_event_context_snap_watchdog_callback(knot->desktop->event_context->_delayed_snap_event); } - // now we can safely close the snapping window - if (snap_delay_temporarily_active) { - if (knot->desktop->event_context->_snap_window_open == true) { - sp_event_context_snap_window_closed(knot->desktop->event_context); - } - snap_delay_temporarily_active = false; - } + sp_event_context_discard_delayed_snap_event(knot->desktop->event_context); knot->pressure = 0; if (transform_escaped) { @@ -446,10 +434,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot } grabbed = FALSE; moved = FALSE; - if (snap_delay_temporarily_active) { - sp_event_context_snap_window_closed(knot->desktop->event_context); - snap_delay_temporarily_active = false; - } + sp_event_context_discard_delayed_snap_event(knot->desktop->event_context); break; default: consumed = FALSE; diff --git a/src/knotholder.cpp b/src/knotholder.cpp index 773b9249c..55a171414 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -139,7 +139,6 @@ KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state) { if (this->dragging == false) { this->dragging = true; - //sp_event_context_snap_window_open(desktop->canvas); } // this was a local change and the knotholder does not need to be recreated: @@ -165,7 +164,6 @@ void KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/) { this->dragging = false; - //sp_event_context_snap_window_closed(desktop->canvas); if (this->released) { this->released(this->item); diff --git a/src/node-context.cpp b/src/node-context.cpp index 6ad7b85d4..a0fb78ba1 100644 --- a/src/node-context.cpp +++ b/src/node-context.cpp @@ -300,8 +300,6 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event) nc->remove_flash_counter--; } - sp_event_context_snap_window_open(event_context, false); // Just put the snap window open, bluntly. Will be closed when we have left the context - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 8a47b658b..f9a615583 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -3590,7 +3590,6 @@ static void node_grabbed(SPKnot *knot, guint state, gpointer data) } n->is_dragging = true; - //sp_event_context_snap_window_open(n->subpath->nodepath->desktop->canvas); // Reconstruct and store the location of the mouse pointer at the time when we started dragging (needed for snapping) n->subpath->nodepath->drag_origin_mouse = knot->grabbed_rel_pos + knot->drag_origin; @@ -3608,7 +3607,6 @@ static void node_ungrabbed(SPKnot */*knot*/, guint /*state*/, gpointer data) n->dragging_out = NULL; n->is_dragging = false; - //sp_event_context_snap_window_closed(n->subpath->nodepath->desktop->canvas); n->subpath->nodepath->drag_origin_mouse = Geom::Point(NR_HUGE, NR_HUGE); sp_canvas_end_forced_full_redraws(n->subpath->nodepath->desktop->canvas); diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 261c7d4cf..4c9627071 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -263,7 +263,7 @@ sp_pen_context_finish(SPEventContext *ec) { SPPenContext *pc = SP_PEN_CONTEXT(ec); - sp_event_context_snap_window_closed(ec, false); //TODO: Detailed implementation of the snap window; now it's simply always open + sp_event_context_discard_delayed_snap_event(ec); if (pc->npoints != 0) { pen_cancel (pc); @@ -367,8 +367,6 @@ sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) { SPPenContext *const pc = SP_PEN_CONTEXT(ec); - sp_event_context_snap_window_open(ec, false); //TODO: Detailed implementation of the snap window; now it's simply always open - gint ret = FALSE; switch (event->type) { diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 4b87e86b5..31b7441d4 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -255,7 +255,6 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve /* Set first point of sequence */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - sp_event_context_snap_window_open(event_context); if (anchor) { p = anchor->dp; @@ -349,7 +348,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev /* We may be idle or already freehand */ if ( mevent.state & GDK_BUTTON1_MASK && pc->is_drawing ) { if (pc->state == SP_PENCIL_CONTEXT_IDLE) { - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); } pc->state = SP_PENCIL_CONTEXT_FREEHAND; @@ -417,7 +416,6 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re /* Releasing button in idle mode means single click */ /* We have already set up start point/anchor in button_press */ pc->state = SP_PENCIL_CONTEXT_ADDLINE; - //sp_event_context_snap_window_open(dt->canvas); ret = TRUE; break; case SP_PENCIL_CONTEXT_ADDLINE: @@ -431,7 +429,7 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re spdc_set_endpoint(pc, p); spdc_finish_endpoint(pc); pc->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); ret = TRUE; break; case SP_PENCIL_CONTEXT_FREEHAND: @@ -445,7 +443,6 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re } pc->state = SP_PENCIL_CONTEXT_SKETCH; - //sp_event_context_snap_window_open(dt->canvas); } else { /* Finish segment now */ /// \todo fixme: Clean up what follows (Lauris) @@ -465,7 +462,6 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); } pc->state = SP_PENCIL_CONTEXT_IDLE; - // sp_event_context_snap_window_closed(dt->canvas); // reset sketch mode too pc->sketch_n = 0; } @@ -498,7 +494,7 @@ pencil_cancel (SPPencilContext *const pc) pc->is_drawing = false; pc->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_snap_window_closed(SP_EVENT_CONTEXT(pc)); + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(pc)); pc->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); @@ -589,7 +585,7 @@ pencil_handle_key_release(SPPencilContext *const pc, guint const keyval, guint c pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); } pc->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_snap_window_closed(SP_EVENT_CONTEXT(pc)); + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(pc)); pc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand sketch")); ret = TRUE; } diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 51b5f2e85..ef5881378 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -258,7 +258,6 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE); dragging = true; - sp_event_context_snap_window_open(event_context); /* Position center */ Geom::Point button_dt(desktop->w2d(button_w)); @@ -307,7 +306,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent event_context->xp = event_context->yp = 0; if (event->button.button == 1 && !event_context->space_panning) { dragging = false; - sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the rect @@ -375,7 +374,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent case GDK_Escape: if (dragging) { dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); // if drawing, cancel, otherwise pass it up for deselecting sp_rect_cancel(rc); ret = TRUE; @@ -387,7 +386,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the rect sp_rect_finish(rc); diff --git a/src/select-context.cpp b/src/select-context.cpp index aed594fee..a5f5202ae 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -212,7 +212,7 @@ sp_select_context_abort(SPEventContext *event_context) seltrans->ungrab(); sc->moved = FALSE; sc->dragging = FALSE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); drag_escaped = 1; if (sc->item) { @@ -324,7 +324,6 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE // pass the event to root handler which will perform rubberband, shift-click, ctrl-click, ctrl-drag } else { sc->dragging = TRUE; - sp_event_context_snap_window_open(event_context); sc->moved = FALSE; sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5); @@ -424,7 +423,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) desktop->setCurrentLayer(reinterpret_cast(clicked_item)); sp_desktop_selection(desktop)->clear(); sc->dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); sp_canvas_end_forced_full_redraws(desktop->canvas); } else { // switch tool @@ -495,9 +494,6 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) if (sc->button_press_ctrl || (sc->button_press_alt && !sc->button_press_shift && !selection->isEmpty())) { // if it's not click and ctrl or alt was pressed (the latter with some selection // but not with shift) we want to drag rather than rubberband - if (sc->dragging == FALSE) { - sp_event_context_snap_window_open(event_context); - } sc->dragging = TRUE; sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5); @@ -549,7 +545,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) ret = TRUE; } else { sc->dragging = FALSE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); sp_canvas_end_forced_full_redraws(desktop->canvas); } } else { @@ -598,7 +594,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) } } sc->dragging = FALSE; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); sp_canvas_end_forced_full_redraws(desktop->canvas); if (sc->item) { diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 3bd5f611a..c3c841149 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -376,8 +376,6 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } } - //sp_event_context_snap_window_open(_desktop->event_context); - if ((x != -1) && (y != -1)) { sp_canvas_item_show(_norm); sp_canvas_item_show(_grip); @@ -430,8 +428,6 @@ void Inkscape::SelTrans::ungrab() _grabbed = false; _show_handles = true; - //sp_event_context_snap_window_closed(_desktop->event_context); - _desktop->snapindicator->remove_snapsource(); Inkscape::Selection *selection = sp_desktop_selection(_desktop); diff --git a/src/snap.cpp b/src/snap.cpp index 91d5d64ec..4d5dad55a 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -206,13 +206,6 @@ Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::SnapPreferences::PointTyp bool first_point, Geom::OptRect const &bbox_to_snap) const { - if (_desktop->event_context && _desktop->event_context->_snap_window_open == false) { - g_warning("The current tool tries to snap, but it hasn't yet opened the snap window. Please report this!"); - // When the context goes into dragging-mode, then Inkscape should call this: sp_event_context_snap_window_open(event_context); - } - - //std::cout << "SnapManager::freeSnap -> postponed: " << snapprefs.getSnapPostponedGlobally() << std::endl; - if (!someSnapperMightSnap()) { return Inkscape::SnappedPoint(p, source_type, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false, false); } @@ -371,12 +364,7 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P bool first_point, Geom::OptRect const &bbox_to_snap) const { - if (_desktop->event_context && _desktop->event_context->_snap_window_open == false) { - g_warning("The current tool tries to snap, but it hasn't yet opened the snap window. Please report this!"); - // When the context goes into dragging-mode, then Inkscape should call this: sp_event_context_snap_window_open(event_context); - } - - if (!someSnapperMightSnap()) { + if (!someSnapperMightSnap()) { return Inkscape::SnappedPoint(p, source_type, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false, false); } @@ -419,11 +407,6 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P */ void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal) const { - if (_desktop->event_context && _desktop->event_context->_snap_window_open == false) { - g_warning("The current tool tries to snap, but it hasn't yet opened the snap window. Please report this!"); - // When the context goes into dragging-mode, then Inkscape should call this: sp_event_context_snap_window_open(event_context); - } - if (!snapprefs.getSnapEnabledGlobally() || snapprefs.getSnapPostponedGlobally()) { return; } @@ -465,12 +448,7 @@ void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal) void SnapManager::guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const { - if (_desktop->event_context && _desktop->event_context->_snap_window_open == false) { - g_warning("The current tool tries to snap, but it hasn't yet opened the snap window. Please report this!"); - // When the context goes into dragging-mode, then Inkscape should call this: sp_event_context_snap_window_open(event_context); - } - - if (!snapprefs.getSnapEnabledGlobally() || snapprefs.getSnapPostponedGlobally()) { + if (!snapprefs.getSnapEnabledGlobally() || snapprefs.getSnapPostponedGlobally()) { return; } diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 2f65b0ba9..5c7c43c83 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -221,7 +221,6 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) if (event->button.button == 1 && !event_context->space_panning) { dragging = TRUE; - sp_event_context_snap_window_open(event_context); sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event); SnapManager &m = desktop->namedview->snap_manager; @@ -270,7 +269,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) event_context->xp = event_context->yp = 0; if (event->button.button == 1 && !event_context->space_panning) { dragging = FALSE; - sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the spiral sp_spiral_finish(sc); @@ -323,7 +322,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) case GDK_Escape: if (dragging) { dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); // if drawing, cancel, otherwise pass it up for deselecting sp_spiral_cancel(sc); ret = TRUE; @@ -335,7 +334,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the spiral sp_spiral_finish(sc); diff --git a/src/star-context.cpp b/src/star-context.cpp index f0c64e875..80d378f27 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -236,7 +236,6 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent if (event->button.button == 1 && !event_context->space_panning) { dragging = TRUE; - sp_event_context_snap_window_open(event_context); sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event); @@ -283,7 +282,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent event_context->xp = event_context->yp = 0; if (event->button.button == 1 && !event_context->space_panning) { dragging = FALSE; - sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the star sp_star_finish (sc); @@ -336,7 +335,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent case GDK_Escape: if (dragging) { dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); // if drawing, cancel, otherwise pass it up for deselecting sp_star_cancel(sc); ret = TRUE; @@ -347,7 +346,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_snap_window_closed(event_context); + sp_event_context_discard_delayed_snap_event(event_context); if (!event_context->within_tolerance) { // we've been dragging, finish the star sp_star_finish(sc); diff --git a/src/text-context.cpp b/src/text-context.cpp index 538e13e43..c1986972a 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -352,7 +352,6 @@ sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve sp_text_context_update_cursor(tc); sp_text_context_update_text_selection(tc); tc->dragging = 1; - sp_event_context_snap_window_open(event_context); } ret = TRUE; } @@ -369,7 +368,6 @@ sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve sp_text_context_update_cursor(tc); sp_text_context_update_text_selection(tc); tc->dragging = 2; - sp_event_context_snap_window_open(event_context); ret = TRUE; } } @@ -381,14 +379,13 @@ sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve sp_text_context_update_cursor(tc); sp_text_context_update_text_selection(tc); tc->dragging = 3; - sp_event_context_snap_window_open(event_context); ret = TRUE; } break; case GDK_BUTTON_RELEASE: if (event->button.button == 1 && tc->dragging && !event_context->space_panning) { tc->dragging = 0; - sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings + sp_event_context_discard_delayed_snap_event(event_context); ret = TRUE; } break; -- 2.30.2