]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkwindow.c
gdk/win32/gdkpixmap-win32.c (gdk_pixmap_new, gdk_bitmap_create_from_data,
[~andy/gtk] / gdk / gdkwindow.c
index e166165140e011eefbeaa9529eb3f33b21df4b8f..4687626121123fd8cdb6f95eb115baf700d8a8ed 100644 (file)
@@ -30,6 +30,7 @@
 #include "gdkpixmap.h"
 #include "gdkdrawable.h"
 #include "gdkpixmap.h"
+#include "gdkscreen.h"
 
 #define USE_BACKING_STORE      /* Appears to work on Win32, too, now. */
 
@@ -43,26 +44,19 @@ struct _GdkWindowPaint
   gint y_offset;
 };
 
-static const GdkPointerHooks default_pointer_hooks = {
-  _gdk_windowing_window_get_pointer,
-  _gdk_windowing_window_at_pointer
-};
-
-static const GdkPointerHooks *current_pointer_hooks = &default_pointer_hooks;
-
 static GdkGC *gdk_window_create_gc      (GdkDrawable     *drawable,
                                          GdkGCValues     *values,
                                          GdkGCValuesMask  mask);
 static void   gdk_window_draw_rectangle (GdkDrawable     *drawable,
                                          GdkGC           *gc,
-                                         gint             filled,
+                                         gboolean         filled,
                                          gint             x,
                                          gint             y,
                                          gint             width,
                                          gint             height);
 static void   gdk_window_draw_arc       (GdkDrawable     *drawable,
                                          GdkGC           *gc,
-                                         gint             filled,
+                                         gboolean         filled,
                                          gint             x,
                                          gint             y,
                                          gint             width,
@@ -71,7 +65,7 @@ static void   gdk_window_draw_arc       (GdkDrawable     *drawable,
                                          gint             angle2);
 static void   gdk_window_draw_polygon   (GdkDrawable     *drawable,
                                          GdkGC           *gc,
-                                         gint             filled,
+                                         gboolean         filled,
                                          GdkPoint        *points,
                                          gint             npoints);
 static void   gdk_window_draw_text      (GdkDrawable     *drawable,
@@ -126,12 +120,27 @@ static void   gdk_window_draw_image     (GdkDrawable     *drawable,
                                          gint             width,
                                          gint             height);
 
-static GdkImage*  gdk_window_get_image  (GdkDrawable     *drawable,
-                                         gint             x,
-                                         gint             y,
-                                         gint             width,
-                                         gint             height);
-
+static void gdk_window_draw_pixbuf (GdkDrawable     *drawable,
+                                   GdkGC           *gc,
+                                   GdkPixbuf       *pixbuf,
+                                   gint             src_x,
+                                   gint             src_y,
+                                   gint             dest_x,
+                                   gint             dest_y,
+                                   gint             width,
+                                   gint             height,
+                                   GdkRgbDither     dither,
+                                   gint             x_dither,
+                                   gint             y_dither);
+
+static GdkImage* gdk_window_copy_to_image (GdkDrawable *drawable,
+                                          GdkImage    *image,
+                                          gint         src_x,
+                                          gint         src_y,
+                                          gint         dest_x,
+                                          gint         dest_y,
+                                          gint         width,
+                                          gint         height);
 
 static void   gdk_window_real_get_size  (GdkDrawable     *drawable,
                                          gint            *width,
@@ -139,8 +148,9 @@ static void   gdk_window_real_get_size  (GdkDrawable     *drawable,
 
 static GdkVisual*   gdk_window_real_get_visual   (GdkDrawable *drawable);
 static gint         gdk_window_real_get_depth    (GdkDrawable *drawable);
+static GdkScreen*   gdk_window_real_get_screen   (GdkDrawable *drawable);
 static void         gdk_window_real_set_colormap (GdkDrawable *drawable,
-                                             GdkColormap *cmap);
+                                                 GdkColormap *cmap);
 static GdkColormap* gdk_window_real_get_colormap (GdkDrawable *drawable);
 
 static GdkDrawable* gdk_window_get_composite_drawable (GdkDrawable *drawable,
@@ -223,12 +233,14 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
   drawable_class->draw_lines = gdk_window_draw_lines;
   drawable_class->draw_glyphs = gdk_window_draw_glyphs;
   drawable_class->draw_image = gdk_window_draw_image;
+  drawable_class->draw_pixbuf = gdk_window_draw_pixbuf;
   drawable_class->get_depth = gdk_window_real_get_depth;
+  drawable_class->get_screen = gdk_window_real_get_screen;
   drawable_class->get_size = gdk_window_real_get_size;
   drawable_class->set_colormap = gdk_window_real_set_colormap;
   drawable_class->get_colormap = gdk_window_real_get_colormap;
   drawable_class->get_visual = gdk_window_real_get_visual;
-  drawable_class->get_image = gdk_window_get_image;
+  drawable_class->_copy_to_image = gdk_window_copy_to_image;
   drawable_class->get_clip_region = gdk_window_get_clip_region;
   drawable_class->get_visible_region = gdk_window_get_visible_region;
   drawable_class->get_composite_drawable = gdk_window_get_composite_drawable;
@@ -254,7 +266,7 @@ gdk_window_finalize (GObject *object)
        _gdk_window_destroy (window, TRUE);
     }
 
-  g_object_unref (G_OBJECT (obj->impl));
+  g_object_unref (obj->impl);
   obj->impl = NULL;
   
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -264,17 +276,17 @@ gdk_window_finalize (GObject *object)
  * _gdk_window_destroy_hierarchy:
  * @window: a #GdkWindow
  * @recursing: If TRUE, then this is being called because a parent
- *            was destroyed. This generally means that the call to the windowing system
- *            to destroy the window can be omitted, since it will be destroyed as a result
- *            of the parent being destroyed. Unless @foreign_destroy
- *            
- * foreign_destroy: If TRUE, the window or a parent was destroyed by some external 
- *            agency. The window has already been destroyed and no windowing
- *            system calls should be made. (This may never happen for some
- *            windowing systems.)
+ *            was destroyed. This generally means that the call to the 
+ *            windowing system to destroy the window can be omitted, since
+ *            it will be destroyed as a result of the parent being destroyed.
+ *            Unless @foreign_destroy.           
+ * @foreign_destroy: If TRUE, the window or a parent was destroyed by some 
+ *            external agency. The window has already been destroyed and no 
+ *            windowing system calls should be made. (This may never happen
+ *            for some windowing systems.)
  *
- * Internal function to destroy a window. Like gdk_window_destroy(), but does not
- * drop the reference count created by gdk_window_new().
+ * Internal function to destroy a window. Like gdk_window_destroy(),
+ * but does not drop the reference count created by gdk_window_new().
  **/
 static void
 _gdk_window_destroy_hierarchy (GdkWindow *window,
@@ -316,7 +328,7 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
               private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
               private->bg_pixmap != GDK_NO_BG)
            {
-             gdk_pixmap_unref (private->bg_pixmap);
+             g_object_unref (private->bg_pixmap);
              private->bg_pixmap = NULL;
            }
          
@@ -334,7 +346,8 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
                  
                  temp_private = (GdkWindowObject*) temp_window;
                  if (temp_private)
-                   _gdk_window_destroy_hierarchy (temp_window, TRUE, foreign_destroy);
+                   _gdk_window_destroy_hierarchy (temp_window,
+                                                   TRUE, foreign_destroy);
                }
              
              g_list_free (children);
@@ -370,13 +383,13 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
 /**
  * _gdk_window_destroy:
  * @window: a #GdkWindow
- * foreign_destroy: If TRUE, the window or a parent was destroyed by some external 
- *            agency. The window has already been destroyed and no windowing
- *            system calls should be made. (This may never happen for some
- *            windowing systems.)
+ * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
+ *            external agency. The window has already been destroyed and no
+ *            windowing system calls should be made. (This may never happen
+ *            for some windowing systems.)
  *
- * Internal function to destroy a window. Like gdk_window_destroy(), but does not
- * drop the reference count created by gdk_window_new().
+ * Internal function to destroy a window. Like gdk_window_destroy(),
+ * but does not drop the reference count created by gdk_window_new().
  **/
 void
 _gdk_window_destroy (GdkWindow *window,
@@ -389,19 +402,19 @@ _gdk_window_destroy (GdkWindow *window,
  * gdk_window_destroy:
  * @window: a #GdkWindow
  *
- * Destroys @window (destroys the server-side resource associated with @window).
- * Memory allocated for @window may not be freed until all references
- * to @window are dropped. All children of @window are also destroyed.
+ * Destroys the window system resources associated with @window and decrements @window's
+ * reference count. The window system resources for all children of @window are also
+ * destroyed, but the children's reference counts are not decremented.
+ *
+ * Note that a window will not be destroyed automatically when its reference count
+ * reaches zero. You must call this function yourself before that happens.
  *
- * There's normally no need to use this function, window are automatically
- * destroyed when their reference count reaches 0.
- * 
  **/
 void
 gdk_window_destroy (GdkWindow *window)
 {
   _gdk_window_destroy_hierarchy (window, FALSE, FALSE);
-  gdk_drawable_unref (window);
+  g_object_unref (window);
 }
 
 /**
@@ -467,10 +480,11 @@ gdk_window_get_window_type (GdkWindow *window)
  * @x: X coordinate of window
  * @y: Y coordinate of window
  *
- * Obtains the position of the window as reported in the most-recently-processed
- * #GdkEventConfigure. Contrast with gdk_window_get_geometry() which
- * queries the X server for the current window position, regardless of which
- * events have been received or processed.
+ * Obtains the position of the window as reported in the
+ * most-recently-processed #GdkEventConfigure. Contrast with
+ * gdk_window_get_geometry() which queries the X server for the
+ * current window position, regardless of which events have been
+ * received or processed.
  *
  * The position coordinates are relative to the window's parent window.
  * 
@@ -587,8 +601,10 @@ gdk_window_peek_children (GdkWindow *window)
  * @data: data to pass to filter callback
  *
  * Adds an event filter to @window, allowing you to intercept events
- * before they reach GDK. This is a low-level operation and makes it easy to break
- * GDK and/or GTK+, so you have to know what you're doing.
+ * before they reach GDK. This is a low-level operation and makes it
+ * easy to break GDK and/or GTK+, so you have to know what you're
+ * doing. Pass %NULL for @window to get all events for all windows,
+ * instead of events for a specific window.
  * 
  **/
 void          
@@ -677,9 +693,10 @@ gdk_window_remove_filter (GdkWindow     *window,
 }
 
 /**
- * gdk_window_get_toplevels:
+ * gdk_screen_get_toplevel_windows:
+ * @screen: The #GdkScreen where the toplevels are located.
  * 
- * Obtains a list of all toplevel windows known to GDK.
+ * Obtains a list of all toplevel windows known to GDK on the screen @screen.
  * A toplevel window is a child of the root window (see
  * gdk_get_default_root_window()).
  *
@@ -687,14 +704,21 @@ gdk_window_remove_filter (GdkWindow     *window,
  * its elements need not be freed.
  * 
  * Return value: list of toplevel windows, free with g_list_free()
+ *
+ * Since: 2.2
  **/
 GList *
-gdk_window_get_toplevels (void)
+gdk_screen_get_toplevel_windows (GdkScreen *screen)
 {
+  GdkWindow * root_window;
   GList *new_list = NULL;
   GList *tmp_list;
   
-  tmp_list = ((GdkWindowObject *)_gdk_parent_root)->children;
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
+  
+  root_window = gdk_screen_get_root_window (screen);
+
+  tmp_list = ((GdkWindowObject *)root_window)->children;
   while (tmp_list)
     {
       if (GDK_WINDOW_TYPE (tmp_list->data) != GDK_WINDOW_FOREIGN)
@@ -705,6 +729,25 @@ gdk_window_get_toplevels (void)
   return new_list;
 }
 
+/**
+ * gdk_window_get_toplevels:
+ * 
+ * Obtains a list of all toplevel windows known to GDK on the default
+ * screen (see gdk_window_get_toplevels_for_screen()).
+ * A toplevel window is a child of the root window (see
+ * gdk_get_default_root_window()).
+ *
+ * The returned list should be freed with g_list_free(), but
+ * its elements need not be freed.
+ * 
+ * Return value: list of toplevel windows, free with g_list_free()
+ **/
+GList *
+gdk_window_get_toplevels (void)
+{
+  return gdk_screen_get_toplevel_windows (gdk_screen_get_default ());
+}
+
 /**
  * gdk_window_is_visible:
  * @window: a #GdkWindow
@@ -729,22 +772,22 @@ gdk_window_is_visible (GdkWindow *window)
  * Check if the window and all ancestors of the window are
  * mapped. (This is not necessarily "viewable" in the X sense, since
  * we only check as far as we have GDK window parents, not to the root
- * window)
- * 
- * 
- * 
+ * window.)
+ *
  * Return value: %TRUE if the window is viewable
  **/
 gboolean 
 gdk_window_is_viewable (GdkWindow *window)
 {
   GdkWindowObject *private = (GdkWindowObject *)window;
+  GdkScreen *screen = gdk_drawable_get_screen (window);
+  GdkWindow *root_window = gdk_screen_get_root_window (screen);
   
   g_return_val_if_fail (window != NULL, FALSE);
   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
   
   while (private && 
-        (private != (GdkWindowObject *)_gdk_parent_root) &&
+        (private != (GdkWindowObject *)root_window) &&
         (GDK_WINDOW_TYPE (private) != GDK_WINDOW_FOREIGN))
     {
       if (!GDK_WINDOW_IS_MAPPED (window))
@@ -815,14 +858,17 @@ gdk_window_get_bg_gc (GdkWindow *window, GdkWindowPaint *paint)
       
       return gdk_window_get_bg_gc (GDK_WINDOW (private->parent), &tmp_paint);
     }
-  else if (private->bg_pixmap && private->bg_pixmap != GDK_PARENT_RELATIVE_BG && private->bg_pixmap != GDK_NO_BG)
+  else if (private->bg_pixmap && 
+           private->bg_pixmap != GDK_PARENT_RELATIVE_BG && 
+           private->bg_pixmap != GDK_NO_BG)
     {
       gc_values.fill = GDK_TILED;
       gc_values.tile = private->bg_pixmap;
       gc_values.ts_x_origin = - paint->x_offset;
       gc_values.ts_y_origin = - paint->y_offset;
       
-      gc_mask = GDK_GC_FILL | GDK_GC_TILE | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN;
+      gc_mask = (GDK_GC_FILL | GDK_GC_TILE | 
+                 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
     }
   else
     {
@@ -848,7 +894,7 @@ gdk_window_paint_init_bg (GdkWindow      *window,
   gdk_gc_set_clip_region (tmp_gc, init_region);
 
   gdk_draw_rectangle (paint->pixmap, tmp_gc, TRUE, 0, 0, -1, -1);
-  gdk_gc_unref (tmp_gc);
+  g_object_unref (tmp_gc);
 }
 
 #ifdef GDK_WINDOWING_X11
@@ -948,8 +994,8 @@ gdk_window_begin_paint_region (GdkWindow *window,
                             0, 0,
                             old_rect.x - new_rect.x, old_rect.y - new_rect.y,
                              old_rect.width, old_rect.height);
-          gdk_gc_unref (tmp_gc);
-         gdk_drawable_unref (tmp_paint->pixmap);
+          g_object_unref (tmp_gc);
+         g_object_unref (tmp_paint->pixmap);
 
          paint->x_offset = new_rect.x;
          paint->y_offset = new_rect.y;
@@ -987,7 +1033,8 @@ gdk_window_begin_paint_region (GdkWindow *window,
     {
       paint->x_offset = clip_box.x;
       paint->y_offset = clip_box.y;
-      paint->pixmap = gdk_pixmap_new (window, clip_box.width, clip_box.height, -1);
+      paint->pixmap = gdk_pixmap_new (window, 
+                                      clip_box.width, clip_box.height, -1);
     }
 
   if (!gdk_region_empty (init_region))
@@ -1035,7 +1082,8 @@ gdk_window_end_paint (GdkWindow *window)
     }
 
   paint = private->paint_stack->data;
-  private->paint_stack = g_slist_delete_link (private->paint_stack, private->paint_stack);
+  private->paint_stack = g_slist_delete_link (private->paint_stack, 
+                                              private->paint_stack);
 
   gdk_region_get_clipbox (paint->region, &clip_box);
 
@@ -1051,7 +1099,7 @@ gdk_window_end_paint (GdkWindow *window)
                      clip_box.y - paint->y_offset,
                      clip_box.x - x_offset, clip_box.y - y_offset,
                      clip_box.width, clip_box.height);
-  gdk_gc_unref (tmp_gc);
+  g_object_unref (tmp_gc);
 
   if (private->paint_stack)
     {
@@ -1065,7 +1113,7 @@ gdk_window_end_paint (GdkWindow *window)
        }
     }
   else
-    gdk_drawable_unref (paint->pixmap);
+    g_object_unref (paint->pixmap);
 
   gdk_region_destroy (paint->region);
   g_free (paint);
@@ -1086,7 +1134,7 @@ gdk_window_free_paint_stack (GdkWindow *window)
          GdkWindowPaint *paint = tmp_list->data;
 
          if (tmp_list == private->paint_stack)
-           gdk_drawable_unref (paint->pixmap);
+           g_object_unref (paint->pixmap);
                  
          gdk_region_destroy (paint->region);
          g_free (paint);
@@ -1119,11 +1167,14 @@ gdk_window_get_offsets (GdkWindow *window,
 /**
  * gdk_window_get_internal_paint_info:
  * @window: a #GdkWindow
- * @real_drawable: location to store the drawable to which drawing should be done.
- * @x_offset: location to store the X offset between coordinates in @window, and
- *            the underlying window system primitive coordinates for *@real_drawable.
- * @y_offset: location to store the Y offset between coordinates in @window, and
- *            the underlying window system primitive coordinates for *@real_drawable.
+ * @real_drawable: location to store the drawable to which drawing should be 
+ *            done.
+ * @x_offset: location to store the X offset between coordinates in @window,
+ *            and the underlying window system primitive coordinates for 
+ *            *@real_drawable.
+ * @y_offset: location to store the Y offset between coordinates in @window,
+ *            and the underlying window system primitive coordinates for
+ *            *@real_drawable.
  * 
  * If you bypass the GDK layer and use windowing system primitives to
  * draw directly onto a #GdkWindow, then you need to deal with two
@@ -1208,7 +1259,7 @@ gdk_window_create_gc (GdkDrawable     *drawable,
 static void
 gdk_window_draw_rectangle (GdkDrawable *drawable,
                           GdkGC       *gc,
-                          gint         filled,
+                          gboolean     filled,
                           gint         x,
                           gint         y,
                           gint         width,
@@ -1236,7 +1287,7 @@ gdk_window_draw_rectangle (GdkDrawable *drawable,
 static void
 gdk_window_draw_arc (GdkDrawable *drawable,
                     GdkGC       *gc,
-                    gint         filled,
+                    gboolean     filled,
                     gint         x,
                     gint         y,
                     gint         width,
@@ -1267,7 +1318,7 @@ gdk_window_draw_arc (GdkDrawable *drawable,
 static void
 gdk_window_draw_polygon (GdkDrawable *drawable,
                         GdkGC       *gc,
-                        gint         filled,
+                        gboolean     filled,
                         GdkPoint    *points,
                         gint         npoints)
 {
@@ -1393,7 +1444,7 @@ gdk_window_get_composite_drawable (GdkDrawable *window,
                                          composite_x_offset,
                                          composite_y_offset);
       
-      return GDK_DRAWABLE (g_object_ref (G_OBJECT (window)));
+      return g_object_ref (window);
     }
   
   buffered_region = NULL;
@@ -1443,7 +1494,7 @@ gdk_window_get_composite_drawable (GdkDrawable *window,
                                          composite_x_offset,
                                          composite_y_offset);
 
-      return GDK_DRAWABLE (g_object_ref (G_OBJECT (window)));
+      return g_object_ref (window);
     }
   
   tmp_pixmap = gdk_pixmap_new (window,
@@ -1492,7 +1543,7 @@ gdk_window_get_composite_drawable (GdkDrawable *window,
   *composite_x_offset = x;
   *composite_y_offset = y;
 
-  g_object_unref (G_OBJECT (tmp_gc));
+  g_object_unref (tmp_gc);
   
   return tmp_pixmap;
 }
@@ -1743,7 +1794,7 @@ gdk_window_clear_backing_rect (GdkWindow *window,
   tmp_gc = gdk_window_get_bg_gc (window, paint);
   gdk_draw_rectangle (paint->pixmap, tmp_gc, TRUE,
                      x - paint->x_offset, y - paint->y_offset, width, height);
-  gdk_gc_unref (tmp_gc);
+  g_object_unref (tmp_gc);
 }
 
 /**
@@ -1862,6 +1913,65 @@ gdk_window_draw_image (GdkDrawable *drawable,
   RESTORE_GC (gc);
 }
 
+static void
+gdk_window_draw_pixbuf (GdkDrawable     *drawable,
+                       GdkGC           *gc,
+                       GdkPixbuf       *pixbuf,
+                       gint             src_x,
+                       gint             src_y,
+                       gint             dest_x,
+                       gint             dest_y,
+                       gint             width,
+                       gint             height,
+                       GdkRgbDither     dither,
+                       gint             x_dither,
+                       gint             y_dither)
+{
+  GdkWindowObject *private = (GdkWindowObject *)drawable;
+
+  if (GDK_WINDOW_DESTROYED (drawable))
+    return;
+  
+  if (gc)
+    {
+      OFFSET_GC (gc);
+  
+      if (private->paint_stack)
+       {
+         GdkWindowPaint *paint = private->paint_stack->data;
+         gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
+                          dest_x - x_offset, dest_y - y_offset,
+                          width, height,
+                          dither, x_dither - x_offset, y_dither - y_offset);
+       }
+      else
+       gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
+                        dest_x - x_offset, dest_y - y_offset,
+                        width, height,
+                        dither, x_dither, y_dither);
+      
+      RESTORE_GC (gc);
+    }
+  else
+    {
+      gint x_offset, y_offset;
+      gdk_window_get_offsets (drawable, &x_offset, &y_offset);
+      
+      if (private->paint_stack)
+       {
+         GdkWindowPaint *paint = private->paint_stack->data;
+         gdk_draw_pixbuf (paint->pixmap, gc, pixbuf, src_x, src_y,
+                          dest_x - x_offset, dest_y - y_offset,
+                          width, height,
+                           dither, x_dither - x_offset, y_dither - y_offset);
+       }
+      else
+       gdk_draw_pixbuf (private->impl, gc, pixbuf, src_x, src_y,
+                        dest_x - x_offset, dest_y - y_offset,
+                        width, height,
+                        dither, x_dither, y_dither);
+    }
+}
 
 static void
 gdk_window_real_get_size (GdkDrawable *drawable,
@@ -1888,19 +1998,15 @@ gdk_window_real_get_visual (GdkDrawable *drawable)
 static gint
 gdk_window_real_get_depth (GdkDrawable *drawable)
 {
-  gint depth;
-  
   g_return_val_if_fail (GDK_IS_WINDOW (drawable), 0);
 
-  depth = ((GdkWindowObject *)GDK_WINDOW (drawable))->depth;
-
-  if (depth == 0)
-    {
-      g_print ("0 depth for type %s\n", g_type_name (G_OBJECT_TYPE (drawable)));
-      G_BREAKPOINT ();
-    }
+  return ((GdkWindowObject *)GDK_WINDOW (drawable))->depth;
+}
 
-  return depth;
+static GdkScreen*
+gdk_window_real_get_screen (GdkDrawable *drawable)
+{
+  return gdk_drawable_get_screen (GDK_WINDOW_OBJECT (drawable)->impl);
 }
 
 static void
@@ -1927,11 +2033,14 @@ gdk_window_real_get_colormap (GdkDrawable *drawable)
 }
                       
 static GdkImage*
-gdk_window_get_image (GdkDrawable *drawable,
-                      gint         x,
-                      gint         y,
-                      gint         width,
-                      gint         height)
+gdk_window_copy_to_image (GdkDrawable     *drawable,
+                         GdkImage        *image,
+                         gint             src_x,
+                         gint             src_y,
+                         gint             dest_x,
+                         gint             dest_y,
+                         gint             width,
+                         gint             height)
 {
   gint x_offset, y_offset;
   
@@ -1946,10 +2055,12 @@ gdk_window_get_image (GdkDrawable *drawable,
   
   _gdk_windowing_window_get_offsets (drawable, &x_offset, &y_offset);
   
-  return gdk_drawable_get_image (((GdkWindowObject*)drawable)->impl,
-                                 x - x_offset,
-                                 y - y_offset,
-                                 width, height);
+  return _gdk_drawable_copy_to_image (((GdkWindowObject*)drawable)->impl,
+                                     image,
+                                     src_x - x_offset,
+                                     src_y - y_offset,
+                                     dest_x, dest_y,
+                                     width, height);
 }
 
 /* Code for dirty-region queueing
@@ -1974,7 +2085,8 @@ gdk_window_process_updates_internal (GdkWindow *window)
       GdkRegion *update_area = private->update_area;
       private->update_area = NULL;
       
-      if (_gdk_event_func && gdk_window_is_viewable (window))
+      if (_gdk_event_func && gdk_window_is_viewable (window) &&
+         (private->event_mask & GDK_EXPOSURE_MASK))
        {
          GdkEvent event;
          GdkRectangle window_rect;
@@ -1985,7 +2097,7 @@ gdk_window_process_updates_internal (GdkWindow *window)
           if (debug_updates)
             {
               /* Make sure we see the red invalid area before redrawing. */
-              gdk_flush ();
+              gdk_display_sync (gdk_drawable_get_display (window));
               g_usleep (70000);
             }
           
@@ -1999,7 +2111,7 @@ gdk_window_process_updates_internal (GdkWindow *window)
          save_region = _gdk_windowing_window_queue_antiexpose (window, update_area);
       
          event.expose.type = GDK_EXPOSE;
-         event.expose.window = gdk_window_ref (window);
+         event.expose.window = g_object_ref (window);
          event.expose.count = 0;
 
          if (save_region)
@@ -2021,7 +2133,7 @@ gdk_window_process_updates_internal (GdkWindow *window)
 
          if (expose_region != update_area)
            gdk_region_destroy (expose_region);
-         gdk_window_unref (window);
+         g_object_unref (window);
        }
       if (!save_region)
        gdk_region_destroy (update_area);
@@ -2047,9 +2159,12 @@ gdk_window_process_all_updates (void)
   update_windows = NULL;
   update_idle = 0;
 
+  g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
+  
   while (tmp_list)
     {
       gdk_window_process_updates_internal (tmp_list->data);
+      g_object_unref (tmp_list->data);
       tmp_list = tmp_list->next;
     }
 
@@ -2061,7 +2176,9 @@ gdk_window_process_all_updates (void)
 static gboolean
 gdk_window_update_idle (gpointer data)
 {
+  GDK_THREADS_ENTER ();
   gdk_window_process_all_updates ();
+  GDK_THREADS_LEAVE ();
   
   return FALSE;
 }
@@ -2151,13 +2268,37 @@ gdk_window_invalidate_rect   (GdkWindow    *window,
   gdk_region_destroy (region);
 }
 
+static void
+draw_ugly_color (GdkWindow *window,
+                GdkRegion *region)
+{
+  /* Draw ugly color all over the newly-invalid region */
+  GdkColor ugly_color = { 0, 50000, 10000, 10000 };
+  GdkGC *ugly_gc;
+  GdkRectangle clipbox;
+    
+  ugly_gc = gdk_gc_new (window);
+  gdk_gc_set_rgb_fg_color (ugly_gc, &ugly_color);
+  gdk_gc_set_clip_region (ugly_gc, region);
+
+  gdk_region_get_clipbox (region, &clipbox);
+  
+  gdk_draw_rectangle (window,
+                     ugly_gc,
+                     TRUE,
+                     clipbox.x, clipbox.y,
+                     clipbox.width, clipbox.height);
+  
+  g_object_unref (ugly_gc);
+}
+
 /**
  * gdk_window_invalidate_maybe_recurse:
  * @window: a #GdkWindow
  * @region: a #GdkRegion
  * @child_func: function to use to decide if to recurse to a child,
  *              %NULL means never recurse.
- * @child_func_data: data passed to @child_func
+ * @user_data: data passed to @child_func
  *
  * Adds @region to the update area for @window. The update area is the
  * region that needs to be redrawn, or "dirty region." The call
@@ -2173,7 +2314,7 @@ gdk_window_invalidate_rect   (GdkWindow    *window,
  *
  * The @child_func parameter controls whether the region of
  * each child window that intersects @region will also be invalidated.
- * Only children for whic @child_func returns TRUE will have the area
+ * Only children for which @child_func returns TRUE will have the area
  * invalidated.
  **/
 void
@@ -2200,26 +2341,7 @@ gdk_window_invalidate_maybe_recurse (GdkWindow *window,
   if (!gdk_region_empty (visible_region))
     {
       if (debug_updates)
-        {
-          /* Draw ugly color all over the newly-invalid region */
-          GdkRectangle ugly_rect;
-          GdkGC *ugly_gc;
-          GdkColor ugly_color = { 0, 60000, 10000, 10000 };
-          
-          ugly_gc = gdk_gc_new (window);
-
-          gdk_gc_set_rgb_fg_color (ugly_gc, &ugly_color);
-          
-         gdk_region_get_clipbox (visible_region, &ugly_rect);
-
-          gdk_draw_rectangle (window,
-                              ugly_gc,
-                              TRUE,
-                              ugly_rect.x, ugly_rect.y,
-                              ugly_rect.width, ugly_rect.height);
-          
-          g_object_unref (G_OBJECT (ugly_gc));
-        }
+        draw_ugly_color (window, region);
       
       if (private->update_area)
        {
@@ -2570,33 +2692,6 @@ gdk_window_constrain_size (GdkGeometry *geometry,
   *new_height = height;
 }
 
-/**
- * gdk_set_pointer_hooks:
- * @new_hooks: a table of pointer to functions for getting
- *   quantities related to the current pointer position,
- *   or %NULL to restore the default table.
- * 
- * This function allows for hooking into the operation
- * of getting the current location of the pointer. This
- * is only useful for such low-level tools as an
- * event recorder. Applications should never have any
- * reason to use this facility
- * 
- * Return value: the previous pointer hook table
- **/
-GdkPointerHooks *
-gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
-{
-  const GdkPointerHooks *result = current_pointer_hooks;
-
-  if (new_hooks)
-    current_pointer_hooks = new_hooks;
-  else
-    current_pointer_hooks = &default_pointer_hooks;
-
-  return (GdkPointerHooks *)result;
-}
-
 /**
  * gdk_window_get_pointer:
  * @window: a #GdkWindow
@@ -2607,18 +2702,49 @@ gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
  * Obtains the current pointer position and modifier state.
  * The position is given in coordinates relative to @window.
  * 
- * Return value: the window containing the pointer (as with gdk_window_at_pointer()), or %NULL
- *               if the window containing the pointer isn't known to GDK
+ * Return value: the window containing the pointer (as with
+ * gdk_window_at_pointer()), or %NULL if the window containing the
+ * pointer isn't known to GDK
  **/
 GdkWindow*
 gdk_window_get_pointer (GdkWindow        *window,
                        gint              *x,
                        gint              *y,
-                       GdkModifierType *mask)
+                       GdkModifierType   *mask)
 {
-  g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
+  GdkDisplay *display;
+  gint tmp_x, tmp_y;
+  GdkModifierType tmp_mask;
+  GdkWindow *child;
   
-  return current_pointer_hooks->get_pointer (window, x, y, mask); 
+  g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
+
+  if (window)
+    {
+      display = gdk_drawable_get_display (window);
+    }
+  else
+    {
+      GdkScreen *screen = gdk_screen_get_default ();
+
+      display = gdk_screen_get_display (screen);
+      window = gdk_screen_get_root_window (screen);
+      
+      GDK_NOTE (MULTIHEAD,
+               g_message ("Passing NULL for window to gdk_window_get_pointer()\n"
+                          "is not multihead safe"));
+    }
+
+  child = display->pointer_hooks->window_get_pointer (display, window, &tmp_x, &tmp_y, &tmp_mask);
+
+  if (x)
+    *x = tmp_x;
+  if (y)
+    *y = tmp_y;
+  if (mask)
+    *mask = tmp_mask;
+
+  return child;
 }
 
 /**
@@ -2626,10 +2752,14 @@ gdk_window_get_pointer (GdkWindow         *window,
  * @win_x: return location for origin of the window under the pointer
  * @win_y: return location for origin of the window under the pointer
  * 
- * Obtains the window underneath the mouse pointer, returning the location
- * of that window in @win_x, @win_y. Returns %NULL if the window under
- * the mouse pointer is not known to GDK (for example, belongs to
- * another application).
+ * Obtains the window underneath the mouse pointer, returning the
+ * location of that window in @win_x, @win_y. Returns %NULL if the
+ * window under the mouse pointer is not known to GDK (if the window
+ * belongs to another application and a #GdkWindow hasn't been created
+ * for it with gdk_window_foreign_new())
+ *
+ * NOTE: For multihead-aware widgets or applications use
+ * gdk_display_get_window_at_pointer() instead.
  * 
  * Return value: window under the mouse pointer
  **/
@@ -2637,7 +2767,7 @@ GdkWindow*
 gdk_window_at_pointer (gint *win_x,
                       gint *win_y)
 {
-  return current_pointer_hooks->window_at_pointer (NULL, win_x, win_y);
+  return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
 }
 
 /**
@@ -2651,6 +2781,25 @@ gdk_window_at_pointer (gint *win_x,
 GdkWindow *
 gdk_get_default_root_window (void)
 {
-  return _gdk_parent_root;
+  return gdk_screen_get_root_window (gdk_screen_get_default ());
+}
+
+/**
+ * gdk_window_foreign_new:
+ * @anid: a native window handle.
+ * 
+ * Wraps a native window for the default display in a #GdkWindow.
+ * This may fail if the window has been destroyed.
+ *
+ * For example in the X backend, a native window handle is an Xlib
+ * <type>XID</type>.
+ * 
+ * Return value: the newly-created #GdkWindow wrapper for the 
+ *    native window or %NULL if the window has been destroyed.
+ **/
+GdkWindow *
+gdk_window_foreign_new (GdkNativeWindow anid)
+{
+  return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);
 }