Index: GSWheelColorPicker.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/ColorPickers/GSWheelColorPicker.m,v
retrieving revision 1.1
diff -u -r1.1 GSWheelColorPicker.m
--- GSWheelColorPicker.m	2 Jun 2002 21:00:34 -0000	1.1
+++ GSWheelColorPicker.m	7 Apr 2003 05:57:23 -0000
@@ -148,17 +148,13 @@
   PSrectfill(x - 1, y - 1, 2, 2);
 }
 
-
 - (void) mouseDown: (NSEvent *)theEvent
 {
-  NSApplication *app = [NSApplication sharedApplication];
   unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
-			  | NSLeftMouseDraggedMask | NSMouseMovedMask
-			  | NSPeriodicMask;
+			  | NSLeftMouseDraggedMask;
   NSPoint point = [self convertPoint: [theEvent locationInWindow] 
 			fromView: nil];
   NSEventType eventType = [theEvent type];
-  NSDate *distantFuture = [NSDate distantFuture];
 
   float new_hue, new_saturation;
   float old_x, old_y;
@@ -173,64 +169,83 @@
     cr = frame.size.height;
   cr = cr / 2 - 2;
 
-
-  [NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05];
-  [[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
-
   new_hue = hue;
   new_saturation = saturation;
 
   do
     {
-      if (eventType != NSPeriodic)
-	{
-	  point = [self convertPoint: [theEvent locationInWindow]
-			fromView: nil];
-
-	  dx = point.x - cx;
-	  dy = point.y - cy;
-
-	  new_saturation = dx * dx + dy * dy;
-	  new_saturation = sqrt(new_saturation);
-	  new_saturation /= cr;
-	  if (new_saturation > 1)
-	    new_saturation = 1;
-
-	  new_hue = atan2(dy, dx);
-	  new_hue = new_hue / 2.0 / PI;
-	  if (new_hue < 0)
-	    new_hue += 1;
-	}
-      else
-	{
-	  if (new_hue != hue || new_saturation != saturation)
-	    {
-	      old_x = cos(hue * 2 * PI) * saturation * cr + cx;
-	      old_y = sin(hue * 2 * PI) * saturation * cr + cy;
-
-	      hue = new_hue;
-	      saturation = new_saturation;
-
-	      [self lockFocus];
-	      [self drawRect: NSMakeRect(old_x - 3, old_y - 3, 6, 6)];
-	      [self drawRect: NSMakeRect(point.x - 3, point.y - 3, 6, 6)];
-	      [self unlockFocus];
-	      [_window flushWindow];
-
-	      if (target)
-		[target performSelector: action withObject: self];
-	    }
-	}
-
-      theEvent = [app nextEventMatchingMask: eventMask
-				  untilDate: distantFuture
-				     inMode: NSEventTrackingRunLoopMode
-				    dequeue: YES];
-      eventType = [theEvent type];
-    } while (eventType != NSLeftMouseUp);
-  [NSEvent stopPeriodicEvents];
+       /* Inner loop that gets and (quickly) handles all events that have
+          already arrived. */
+       while (theEvent && eventType != NSLeftMouseUp)
+         {
+           switch (eventType)
+             {
+               case NSLeftMouseDown:
+               case NSLeftMouseDragged:
+	         {
+	           point = [self convertPoint: [theEvent locationInWindow]
+			             fromView: nil];
+
+	           dx = point.x - cx;
+	           dy = point.y - cy;
+
+	           new_saturation = dx * dx + dy * dy;
+	           new_saturation = sqrt(new_saturation);
+	           new_saturation /= cr;
+	           if (new_saturation > 1)
+	             new_saturation = 1;
+
+	           new_hue = atan2(dy, dx);
+	           new_hue = new_hue / 2.0 / PI;
+	           if (new_hue < 0)
+	             new_hue += 1;
+
+                   break;
+	         }
+               default:
+                 NSDebugLog(@"GSWheelColorPicker: unhandled event");
+             }
+       
+           /* Note the event here. Don't do any expensive handling. */
+           theEvent = [NSApp nextEventMatchingMask: eventMask
+                         untilDate: [NSDate distantPast] /* Only get events that have arrived */
+                         inMode: NSEventTrackingRunLoopMode
+                         dequeue: YES];
+           eventType = [theEvent type];
+         }
+                           
+       if (eventType == NSLeftMouseUp)
+         break;
+
+       /* No more events right now. Do expensive handling, like drawing, 
+        * here. 
+	*/
+       if (new_hue != hue || new_saturation != saturation)
+         {
+	   old_x = cos(hue * 2 * PI) * saturation * cr + cx;
+	   old_y = sin(hue * 2 * PI) * saturation * cr + cy;
+
+	   hue = new_hue;
+	   saturation = new_saturation;
+
+	   [self lockFocus];
+	   [self drawRect: NSMakeRect(old_x - 3, old_y - 3, 6, 6)];
+	   [self drawRect: NSMakeRect(point.x - 3, point.y - 3, 6, 6)];
+	   [self unlockFocus];
+	   [_window flushWindow];
+
+	   if (target)
+	     [target performSelector: action withObject: self];
+	 }
+
+       /* Get the next event, blocking if necessary. */
+       theEvent = [NSApp nextEventMatchingMask: eventMask
+                     untilDate: nil /* No limit, block until we get an event. */
+                     inMode: NSEventTrackingRunLoopMode
+                     dequeue: YES];
+       eventType = [theEvent type];
+  } while (eventType != NSLeftMouseUp);
 }
-
 @end
 
 
