gEDA-dev: [PATCH] Fixes a race condition with mouse wheel scroll events

Alex Precosky precosky at mac.com
Sun Jul 1 20:43:47 EDT 2007


If more than one mouse wheel scroll events are received into the  
event queue
before the first one can be processed, then the program was zooming  
in to the
wrong location.  This is because the mouse moved event handler, which  
is triggered
by a call to warp the cursor in the scroll event handler, must run to  
update
the mouse postion global variables that the scroll event handler needs.
---
  gschem/src/a_zoom.c |   17 +++++++++++++++++
  1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/gschem/src/a_zoom.c b/gschem/src/a_zoom.c
index 23edb4a..8f431f3 100644
--- a/gschem/src/a_zoom.c
+++ b/gschem/src/a_zoom.c
@@ -133,6 +133,23 @@ void a_zoom(TOPLEVEL *w_current, int dir, int  
selected_from, int pan_flags)
    /* calculate new window and draw it */
    a_pan_general(w_current, world_pan_center_x, world_pan_center_y,
                  relativ_zoom_factor, pan_flags);
+
+  /* Before warping the cursor, filter out any consecutive scroll  
events
+   * from the event queue.  If the program receives more than one  
scroll
+   * event before it can process the first one, then the globals  
mouse_x
+   * and mouse_y won't contain the proper mouse position,
+   * because the handler for the mouse moved event needs to
+   * run first to set these values.
+   */
+  GdkEvent *topEvent = gdk_event_get();
+  while( topEvent != NULL ) {
+    if( topEvent->type != GDK_SCROLL ) {
+      gdk_event_put( topEvent );
+      break;
+    }
+    gdk_event_free( topEvent );
+    topEvent = gdk_event_get();
+  }

    /* warp the cursor to the right position */
    if (w_current->warp_cursor) {
-- 
1.5.2.1


More information about the geda-dev mailing list