Index: gdk/x11/gdkimage-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkimage-x11.c,v
retrieving revision 1.36
diff -u -r1.36 gdkimage-x11.c
--- gdk/x11/gdkimage-x11.c	2001/07/23 21:28:38	1.36
+++ gdk/x11/gdkimage-x11.c	2001/07/27 15:30:05
@@ -390,40 +390,43 @@
 
   visual = gdk_drawable_get_visual (drawable);
 
-  g_assert (visual || !GDK_IS_WINDOW (drawable));
+  g_assert (visual || !GDK_IS_WINDOW_IMPL_X11 (drawable));
 
   impl = GDK_DRAWABLE_IMPL_X11 (drawable);
   
   have_grab = FALSE;
 
-  if (GDK_IS_WINDOW (drawable))
+  if (GDK_IS_WINDOW_IMPL_X11 (impl))
     {
       GdkRectangle screen_rect;
-      Window child;
+      Window dummy_w;
+      guint dummy_i;
 
       g_assert (visual);
       
       have_grab = TRUE;
       gdk_x11_grab_server ();
       
-      XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (drawable),
+      XTranslateCoordinates (impl->xdisplay,
 			     gdk_root_window,
-			     GDK_DRAWABLE_XID (drawable),
+			     impl->xid,
 			     0, 0, 
 			     &screen_rect.x, &screen_rect.y, 
-			     &child);
+			     &dummy_w);
 
       screen_rect.width = gdk_screen_width ();
       screen_rect.height = gdk_screen_height ();
       
       gdk_error_trap_push ();
       
-      gdk_window_get_geometry (GDK_WINDOW (drawable),
-                               &window_rect.x,
-                               &window_rect.y,
-                               &window_rect.width,
-                               &window_rect.height,
-                               NULL);
+      XGetGeometry (impl->xdisplay,
+		    impl->xid,
+		    &dummy_w, 
+		    &window_rect.x,
+		    &window_rect.y,
+		    &window_rect.width,
+		    &window_rect.height,
+		    &dummy_i, &dummy_i);
 
       if (gdk_error_trap_pop () ||
           !gdk_rectangle_intersect (&window_rect, &screen_rect, 
@@ -457,21 +460,24 @@
     {
       if (have_grab)
 	gdk_x11_ungrab_server ();
-      return image = gdk_image_new (GDK_IMAGE_FASTEST,
-                                    visual,
-                                    width, height);
+      return gdk_image_new (GDK_IMAGE_FASTEST,
+			    visual,
+			    width, height);
     }
 
   if (req.x != x || req.y != y)
     {
-      g_assert (GDK_IS_WINDOW (drawable));
+      g_assert (GDK_IS_WINDOW_IMPL_X11 (impl));
       g_assert (visual);
 
       image = gdk_image_new (GDK_IMAGE_FASTEST,
                              visual,
                              width, height);
-      if (image == NULL)
+      if (image == NULL) {
+	if (have_grab)
+	  gdk_x11_ungrab_server ();
         return NULL;
+      }
 
       private = PRIVATE_DATA (image);
 
@@ -497,19 +503,17 @@
     }
   else
     {
-
       ximage = XGetImage (impl->xdisplay,
                           impl->xid,
-                          x, y, width, height,
+			  req.x, req.y, req.width, req.height,
                           AllPlanes, ZPixmap);
 
-      if (!ximage)
-        {
-          if (have_grab)
-            gdk_x11_ungrab_server ();
-          return NULL;
-        }
+      if (have_grab)
+	gdk_x11_ungrab_server ();
 
+      if (!ximage)
+	return NULL;
+      
       image = g_object_new (gdk_image_get_type (), NULL);
 
       private = PRIVATE_DATA (image);
