Index: Source/x11/XGServerEvent.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/back/Source/x11/XGServerEvent.m,v
retrieving revision 1.10
diff -u -r1.10 XGServerEvent.m
--- Source/x11/XGServerEvent.m	17 Jun 2003 13:32:04 -0000	1.10
+++ Source/x11/XGServerEvent.m	29 Oct 2003 04:36:04 -0000
@@ -502,6 +502,7 @@
 				cWin->number, 
 				generic.currentFocusWindow,
 				[nswin windowNumber]);
+#if 0
 		    if ([NSApp isActive]
 			&& ((generic.currentFocusWindow
 			     && cWin->number == generic.currentFocusWindow)
@@ -530,7 +531,15 @@
 			[self setinputfocus: number];
 		      }
 		    else
+#endif
 		      {
+			/* Invalidate the previous request. It's possible
+			   the app lost focus before this request was
+			   fufilled and we are being focused again, or... */
+			{
+			  generic.focusRequestNumber = 0;
+			  generic.desiredFocusWindow = 0;
+			}
 			/*
 			 * Here the app asked for this (if nswin==nil)
 			 * or there was a click on the title bar or
@@ -943,6 +952,12 @@
 	    cWin = [XGServer _windowForXWindow: xEvent.xfocus.window];
 	    NSDebugLLog(@"Focus", @"%d lost focus on %d\n",
 			xEvent.xfocus.window, (cWin) ? cWin->number : 0);
+	    if (cWin && generic.desiredFocusWindow == cWin->number)
+	      {
+		/* Request not valid anymore since we lost focus */
+		generic.focusRequestNumber = 0;
+		generic.desiredFocusWindow = 0;
+	      }
 	  }
 	  break;
 
@@ -1037,6 +1052,8 @@
 	      if (generic.desiredFocusWindow == cWin->number
 		  && generic.focusRequestNumber == 0)
 		{
+		  NSDebugLLog(@"Focus", @"Refocusing %d on map notify", 
+			      cWin->number);
 		  [self setinputfocus: cWin->number];
 		}
 	      /*
