Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.177
diff -u -p -r1.177 display.c
--- src/display.c	28 Jan 2003 15:07:43 -0000	1.177
+++ src/display.c	22 Feb 2003 02:12:26 -0000
@@ -2914,7 +2914,7 @@ meta_display_end_grab_op (MetaDisplay *d
   meta_topic (META_DEBUG_WINDOW_OPS,
               "Ending grab op %d at time %lu\n", display->grab_op,
               (unsigned long) timestamp);
-  
+
   if (display->grab_op == META_GRAB_OP_NONE)
     return;
 
Index: src/place.c
===================================================================
RCS file: /cvs/gnome/metacity/src/place.c,v
retrieving revision 1.29
diff -u -p -r1.29 place.c
--- src/place.c	2 Oct 2002 02:42:24 -0000	1.29
+++ src/place.c	22 Feb 2003 02:12:27 -0000
@@ -121,12 +121,8 @@ find_next_cascade (MetaWindow *window,
    * of NW corner of window frame.
    */
   
-  /* FIXME this is bogus because we get the current xinerama
-   * for the window based on its position, but we haven't
-   * placed it yet.
-   */
-  meta_window_get_work_area (window, TRUE, &work_area);
-  
+  meta_window_get_work_area_for_xinerama (window, TRUE, 0, &work_area);
+
   cascade_x = MAX (0, work_area.x);
   cascade_y = MAX (0, work_area.y);
   
@@ -364,12 +360,19 @@ topmost_cmp (gconstpointer a, gconstpoin
 }
 
 static gboolean
-fit_rect_in_xinerama (MetaScreen    *screen,
+fit_rect_in_xinerama (MetaWindow *window,
                       MetaRectangle *rect)
 {
   int i;
   int best_index;
   int best_overlap;
+  /* see the comment in find_first_fit for the explanation for this
+   * variable
+   */
+  int fluff;
+
+  MetaScreen *screen = window->screen;
+  MetaRectangle work_area;
   const MetaXineramaScreenInfo *xsi;
   
   /* Find xinerama with best fit, then
@@ -409,17 +412,23 @@ fit_rect_in_xinerama (MetaScreen    *scr
   /* some overlap had to be better than -1 */
   g_assert (best_index >= 0);
 
-  xsi = &screen->xinerama_infos[best_index];
+  meta_window_get_work_area_for_xinerama(window, TRUE, best_index, &work_area);
   
-  if (rect->x < xsi->x_origin)
-    rect->x = xsi->x_origin;
-  if (rect->y < xsi->y_origin)
-    rect->y = xsi->y_origin;
+  if ((rect->x < work_area.x) || (rect->y < work_area.y) ||
+      (rect->x > work_area.x + work_area.width) ||
+      (rect->y > work_area.y + work_area.height))
+    {
+
+      fluff = (work_area.width % rect->width) / 2;
+      rect->x = work_area.x+fluff;
+      fluff = (work_area.height % rect->height) / 3;
+      rect->y = work_area.y+fluff;
+    }
 
   /* Now return whether we are entirely within the xinerama screen */
-  return
-    ((rect->x + rect->width) < (xsi->x_origin + xsi->width)) &&
-    ((rect->y + rect->height) < (xsi->y_origin + xsi->height));
+  return 
+    ((rect->x + rect->width) < (work_area.x + work_area.width)) &&
+    ((rect->y + rect->height) < (work_area.y + work_area.height));
 }
 
 /* Find the leftmost, then topmost, empty area on the workspace
@@ -449,9 +458,19 @@ find_first_fit (MetaWindow *window,
    */
   
   int retval;
+  /* The first-fit includes the "fluff" to implement "visually
+   * centered tiling", where windows are mapped so that there is just
+   * enough space on the left and top of the window that if the screen
+   * is tiled with as many of that type of window as will fit, the
+   * whole group will be visually centered (i.e. centered horizontally
+   * and with twice as much space on the bottom as on the top).
+   */
+
+  int fluff;
   GList *sorted;
   GList *tmp;
   MetaRectangle rect;
+  MetaRectangle work_area;
   int i;
   
   retval = FALSE;
@@ -467,10 +486,13 @@ find_first_fit (MetaWindow *window,
     }
 
   /* Try origin of first Xinerama */
-  rect.x = window->screen->xinerama_infos[0].x_origin;
-  rect.y = window->screen->xinerama_infos[0].y_origin;
+  meta_window_get_work_area_for_xinerama(window, TRUE, 0, &work_area);
+  fluff = (work_area.width % rect.width) / 2;
+  rect.x = work_area.x + fluff;
+  fluff = (work_area.height % rect.height) / 3;
+  rect.y = work_area.y + fluff;
 
-  if (fit_rect_in_xinerama (window->screen, &rect) &&
+  if (fit_rect_in_xinerama (window, &rect) &&
       !rectangle_overlaps_some_window (&rect, windows))
     {
       *new_x = rect.x;
@@ -496,28 +518,33 @@ find_first_fit (MetaWindow *window,
   while (tmp != NULL)
     {
       MetaWindow *w = tmp->data;
-      MetaRectangle outer_rect;
-      
-      meta_window_get_outer_rect (w, &outer_rect);
-
-      rect.x = outer_rect.x;
-      rect.y = outer_rect.y + outer_rect.height;
-      
-      if (fit_rect_in_xinerama (window->screen, &rect) &&
-          !rectangle_overlaps_some_window (&rect, sorted))
-        {
-          *new_x = rect.x;
-          *new_y = rect.y;
-          if (fgeom)
-            {
-              *new_x += fgeom->left_width;
-              *new_y += fgeom->top_height;
-            }
 
-          retval = TRUE;
+      /* don't try to place on the edge of a dock */
+      if (META_WINDOW_DOCK != w->type)
+	{
+	  MetaRectangle outer_rect;
+	  
+	  meta_window_get_outer_rect (w, &outer_rect);
+	  
+	  rect.x = outer_rect.x;
+	  rect.y = outer_rect.y + outer_rect.height;
+	  
+	  if (fit_rect_in_xinerama (window, &rect) &&
+	      !rectangle_overlaps_some_window (&rect, sorted))
+	    {
+	      *new_x = rect.x;
+	      *new_y = rect.y;
+	      if (fgeom)
+		{
+		  *new_x += fgeom->left_width;
+		  *new_y += fgeom->top_height;
+		}
+	      
+	      retval = TRUE;
 
-          goto out;
-        }
+	      goto out;
+	    }
+	}
       
       tmp = tmp->next;
     }
@@ -530,40 +557,48 @@ find_first_fit (MetaWindow *window,
   while (tmp != NULL)
     {
       MetaWindow *w = tmp->data;
-      MetaRectangle outer_rect;
-      
-      meta_window_get_outer_rect (w, &outer_rect);
 
-      rect.x = outer_rect.x + outer_rect.width;
-      rect.y = outer_rect.y;
+      /* don't try to place on the edge of a dock */
+     if (META_WINDOW_DOCK != w->type)
+	{
+	  MetaRectangle outer_rect;
       
-      if (fit_rect_in_xinerama (window->screen, &rect) &&
-          !rectangle_overlaps_some_window (&rect, sorted))
-        {
-          *new_x = rect.x;
-          *new_y = rect.y;
-          if (fgeom)
-            {
-              *new_x += fgeom->left_width;
-              *new_y += fgeom->top_height;
-            }
+	  meta_window_get_outer_rect (w, &outer_rect);
 
-          retval = TRUE;
-
-          goto out;
-        }      
+	  rect.x = outer_rect.x + outer_rect.width;
+	  rect.y = outer_rect.y;
       
+	  if (fit_rect_in_xinerama (window, &rect) &&
+	      !rectangle_overlaps_some_window (&rect, sorted))
+	    {
+	      *new_x = rect.x;
+	      *new_y = rect.y;
+	      if (fgeom)
+		{
+		  *new_x += fgeom->left_width;
+		  *new_y += fgeom->top_height;
+		}
+
+	      retval = TRUE;
+
+	      goto out;
+	    }      
+	}
       tmp = tmp->next;
-    }  
+    }
 
   /* Origin of each Xinerama screen which isn't the first */
   i = 1;
   while (i < window->screen->n_xinerama_infos)
     {
-      rect.x = window->screen->xinerama_infos[i].x_origin;
-      rect.y = window->screen->xinerama_infos[i].y_origin;
-      
-      if (fit_rect_in_xinerama (window->screen, &rect) &&
+
+      meta_window_get_work_area_for_xinerama(window, TRUE, i, &work_area);
+      fluff = (work_area.width % rect.width) / 2;
+      rect.x = work_area.x + fluff;
+      fluff = (work_area.height % rect.height) / 3;
+      rect.y = work_area.y + fluff;
+
+      if (fit_rect_in_xinerama (window, &rect) &&
           !rectangle_overlaps_some_window (&rect, windows))
         {
           *new_x = rect.x;
@@ -605,14 +640,11 @@ constrain_placement (MetaWindow        *
   
   meta_window_get_outer_rect (window, &outer_rect);
   
-  /* FIXME this is bogus because we get the current xinerama
-   * for the window based on its position, but we haven't
-   * placed it yet.
-   */
-  meta_window_get_work_area (window, TRUE, &work_area);
+  meta_window_get_work_area_for_xinerama (window, TRUE, 0, &work_area);
 
   nw_x = work_area.x;
   nw_y = work_area.y;
+
   if (window->frame)
     {
       nw_x += fgeom->left_width;
@@ -749,33 +781,33 @@ meta_window_place (MetaWindow        *wi
                                       window->xtransient_for);
 
       if (parent)
-        {
-          int w;
-
-          meta_window_get_position (parent, &x, &y);
-          w = parent->rect.width;
-
-          /* center of parent */
-          x = x + w / 2;
-          /* center of child over center of parent */
-          x -= window->rect.width / 2;
-
-          /* put child down 1/5 or so from the top of parent, unless
-           * it makes us have more of parent showing above child than
-           * below
-           */
-          if (window->rect.height <= (parent->rect.height - (parent->rect.height / 5) * 2))
-            y += parent->rect.height / 5;
-
-          /* put top of child's frame, not top of child's client */
-          if (fgeom)
-            y += fgeom->top_height;
-
-          meta_topic (META_DEBUG_PLACEMENT, "Centered window %s over transient parent\n",
-                      window->desc);
-          
-          goto done;
-        }
+	{
+	  int w;
+	  
+	  meta_window_get_position (parent, &x, &y);
+	  w = parent->rect.width;
+ 
+	  /* center of parent */
+	  x = x + w / 2;
+	  /* center of child over center of parent */
+	  x -= window->rect.width / 2;
+ 
+	  /* put child down 1/5 or so from the top of parent, unless
+	   * it makes us have more of parent showing above child than
+	   * below
+	   */
+	  if (window->rect.height <= (parent->rect.height - (parent->rect.height / 5) * 2))
+	    y += parent->rect.height / 5;
+ 
+	  /* put top of child's frame, not top of child's client */
+	  if (fgeom)
+	    y += fgeom->top_height;
+ 
+	  meta_topic (META_DEBUG_PLACEMENT, "Centered window %s over transient parent\n",
+		      window->desc);
+           
+	  goto done;
+	}
     }
 
   /* FIXME UTILITY with transient set should be stacked up
@@ -849,6 +881,7 @@ meta_window_place (MetaWindow        *wi
   constrain_placement (window, fgeom, x, y, &x, &y);
 
  done_no_constraints:
+  
   *new_x = x;
   *new_y = y;
 }
Index: src/screen.c
===================================================================
RCS file: /cvs/gnome/metacity/src/screen.c,v
retrieving revision 1.102
diff -u -p -r1.102 screen.c
--- src/screen.c	14 Feb 2003 07:03:46 -0000	1.102
+++ src/screen.c	22 Feb 2003 02:12:29 -0000
@@ -1283,18 +1283,15 @@ meta_screen_focus_default_window (MetaSc
 }
 
 const MetaXineramaScreenInfo*
-meta_screen_get_xinerama_for_window (MetaScreen *screen,
-				     MetaWindow *window)
+meta_screen_get_xinerama_for_rect (MetaScreen *screen,
+				   MetaRectangle *rect)
 {
   int i;
   int best_xinerama, xinerama_score;
-  MetaRectangle window_rect;
 
   if (screen->n_xinerama_infos == 1)
     return &screen->xinerama_infos[0];
-  
-  meta_window_get_outer_rect (window, &window_rect);
-  
+
   best_xinerama = 0;
   xinerama_score = 0;
 
@@ -1308,7 +1305,7 @@ meta_screen_get_xinerama_for_window (Met
       screen_info.width = screen->xinerama_infos[i].width;
       screen_info.height = screen->xinerama_infos[i].height;
       
-      if (meta_rectangle_intersect (&screen_info, &window_rect, &dest))
+      if (meta_rectangle_intersect (&screen_info, rect, &dest))
         {
           if (dest.width * dest.height > xinerama_score)
             {
@@ -1316,7 +1313,6 @@ meta_screen_get_xinerama_for_window (Met
               best_xinerama = i;
             }
         }
-
       ++i;
     }
 
@@ -1324,6 +1320,43 @@ meta_screen_get_xinerama_for_window (Met
 }
 
 const MetaXineramaScreenInfo*
+meta_screen_get_xinerama_for_window (MetaScreen *screen,
+				     MetaWindow *window)
+{
+  MetaRectangle window_rect;
+  
+  meta_window_get_outer_rect (window, &window_rect);
+
+  return meta_screen_get_xinerama_for_rect(screen, &window_rect);
+}
+
+gboolean
+meta_screen_window_on_xinerama (MetaScreen *screen,
+				MetaWindow *window,
+				gint which_xinerama)
+{
+  MetaRectangle window_rect;
+  MetaRectangle dest, screen_info;
+  
+  meta_window_get_outer_rect (window, &window_rect);
+  
+  screen_info.x = screen->xinerama_infos[which_xinerama].x_origin;
+  screen_info.y = screen->xinerama_infos[which_xinerama].y_origin;
+  screen_info.width = screen->xinerama_infos[which_xinerama].width;
+  screen_info.height = screen->xinerama_infos[which_xinerama].height;
+  
+  if (meta_rectangle_intersect (&screen_info, &window_rect, &dest))
+    {
+      if (dest.width * dest.height > 0)
+	{
+	  return TRUE;
+	}
+    }
+
+  return FALSE;
+}
+
+const MetaXineramaScreenInfo*
 meta_screen_get_current_xinerama (MetaScreen *screen)
 {
   if (screen->n_xinerama_infos == 1)
@@ -1357,9 +1390,11 @@ meta_screen_get_current_xinerama (MetaSc
       while (i < screen->n_xinerama_infos)
         {
           if ((root_x_return >= screen->xinerama_infos[i].x_origin &&
-               root_x_return < (screen->xinerama_infos[i].x_origin + screen->xinerama_infos[i].width) &&
+               root_x_return < (screen->xinerama_infos[i].x_origin + 
+				screen->xinerama_infos[i].width) &&
                root_y_return >= screen->xinerama_infos[i].y_origin &&
-               root_y_return < (screen->xinerama_infos[i].y_origin + screen->xinerama_infos[i].height)))
+               root_y_return < (screen->xinerama_infos[i].y_origin + 
+				screen->xinerama_infos[i].height)))
           {
             screen->last_xinerama_index = i;
             break;
@@ -1594,7 +1629,7 @@ set_work_area_hint (MetaScreen *screen)
 
       if (workspace->screen == screen)
         {
-          meta_workspace_get_work_area (workspace, &area);
+          meta_workspace_get_work_area (workspace, &area, -1);
           tmp[0] = area.x;
           tmp[1] = area.y;
           tmp[2] = area.width;
Index: src/screen.h
===================================================================
RCS file: /cvs/gnome/metacity/src/screen.h,v
retrieving revision 1.46
diff -u -p -r1.46 screen.h
--- src/screen.h	28 Jan 2003 15:07:43 -0000	1.46
+++ src/screen.h	22 Feb 2003 02:12:29 -0000
@@ -134,8 +134,13 @@ void          meta_screen_focus_default_
                                                 MetaWindow                 *not_this_one);
 
 const MetaXineramaScreenInfo* meta_screen_get_current_xinerama (MetaScreen *screen);
+const MetaXineramaScreenInfo* meta_screen_get_xinerama_for_rect (MetaScreen *screen,
+								 MetaRectangle *rect);
 const MetaXineramaScreenInfo* meta_screen_get_xinerama_for_window (MetaScreen *screen,
 								   MetaWindow *window);
+gboolean meta_screen_window_on_xinerama (MetaScreen *screen, 
+					 MetaWindow *window,
+					 gint which_xinerama);
 
 void          meta_screen_update_workspace_layout (MetaScreen             *screen);
 void          meta_screen_update_workspace_names  (MetaScreen             *screen);
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.264
diff -u -p -r1.264 window.c
--- src/window.c	25 Jan 2003 16:58:43 -0000	1.264
+++ src/window.c	22 Feb 2003 02:12:35 -0000
@@ -670,7 +670,7 @@ meta_window_new (MetaDisplay *display,
       MetaRectangle outer;
       
       meta_window_get_work_area (window, TRUE, &workarea);      
-
+    
       meta_window_get_outer_rect (window, &outer);
       
       if (outer.width >= workarea.width &&
@@ -2174,6 +2174,9 @@ meta_window_move_resize_internal (MetaWi
    */
   int client_move_x;
   int client_move_y;
+
+  const MetaXineramaScreenInfo *old_xsi;
+  const MetaXineramaScreenInfo *new_xsi;
   
   is_configure_request = (flags & META_IS_CONFIGURE_REQUEST) != 0;
   do_gravity_adjust = (flags & META_DO_GRAVITY_ADJUST) != 0;
@@ -2181,7 +2184,10 @@ meta_window_move_resize_internal (MetaWi
   
   /* We don't need it in the idle queue anymore. */
   meta_window_unqueue_move_resize (window);  
-  
+
+  /* see which xinerama the window is on to begin */
+  old_xsi = meta_screen_get_xinerama_for_window(window->screen, window);
+
   {
     int oldx, oldy;
     meta_window_get_position (window, &oldx, &oldy);
@@ -2559,6 +2565,13 @@ meta_window_move_resize_internal (MetaWi
     {
       meta_topic (META_DEBUG_GEOMETRY, "Size/position not modified\n");
     }
+
+  /* invalidate work areas if strut window changes xinerama */
+  new_xsi = meta_screen_get_xinerama_for_window(window->screen, window);
+  if ((new_xsi != old_xsi) && (window->has_struts))
+    {
+      invalidate_work_areas(window);
+    }
   
   /* Update struts for new window size */
   if (window->do_not_cover && (need_resize_client || need_move_client))
@@ -5823,9 +5836,15 @@ constrain_position (MetaWindow        *w
     }
   else if (window->maximized)
     {
+      const MetaXineramaScreenInfo* xsi;
       MetaRectangle work_area;
-      
-      meta_window_get_work_area (window, TRUE, &work_area);
+
+      xsi = meta_screen_get_xinerama_for_rect (window->screen, 
+					       &window->saved_rect);
+      meta_window_get_work_area_for_xinerama (window, 
+					      TRUE, 
+					      xsi->number, 
+					      &work_area);
       
       x = work_area.x;
       y = work_area.y;
@@ -5840,7 +5859,7 @@ constrain_position (MetaWindow        *w
        * the maximized area horizontally.
        */
       x += (work_area.width - window->rect.width -
-            (window->frame ? (fgeom->left_width + fgeom->right_width) : 0)) / 2;
+            (window->frame ? (fgeom->left_width + fgeom->right_width) : 0))/ 2;
     }
   else
     {
@@ -5848,8 +5867,25 @@ constrain_position (MetaWindow        *w
       int se_x, se_y;
       int offscreen_w, offscreen_h;
       MetaRectangle work_area;
+      MetaRectangle window_area;
+      const MetaXineramaScreenInfo* xsi;
+
+      /* this is the rect for the window if it were where we're moving
+	 it now */
+      meta_window_get_outer_rect(window, &window_area);
+      window_area.x = x;
+      window_area.y = y;
+      if (fgeom)
+	{
+	  window_area.x -= fgeom->left_width;
+	  window_area.y -= fgeom->top_height;
+	}
       
-      meta_window_get_work_area (window, FALSE, &work_area);
+      xsi = meta_screen_get_xinerama_for_rect (window->screen, &window_area);
+      meta_window_get_work_area_for_xinerama (window, 
+					      TRUE, 
+					      xsi->number, 
+					      &work_area);
       
       /* (FIXME instead of TITLEBAR_LENGTH_ONSCREEN, get the actual
        * size of the menu control?).
@@ -5867,7 +5903,11 @@ constrain_position (MetaWindow        *w
       if (window->frame)
         {
           /* Must keep TITLEBAR_LENGTH_ONSCREEN onscreen when moving left */
-          nw_x -= fgeom->left_width + window->rect.width + fgeom->right_width - TITLEBAR_LENGTH_ONSCREEN;
+          nw_x -= 
+	    fgeom->left_width + 
+	    window->rect.width + 
+	    fgeom->right_width - 
+	    TITLEBAR_LENGTH_ONSCREEN;
           /* Can't move off the top */
           nw_y += fgeom->top_height;
         }
@@ -5936,7 +5976,7 @@ constrain_position (MetaWindow        *w
           nw_y = se_y;
           se_y = tmp;
         }
-      
+
       /* Clamp window to the given positions.
        * Do the SE clamp first, so that the NW clamp has precedence
        * and we don't tend to lose the titlebar for too-large
@@ -5951,7 +5991,7 @@ constrain_position (MetaWindow        *w
         x = nw_x;
       if (y < nw_y)
         y = nw_y;
-      
+     
 #undef TITLEBAR_LENGTH_ONSCREEN
     }
   
@@ -6474,7 +6514,7 @@ meta_window_handle_mouse_grab_op_event (
             update_resize (window, event->xbutton.x_root, event->xbutton.y_root);
         }
 
-      meta_display_end_grab_op (window->display, event->xbutton.time);
+     meta_display_end_grab_op (window->display, event->xbutton.time);
       break;    
 
     case MotionNotify:
@@ -6569,62 +6609,86 @@ meta_window_set_gravity (MetaWindow *win
 }
 
 void
-meta_window_get_work_area (MetaWindow    *window,
-                           gboolean       for_current_xinerama,
-                           MetaRectangle *area)
+meta_window_get_work_area_for_xinerama (MetaWindow    *window,
+					gboolean      for_current_xinerama,
+					gint          which_xinerama,
+					MetaRectangle *area)
 {
   MetaRectangle space_area;
   GList *tmp;
   
-  int left_strut;
-  int right_strut;
-  int top_strut;
-  int bottom_strut;  
+  int left_strut = 0;
+  int right_strut = 0;
+  int top_strut = 0;
+  int bottom_strut = 0;  
+
+  int screen_width;
+  int screen_height;
+  int screen_origin_x;
+  int screen_origin_y;
 
   if (for_current_xinerama)
     {
-      const MetaXineramaScreenInfo *xinerama;
-      
-      xinerama = meta_screen_get_xinerama_for_window (window->screen,
-                                                      window);
-      
-      left_strut = xinerama->x_origin;
-      right_strut = window->screen->width - xinerama->width - xinerama->x_origin;
-      top_strut = xinerama->y_origin;
-      bottom_strut = window->screen->height - xinerama->height - xinerama->y_origin;
+      screen_width = window->screen->xinerama_infos[which_xinerama].width;
+      screen_height = window->screen->xinerama_infos[which_xinerama].height;
+      screen_origin_x = window->screen->xinerama_infos[which_xinerama].x_origin;
+      screen_origin_y = window->screen->xinerama_infos[which_xinerama].y_origin;
     }
   else
     {
-      left_strut = 0;
-      right_strut = 0;
-      top_strut = 0;
-      bottom_strut = 0;
+      screen_width = window->screen->width;
+      screen_height = window->screen->height;
+      screen_origin_x = 0;
+      screen_origin_y = 0;
     }
-      
+     
   tmp = meta_window_get_workspaces (window);
   
   while (tmp != NULL)
     {
-      meta_workspace_get_work_area (tmp->data, &space_area);
+      meta_workspace_get_work_area (tmp->data, &space_area,
+				    for_current_xinerama ? which_xinerama : -1);
 
-      left_strut = MAX (left_strut, space_area.x);
+      left_strut = MAX (left_strut, space_area.x - screen_origin_x);
       right_strut = MAX (right_strut,
-                         (window->screen->width - space_area.x - space_area.width));
-      top_strut = MAX (top_strut, space_area.y);
+			 (screen_width - 
+			  (space_area.x - screen_origin_x) - 
+			  space_area.width));
+      top_strut = MAX (top_strut, space_area.y - screen_origin_y);
       bottom_strut = MAX (bottom_strut,
-                          (window->screen->height - space_area.y - space_area.height));      
-      
+			  (screen_height - 
+			   (space_area.y - screen_origin_y) - 
+			   space_area.height));      
       tmp = tmp->next;
     }
   
-  area->x = left_strut;
-  area->y = top_strut;
-  area->width = window->screen->width - left_strut - right_strut;
-  area->height = window->screen->height - top_strut - bottom_strut;
+  area->x = screen_origin_x + left_strut;
+  area->y = screen_origin_y + top_strut;
+  area->width = screen_width - left_strut - right_strut;
+  area->height = screen_height - top_strut - bottom_strut;
 
   meta_topic (META_DEBUG_WORKAREA,
               "Window %s has work area %d,%d %d x %d\n",
               window->desc, area->x, area->y, area->width, area->height);
+}
+
+void
+meta_window_get_work_area (MetaWindow    *window,
+			   gboolean       for_current_xinerama,
+                           MetaRectangle *area)
+{
+  const MetaXineramaScreenInfo *xinerama = NULL;
+
+  if (for_current_xinerama)
+    {
+      xinerama = meta_screen_get_xinerama_for_window (window->screen,
+						      window);
+    }
+
+  meta_window_get_work_area_for_xinerama(window,
+					 for_current_xinerama,
+					 for_current_xinerama ? xinerama->number : -1,
+					 area);
 }
 
 gboolean
Index: src/window.h
===================================================================
RCS file: /cvs/gnome/metacity/src/window.h,v
retrieving revision 1.82
diff -u -p -r1.82 window.h
--- src/window.h	5 Jan 2003 07:51:02 -0000	1.82
+++ src/window.h	22 Feb 2003 02:12:36 -0000
@@ -417,6 +417,11 @@ gboolean meta_window_visible_on_workspac
 void meta_window_get_work_area (MetaWindow    *window,
                                 gboolean       for_current_xinerama,
                                 MetaRectangle *area);
+/* Get minimum work area for all workspaces, specifying a specific xinerama */
+void meta_window_get_work_area_for_xinerama (MetaWindow    *window,
+					     gboolean      for_current_xinerama,
+					     gint          which_xinerama,
+					     MetaRectangle *area);
 
 gboolean meta_window_same_application (MetaWindow *window,
                                        MetaWindow *other_window);
Index: src/workspace.c
===================================================================
RCS file: /cvs/gnome/metacity/src/workspace.c,v
retrieving revision 1.41
diff -u -p -r1.41 workspace.c
--- src/workspace.c	22 Jan 2003 04:54:04 -0000	1.41
+++ src/workspace.c	22 Feb 2003 02:12:36 -0000
@@ -42,11 +42,10 @@ meta_workspace_new (MetaScreen *screen)
     g_list_append (workspace->screen->workspaces, workspace);
   workspace->windows = NULL;
 
-  workspace->work_area.x = 0;
-  workspace->work_area.y = 0;
-  workspace->work_area.width = screen->width;
-  workspace->work_area.height = screen->height;
-  workspace->work_area_invalid = TRUE;
+  workspace->work_areas = NULL;
+  workspace->work_areas =
+    g_new(MetaRectangle, screen->n_xinerama_infos);
+  workspace->work_areas_invalid = TRUE;
   
   return workspace;
 }
@@ -84,6 +83,7 @@ meta_workspace_free (MetaWorkspace *work
   workspace->screen->workspaces =
     g_list_remove (workspace->screen->workspaces, workspace);
   
+  g_free (workspace->work_areas);
   g_free (workspace);
 
   /* don't bother to reset names, pagers can just ignore
@@ -304,7 +304,7 @@ meta_workspace_invalidate_work_area (Met
   GList *tmp;
   GList *windows;
   
-  if (workspace->work_area_invalid)
+  if (workspace->work_areas_invalid)
     {
       meta_topic (META_DEBUG_WORKAREA,
                   "Work area for workspace %d is already invalid\n",
@@ -316,7 +316,7 @@ meta_workspace_invalidate_work_area (Met
               "Invalidating work area for workspace %d\n",
               meta_workspace_index (workspace));
   
-  workspace->work_area_invalid = TRUE;
+  workspace->work_areas_invalid = TRUE;
 
   /* redo the size/position constraints on all windows */
   windows = meta_workspace_list_windows (workspace);
@@ -335,81 +335,169 @@ meta_workspace_invalidate_work_area (Met
   meta_screen_queue_workarea_recalc (workspace->screen);
 }
 
+/* this function actually computes all workareas for the workspace,
+ * which includes a work area for each xinerama and a big workarea 
+ * for functions that want the "big picture"
+*/
 void
 meta_workspace_get_work_area (MetaWorkspace *workspace,
-                              MetaRectangle *area)
+                              MetaRectangle *area,
+			      gint which_xinerama)
 {  
-  if (workspace->work_area_invalid)
+  if (workspace->work_areas_invalid)
     {
       int left_strut = 0;
       int right_strut = 0;
       int top_strut = 0;
       int bottom_strut = 0;
+      int all_left_strut = 0;
+      int all_right_strut = 0;
+      int all_top_strut = 0;
+      int all_bottom_strut = 0;
+      int i;
       GList *tmp;
       GList *windows;
-
+      
       windows = meta_workspace_list_windows (workspace);
-      tmp = windows;
-      while (tmp != NULL)
-        {
-          MetaWindow *w = tmp->data;
-
-          if (w->has_struts)
-            {
-              meta_topic (META_DEBUG_WORKAREA,
-                          "Merging win %s with %d %d %d %d with %d %d %d %d\n",
-                          w->desc,
-                          w->left_strut, w->right_strut, w->top_strut, w->bottom_strut,
-                          left_strut, right_strut, top_strut, bottom_strut);
-              left_strut = MAX (left_strut, w->left_strut);
-              right_strut = MAX (right_strut, w->right_strut);
-              top_strut = MAX (top_strut, w->top_strut);
-              bottom_strut = MAX (bottom_strut, w->bottom_strut);
-            }
-          
-          tmp = tmp->next;
-        }
 
-      g_list_free (windows);
+      for (i = 0; i < workspace->screen->n_xinerama_infos; i++)
+	{
+	  left_strut = 0;
+	  right_strut = 0;
+	  top_strut = 0;
+	  bottom_strut = 0;
+
+	  tmp = windows;
+	  while (tmp != NULL)
+	    {
+	      MetaWindow *w = tmp->data;
+
+	      if (w->has_struts && 
+		  (meta_screen_window_on_xinerama(w->screen, w, i)))
+		{
+		  meta_topic (META_DEBUG_WORKAREA,
+			      "Merging win %s with %d %d %d %d "
+			      "with %d %d %d %d\n",
+			      w->desc,
+			      w->left_strut, w->right_strut, 
+			      w->top_strut, w->bottom_strut,
+			      left_strut, right_strut, 
+			      top_strut, bottom_strut);
+		  left_strut = MAX (left_strut, 
+				    w->left_strut - 
+				    workspace->screen->
+				    xinerama_infos[i].x_origin);
+		  all_left_strut = MAX (all_left_strut, w->left_strut);
+		  right_strut = MAX (right_strut, w->right_strut);
+		  all_right_strut = MAX (all_right_strut, w->right_strut);
+		  top_strut = MAX (top_strut,
+				   w->top_strut - 
+				   workspace->screen->
+				   xinerama_infos[i].y_origin);
+		  all_top_strut = MAX (all_top_strut, w->top_strut);
+		  bottom_strut = MAX (bottom_strut, w->bottom_strut);
+		  all_bottom_strut = MAX (all_bottom_strut, w->bottom_strut);
+		}
+          
+	      tmp = tmp->next;
+	    }
 
-      /* Some paranoid robustness */
+	  /* Some paranoid robustness */
 #define MIN_SANE_AREA 100
       
-      if ((left_strut + right_strut) > (workspace->screen->width - MIN_SANE_AREA))
-        {
-          meta_topic (META_DEBUG_WORKAREA,
-                      "Making left/right struts %d %d sane\n",
-                      left_strut, right_strut);
-          left_strut = (workspace->screen->width - MIN_SANE_AREA) / 2;
-          right_strut = left_strut;
-        }
-
-      if ((top_strut + bottom_strut) > (workspace->screen->height - MIN_SANE_AREA))
-        {
-          meta_topic (META_DEBUG_WORKAREA,
-                      "Making top/bottom struts %d %d sane\n",
-                      top_strut, bottom_strut);
-          top_strut = (workspace->screen->height - MIN_SANE_AREA) / 2;
-          bottom_strut = top_strut;
-        }
+	  if ((left_strut + right_strut) > 
+	      (workspace->screen->xinerama_infos[i].width - MIN_SANE_AREA))
+	    {
+	      meta_topic (META_DEBUG_WORKAREA,
+			  "Making left/right struts %d %d sane xinerama %d\n",
+			  left_strut, right_strut, i);
+	      left_strut = (workspace->screen->xinerama_infos[i].width - 
+			    MIN_SANE_AREA) / 2;
+	      right_strut = left_strut;
+	    }
+
+	  if ((top_strut + bottom_strut) > 
+	      (workspace->screen->xinerama_infos[i].height - MIN_SANE_AREA))
+	    {
+	      meta_topic (META_DEBUG_WORKAREA,
+			  "Making top/bottom struts %d %d sane xinerama %d\n",
+			  top_strut, bottom_strut, i);
+	      top_strut = (workspace->screen->xinerama_infos[i].height - 
+			   MIN_SANE_AREA) / 2;
+	      bottom_strut = top_strut;
+	    }
       
-      workspace->work_area.x = left_strut;
-      workspace->work_area.y = top_strut;
-      workspace->work_area.width = workspace->screen->width - left_strut - right_strut;
-      workspace->work_area.height = workspace->screen->height - top_strut - bottom_strut;
+	  workspace->work_areas[i].x = 
+	    left_strut + workspace->screen->xinerama_infos[i].x_origin;
+	  workspace->work_areas[i].y = top_strut + 
+	    workspace->screen->xinerama_infos[i].y_origin;
+	  workspace->work_areas[i].width = 
+	    workspace->screen->xinerama_infos[i].width - 
+	    left_strut - right_strut;
+	  workspace->work_areas[i].height = 
+	    workspace->screen->xinerama_infos[i].height - 
+	    top_strut - bottom_strut;
+
+
+	  meta_topic (META_DEBUG_WORKAREA,
+		      "Computed work area for workspace %d "
+		      "xinerama %d: %d,%d %d x %d\n",
+		      meta_workspace_index (workspace),
+		      i,
+		      workspace->work_areas[i].x,
+		      workspace->work_areas[i].y,
+		      workspace->work_areas[i].width,
+		      workspace->work_areas[i].height);
+	}
 
-      workspace->work_area_invalid = FALSE;
+      g_list_free (windows);
+      if ((left_strut + right_strut) > 
+	  (workspace->screen->width - MIN_SANE_AREA))
+	{
+	  meta_topic (META_DEBUG_WORKAREA,
+		      "Making left/right struts %d %d sane\n",
+		      left_strut, right_strut);
+	  left_strut = (workspace->screen->width - MIN_SANE_AREA) / 2;
+	  right_strut = left_strut;
+	}
+      
+      if ((top_strut + bottom_strut) > 
+	  (workspace->screen->xinerama_infos[i].height - MIN_SANE_AREA))
+	{
+	  meta_topic (META_DEBUG_WORKAREA,
+		      "Making top/bottom struts %d %d sane\n",
+		      top_strut, bottom_strut);
+	  top_strut = (workspace->screen->height - MIN_SANE_AREA) / 2;
+	  bottom_strut = top_strut;
+	}
+      
+      workspace->all_work_areas.x = all_left_strut;
+      workspace->all_work_areas.y = all_top_strut;
+      workspace->all_work_areas.width = 
+	workspace->screen->width - all_left_strut - all_right_strut;
+      workspace->all_work_areas.height = 
+	workspace->screen->height - all_top_strut - all_bottom_strut;
+
+      workspace->work_areas_invalid = FALSE;
 
       meta_topic (META_DEBUG_WORKAREA,
-                  "Computed work area for workspace %d: %d,%d %d x %d\n",
-                  meta_workspace_index (workspace),
-                  workspace->work_area.x,
-                  workspace->work_area.y,
-                  workspace->work_area.width,
-                  workspace->work_area.height);
+		  "Computed work area for workspace %d: %d,%d %d x %d\n",
+		  meta_workspace_index (workspace),
+		  workspace->all_work_areas.x,
+		  workspace->all_work_areas.y,
+		  workspace->all_work_areas.width,
+		  workspace->all_work_areas.height);
+      
     }
 
-  *area = workspace->work_area;
+  if (which_xinerama < 0)
+    {
+      *area = workspace->all_work_areas;
+    } 
+  else 
+    {
+      *area = workspace->work_areas[which_xinerama];
+    }
 }
 
 #ifdef WITH_VERBOSE_MODE
Index: src/workspace.h
===================================================================
RCS file: /cvs/gnome/metacity/src/workspace.h,v
retrieving revision 1.13
diff -u -p -r1.13 workspace.h
--- src/workspace.h	3 Nov 2002 19:06:39 -0000	1.13
+++ src/workspace.h	22 Feb 2003 02:12:36 -0000
@@ -40,9 +40,11 @@ struct _MetaWorkspace
   MetaScreen *screen;
   
   GList *windows;
+
+  MetaRectangle all_work_areas;
   
-  MetaRectangle work_area;
-  guint work_area_invalid : 1;
+  MetaRectangle *work_areas;
+  guint work_areas_invalid : 1;
 };
 
 MetaWorkspace* meta_workspace_new           (MetaScreen    *screen);
@@ -62,7 +64,8 @@ GList*         meta_workspace_list_windo
 
 void meta_workspace_invalidate_work_area (MetaWorkspace *workspace);
 void meta_workspace_get_work_area        (MetaWorkspace *workspace,
-                                          MetaRectangle *area);
+                                          MetaRectangle *area,
+	                                  gint which_xinerama);
 
 
 MetaWorkspace* meta_workspace_get_neighbor (MetaWorkspace      *workspace,
