Index: gdk/x11/gdkimage-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkimage-x11.c,v
retrieving revision 1.35
diff -u -3 -p -u -r1.35 gdkimage-x11.c
--- gdk/x11/gdkimage-x11.c	2001/06/29 01:59:00	1.35
+++ gdk/x11/gdkimage-x11.c	2001/07/20 12:20:49
@@ -382,6 +382,7 @@ _gdk_x11_get_image (GdkDrawable    *draw
   GdkDrawableImplX11 *impl;
   GdkVisual *visual;
   gboolean have_grab;
+  GdkRectangle req;
   GdkRectangle window_rect;
   XImage *ximage;
   
@@ -402,19 +403,30 @@ _gdk_x11_get_image (GdkDrawable    *draw
   impl = GDK_DRAWABLE_IMPL_X11 (drawable);
   
   have_grab = FALSE;
-  window_rect.x = x;
-  window_rect.y = y;
-  window_rect.width = width;
-  window_rect.height = height;
+
+  image = gdk_image_new (GDK_IMAGE_FASTEST,
+                         visual,
+                         width, height);
+  if (image == NULL)
+    return NULL;
+
+  private = PRIVATE_DATA (image);
+    
   if (GDK_IS_WINDOW (drawable))
     {
       GdkRectangle screen_rect;
+      Window child;
       
       have_grab = TRUE;
       gdk_x11_grab_server ();
+      
+      XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (drawable),
+			     gdk_root_window,
+			     GDK_DRAWABLE_XID (drawable),
+			     0, 0, 
+			     &screen_rect.x, &screen_rect.y, 
+			     &child);
 
-      screen_rect.x = 0;
-      screen_rect.y = 0;
       screen_rect.width = gdk_screen_width ();
       screen_rect.height = gdk_screen_height ();
       
@@ -428,31 +440,46 @@ _gdk_x11_get_image (GdkDrawable    *draw
                                NULL);
 
       if (gdk_error_trap_pop () ||
-          !gdk_rectangle_intersect (&window_rect, &screen_rect,
+          !gdk_rectangle_intersect (&window_rect, &screen_rect, 
                                     &window_rect))
         {
           gdk_x11_ungrab_server ();
-          return NULL;
+          return image;
         }
     }
-
-  image = gdk_image_new (GDK_IMAGE_FASTEST,
-                         visual,
-                         width, height);
-
-  if (image == NULL)
-    return NULL;
-
-  private = PRIVATE_DATA (image);
+  else
+    {
+      window_rect.x = 0;
+      window_rect.y = 0;
+      gdk_drawable_get_size (drawable,
+			     &window_rect.width,
+			     &window_rect.height);
+    }
+      
+  req.x = x;
+  req.y = y;
+  req.width = width;
+  req.height = height;
   
+  /* window_rect specifies the part of drawable which we can get from
+     the server in window coordinates. 
+     For pixmaps this is all of the pixmap, for windows it is just 
+     the onscreen part. */
+  if (!gdk_rectangle_intersect (&req, &window_rect, &req)) 
+    {
+      if (have_grab)
+	gdk_x11_ungrab_server ();
+      return image;
+    }
+
   gdk_error_trap_push ();
 
   ximage = XGetSubImage (impl->xdisplay,
                          impl->xid,
-                         x, y, width, height,
+                         req.x, req.y, req.width, req.height,
                          AllPlanes, ZPixmap,
                          private->ximage,
-                         x, y);
+                         req.x - x, req.y - y);
 
   if (have_grab)
     gdk_x11_ungrab_server ();
