Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.177
diff -u -r1.177 display.c
--- src/display.c	28 Jan 2003 15:07:43 -0000	1.177
+++ src/display.c	12 Feb 2003 14:54:13 -0000
@@ -1835,7 +1835,10 @@
 		  if (showing_desktop)
 		    meta_screen_show_desktop (screen);
 		  else
-		    meta_screen_unshow_desktop (screen);
+		    {
+		      minimize_all_but (window);
+		      meta_screen_unshow_desktop (screen);
+		    }
 		}
               else if (event->xclient.message_type ==
                        display->atom_metacity_restart_message)
Index: src/keybindings.c
===================================================================
RCS file: /cvs/gnome/metacity/src/keybindings.c,v
retrieving revision 1.77
diff -u -r1.77 keybindings.c
--- src/keybindings.c	5 Feb 2003 03:58:16 -0000	1.77
+++ src/keybindings.c	12 Feb 2003 14:54:29 -0000
@@ -2511,7 +2511,10 @@
                        MetaKeyBinding *binding)
 {
   if (screen->showing_desktop)
-    meta_screen_unshow_desktop (screen);
+    {
+      meta_screen_unshow_desktop (screen);
+      meta_screen_focus_top_window (screen, NULL);
+    }
   else
     meta_screen_show_desktop (screen);
 }
Index: src/screen.c
===================================================================
RCS file: /cvs/gnome/metacity/src/screen.c,v
retrieving revision 1.101
diff -u -r1.101 screen.c
--- src/screen.c	28 Jan 2003 15:07:43 -0000	1.101
+++ src/screen.c	12 Feb 2003 14:54:38 -0000
@@ -1999,6 +1999,31 @@
 }
 
 void
+minimize_all_but (MetaWindow *keep)
+{
+  GSList *windows;
+  GSList *tmp;
+  
+  windows = meta_display_list_windows (keep->screen->display);
+  
+  tmp = windows;
+  while (tmp != NULL)
+    {
+      MetaWindow *w = tmp->data;
+      
+      if (w->screen == keep->screen &&
+	  w->type != META_WINDOW_DESKTOP &&
+	  w->type != META_WINDOW_DOCK &&
+	  w != keep)
+	meta_window_minimize (w);
+      
+      tmp = tmp->next;
+    }
+  
+  g_slist_free (windows);
+}
+
+void
 meta_screen_show_desktop (MetaScreen *screen)
 {
   if (screen->showing_desktop)
@@ -2022,8 +2047,6 @@
   queue_windows_showing (screen);
 
   update_showing_desktop_hint (screen);
-
-  meta_screen_focus_top_window (screen, NULL);
 }
 
 #ifdef HAVE_STARTUP_NOTIFICATION
Index: src/screen.h
===================================================================
RCS file: /cvs/gnome/metacity/src/screen.h,v
retrieving revision 1.46
diff -u -r1.46 screen.h
--- src/screen.h	28 Jan 2003 15:07:43 -0000	1.46
+++ src/screen.h	12 Feb 2003 14:54:41 -0000
@@ -166,6 +166,7 @@
                          int         width,
                          int         height);
 
+void     minimize_all_but (MetaWindow *keep);
 
 /* Show/hide the desktop (temporarily hide all windows) */
 void     meta_screen_show_desktop   (MetaScreen *screen);
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.264
diff -u -r1.264 window.c
--- src/window.c	25 Jan 2003 16:58:43 -0000	1.264
+++ src/window.c	12 Feb 2003 14:56:28 -0000
@@ -685,7 +685,10 @@
   if (window->screen->showing_desktop &&
       window->type != META_WINDOW_DESKTOP &&
       window->type != META_WINDOW_DOCK)
-    meta_screen_unshow_desktop (window->screen);
+    {
+      minimize_all_but (window);
+      meta_screen_unshow_desktop (window->screen);
+    }
   
   meta_window_queue_calc_showing (window);
 
@@ -1750,9 +1753,6 @@
 void
 meta_window_unminimize (MetaWindow  *window)
 {
-  if (window->screen->showing_desktop)
-    meta_screen_unshow_desktop (window->screen);
-  
   if (window->minimized)
     {
       window->minimized = FALSE;
@@ -1984,8 +1984,11 @@
   if (window->screen->showing_desktop &&
       window->type != META_WINDOW_DESKTOP &&
       window->type != META_WINDOW_DOCK)
-    meta_screen_unshow_desktop (window->screen);
-  
+    {
+      minimize_all_but (window);
+      meta_screen_unshow_desktop (window->screen);
+    }
+ 
   /* Get window on current workspace */
   if (!meta_window_visible_on_workspace (window,
                                          window->screen->active_workspace))
