diff -urN metacity-cvs-clean/src/window.c metacity/src/window.c
--- metacity-cvs-clean/src/window.c	Mon Jul 15 17:39:31 2002
+++ metacity/src/window.c	Tue Jul 16 18:36:57 2002
@@ -333,6 +333,7 @@
 
   window->frame = NULL;
   window->has_focus = FALSE;
+  window->expecting_focus_event = FALSE;
 
   window->user_has_move_resized = FALSE;
   
@@ -786,7 +787,7 @@
    * on what gets focused, maintaining sloppy focus
    * invariants.
    */
-  if (window->has_focus)
+  if (window->has_focus || window->expecting_focus_event)
     {
       meta_topic (META_DEBUG_FOCUS,
                   "Focusing top window since we're unmanaging %s\n",
@@ -2750,6 +2751,7 @@
                           window->frame->xwindow,
                           RevertToPointerRoot,
                           CurrentTime);
+          window->expecting_focus_event = TRUE;
         }
     }
   else
@@ -2765,6 +2767,7 @@
                           window->xwindow,
                           RevertToPointerRoot,
                           timestamp);
+          window->expecting_focus_event = TRUE;
         }
       
       if (window->take_focus)
@@ -3486,6 +3489,7 @@
                       "* Focus --> %s\n", window->desc);
           window->display->focus_window = window;
           window->has_focus = TRUE;
+          window->expecting_focus_event = FALSE;
           /* Move to the front of the MRU list */
           window->display->mru_list =
             g_list_remove (window->display->mru_list, window);
diff -urN metacity-cvs-clean/src/window.h metacity/src/window.h
--- metacity-cvs-clean/src/window.h	Mon Jul 15 17:39:31 2002
+++ metacity/src/window.h	Tue Jul 16 18:36:55 2002
@@ -166,6 +166,11 @@
    */
   guint has_focus : 1;
   
+  /* this flag indicates XSetInputFocus has been called
+   * but we have not yet received the resulting FocusIn event
+   */
+  guint expecting_focus_event : 1;
+
   /* Track whether the user has ever manually modified
    * the window; if so, we can use the saved user size/pos
    */
