From 3f2ff5447db1411214ced97b31fe448cb46c1038 Mon Sep 17 00:00:00 2001 From: johncoswell Date: Sun, 3 Sep 2006 13:26:57 +0000 Subject: [PATCH] Disable pen event handling during important update operations --- src/pen-context.cpp | 32 ++++++++++++++++++++++++++++++++ src/pen-context.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/pen-context.cpp b/src/pen-context.cpp index c1d7af150..1136efb34 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -64,6 +64,8 @@ static gint pen_handle_2button_press(SPPenContext *const pc); static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event); static void spdc_reset_colors(SPPenContext *pc); +static void pen_disable_events(SPPenContext *const pc); +static void pen_enable_events(SPPenContext *const pc); static NR::Point pen_drag_origin_w(0, 0); static bool pen_within_tolerance = false; @@ -141,6 +143,8 @@ sp_pen_context_init(SPPenContext *pc) pc->c1 = NULL; pc->cl0 = NULL; pc->cl1 = NULL; + + pc->events_disabled = 0; } /** @@ -335,6 +339,11 @@ sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) */ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent) { + if (pc->events_disabled) { + // skip event processing if events are disabled + return FALSE; + } + gint ret = FALSE; if (bevent.button == 1) { @@ -473,6 +482,11 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent) // allow middle-button scrolling return FALSE; } + + if (pc->events_disabled) { + // skip motion events if pen events are disabled + return FALSE; + } NR::Point const event_w(mevent.x, mevent.y); @@ -589,6 +603,11 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent) static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent) { + if (pc->events_disabled) { + // skip event processing if events are disabled + return FALSE; + } + gint ret = FALSE; if ( revent.button == 1 ) { @@ -906,7 +925,9 @@ pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_Return: case GDK_KP_Enter: if (pc->npoints != 0) { + pen_disable_events(pc); spdc_pen_finish(pc, FALSE); + pen_enable_events(pc); ret = TRUE; } break; @@ -1150,6 +1171,17 @@ spdc_pen_finish(SPPenContext *const pc, gboolean const closed) } } +static void +pen_disable_events(SPPenContext *const pc) { + pc->events_disabled++; +} + +static void +pen_enable_events(SPPenContext *const pc) { + g_return_if_fail(pc->events_disabled != 0); + + pc->events_disabled--; +} /* Local Variables: diff --git a/src/pen-context.h b/src/pen-context.h index d0392134b..e149391a9 100644 --- a/src/pen-context.h +++ b/src/pen-context.h @@ -40,6 +40,8 @@ struct SPPenContext : public SPDrawContext { unsigned int onlycurves : 1; SPCanvasItem *c0, *c1, *cl0, *cl1; + + unsigned int events_disabled : 1; }; /// The SPPenContext vtable (empty). -- 2.30.2