diff --git a/panel/panel-window.c b/panel/panel-window.c
index 73f8cc968bae497e164e24b0b5176aa0bc4a55fd..b090eb7f22b887647e81cd1abdd4ced695d46331 100644
--- a/panel/panel-window.c
+++ b/panel/panel-window.c
@@ -1945,9 +1945,24 @@ panel_window_screen_layout_changed (GdkScreen   *screen,
 
       /* get the screen geometry we also use this if there is only
        * one monitor and no output is choosen, as a fast-path */
-      a.x = a.y = 0;
-      a.width = gdk_screen_get_width (screen);
-      a.height = gdk_screen_get_height (screen);
+      gdk_screen_get_monitor_geometry (screen, 0, &a);
+
+      a.width += a.x;
+      a.height += a.y;
+
+      for (n = 1; n < n_monitors; n++)
+        {
+          gdk_screen_get_monitor_geometry (screen, n, &b);
+
+          a.x = MIN (a.x, b.x);
+          a.y = MIN (a.y, b.y);
+          a.width = MAX (a.width, b.x + b.width);
+          a.height = MAX (a.height, b.y + b.height);
+        }
+
+      a.width -= a.x;
+      a.height -= a.y;
+
       panel_return_if_fail (a.width > 0 && a.height > 0);
     }
   else if (window->output_name != NULL