diff --git a/src/main.C b/src/main.C
index 4b8b62d..b2dc3a5 100644
--- a/src/main.C
+++ b/src/main.C
@@ -1082,23 +1082,30 @@ rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, in
        * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
        * reposition window on resize depending on placement on screen
        */
-      int x, y, x1, y1;
+      int x, y, x1, y1, unused_x, unused_y;
       int dx, dy;
       unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
-      Window unused_cr;
+      Window unused_cr, wm_parent;
+      Window *children;
+      unsigned int num_children, border_width;

       XTranslateCoordinates (dpy, parent, display->root,
                              0, 0, &x, &y, &unused_cr);
       XGetGeometry (dpy, parent, &unused_cr, &x1, &y1,
                     &unused_w1, &unused_h1, &unused_b1, &unused_d1);
+      XQueryTree (dpy, parent, &unused_cr, &wm_parent, &children, &num_children);
+      XFree(children);
+      XGetGeometry (dpy, wm_parent, &unused_cr, &unused_x, &unused_y,
+                    &unused_w1, &unused_h1, &border_width, &unused_d1);
+
       /*
        * if display->root isn't the parent window, a WM will probably have offset
        * our position for handles and decorations.  Counter it
        */
       if (x1 != x || y1 != y)
         {
-          x -= x1;
-          y -= y1;
+          x -= x1 + border_width;
+          y -= y1 + border_width;
         }

       x1 = (DisplayWidth  (dpy, display->screen) - old_width ) / 2;
