Index: metacity/metacity-2.14.5/src/display.c
===================================================================
--- metacity.orig/metacity-2.14.5/src/display.c	2006-06-10 23:41:41.000000000 +0100
+++ metacity/metacity-2.14.5/src/display.c	2006-10-24 23:12:44.000000000 +0100
@@ -1334,81 +1334,36 @@
   return meta_ui_get_double_click_timeout (screen->ui);
 }                                
 
-#if 0
-static void
-handle_net_moveresize_window (MetaDisplay* display,
-                              XEvent *event)
+void
+handle_net_moveresize_window (MetaDisplay *display,
+                              XEvent      *event)
 {
   MetaWindow *window;
-  int x, y, width, height;
-  gboolean only_resize;
-  unsigned int gravity;
-  unsigned int mode;
+  int gravity;
+  MetaClientType source;
+  guint value_mask;
 
   window = meta_display_lookup_x_window (display,
                                          event->xclient.window);
+  if (!window)
+    return;
 
-  /*
-   * FIXME: The specification seems to have serious endian issues
-   * here.  Does bits 8-11 mean the high-order byte, or the low-order
-   * byte?
-   */
-  gravity = (event->xclient.data.l[0] & ~0xff);
-  mode = (event->xclient.data.l[0] & ~0xff00) >> 8;
-
-  if (window)
-    {
-      /* FIXME!!!!  This function is _wrong_ except for the resize-only
-       * case.  Even then, it sucks to special case the code instead of
-       * factoring out common functionality with the configure reqest
-       * handling, especially since the EWMH says this message should be
-       * treated identically to a configure request with the exception of
-       * having a special gravity specified.
-       */
-      meta_window_get_gravity_position (window, &x, &y);
-      width = window->rect.width;
-      height = window->rect.height;
-
-      if (mode & (CWX | CWY))
-        only_resize = FALSE;
-      else
-        only_resize = TRUE;
-
-      if (mode & CWX)
-        x = event->xclient.data.l[1];
-      if (mode & CWY)
-        y = event->xclient.data.l[2];
-      if (mode & CWWidth)
-        width = event->xclient.data.l[3];
-      if (mode & CWHeight)
-        height = event->xclient.data.l[4];
-
-      if (only_resize)
-        {
-          if (gravity)
-	    meta_window_resize_with_gravity (window,
-					     FALSE,
-					     width,
-					     height,
-					     gravity);
-          else
-            meta_window_resize (window,
-				FALSE,
-				width,
-				height);
-        }
-      else
-        {
-          meta_window_move_resize (window,
-                                   FALSE,
-                                   x,
-                                   y,
-                                   width,
-                                   height);
-        }
-    }
+  gravity = (event->xclient.data.l[0] & 0xff);
+  if (0 == gravity)
+    gravity = window->size_hints.win_gravity;
+  value_mask = (event->xclient.data.l[0] & 0xf00) >> 8;
+  source = (event->xclient.data.l[0] & 0xf000) >> 12;
+
+  meta_window_move_resize_request(window,
+                                  value_mask,
+                                  gravity,
+                                  event->xclient.data.l[1],  // x
+                                  event->xclient.data.l[2],  // y
+                                  event->xclient.data.l[3],  // width
+                                  event->xclient.data.l[4]); // height
 }
 
+#if 0
 static void
 handle_net_restack_window (MetaDisplay* display,
                            XEvent *event)
@@ -2191,7 +2146,6 @@
             group == NULL) /* window/group != NULL means it wasn't a root window */
           screen = meta_display_screen_for_root (display,
                                                  event->xproperty.window);
-            
         if (screen != NULL)
           {
             if (event->xproperty.atom ==
@@ -2200,14 +2154,6 @@
             else if (event->xproperty.atom ==
                      display->atom_net_desktop_names)
               meta_screen_update_workspace_names (screen);
-#if 0
-            else if (event->xproperty.atom ==
-                     display->atom_net_restack_window)
-              handle_net_restack_window (display, event);
-            else if (event->xproperty.atom ==
-                     display->atom_net_moveresize_window)
-              handle_net_moveresize_window (display, event);
-#endif
 
             /* we just use this property as a sentinel to avoid
              * certain race conditions.  See the comment for the
Index: metacity/metacity-2.14.5/src/window.c
===================================================================
--- metacity.orig/metacity-2.14.5/src/window.c	2006-06-19 23:09:31.000000000 +0100
+++ metacity/metacity-2.14.5/src/window.c	2006-10-24 23:11:39.000000000 +0100
@@ -2802,7 +2802,7 @@
               is_configure_request ? " (configure request)" : "",
               is_user_action ? " (user move/resize)" : "",
               old_rect.x, old_rect.y, old_rect.width, old_rect.height);
-  
+
   if (window->frame)
     meta_frame_calc_geometry (window->frame,
                               &fgeom);
@@ -2845,13 +2845,13 @@
                   "weird positioning; new pos %d,%d\n",
                   new_rect.x, new_rect.y);
     }
-
-  meta_window_constrain (window,
-                         window->frame ? &fgeom : NULL,
-                         flags,
-                         resize_gravity,
-                         &old_rect,
-                         &new_rect);
+  else
+    meta_window_constrain (window,
+                           window->frame ? &fgeom : NULL,
+                           flags,
+                           resize_gravity,
+                           &old_rect,
+                           &new_rect);
 
   w = new_rect.width;
   h = new_rect.height;
@@ -3395,6 +3395,7 @@
 
 void
 meta_window_get_gravity_position (MetaWindow  *window,
+                                  int          gravity,
                                   int         *root_x,
                                   int         *root_y)
 {
@@ -3405,7 +3406,7 @@
   w = window->rect.width;
   h = window->rect.height;
 
-  if (window->size_hints.win_gravity == StaticGravity)
+  if (gravity == StaticGravity)
     {
       frame_extents = window->rect;
       if (window->frame)
@@ -3425,7 +3426,7 @@
   x = frame_extents.x;
   y = frame_extents.y;
   
-  switch (window->size_hints.win_gravity)
+  switch (gravity)
     {
     case NorthGravity:
     case CenterGravity:
@@ -3448,7 +3449,7 @@
       break;
     }
   
-  switch (window->size_hints.win_gravity)
+  switch (gravity)
     {
     case WestGravity:
     case CenterGravity:
@@ -3483,7 +3484,9 @@
                           int         *width,
                           int         *height)
 {
-  meta_window_get_gravity_position (window, x, y);
+  meta_window_get_gravity_position (window,
+                                    window->size_hints.win_gravity,
+                                    x, y);
 
   *width = (window->rect.width - window->size_hints.base_width) /
     window->size_hints.width_inc;
@@ -4092,9 +4095,14 @@
     meta_error_trap_pop (window->display, FALSE);
 }
 
-gboolean
-meta_window_configure_request (MetaWindow *window,
-                               XEvent     *event)
+void
+meta_window_move_resize_request(MetaWindow *window,
+                                guint       value_mask,
+                                guint       new_gravity,
+                                gint        new_x,
+                                gint        new_y,
+                                gint        new_width,
+                                gint        new_height)
 {
   int x, y, width, height;
   gboolean only_resize;
@@ -4140,8 +4148,9 @@
    * server-side position in effect when the configure request was
    * generated.
    */
-
-  meta_window_get_gravity_position (window, &x, &y);
+  meta_window_get_gravity_position (window,
+                                    new_gravity,
+                                    &x, &y);
 
   only_resize = TRUE;
 
@@ -4152,14 +4161,18 @@
       if (window->type == META_WINDOW_DIALOG ||
           window->type == META_WINDOW_MODAL_DIALOG ||
           window->type == META_WINDOW_SPLASHSCREEN)
-        ; /* No position change for these */
+        {
+          ; /* No position change for these */
+        }
       else if ((window->size_hints.flags & PPosition) ||
                /* USPosition is just stale if window is placed;
                 * no --geometry involved here.
                 */
                ((window->size_hints.flags & USPosition) &&
                 !window->placed))
-        allow_position_change = TRUE;
+        {
+          allow_position_change = TRUE;
+        }
     }
   else
     {
@@ -4171,13 +4184,11 @@
   
   if (allow_position_change)
     {
-      if (event->xconfigurerequest.value_mask & CWX)
-        x = event->xconfigurerequest.x;
-      
-      if (event->xconfigurerequest.value_mask & CWY)
-        y = event->xconfigurerequest.y;
-
-      if (event->xconfigurerequest.value_mask & (CWX | CWY))
+      if (value_mask & CWX)
+        x = new_x;
+      if (value_mask & CWY)
+        y = new_y;
+      if (value_mask & (CWX | CWY))
         {
           only_resize = FALSE;
 
@@ -4198,31 +4209,20 @@
 
   width = window->rect.width;
   height = window->rect.height;
-
   if (!in_grab_op)
     {
-      if (event->xconfigurerequest.value_mask & CWWidth)
-        width = event->xconfigurerequest.width;
+      if (value_mask & CWWidth)
+        width = new_width;
       
-      if (event->xconfigurerequest.value_mask & CWHeight)
-        height = event->xconfigurerequest.height;
+      if (value_mask & CWHeight)
+        height = new_height;
     }
 
   /* ICCCM 4.1.5 */
   
-  /* Note that x, y is the corner of the window border,
-   * and width, height is the size of the window inside
-   * its border, but that we always deny border requests
-   * and give windows a border of 0. But we save the
-   * requested border here.
-   */
-  if (event->xconfigurerequest.value_mask & CWBorderWidth)
-    window->border_width = event->xconfigurerequest.border_width;
-
   /* We're ignoring the value_mask here, since sizes
    * not in the mask will be the current window geometry.
    */
-  
   window->size_hints.x = x;
   window->size_hints.y = y;
   window->size_hints.width = width;
@@ -4239,21 +4239,45 @@
    * setup requires the only_resize thing.  Yeah, it'd be much better to
    * have a different setup for meta_window_move_resize_internal()...
    */
-  
   flags = META_IS_CONFIGURE_REQUEST;
-  if (event->xconfigurerequest.value_mask & (CWX | CWY))
+  if (value_mask & (CWX | CWY))
     flags |= META_IS_MOVE_ACTION;
-  if (event->xconfigurerequest.value_mask & (CWWidth | CWHeight))
+  if (value_mask & (CWWidth | CWHeight))
     flags |= META_IS_RESIZE_ACTION;
 
   if (flags & (META_IS_MOVE_ACTION | META_IS_RESIZE_ACTION))
-    meta_window_move_resize_internal (window, 
-                                      flags,
-                                      window->size_hints.win_gravity,
-                                      window->size_hints.x,
-                                      window->size_hints.y,
-                                      window->size_hints.width,
-                                      window->size_hints.height);
+    {
+      meta_window_move_resize_internal (window,
+                                        flags,
+                                        new_gravity,
+                                        window->size_hints.x,
+                                        window->size_hints.y,
+                                        window->size_hints.width,
+                                        window->size_hints.height);
+    }
+}
+
+gboolean
+meta_window_configure_request (MetaWindow *window,
+                               XEvent     *event)
+{
+  /* Note that x, y is the corner of the window border,
+   * and width, height is the size of the window inside
+   * its border, but that we always deny border requests
+   * and give windows a border of 0. But we save the
+   * requested border here.
+   */
+  if (event->xconfigurerequest.value_mask & CWBorderWidth)
+    window->border_width = event->xconfigurerequest.border_width;
+
+
+  meta_window_move_resize_request(window,
+                                  event->xconfigurerequest.value_mask,
+                                  window->size_hints.win_gravity,
+                                  event->xconfigurerequest.x,
+                                  event->xconfigurerequest.y,
+                                  event->xconfigurerequest.width,
+                                  event->xconfigurerequest.height);
 
   /* Handle stacking. We only handle raises/lowers, mostly because
    * stack.c really can't deal with anything else.  I guess we'll fix
@@ -4726,6 +4750,14 @@
       window_activate (window, timestamp, source_indication);
       return TRUE;
     }
+  else if (event->xclient.message_type ==
+           display->atom_net_moveresize_window)
+    handle_net_moveresize_window (display, event);
+#if 0
+  else if (event->xclient.message_type ==
+           display->atom_net_restack_window)
+    handle_net_restack_window (display, event);
+#endif
   
   return FALSE;
 }
Index: metacity/metacity-2.14.5/src/window.h
===================================================================
--- metacity.orig/metacity-2.14.5/src/window.h	2006-06-19 23:09:44.000000000 +0100
+++ metacity/metacity-2.14.5/src/window.h	2006-10-09 23:06:48.000000000 +0100
@@ -451,6 +451,7 @@
  * request.
  */
 void        meta_window_get_gravity_position (MetaWindow  *window,
+                                              int          gravity,
                                               int         *x,
                                               int         *y);
 /* Get geometry for saving in the session; x/y are gravity
@@ -490,6 +491,13 @@
                                      Time        timestamp);
 
 
+void     meta_window_move_resize_request(MetaWindow *window,
+                                         guint flags,
+                                         guint new_gravity,
+                                         gint new_x,
+                                         gint new_y,
+                                         gint new_width,
+                                         gint new_height);
 gboolean meta_window_configure_request (MetaWindow *window,
                                         XEvent     *event);
 gboolean meta_window_property_notify   (MetaWindow *window,
Index: metacity/metacity-2.14.5/src/screen.c
===================================================================
--- metacity.orig/metacity-2.14.5/src/screen.c	2006-07-07 23:10:26.000000000 +0100
+++ metacity/metacity-2.14.5/src/screen.c	2006-10-09 22:48:12.000000000 +0100
@@ -86,7 +86,7 @@
 static int
 set_supported_hint (MetaScreen *screen)
 {
-#define N_SUPPORTED 58
+#define N_SUPPORTED 59
   Atom atoms[N_SUPPORTED];
   
   atoms[0] = screen->display->atom_net_wm_name;
@@ -147,9 +147,9 @@
   atoms[55] = screen->display->atom_net_wm_state_demands_attention;
   atoms[56] = screen->display->atom_net_desktop_geometry;
   atoms[57] = screen->display->atom_net_desktop_viewport;
-  //atoms[58] = screen->display->atom_net_restack_window;
-  //atoms[59] = screen->display->atom_net_moveresize_window;
-  
+  atoms[58] = screen->display->atom_net_moveresize_window;
+  //atoms[59] = screen->display->atom_net_restack_window;
+
   XChangeProperty (screen->display->xdisplay, screen->xroot,
                    screen->display->atom_net_supported,
                    XA_ATOM,
Index: metacity/metacity-2.14.5/src/display.h
===================================================================
--- metacity.orig/metacity-2.14.5/src/display.h	2006-10-09 23:02:25.000000000 +0100
+++ metacity/metacity-2.14.5/src/display.h	2006-10-09 23:03:57.000000000 +0100
@@ -566,4 +566,7 @@
                                              MetaWindow  *window);
 void meta_display_remove_autoraise_callback (MetaDisplay *display);
 
+void handle_net_moveresize_window(MetaDisplay *display,
+                                  XEvent      *event);
+
 #endif
