diff -ru metacity-cvs-shakeloose-03/src/constraints.c metacity-cvs/src/constraints.c
--- metacity-cvs-shakeloose-03/src/constraints.c	2006-09-27 15:57:23.000000000 +0200
+++ metacity-cvs/src/constraints.c	2006-09-28 02:06:37.000000000 +0200
@@ -519,26 +519,13 @@
                    .083 * info->work_area_xinerama.height;
         }
 
-      if (window->maximize_horizontally_after_placement &&
+      if (window->maximize_horizontally_after_placement ||
           window->maximize_vertically_after_placement)
         meta_window_maximize_internal (window,   
-                                       META_MAXIMIZE_HORIZONTAL |
-                                       META_MAXIMIZE_VERTICAL,
-                                       &info->current);
-      else if (window->maximize_horizontally_after_placement)
-        {
-          info->current.x = info->work_area_xinerama.x
-            + info->fgeom->left_width;
-          info->current.width = info->work_area_xinerama.width
-            - info->fgeom->left_width - info->fgeom->right_width;
-        }
-      else if (window->maximize_vertically_after_placement);
-        {
-          info->current.y = info->work_area_xinerama.y
-            + info->fgeom->top_height;
-          info->current.height = info->work_area_xinerama.height
-            - info->fgeom->top_height - info->fgeom->bottom_height;
-        }
+	    (window->maximize_horizontally_after_placement ?
+	     META_MAXIMIZE_HORIZONTAL : 0 ) |
+	    (window->maximize_vertically_after_placement ?
+	     META_MAXIMIZE_VERTICAL : 0), &info->current);
 
       /* maximization may have changed frame geometry */
       if (window->frame && !window->fullscreen)
diff -ru metacity-cvs-shakeloose-03/src/window.c metacity-cvs/src/window.c
--- metacity-cvs-shakeloose-03/src/window.c	2006-09-27 15:57:23.000000000 +0200
+++ metacity-cvs/src/window.c	2006-09-28 17:20:35.000000000 +0200
@@ -2325,13 +2325,32 @@
   meta_topic (META_DEBUG_WINDOW_OPS,
               "Unmaximizing %s just before freeing\n",
               window->desc);
-      
-  window->rect = window->saved_rect;
-  send_configure_notify (window);
 
   window->maximized_horizontally = FALSE;
   window->maximized_vertically = FALSE;
-  set_net_wm_state (window);
+
+  if (window->withdrawn)		/* See bug #137185 */
+    {
+      window->rect = window->saved_rect;
+      send_configure_notify (window);
+
+      set_net_wm_state (window);
+    }
+  else if (window->screen->closing)	/* See bug #358042 */
+    {
+      /* Do NOT update net_wm_state: this screen is closing,
+       * it likely will be managed by another window manager
+       * that will need the current _NET_WM_STATE atoms.
+       * Moreover, it will need to know the unmaximized geometry,
+       * therefore move_resize the window to saved_rect here
+       * before closing it. */
+      meta_window_move_resize (window,
+                               FALSE,
+                               window->saved_rect.x,
+                               window->saved_rect.y,
+                               window->saved_rect.width,
+                               window->saved_rect.height);
+    }
 }
 
 void
