Index: display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.186
diff -r1.186 display.c
272c272,273
<     "_GNOME_PANEL_ACTION_RUN_DIALOG"
---
>     "_GNOME_PANEL_ACTION_RUN_DIALOG",
>     "_METACITY_SENTINEL"
418a420
>   display->atom_metacity_sentinel = atoms[84];
475a478
>   display->sentinel_counter = 0;
1437c1440,1441
<                event->xcrossing.detail != NotifyInferior)
---
>                event->xcrossing.detail != NotifyInferior &&
>                meta_display_focus_sentinel_clear (display))
1752a1757,1766
> 
>         /* we just use this property as a sentinel to avoid certain race
>          * conditions.  See the comment for the ignore_enter_notify
>          * variable declaration in display.h
>          */
>         if (event->xproperty.atom ==
> 	    display->atom_metacity_sentinel)
>           {
>             meta_display_decrement_focus_sentinel (display);
>           }
3997a4012,4049
> }
> 
> void
> meta_display_increment_focus_sentinel (MetaDisplay *display)
> {
>   unsigned long data[1];
> 
>   if (meta_display_focus_sentinel_clear (display))
>     {
>       data[0] = meta_display_get_current_time (display);
>   
>       XChangeProperty (display->xdisplay,
>                        ((MetaScreen*) display->screens->data)->xroot,
>                        display->atom_metacity_sentinel,
>                        XA_CARDINAL,
>                        32, PropModeReplace, (guchar*) data, 1);
>       
>       display->sentinel_counter += 1;
>     }
> }
> 
> void
> meta_display_decrement_focus_sentinel (MetaDisplay *display)
> {
>   display->sentinel_counter -= 1;
> 
>   if (display->sentinel_counter < 0)
>     display->sentinel_counter = 0;
> }
> 
> gboolean
> meta_display_focus_sentinel_clear (MetaDisplay *display)
> {
>   if (display->sentinel_counter == 0) {
>     return TRUE;
>   } else {
>     return FALSE;
>   }
Index: display.h
===================================================================
RCS file: /cvs/gnome/metacity/src/display.h,v
retrieving revision 1.102
diff -r1.102 display.h
174a175
>   Atom atom_metacity_sentinel;
250a252,257
> 
>   /* we use property updates as sentinels for certain window focus events
>    * to avoid some race conditions on EnterNotify events
>    */
>   int         sentinel_counter;
> 
440a448,451
> 
> void meta_display_increment_focus_sentinel (MetaDisplay *display);
> void meta_display_decrement_focus_sentinel (MetaDisplay *display);
> gboolean meta_display_focus_sentinel_clear (MetaDisplay *display);
Index: keybindings.c
===================================================================
RCS file: /cvs/gnome/metacity/src/keybindings.c,v
retrieving revision 1.86
diff -r1.86 keybindings.c
3025c3025
<         meta_workspace_activate (workspace);
---
>         meta_workspace_activate_with_focus (workspace, window);
Index: window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.277
diff -r1.277 window.c
1440a1441,1454
> 
>   /* for all displays used in the queue, set a sentinel property on
>    * the root window so that we can ignore EnterNotify events that
>    * occur before the window maps occur.  This avoids a race
>    * condition. */
>   tmp = should_show;
>   while (tmp != NULL)
>     {
>       MetaWindow *window = tmp->data;
>       meta_display_increment_focus_sentinel (window->display);
> 
>       tmp = tmp->next;
>     }
>    
Index: workspace.c
===================================================================
RCS file: /cvs/gnome/metacity/src/workspace.c,v
retrieving revision 1.42
diff -r1.42 workspace.c
199c199,200
< meta_workspace_activate (MetaWorkspace *workspace)
---
> meta_workspace_activate_with_focus (MetaWorkspace *workspace,
>                                     MetaWindow    *focus_this)
221,222c222,239
<   meta_topic (META_DEBUG_FOCUS, "Focusing default window on new workspace\n");
<   meta_screen_focus_default_window (workspace->screen, NULL);
---
>   if (focus_this)
>     {
>       meta_window_focus (focus_this,
>                          meta_display_get_current_time (focus_this->display));
>       meta_window_raise (focus_this);
>     }
>   else
>     {
>       meta_topic (META_DEBUG_FOCUS, "Focusing default window on new workspace\n");
>       meta_screen_focus_default_window (workspace->screen, NULL);
>     }
> }
> 
> void
> meta_workspace_activate (MetaWorkspace *workspace)
> {
>   meta_workspace_activate_with_focus (workspace,
>                                       NULL);
Index: workspace.h
===================================================================
RCS file: /cvs/gnome/metacity/src/workspace.h,v
retrieving revision 1.14
diff -r1.14 workspace.h
61c61,63
< void           meta_workspace_activate      (MetaWorkspace *workspace);
---
> void           meta_workspace_activate_with_focus (MetaWorkspace *workspace,
>                                                    MetaWindow    *focus_this);
> void           meta_workspace_activate            (MetaWorkspace *workspace);
