Index: src/boxes.c
===================================================================
RCS file: /cvs/gnome/metacity/src/boxes.c,v
retrieving revision 1.3
diff -p -u -r1.3 boxes.c
--- src/boxes.c	2 Jan 2006 18:37:46 -0000	1.3
+++ src/boxes.c	9 Jan 2006 20:11:20 -0000
@@ -622,15 +622,38 @@ meta_rectangle_expand_region (GList     
                               const int  top_expand,
                               const int  bottom_expand)
 {
-  /* Now it's time to do the directional expansion */
+  return meta_rectangle_expand_region_conditionally (region,
+                                                     left_expand,
+                                                     right_expand,
+                                                     top_expand,
+                                                     bottom_expand,
+                                                     0,
+                                                     0);
+}
+
+GList*
+meta_rectangle_expand_region_conditionally (GList     *region,
+                                            const int  left_expand,
+                                            const int  right_expand,
+                                            const int  top_expand,
+                                            const int  bottom_expand,
+                                            const int  min_x,
+                                            const int  min_y)
+{
   GList *tmp_list = region;
   while (tmp_list)
     {
       MetaRectangle *rect = (MetaRectangle*) tmp_list->data;
-      rect->x      -= left_expand;
-      rect->width  += (left_expand + right_expand);
-      rect->y      -= top_expand;
-      rect->height += (top_expand + bottom_expand);
+      if (rect->width >= min_x)
+        {
+          rect->x      -= left_expand;
+          rect->width  += (left_expand + right_expand);
+        }
+      if (rect->height >= min_y)
+        {
+          rect->y      -= top_expand;
+          rect->height += (top_expand + bottom_expand);
+        }
       tmp_list = tmp_list->next;
     }
 
@@ -1067,8 +1090,7 @@ replace_rect_with_list (GList *old_eleme
   if (!new_list)
     {
       /* If there is no new list, just remove the old_element */
-      ret = old_element->next;
-      g_list_remove_link (old_element, old_element);
+      ret = g_list_remove_link (old_element, old_element);
     }
   else
     {
Index: src/boxes.h
===================================================================
RCS file: /cvs/gnome/metacity/src/boxes.h,v
retrieving revision 1.2
diff -p -u -r1.2 boxes.h
--- src/boxes.h	19 Nov 2005 14:58:50 -0000	1.2
+++ src/boxes.h	9 Jan 2006 20:11:20 -0000
@@ -146,11 +146,23 @@ GList*   meta_rectangle_get_minimal_span
                                          const MetaRectangle *basic_rect,
                                          const GSList        *all_struts);
 
+/* Expand all rectangles in region by the given amount on each side */
 GList*   meta_rectangle_expand_region   (GList               *region,
                                          const int            left_expand,
                                          const int            right_expand,
                                          const int            top_expand,
                                          const int            bottom_expand);
+/* Same as for meta_rectangle_expand_region except that rectangles not at
+ * least min_x or min_y in size are not expanded in that direction
+ */
+GList*   meta_rectangle_expand_region_conditionally (
+                                         GList                *region,
+                                         const int            left_expand,
+                                         const int            right_expand,
+                                         const int            top_expand,
+                                         const int            bottom_expand,
+                                         const int            min_x,
+                                         const int            min_y);
 
 /* Free the list created by
  *   meta_rectangle_get_minimal_spanning_set_for_region()
Index: src/constraints.c
===================================================================
RCS file: /cvs/gnome/metacity/src/constraints.c,v
retrieving revision 1.26
diff -p -u -r1.26 constraints.c
--- src/constraints.c	2 Jan 2006 18:37:46 -0000	1.26
+++ src/constraints.c	9 Jan 2006 20:11:20 -0000
@@ -1046,7 +1046,9 @@ constrain_partially_onscreen (MetaWindow
                               gboolean            check_only)
 {
   gboolean retval;
-  int top_amount, bottom_amount, horiz_amount, vert_amount;
+  int top_amount, bottom_amount;
+  int horiz_amount_offscreen, vert_amount_offscreen;
+  int horiz_amount_onscreen,  vert_amount_onscreen;
 
   if (priority > PRIORITY_PARTIALLY_VISIBLE_ON_WORKAREA)
     return TRUE;
@@ -1066,39 +1068,46 @@ constrain_partially_onscreen (MetaWindow
    * Then, the amount that is allowed off is just the window size minus
    * this amount.
    */
-  horiz_amount = info->current.width  / 4;
-  vert_amount  = info->current.height / 4;
-  horiz_amount = CLAMP (horiz_amount, 10, 75);
-  vert_amount  = CLAMP (vert_amount,  10, 75);
-  horiz_amount = info->current.width - horiz_amount;
-  vert_amount  = info->current.height - vert_amount;
-  top_amount = vert_amount;
+  horiz_amount_onscreen = info->current.width  / 4;
+  vert_amount_onscreen  = info->current.height / 4;
+  horiz_amount_onscreen = CLAMP (horiz_amount_onscreen, 10, 75);
+  vert_amount_onscreen  = CLAMP (vert_amount_onscreen,  10, 75);
+  horiz_amount_offscreen = info->current.width - horiz_amount_onscreen;
+  vert_amount_offscreen  = info->current.height - vert_amount_onscreen;
+  top_amount = vert_amount_offscreen;
   /* Allow the titlebar to touch the bottom panel;  If there is no titlebar,
    * require vert_amount to remain on the screen.
    */
   if (window->frame)
-    bottom_amount = info->current.height + info->fgeom->bottom_height;
+    {
+      bottom_amount = info->current.height + info->fgeom->bottom_height;
+      vert_amount_onscreen = info->fgeom->top_height;
+    }
   else
-    bottom_amount = vert_amount;
+    bottom_amount = vert_amount_offscreen;
 
   /* Extend the region, have a helper function handle the constraint,
    * then return the region to its original size.
    */
-  meta_rectangle_expand_region (info->usable_screen_region,
-                                horiz_amount,
-                                horiz_amount, 
-                                top_amount,
-                                bottom_amount);
+  meta_rectangle_expand_region_conditionally (info->usable_screen_region,
+                                              horiz_amount_offscreen,
+                                              horiz_amount_offscreen, 
+                                              top_amount,
+                                              bottom_amount,
+                                              horiz_amount_onscreen,
+                                              vert_amount_onscreen);
   retval =
     do_screen_and_xinerama_relative_constraints (window, 
                                                  info->usable_screen_region,
                                                  info,
                                                  check_only);
-  meta_rectangle_expand_region (info->usable_screen_region,
-                                -horiz_amount,
-                                -horiz_amount, 
-                                -top_amount,
-                                -bottom_amount);
+  meta_rectangle_expand_region_conditionally (info->usable_screen_region,
+                                              -horiz_amount_offscreen,
+                                              -horiz_amount_offscreen,
+                                              -top_amount,
+                                              -bottom_amount,
+                                              horiz_amount_onscreen,
+                                              vert_amount_onscreen);
 
   return retval;
 }
