Index: src/window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.291
diff -p -u -r1.291 window.c
--- src/window.c	30 Jun 2003 14:49:11 -0000	1.291
+++ src/window.c	26 Jul 2003 23:58:58 -0000
@@ -5626,14 +5626,23 @@ update_move (MetaWindow  *window,
       /* Shake loose */
           
       window->shaken_loose = TRUE;
+		  
+      /* move the unmaximized window to the cursor */
+      double prop = 
+	((double)(x - window->display->grab_initial_window_pos.x)) / 
+	((double)window->display->grab_initial_window_pos.width);
+
+      window->display->grab_initial_window_pos.x = 
+	x - window->saved_rect.width * prop;
+      window->display->grab_initial_window_pos.y = y;
+
+      if (window->frame)
+	{
+	  window->display->grab_initial_window_pos.y += window->frame->child_y / 2;
+	}
 
-      /* Unmaximize at wherever the window would have moved to if it
-       * hadn't been maximized. FIXME if you grab the right side of
-       * the titlebar then on unmaximize the pointer isn't on the
-       * titlebar which is kind of odd.
-       */
-      window->saved_rect.x = new_x;
-      window->saved_rect.y = new_y;
+      window->saved_rect.x = window->display->grab_initial_window_pos.x-dx;
+      window->saved_rect.y = window->display->grab_initial_window_pos.y-dy;
           
       meta_window_unmaximize (window);
 
@@ -5645,30 +5654,28 @@ update_move (MetaWindow  *window,
   else if (window->shaken_loose || window->maximized)
     {
       const MetaXineramaScreenInfo *wxinerama;
+      MetaRectangle work_area;
       int monitor;
 
       wxinerama = meta_screen_get_xinerama_for_window (window->screen, window);
 
       for (monitor = 0; monitor < window->screen->n_xinerama_infos; monitor++)
         {
-          /* FIXME this should check near the top of the work area probably,
-           * maybe only counting full-monitor-width panels in work area
-           * for this purpose.
-           */
-          /* check if cursor is near the top of a xinerama monitor */ 
-          if (x >= window->screen->xinerama_infos[monitor].x_origin &&
-              x < (window->screen->xinerama_infos[monitor].x_origin + 
-                   window->screen->xinerama_infos[monitor].width) &&
-              y >= window->screen->xinerama_infos[monitor].y_origin &&
-              y < (window->screen->xinerama_infos[monitor].y_origin + shake_threshold))
+	  meta_window_get_work_area_for_xinerama (window, monitor, &work_area);
+
+          /* check if cursor is near the top of a xinerama work area */ 
+          if (x >= work_area.x &&
+              x < (work_area.x + work_area.width) &&
+	      y >= work_area.y &&
+	      y < (work_area.y + shake_threshold))
             {
               /* move the saved rect if window will become maximized on an
                * other monitor so user isn't surprised on a later unmaximize
                */
               if (wxinerama->number != monitor)
                 {
-                  window->saved_rect.x = window->screen->xinerama_infos[monitor].x_origin;
-                  window->saved_rect.y = window->screen->xinerama_infos[monitor].y_origin;
+                  window->saved_rect.x = work_area.x;
+		  window->saved_rect.y = work_area.y;
                   
                   if (window->frame) 
                     {
@@ -5679,11 +5686,12 @@ update_move (MetaWindow  *window,
                   meta_window_unmaximize (window);
                 }
 
-              window->shaken_loose = FALSE;
-
-              meta_window_maximize (window);
+	      window->display->grab_initial_window_pos = work_area;
+	      window->shaken_loose = FALSE;
+	      
+	      meta_window_maximize (window);
 
-              return;
+	      return;
             }
         }
     }
