2006-11-30  Federico Mena Quintero  <federico@novell.com>

	Fix http://bugzilla.gnome.org/show_bug.cgi?id=381127:

	* src/window.c (idle_calc_showing): Grab the server while the
	windows are being shuffled.  First show the windows to be shown, 
	and then hide the windows to be hidden, in order to minimize
	the number of expose events.

--- metacity/src/window.c.orig	2006-11-30 19:31:45.000000000 -0600
+++ metacity/src/window.c	2006-11-30 20:01:45.000000000 -0600
@@ -1379,6 +1379,7 @@ idle_calc_showing (gpointer data)
   GSList *should_hide;
   GSList *unplaced;
   GSList *displays;
+  MetaWindow *first_window;
 
   meta_topic (META_DEBUG_WINDOW_STATE,
               "Clearing the calc_showing queue\n");
@@ -1427,6 +1428,10 @@ idle_calc_showing (gpointer data)
   /* top to bottom */
   should_show = g_slist_sort (should_show, stackcmp);
   should_show = g_slist_reverse (should_show);
+
+  first_window = copy->data;
+
+  meta_display_grab (first_window->display);
   
   tmp = unplaced;
   while (tmp != NULL)
@@ -1440,26 +1445,26 @@ idle_calc_showing (gpointer data)
       tmp = tmp->next;
     }
 
-  tmp = should_hide;
+  tmp = should_show;
   while (tmp != NULL)
     {
       MetaWindow *window;
 
       window = tmp->data;
 
-      implement_showing (window, FALSE);
+      implement_showing (window, TRUE);
       
       tmp = tmp->next;
     }
   
-  tmp = should_show;
+  tmp = should_hide;
   while (tmp != NULL)
     {
       MetaWindow *window;
 
       window = tmp->data;
 
-      implement_showing (window, TRUE);
+      implement_showing (window, FALSE);
       
       tmp = tmp->next;
     }
@@ -1500,6 +1505,8 @@ idle_calc_showing (gpointer data)
         }
     }
 
+  meta_display_ungrab (first_window->display);
+  
   g_slist_free (copy);
 
   g_slist_free (unplaced);
