Index: GSTitleView.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/GSTitleView.m,v
retrieving revision 1.9
diff -u -r1.9 GSTitleView.m
--- GSTitleView.m	21 Jan 2005 20:39:18 -0000	1.9
+++ GSTitleView.m	1 Feb 2005 19:58:09 -0000
@@ -267,16 +267,22 @@
 {
   return YES;
 } 
- 
+
+
 - (void) mouseDown: (NSEvent*)theEvent
 {
-  NSPoint  lastLocation;
+  NSPoint  locationInWindow;
   NSPoint  location;
-  unsigned eventMask = NSLeftMouseUpMask | NSPeriodicMask;
+  unsigned eventMask = NSLeftMouseUpMask | NSRightMouseUpMask
+		       | NSLeftMouseDraggedMask | NSRightMouseDraggedMask;
   BOOL     done = NO;
-  NSDate   *theDistantFuture = [NSDate distantFuture];
+  NSDate   *theDistantPast = [NSDate distantPast];
   NSPoint  startWindowOrigin;
   NSPoint  endWindowOrigin;
+  NSSize   screenSize = [[_window screen] frame].size;
+  NSSize   windowSize = [_window frame].size;
+  unsigned int lipMask;
+#define LIP 16.0
 
   NSDebugLLog (@"NSMenu", @"Mouse down in title!");
 
@@ -284,49 +290,102 @@
   startWindowOrigin = [_window frame].origin;
 
   // Remember start location of cursor in window
-  lastLocation = [theEvent locationInWindow];
+  location = locationInWindow = [theEvent locationInWindow];
 
   [_window _captureMouse: nil];
   
-  [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.02];
-
+  lipMask = 0;
   while (!done)
     {
-      theEvent = [NSApp nextEventMatchingMask: eventMask
-                                    untilDate: theDistantFuture
-                                       inMode: NSEventTrackingRunLoopMode
-                                      dequeue: YES];
-      switch ([theEvent type])
-        {
-        case NSRightMouseUp:
-        case NSLeftMouseUp: 
-          done = YES; 
-          [_window _releaseMouse: nil];
-          break;
-        case NSPeriodic:
-          location = [_window mouseLocationOutsideOfEventStream];
-          if (NSEqualPoints(location, lastLocation) == NO)
-            {
-              NSPoint origin = [_window frame].origin;
-
-              origin.x += (location.x - lastLocation.x);
-              origin.y += (location.y - lastLocation.y);
-	      if (_ownedByMenu)
+      while (theEvent)
+	{
+	  if ([theEvent type] == NSRightMouseUp
+	      || [theEvent type] == NSLeftMouseUp)
+	    break;
+
+	  location = [theEvent locationInWindow];
+
+	  theEvent = [NSApp nextEventMatchingMask: eventMask
+					untilDate: theDistantPast
+					   inMode: NSEventTrackingRunLoopMode
+					  dequeue: YES];
+	}
+
+      if ([theEvent type] == NSRightMouseUp
+	  || [theEvent type] == NSLeftMouseUp)
+	break;
+
+      if (NSEqualPoints(location, locationInWindow) == NO)
+	{
+	  NSPoint origin = [_window frame].origin;
+
+	  origin.x += (location.x - locationInWindow.x);
+	  origin.y += (location.y - locationInWindow.y);
+
+	  if (origin.x < 0 && origin.x >= -LIP && (lipMask & 1))
+	    {
+	      origin.x = 0;
+	    }
+	  else if (origin.x < 0)
+	    lipMask &= ~1;
+	  else
+	    lipMask |= 1;
+
+	  if (origin.x + windowSize.width > screenSize.width)
+	    {
+	      if (origin.x + windowSize.width <= screenSize.width + LIP
+		  && (lipMask & 2))
 		{
-		  [_owner nestedSetFrameOrigin: origin];
+		  origin.x = screenSize.width - windowSize.width;
 		}
 	      else
+		lipMask &= ~2;
+	    }
+	  else
+	    lipMask |= 2;
+
+
+	  if (origin.y < 0 && origin.y >= -LIP && (lipMask & 4))
+	    {
+	      origin.y = 0;
+	    }
+	  else if (origin.y < 0)
+	    lipMask &= ~4;
+	  else
+	    lipMask |= 4;
+
+	  if (origin.y + windowSize.height > screenSize.height)
+	    {
+	      if (origin.y + windowSize.height <= screenSize.height + LIP
+		  && (lipMask & 8))
 		{
-		  [_owner setFrameOrigin: origin];
+		  origin.y = screenSize.height - windowSize.height;
 		}
-            }
-          break;
+	      else
+		lipMask &= ~8;
+	    }
+	  else
+	    lipMask |= 8;
 
-        default: 
-          break;
+
+	  if (_ownedByMenu)
+	    {
+	      [_owner nestedSetFrameOrigin: origin];
+	    }
+	  else
+	    {
+	      [_owner setFrameOrigin: origin];
+	    }
         }
+
+      theEvent = [NSApp nextEventMatchingMask: eventMask
+				    untilDate: nil
+				       inMode: NSEventTrackingRunLoopMode
+				      dequeue: YES];
     }
 
+  [_window _releaseMouse: nil];
+
   // Make menu torn off
   if (_ownedByMenu && ![_owner isTornOff] && [_owner supermenu])
     {
@@ -338,7 +397,7 @@
 	}
     }
 
-  [NSEvent stopPeriodicEvents];
+//  [NSEvent stopPeriodicEvents];
 }
 
 // We do not need app menu over menu
