1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include <cairo-gobject.h>
32 #include "gdkwindow.h"
34 #ifdef GDK_WINDOWING_X11
35 #include "x11/gdkx.h" /* For workaround */
38 #include "gdkrectangle.h"
39 #include "gdkinternals.h"
41 #include "gdkscreen.h"
42 #include "gdkdeviceprivate.h"
43 #include "gdkdrawable.h"
44 #include "gdkmarshalers.h"
45 #include "gdkscreen.h"
46 #include "gdkwindowimpl.h"
50 #undef DEBUG_WINDOW_PRINTING
55 * @Short_description: Onscreen display areas in the target window system
58 * A #GdkWindow is a rectangular region on the screen. It's a low-level object,
59 * used to implement high-level objects such as #GtkWidget and #GtkWindow on the
60 * GTK+ level. A #GtkWindow is a toplevel window, the thing a user might think
61 * of as a "window" with a titlebar and so on; a #GtkWindow may contain many
62 * #GdkWindow<!-- -->s. For example, each #GtkButton has a #GdkWindow associated
65 * <refsect2 id="COMPOSITED-WINDOWS">
66 * <title>Composited Windows</title>
68 * Normally, the windowing system takes care of rendering the contents of a
69 * child window onto its parent window. This mechanism can be intercepted by
70 * calling gdk_window_set_composited() on the child window. For a
71 * <firstterm>composited</firstterm> window it is the responsibility of the
72 * application to render the window contents at the right spot.
74 * <example id="composited-window-example">
75 * <title>Composited windows</title>
77 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/gdk/composited-window-example.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include>
78 * </programlisting></example>
80 * In the example <xref linkend="composited-window-example"/>, a button is
81 * placed inside of an event box inside of a window. The event box is set as
82 * composited and therefore is no longer automatically drawn to the screen.
84 * When the contents of the event box change, an expose event is generated on
85 * it's parent window (which, in this case, belongs to the toplevel #GtkWindow).
86 * The expose handler for this widget is responsible for merging the changes
87 * back on the screen in the way that it wishes.
89 * In our case, we merge the contents with a 50% transparency. We also set the
90 * background colour of the window to red. The effect is that the background
91 * shows through the button.
94 * <refsect2 id="OFFSCREEN-WINDOWS">
95 * <title>Offscreen Windows</title>
97 * Offscreen windows are more general than composited windows, since they allow
98 * not only to modify the rendering of the child window onto its parent, but
99 * also to apply coordinate transformations.
101 * To integrate an offscreen window into a window hierarchy, one has to call
102 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
103 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
104 * select an offscreen child at given coordinates, and the
105 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
106 * offscreen window are used to translate coordinates between the embedder and
107 * the offscreen window.
109 * For rendering an offscreen window onto its embedder, the contents of the
110 * offscreen window are available as a surface, via
111 * gdk_offscreen_window_get_surface().
117 /* Historically a GdkWindow always matches a platform native window,
118 * be it a toplevel window or a child window. In this setup the
119 * GdkWindow (and other GdkDrawables) were platform independent classes,
120 * and the actual platform specific implementation was in a delegate
121 * object availible as "impl" in the window object.
123 * With the addition of client side windows and offscreen windows this
124 * changes a bit. The application-visible GdkWindow object behaves as
125 * it did before, but not all such windows now have a corresponding native
126 * window. Instead windows that are "client side" are emulated by the gdk
127 * code such that clipping, drawing, moving, events etc work as expected.
129 * For GdkWindows that have a native window the "impl" object is the
130 * same as before. However, for all client side windows the impl object
131 * is shared with its parent (i.e. all client windows descendants of one
132 * native window has the same impl.
134 * Additionally there is a new type of platform independent impl object,
135 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
136 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
137 * windows). Such windows work by allocating a #cairo_surface_t as the backing
138 * store for drawing operations, which is resized with the window.
140 * GdkWindows have a pointer to the "impl window" they are in, i.e.
141 * the topmost GdkWindow which have the same "impl" value. This is stored
142 * in impl_window, which is different from the window itself only for client
144 * All GdkWindows (native or not) track the position of the window in the parent
145 * (x, y), the size of the window (width, height), the position of the window
146 * with respect to the impl window (abs_x, abs_y). We also track the clip
147 * region of the window wrt parent windows and siblings, in window-relative
148 * coordinates with and without child windows included (clip_region,
149 * clip_region_with_children).
151 * All toplevel windows are native windows, but also child windows can be
152 * native (although not children of offscreens). We always listen to
153 * a basic set of events (see get_native_event_mask) for these windows
154 * so that we can emulate events for any client side children.
156 * For native windows we apply the calculated clip region as a window shape
157 * so that eg. client side siblings that overlap the native child properly
158 * draws over the native child window.
160 * In order to minimize flicker and for performance we use a couple of cacheing
161 * tricks. First of all, every time we do a window to window copy area, for instance
162 * when moving a client side window or when scrolling/moving a region in a window
163 * we store this in outstanding_moves instead of applying immediately. We then
164 * delay this move until we really need it (because something depends on being
165 * able to read it), or until we're handing a redraw from an expose/invalidation
166 * (actually we delay it past redraw, but before blitting the double buffer
167 * to the window). This gives us two advantages. First of all it minimizes the time
168 * from the window is moved to the exposes related to that move, secondly it allows
169 * us to be smart about how to do the copy. We combine multiple moves into one (when
170 * possible) and we don't actually do copies to anything that is or will be
171 * invalidated and exposed anyway.
173 * Secondly, we use something called a "implicit paint" during repaint handling.
174 * An implicit paint is similar to a regular paint for the paint stack, but it is
175 * not put on the stack. Instead, it is set on the impl window, and later when
176 * regular gdk_window_begin_paint_region() happen on a window of this impl window
177 * we reuse the surface from the implicit paint. During repaint we create and at the
178 * end flush an implicit paint, which means we can collect all the paints on
179 * multiple client side windows in the same backing store.
182 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
184 /* This adds a local value to the GdkVisibilityState enum */
185 #define GDK_VISIBILITY_NOT_VIEWABLE 3
188 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
202 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
206 struct _GdkWindowPaint
208 cairo_region_t *region;
209 cairo_surface_t *surface;
210 guint uses_implicit : 1;
216 cairo_region_t *dest_region; /* The destination region */
217 int dx, dy; /* The amount that the source was moved to reach dest_region */
218 } GdkWindowRegionMove;
222 static void gdk_window_drop_cairo_surface (GdkWindow *private);
224 static void gdk_window_free_paint_stack (GdkWindow *window);
226 static void gdk_window_init (GdkWindow *window);
227 static void gdk_window_class_init (GdkWindowObjectClass *klass);
228 static void gdk_window_finalize (GObject *object);
230 static void gdk_window_set_property (GObject *object,
234 static void gdk_window_get_property (GObject *object,
239 static void gdk_window_clear_backing_region (GdkWindow *window,
240 cairo_region_t *region);
242 static void recompute_visible_regions (GdkWindow *private,
243 gboolean recalculate_siblings,
244 gboolean recalculate_children);
245 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
246 static void gdk_window_flush_recursive (GdkWindow *window);
247 static void do_move_region_bits_on_impl (GdkWindow *window,
248 cairo_region_t *region, /* In impl window coords */
250 static void gdk_window_invalidate_in_parent (GdkWindow *private);
251 static void move_native_children (GdkWindow *private);
252 static void update_cursor (GdkDisplay *display,
254 static void impl_window_add_update_area (GdkWindow *impl_window,
255 cairo_region_t *region);
256 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
257 static void gdk_window_invalidate_region_full (GdkWindow *window,
258 const cairo_region_t *region,
259 gboolean invalidate_children,
261 static void gdk_window_invalidate_rect_full (GdkWindow *window,
262 const GdkRectangle *rect,
263 gboolean invalidate_children,
266 static guint signals[LAST_SIGNAL] = { 0 };
268 static gpointer parent_class = NULL;
270 static const cairo_user_data_key_t gdk_window_cairo_key;
273 new_region_tag (void)
275 static guint32 tag = 0;
281 gdk_window_object_get_type (void)
283 static GType object_type = 0;
286 object_type = g_type_register_static_simple (GDK_TYPE_DRAWABLE,
288 sizeof (GdkWindowObjectClass),
289 (GClassInitFunc) gdk_window_class_init,
291 (GInstanceInitFunc) gdk_window_init,
298 _gdk_paintable_get_type (void)
300 static GType paintable_type = 0;
304 const GTypeInfo paintable_info =
306 sizeof (GdkPaintableIface), /* class_size */
307 NULL, /* base_init */
308 NULL, /* base_finalize */
311 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
312 g_intern_static_string ("GdkPaintable"),
315 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
318 return paintable_type;
322 gdk_window_init (GdkWindow *window)
324 /* 0-initialization is good for all other fields. */
326 window->window_type = GDK_WINDOW_CHILD;
328 window->state = GDK_WINDOW_STATE_WITHDRAWN;
331 window->toplevel_window_type = -1;
333 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
334 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
335 /* Default to unobscured since some backends don't send visibility events */
336 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
339 /* Stop and return on the first non-NULL parent */
341 accumulate_get_window (GSignalInvocationHint *ihint,
343 const GValue *handler_return,
346 g_value_copy (handler_return, return_accu);
347 /* Continue while returning NULL */
348 return g_value_get_object (handler_return) == NULL;
352 create_surface_accumulator (GSignalInvocationHint *ihint,
354 const GValue *handler_return,
357 g_value_copy (handler_return, return_accu);
359 /* Stop on the first non-NULL return value */
360 return g_value_get_boxed (handler_return) == NULL;
363 static GQuark quark_pointer_window = 0;
366 gdk_window_class_init (GdkWindowObjectClass *klass)
368 GObjectClass *object_class = G_OBJECT_CLASS (klass);
370 parent_class = g_type_class_peek_parent (klass);
372 object_class->finalize = gdk_window_finalize;
373 object_class->set_property = gdk_window_set_property;
374 object_class->get_property = gdk_window_get_property;
376 klass->create_surface = _gdk_offscreen_window_create_surface;
378 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
386 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
387 * gdk_window_get_cursor() for details.
391 g_object_class_install_property (object_class,
393 g_param_spec_boxed ("cursor",
400 * GdkWindow::pick-embedded-child:
401 * @window: the window on which the signal is emitted
402 * @x: x coordinate in the window
403 * @y: y coordinate in the window
405 * The ::pick-embedded-child signal is emitted to find an embedded
406 * child at the given position.
408 * Returns: the #GdkWindow of the embedded child at @x, @y, or %NULL
412 signals[PICK_EMBEDDED_CHILD] =
413 g_signal_new (g_intern_static_string ("pick-embedded-child"),
414 G_OBJECT_CLASS_TYPE (object_class),
416 G_STRUCT_OFFSET (GdkWindowObjectClass, pick_embedded_child),
417 accumulate_get_window, NULL,
418 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
425 * GdkWindow::to-embedder:
426 * @window: the offscreen window on which the signal is emitted
427 * @offscreen-x: x coordinate in the offscreen window
428 * @offscreen-y: y coordinate in the offscreen window
429 * @embedder-x: return location for the x coordinate in the embedder window
430 * @embedder-y: return location for the y coordinate in the embedder window
432 * The ::to-embedder signal is emitted to translate coordinates
433 * in an offscreen window to its embedder.
435 * See also #GtkWindow::from-embedder.
439 signals[TO_EMBEDDER] =
440 g_signal_new (g_intern_static_string ("to-embedder"),
441 G_OBJECT_CLASS_TYPE (object_class),
443 G_STRUCT_OFFSET (GdkWindowObjectClass, to_embedder),
445 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
454 * GdkWindow::from-embedder:
455 * @window: the offscreen window on which the signal is emitted
456 * @embedder-x: x coordinate in the embedder window
457 * @embedder-y: y coordinate in the embedder window
458 * @offscreen-x: return location for the x coordinate in the offscreen window
459 * @offscreen-y: return location for the y coordinate in the offscreen window
461 * The ::from-embedder signal is emitted to translate coordinates
462 * in the embedder of an offscreen window to the offscreen window.
464 * See also #GtkWindow::to-embedder.
468 signals[FROM_EMBEDDER] =
469 g_signal_new (g_intern_static_string ("from-embedder"),
470 G_OBJECT_CLASS_TYPE (object_class),
472 G_STRUCT_OFFSET (GdkWindowObjectClass, from_embedder),
474 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
483 * GdkWindow::create-surface:
484 * @window: the offscreen window on which the signal is emitted
485 * @width: the width of the offscreen surface to create
486 * @height: the height of the offscreen surface to create
488 * The ::create-surface signal is emitted when an offscreen window
489 * needs its surface (re)created, which happens either when the the
490 * window is first drawn to, or when the window is being
491 * resized. The first signal handler that returns a non-%NULL
492 * surface will stop any further signal emission, and its surface
495 * Note that it is not possible to access the window's previous
496 * surface from within any callback of this signal. Calling
497 * gdk_offscreen_window_get_surface() will lead to a crash.
499 * Returns: the newly created #cairo_surface_t for the offscreen window
503 signals[CREATE_SURFACE] =
504 g_signal_new (g_intern_static_string ("create-surface"),
505 G_OBJECT_CLASS_TYPE (object_class),
507 G_STRUCT_OFFSET (GdkWindowObjectClass, create_surface),
508 create_surface_accumulator, NULL,
509 _gdk_marshal_BOXED__INT_INT,
510 CAIRO_GOBJECT_TYPE_SURFACE,
517 device_removed_cb (GdkDeviceManager *device_manager,
521 window->devices_inside = g_list_remove (window->devices_inside, device);
522 g_hash_table_remove (window->device_cursor, device);
524 if (window->device_events)
525 g_hash_table_remove (window->device_events, device);
529 gdk_window_finalize (GObject *object)
531 GdkWindow *window = GDK_WINDOW (object);
532 GdkDeviceManager *device_manager;
534 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
535 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
537 if (!GDK_WINDOW_DESTROYED (window))
539 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
541 g_warning ("losing last reference to undestroyed window\n");
542 _gdk_window_destroy (window, FALSE);
545 /* We use TRUE here, to keep us from actually calling
546 * XDestroyWindow() on the window
548 _gdk_window_destroy (window, TRUE);
551 gdk_window_drop_cairo_surface (window);
555 g_object_unref (window->impl);
559 if (window->impl_window != window)
561 g_object_unref (window->impl_window);
562 window->impl_window = NULL;
566 cairo_region_destroy (window->shape);
568 if (window->input_shape)
569 cairo_region_destroy (window->input_shape);
572 gdk_cursor_unref (window->cursor);
574 if (window->device_cursor)
575 g_hash_table_destroy (window->device_cursor);
577 if (window->device_events)
578 g_hash_table_destroy (window->device_events);
580 if (window->devices_inside)
581 g_list_free (window->devices_inside);
583 G_OBJECT_CLASS (parent_class)->finalize (object);
587 gdk_window_set_property (GObject *object,
592 GdkWindow *window = (GdkWindow *)object;
597 gdk_window_set_cursor (window, g_value_get_boxed (value));
601 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
607 gdk_window_get_property (GObject *object,
612 GdkWindow *window = (GdkWindow *) object;
617 g_value_set_boxed (value, gdk_window_get_cursor (window));
621 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
627 gdk_window_is_offscreen (GdkWindow *window)
629 return window->window_type == GDK_WINDOW_OFFSCREEN;
633 gdk_window_get_impl_window (GdkWindow *window)
635 return window->impl_window;
639 _gdk_window_get_impl_window (GdkWindow *window)
641 return gdk_window_get_impl_window (window);
645 gdk_window_has_impl (GdkWindow *window)
647 return window->impl_window == window;
651 gdk_window_is_toplevel (GdkWindow *window)
654 window->parent == NULL ||
655 window->parent->window_type == GDK_WINDOW_ROOT;
659 _gdk_window_has_impl (GdkWindow *window)
661 return gdk_window_has_impl (window);
665 gdk_window_has_no_impl (GdkWindow *window)
667 return window->impl_window != window;
671 remove_child_area (GdkWindow *private,
674 cairo_region_t *region)
677 cairo_region_t *child_region;
680 cairo_region_t *shape;
682 for (l = private->children; l; l = l->next)
689 /* If region is empty already, no need to do
690 anything potentially costly */
691 if (cairo_region_is_empty (region))
694 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
697 /* Ignore offscreen children, as they don't draw in their parent and
698 * don't take part in the clipping */
699 if (gdk_window_is_offscreen (child))
704 r.width = child->width;
705 r.height = child->height;
707 /* Bail early if child totally outside region */
708 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
711 child_region = cairo_region_create_rectangle (&r);
715 /* Adjust shape region to parent window coords */
716 cairo_region_translate (child->shape, child->x, child->y);
717 cairo_region_intersect (child_region, child->shape);
718 cairo_region_translate (child->shape, -child->x, -child->y);
720 else if (private->window_type == GDK_WINDOW_FOREIGN)
722 shape = _gdk_windowing_window_get_shape ((GdkWindow *)child);
725 cairo_region_intersect (child_region, shape);
726 cairo_region_destroy (shape);
732 if (child->input_shape)
733 cairo_region_intersect (child_region, child->input_shape);
734 else if (private->window_type == GDK_WINDOW_FOREIGN)
736 shape = _gdk_windowing_window_get_input_shape ((GdkWindow *)child);
739 cairo_region_intersect (child_region, shape);
740 cairo_region_destroy (shape);
745 cairo_region_subtract (region, child_region);
746 cairo_region_destroy (child_region);
751 static GdkVisibilityState
752 effective_visibility (GdkWindow *window)
754 GdkVisibilityState native;
756 if (!gdk_window_is_viewable (window))
757 return GDK_VISIBILITY_NOT_VIEWABLE;
759 native = window->impl_window->native_visibility;
761 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
762 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
763 return GDK_VISIBILITY_FULLY_OBSCURED;
764 else if (native == GDK_VISIBILITY_UNOBSCURED)
765 return window->visibility;
766 else /* native PARTIAL, private partial or unobscured */
767 return GDK_VISIBILITY_PARTIAL;
771 gdk_window_update_visibility (GdkWindow *window)
773 GdkVisibilityState new_visibility;
776 new_visibility = effective_visibility (window);
778 if (new_visibility != window->effective_visibility)
780 window->effective_visibility = new_visibility;
782 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
783 window->event_mask & GDK_VISIBILITY_NOTIFY)
785 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
787 event->visibility.state = new_visibility;
793 gdk_window_update_visibility_recursively (GdkWindow *window,
794 GdkWindow *only_for_impl)
799 gdk_window_update_visibility (window);
800 for (l = window->children; l != NULL; l = l->next)
803 if ((only_for_impl == NULL) ||
804 (only_for_impl == child->impl_window))
805 gdk_window_update_visibility_recursively (child, only_for_impl);
810 should_apply_clip_as_shape (GdkWindow *window)
813 gdk_window_has_impl (window) &&
814 /* Not for offscreens */
815 !gdk_window_is_offscreen (window) &&
816 /* or for toplevels */
817 !gdk_window_is_toplevel (window) &&
818 /* or for foreign windows */
819 window->window_type != GDK_WINDOW_FOREIGN &&
820 /* or for the root window */
821 window->window_type != GDK_WINDOW_ROOT;
825 apply_shape (GdkWindow *window,
826 cairo_region_t *region)
828 GdkWindowImplClass *impl_class;
830 /* We trash whether we applied a shape so that
831 we can avoid unsetting it many times, which
832 could happen in e.g. apply_clip_as_shape as
833 windows get resized */
834 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
836 impl_class->shape_combine_region (window,
838 else if (window->applied_shape)
839 impl_class->shape_combine_region (window,
842 window->applied_shape = region != NULL;
846 region_rect_equal (const cairo_region_t *region,
847 const GdkRectangle *rect)
849 GdkRectangle extents;
851 if (cairo_region_num_rectangles (region) != 1)
854 cairo_region_get_extents (region, &extents);
856 return extents.x == rect->x &&
857 extents.y == rect->y &&
858 extents.width == rect->width &&
859 extents.height == rect->height;
863 apply_clip_as_shape (GdkWindow *window)
868 r.width = window->width;
869 r.height = window->height;
871 /* We only apply the clip region if would differ
872 from the actual clip region implied by the size
873 of the window. This is to avoid unneccessarily
874 adding meaningless shapes to all native subwindows */
875 if (!region_rect_equal (window->clip_region, &r))
876 apply_shape (window, window->clip_region);
878 apply_shape (window, NULL);
882 recompute_visible_regions_internal (GdkWindow *private,
883 gboolean recalculate_clip,
884 gboolean recalculate_siblings,
885 gboolean recalculate_children)
890 cairo_region_t *new_clip, *old_clip_region_with_children;
891 gboolean clip_region_changed;
892 gboolean abs_pos_changed;
893 int old_abs_x, old_abs_y;
895 old_abs_x = private->abs_x;
896 old_abs_y = private->abs_y;
898 /* Update absolute position */
899 if (gdk_window_has_impl (private))
901 /* Native window starts here */
907 private->abs_x = private->parent->abs_x + private->x;
908 private->abs_y = private->parent->abs_y + private->y;
912 private->abs_x != old_abs_x ||
913 private->abs_y != old_abs_y;
915 /* Update clip region based on:
918 * siblings in parents above window
920 clip_region_changed = FALSE;
921 if (recalculate_clip)
923 if (private->viewable)
925 /* Calculate visible region (sans children) in parent window coords */
928 r.width = private->width;
929 r.height = private->height;
930 new_clip = cairo_region_create_rectangle (&r);
932 if (!gdk_window_is_toplevel (private))
934 cairo_region_intersect (new_clip, private->parent->clip_region);
936 /* Remove all overlapping children from parent.
937 * Unless we're all native, because then we don't need to take
938 * siblings into account since X does that clipping for us.
939 * This makes things like SWT that modify the raw X stacking
940 * order without GDKs knowledge work.
942 if (!_gdk_native_windows)
943 remove_child_area (private->parent, private, FALSE, new_clip);
946 /* Convert from parent coords to window coords */
947 cairo_region_translate (new_clip, -private->x, -private->y);
950 cairo_region_intersect (new_clip, private->shape);
953 new_clip = cairo_region_create ();
955 if (private->clip_region == NULL ||
956 !cairo_region_equal (private->clip_region, new_clip))
957 clip_region_changed = TRUE;
959 if (private->clip_region)
960 cairo_region_destroy (private->clip_region);
961 private->clip_region = new_clip;
963 old_clip_region_with_children = private->clip_region_with_children;
964 private->clip_region_with_children = cairo_region_copy (private->clip_region);
965 if (private->window_type != GDK_WINDOW_ROOT)
966 remove_child_area (private, NULL, FALSE, private->clip_region_with_children);
968 if (clip_region_changed ||
969 !cairo_region_equal (private->clip_region_with_children, old_clip_region_with_children))
970 private->clip_tag = new_region_tag ();
972 if (old_clip_region_with_children)
973 cairo_region_destroy (old_clip_region_with_children);
976 if (clip_region_changed)
978 GdkVisibilityState visibility;
979 gboolean fully_visible;
981 if (cairo_region_is_empty (private->clip_region))
982 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
987 fully_visible = cairo_region_equal (private->clip_region,
994 r.width = private->width;
995 r.height = private->height;
996 fully_visible = region_rect_equal (private->clip_region, &r);
1000 visibility = GDK_VISIBILITY_UNOBSCURED;
1002 visibility = GDK_VISIBILITY_PARTIAL;
1005 if (private->visibility != visibility)
1007 private->visibility = visibility;
1008 gdk_window_update_visibility (private);
1012 /* Update all children, recursively (except for root, where children are not exact). */
1013 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1014 private->window_type != GDK_WINDOW_ROOT)
1016 for (l = private->children; l; l = l->next)
1019 /* Only recalculate clip if the the clip region changed, otherwise
1020 * there is no way the child clip region could change (its has not e.g. moved)
1021 * Except if recalculate_children is set to force child updates
1023 recompute_visible_regions_internal (child,
1024 recalculate_clip && (clip_region_changed || recalculate_children),
1029 if (clip_region_changed &&
1030 should_apply_clip_as_shape (private))
1031 apply_clip_as_shape (private);
1033 if (recalculate_siblings &&
1034 !gdk_window_is_toplevel (private))
1036 /* If we moved a child window in parent or changed the stacking order, then we
1037 * need to recompute the visible area of all the other children in the parent
1039 for (l = private->parent->children; l; l = l->next)
1043 if (child != private)
1044 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1047 /* We also need to recompute the _with_children clip for the parent */
1048 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1051 if (private->cairo_surface && gdk_window_has_impl (private))
1053 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1055 private->cairo_surface = iface->resize_cairo_surface (private->impl,
1056 private->cairo_surface,
1060 else if (private->cairo_surface)
1061 gdk_window_drop_cairo_surface (private);
1064 /* Call this when private has changed in one or more of these ways:
1068 * stacking order of window changed
1071 * It will recalculate abs_x/y and the clip regions
1073 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1074 * for recalculate_siblings. (Mostly used internally for the recursion)
1076 * If a child window was removed (and you can't use that child for
1077 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1080 recompute_visible_regions (GdkWindow *private,
1081 gboolean recalculate_siblings,
1082 gboolean recalculate_children)
1084 recompute_visible_regions_internal (private,
1086 recalculate_siblings,
1087 recalculate_children);
1091 _gdk_window_update_size (GdkWindow *window)
1093 recompute_visible_regions (window, TRUE, FALSE);
1096 /* Find the native window that would be just above "child"
1097 * in the native stacking order if "child" was a native window
1098 * (it doesn't have to be native). If there is no such native
1099 * window inside this native parent then NULL is returned.
1100 * If child is NULL, find lowest native window in parent.
1103 find_native_sibling_above_helper (GdkWindow *parent,
1111 l = g_list_find (parent->children, child);
1112 g_assert (l != NULL); /* Better be a child of its parent... */
1113 l = l->prev; /* Start looking at the one above the child */
1116 l = g_list_last (parent->children);
1118 for (; l != NULL; l = l->prev)
1122 if (gdk_window_has_impl (w))
1125 g_assert (parent != w);
1126 w = find_native_sibling_above_helper (w, NULL);
1136 find_native_sibling_above (GdkWindow *parent,
1141 w = find_native_sibling_above_helper (parent, child);
1145 if (gdk_window_has_impl (parent))
1148 return find_native_sibling_above (parent->parent, parent);
1152 get_native_device_event_mask (GdkWindow *private,
1155 GdkEventMask event_mask;
1158 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1160 event_mask = private->event_mask;
1162 if (_gdk_native_windows ||
1163 private->window_type == GDK_WINDOW_ROOT ||
1164 private->window_type == GDK_WINDOW_FOREIGN)
1170 /* Do whatever the app asks to, since the app
1171 * may be asking for weird things for native windows,
1172 * but don't use motion hints as that may affect non-native
1173 * child windows that don't want it. Also, we need to
1174 * set all the app-specified masks since they will be picked
1175 * up by any implicit grabs (i.e. if they were not set as
1176 * native we would not get the events we need). */
1177 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1179 /* We need thse for all native windows so we can
1180 emulate events on children: */
1183 GDK_VISIBILITY_NOTIFY_MASK |
1184 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1186 /* Additionally we select for pointer and button events
1187 * for toplevels as we need to get these to emulate
1188 * them for non-native subwindows. Even though we don't
1189 * select on them for all native windows we will get them
1190 * as the events are propagated out to the first window
1191 * that select for them.
1192 * Not selecting for button press on all windows is an
1193 * important thing, because in X only one client can do
1194 * so, and we don't want to unexpectedly prevent another
1195 * client from doing it.
1197 * We also need to do the same if the app selects for button presses
1198 * because then we will get implicit grabs for this window, and the
1199 * event mask used for that grab is based on the rest of the mask
1200 * for the window, but we might need more events than this window
1201 * lists due to some non-native child window.
1203 if (gdk_window_is_toplevel (private) ||
1204 mask & GDK_BUTTON_PRESS_MASK)
1206 GDK_POINTER_MOTION_MASK |
1207 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1215 get_native_grab_event_mask (GdkEventMask grab_mask)
1217 /* Similar to the above but for pointer events only */
1219 GDK_POINTER_MOTION_MASK |
1220 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1221 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1224 ~GDK_POINTER_MOTION_HINT_MASK);
1228 get_native_event_mask (GdkWindow *private)
1230 return get_native_device_event_mask (private, NULL);
1233 /* Puts the native window in the right order wrt the other native windows
1234 * in the hierarchy, given the position it has in the client side data.
1235 * This is useful if some operation changed the stacking order.
1236 * This calls assumes the native window is now topmost in its native parent.
1239 sync_native_window_stack_position (GdkWindow *window)
1242 GdkWindowImplClass *impl_class;
1243 GList listhead = {0};
1245 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1247 above = find_native_sibling_above (window->parent, window);
1250 listhead.data = window;
1251 impl_class->restack_under (above, &listhead);
1257 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1258 * the default root window for the default display.
1259 * @attributes: attributes of the new window
1260 * @attributes_mask: mask indicating which fields in @attributes are valid
1262 * Creates a new #GdkWindow using the attributes from
1263 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1264 * more details. Note: to use this on displays other than the default
1265 * display, @parent must be specified.
1267 * Return value: (transfer none): the new #GdkWindow
1270 gdk_window_new (GdkWindow *parent,
1271 GdkWindowAttr *attributes,
1272 gint attributes_mask)
1278 GdkEventMask event_mask;
1279 GdkWindow *real_parent;
1280 GdkDeviceManager *device_manager;
1282 g_return_val_if_fail (attributes != NULL, NULL);
1286 GDK_NOTE (MULTIHEAD,
1287 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1289 screen = gdk_screen_get_default ();
1290 parent = gdk_screen_get_root_window (screen);
1293 screen = gdk_window_get_screen (parent);
1295 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1297 if (GDK_WINDOW_DESTROYED (parent))
1299 g_warning ("gdk_window_new(): parent is destroyed\n");
1303 if (attributes->window_type == GDK_WINDOW_OFFSCREEN &&
1304 _gdk_native_windows)
1306 g_warning ("Offscreen windows not supported with native-windows gdk");
1310 window = g_object_new (GDK_TYPE_WINDOW, NULL);
1312 /* Windows with a foreign parent are treated as if they are children
1313 * of the root window, except for actual creation.
1315 real_parent = parent;
1316 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1317 parent = gdk_screen_get_root_window (screen);
1319 window->parent = parent;
1321 window->accept_focus = TRUE;
1322 window->focus_on_map = TRUE;
1324 if (attributes_mask & GDK_WA_X)
1329 if (attributes_mask & GDK_WA_Y)
1336 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1337 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1339 #ifdef GDK_WINDOWING_X11
1340 /* Work around a bug where Xorg refuses to map toplevel InputOnly windows
1341 * from an untrusted client: http://bugs.freedesktop.org/show_bug.cgi?id=6988
1343 if (attributes->wclass == GDK_INPUT_ONLY &&
1344 window->parent->window_type == GDK_WINDOW_ROOT &&
1345 !G_LIKELY (GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (parent))->trusted_client))
1347 g_warning ("Coercing GDK_INPUT_ONLY toplevel window to GDK_INPUT_OUTPUT to work around bug in Xorg server");
1348 attributes->wclass = GDK_INPUT_OUTPUT;
1352 if (attributes->wclass == GDK_INPUT_ONLY)
1354 /* Backwards compatiblity - we've always ignored
1355 * attributes->window_type for input-only windows
1358 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1359 window->window_type = GDK_WINDOW_TEMP;
1361 window->window_type = GDK_WINDOW_CHILD;
1364 window->window_type = attributes->window_type;
1367 switch (window->window_type)
1369 case GDK_WINDOW_TOPLEVEL:
1370 case GDK_WINDOW_TEMP:
1371 case GDK_WINDOW_OFFSCREEN:
1372 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1373 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1374 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1375 case GDK_WINDOW_CHILD:
1379 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1383 if (attributes_mask & GDK_WA_VISUAL)
1384 window->visual = attributes->visual;
1386 window->visual = gdk_screen_get_system_visual (screen);
1388 window->event_mask = attributes->event_mask;
1390 if (attributes->wclass == GDK_INPUT_OUTPUT)
1392 window->input_only = FALSE;
1393 window->depth = window->visual->depth;
1395 /* XXX: Cache this somehow? */
1396 window->background = cairo_pattern_create_rgb (0, 0, 0);
1401 window->input_only = TRUE;
1405 window->parent->children = g_list_prepend (window->parent->children, window);
1407 window->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
1408 (GDestroyNotify) gdk_cursor_unref);
1410 native = _gdk_native_windows; /* Default */
1411 if (window->parent->window_type == GDK_WINDOW_ROOT)
1412 native = TRUE; /* Always use native windows for toplevels */
1413 else if (!window->input_only &&
1414 (attributes_mask & GDK_WA_VISUAL &&
1415 attributes->visual != gdk_window_get_visual (window->parent)))
1416 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1418 if (gdk_window_is_offscreen (window))
1420 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1421 window->impl_window = window;
1425 event_mask = get_native_event_mask (window);
1427 /* Create the impl */
1428 _gdk_window_impl_new (window, real_parent, screen, event_mask, attributes, attributes_mask);
1429 window->impl_window = window;
1431 /* This will put the native window topmost in the native parent, which may
1432 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1433 if (!_gdk_window_has_impl (real_parent))
1434 sync_native_window_stack_position (window);
1438 window->impl_window = g_object_ref (window->parent->impl_window);
1439 window->impl = g_object_ref (window->impl_window->impl);
1442 recompute_visible_regions (window, TRUE, FALSE);
1444 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1445 (attributes->cursor) :
1448 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1449 g_signal_connect (device_manager, "device-removed",
1450 G_CALLBACK (device_removed_cb), window);
1456 is_parent_of (GdkWindow *parent,
1467 w = gdk_window_get_parent (w);
1474 change_impl (GdkWindow *private,
1475 GdkWindow *impl_window,
1480 GdkDrawable *old_impl;
1481 GdkWindow *old_impl_window;
1483 old_impl = private->impl;
1484 old_impl_window = private->impl_window;
1485 if (private != impl_window)
1486 private->impl_window = g_object_ref (impl_window);
1488 private->impl_window = private;
1489 private->impl = g_object_ref (new);
1490 if (old_impl_window != private)
1491 g_object_unref (old_impl_window);
1492 g_object_unref (old_impl);
1494 for (l = private->children; l != NULL; l = l->next)
1498 if (child->impl == old_impl)
1499 change_impl (child, impl_window, new);
1504 reparent_to_impl (GdkWindow *private)
1509 GdkWindowImplClass *impl_class;
1511 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1513 /* Enumerate in reverse order so we get the right order for the native
1514 windows (first in childrens list is topmost, and reparent places on top) */
1515 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1519 if (child->impl == private->impl)
1520 reparent_to_impl (child);
1523 show = impl_class->reparent ((GdkWindow *)child,
1524 (GdkWindow *)private,
1525 child->x, child->y);
1527 gdk_window_show_unraised ((GdkWindow *)child);
1534 * gdk_window_reparent:
1535 * @window: a #GdkWindow
1536 * @new_parent: new parent to move @window into
1537 * @x: X location inside the new parent
1538 * @y: Y location inside the new parent
1540 * Reparents @window into the given @new_parent. The window being
1541 * reparented will be unmapped as a side effect.
1545 gdk_window_reparent (GdkWindow *window,
1546 GdkWindow *new_parent,
1550 GdkWindow *old_parent;
1552 gboolean show, was_mapped, applied_clip_as_shape;
1553 gboolean do_reparent_to_impl;
1554 GdkEventMask old_native_event_mask;
1555 GdkWindowImplClass *impl_class;
1557 g_return_if_fail (GDK_IS_WINDOW (window));
1558 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1559 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1561 if (GDK_WINDOW_DESTROYED (window) ||
1562 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1565 screen = gdk_window_get_screen (window);
1567 new_parent = gdk_screen_get_root_window (screen);
1569 /* No input-output children of input-only windows */
1570 if (new_parent->input_only && !window->input_only)
1573 /* Don't create loops in hierarchy */
1574 if (is_parent_of (window, new_parent))
1577 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1578 To make sure we're ok, just wipe it. */
1579 gdk_window_drop_cairo_surface (window);
1581 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1582 old_parent = window->parent;
1584 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1587 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1588 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1589 new_parent->window_type == GDK_WINDOW_FOREIGN)
1590 gdk_window_ensure_native (window);
1592 applied_clip_as_shape = should_apply_clip_as_shape (window);
1594 old_native_event_mask = 0;
1595 do_reparent_to_impl = FALSE;
1596 if (gdk_window_has_impl (window))
1598 old_native_event_mask = get_native_event_mask (window);
1600 show = impl_class->reparent (window, new_parent, x, y);
1604 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1605 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1606 new_parent->window_type != GDK_WINDOW_FOREIGN);
1609 gdk_window_hide (window);
1611 do_reparent_to_impl = TRUE;
1612 change_impl (window,
1613 new_parent->impl_window,
1617 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1620 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1622 new_parent = gdk_screen_get_root_window (screen);
1626 old_parent->children = g_list_remove (old_parent->children, window);
1628 window->parent = new_parent;
1632 new_parent->children = g_list_prepend (new_parent->children, window);
1634 /* Switch the window type as appropriate */
1636 switch (GDK_WINDOW_TYPE (new_parent))
1638 case GDK_WINDOW_ROOT:
1639 case GDK_WINDOW_FOREIGN:
1640 if (window->toplevel_window_type != -1)
1641 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1642 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1643 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1645 case GDK_WINDOW_OFFSCREEN:
1646 case GDK_WINDOW_TOPLEVEL:
1647 case GDK_WINDOW_CHILD:
1648 case GDK_WINDOW_TEMP:
1649 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1650 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1652 /* Save the original window type so we can restore it if the
1653 * window is reparented back to be a toplevel
1655 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1656 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1660 /* We might have changed window type for a native windows, so we
1661 need to change the event mask too. */
1662 if (gdk_window_has_impl (window))
1664 GdkEventMask native_event_mask = get_native_event_mask (window);
1666 if (native_event_mask != old_native_event_mask)
1667 impl_class->set_events (window, native_event_mask);
1670 _gdk_window_update_viewable (window);
1672 recompute_visible_regions (window, TRUE, FALSE);
1673 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1674 recompute_visible_regions (old_parent, FALSE, TRUE);
1676 /* We used to apply the clip as the shape, but no more.
1677 Reset this to the real shape */
1678 if (gdk_window_has_impl (window) &&
1679 applied_clip_as_shape &&
1680 !should_apply_clip_as_shape (window))
1681 apply_shape (window, window->shape);
1683 if (do_reparent_to_impl)
1684 reparent_to_impl (window);
1687 /* The reparent will have put the native window topmost in the native parent,
1688 * which may be wrong wrt other native windows in the non-native hierarchy,
1690 if (!gdk_window_has_impl (new_parent))
1691 sync_native_window_stack_position (window);
1695 gdk_window_show_unraised (window);
1697 _gdk_synthesize_crossing_events_for_geometry_change (window);
1701 temporary_disable_extension_events (GdkWindow*window)
1707 if (window->extension_events != 0)
1709 g_object_set_data (G_OBJECT (window),
1710 "gdk-window-extension-events",
1711 GINT_TO_POINTER (window->extension_events));
1712 gdk_input_set_extension_events ((GdkWindow *)window, 0,
1713 GDK_EXTENSION_EVENTS_NONE);
1718 for (l = window->children; l != NULL; l = l->next)
1722 if (window->impl_window == child->impl_window)
1723 res |= temporary_disable_extension_events (child);
1730 reenable_extension_events (GdkWindow *window)
1736 mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window),
1737 "gdk-window-extension-events"));
1741 /* We don't have the mode here, so we pass in cursor.
1742 This works with the current code since mode is not
1743 stored except as part of the mask, and cursor doesn't
1745 gdk_input_set_extension_events ((GdkWindow *)window, mask,
1746 GDK_EXTENSION_EVENTS_CURSOR);
1747 g_object_set_data (G_OBJECT (window),
1748 "gdk-window-extension-events",
1752 for (l = window->children; l != NULL; l = l->next)
1756 if (window->impl_window == child->impl_window)
1757 reenable_extension_events (window);
1762 * gdk_window_ensure_native:
1763 * @window: a #GdkWindow
1765 * Tries to ensure that there is a window-system native window for this
1766 * GdkWindow. This may fail in some situations, returning %FALSE.
1768 * Offscreen window and children of them can never have native windows.
1770 * Some backends may not support native child windows.
1772 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1777 gdk_window_ensure_native (GdkWindow *window)
1779 GdkWindow *impl_window;
1780 GdkDrawable *new_impl, *old_impl;
1784 GdkWindowImplClass *impl_class;
1785 gboolean disabled_extension_events;
1787 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1789 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1790 GDK_WINDOW_DESTROYED (window))
1793 impl_window = gdk_window_get_impl_window (window);
1795 if (gdk_window_is_offscreen (impl_window))
1796 return FALSE; /* native in offscreens not supported */
1798 if (impl_window == window)
1799 /* Already has an impl, and its not offscreen . */
1802 /* Need to create a native window */
1804 /* First we disable any extension events on the window or its
1805 descendants to handle the native input window moving */
1806 disabled_extension_events = FALSE;
1807 if (impl_window->input_window)
1808 disabled_extension_events = temporary_disable_extension_events (window);
1810 gdk_window_drop_cairo_surface (window);
1812 screen = gdk_window_get_screen (window);
1814 old_impl = window->impl;
1815 _gdk_window_impl_new (window, window->parent,
1817 get_native_event_mask (window),
1819 new_impl = window->impl;
1821 window->impl = old_impl;
1822 change_impl (window, window, new_impl);
1824 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1826 /* Native window creation will put the native window topmost in the
1827 * native parent, which may be wrong wrt the position of the previous
1828 * non-native window wrt to the other non-native children, so correct this.
1830 above = find_native_sibling_above (window->parent, window);
1833 listhead.data = window;
1834 listhead.prev = NULL;
1835 listhead.next = NULL;
1836 impl_class->restack_under ((GdkWindow *)above, &listhead);
1839 recompute_visible_regions (window, FALSE, FALSE);
1841 /* The shape may not have been set, as the clip region doesn't actually
1842 change, so do it here manually */
1843 if (should_apply_clip_as_shape (window))
1844 apply_clip_as_shape (window);
1846 reparent_to_impl (window);
1848 if (!window->input_only)
1850 impl_class->set_background (window, window->background);
1853 impl_class->input_shape_combine_region (window,
1854 window->input_shape,
1857 if (gdk_window_is_viewable (window))
1858 impl_class->show (window, FALSE);
1860 if (disabled_extension_events)
1861 reenable_extension_events (window);
1867 window_remove_filters (GdkWindow *window)
1869 if (window->filters)
1873 for (tmp_list = window->filters; tmp_list; tmp_list = tmp_list->next)
1874 g_free (tmp_list->data);
1876 g_list_free (window->filters);
1877 window->filters = NULL;
1882 update_pointer_info_foreach (GdkDisplay *display,
1884 GdkPointerWindowInfo *pointer_info,
1887 GdkWindow *window = user_data;
1889 if (pointer_info->toplevel_under_pointer == window)
1891 g_object_unref (pointer_info->toplevel_under_pointer);
1892 pointer_info->toplevel_under_pointer = NULL;
1897 window_remove_from_pointer_info (GdkWindow *window,
1898 GdkDisplay *display)
1900 _gdk_display_pointer_info_foreach (display,
1901 update_pointer_info_foreach,
1906 * _gdk_window_destroy_hierarchy:
1907 * @window: a #GdkWindow
1908 * @recursing: If TRUE, then this is being called because a parent
1910 * @recursing_native: If TRUE, then this is being called because a native parent
1911 * was destroyed. This generally means that the call to the
1912 * windowing system to destroy the window can be omitted, since
1913 * it will be destroyed as a result of the parent being destroyed.
1914 * Unless @foreign_destroy.
1915 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1916 * external agency. The window has already been destroyed and no
1917 * windowing system calls should be made. (This may never happen
1918 * for some windowing systems.)
1920 * Internal function to destroy a window. Like gdk_window_destroy(),
1921 * but does not drop the reference count created by gdk_window_new().
1924 _gdk_window_destroy_hierarchy (GdkWindow *window,
1926 gboolean recursing_native,
1927 gboolean foreign_destroy)
1929 GdkWindowImplClass *impl_class;
1930 GdkWindow *temp_window;
1932 GdkDisplay *display;
1936 g_return_if_fail (GDK_IS_WINDOW (window));
1938 if (GDK_WINDOW_DESTROYED (window))
1941 display = gdk_window_get_display (window);
1942 screen = gdk_window_get_screen (window);
1943 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1944 if (temp_window == window)
1945 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1948 switch (window->window_type)
1950 case GDK_WINDOW_ROOT:
1951 if (!screen->closed)
1953 g_error ("attempted to destroy root window");
1956 /* else fall thru */
1957 case GDK_WINDOW_TOPLEVEL:
1958 case GDK_WINDOW_CHILD:
1959 case GDK_WINDOW_TEMP:
1960 case GDK_WINDOW_FOREIGN:
1961 case GDK_WINDOW_OFFSCREEN:
1962 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1964 /* Logically, it probably makes more sense to send
1965 * a "destroy yourself" message to the foreign window
1966 * whether or not it's in our hierarchy; but for historical
1967 * reasons, we only send "destroy yourself" messages to
1968 * foreign windows in our hierarchy.
1971 _gdk_windowing_window_destroy_foreign (window);
1973 /* Also for historical reasons, we remove any filters
1974 * on a foreign window when it or a parent is destroyed;
1975 * this likely causes problems if two separate portions
1976 * of code are maintaining filter lists on a foreign window.
1978 window_remove_filters (window);
1984 if (window->parent->children)
1985 window->parent->children = g_list_remove (window->parent->children, window);
1988 GDK_WINDOW_IS_MAPPED (window))
1990 recompute_visible_regions (window, TRUE, FALSE);
1991 gdk_window_invalidate_in_parent (window);
1995 gdk_window_free_paint_stack (window);
1997 if (window->background)
1999 cairo_pattern_destroy (window->background);
2000 window->background = NULL;
2003 if (window->window_type == GDK_WINDOW_FOREIGN)
2004 g_assert (window->children == NULL);
2007 children = tmp = window->children;
2008 window->children = NULL;
2012 temp_window = tmp->data;
2016 _gdk_window_destroy_hierarchy (temp_window,
2018 recursing_native || gdk_window_has_impl (window),
2022 g_list_free (children);
2025 _gdk_window_clear_update_area (window);
2027 gdk_window_drop_cairo_surface (window);
2029 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2031 if (gdk_window_has_impl (window))
2032 impl_class->destroy (window, recursing_native,
2036 /* hide to make sure we repaint and break grabs */
2037 gdk_window_hide (window);
2040 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2041 window->parent = NULL;
2042 window->destroyed = TRUE;
2044 window_remove_filters (window);
2046 window_remove_from_pointer_info (window, display);
2048 if (window->clip_region)
2050 cairo_region_destroy (window->clip_region);
2051 window->clip_region = NULL;
2054 if (window->clip_region_with_children)
2056 cairo_region_destroy (window->clip_region_with_children);
2057 window->clip_region_with_children = NULL;
2060 if (window->outstanding_moves)
2062 g_list_foreach (window->outstanding_moves, (GFunc)gdk_window_region_move_free, NULL);
2063 g_list_free (window->outstanding_moves);
2064 window->outstanding_moves = NULL;
2072 * _gdk_window_destroy:
2073 * @window: a #GdkWindow
2074 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2075 * external agency. The window has already been destroyed and no
2076 * windowing system calls should be made. (This may never happen
2077 * for some windowing systems.)
2079 * Internal function to destroy a window. Like gdk_window_destroy(),
2080 * but does not drop the reference count created by gdk_window_new().
2083 _gdk_window_destroy (GdkWindow *window,
2084 gboolean foreign_destroy)
2086 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2090 * gdk_window_destroy:
2091 * @window: a #GdkWindow
2093 * Destroys the window system resources associated with @window and decrements @window's
2094 * reference count. The window system resources for all children of @window are also
2095 * destroyed, but the children's reference counts are not decremented.
2097 * Note that a window will not be destroyed automatically when its reference count
2098 * reaches zero. You must call this function yourself before that happens.
2102 gdk_window_destroy (GdkWindow *window)
2104 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2105 g_object_unref (window);
2109 * gdk_window_set_user_data:
2110 * @window: a #GdkWindow
2111 * @user_data: user data
2113 * For most purposes this function is deprecated in favor of
2114 * g_object_set_data(). However, for historical reasons GTK+ stores
2115 * the #GtkWidget that owns a #GdkWindow as user data on the
2116 * #GdkWindow. So, custom widget implementations should use
2117 * this function for that. If GTK+ receives an event for a #GdkWindow,
2118 * and the user data for the window is non-%NULL, GTK+ will assume the
2119 * user data is a #GtkWidget, and forward the event to that widget.
2123 gdk_window_set_user_data (GdkWindow *window,
2126 g_return_if_fail (GDK_IS_WINDOW (window));
2128 window->user_data = user_data;
2132 * gdk_window_get_user_data:
2133 * @window: a #GdkWindow
2134 * @data: return location for user data
2136 * Retrieves the user data for @window, which is normally the widget
2137 * that @window belongs to. See gdk_window_set_user_data().
2141 gdk_window_get_user_data (GdkWindow *window,
2144 g_return_if_fail (GDK_IS_WINDOW (window));
2146 *data = window->user_data;
2150 * gdk_window_get_window_type:
2151 * @window: a #GdkWindow
2153 * Gets the type of the window. See #GdkWindowType.
2155 * Return value: type of window
2158 gdk_window_get_window_type (GdkWindow *window)
2160 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2162 return GDK_WINDOW_TYPE (window);
2166 * gdk_window_get_visual:
2167 * @window: a #GdkWindow
2169 * Gets the #GdkVisual describing the pixel format of @window.
2171 * Return value: (transfer none): a #GdkVisual
2176 gdk_window_get_visual (GdkWindow *window)
2178 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2180 return window->visual;
2184 * gdk_window_get_screen:
2185 * @window: a #GdkWindow
2187 * Gets the #GdkScreen associated with a #GdkWindow.
2189 * Return value: (transfer none): the #GdkScreen associated with @window
2194 gdk_window_get_screen (GdkWindow *window)
2196 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2198 return gdk_visual_get_screen (window->visual);
2202 * gdk_window_get_display:
2203 * @window: a #GdkWindow
2205 * Gets the #GdkDisplay associated with a #GdkWindow.
2207 * Return value: (transfer none): the #GdkDisplay associated with @window
2212 gdk_window_get_display (GdkWindow *window)
2214 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2216 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2219 * gdk_window_is_destroyed:
2220 * @window: a #GdkWindow
2222 * Check to see if a window is destroyed..
2224 * Return value: %TRUE if the window is destroyed
2229 gdk_window_is_destroyed (GdkWindow *window)
2231 return GDK_WINDOW_DESTROYED (window);
2235 to_embedder (GdkWindow *window,
2236 gdouble offscreen_x,
2237 gdouble offscreen_y,
2238 gdouble *embedder_x,
2239 gdouble *embedder_y)
2241 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2242 offscreen_x, offscreen_y,
2243 embedder_x, embedder_y);
2247 from_embedder (GdkWindow *window,
2250 gdouble *offscreen_x,
2251 gdouble *offscreen_y)
2253 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2254 embedder_x, embedder_y,
2255 offscreen_x, offscreen_y);
2259 * gdk_window_has_native:
2260 * @window: a #GdkWindow
2262 * Checks whether the window has a native window or not. Note that
2263 * you can use gdk_window_ensure_native() if a native window is needed.
2265 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2270 gdk_window_has_native (GdkWindow *window)
2272 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2274 return window->parent == NULL || window->parent->impl != window->impl;
2278 * gdk_window_get_position:
2279 * @window: a #GdkWindow
2280 * @x: X coordinate of window
2281 * @y: Y coordinate of window
2283 * Obtains the position of the window as reported in the
2284 * most-recently-processed #GdkEventConfigure. Contrast with
2285 * gdk_window_get_geometry() which queries the X server for the
2286 * current window position, regardless of which events have been
2287 * received or processed.
2289 * The position coordinates are relative to the window's parent window.
2293 gdk_window_get_position (GdkWindow *window,
2297 g_return_if_fail (GDK_IS_WINDOW (window));
2306 * gdk_window_get_parent:
2307 * @window: a #GdkWindow
2309 * Obtains the parent of @window, as known to GDK. Does not query the
2310 * X server; thus this returns the parent as passed to gdk_window_new(),
2311 * not the actual parent. This should never matter unless you're using
2312 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2313 * matter for toplevel windows, because the window manager may choose
2316 * Note that you should use gdk_window_get_effective_parent() when
2317 * writing generic code that walks up a window hierarchy, because
2318 * gdk_window_get_parent() will most likely not do what you expect if
2319 * there are offscreen windows in the hierarchy.
2321 * Return value: (transfer none): parent of @window
2324 gdk_window_get_parent (GdkWindow *window)
2326 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2328 return window->parent;
2332 * gdk_window_get_effective_parent:
2333 * @window: a #GdkWindow
2335 * Obtains the parent of @window, as known to GDK. Works like
2336 * gdk_window_get_parent() for normal windows, but returns the
2337 * window's embedder for offscreen windows.
2339 * See also: gdk_offscreen_window_get_embedder()
2341 * Return value: (transfer none): effective parent of @window
2346 gdk_window_get_effective_parent (GdkWindow *window)
2348 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2350 if (gdk_window_is_offscreen (window))
2351 return gdk_offscreen_window_get_embedder (window);
2353 return window->parent;
2357 * gdk_window_get_toplevel:
2358 * @window: a #GdkWindow
2360 * Gets the toplevel window that's an ancestor of @window.
2362 * Any window type but %GDK_WINDOW_CHILD is considered a
2363 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2364 * has a root window as parent.
2366 * Note that you should use gdk_window_get_effective_toplevel() when
2367 * you want to get to a window's toplevel as seen on screen, because
2368 * gdk_window_get_toplevel() will most likely not do what you expect
2369 * if there are offscreen windows in the hierarchy.
2371 * Return value: (transfer none): the toplevel window containing @window
2374 gdk_window_get_toplevel (GdkWindow *window)
2376 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2378 while (window->window_type == GDK_WINDOW_CHILD)
2380 if (gdk_window_is_toplevel (window))
2382 window = window->parent;
2389 * gdk_window_get_effective_toplevel:
2390 * @window: a #GdkWindow
2392 * Gets the toplevel window that's an ancestor of @window.
2394 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2395 * embedder as its parent, using gdk_window_get_effective_parent().
2397 * See also: gdk_offscreen_window_get_embedder()
2399 * Return value: (transfer none): the effective toplevel window containing @window
2404 gdk_window_get_effective_toplevel (GdkWindow *window)
2408 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2410 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2411 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2418 * gdk_window_get_children:
2419 * @window: a #GdkWindow
2421 * Gets the list of children of @window known to GDK.
2422 * This function only returns children created via GDK,
2423 * so for example it's useless when used with the root window;
2424 * it only returns windows an application created itself.
2426 * The returned list must be freed, but the elements in the
2429 * Return value: (transfer container) (element-type GdkWindow):
2430 * list of child windows inside @window
2433 gdk_window_get_children (GdkWindow *window)
2435 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2437 if (GDK_WINDOW_DESTROYED (window))
2440 return g_list_copy (window->children);
2444 * gdk_window_peek_children:
2445 * @window: a #GdkWindow
2447 * Like gdk_window_get_children(), but does not copy the list of
2448 * children, so the list does not need to be freed.
2450 * Return value: (transfer none) (element-type GdkWindow):
2451 * a reference to the list of child windows in @window
2454 gdk_window_peek_children (GdkWindow *window)
2456 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2458 if (GDK_WINDOW_DESTROYED (window))
2461 return window->children;
2465 * gdk_window_add_filter:
2466 * @window: a #GdkWindow
2467 * @function: filter callback
2468 * @data: data to pass to filter callback
2470 * Adds an event filter to @window, allowing you to intercept events
2471 * before they reach GDK. This is a low-level operation and makes it
2472 * easy to break GDK and/or GTK+, so you have to know what you're
2473 * doing. Pass %NULL for @window to get all events for all windows,
2474 * instead of events for a specific window.
2476 * See gdk_display_add_client_message_filter() if you are interested
2477 * in X ClientMessage events.
2480 gdk_window_add_filter (GdkWindow *window,
2481 GdkFilterFunc function,
2485 GdkEventFilter *filter;
2487 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2489 if (window && GDK_WINDOW_DESTROYED (window))
2492 /* Filters are for the native events on the native window, so
2493 ensure there is a native window. */
2495 gdk_window_ensure_native (window);
2498 tmp_list = window->filters;
2500 tmp_list = _gdk_default_filters;
2504 filter = (GdkEventFilter *)tmp_list->data;
2505 if ((filter->function == function) && (filter->data == data))
2507 filter->ref_count++;
2510 tmp_list = tmp_list->next;
2513 filter = g_new (GdkEventFilter, 1);
2514 filter->function = function;
2515 filter->data = data;
2516 filter->ref_count = 1;
2520 window->filters = g_list_append (window->filters, filter);
2522 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2526 * gdk_window_remove_filter:
2527 * @window: a #GdkWindow
2528 * @function: previously-added filter function
2529 * @data: user data for previously-added filter function
2531 * Remove a filter previously added with gdk_window_add_filter().
2535 gdk_window_remove_filter (GdkWindow *window,
2536 GdkFilterFunc function,
2539 GList *tmp_list, *node;
2540 GdkEventFilter *filter;
2542 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2545 tmp_list = window->filters;
2547 tmp_list = _gdk_default_filters;
2551 filter = (GdkEventFilter *)tmp_list->data;
2553 tmp_list = tmp_list->next;
2555 if ((filter->function == function) && (filter->data == data))
2557 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2558 filter->ref_count--;
2559 if (filter->ref_count != 0)
2563 window->filters = g_list_remove_link (window->filters, node);
2565 _gdk_default_filters = g_list_remove_link (_gdk_default_filters, node);
2566 g_list_free_1 (node);
2575 * gdk_screen_get_toplevel_windows:
2576 * @screen: The #GdkScreen where the toplevels are located.
2578 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2579 * A toplevel window is a child of the root window (see
2580 * gdk_get_default_root_window()).
2582 * The returned list should be freed with g_list_free(), but
2583 * its elements need not be freed.
2585 * Return value: (transfer container) (element-type GdkWindow):
2586 * list of toplevel windows, free with g_list_free()
2591 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2593 GdkWindow * root_window;
2594 GList *new_list = NULL;
2597 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2599 root_window = gdk_screen_get_root_window (screen);
2601 tmp_list = root_window->children;
2604 GdkWindow *w = tmp_list->data;
2606 if (w->window_type != GDK_WINDOW_FOREIGN)
2607 new_list = g_list_prepend (new_list, w);
2608 tmp_list = tmp_list->next;
2615 * gdk_window_is_visible:
2616 * @window: a #GdkWindow
2618 * Checks whether the window has been mapped (with gdk_window_show() or
2619 * gdk_window_show_unraised()).
2621 * Return value: %TRUE if the window is mapped
2624 gdk_window_is_visible (GdkWindow *window)
2626 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2628 return GDK_WINDOW_IS_MAPPED (window);
2632 * gdk_window_is_viewable:
2633 * @window: a #GdkWindow
2635 * Check if the window and all ancestors of the window are
2636 * mapped. (This is not necessarily "viewable" in the X sense, since
2637 * we only check as far as we have GDK window parents, not to the root
2640 * Return value: %TRUE if the window is viewable
2643 gdk_window_is_viewable (GdkWindow *window)
2645 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2647 if (window->destroyed)
2650 return window->viewable;
2654 * gdk_window_get_state:
2655 * @window: a #GdkWindow
2657 * Gets the bitwise OR of the currently active window state flags,
2658 * from the #GdkWindowState enumeration.
2660 * Return value: window state bitfield
2663 gdk_window_get_state (GdkWindow *window)
2665 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2667 return window->state;
2670 static cairo_content_t
2671 gdk_window_get_content (GdkWindow *window)
2673 cairo_surface_t *surface;
2674 cairo_content_t content;
2676 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2678 surface = _gdk_window_ref_cairo_surface (window);
2679 content = cairo_surface_get_content (surface);
2680 cairo_surface_destroy (surface);
2685 /* This creates an empty "implicit" paint region for the impl window.
2686 * By itself this does nothing, but real paints to this window
2687 * or children of it can use this surface as backing to avoid allocating
2688 * multiple surfaces for subwindow rendering. When doing so they
2689 * add to the region of the implicit paint region, which will be
2690 * pushed to the window when the implicit paint region is ended.
2691 * Such paints should not copy anything to the window on paint end, but
2692 * should rely on the implicit paint end.
2693 * The implicit paint will be automatically ended if someone draws
2694 * directly to the window or a child window.
2697 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2699 GdkWindowPaint *paint;
2701 g_assert (gdk_window_has_impl (window));
2703 if (_gdk_native_windows)
2704 return FALSE; /* No need for implicit paints since we can't merge draws anyway */
2706 if (GDK_IS_PAINTABLE (window->impl))
2707 return FALSE; /* Implementation does double buffering */
2709 if (window->paint_stack != NULL ||
2710 window->implicit_paint != NULL)
2711 return FALSE; /* Don't stack implicit paints */
2713 /* Never do implicit paints for foreign windows, they don't need
2714 * double buffer combination since they have no client side children,
2715 * and creating surfaces for them is risky since they could disappear
2718 if (window->window_type == GDK_WINDOW_FOREIGN)
2721 paint = g_new (GdkWindowPaint, 1);
2722 paint->region = cairo_region_create (); /* Empty */
2723 paint->uses_implicit = FALSE;
2724 paint->flushed = FALSE;
2725 paint->surface = gdk_window_create_similar_surface (window,
2726 gdk_window_get_content (window),
2727 MAX (rect->width, 1),
2728 MAX (rect->height, 1));
2729 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2731 window->implicit_paint = paint;
2736 static cairo_surface_t *
2737 gdk_window_ref_impl_surface (GdkWindow *window)
2739 return GDK_DRAWABLE_GET_CLASS (window->impl)->ref_cairo_surface (window->impl);
2743 gdk_cairo_create_for_impl (GdkWindow *window)
2745 cairo_surface_t *surface;
2748 surface = gdk_window_ref_impl_surface (window);
2749 cr = cairo_create (surface);
2751 cairo_surface_destroy (surface);
2756 /* Ensure that all content related to this (sub)window is pushed to the
2757 native region. If there is an active paint then that area is not
2758 pushed, in order to not show partially finished double buffers. */
2760 gdk_window_flush_implicit_paint (GdkWindow *window)
2762 GdkWindow *impl_window;
2763 GdkWindowPaint *paint;
2764 cairo_region_t *region;
2767 impl_window = gdk_window_get_impl_window (window);
2768 if (impl_window->implicit_paint == NULL)
2771 paint = impl_window->implicit_paint;
2772 paint->flushed = TRUE;
2773 region = cairo_region_copy (window->clip_region_with_children);
2775 /* Don't flush active double buffers, as that may show partially done
2777 for (list = window->paint_stack; list != NULL; list = list->next)
2779 GdkWindowPaint *tmp_paint = list->data;
2781 cairo_region_subtract (region, tmp_paint->region);
2784 cairo_region_translate (region, -window->abs_x, -window->abs_y);
2785 cairo_region_intersect (region, paint->region);
2787 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2791 /* Remove flushed region from the implicit paint */
2792 cairo_region_subtract (paint->region, region);
2794 /* Some regions are valid, push these to window now */
2795 cr = gdk_cairo_create_for_impl (window);
2796 gdk_cairo_region (cr, region);
2798 cairo_set_source_surface (cr, paint->surface, 0, 0);
2799 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2804 cairo_region_destroy (region);
2807 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2809 gdk_window_end_implicit_paint (GdkWindow *window)
2811 GdkWindowPaint *paint;
2813 g_assert (gdk_window_has_impl (window));
2815 g_assert (window->implicit_paint != NULL);
2817 paint = window->implicit_paint;
2819 window->implicit_paint = NULL;
2821 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2825 /* Some regions are valid, push these to window now */
2826 cr = gdk_cairo_create_for_impl (window);
2827 gdk_cairo_region (cr, paint->region);
2829 cairo_set_source_surface (cr, paint->surface, 0, 0);
2830 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2835 cairo_region_destroy (paint->region);
2837 cairo_surface_destroy (paint->surface);
2842 * gdk_window_begin_paint_rect:
2843 * @window: a #GdkWindow
2844 * @rectangle: rectangle you intend to draw to
2846 * A convenience wrapper around gdk_window_begin_paint_region() which
2847 * creates a rectangular region for you. See
2848 * gdk_window_begin_paint_region() for details.
2852 gdk_window_begin_paint_rect (GdkWindow *window,
2853 const GdkRectangle *rectangle)
2855 cairo_region_t *region;
2857 g_return_if_fail (GDK_IS_WINDOW (window));
2859 region = cairo_region_create_rectangle (rectangle);
2860 gdk_window_begin_paint_region (window, region);
2861 cairo_region_destroy (region);
2865 * gdk_window_begin_paint_region:
2866 * @window: a #GdkWindow
2867 * @region: region you intend to draw to
2869 * Indicates that you are beginning the process of redrawing @region.
2870 * A backing store (offscreen buffer) large enough to contain @region
2871 * will be created. The backing store will be initialized with the
2872 * background color or background surface for @window. Then, all
2873 * drawing operations performed on @window will be diverted to the
2874 * backing store. When you call gdk_window_end_paint(), the backing
2875 * store will be copied to @window, making it visible onscreen. Only
2876 * the part of @window contained in @region will be modified; that is,
2877 * drawing operations are clipped to @region.
2879 * The net result of all this is to remove flicker, because the user
2880 * sees the finished product appear all at once when you call
2881 * gdk_window_end_paint(). If you draw to @window directly without
2882 * calling gdk_window_begin_paint_region(), the user may see flicker
2883 * as individual drawing operations are performed in sequence. The
2884 * clipping and background-initializing features of
2885 * gdk_window_begin_paint_region() are conveniences for the
2886 * programmer, so you can avoid doing that work yourself.
2888 * When using GTK+, the widget system automatically places calls to
2889 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2890 * emissions of the expose_event signal. That is, if you're writing an
2891 * expose event handler, you can assume that the exposed area in
2892 * #GdkEventExpose has already been cleared to the window background,
2893 * is already set as the clip region, and already has a backing store.
2894 * Therefore in most cases, application code need not call
2895 * gdk_window_begin_paint_region(). (You can disable the automatic
2896 * calls around expose events on a widget-by-widget basis by calling
2897 * gtk_widget_set_double_buffered().)
2899 * If you call this function multiple times before calling the
2900 * matching gdk_window_end_paint(), the backing stores are pushed onto
2901 * a stack. gdk_window_end_paint() copies the topmost backing store
2902 * onscreen, subtracts the topmost region from all other regions in
2903 * the stack, and pops the stack. All drawing operations affect only
2904 * the topmost backing store in the stack. One matching call to
2905 * gdk_window_end_paint() is required for each call to
2906 * gdk_window_begin_paint_region().
2910 gdk_window_begin_paint_region (GdkWindow *window,
2911 const cairo_region_t *region)
2913 #ifdef USE_BACKING_STORE
2914 GdkRectangle clip_box;
2915 GdkWindowPaint *paint, *implicit_paint;
2916 GdkWindow *impl_window;
2919 g_return_if_fail (GDK_IS_WINDOW (window));
2921 if (GDK_WINDOW_DESTROYED (window))
2924 if (GDK_IS_PAINTABLE (window->impl))
2926 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2928 if (iface->begin_paint_region)
2929 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2934 impl_window = gdk_window_get_impl_window (window);
2935 implicit_paint = impl_window->implicit_paint;
2937 paint = g_new (GdkWindowPaint, 1);
2938 paint->region = cairo_region_copy (region);
2939 paint->region_tag = new_region_tag ();
2941 cairo_region_intersect (paint->region, window->clip_region_with_children);
2942 cairo_region_get_extents (paint->region, &clip_box);
2944 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2946 /* Mark the region as valid on the implicit paint */
2949 cairo_region_union (implicit_paint->region, paint->region);
2951 /* Convert back to normal coords */
2952 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2956 paint->uses_implicit = TRUE;
2957 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2958 window->abs_x + clip_box.x,
2959 window->abs_y + clip_box.y,
2960 MAX (clip_box.width, 1),
2961 MAX (clip_box.height, 1));
2965 paint->uses_implicit = FALSE;
2966 paint->surface = gdk_window_create_similar_surface (window,
2967 gdk_window_get_content (window),
2968 MAX (clip_box.width, 1),
2969 MAX (clip_box.height, 1));
2971 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
2973 for (list = window->paint_stack; list != NULL; list = list->next)
2975 GdkWindowPaint *tmp_paint = list->data;
2977 cairo_region_subtract (tmp_paint->region, paint->region);
2980 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
2982 if (!cairo_region_is_empty (paint->region))
2984 gdk_window_clear_backing_region (window,
2988 #endif /* USE_BACKING_STORE */
2992 * gdk_window_end_paint:
2993 * @window: a #GdkWindow
2995 * Indicates that the backing store created by the most recent call to
2996 * gdk_window_begin_paint_region() should be copied onscreen and
2997 * deleted, leaving the next-most-recent backing store or no backing
2998 * store at all as the active paint region. See
2999 * gdk_window_begin_paint_region() for full details. It is an error to
3000 * call this function without a matching
3001 * gdk_window_begin_paint_region() first.
3005 gdk_window_end_paint (GdkWindow *window)
3007 #ifdef USE_BACKING_STORE
3008 GdkWindow *composited;
3009 GdkWindowPaint *paint;
3010 GdkRectangle clip_box;
3011 cairo_region_t *full_clip;
3013 g_return_if_fail (GDK_IS_WINDOW (window));
3015 if (GDK_WINDOW_DESTROYED (window))
3018 if (GDK_IS_PAINTABLE (window->impl))
3020 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3022 if (iface->end_paint)
3023 iface->end_paint ((GdkPaintable*)window->impl);
3027 if (window->paint_stack == NULL)
3029 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3033 paint = window->paint_stack->data;
3035 window->paint_stack = g_slist_delete_link (window->paint_stack,
3036 window->paint_stack);
3038 cairo_region_get_extents (paint->region, &clip_box);
3040 if (!paint->uses_implicit)
3044 gdk_window_flush_outstanding_moves (window);
3046 full_clip = cairo_region_copy (window->clip_region_with_children);
3047 cairo_region_intersect (full_clip, paint->region);
3049 cr = gdk_cairo_create (window);
3050 cairo_set_source_surface (cr, paint->surface, 0, 0);
3051 gdk_cairo_region (cr, full_clip);
3055 cairo_region_destroy (full_clip);
3058 cairo_surface_destroy (paint->surface);
3059 cairo_region_destroy (paint->region);
3062 /* find a composited window in our hierarchy to signal its
3063 * parent to redraw, calculating the clip box as we go...
3065 * stop if parent becomes NULL since then we'd have nowhere
3066 * to draw (ie: 'composited' will always be non-NULL here).
3068 for (composited = window;
3070 composited = composited->parent)
3072 clip_box.x += composited->x;
3073 clip_box.y += composited->y;
3074 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3075 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3077 if (composited->composited)
3079 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3084 #endif /* USE_BACKING_STORE */
3088 gdk_window_free_paint_stack (GdkWindow *window)
3090 if (window->paint_stack)
3092 GSList *tmp_list = window->paint_stack;
3096 GdkWindowPaint *paint = tmp_list->data;
3098 if (tmp_list == window->paint_stack)
3099 cairo_surface_destroy (paint->surface);
3101 cairo_region_destroy (paint->region);
3104 tmp_list = tmp_list->next;
3107 g_slist_free (window->paint_stack);
3108 window->paint_stack = NULL;
3113 do_move_region_bits_on_impl (GdkWindow *impl_window,
3114 cairo_region_t *dest_region, /* In impl window coords */
3117 GdkWindowImplClass *impl_class;
3119 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3121 impl_class->translate (impl_window, dest_region, dx, dy);
3124 static GdkWindowRegionMove *
3125 gdk_window_region_move_new (cairo_region_t *region,
3128 GdkWindowRegionMove *move;
3130 move = g_slice_new (GdkWindowRegionMove);
3131 move->dest_region = cairo_region_copy (region);
3139 gdk_window_region_move_free (GdkWindowRegionMove *move)
3141 cairo_region_destroy (move->dest_region);
3142 g_slice_free (GdkWindowRegionMove, move);
3146 append_move_region (GdkWindow *impl_window,
3147 cairo_region_t *new_dest_region,
3150 GdkWindowRegionMove *move, *old_move;
3151 cairo_region_t *new_total_region, *old_total_region;
3152 cairo_region_t *source_overlaps_destination;
3153 cairo_region_t *non_overwritten;
3154 gboolean added_move;
3157 if (cairo_region_is_empty (new_dest_region))
3160 /* In principle this could just append the move to the list of outstanding
3161 moves that will be replayed before drawing anything when we're handling
3162 exposes. However, we'd like to do a bit better since its commonly the case
3163 that we get multiple copies where A is copied to B and then B is copied
3164 to C, and we'd like to express this as a simple copy A to C operation. */
3166 /* We approach this by taking the new move and pushing it ahead of moves
3167 starting at the end of the list and stopping when its not safe to do so.
3168 It's not safe to push past a move if either the source of the new move
3169 is in the destination of the old move, or if the destination of the new
3170 move is in the source of the new move, or if the destination of the new
3171 move overlaps the destination of the old move. We simplify this by
3172 just comparing the total regions (src + dest) */
3173 new_total_region = cairo_region_copy (new_dest_region);
3174 cairo_region_translate (new_total_region, -dx, -dy);
3175 cairo_region_union (new_total_region, new_dest_region);
3178 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3183 old_total_region = cairo_region_copy (old_move->dest_region);
3184 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3185 cairo_region_union (old_total_region, old_move->dest_region);
3187 cairo_region_intersect (old_total_region, new_total_region);
3188 /* If these regions intersect then its not safe to push the
3189 new region before the old one */
3190 if (!cairo_region_is_empty (old_total_region))
3192 /* The area where the new moves source overlaps the old ones
3194 source_overlaps_destination = cairo_region_copy (new_dest_region);
3195 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3196 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3197 cairo_region_translate (source_overlaps_destination, dx, dy);
3199 /* We can do all sort of optimizations here, but to do things safely it becomes
3200 quite complicated. However, a very common case is that you copy something first,
3201 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3202 in the same direction). We'd like to detect this case and optimize it to one
3204 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3206 /* This means we might be able to replace the old move and the new one
3207 with the new one read from the old ones source, and a second copy of
3208 the non-overwritten parts of the old move. However, such a split
3209 is only valid if the source in the old move isn't overwritten
3210 by the destination of the new one */
3212 /* the new destination of old move if split is ok: */
3213 non_overwritten = cairo_region_copy (old_move->dest_region);
3214 cairo_region_subtract (non_overwritten, new_dest_region);
3215 /* move to source region */
3216 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3218 cairo_region_intersect (non_overwritten, new_dest_region);
3219 if (cairo_region_is_empty (non_overwritten))
3222 move = gdk_window_region_move_new (new_dest_region,
3226 impl_window->outstanding_moves =
3227 g_list_insert_before (impl_window->outstanding_moves,
3229 cairo_region_subtract (old_move->dest_region, new_dest_region);
3231 cairo_region_destroy (non_overwritten);
3234 cairo_region_destroy (source_overlaps_destination);
3235 cairo_region_destroy (old_total_region);
3238 cairo_region_destroy (old_total_region);
3241 cairo_region_destroy (new_total_region);
3245 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3248 impl_window->outstanding_moves =
3249 g_list_prepend (impl_window->outstanding_moves,
3252 impl_window->outstanding_moves =
3253 g_list_insert_before (impl_window->outstanding_moves,
3258 /* Moves bits and update area by dx/dy in impl window.
3259 Takes ownership of region to avoid copy (because we may change it) */
3261 move_region_on_impl (GdkWindow *impl_window,
3262 cairo_region_t *region, /* In impl window coords */
3265 if ((dx == 0 && dy == 0) ||
3266 cairo_region_is_empty (region))
3268 cairo_region_destroy (region);
3272 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3274 /* Move any old invalid regions in the copy source area by dx/dy */
3275 if (impl_window->update_area)
3277 cairo_region_t *update_area;
3279 update_area = cairo_region_copy (region);
3281 /* Convert from target to source */
3282 cairo_region_translate (update_area, -dx, -dy);
3283 cairo_region_intersect (update_area, impl_window->update_area);
3284 /* We only copy the area, so keep the old update area invalid.
3285 It would be safe to remove it too, as code that uses
3286 move_region_on_impl generally also invalidate the source
3287 area. However, it would just use waste cycles. */
3290 cairo_region_translate (update_area, dx, dy);
3291 cairo_region_union (impl_window->update_area, update_area);
3293 /* This area of the destination is now invalid,
3294 so no need to copy to it. */
3295 cairo_region_subtract (region, update_area);
3297 cairo_region_destroy (update_area);
3300 /* If we're currently exposing this window, don't copy to this
3301 destination, as it will be overdrawn when the expose is done,
3302 instead invalidate it and repaint later. */
3303 if (impl_window->implicit_paint)
3305 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3306 cairo_region_t *exposing;
3308 exposing = cairo_region_copy (implicit_paint->region);
3309 cairo_region_intersect (exposing, region);
3310 cairo_region_subtract (region, exposing);
3312 impl_window_add_update_area (impl_window, exposing);
3313 cairo_region_destroy (exposing);
3316 append_move_region (impl_window, region, dx, dy);
3318 cairo_region_destroy (region);
3321 /* Flushes all outstanding changes to the window, call this
3322 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3325 gdk_window_flush_outstanding_moves (GdkWindow *window)
3327 GdkWindow *impl_window;
3328 GList *l, *outstanding;
3329 GdkWindowRegionMove *move;
3331 impl_window = gdk_window_get_impl_window (window);
3332 outstanding = impl_window->outstanding_moves;
3333 impl_window->outstanding_moves = NULL;
3335 for (l = outstanding; l != NULL; l = l->next)
3339 do_move_region_bits_on_impl (impl_window,
3340 move->dest_region, move->dx, move->dy);
3342 gdk_window_region_move_free (move);
3345 g_list_free (outstanding);
3350 * @window: a #GdkWindow
3352 * Flush all outstanding cached operations on a window, leaving the
3353 * window in a state which reflects all that has been drawn before.
3355 * Gdk uses multiple kinds of caching to get better performance and
3356 * nicer drawing. For instance, during exposes all paints to a window
3357 * using double buffered rendering are keep on a surface until the last
3358 * window has been exposed. It also delays window moves/scrolls until
3359 * as long as possible until next update to avoid tearing when moving
3362 * Normally this should be completely invisible to applications, as
3363 * we automatically flush the windows when required, but this might
3364 * be needed if you for instance mix direct native drawing with
3365 * gdk drawing. For Gtk widgets that don't use double buffering this
3366 * will be called automatically before sending the expose event.
3371 gdk_window_flush (GdkWindow *window)
3373 gdk_window_flush_outstanding_moves (window);
3374 gdk_window_flush_implicit_paint (window);
3377 /* If we're about to move/resize or otherwise change the
3378 * hierarchy of a client side window in an impl and we're
3379 * called from an expose event handler then we need to
3380 * flush any already painted parts of the implicit paint
3381 * that are not part of the current paint, as these may
3382 * be used when scrolling or may overdraw the changes
3383 * caused by the hierarchy change.
3386 gdk_window_flush_if_exposing (GdkWindow *window)
3388 GdkWindow *impl_window;
3390 impl_window = gdk_window_get_impl_window (window);
3392 /* If we're in an implicit paint (i.e. in an expose handler, flush
3393 all the already finished exposes to get things to an uptodate state. */
3394 if (impl_window->implicit_paint)
3395 gdk_window_flush (window);
3400 gdk_window_flush_recursive_helper (GdkWindow *window,
3406 for (l = window->children; l != NULL; l = l->next)
3410 if (child->impl == impl)
3411 /* Same impl, ignore */
3412 gdk_window_flush_recursive_helper (child, impl);
3414 gdk_window_flush_recursive (child);
3419 gdk_window_flush_recursive (GdkWindow *window)
3421 gdk_window_flush (window);
3422 gdk_window_flush_recursive_helper (window, window->impl);
3426 * gdk_window_get_clip_region:
3427 * @window: a #GdkWindow
3429 * Computes the region of a window that potentially can be written
3430 * to by drawing primitives. This region may not take into account
3431 * other factors such as if the window is obscured by other windows,
3432 * but no area outside of this region will be affected by drawing
3435 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3436 * when you are done.
3439 gdk_window_get_clip_region (GdkWindow *window)
3441 cairo_region_t *result;
3443 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3445 result = cairo_region_copy (window->clip_region);
3447 if (window->paint_stack)
3449 cairo_region_t *paint_region = cairo_region_create ();
3450 GSList *tmp_list = window->paint_stack;
3454 GdkWindowPaint *paint = tmp_list->data;
3456 cairo_region_union (paint_region, paint->region);
3458 tmp_list = tmp_list->next;
3461 cairo_region_intersect (result, paint_region);
3462 cairo_region_destroy (paint_region);
3469 * gdk_window_get_visible_region:
3470 * @window: a #GdkWindow
3472 * Computes the region of the @window that is potentially visible.
3473 * This does not necessarily take into account if the window is
3474 * obscured by other windows, but no area outside of this region
3477 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3478 * when you are done.
3481 gdk_window_get_visible_region (GdkWindow *window)
3483 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3485 return cairo_region_copy (window->clip_region);
3489 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint, int x_offset_cairo, int y_offset_cairo)
3491 GdkWindow *bg_window;
3492 cairo_pattern_t *pattern = NULL;
3493 int x_offset = 0, y_offset = 0;
3496 cr = cairo_create (paint->surface);
3498 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3500 pattern = gdk_window_get_background_pattern (bg_window);
3504 x_offset += bg_window->x;
3505 y_offset += bg_window->y;
3510 cairo_translate (cr, -x_offset, -y_offset);
3511 cairo_set_source (cr, pattern);
3512 cairo_translate (cr, x_offset, y_offset);
3515 cairo_set_source_rgb (cr, 0, 0, 0);
3521 gdk_window_clear_backing_region (GdkWindow *window,
3522 cairo_region_t *region)
3524 GdkWindowPaint *paint = window->paint_stack->data;
3525 cairo_region_t *clip;
3526 GdkRectangle clipbox;
3529 if (GDK_WINDOW_DESTROYED (window))
3532 cr = setup_backing_rect (window, paint, 0, 0);
3534 clip = cairo_region_copy (paint->region);
3535 cairo_region_intersect (clip, region);
3536 cairo_region_get_extents (clip, &clipbox);
3538 gdk_cairo_region (cr, clip);
3543 cairo_region_destroy (clip);
3547 gdk_window_clear_backing_region_direct (GdkWindow *window,
3548 cairo_region_t *region)
3550 GdkWindowPaint paint;
3551 cairo_region_t *clip;
3552 GdkRectangle clipbox;
3555 if (GDK_WINDOW_DESTROYED (window))
3558 paint.surface = _gdk_window_ref_cairo_surface (window);
3560 cr = setup_backing_rect (window, &paint, 0, 0);
3562 clip = cairo_region_copy (window->clip_region_with_children);
3563 cairo_region_intersect (clip, region);
3564 cairo_region_get_extents (clip, &clipbox);
3566 gdk_cairo_region (cr, clip);
3571 cairo_region_destroy (clip);
3572 cairo_surface_destroy (paint.surface);
3577 gdk_window_clear_region_internal (GdkWindow *window,
3578 cairo_region_t *region)
3580 if (window->paint_stack)
3581 gdk_window_clear_backing_region (window, region);
3583 gdk_window_clear_backing_region_direct (window, region);
3587 gdk_window_drop_cairo_surface (GdkWindow *window)
3589 if (window->cairo_surface)
3591 cairo_surface_finish (window->cairo_surface);
3592 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3594 window->cairo_surface = NULL;
3599 gdk_window_cairo_surface_destroy (void *data)
3601 GdkWindow *window = data;
3603 window->cairo_surface = NULL;
3606 static cairo_surface_t *
3607 gdk_window_create_cairo_surface (GdkWindow *window,
3611 cairo_surface_t *surface, *subsurface;
3613 surface = gdk_window_ref_impl_surface (window);
3614 if (gdk_window_has_impl (window))
3617 subsurface = cairo_surface_create_for_rectangle (surface,
3622 cairo_surface_destroy (surface);
3628 _gdk_window_ref_cairo_surface (GdkWindow *window)
3630 cairo_surface_t *surface;
3632 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3634 if (window->paint_stack)
3636 GdkWindowPaint *paint = window->paint_stack->data;
3638 surface = paint->surface;
3639 cairo_surface_reference (surface);
3644 /* This will be drawing directly to the window, so flush implicit paint */
3645 gdk_window_flush (window);
3647 if (!window->cairo_surface)
3649 window->cairo_surface = gdk_window_create_cairo_surface (window,
3653 if (window->cairo_surface)
3655 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3656 window, gdk_window_cairo_surface_destroy);
3660 cairo_surface_reference (window->cairo_surface);
3662 surface = window->cairo_surface;
3670 * @drawable: a #GdkWindow
3672 * Creates a Cairo context for drawing to @window.
3675 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3676 * produce undefined results, so avoid it at all costs.
3679 * Return value: A newly created Cairo context. Free with
3680 * cairo_destroy() when you are done drawing.
3685 gdk_cairo_create (GdkWindow *window)
3687 cairo_surface_t *surface;
3690 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3692 surface = _gdk_window_ref_cairo_surface (window);
3693 cr = cairo_create (surface);
3695 if (!window->paint_stack)
3697 cairo_reset_clip (cr);
3700 cairo_identity_matrix (cr);
3702 cairo_new_path (cr);
3703 gdk_cairo_region (cr, window->clip_region_with_children);
3710 GdkWindowPaint *paint = window->paint_stack->data;
3712 /* Only needs to clip to region if piggybacking
3713 on an implicit paint */
3714 cairo_reset_clip (cr);
3715 if (paint->uses_implicit)
3718 cairo_identity_matrix (cr);
3720 cairo_new_path (cr);
3721 gdk_cairo_region (cr, paint->region);
3728 cairo_surface_destroy (surface);
3733 /* Code for dirty-region queueing
3735 static GSList *update_windows = NULL;
3736 static guint update_idle = 0;
3737 static gboolean debug_updates = FALSE;
3739 static inline gboolean
3740 gdk_window_is_ancestor (GdkWindow *window,
3741 GdkWindow *ancestor)
3745 GdkWindow *parent = window->parent;
3747 if (parent == ancestor)
3757 gdk_window_add_update_window (GdkWindow *window)
3760 GSList *prev = NULL;
3761 gboolean has_ancestor_in_list = FALSE;
3763 for (tmp = update_windows; tmp; tmp = tmp->next)
3765 GdkWindow *parent = window->parent;
3767 /* check if tmp is an ancestor of "window"; if it is, set a
3768 * flag indicating that all following windows are either
3769 * children of "window" or from a differen hierarchy
3771 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3772 has_ancestor_in_list = TRUE;
3774 /* insert in reverse stacking order when adding around siblings,
3775 * so processing updates properly paints over lower stacked windows
3777 if (parent == GDK_WINDOW (tmp->data)->parent)
3779 gint index = g_list_index (parent->children, window);
3780 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3782 gint sibling_index = g_list_index (parent->children, tmp->data);
3783 if (index > sibling_index)
3787 /* here, tmp got advanced past all lower stacked siblings */
3788 tmp = g_slist_prepend (tmp, window);
3792 update_windows = tmp;
3796 /* if "window" has an ancestor in the list and tmp is one of
3797 * "window's" children, insert "window" before tmp
3799 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3801 tmp = g_slist_prepend (tmp, window);
3806 update_windows = tmp;
3810 /* if we're at the end of the list and had an ancestor it it,
3811 * append to the list
3813 if (! tmp->next && has_ancestor_in_list)
3815 tmp = g_slist_append (tmp, window);
3822 /* if all above checks failed ("window" is from a different
3823 * hierarchy than what is already in the list) or the list is
3826 update_windows = g_slist_prepend (update_windows, window);
3830 gdk_window_remove_update_window (GdkWindow *window)
3832 update_windows = g_slist_remove (update_windows, window);
3836 gdk_window_update_idle (gpointer data)
3838 gdk_window_process_all_updates ();
3844 gdk_window_is_toplevel_frozen (GdkWindow *window)
3846 GdkWindow *toplevel;
3848 toplevel = gdk_window_get_toplevel (window);
3850 return toplevel->update_and_descendants_freeze_count > 0;
3854 gdk_window_schedule_update (GdkWindow *window)
3857 (window->update_freeze_count ||
3858 gdk_window_is_toplevel_frozen (window)))
3863 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3864 gdk_window_update_idle,
3869 _gdk_window_process_updates_recurse (GdkWindow *window,
3870 cairo_region_t *expose_region)
3873 cairo_region_t *child_region;
3875 GList *l, *children;
3877 if (cairo_region_is_empty (expose_region))
3880 if (gdk_window_is_offscreen (window->impl_window) &&
3881 window == window->impl_window)
3882 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3884 /* Make this reentrancy safe for expose handlers freeing windows */
3885 children = g_list_copy (window->children);
3886 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3888 /* Iterate over children, starting at topmost */
3889 for (l = children; l != NULL; l = l->next)
3893 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3896 /* Ignore offscreen children, as they don't draw in their parent and
3897 * don't take part in the clipping */
3898 if (gdk_window_is_offscreen (child))
3903 r.width = child->width;
3904 r.height = child->height;
3906 child_region = cairo_region_create_rectangle (&r);
3909 /* Adjust shape region to parent window coords */
3910 cairo_region_translate (child->shape, child->x, child->y);
3911 cairo_region_intersect (child_region, child->shape);
3912 cairo_region_translate (child->shape, -child->x, -child->y);
3915 if (child->impl == window->impl)
3917 /* Client side child, expose */
3918 cairo_region_intersect (child_region, expose_region);
3919 cairo_region_subtract (expose_region, child_region);
3920 cairo_region_translate (child_region, -child->x, -child->y);
3921 _gdk_window_process_updates_recurse ((GdkWindow *)child, child_region);
3925 /* Native child, just remove area from expose region */
3926 cairo_region_subtract (expose_region, child_region);
3928 cairo_region_destroy (child_region);
3931 g_list_foreach (children, (GFunc)g_object_unref, NULL);
3932 g_list_free (children);
3934 if (!cairo_region_is_empty (expose_region) &&
3937 if (window->event_mask & GDK_EXPOSURE_MASK)
3941 event.expose.type = GDK_EXPOSE;
3942 event.expose.window = g_object_ref (window);
3943 event.expose.send_event = FALSE;
3944 event.expose.count = 0;
3945 event.expose.region = expose_region;
3946 cairo_region_get_extents (expose_region, &event.expose.area);
3948 (*_gdk_event_func) (&event, _gdk_event_data);
3950 g_object_unref (window);
3952 else if (window->window_type != GDK_WINDOW_FOREIGN)
3954 /* No exposure mask set, so nothing will be drawn, the
3955 * app relies on the background being what it specified
3956 * for the window. So, we need to clear this manually.
3958 * For foreign windows if expose is not set that generally
3959 * means some other client paints them, so don't clear
3962 * We use begin/end_paint around the clear so that we can
3963 * piggyback on the implicit paint */
3965 gdk_window_begin_paint_region (window, expose_region);
3966 gdk_window_clear_region_internal (window, expose_region);
3967 gdk_window_end_paint (window);
3972 /* Process and remove any invalid area on the native window by creating
3973 * expose events for the window and all non-native descendants.
3974 * Also processes any outstanding moves on the window before doing
3975 * any drawing. Note that its possible to have outstanding moves without
3976 * any invalid area as we use the update idle mechanism to coalesce
3977 * multiple moves as well as multiple invalidations.
3980 gdk_window_process_updates_internal (GdkWindow *window)
3982 GdkWindowImplClass *impl_class;
3983 gboolean save_region = FALSE;
3984 GdkRectangle clip_box;
3986 /* Ensure the window lives while updating it */
3987 g_object_ref (window);
3989 /* If an update got queued during update processing, we can get a
3990 * window in the update queue that has an empty update_area.
3993 if (window->update_area)
3995 cairo_region_t *update_area = window->update_area;
3996 window->update_area = NULL;
3998 if (_gdk_event_func && gdk_window_is_viewable (window))
4000 cairo_region_t *expose_region;
4001 gboolean end_implicit;
4003 /* Clip to part visible in toplevel */
4004 cairo_region_intersect (update_area, window->clip_region);
4008 /* Make sure we see the red invalid area before redrawing. */
4009 gdk_display_sync (gdk_window_get_display (window));
4013 /* At this point we will be completely redrawing all of update_area.
4014 * If we have any outstanding moves that end up moving stuff inside
4015 * this area we don't actually need to move that as that part would
4016 * be overdrawn by the expose anyway. So, in order to copy less data
4017 * we remove these areas from the outstanding moves.
4019 if (window->outstanding_moves)
4021 GdkWindowRegionMove *move;
4022 cairo_region_t *remove;
4025 remove = cairo_region_copy (update_area);
4026 /* We iterate backwards, starting from the state that would be
4027 if we had applied all the moves. */
4028 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
4033 /* Don't need this area */
4034 cairo_region_subtract (move->dest_region, remove);
4036 /* However if any of the destination we do need has a source
4037 in the updated region we do need that as a destination for
4038 the earlier moves */
4039 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4040 cairo_region_subtract (remove, move->dest_region);
4042 if (cairo_region_is_empty (move->dest_region))
4044 gdk_window_region_move_free (move);
4045 window->outstanding_moves =
4046 g_list_delete_link (window->outstanding_moves, l);
4048 else /* move back */
4049 cairo_region_translate (move->dest_region, move->dx, move->dy);
4051 cairo_region_destroy (remove);
4054 /* By now we a set of window moves that should be applied, and then
4055 * an update region that should be repainted. A trivial implementation
4056 * would just do that in order, however in order to get nicer drawing
4057 * we do some tricks:
4059 * First of all, each subwindow expose may be double buffered by
4060 * itself (depending on widget setting) via
4061 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4062 * creating a single surface the size of the invalid area on the
4063 * native window which all the individual normal paints will draw
4064 * into. This way in the normal case there will be only one surface
4065 * allocated and only once surface draw done for all the windows
4066 * in this native window.
4067 * There are a couple of reasons this may fail, for instance, some
4068 * backends (like quartz) do its own double buffering, so we disable
4069 * gdk double buffering there. Secondly, some subwindow could be
4070 * non-double buffered and draw directly to the window outside a
4071 * begin/end_paint pair. That will be lead to a gdk_window_flush
4072 * which immediately executes all outstanding moves and paints+removes
4073 * the implicit paint (further paints will allocate their own surfaces).
4075 * Secondly, in the case of implicit double buffering we expose all
4076 * the child windows into the implicit surface before we execute
4077 * the outstanding moves. This way we minimize the time between
4078 * doing the moves and rendering the new update area, thus minimizing
4079 * flashing. Of course, if any subwindow is non-double buffered we
4080 * well flush earlier than that.
4082 * Thirdly, after having done the outstanding moves we queue an
4083 * "antiexpose" on the area that will be drawn by the expose, which
4084 * means that any invalid region on the native window side before
4085 * the first expose drawing operation will be discarded, as it
4086 * has by then been overdrawn with valid data. This means we can
4087 * avoid doing the unnecessary repaint any outstanding expose events.
4090 cairo_region_get_extents (update_area, &clip_box);
4091 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4092 expose_region = cairo_region_copy (update_area);
4095 /* Rendering is not double buffered by gdk, do outstanding
4096 * moves and queue antiexposure immediately. No need to do
4098 gdk_window_flush_outstanding_moves (window);
4099 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4100 save_region = impl_class->queue_antiexpose (window, update_area);
4103 /* Render the invalid areas to the implicit paint, by sending exposes.
4104 * May flush if non-double buffered widget draw. */
4105 _gdk_windowing_window_process_updates_recurse (window, expose_region);
4109 /* Do moves right before exposes are rendered to the window */
4110 gdk_window_flush_outstanding_moves (window);
4112 /* By this time we know that any outstanding expose for this
4113 * area is invalid and we can avoid it, so queue an antiexpose.
4114 * However, it may be that due to an non-double buffered expose
4115 * we have already started drawing to the window, so it would
4116 * be to late to anti-expose now. Since this is merely an
4117 * optimization we just avoid doing it at all in that case.
4119 if (window->implicit_paint != NULL &&
4120 !window->implicit_paint->flushed)
4122 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4123 save_region = impl_class->queue_antiexpose (window, update_area);
4126 gdk_window_end_implicit_paint (window);
4128 cairo_region_destroy (expose_region);
4131 cairo_region_destroy (update_area);
4134 if (window->outstanding_moves)
4136 /* Flush any outstanding moves, may happen if we moved a window but got
4137 no actual invalid area */
4138 gdk_window_flush_outstanding_moves (window);
4141 g_object_unref (window);
4145 flush_all_displays (void)
4147 GSList *displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4150 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
4151 gdk_display_flush (tmp_list->data);
4153 g_slist_free (displays);
4156 /* Currently it is not possible to override
4157 * gdk_window_process_all_updates in the same manner as
4158 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4159 * by implementing the GdkPaintable interface. If in the future a
4160 * backend would need this, the right solution would be to add a
4161 * method to GdkDisplay that can be optionally
4162 * NULL. gdk_window_process_all_updates can then walk the list of open
4163 * displays and call the mehod.
4167 * gdk_window_process_all_updates:
4169 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4170 * in the application.
4174 gdk_window_process_all_updates (void)
4176 GSList *old_update_windows = update_windows;
4177 GSList *tmp_list = update_windows;
4178 static gboolean in_process_all_updates = FALSE;
4179 static gboolean got_recursive_update = FALSE;
4181 if (in_process_all_updates)
4183 /* We can't do this now since that would recurse, so
4184 delay it until after the recursion is done. */
4185 got_recursive_update = TRUE;
4190 in_process_all_updates = TRUE;
4191 got_recursive_update = FALSE;
4194 g_source_remove (update_idle);
4196 update_windows = NULL;
4199 _gdk_windowing_before_process_all_updates ();
4201 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4205 GdkWindow *window = tmp_list->data;
4207 if (!GDK_WINDOW_DESTROYED (window))
4209 if (window->update_freeze_count ||
4210 gdk_window_is_toplevel_frozen (window))
4211 gdk_window_add_update_window (window);
4213 gdk_window_process_updates_internal (window);
4216 g_object_unref (window);
4217 tmp_list = tmp_list->next;
4220 g_slist_free (old_update_windows);
4222 flush_all_displays ();
4224 _gdk_windowing_after_process_all_updates ();
4226 in_process_all_updates = FALSE;
4228 /* If we ignored a recursive call, schedule a
4229 redraw now so that it eventually happens,
4230 otherwise we could miss an update if nothing
4231 else schedules an update. */
4232 if (got_recursive_update && !update_idle)
4234 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4235 gdk_window_update_idle,
4240 * gdk_window_process_updates:
4241 * @window: a #GdkWindow
4242 * @update_children: whether to also process updates for child windows
4244 * Sends one or more expose events to @window. The areas in each
4245 * expose event will cover the entire update area for the window (see
4246 * gdk_window_invalidate_region() for details). Normally GDK calls
4247 * gdk_window_process_all_updates() on your behalf, so there's no
4248 * need to call this function unless you want to force expose events
4249 * to be delivered immediately and synchronously (vs. the usual
4250 * case, where GDK delivers them in an idle handler). Occasionally
4251 * this is useful to produce nicer scrolling behavior, for example.
4255 gdk_window_process_updates (GdkWindow *window,
4256 gboolean update_children)
4258 GdkWindow *impl_window;
4260 g_return_if_fail (GDK_IS_WINDOW (window));
4262 if (GDK_WINDOW_DESTROYED (window))
4265 /* Make sure the window lives during the expose callouts */
4266 g_object_ref (window);
4268 impl_window = gdk_window_get_impl_window (window);
4269 if ((impl_window->update_area ||
4270 impl_window->outstanding_moves) &&
4271 !impl_window->update_freeze_count &&
4272 !gdk_window_is_toplevel_frozen (window) &&
4274 /* Don't recurse into process_updates_internal, we'll
4275 * do the update later when idle instead. */
4276 impl_window->implicit_paint == NULL)
4278 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4279 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4282 if (update_children)
4284 /* process updates in reverse stacking order so composition or
4285 * painting over achieves the desired effect for offscreen windows
4287 GList *node, *children;
4289 children = g_list_copy (window->children);
4290 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4292 for (node = g_list_last (children); node; node = node->prev)
4294 gdk_window_process_updates (node->data, TRUE);
4295 g_object_unref (node->data);
4298 g_list_free (children);
4301 g_object_unref (window);
4305 gdk_window_invalidate_rect_full (GdkWindow *window,
4306 const GdkRectangle *rect,
4307 gboolean invalidate_children,
4310 GdkRectangle window_rect;
4311 cairo_region_t *region;
4313 g_return_if_fail (GDK_IS_WINDOW (window));
4315 if (GDK_WINDOW_DESTROYED (window))
4318 if (window->input_only || !window->viewable)
4325 window_rect.width = window->width;
4326 window_rect.height = window->height;
4327 rect = &window_rect;
4330 region = cairo_region_create_rectangle (rect);
4331 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4332 cairo_region_destroy (region);
4336 * gdk_window_invalidate_rect:
4337 * @window: a #GdkWindow
4338 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4340 * @invalidate_children: whether to also invalidate child windows
4342 * A convenience wrapper around gdk_window_invalidate_region() which
4343 * invalidates a rectangular region. See
4344 * gdk_window_invalidate_region() for details.
4347 gdk_window_invalidate_rect (GdkWindow *window,
4348 const GdkRectangle *rect,
4349 gboolean invalidate_children)
4351 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4355 draw_ugly_color (GdkWindow *window,
4356 const cairo_region_t *region)
4360 cr = gdk_cairo_create (window);
4361 /* Draw ugly color all over the newly-invalid region */
4362 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4363 gdk_cairo_region (cr, region);
4370 impl_window_add_update_area (GdkWindow *impl_window,
4371 cairo_region_t *region)
4373 if (impl_window->update_area)
4374 cairo_region_union (impl_window->update_area, region);
4377 gdk_window_add_update_window (impl_window);
4378 impl_window->update_area = cairo_region_copy (region);
4379 gdk_window_schedule_update (impl_window);
4383 /* clear_bg controls if the region will be cleared to
4384 * the background pattern if the exposure mask is not
4385 * set for the window, whereas this might not otherwise be
4386 * done (unless necessary to emulate background settings).
4387 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4388 * need to clear the background, such as when exposing the area beneath a
4389 * hidden or moved window, but not when an app requests repaint or when the
4390 * windowing system exposes a newly visible area (because then the windowing
4391 * system has already cleared the area).
4394 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4395 const cairo_region_t *region,
4397 GdkWindowChildFunc child_func,
4400 GdkWindow *impl_window;
4401 cairo_region_t *visible_region;
4404 g_return_if_fail (GDK_IS_WINDOW (window));
4406 if (GDK_WINDOW_DESTROYED (window))
4409 if (window->input_only ||
4410 !window->viewable ||
4411 cairo_region_is_empty (region) ||
4412 window->window_type == GDK_WINDOW_ROOT)
4415 visible_region = gdk_window_get_visible_region (window);
4416 cairo_region_intersect (visible_region, region);
4418 tmp_list = window->children;
4421 GdkWindow *child = tmp_list->data;
4423 if (!child->input_only)
4425 cairo_region_t *child_region;
4426 GdkRectangle child_rect;
4428 child_rect.x = child->x;
4429 child_rect.y = child->y;
4430 child_rect.width = child->width;
4431 child_rect.height = child->height;
4432 child_region = cairo_region_create_rectangle (&child_rect);
4434 /* remove child area from the invalid area of the parent */
4435 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4436 !child->composited &&
4437 !gdk_window_is_offscreen (child))
4438 cairo_region_subtract (visible_region, child_region);
4440 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4442 cairo_region_t *tmp = cairo_region_copy (region);
4444 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4445 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4446 cairo_region_intersect (child_region, tmp);
4448 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4449 child_region, clear_bg, child_func, user_data);
4451 cairo_region_destroy (tmp);
4454 cairo_region_destroy (child_region);
4457 tmp_list = tmp_list->next;
4460 impl_window = gdk_window_get_impl_window (window);
4462 if (!cairo_region_is_empty (visible_region) ||
4463 /* Even if we're not exposing anything, make sure we process
4464 idles for windows with outstanding moves */
4465 (impl_window->outstanding_moves != NULL &&
4466 impl_window->update_area == NULL))
4469 draw_ugly_color (window, region);
4471 /* Convert to impl coords */
4472 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4474 /* Only invalidate area if app requested expose events or if
4475 we need to clear the area (by request or to emulate background
4476 clearing for non-native windows or native windows with no support
4477 for window backgrounds */
4478 if (window->event_mask & GDK_EXPOSURE_MASK ||
4479 clear_bg == CLEAR_BG_ALL ||
4480 clear_bg == CLEAR_BG_WINCLEARED)
4481 impl_window_add_update_area (impl_window, visible_region);
4484 cairo_region_destroy (visible_region);
4488 * gdk_window_invalidate_maybe_recurse:
4489 * @window: a #GdkWindow
4490 * @region: a #cairo_region_t
4491 * @child_func: function to use to decide if to recurse to a child,
4492 * %NULL means never recurse.
4493 * @user_data: data passed to @child_func
4495 * Adds @region to the update area for @window. The update area is the
4496 * region that needs to be redrawn, or "dirty region." The call
4497 * gdk_window_process_updates() sends one or more expose events to the
4498 * window, which together cover the entire update area. An
4499 * application would normally redraw the contents of @window in
4500 * response to those expose events.
4502 * GDK will call gdk_window_process_all_updates() on your behalf
4503 * whenever your program returns to the main loop and becomes idle, so
4504 * normally there's no need to do that manually, you just need to
4505 * invalidate regions that you know should be redrawn.
4507 * The @child_func parameter controls whether the region of
4508 * each child window that intersects @region will also be invalidated.
4509 * Only children for which @child_func returns TRUE will have the area
4513 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4514 const cairo_region_t *region,
4515 GdkWindowChildFunc child_func,
4518 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4519 child_func, user_data);
4523 true_predicate (GdkWindow *window,
4530 gdk_window_invalidate_region_full (GdkWindow *window,
4531 const cairo_region_t *region,
4532 gboolean invalidate_children,
4535 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4536 invalidate_children ?
4537 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4542 * gdk_window_invalidate_region:
4543 * @window: a #GdkWindow
4544 * @region: a #cairo_region_t
4545 * @invalidate_children: %TRUE to also invalidate child windows
4547 * Adds @region to the update area for @window. The update area is the
4548 * region that needs to be redrawn, or "dirty region." The call
4549 * gdk_window_process_updates() sends one or more expose events to the
4550 * window, which together cover the entire update area. An
4551 * application would normally redraw the contents of @window in
4552 * response to those expose events.
4554 * GDK will call gdk_window_process_all_updates() on your behalf
4555 * whenever your program returns to the main loop and becomes idle, so
4556 * normally there's no need to do that manually, you just need to
4557 * invalidate regions that you know should be redrawn.
4559 * The @invalidate_children parameter controls whether the region of
4560 * each child window that intersects @region will also be invalidated.
4561 * If %FALSE, then the update area for child windows will remain
4562 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4563 * fine grained control over which children are invalidated.
4566 gdk_window_invalidate_region (GdkWindow *window,
4567 const cairo_region_t *region,
4568 gboolean invalidate_children)
4570 gdk_window_invalidate_maybe_recurse (window, region,
4571 invalidate_children ?
4572 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4577 * _gdk_window_invalidate_for_expose:
4578 * @window: a #GdkWindow
4579 * @region: a #cairo_region_t
4581 * Adds @region to the update area for @window. The update area is the
4582 * region that needs to be redrawn, or "dirty region." The call
4583 * gdk_window_process_updates() sends one or more expose events to the
4584 * window, which together cover the entire update area. An
4585 * application would normally redraw the contents of @window in
4586 * response to those expose events.
4588 * GDK will call gdk_window_process_all_updates() on your behalf
4589 * whenever your program returns to the main loop and becomes idle, so
4590 * normally there's no need to do that manually, you just need to
4591 * invalidate regions that you know should be redrawn.
4593 * This version of invalidation is used when you recieve expose events
4594 * from the native window system. It exposes the native window, plus
4595 * any non-native child windows (but not native child windows, as those would
4596 * have gotten their own expose events).
4599 _gdk_window_invalidate_for_expose (GdkWindow *window,
4600 cairo_region_t *region)
4602 GdkWindowRegionMove *move;
4603 cairo_region_t *move_region;
4606 /* Any invalidations comming from the windowing system will
4607 be in areas that may be moved by outstanding moves,
4608 so we need to modify the expose region correspondingly,
4609 otherwise we would expose in the wrong place, as the
4610 outstanding moves will be copied before we draw the
4612 for (l = window->outstanding_moves; l != NULL; l = l->next)
4616 /* covert to move source region */
4617 move_region = cairo_region_copy (move->dest_region);
4618 cairo_region_translate (move_region, -move->dx, -move->dy);
4620 /* Move area of region that intersects with move source
4621 by dx, dy of the move*/
4622 cairo_region_intersect (move_region, region);
4623 cairo_region_subtract (region, move_region);
4624 cairo_region_translate (move_region, move->dx, move->dy);
4625 cairo_region_union (region, move_region);
4627 cairo_region_destroy (move_region);
4630 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4631 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4637 * gdk_window_get_update_area:
4638 * @window: a #GdkWindow
4640 * Transfers ownership of the update area from @window to the caller
4641 * of the function. That is, after calling this function, @window will
4642 * no longer have an invalid/dirty region; the update area is removed
4643 * from @window and handed to you. If a window has no update area,
4644 * gdk_window_get_update_area() returns %NULL. You are responsible for
4645 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4647 * Return value: the update area for @window
4650 gdk_window_get_update_area (GdkWindow *window)
4652 GdkWindow *impl_window;
4653 cairo_region_t *tmp_region;
4655 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4657 impl_window = gdk_window_get_impl_window (window);
4659 if (impl_window->update_area)
4661 tmp_region = cairo_region_copy (window->clip_region_with_children);
4662 /* Convert to impl coords */
4663 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4664 cairo_region_intersect (tmp_region, impl_window->update_area);
4666 if (cairo_region_is_empty (tmp_region))
4668 cairo_region_destroy (tmp_region);
4673 cairo_region_subtract (impl_window->update_area, tmp_region);
4675 if (cairo_region_is_empty (impl_window->update_area) &&
4676 impl_window->outstanding_moves == NULL)
4678 cairo_region_destroy (impl_window->update_area);
4679 impl_window->update_area = NULL;
4681 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4684 /* Convert from impl coords */
4685 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4695 * _gdk_window_clear_update_area:
4696 * @window: a #GdkWindow.
4698 * Internal function to clear the update area for a window. This
4699 * is called when the window is hidden or destroyed.
4702 _gdk_window_clear_update_area (GdkWindow *window)
4704 g_return_if_fail (GDK_IS_WINDOW (window));
4706 if (window->update_area)
4708 gdk_window_remove_update_window (window);
4710 cairo_region_destroy (window->update_area);
4711 window->update_area = NULL;
4716 * gdk_window_freeze_updates:
4717 * @window: a #GdkWindow
4719 * Temporarily freezes a window such that it won't receive expose
4720 * events. The window will begin receiving expose events again when
4721 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4722 * has been called more than once, gdk_window_thaw_updates() must be called
4723 * an equal number of times to begin processing exposes.
4726 gdk_window_freeze_updates (GdkWindow *window)
4728 GdkWindow *impl_window;
4730 g_return_if_fail (GDK_IS_WINDOW (window));
4732 impl_window = gdk_window_get_impl_window (window);
4733 impl_window->update_freeze_count++;
4737 * gdk_window_thaw_updates:
4738 * @window: a #GdkWindow
4740 * Thaws a window frozen with gdk_window_freeze_updates().
4743 gdk_window_thaw_updates (GdkWindow *window)
4745 GdkWindow *impl_window;
4747 g_return_if_fail (GDK_IS_WINDOW (window));
4749 impl_window = gdk_window_get_impl_window (window);
4751 g_return_if_fail (impl_window->update_freeze_count > 0);
4753 if (--impl_window->update_freeze_count == 0)
4754 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4758 * gdk_window_freeze_toplevel_updates_libgtk_only:
4759 * @window: a #GdkWindow
4761 * Temporarily freezes a window and all its descendants such that it won't
4762 * receive expose events. The window will begin receiving expose events
4763 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4764 * gdk_window_freeze_toplevel_updates_libgtk_only()
4765 * has been called more than once,
4766 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4767 * an equal number of times to begin processing exposes.
4769 * This function is not part of the GDK public API and is only
4773 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4775 g_return_if_fail (GDK_IS_WINDOW (window));
4776 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4778 window->update_and_descendants_freeze_count++;
4782 * gdk_window_thaw_toplevel_updates_libgtk_only:
4783 * @window: a #GdkWindow
4785 * Thaws a window frozen with
4786 * gdk_window_freeze_toplevel_updates_libgtk_only().
4788 * This function is not part of the GDK public API and is only
4792 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4794 g_return_if_fail (GDK_IS_WINDOW (window));
4795 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4796 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4798 window->update_and_descendants_freeze_count--;
4800 gdk_window_schedule_update (window);
4804 * gdk_window_set_debug_updates:
4805 * @setting: %TRUE to turn on update debugging
4807 * With update debugging enabled, calls to
4808 * gdk_window_invalidate_region() clear the invalidated region of the
4809 * screen to a noticeable color, and GDK pauses for a short time
4810 * before sending exposes to windows during
4811 * gdk_window_process_updates(). The net effect is that you can see
4812 * the invalid region for each window and watch redraws as they
4813 * occur. This allows you to diagnose inefficiencies in your application.
4815 * In essence, because the GDK rendering model prevents all flicker,
4816 * if you are redrawing the same region 400 times you may never
4817 * notice, aside from noticing a speed problem. Enabling update
4818 * debugging causes GTK to flicker slowly and noticeably, so you can
4819 * see exactly what's being redrawn when, in what order.
4821 * The --gtk-debug=updates command line option passed to GTK+ programs
4822 * enables this debug option at application startup time. That's
4823 * usually more useful than calling gdk_window_set_debug_updates()
4824 * yourself, though you might want to use this function to enable
4825 * updates sometime after application startup time.
4829 gdk_window_set_debug_updates (gboolean setting)
4831 debug_updates = setting;
4835 * gdk_window_constrain_size:
4836 * @geometry: a #GdkGeometry structure
4837 * @flags: a mask indicating what portions of @geometry are set
4838 * @width: desired width of window
4839 * @height: desired height of the window
4840 * @new_width: location to store resulting width
4841 * @new_height: location to store resulting height
4843 * Constrains a desired width and height according to a
4844 * set of geometry hints (such as minimum and maximum size).
4847 gdk_window_constrain_size (GdkGeometry *geometry,
4854 /* This routine is partially borrowed from fvwm.
4856 * Copyright 1993, Robert Nation
4857 * You may use this code for any purpose, as long as the original
4858 * copyright remains in the source code and all documentation
4860 * which in turn borrows parts of the algorithm from uwm
4863 gint min_height = 0;
4864 gint base_width = 0;
4865 gint base_height = 0;
4868 gint max_width = G_MAXINT;
4869 gint max_height = G_MAXINT;
4871 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4873 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4875 base_width = geometry->base_width;
4876 base_height = geometry->base_height;
4877 min_width = geometry->min_width;
4878 min_height = geometry->min_height;
4880 else if (flags & GDK_HINT_BASE_SIZE)
4882 base_width = geometry->base_width;
4883 base_height = geometry->base_height;
4884 min_width = geometry->base_width;
4885 min_height = geometry->base_height;
4887 else if (flags & GDK_HINT_MIN_SIZE)
4889 base_width = geometry->min_width;
4890 base_height = geometry->min_height;
4891 min_width = geometry->min_width;
4892 min_height = geometry->min_height;
4895 if (flags & GDK_HINT_MAX_SIZE)
4897 max_width = geometry->max_width ;
4898 max_height = geometry->max_height;
4901 if (flags & GDK_HINT_RESIZE_INC)
4903 xinc = MAX (xinc, geometry->width_inc);
4904 yinc = MAX (yinc, geometry->height_inc);
4907 /* clamp width and height to min and max values
4909 width = CLAMP (width, min_width, max_width);
4910 height = CLAMP (height, min_height, max_height);
4912 /* shrink to base + N * inc
4914 width = base_width + FLOOR (width - base_width, xinc);
4915 height = base_height + FLOOR (height - base_height, yinc);
4917 /* constrain aspect ratio, according to:
4920 * min_aspect <= -------- <= max_aspect
4924 if (flags & GDK_HINT_ASPECT &&
4925 geometry->min_aspect > 0 &&
4926 geometry->max_aspect > 0)
4930 if (geometry->min_aspect * height > width)
4932 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4933 if (height - delta >= min_height)
4937 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4938 if (width + delta <= max_width)
4943 if (geometry->max_aspect * height < width)
4945 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4946 if (width - delta >= min_width)
4950 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4951 if (height + delta <= max_height)
4960 *new_height = height;
4964 * gdk_window_get_pointer:
4965 * @window: a #GdkWindow
4966 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4967 * return the X coordinate
4968 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4969 * return the Y coordinate
4970 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4973 * Obtains the current pointer position and modifier state.
4974 * The position is given in coordinates relative to the upper left
4975 * corner of @window.
4977 * Return value: (transfer none): the window containing the pointer (as with
4978 * gdk_window_at_pointer()), or %NULL if the window containing the
4979 * pointer isn't known to GDK
4981 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4984 gdk_window_get_pointer (GdkWindow *window,
4987 GdkModifierType *mask)
4989 GdkDisplay *display;
4991 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4993 display = gdk_window_get_display (window);
4995 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
4999 * gdk_window_get_device_position:
5000 * @window: a #GdkWindow.
5001 * @device: #GdkDevice to query to.
5002 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5003 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5004 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5006 * Obtains the current device position and modifier state.
5007 * The position is given in coordinates relative to the upper left
5008 * corner of @window.
5010 * Return value: (transfer none): The window underneath @device (as with
5011 * gdk_display_get_window_at_device_position()), or %NULL if the
5012 * window is not known to GDK.
5017 gdk_window_get_device_position (GdkWindow *window,
5021 GdkModifierType *mask)
5023 GdkDisplay *display;
5025 GdkModifierType tmp_mask;
5028 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5029 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5034 display = gdk_window_get_display (window);
5035 child = display->device_hooks->window_get_device_position (display, device, window,
5036 &tmp_x, &tmp_y, &tmp_mask);
5045 _gdk_display_enable_motion_hints (display, device);
5051 * gdk_window_at_pointer:
5052 * @win_x: (out) (allow-none): return location for origin of the window under the pointer
5053 * @win_y: (out) (allow-none): return location for origin of the window under the pointer
5055 * Obtains the window underneath the mouse pointer, returning the
5056 * location of that window in @win_x, @win_y. Returns %NULL if the
5057 * window under the mouse pointer is not known to GDK (if the window
5058 * belongs to another application and a #GdkWindow hasn't been created
5059 * for it with gdk_window_foreign_new())
5061 * NOTE: For multihead-aware widgets or applications use
5062 * gdk_display_get_window_at_pointer() instead.
5064 * Return value: (transfer none): window under the mouse pointer
5066 * Deprecated: 3.0: Use gdk_display_get_window_at_device_position() instead.
5069 gdk_window_at_pointer (gint *win_x,
5072 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
5076 * gdk_get_default_root_window:
5078 * Obtains the root window (parent all other windows are inside)
5079 * for the default display and screen.
5081 * Return value: (transfer none): the default root window
5084 gdk_get_default_root_window (void)
5086 return gdk_screen_get_root_window (gdk_screen_get_default ());
5090 * gdk_window_foreign_new:
5091 * @anid: a native window handle.
5093 * Wraps a native window for the default display in a #GdkWindow.
5094 * This may fail if the window has been destroyed.
5096 * For example in the X backend, a native window handle is an Xlib
5099 * Return value: (transfer full): the newly-created #GdkWindow wrapper
5100 * for the native window, or %NULL if the window has been destroyed.
5103 gdk_window_foreign_new (GdkNativeWindow anid)
5105 return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);
5109 get_all_native_children (GdkWindow *window,
5115 for (l = window->children; l != NULL; l = l->next)
5119 if (gdk_window_has_impl (child))
5120 *native = g_list_prepend (*native, child);
5122 get_all_native_children (child, native);
5128 gdk_window_raise_internal (GdkWindow *window)
5130 GdkWindow *parent = window->parent;
5132 GList *native_children;
5134 GdkWindowImplClass *impl_class;
5138 parent->children = g_list_remove (parent->children, window);
5139 parent->children = g_list_prepend (parent->children, window);
5142 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5143 /* Just do native raise for toplevels */
5144 if (gdk_window_is_toplevel (window) ||
5145 /* The restack_under codepath should work correctly even if the parent
5146 is native, but it relies on the order of ->children to be correct,
5147 and some apps like SWT reorder the x windows without gdks knowledge,
5148 so we use raise directly in order to make these behave as before
5149 when using native windows */
5150 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5152 impl_class->raise (window);
5154 else if (gdk_window_has_impl (window))
5156 above = find_native_sibling_above (parent, window);
5159 listhead.data = window;
5160 listhead.next = NULL;
5161 listhead.prev = NULL;
5162 impl_class->restack_under ((GdkWindow *)above,
5166 impl_class->raise (window);
5170 native_children = NULL;
5171 get_all_native_children (window, &native_children);
5172 if (native_children != NULL)
5174 above = find_native_sibling_above (parent, window);
5177 impl_class->restack_under (above, native_children);
5180 /* Right order, since native_children is bottom-topmost first */
5181 for (l = native_children; l != NULL; l = l->next)
5182 impl_class->raise (l->data);
5185 g_list_free (native_children);
5191 /* Returns TRUE If the native window was mapped or unmapped */
5193 set_viewable (GdkWindow *w,
5197 GdkWindowImplClass *impl_class;
5200 if (w->viewable == val)
5206 recompute_visible_regions (w, FALSE, FALSE);
5208 for (l = w->children; l != NULL; l = l->next)
5212 if (GDK_WINDOW_IS_MAPPED (child) &&
5213 child->window_type != GDK_WINDOW_FOREIGN)
5214 set_viewable (child, val);
5217 if (!_gdk_native_windows &&
5218 gdk_window_has_impl (w) &&
5219 w->window_type != GDK_WINDOW_FOREIGN &&
5220 !gdk_window_is_toplevel (w))
5222 /* For most native windows we show/hide them not when they are
5223 * mapped/unmapped, because that may not produce the correct results.
5224 * For instance, if a native window have a non-native parent which is
5225 * hidden, but its native parent is viewable then showing the window
5226 * would make it viewable to X but its not viewable wrt the non-native
5227 * hierarchy. In order to handle this we track the gdk side viewability
5228 * and only map really viewable windows.
5230 * There are two exceptions though:
5232 * For foreign windows we don't want ever change the mapped state
5233 * except when explicitly done via gdk_window_show/hide, as this may
5234 * cause problems for client owning the foreign window when its window
5235 * is suddenly mapped or unmapped.
5237 * For toplevel windows embedded in a foreign window (e.g. a plug)
5238 * we sometimes synthesize a map of a window, but the native
5239 * window is really shown by the embedder, so we don't want to
5240 * do the show ourselves. We can't really tell this case from the normal
5241 * toplevel show as such toplevels are seen by gdk as parents of the
5242 * root window, so we make an exception for all toplevels.
5244 * Also, when in GDK_NATIVE_WINDOW mode we never need to play games
5245 * like this, so we just always show/hide directly.
5248 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5250 impl_class->show ((GdkWindow *)w, FALSE);
5252 impl_class->hide ((GdkWindow *)w);
5260 /* Returns TRUE If the native window was mapped or unmapped */
5262 _gdk_window_update_viewable (GdkWindow *window)
5266 if (window->window_type == GDK_WINDOW_FOREIGN ||
5267 window->window_type == GDK_WINDOW_ROOT)
5269 else if (gdk_window_is_toplevel (window) ||
5270 window->parent->viewable)
5271 viewable = GDK_WINDOW_IS_MAPPED (window);
5275 return set_viewable (window, viewable);
5279 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5281 GdkWindowImplClass *impl_class;
5282 gboolean was_mapped, was_viewable;
5285 g_return_if_fail (GDK_IS_WINDOW (window));
5287 if (window->destroyed)
5290 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5291 was_viewable = window->viewable;
5294 /* Keep children in (reverse) stacking order */
5295 gdk_window_raise_internal (window);
5297 if (gdk_window_has_impl (window))
5300 gdk_synthesize_window_state (window,
5301 GDK_WINDOW_STATE_WITHDRAWN,
5309 did_show = _gdk_window_update_viewable (window);
5311 /* If it was already viewable the backend show op won't be called, call it
5312 again to ensure things happen right if the mapped tracking was not right
5313 for e.g. a foreign window.
5314 Dunno if this is strictly needed but its what happened pre-csw.
5315 Also show if not done by gdk_window_update_viewable. */
5316 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5318 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5319 impl_class->show (window, !did_show ? was_mapped : TRUE);
5322 if (!was_mapped && !gdk_window_has_impl (window))
5324 if (window->event_mask & GDK_STRUCTURE_MASK)
5325 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5327 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5328 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5331 if (!was_mapped || raise)
5333 recompute_visible_regions (window, TRUE, FALSE);
5335 /* If any decendants became visible we need to send visibility notify */
5336 gdk_window_update_visibility_recursively (window, NULL);
5338 if (gdk_window_is_viewable (window))
5340 _gdk_synthesize_crossing_events_for_geometry_change (window);
5341 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5347 * gdk_window_show_unraised:
5348 * @window: a #GdkWindow
5350 * Shows a #GdkWindow onscreen, but does not modify its stacking
5351 * order. In contrast, gdk_window_show() will raise the window
5352 * to the top of the window stack.
5354 * On the X11 platform, in Xlib terms, this function calls
5355 * XMapWindow() (it also updates some internal GDK state, which means
5356 * that you can't really use XMapWindow() directly on a GDK window).
5359 gdk_window_show_unraised (GdkWindow *window)
5361 gdk_window_show_internal (window, FALSE);
5366 * @window: a #GdkWindow
5368 * Raises @window to the top of the Z-order (stacking order), so that
5369 * other windows with the same parent window appear below @window.
5370 * This is true whether or not the windows are visible.
5372 * If @window is a toplevel, the window manager may choose to deny the
5373 * request to move the window in the Z-order, gdk_window_raise() only
5374 * requests the restack, does not guarantee it.
5377 gdk_window_raise (GdkWindow *window)
5379 cairo_region_t *old_region, *new_region;
5381 g_return_if_fail (GDK_IS_WINDOW (window));
5383 if (window->destroyed)
5386 gdk_window_flush_if_exposing (window);
5389 if (gdk_window_is_viewable (window) &&
5390 !window->input_only)
5391 old_region = cairo_region_copy (window->clip_region);
5393 /* Keep children in (reverse) stacking order */
5394 gdk_window_raise_internal (window);
5396 recompute_visible_regions (window, TRUE, FALSE);
5400 new_region = cairo_region_copy (window->clip_region);
5402 cairo_region_subtract (new_region, old_region);
5403 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_ALL);
5405 cairo_region_destroy (old_region);
5406 cairo_region_destroy (new_region);
5411 gdk_window_lower_internal (GdkWindow *window)
5413 GdkWindow *parent = window->parent;
5414 GdkWindowImplClass *impl_class;
5416 GList *native_children;
5421 parent->children = g_list_remove (parent->children, window);
5422 parent->children = g_list_append (parent->children, window);
5425 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5426 /* Just do native lower for toplevels */
5427 if (gdk_window_is_toplevel (window) ||
5428 /* The restack_under codepath should work correctly even if the parent
5429 is native, but it relies on the order of ->children to be correct,
5430 and some apps like SWT reorder the x windows without gdks knowledge,
5431 so we use lower directly in order to make these behave as before
5432 when using native windows */
5433 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5435 impl_class->lower (window);
5437 else if (gdk_window_has_impl (window))
5439 above = find_native_sibling_above (parent, window);
5442 listhead.data = window;
5443 listhead.next = NULL;
5444 listhead.prev = NULL;
5445 impl_class->restack_under ((GdkWindow *)above, &listhead);
5448 impl_class->raise (window);
5452 native_children = NULL;
5453 get_all_native_children (window, &native_children);
5454 if (native_children != NULL)
5456 above = find_native_sibling_above (parent, window);
5459 impl_class->restack_under ((GdkWindow *)above,
5463 /* Right order, since native_children is bottom-topmost first */
5464 for (l = native_children; l != NULL; l = l->next)
5465 impl_class->raise (l->data);
5468 g_list_free (native_children);
5475 gdk_window_invalidate_in_parent (GdkWindow *private)
5477 GdkRectangle r, child;
5479 if (gdk_window_is_toplevel (private))
5482 /* get the visible rectangle of the parent */
5484 r.width = private->parent->width;
5485 r.height = private->parent->height;
5487 child.x = private->x;
5488 child.y = private->y;
5489 child.width = private->width;
5490 child.height = private->height;
5491 gdk_rectangle_intersect (&r, &child, &r);
5493 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5499 * @window: a #GdkWindow
5501 * Lowers @window to the bottom of the Z-order (stacking order), so that
5502 * other windows with the same parent window appear above @window.
5503 * This is true whether or not the other windows are visible.
5505 * If @window is a toplevel, the window manager may choose to deny the
5506 * request to move the window in the Z-order, gdk_window_lower() only
5507 * requests the restack, does not guarantee it.
5509 * Note that gdk_window_show() raises the window again, so don't call this
5510 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5513 gdk_window_lower (GdkWindow *window)
5515 g_return_if_fail (GDK_IS_WINDOW (window));
5517 if (window->destroyed)
5520 gdk_window_flush_if_exposing (window);
5522 /* Keep children in (reverse) stacking order */
5523 gdk_window_lower_internal (window);
5525 recompute_visible_regions (window, TRUE, FALSE);
5527 _gdk_synthesize_crossing_events_for_geometry_change (window);
5528 gdk_window_invalidate_in_parent (window);
5532 * gdk_window_restack:
5533 * @window: a #GdkWindow
5534 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5537 * Changes the position of @window in the Z-order (stacking order), so that
5538 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5541 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5542 * lowers the window.
5544 * If @window is a toplevel, the window manager may choose to deny the
5545 * request to move the window in the Z-order, gdk_window_restack() only
5546 * requests the restack, does not guarantee it.
5551 gdk_window_restack (GdkWindow *window,
5555 GdkWindowImplClass *impl_class;
5557 GdkWindow *above_native;
5558 GList *sibling_link;
5559 GList *native_children;
5562 g_return_if_fail (GDK_IS_WINDOW (window));
5563 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5565 if (window->destroyed)
5568 if (sibling == NULL)
5571 gdk_window_raise (window);
5573 gdk_window_lower (window);
5577 gdk_window_flush_if_exposing (window);
5579 if (gdk_window_is_toplevel (window))
5581 g_return_if_fail (gdk_window_is_toplevel (sibling));
5582 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5583 impl_class->restack_toplevel (window, sibling, above);
5587 parent = window->parent;
5590 sibling_link = g_list_find (parent->children, sibling);
5591 g_return_if_fail (sibling_link != NULL);
5592 if (sibling_link == NULL)
5595 parent->children = g_list_remove (parent->children, window);
5597 parent->children = g_list_insert_before (parent->children,
5601 parent->children = g_list_insert_before (parent->children,
5605 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5606 if (gdk_window_has_impl (window))
5608 above_native = find_native_sibling_above (parent, window);
5611 listhead.data = window;
5612 listhead.next = NULL;
5613 listhead.prev = NULL;
5614 impl_class->restack_under (above_native, &listhead);
5617 impl_class->raise (window);
5621 native_children = NULL;
5622 get_all_native_children (window, &native_children);
5623 if (native_children != NULL)
5625 above_native = find_native_sibling_above (parent, window);
5627 impl_class->restack_under (above_native,
5631 /* Right order, since native_children is bottom-topmost first */
5632 for (l = native_children; l != NULL; l = l->next)
5633 impl_class->raise (l->data);
5636 g_list_free (native_children);
5641 recompute_visible_regions (window, TRUE, FALSE);
5643 _gdk_synthesize_crossing_events_for_geometry_change (window);
5644 gdk_window_invalidate_in_parent (window);
5650 * @window: a #GdkWindow
5652 * Like gdk_window_show_unraised(), but also raises the window to the
5653 * top of the window stack (moves the window to the front of the
5656 * This function maps a window so it's visible onscreen. Its opposite
5657 * is gdk_window_hide().
5659 * When implementing a #GtkWidget, you should call this function on the widget's
5660 * #GdkWindow as part of the "map" method.
5663 gdk_window_show (GdkWindow *window)
5665 gdk_window_show_internal (window, TRUE);
5670 * @window: a #GdkWindow
5672 * For toplevel windows, withdraws them, so they will no longer be
5673 * known to the window manager; for all windows, unmaps them, so
5674 * they won't be displayed. Normally done automatically as
5675 * part of gtk_widget_hide().
5678 gdk_window_hide (GdkWindow *window)
5680 GdkWindowImplClass *impl_class;
5681 gboolean was_mapped, did_hide;
5683 g_return_if_fail (GDK_IS_WINDOW (window));
5685 if (window->destroyed)
5688 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5690 if (gdk_window_has_impl (window))
5693 if (GDK_WINDOW_IS_MAPPED (window))
5694 gdk_synthesize_window_state (window,
5696 GDK_WINDOW_STATE_WITHDRAWN);
5698 else if (was_mapped)
5700 GdkDisplay *display;
5701 GdkDeviceManager *device_manager;
5704 /* May need to break grabs on children */
5705 display = gdk_window_get_display (window);
5706 device_manager = gdk_display_get_device_manager (display);
5708 /* Get all devices */
5709 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5710 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5711 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5713 for (d = devices; d; d = d->next)
5715 GdkDevice *device = d->data;
5717 if (_gdk_display_end_device_grab (display, device,
5718 _gdk_windowing_window_get_next_serial (display),
5721 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5724 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5725 g_list_free (devices);
5728 did_hide = _gdk_window_update_viewable (window);
5730 /* Hide foreign window as those are not handled by update_viewable. */
5731 if (gdk_window_has_impl (window) && (!did_hide))
5733 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5734 impl_class->hide (window);
5737 recompute_visible_regions (window, TRUE, FALSE);
5739 /* all decendants became non-visible, we need to send visibility notify */
5740 gdk_window_update_visibility_recursively (window, NULL);
5742 if (was_mapped && !gdk_window_has_impl (window))
5744 if (window->event_mask & GDK_STRUCTURE_MASK)
5745 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5747 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5748 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5750 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5753 /* Invalidate the rect */
5755 gdk_window_invalidate_in_parent (window);
5759 * gdk_window_withdraw:
5760 * @window: a toplevel #GdkWindow
5762 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5763 * This function is not really useful as gdk_window_hide() automatically
5764 * withdraws toplevel windows before hiding them.
5767 gdk_window_withdraw (GdkWindow *window)
5769 GdkWindowImplClass *impl_class;
5770 gboolean was_mapped;
5772 g_return_if_fail (GDK_IS_WINDOW (window));
5774 if (window->destroyed)
5777 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5779 if (gdk_window_has_impl (window))
5781 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5782 impl_class->withdraw (window);
5786 if (window->event_mask & GDK_STRUCTURE_MASK)
5787 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5789 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5790 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5792 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5795 recompute_visible_regions (window, TRUE, FALSE);
5800 * gdk_window_set_events:
5801 * @window: a #GdkWindow
5802 * @event_mask: event mask for @window
5804 * The event mask for a window determines which events will be reported
5805 * for that window from all master input devices. For example, an event mask
5806 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5807 * press events. The event mask is the bitwise OR of values from the
5808 * #GdkEventMask enumeration.
5811 gdk_window_set_events (GdkWindow *window,
5812 GdkEventMask event_mask)
5814 GdkWindowImplClass *impl_class;
5815 GdkDisplay *display;
5817 g_return_if_fail (GDK_IS_WINDOW (window));
5819 if (window->destroyed)
5822 /* If motion hint is disabled, enable motion events again */
5823 display = gdk_window_get_display (window);
5824 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5825 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5827 GList *devices = window->devices_inside;
5831 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5832 devices = devices->next;
5836 window->event_mask = event_mask;
5838 if (gdk_window_has_impl (window))
5840 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5841 impl_class->set_events (window,
5842 get_native_event_mask (window));
5848 * gdk_window_get_events:
5849 * @window: a #GdkWindow
5851 * Gets the event mask for @window for all master input devices. See
5852 * gdk_window_set_events().
5854 * Return value: event mask for @window
5857 gdk_window_get_events (GdkWindow *window)
5859 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5861 if (window->destroyed)
5864 return window->event_mask;
5868 * gdk_window_set_device_events:
5869 * @window: a #GdkWindow
5870 * @device: #GdkDevice to enable events for.
5871 * @event_mask: event mask for @window
5873 * Sets the event mask for a given device (Normally a floating device, not
5874 * attached to any visible pointer) to @window. For example, an event mask
5875 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5876 * press events. The event mask is the bitwise OR of values from the
5877 * #GdkEventMask enumeration.
5882 gdk_window_set_device_events (GdkWindow *window,
5884 GdkEventMask event_mask)
5886 GdkEventMask device_mask;
5887 GdkDisplay *display;
5890 g_return_if_fail (GDK_IS_WINDOW (window));
5891 g_return_if_fail (GDK_IS_DEVICE (device));
5893 if (GDK_WINDOW_DESTROYED (window))
5896 /* If motion hint is disabled, enable motion events again */
5897 display = gdk_window_get_display (window);
5898 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5899 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5900 _gdk_display_enable_motion_hints (display, device);
5902 if (G_UNLIKELY (!window->device_events))
5903 window->device_events = g_hash_table_new (NULL, NULL);
5905 if (event_mask == 0)
5907 /* FIXME: unsetting events on a master device
5908 * would restore window->event_mask
5910 g_hash_table_remove (window->device_events, device);
5913 g_hash_table_insert (window->device_events, device,
5914 GINT_TO_POINTER (event_mask));
5916 if (_gdk_native_windows)
5919 native = gdk_window_get_toplevel (window);
5921 while (gdk_window_is_offscreen (native))
5923 native = gdk_offscreen_window_get_embedder (native);
5925 if (native == NULL ||
5926 (!_gdk_window_has_impl (native) &&
5927 !gdk_window_is_viewable (native)))
5930 native = gdk_window_get_toplevel (native);
5933 device_mask = get_native_device_event_mask (window, device);
5934 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5938 * gdk_window_get_device_events:
5939 * @window: a #GdkWindow.
5940 * @device: a #GdkDevice.
5942 * Returns the event mask for @window corresponding to an specific device.
5944 * Returns: device event mask for @window
5949 gdk_window_get_device_events (GdkWindow *window,
5954 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5955 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5957 if (GDK_WINDOW_DESTROYED (window))
5960 if (!window->device_events)
5963 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5965 /* FIXME: device could be controlled by window->event_mask */
5971 gdk_window_move_resize_toplevel (GdkWindow *window,
5978 cairo_region_t *old_region, *new_region;
5979 GdkWindowImplClass *impl_class;
5981 int old_x, old_y, old_abs_x, old_abs_y;
5991 is_resize = (width != -1) || (height != -1);
5993 if (gdk_window_is_viewable (window) &&
5994 !window->input_only)
5997 old_region = cairo_region_copy (window->clip_region);
6000 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6001 impl_class->move_resize (window, with_move, x, y, width, height);
6003 dx = window->x - old_x;
6004 dy = window->y - old_y;
6006 old_abs_x = window->abs_x;
6007 old_abs_y = window->abs_y;
6009 /* Avoid recomputing for pure toplevel moves, for performance reasons */
6011 recompute_visible_regions (window, TRUE, FALSE);
6015 new_region = cairo_region_copy (window->clip_region);
6017 /* This is the newly exposed area (due to any resize),
6018 * X will expose it, but lets do that without the
6021 cairo_region_subtract (new_region, old_region);
6022 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
6024 cairo_region_destroy (old_region);
6025 cairo_region_destroy (new_region);
6028 _gdk_synthesize_crossing_events_for_geometry_change (window);
6033 move_native_children (GdkWindow *private)
6037 GdkWindowImplClass *impl_class;
6039 for (l = private->children; l; l = l->next)
6043 if (child->impl != private->impl)
6045 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
6046 impl_class->move_resize (child, TRUE,
6048 child->width, child->height);
6051 move_native_children (child);
6056 collect_native_child_region_helper (GdkWindow *window,
6058 cairo_region_t **region,
6063 cairo_region_t *tmp;
6066 for (l = window->children; l != NULL; l = l->next)
6070 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
6073 if (child->impl != impl)
6075 tmp = cairo_region_copy (child->clip_region);
6076 cairo_region_translate (tmp,
6077 x_offset + child->x,
6078 y_offset + child->y);
6079 if (*region == NULL)
6083 cairo_region_union (*region, tmp);
6084 cairo_region_destroy (tmp);
6088 collect_native_child_region_helper (child, impl, region,
6089 x_offset + child->x,
6090 y_offset + child->y);
6096 static cairo_region_t *
6097 collect_native_child_region (GdkWindow *window,
6098 gboolean include_this)
6100 cairo_region_t *region;
6102 if (include_this && gdk_window_has_impl (window) && window->viewable)
6103 return cairo_region_copy (window->clip_region);
6107 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6114 gdk_window_move_resize_internal (GdkWindow *window,
6121 cairo_region_t *old_region, *new_region, *copy_area;
6122 cairo_region_t *old_native_child_region, *new_native_child_region;
6123 GdkWindow *impl_window;
6124 GdkWindowImplClass *impl_class;
6126 int old_x, old_y, old_abs_x, old_abs_y;
6129 g_return_if_fail (GDK_IS_WINDOW (window));
6131 if (window->destroyed)
6134 if (gdk_window_is_toplevel (window))
6136 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6140 /* Bail early if no change */
6141 if (window->width == width &&
6142 window->height == height &&
6148 gdk_window_flush_if_exposing (window);
6150 /* Handle child windows */
6155 impl_window = gdk_window_get_impl_window (window);
6160 old_native_child_region = NULL;
6161 if (gdk_window_is_viewable (window) &&
6162 !window->input_only)
6166 old_region = cairo_region_copy (window->clip_region);
6167 /* Adjust region to parent window coords */
6168 cairo_region_translate (old_region, window->x, window->y);
6170 old_native_child_region = collect_native_child_region (window, TRUE);
6171 if (old_native_child_region)
6173 /* Adjust region to parent window coords */
6174 cairo_region_translate (old_native_child_region, window->x, window->y);
6176 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6177 * source or destination for a delayed GdkWindowRegionMove. So, we need
6178 * to flush those here for the parent window and all overlapped subwindows
6179 * of it. And we need to do this before setting the new clips as those will be
6182 gdk_window_flush_recursive (window->parent);
6186 /* Set the new position and size */
6192 if (!(width < 0 && height < 0))
6196 window->width = width;
6199 window->height = height;
6202 dx = window->x - old_x;
6203 dy = window->y - old_y;
6205 old_abs_x = window->abs_x;
6206 old_abs_y = window->abs_y;
6208 recompute_visible_regions (window, TRUE, FALSE);
6210 new_native_child_region = NULL;
6211 if (old_native_child_region)
6213 new_native_child_region = collect_native_child_region (window, TRUE);
6214 /* Adjust region to parent window coords */
6215 cairo_region_translate (new_native_child_region, window->x, window->y);
6218 if (gdk_window_has_impl (window))
6220 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6222 /* Do the actual move after recomputing things, as this will have set the shape to
6223 the now correct one, thus avoiding copying regions that should not be copied. */
6224 impl_class->move_resize (window, TRUE,
6225 window->x, window->y,
6226 window->width, window->height);
6228 else if (old_abs_x != window->abs_x ||
6229 old_abs_y != window->abs_y)
6230 move_native_children (window);
6234 new_region = cairo_region_copy (window->clip_region);
6235 /* Adjust region to parent window coords */
6236 cairo_region_translate (new_region, window->x, window->y);
6239 * Part of the data at the new location can be copied from the
6240 * old location, this area is the intersection of the old region
6241 * moved as the copy will move it and then intersected with
6245 * Everything in the old and new regions that is not copied must be
6246 * invalidated (including children) as this is newly exposed
6248 copy_area = cairo_region_copy (new_region);
6250 cairo_region_union (new_region, old_region);
6252 if (old_native_child_region)
6254 /* Don't copy from inside native children, as this is copied by
6255 * the native window move.
6257 cairo_region_subtract (old_region, old_native_child_region);
6259 cairo_region_translate (old_region, dx, dy);
6261 cairo_region_intersect (copy_area, old_region);
6263 if (new_native_child_region)
6265 /* Don't copy any bits that would cause a read from the moved
6266 native windows, as we can't read that data */
6267 cairo_region_translate (new_native_child_region, dx, dy);
6268 cairo_region_subtract (copy_area, new_native_child_region);
6269 cairo_region_translate (new_native_child_region, -dx, -dy);
6272 cairo_region_subtract (new_region, copy_area);
6274 /* Convert old region to impl coords */
6275 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6277 /* convert from parent coords to impl */
6278 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6280 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6282 /* Invalidate affected part in the parent window
6283 * (no higher window should be affected)
6284 * We also invalidate any children in that area, which could include
6285 * this window if it still overlaps that area.
6287 if (old_native_child_region)
6289 /* No need to expose the region that the native window move copies */
6290 cairo_region_translate (old_native_child_region, dx, dy);
6291 cairo_region_intersect (old_native_child_region, new_native_child_region);
6292 cairo_region_subtract (new_region, old_native_child_region);
6294 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6296 cairo_region_destroy (old_region);
6297 cairo_region_destroy (new_region);
6300 if (old_native_child_region)
6302 cairo_region_destroy (old_native_child_region);
6303 cairo_region_destroy (new_native_child_region);
6306 _gdk_synthesize_crossing_events_for_geometry_change (window);
6313 * @window: a #GdkWindow
6314 * @x: X coordinate relative to window's parent
6315 * @y: Y coordinate relative to window's parent
6317 * Repositions a window relative to its parent window.
6318 * For toplevel windows, window managers may ignore or modify the move;
6319 * you should probably use gtk_window_move() on a #GtkWindow widget
6320 * anyway, instead of using GDK functions. For child windows,
6321 * the move will reliably succeed.
6323 * If you're also planning to resize the window, use gdk_window_move_resize()
6324 * to both move and resize simultaneously, for a nicer visual effect.
6327 gdk_window_move (GdkWindow *window,
6331 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6335 * gdk_window_resize:
6336 * @window: a #GdkWindow
6337 * @width: new width of the window
6338 * @height: new height of the window
6340 * Resizes @window; for toplevel windows, asks the window manager to resize
6341 * the window. The window manager may not allow the resize. When using GTK+,
6342 * use gtk_window_resize() instead of this low-level GDK function.
6344 * Windows may not be resized below 1x1.
6346 * If you're also planning to move the window, use gdk_window_move_resize()
6347 * to both move and resize simultaneously, for a nicer visual effect.
6350 gdk_window_resize (GdkWindow *window,
6354 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6359 * gdk_window_move_resize:
6360 * @window: a #GdkWindow
6361 * @x: new X position relative to window's parent
6362 * @y: new Y position relative to window's parent
6364 * @height: new height
6366 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6367 * except that both operations are performed at once, avoiding strange
6368 * visual effects. (i.e. the user may be able to see the window first
6369 * move, then resize, if you don't use gdk_window_move_resize().)
6372 gdk_window_move_resize (GdkWindow *window,
6378 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6383 * gdk_window_scroll:
6384 * @window: a #GdkWindow
6385 * @dx: Amount to scroll in the X direction
6386 * @dy: Amount to scroll in the Y direction
6388 * Scroll the contents of @window, both pixels and children, by the
6389 * given amount. @window itself does not move. Portions of the window
6390 * that the scroll operation brings in from offscreen areas are
6391 * invalidated. The invalidated region may be bigger than what would
6392 * strictly be necessary.
6394 * For X11, a minimum area will be invalidated if the window has no
6395 * subwindows, or if the edges of the window's parent do not extend
6396 * beyond the edges of the window. In other cases, a multi-step process
6397 * is used to scroll the window which may produce temporary visual
6398 * artifacts and unnecessary invalidations.
6401 gdk_window_scroll (GdkWindow *window,
6405 GdkWindow *impl_window;
6406 cairo_region_t *copy_area, *noncopy_area;
6407 cairo_region_t *old_native_child_region, *new_native_child_region;
6410 g_return_if_fail (GDK_IS_WINDOW (window));
6412 if (dx == 0 && dy == 0)
6415 if (window->destroyed)
6418 gdk_window_flush_if_exposing (window);
6420 old_native_child_region = collect_native_child_region (window, FALSE);
6421 if (old_native_child_region)
6423 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6424 * source or destination for a delayed GdkWindowRegionMove. So, we need
6425 * to flush those here for the window and all overlapped subwindows
6426 * of it. And we need to do this before setting the new clips as those will be
6429 gdk_window_flush_recursive (window);
6433 /* First move all child windows, without causing invalidation */
6435 tmp_list = window->children;
6438 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6440 /* Just update the positions, the bits will move with the copy */
6444 tmp_list = tmp_list->next;
6447 recompute_visible_regions (window, FALSE, TRUE);
6449 new_native_child_region = NULL;
6450 if (old_native_child_region)
6451 new_native_child_region = collect_native_child_region (window, FALSE);
6453 move_native_children (window);
6455 /* Then copy the actual bits of the window w/ child windows */
6457 impl_window = gdk_window_get_impl_window (window);
6459 /* Calculate the area that can be gotten by copying the old area */
6460 copy_area = cairo_region_copy (window->clip_region);
6461 if (old_native_child_region)
6463 /* Don't copy from inside native children, as this is copied by
6464 * the native window move.
6466 cairo_region_subtract (copy_area, old_native_child_region);
6468 /* Don't copy any bits that would cause a read from the moved
6469 native windows, as we can't read that data */
6470 cairo_region_subtract (copy_area, new_native_child_region);
6472 cairo_region_translate (copy_area, dx, dy);
6473 cairo_region_intersect (copy_area, window->clip_region);
6475 /* And the rest need to be invalidated */
6476 noncopy_area = cairo_region_copy (window->clip_region);
6477 cairo_region_subtract (noncopy_area, copy_area);
6479 /* convert from window coords to impl */
6480 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6482 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6484 /* Invalidate not copied regions */
6485 if (old_native_child_region)
6487 /* No need to expose the region that the native window move copies */
6488 cairo_region_translate (old_native_child_region, dx, dy);
6489 cairo_region_intersect (old_native_child_region, new_native_child_region);
6490 cairo_region_subtract (noncopy_area, old_native_child_region);
6492 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6494 cairo_region_destroy (noncopy_area);
6496 if (old_native_child_region)
6498 cairo_region_destroy (old_native_child_region);
6499 cairo_region_destroy (new_native_child_region);
6502 _gdk_synthesize_crossing_events_for_geometry_change (window);
6506 * gdk_window_move_region:
6507 * @window: a #GdkWindow
6508 * @region: The #cairo_region_t to move
6509 * @dx: Amount to move in the X direction
6510 * @dy: Amount to move in the Y direction
6512 * Move the part of @window indicated by @region by @dy pixels in the Y
6513 * direction and @dx pixels in the X direction. The portions of @region
6514 * that not covered by the new position of @region are invalidated.
6516 * Child windows are not moved.
6521 gdk_window_move_region (GdkWindow *window,
6522 const cairo_region_t *region,
6526 GdkWindow *impl_window;
6527 cairo_region_t *nocopy_area;
6528 cairo_region_t *copy_area;
6530 g_return_if_fail (GDK_IS_WINDOW (window));
6531 g_return_if_fail (region != NULL);
6533 if (dx == 0 && dy == 0)
6536 if (window->destroyed)
6539 impl_window = gdk_window_get_impl_window (window);
6541 /* compute source regions */
6542 copy_area = cairo_region_copy (region);
6543 cairo_region_intersect (copy_area, window->clip_region_with_children);
6545 /* compute destination regions */
6546 cairo_region_translate (copy_area, dx, dy);
6547 cairo_region_intersect (copy_area, window->clip_region_with_children);
6549 /* Invalidate parts of the region (source and dest) not covered
6551 nocopy_area = cairo_region_copy (region);
6552 cairo_region_translate (nocopy_area, dx, dy);
6553 cairo_region_union (nocopy_area, region);
6554 cairo_region_subtract (nocopy_area, copy_area);
6556 /* convert from window coords to impl */
6557 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6558 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6560 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6561 cairo_region_destroy (nocopy_area);
6565 * gdk_window_set_background:
6566 * @window: a #GdkWindow
6567 * @color: a #GdkColor
6569 * Sets the background color of @window. (However, when using GTK+,
6570 * set the background of a widget with gtk_widget_modify_bg() - if
6571 * you're an application - or gtk_style_set_background() - if you're
6572 * implementing a custom widget.)
6574 * See also gdk_window_set_background_pattern().
6577 gdk_window_set_background (GdkWindow *window,
6578 const GdkColor *color)
6580 cairo_pattern_t *pattern;
6582 g_return_if_fail (GDK_IS_WINDOW (window));
6584 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6585 color->green / 65535.,
6586 color->blue / 65535.);
6588 gdk_window_set_background_pattern (window, pattern);
6590 cairo_pattern_destroy (pattern);
6594 * gdk_window_set_background_rgba:
6595 * @window: a #GdkWindow
6596 * @rgba: a #GdkRGBA color
6598 * Sets the background color of @window.
6600 * See also gdk_window_set_background_pattern().
6603 gdk_window_set_background_rgba (GdkWindow *window,
6606 cairo_pattern_t *pattern;
6608 g_return_if_fail (GDK_IS_WINDOW (window));
6609 g_return_if_fail (rgba != NULL);
6611 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6612 rgba->blue, rgba->alpha);
6614 gdk_window_set_background_pattern (window, pattern);
6616 cairo_pattern_destroy (pattern);
6620 * gdk_window_set_background_pattern:
6621 * @window: a #GdkWindow
6622 * @pattern: (allow-none): a pattern to use, or %NULL
6624 * Sets the background of @window.
6626 * A background of %NULL means that the window will inherit its
6627 * background form its parent window.
6629 * The windowing system will normally fill a window with its background
6630 * when the window is obscured then exposed.
6633 gdk_window_set_background_pattern (GdkWindow *window,
6634 cairo_pattern_t *pattern)
6636 g_return_if_fail (GDK_IS_WINDOW (window));
6639 cairo_pattern_reference (pattern);
6640 if (window->background)
6641 cairo_pattern_destroy (window->background);
6642 window->background = pattern;
6644 if (gdk_window_has_impl (window) &&
6645 !window->input_only)
6647 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6648 impl_class->set_background (window, pattern);
6653 * gdk_window_get_background_pattern:
6656 * Gets the pattern used to clear the background on @window. If @window
6657 * does not have its own background and reuses the parent's, %NULL is
6658 * returned and you'll have to query it yourself.
6660 * Returns: The pattern to use for the background or %NULL to use the
6661 * parent's background.
6666 gdk_window_get_background_pattern (GdkWindow *window)
6668 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6670 return window->background;
6674 update_cursor_foreach (GdkDisplay *display,
6676 GdkPointerWindowInfo *pointer_info,
6679 GdkWindow *window = user_data;
6681 if (_gdk_native_windows ||
6682 window->window_type == GDK_WINDOW_ROOT ||
6683 window->window_type == GDK_WINDOW_FOREIGN)
6684 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, window->cursor);
6685 else if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6686 update_cursor (display, device);
6690 * gdk_window_get_cursor:
6691 * @window: a #GdkWindow
6693 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6694 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6695 * there is no custom cursor set on the specified window, and it is
6696 * using the cursor for its parent window.
6698 * Return value: a #GdkCursor, or %NULL. The returned object is owned
6699 * by the #GdkWindow and should not be unreferenced directly. Use
6700 * gdk_window_set_cursor() to unset the cursor of the window
6705 gdk_window_get_cursor (GdkWindow *window)
6707 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6709 return window->cursor;
6713 * gdk_window_set_cursor:
6714 * @window: a #GdkWindow
6715 * @cursor: (allow-none): a cursor
6717 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6718 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6719 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6720 * to gdk_window_set_cursor() means that @window will use the cursor of its
6721 * parent window. Most windows should use this default.
6724 gdk_window_set_cursor (GdkWindow *window,
6727 GdkDisplay *display;
6729 g_return_if_fail (GDK_IS_WINDOW (window));
6731 display = gdk_window_get_display (window);
6735 gdk_cursor_unref (window->cursor);
6736 window->cursor = NULL;
6739 if (!GDK_WINDOW_DESTROYED (window))
6742 window->cursor = gdk_cursor_ref (cursor);
6744 _gdk_display_pointer_info_foreach (display,
6745 update_cursor_foreach,
6748 g_object_notify (G_OBJECT (window), "cursor");
6753 * gdk_window_get_device_cursor:
6754 * @window: a #GdkWindow.
6755 * @device: a #GdkDevice.
6757 * Retrieves a #GdkCursor pointer for the @device currently set on the
6758 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6759 * there is no custom cursor set on the specified window, and it is
6760 * using the cursor for its parent window.
6762 * Returns: a #GdkCursor, or %NULL. The returned object is owned
6763 * by the #GdkWindow and should not be unreferenced directly. Use
6764 * gdk_window_set_cursor() to unset the cursor of the window
6769 gdk_window_get_device_cursor (GdkWindow *window,
6772 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6773 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6775 return g_hash_table_lookup (window->device_cursor, device);
6779 * gdk_window_set_device_cursor:
6780 * @window: a #Gdkwindow
6781 * @device: a #GdkDevice
6782 * @cursor: a #GdkCursor
6784 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6785 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6786 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6787 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6788 * @window will use the cursor of its parent window. Most windows should
6794 gdk_window_set_device_cursor (GdkWindow *window,
6798 GdkDisplay *display;
6800 g_return_if_fail (GDK_IS_WINDOW (window));
6801 g_return_if_fail (GDK_IS_DEVICE (device));
6803 display = gdk_window_get_display (window);
6806 g_hash_table_remove (window->device_cursor, device);
6808 g_hash_table_replace (window->device_cursor, device, gdk_cursor_ref (cursor));
6810 if (!GDK_WINDOW_DESTROYED (window))
6812 GdkPointerWindowInfo *pointer_info;
6814 pointer_info = _gdk_display_get_pointer_info (display, device);
6816 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6817 update_cursor (display, device);
6822 * gdk_window_get_geometry:
6823 * @window: a #GdkWindow
6824 * @x: return location for X coordinate of window (relative to its parent)
6825 * @y: return location for Y coordinate of window (relative to its parent)
6826 * @width: return location for width of window
6827 * @height: return location for height of window
6828 * @depth: return location for bit depth of window
6830 * Any of the return location arguments to this function may be %NULL,
6831 * if you aren't interested in getting the value of that field.
6833 * The X and Y coordinates returned are relative to the parent window
6834 * of @window, which for toplevels usually means relative to the
6835 * window decorations (titlebar, etc.) rather than relative to the
6836 * root window (screen-size background window).
6838 * On the X11 platform, the geometry is obtained from the X server,
6839 * so reflects the latest position of @window; this may be out-of-sync
6840 * with the position of @window delivered in the most-recently-processed
6841 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6842 * position from the most recent configure event.
6845 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6846 * to call gdk_window_get_position(), gdk_window_get_width() and
6847 * gdk_window_get_height() instead, because it avoids the roundtrip to
6848 * the X server and because these functions support the full 32-bit
6849 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6850 * the 16-bit coordinates of X11.
6854 gdk_window_get_geometry (GdkWindow *window,
6862 GdkWindowImplClass *impl_class;
6866 GDK_NOTE (MULTIHEAD,
6867 g_message ("gdk_window_get_geometry(): Window needs "
6868 "to be non-NULL to be multi head safe"));
6869 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6872 g_return_if_fail (GDK_IS_WINDOW (window));
6874 if (!GDK_WINDOW_DESTROYED (window))
6876 if (gdk_window_has_impl (window))
6878 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6879 impl_class->get_geometry (window, x, y,
6882 /* This reports the position wrt to the native parent, we need to convert
6883 it to be relative to the client side parent */
6884 parent = window->parent;
6885 if (parent && !gdk_window_has_impl (parent))
6888 *x -= parent->abs_x;
6890 *y -= parent->abs_y;
6900 *width = window->width;
6902 *height = window->height;
6904 *depth = window->depth;
6910 * gdk_window_get_width:
6911 * @window: a #GdkWindow
6913 * Returns the width of the given @window.
6915 * On the X11 platform the returned size is the size reported in the
6916 * most-recently-processed configure event, rather than the current
6917 * size on the X server.
6919 * Returns: The width of @window
6924 gdk_window_get_width (GdkWindow *window)
6926 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6928 return window->width;
6932 * gdk_window_get_height:
6933 * @window: a #GdkWindow
6935 * Returns the height of the given @window.
6937 * On the X11 platform the returned size is the size reported in the
6938 * most-recently-processed configure event, rather than the current
6939 * size on the X server.
6941 * Returns: The height of @window
6946 gdk_window_get_height (GdkWindow *window)
6948 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6950 return window->height;
6954 * gdk_window_get_origin:
6955 * @window: a #GdkWindow
6956 * @x: return location for X coordinate
6957 * @y: return location for Y coordinate
6959 * Obtains the position of a window in root window coordinates.
6960 * (Compare with gdk_window_get_position() and
6961 * gdk_window_get_geometry() which return the position of a window
6962 * relative to its parent window.)
6964 * Return value: not meaningful, ignore
6967 gdk_window_get_origin (GdkWindow *window,
6971 GdkWindowImplClass *impl_class;
6973 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6975 if (GDK_WINDOW_DESTROYED (window))
6984 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6985 impl_class->get_root_coords (window,
6994 * gdk_window_get_root_coords:
6995 * @window: a #GdkWindow
6996 * @x: X coordinate in window
6997 * @y: Y coordinate in window
6998 * @root_x: return location for X coordinate
6999 * @root_y: return location for Y coordinate
7001 * Obtains the position of a window position in root
7002 * window coordinates. This is similar to
7003 * gdk_window_get_origin() but allows you go pass
7004 * in any position in the window, not just the origin.
7009 gdk_window_get_root_coords (GdkWindow *window,
7015 GdkWindowImplClass *impl_class;
7017 g_return_if_fail (GDK_IS_WINDOW (window));
7019 if (GDK_WINDOW_DESTROYED (window))
7028 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7029 impl_class->get_root_coords (window,
7036 * gdk_window_coords_to_parent:
7037 * @window: a child window
7038 * @x: X coordinate in child's coordinate system
7039 * @y: Y coordinate in child's coordinate system
7040 * @parent_x: (out) (allow-none): return location for X coordinate
7041 * in parent's coordinate system, or %NULL
7042 * @parent_y: (out) (allow-none): return location for Y coordinate
7043 * in parent's coordinate system, or %NULL
7045 * Transforms window coordinates from a child window to its parent
7046 * window, where the parent window is the normal parent as returned by
7047 * gdk_window_get_parent() for normal windows, and the window's
7048 * embedder as returned by gdk_offscreen_window_get_embedder() for
7049 * offscreen windows.
7051 * For normal windows, calling this function is equivalent to adding
7052 * the return values of gdk_window_get_position() to the child coordinates.
7053 * For offscreen windows however (which can be arbitrarily transformed),
7054 * this function calls the GdkWindow::to-embedder: signal to translate
7057 * You should always use this function when writing generic code that
7058 * walks up a window hierarchy.
7060 * See also: gdk_window_coords_from_parent()
7065 gdk_window_coords_to_parent (GdkWindow *window,
7071 g_return_if_fail (GDK_IS_WINDOW (window));
7073 if (gdk_window_is_offscreen (window))
7077 to_embedder (window, x, y, &px, &py);
7088 *parent_x = x + window->x;
7091 *parent_y = y + window->y;
7096 * gdk_window_coords_from_parent:
7097 * @window: a child window
7098 * @parent_x: X coordinate in parent's coordinate system
7099 * @parent_y: Y coordinate in parent's coordinate system
7100 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7101 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7103 * Transforms window coordinates from a parent window to a child
7104 * window, where the parent window is the normal parent as returned by
7105 * gdk_window_get_parent() for normal windows, and the window's
7106 * embedder as returned by gdk_offscreen_window_get_embedder() for
7107 * offscreen windows.
7109 * For normal windows, calling this function is equivalent to subtracting
7110 * the return values of gdk_window_get_position() from the parent coordinates.
7111 * For offscreen windows however (which can be arbitrarily transformed),
7112 * this function calls the GdkWindow::from-embedder: signal to translate
7115 * You should always use this function when writing generic code that
7116 * walks down a window hierarchy.
7118 * See also: gdk_window_coords_to_parent()
7123 gdk_window_coords_from_parent (GdkWindow *window,
7129 g_return_if_fail (GDK_IS_WINDOW (window));
7131 if (gdk_window_is_offscreen (window))
7135 from_embedder (window, parent_x, parent_y, &cx, &cy);
7146 *x = parent_x - window->x;
7149 *y = parent_y - window->y;
7154 * gdk_window_shape_combine_region:
7155 * @window: a #GdkWindow
7156 * @shape_region: region of window to be non-transparent
7157 * @offset_x: X position of @shape_region in @window coordinates
7158 * @offset_y: Y position of @shape_region in @window coordinates
7160 * Makes pixels in @window outside @shape_region be transparent,
7161 * so that the window may be nonrectangular.
7163 * If @shape_region is %NULL, the shape will be unset, so the whole
7164 * window will be opaque again. @offset_x and @offset_y are ignored
7165 * if @shape_region is %NULL.
7167 * On the X11 platform, this uses an X server extension which is
7168 * widely available on most common platforms, but not available on
7169 * very old X servers, and occasionally the implementation will be
7170 * buggy. On servers without the shape extension, this function
7173 * This function works on both toplevel and child windows.
7176 gdk_window_shape_combine_region (GdkWindow *window,
7177 const cairo_region_t *shape_region,
7181 cairo_region_t *old_region, *new_region, *diff;
7183 g_return_if_fail (GDK_IS_WINDOW (window));
7185 if (GDK_WINDOW_DESTROYED (window))
7188 window->shaped = (shape_region != NULL);
7191 cairo_region_destroy (window->shape);
7194 if (GDK_WINDOW_IS_MAPPED (window))
7195 old_region = cairo_region_copy (window->clip_region);
7199 window->shape = cairo_region_copy (shape_region);
7200 cairo_region_translate (window->shape, offset_x, offset_y);
7203 window->shape = NULL;
7205 recompute_visible_regions (window, TRUE, FALSE);
7207 if (gdk_window_has_impl (window) &&
7208 !should_apply_clip_as_shape (window))
7209 apply_shape (window, window->shape);
7213 new_region = cairo_region_copy (window->clip_region);
7215 /* New area in the window, needs invalidation */
7216 diff = cairo_region_copy (new_region);
7217 cairo_region_subtract (diff, old_region);
7219 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7221 cairo_region_destroy (diff);
7223 if (!gdk_window_is_toplevel (window))
7225 /* New area in the non-root parent window, needs invalidation */
7226 diff = cairo_region_copy (old_region);
7227 cairo_region_subtract (diff, new_region);
7229 /* Adjust region to parent window coords */
7230 cairo_region_translate (diff, window->x, window->y);
7232 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7234 cairo_region_destroy (diff);
7237 cairo_region_destroy (new_region);
7238 cairo_region_destroy (old_region);
7243 do_child_shapes (GdkWindow *window,
7247 cairo_region_t *region;
7251 r.width = window->width;
7252 r.height = window->height;
7254 region = cairo_region_create_rectangle (&r);
7255 remove_child_area (window, NULL, FALSE, region);
7257 if (merge && window->shape)
7258 cairo_region_subtract (region, window->shape);
7260 gdk_window_shape_combine_region (window, region, 0, 0);
7264 * gdk_window_set_child_shapes:
7265 * @window: a #GdkWindow
7267 * Sets the shape mask of @window to the union of shape masks
7268 * for all children of @window, ignoring the shape mask of @window
7269 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7270 * the shape mask of @window in the masks to be merged.
7273 gdk_window_set_child_shapes (GdkWindow *window)
7275 g_return_if_fail (GDK_IS_WINDOW (window));
7277 do_child_shapes (window, FALSE);
7281 * gdk_window_merge_child_shapes:
7282 * @window: a #GdkWindow
7284 * Merges the shape masks for any child windows into the
7285 * shape mask for @window. i.e. the union of all masks
7286 * for @window and its children will become the new mask
7287 * for @window. See gdk_window_shape_combine_region().
7289 * This function is distinct from gdk_window_set_child_shapes()
7290 * because it includes @window's shape mask in the set of shapes to
7294 gdk_window_merge_child_shapes (GdkWindow *window)
7296 g_return_if_fail (GDK_IS_WINDOW (window));
7298 do_child_shapes (window, TRUE);
7302 * gdk_window_input_shape_combine_region:
7303 * @window: a #GdkWindow
7304 * @shape_region: region of window to be non-transparent
7305 * @offset_x: X position of @shape_region in @window coordinates
7306 * @offset_y: Y position of @shape_region in @window coordinates
7308 * Like gdk_window_shape_combine_region(), but the shape applies
7309 * only to event handling. Mouse events which happen while
7310 * the pointer position corresponds to an unset bit in the
7311 * mask will be passed on the window below @window.
7313 * An input shape is typically used with RGBA windows.
7314 * The alpha channel of the window defines which pixels are
7315 * invisible and allows for nicely antialiased borders,
7316 * and the input shape controls where the window is
7319 * On the X11 platform, this requires version 1.1 of the
7322 * On the Win32 platform, this functionality is not present and the
7323 * function does nothing.
7328 gdk_window_input_shape_combine_region (GdkWindow *window,
7329 const cairo_region_t *shape_region,
7333 GdkWindowImplClass *impl_class;
7335 g_return_if_fail (GDK_IS_WINDOW (window));
7337 if (GDK_WINDOW_DESTROYED (window))
7340 if (window->input_shape)
7341 cairo_region_destroy (window->input_shape);
7345 window->input_shape = cairo_region_copy (shape_region);
7346 cairo_region_translate (window->input_shape, offset_x, offset_y);
7349 window->input_shape = NULL;
7351 if (gdk_window_has_impl (window))
7353 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7354 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7357 /* Pointer may have e.g. moved outside window due to the input mask change */
7358 _gdk_synthesize_crossing_events_for_geometry_change (window);
7362 do_child_input_shapes (GdkWindow *window,
7366 cairo_region_t *region;
7370 r.width = window->width;
7371 r.height = window->height;
7373 region = cairo_region_create_rectangle (&r);
7374 remove_child_area (window, NULL, TRUE, region);
7376 if (merge && window->shape)
7377 cairo_region_subtract (region, window->shape);
7378 if (merge && window->input_shape)
7379 cairo_region_subtract (region, window->input_shape);
7381 gdk_window_input_shape_combine_region (window, region, 0, 0);
7386 * gdk_window_set_child_input_shapes:
7387 * @window: a #GdkWindow
7389 * Sets the input shape mask of @window to the union of input shape masks
7390 * for all children of @window, ignoring the input shape mask of @window
7391 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7392 * the input shape mask of @window in the masks to be merged.
7397 gdk_window_set_child_input_shapes (GdkWindow *window)
7399 g_return_if_fail (GDK_IS_WINDOW (window));
7401 do_child_input_shapes (window, FALSE);
7405 * gdk_window_merge_child_input_shapes:
7406 * @window: a #GdkWindow
7408 * Merges the input shape masks for any child windows into the
7409 * input shape mask for @window. i.e. the union of all input masks
7410 * for @window and its children will become the new input mask
7411 * for @window. See gdk_window_input_shape_combine_region().
7413 * This function is distinct from gdk_window_set_child_input_shapes()
7414 * because it includes @window's input shape mask in the set of
7415 * shapes to be merged.
7420 gdk_window_merge_child_input_shapes (GdkWindow *window)
7422 g_return_if_fail (GDK_IS_WINDOW (window));
7424 do_child_input_shapes (window, TRUE);
7429 * gdk_window_set_static_gravities:
7430 * @window: a #GdkWindow
7431 * @use_static: %TRUE to turn on static gravity
7433 * Set the bit gravity of the given window to static, and flag it so
7434 * all children get static subwindow gravity. This is used if you are
7435 * implementing scary features that involve deep knowledge of the
7436 * windowing system. Don't worry about it unless you have to.
7438 * Return value: %TRUE if the server supports static gravity
7441 gdk_window_set_static_gravities (GdkWindow *window,
7442 gboolean use_static)
7444 GdkWindowImplClass *impl_class;
7446 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7448 if (gdk_window_has_impl (window))
7450 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7451 return impl_class->set_static_gravities (window, use_static);
7458 * gdk_window_get_composited:
7459 * @window: a #GdkWindow
7461 * Determines whether @window is composited.
7463 * See gdk_window_set_composited().
7465 * Returns: %TRUE if the window is composited.
7470 gdk_window_get_composited (GdkWindow *window)
7472 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7474 return window->composited;
7478 * gdk_window_set_composited:
7479 * @window: a #GdkWindow
7480 * @composited: %TRUE to set the window as composited
7482 * Sets a #GdkWindow as composited, or unsets it. Composited
7483 * windows do not automatically have their contents drawn to
7484 * the screen. Drawing is redirected to an offscreen buffer
7485 * and an expose event is emitted on the parent of the composited
7486 * window. It is the responsibility of the parent's expose handler
7487 * to manually merge the off-screen content onto the screen in
7488 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7491 * It only makes sense for child windows to be composited; see
7492 * gdk_window_set_opacity() if you need translucent toplevel
7495 * An additional effect of this call is that the area of this
7496 * window is no longer clipped from regions marked for
7497 * invalidation on its parent. Draws done on the parent
7498 * window are also no longer clipped by the child.
7500 * This call is only supported on some systems (currently,
7501 * only X11 with new enough Xcomposite and Xdamage extensions).
7502 * You must call gdk_display_supports_composite() to check if
7503 * setting a window as composited is supported before
7504 * attempting to do so.
7509 gdk_window_set_composited (GdkWindow *window,
7510 gboolean composited)
7512 GdkDisplay *display;
7514 g_return_if_fail (GDK_IS_WINDOW (window));
7516 composited = composited != FALSE;
7518 if (window->composited == composited)
7522 gdk_window_ensure_native (window);
7524 display = gdk_window_get_display (window);
7526 if (!gdk_display_supports_composite (display) && composited)
7528 g_warning ("gdk_window_set_composited called but "
7529 "compositing is not supported");
7533 _gdk_windowing_window_set_composited (window, composited);
7535 recompute_visible_regions (window, TRUE, FALSE);
7537 if (GDK_WINDOW_IS_MAPPED (window))
7538 gdk_window_invalidate_in_parent (window);
7540 window->composited = composited;
7544 * gdk_window_get_modal_hint:
7545 * @window: A toplevel #GdkWindow.
7547 * Determines whether or not the window manager is hinted that @window
7548 * has modal behaviour.
7550 * Return value: whether or not the window has the modal hint set.
7555 gdk_window_get_modal_hint (GdkWindow *window)
7557 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7559 return window->modal_hint;
7563 * gdk_window_get_accept_focus:
7564 * @window: a toplevel #GdkWindow.
7566 * Determines whether or not the desktop environment shuld be hinted that
7567 * the window does not want to receive input focus.
7569 * Return value: whether or not the window should receive input focus.
7574 gdk_window_get_accept_focus (GdkWindow *window)
7576 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7578 return window->accept_focus;
7582 * gdk_window_get_focus_on_map:
7583 * @window: a toplevel #GdkWindow.
7585 * Determines whether or not the desktop environment should be hinted that the
7586 * window does not want to receive input focus when it is mapped.
7588 * Return value: whether or not the window wants to receive input focus when
7594 gdk_window_get_focus_on_map (GdkWindow *window)
7596 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7598 return window->focus_on_map;
7602 * gdk_window_is_input_only:
7603 * @window: a toplevel #GdkWindow
7605 * Determines whether or not the window is an input only window.
7607 * Return value: %TRUE if @window is input only
7612 gdk_window_is_input_only (GdkWindow *window)
7614 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7616 return window->input_only;
7620 * gdk_window_is_shaped:
7621 * @window: a toplevel #GdkWindow
7623 * Determines whether or not the window is shaped.
7625 * Return value: %TRUE if @window is shaped
7630 gdk_window_is_shaped (GdkWindow *window)
7632 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7634 return window->shaped;
7638 window_get_size_rectangle (GdkWindow *window,
7641 rect->x = rect->y = 0;
7642 rect->width = window->width;
7643 rect->height = window->height;
7646 /* Calculates the real clipping region for a window, in window coordinates,
7647 * taking into account other windows, gc clip region and gc clip mask.
7650 _gdk_window_calculate_full_clip_region (GdkWindow *window,
7651 GdkWindow *base_window,
7652 gboolean do_children,
7653 gint *base_x_offset,
7654 gint *base_y_offset)
7656 GdkRectangle visible_rect;
7657 cairo_region_t *real_clip_region;
7658 gint x_offset, y_offset;
7659 GdkWindow *parentwin, *lastwin;
7666 if (!window->viewable || window->input_only)
7667 return cairo_region_create ();
7669 window_get_size_rectangle (window, &visible_rect);
7671 /* real_clip_region is in window coordinates */
7672 real_clip_region = cairo_region_create_rectangle (&visible_rect);
7674 x_offset = y_offset = 0;
7678 parentwin = lastwin;
7680 parentwin = lastwin->parent;
7682 /* Remove the areas of all overlapping windows above parentwin in the hiearachy */
7683 for (; parentwin != NULL &&
7684 (parentwin == window || lastwin != base_window);
7685 lastwin = parentwin, parentwin = lastwin->parent)
7688 GdkRectangle real_clip_rect;
7690 if (parentwin != window)
7692 x_offset += lastwin->x;
7693 y_offset += lastwin->y;
7696 /* children is ordered in reverse stack order */
7697 for (cur = parentwin->children;
7698 cur && cur->data != lastwin;
7701 GdkWindow *child = cur->data;
7703 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
7706 /* Ignore offscreen children, as they don't draw in their parent and
7707 * don't take part in the clipping */
7708 if (gdk_window_is_offscreen (child))
7711 window_get_size_rectangle (child, &visible_rect);
7713 /* Convert rect to "window" coords */
7714 visible_rect.x += child->x - x_offset;
7715 visible_rect.y += child->y - y_offset;
7717 /* This shortcut is really necessary for performance when there are a lot of windows */
7718 cairo_region_get_extents (real_clip_region, &real_clip_rect);
7719 if (visible_rect.x >= real_clip_rect.x + real_clip_rect.width ||
7720 visible_rect.x + visible_rect.width <= real_clip_rect.x ||
7721 visible_rect.y >= real_clip_rect.y + real_clip_rect.height ||
7722 visible_rect.y + visible_rect.height <= real_clip_rect.y)
7725 cairo_region_subtract_rectangle (real_clip_region, &visible_rect);
7728 /* Clip to the parent */
7729 window_get_size_rectangle ((GdkWindow *)parentwin, &visible_rect);
7730 /* Convert rect to "window" coords */
7731 visible_rect.x += - x_offset;
7732 visible_rect.y += - y_offset;
7734 cairo_region_intersect_rectangle (real_clip_region, &visible_rect);
7738 *base_x_offset = x_offset;
7740 *base_y_offset = y_offset;
7742 return real_clip_region;
7746 _gdk_window_add_damage (GdkWindow *toplevel,
7747 cairo_region_t *damaged_region)
7749 GdkDisplay *display;
7750 GdkEvent event = { 0, };
7751 event.expose.type = GDK_DAMAGE;
7752 event.expose.window = toplevel;
7753 event.expose.send_event = FALSE;
7754 event.expose.region = damaged_region;
7755 cairo_region_get_extents (event.expose.region, &event.expose.area);
7756 display = gdk_window_get_display (event.expose.window);
7757 _gdk_event_queue_append (display, gdk_event_copy (&event));
7760 /* Gets the toplevel for a window as used for events,
7761 i.e. including offscreen parents */
7763 get_event_parent (GdkWindow *window)
7765 if (gdk_window_is_offscreen (window))
7766 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7768 return window->parent;
7771 /* Gets the toplevel for a window as used for events,
7772 i.e. including offscreen parents going up to the native
7775 get_event_toplevel (GdkWindow *window)
7779 while ((parent = get_event_parent (window)) != NULL &&
7780 (parent->window_type != GDK_WINDOW_ROOT))
7787 _gdk_window_event_parent_of (GdkWindow *parent,
7798 w = get_event_parent (w);
7805 update_cursor (GdkDisplay *display,
7808 GdkWindow *cursor_window, *parent, *toplevel;
7809 GdkWindow *pointer_window;
7810 GdkWindowImplClass *impl_class;
7811 GdkPointerWindowInfo *pointer_info;
7812 GdkDeviceGrabInfo *grab;
7815 pointer_info = _gdk_display_get_pointer_info (display, device);
7816 pointer_window = pointer_info->window_under_pointer;
7818 /* We ignore the serials here and just pick the last grab
7819 we've sent, as that would shortly be used anyway. */
7820 grab = _gdk_display_get_last_device_grab (display, device);
7823 /* the pointer is not in a descendant of the grab window */
7824 !_gdk_window_event_parent_of (grab->window, pointer_window))
7826 /* use the cursor from the grab window */
7827 cursor_window = grab->window;
7831 /* otherwise use the cursor from the pointer window */
7832 cursor_window = pointer_window;
7835 /* Find the first window with the cursor actually set, as
7836 the cursor is inherited from the parent */
7837 while (cursor_window->cursor == NULL &&
7838 (parent = get_event_parent (cursor_window)) != NULL &&
7839 parent->window_type != GDK_WINDOW_ROOT)
7840 cursor_window = parent;
7842 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7845 cursor = cursor_window->cursor;
7847 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7848 * which native window has what cursor set. */
7849 toplevel = get_event_toplevel (pointer_window);
7850 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7851 impl_class->set_device_cursor (toplevel, device, cursor);
7855 point_in_window (GdkWindow *window,
7860 x >= 0 && x < window->width &&
7861 y >= 0 && y < window->height &&
7862 (window->shape == NULL ||
7863 cairo_region_contains_point (window->shape,
7865 (window->input_shape == NULL ||
7866 cairo_region_contains_point (window->input_shape,
7871 convert_native_coords_to_toplevel (GdkWindow *window,
7874 gdouble *toplevel_x,
7875 gdouble *toplevel_y)
7882 while (!gdk_window_is_toplevel (window))
7886 window = window->parent;
7896 convert_toplevel_coords_to_window (GdkWindow *window,
7904 GList *children, *l;
7910 while ((parent = get_event_parent (window)) != NULL &&
7911 (parent->window_type != GDK_WINDOW_ROOT))
7913 children = g_list_prepend (children, window);
7917 for (l = children; l != NULL; l = l->next)
7918 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7920 g_list_free (children);
7927 pick_embedded_child (GdkWindow *window,
7934 g_signal_emit (window,
7935 signals[PICK_EMBEDDED_CHILD], 0,
7942 _gdk_window_find_child_at (GdkWindow *window,
7947 double child_x, child_y;
7950 if (point_in_window (window, x, y))
7952 /* Children is ordered in reverse stack order, i.e. first is topmost */
7953 for (l = window->children; l != NULL; l = l->next)
7957 if (!GDK_WINDOW_IS_MAPPED (sub))
7960 gdk_window_coords_from_parent ((GdkWindow *)sub,
7962 &child_x, &child_y);
7963 if (point_in_window (sub, child_x, child_y))
7964 return (GdkWindow *)sub;
7967 if (window->num_offscreen_children > 0)
7969 sub = pick_embedded_child (window,
7972 return (GdkWindow *)sub;
7980 _gdk_window_find_descendant_at (GdkWindow *window,
7987 gdouble child_x, child_y;
7991 if (point_in_window (window, x, y))
7996 /* Children is ordered in reverse stack order, i.e. first is topmost */
7997 for (l = window->children; l != NULL; l = l->next)
8001 if (!GDK_WINDOW_IS_MAPPED (sub))
8004 gdk_window_coords_from_parent ((GdkWindow *)sub,
8006 &child_x, &child_y);
8007 if (point_in_window (sub, child_x, child_y))
8017 window->num_offscreen_children > 0)
8019 sub = pick_embedded_child (window,
8025 from_embedder (sub, x, y, &x, &y);
8033 /* Not in window at all */
8047 * @window: a toplevel #GdkWindow
8049 * Emits a short beep associated to @window in the appropriate
8050 * display, if supported. Otherwise, emits a short beep on
8051 * the display just as gdk_display_beep().
8056 gdk_window_beep (GdkWindow *window)
8058 GdkDisplay *display;
8059 GdkWindow *toplevel;
8061 g_return_if_fail (GDK_IS_WINDOW (window));
8063 if (GDK_WINDOW_DESTROYED (window))
8066 toplevel = get_event_toplevel (window);
8067 display = gdk_window_get_display (window);
8069 if (toplevel && !gdk_window_is_offscreen (toplevel))
8070 _gdk_windowing_window_beep (toplevel);
8072 gdk_display_beep (display);
8076 * gdk_window_set_support_multidevice:
8077 * @window: a #GdkWindow.
8078 * @support_multidevice: %TRUE to enable multidevice support in @window.
8080 * This function will enable multidevice features in @window.
8082 * Multidevice aware windows will need to handle properly multiple,
8083 * per device enter/leave events, device grabs and grab ownerships.
8088 gdk_window_set_support_multidevice (GdkWindow *window,
8089 gboolean support_multidevice)
8091 g_return_if_fail (GDK_IS_WINDOW (window));
8093 if (GDK_WINDOW_DESTROYED (window))
8096 if (window->support_multidevice == support_multidevice)
8099 window->support_multidevice = support_multidevice;
8101 /* FIXME: What to do if called when some pointers are inside the window ? */
8105 * gdk_window_get_support_multidevice:
8106 * @window: a #GdkWindow.
8108 * Returns %TRUE if the window is aware of the existence of multiple
8111 * Returns: %TRUE if the window handles multidevice features.
8116 gdk_window_get_support_multidevice (GdkWindow *window)
8118 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8120 if (GDK_WINDOW_DESTROYED (window))
8123 return window->support_multidevice;
8126 static const guint type_masks[] = {
8127 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8128 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8129 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8130 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8131 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8132 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8133 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8134 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8135 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8136 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8137 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8138 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8139 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8140 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8141 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8142 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8143 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8144 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8145 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8146 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8147 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8148 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8149 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8150 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8151 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8152 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8153 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8154 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8155 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8156 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8157 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8158 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8159 0, /* GDK_WINDOW_STATE = 32 */
8160 0, /* GDK_SETTING = 33 */
8161 0, /* GDK_OWNER_CHANGE = 34 */
8162 0, /* GDK_GRAB_BROKEN = 35 */
8163 0, /* GDK_DAMAGE = 36 */
8165 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8167 /* send motion events if the right buttons are down */
8169 update_evmask_for_button_motion (guint evmask,
8170 GdkModifierType mask)
8172 if (evmask & GDK_BUTTON_MOTION_MASK &&
8173 mask & (GDK_BUTTON1_MASK |
8178 evmask |= GDK_POINTER_MOTION_MASK;
8180 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8181 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8182 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8183 evmask |= GDK_POINTER_MOTION_MASK;
8189 is_button_type (GdkEventType type)
8191 return type == GDK_BUTTON_PRESS ||
8192 type == GDK_2BUTTON_PRESS ||
8193 type == GDK_3BUTTON_PRESS ||
8194 type == GDK_BUTTON_RELEASE ||
8199 is_motion_type (GdkEventType type)
8201 return type == GDK_MOTION_NOTIFY ||
8202 type == GDK_ENTER_NOTIFY ||
8203 type == GDK_LEAVE_NOTIFY;
8207 find_common_ancestor (GdkWindow *win1,
8211 GList *path1 = NULL, *path2 = NULL;
8212 GList *list1, *list2;
8215 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8217 path1 = g_list_prepend (path1, tmp);
8218 tmp = get_event_parent (tmp);
8222 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8224 path2 = g_list_prepend (path2, tmp);
8225 tmp = get_event_parent (tmp);
8231 while (list1 && list2 && (list1->data == list2->data))
8234 list1 = g_list_next (list1);
8235 list2 = g_list_next (list2);
8237 g_list_free (path1);
8238 g_list_free (path2);
8244 _gdk_make_event (GdkWindow *window,
8246 GdkEvent *event_in_queue,
8247 gboolean before_event)
8249 GdkEvent *event = gdk_event_new (type);
8251 GdkModifierType the_state;
8253 the_time = gdk_event_get_time (event_in_queue);
8254 gdk_event_get_state (event_in_queue, &the_state);
8256 event->any.window = g_object_ref (window);
8257 event->any.send_event = FALSE;
8258 if (event_in_queue && event_in_queue->any.send_event)
8259 event->any.send_event = TRUE;
8263 case GDK_MOTION_NOTIFY:
8264 event->motion.time = the_time;
8265 event->motion.axes = NULL;
8266 event->motion.state = the_state;
8269 case GDK_BUTTON_PRESS:
8270 case GDK_2BUTTON_PRESS:
8271 case GDK_3BUTTON_PRESS:
8272 case GDK_BUTTON_RELEASE:
8273 event->button.time = the_time;
8274 event->button.axes = NULL;
8275 event->button.state = the_state;
8279 event->scroll.time = the_time;
8280 event->scroll.state = the_state;
8284 case GDK_KEY_RELEASE:
8285 event->key.time = the_time;
8286 event->key.state = the_state;
8289 case GDK_ENTER_NOTIFY:
8290 case GDK_LEAVE_NOTIFY:
8291 event->crossing.time = the_time;
8292 event->crossing.state = the_state;
8295 case GDK_PROPERTY_NOTIFY:
8296 event->property.time = the_time;
8297 event->property.state = the_state;
8300 case GDK_SELECTION_CLEAR:
8301 case GDK_SELECTION_REQUEST:
8302 case GDK_SELECTION_NOTIFY:
8303 event->selection.time = the_time;
8306 case GDK_PROXIMITY_IN:
8307 case GDK_PROXIMITY_OUT:
8308 event->proximity.time = the_time;
8311 case GDK_DRAG_ENTER:
8312 case GDK_DRAG_LEAVE:
8313 case GDK_DRAG_MOTION:
8314 case GDK_DRAG_STATUS:
8315 case GDK_DROP_START:
8316 case GDK_DROP_FINISHED:
8317 event->dnd.time = the_time;
8320 case GDK_FOCUS_CHANGE:
8324 case GDK_CLIENT_EVENT:
8325 case GDK_VISIBILITY_NOTIFY:
8337 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8339 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8342 _gdk_event_queue_append (gdk_window_get_display (window), event);
8348 send_crossing_event (GdkDisplay *display,
8349 GdkWindow *toplevel,
8352 GdkCrossingMode mode,
8353 GdkNotifyType notify_type,
8354 GdkWindow *subwindow,
8358 GdkModifierType mask,
8360 GdkEvent *event_in_queue,
8364 guint32 window_event_mask, type_event_mask;
8365 GdkDeviceGrabInfo *grab;
8366 gboolean block_event = FALSE;
8368 grab = _gdk_display_has_device_grab (display, device, serial);
8371 !grab->owner_events)
8373 /* !owner_event => only report events wrt grab window, ignore rest */
8374 if ((GdkWindow *)window != grab->window)
8376 window_event_mask = grab->event_mask;
8379 window_event_mask = window->event_mask;
8381 if (type == GDK_LEAVE_NOTIFY)
8383 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8384 window->devices_inside = g_list_remove (window->devices_inside, device);
8386 if (!window->support_multidevice && window->devices_inside)
8388 /* Block leave events unless it's the last pointer */
8394 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8396 if (!window->support_multidevice && window->devices_inside)
8398 /* Only emit enter events for the first device */
8402 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8403 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8404 !g_list_find (window->devices_inside, device))
8405 window->devices_inside = g_list_prepend (window->devices_inside, device);
8411 if (window_event_mask & type_event_mask)
8413 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8414 gdk_event_set_device (event, device);
8415 event->crossing.time = time_;
8416 event->crossing.subwindow = subwindow;
8418 g_object_ref (subwindow);
8419 convert_toplevel_coords_to_window ((GdkWindow *)window,
8420 toplevel_x, toplevel_y,
8421 &event->crossing.x, &event->crossing.y);
8422 event->crossing.x_root = toplevel_x + toplevel->x;
8423 event->crossing.y_root = toplevel_y + toplevel->y;
8424 event->crossing.mode = mode;
8425 event->crossing.detail = notify_type;
8426 event->crossing.focus = FALSE;
8427 event->crossing.state = mask;
8432 /* The coordinates are in the toplevel window that src/dest are in.
8433 * src and dest are always (if != NULL) in the same toplevel, as
8434 * we get a leave-notify and set the window_under_pointer to null
8435 * before crossing to another toplevel.
8438 _gdk_synthesize_crossing_events (GdkDisplay *display,
8442 GdkCrossingMode mode,
8445 GdkModifierType mask,
8447 GdkEvent *event_in_queue,
8449 gboolean non_linear)
8452 GdkWindow *win, *last, *next;
8456 GdkWindow *toplevel;
8457 GdkNotifyType notify_type;
8459 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8464 return; /* No crossings generated between src and dest */
8466 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8468 if (a && gdk_window_get_device_events (src, device) == 0)
8471 if (b && gdk_window_get_device_events (dest, device) == 0)
8478 c = find_common_ancestor (a, b);
8480 non_linear |= (c != a) && (c != b);
8482 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8484 toplevel = gdk_window_get_toplevel (a);
8486 /* Traverse up from a to (excluding) c sending leave events */
8488 notify_type = GDK_NOTIFY_NONLINEAR;
8490 notify_type = GDK_NOTIFY_INFERIOR;
8492 notify_type = GDK_NOTIFY_ANCESTOR;
8493 send_crossing_event (display, toplevel,
8494 a, GDK_LEAVE_NOTIFY,
8498 toplevel_x, toplevel_y,
8506 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8508 notify_type = GDK_NOTIFY_VIRTUAL;
8511 win = get_event_parent (a);
8512 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8514 send_crossing_event (display, toplevel,
8515 win, GDK_LEAVE_NOTIFY,
8520 toplevel_x, toplevel_y,
8526 win = get_event_parent (win);
8531 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8533 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8535 /* Traverse down from c to b */
8539 win = get_event_parent (b);
8540 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8542 path = g_list_prepend (path, win);
8543 win = get_event_parent (win);
8547 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8549 notify_type = GDK_NOTIFY_VIRTUAL;
8555 list = g_list_next (list);
8561 send_crossing_event (display, toplevel,
8562 win, GDK_ENTER_NOTIFY,
8567 toplevel_x, toplevel_y,
8577 notify_type = GDK_NOTIFY_NONLINEAR;
8579 notify_type = GDK_NOTIFY_ANCESTOR;
8581 notify_type = GDK_NOTIFY_INFERIOR;
8583 send_crossing_event (display, toplevel,
8584 b, GDK_ENTER_NOTIFY,
8589 toplevel_x, toplevel_y,
8596 /* Returns the window inside the event window with the pointer in it
8597 * at the specified coordinates, or NULL if its not in any child of
8598 * the toplevel. It also takes into account !owner_events grabs.
8601 get_pointer_window (GdkDisplay *display,
8602 GdkWindow *event_window,
8608 GdkWindow *pointer_window;
8609 GdkDeviceGrabInfo *grab;
8610 GdkPointerWindowInfo *pointer_info;
8612 pointer_info = _gdk_display_get_pointer_info (display, device);
8614 if (event_window == pointer_info->toplevel_under_pointer)
8616 _gdk_window_find_descendant_at (event_window,
8617 toplevel_x, toplevel_y,
8620 pointer_window = NULL;
8622 grab = _gdk_display_has_device_grab (display, device, serial);
8624 !grab->owner_events &&
8625 pointer_window != grab->window)
8626 pointer_window = NULL;
8628 return pointer_window;
8632 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8636 GdkPointerWindowInfo *device_info;
8638 /* We don't track this if all native, and it can cause issues
8639 with the update_cursor call below */
8640 if (_gdk_native_windows)
8643 device_info = _gdk_display_get_pointer_info (display, device);
8645 if (device_info->window_under_pointer)
8646 g_object_unref (device_info->window_under_pointer);
8647 device_info->window_under_pointer = window;
8651 g_object_ref (window);
8652 update_cursor (display, device);
8655 _gdk_display_enable_motion_hints (display, device);
8660 * @window: the #GdkWindow which will own the grab (the grab window).
8661 * @owner_events: if %FALSE then all pointer events are reported with respect to
8662 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8663 * events for this application are reported as normal, but pointer events outside
8664 * this application are reported with respect to @window and only if selected by
8665 * @event_mask. In either mode, unreported events are discarded.
8666 * @event_mask: specifies the event mask, which is used in accordance with
8667 * @owner_events. Note that only pointer events (i.e. button and motion events)
8669 * @confine_to: If non-%NULL, the pointer will be confined to this
8670 * window during the grab. If the pointer is outside @confine_to, it will
8671 * automatically be moved to the closest edge of @confine_to and enter
8672 * and leave events will be generated as necessary.
8673 * @cursor: the cursor to display while the grab is active. If this is %NULL then
8674 * the normal cursors are used for @window and its descendants, and the cursor
8675 * for @window is used for all other windows.
8676 * @time_: the timestamp of the event which led to this pointer grab. This usually
8677 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8678 * the time isn't known.
8680 * Grabs the pointer (usually a mouse) so that all events are passed to this
8681 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8682 * the grab window becomes unviewable.
8683 * This overrides any previous pointer grab by this client.
8685 * Pointer grabs are used for operations which need complete control over mouse
8686 * events, even if the mouse leaves the application.
8687 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8688 * the #GtkHPaned and #GtkVPaned widgets.
8690 * Note that if the event mask of an X window has selected both button press and
8691 * button release events, then a button press event will cause an automatic
8692 * pointer grab until the button is released.
8693 * X does this automatically since most applications expect to receive button
8694 * press and release events in pairs.
8695 * It is equivalent to a pointer grab on the window with @owner_events set to
8698 * If you set up anything at the time you take the grab that needs to be cleaned
8699 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8700 * are emitted when the grab ends unvoluntarily.
8702 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8704 * Deprecated: 3.0: Use gdk_device_grab() instead.
8707 gdk_pointer_grab (GdkWindow * window,
8708 gboolean owner_events,
8709 GdkEventMask event_mask,
8710 GdkWindow * confine_to,
8715 GdkDisplay *display;
8716 GdkDeviceManager *device_manager;
8718 GdkGrabStatus res = 0;
8720 GList *devices, *dev;
8722 g_return_val_if_fail (window != NULL, 0);
8723 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8724 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8726 /* We need a native window for confine to to work, ensure we have one */
8729 if (!gdk_window_ensure_native (confine_to))
8731 g_warning ("Can't confine to grabbed window, not native");
8736 /* Non-viewable client side window => fail */
8737 if (!_gdk_window_has_impl (window) &&
8738 !gdk_window_is_viewable (window))
8739 return GDK_GRAB_NOT_VIEWABLE;
8741 if (_gdk_native_windows)
8744 native = gdk_window_get_toplevel (window);
8745 while (gdk_window_is_offscreen (native))
8747 native = gdk_offscreen_window_get_embedder (native);
8749 if (native == NULL ||
8750 (!_gdk_window_has_impl (native) &&
8751 !gdk_window_is_viewable (native)))
8752 return GDK_GRAB_NOT_VIEWABLE;
8754 native = gdk_window_get_toplevel (native);
8757 display = gdk_window_get_display (window);
8759 serial = _gdk_windowing_window_get_next_serial (display);
8760 device_manager = gdk_display_get_device_manager (display);
8761 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8763 /* FIXME: Should this be generic to all backends? */
8764 /* FIXME: What happens with extended devices? */
8765 for (dev = devices; dev; dev = dev->next)
8769 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8772 res = _gdk_windowing_device_grab (device,
8776 get_native_grab_event_mask (event_mask),
8781 if (res == GDK_GRAB_SUCCESS)
8782 _gdk_display_add_device_grab (display,
8794 /* FIXME: handle errors when grabbing */
8796 g_list_free (devices);
8802 * gdk_keyboard_grab:
8803 * @window: the #GdkWindow which will own the grab (the grab window).
8804 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8805 * @window. If %TRUE then keyboard events for this application are
8806 * reported as normal, but keyboard events outside this application
8807 * are reported with respect to @window. Both key press and key
8808 * release events are always reported, independant of the event mask
8809 * set by the application.
8810 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8813 * Grabs the keyboard so that all events are passed to this
8814 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8815 * This overrides any previous keyboard grab by this client.
8817 * If you set up anything at the time you take the grab that needs to be cleaned
8818 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8819 * are emitted when the grab ends unvoluntarily.
8821 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8823 * Deprecated: 3.0: Use gdk_device_grab() instead.
8826 gdk_keyboard_grab (GdkWindow *window,
8827 gboolean owner_events,
8831 GdkDisplay *display;
8832 GdkDeviceManager *device_manager;
8834 GdkGrabStatus res = 0;
8836 GList *devices, *dev;
8838 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8840 /* Non-viewable client side window => fail */
8841 if (!_gdk_window_has_impl (window) &&
8842 !gdk_window_is_viewable (window))
8843 return GDK_GRAB_NOT_VIEWABLE;
8845 if (_gdk_native_windows)
8848 native = gdk_window_get_toplevel (window);
8850 while (gdk_window_is_offscreen (native))
8852 native = gdk_offscreen_window_get_embedder (native);
8854 if (native == NULL ||
8855 (!_gdk_window_has_impl (native) &&
8856 !gdk_window_is_viewable (native)))
8857 return GDK_GRAB_NOT_VIEWABLE;
8859 native = gdk_window_get_toplevel (native);
8862 display = gdk_window_get_display (window);
8864 serial = _gdk_windowing_window_get_next_serial (display);
8865 device_manager = gdk_display_get_device_manager (display);
8866 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8868 /* FIXME: Should this be generic to all backends? */
8869 /* FIXME: What happens with extended devices? */
8870 for (dev = devices; dev; dev = dev->next)
8874 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8877 res = _gdk_windowing_device_grab (device,
8881 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8886 if (res == GDK_GRAB_SUCCESS)
8887 _gdk_display_add_device_grab (display,
8898 /* FIXME: handle errors when grabbing */
8900 g_list_free (devices);
8906 * gdk_window_geometry_changed:
8907 * @window: an embedded offscreen #GdkWindow
8909 * This function informs GDK that the geometry of an embedded
8910 * offscreen window has changed. This is necessary for GDK to keep
8911 * track of which offscreen window the pointer is in.
8916 gdk_window_geometry_changed (GdkWindow *window)
8918 _gdk_synthesize_crossing_events_for_geometry_change (window);
8922 do_synthesize_crossing_event (gpointer data)
8924 GdkDisplay *display;
8925 GdkWindow *changed_toplevel;
8926 GHashTableIter iter;
8927 gpointer key, value;
8930 changed_toplevel = data;
8932 changed_toplevel->synthesize_crossing_event_queued = FALSE;
8934 if (GDK_WINDOW_DESTROYED (changed_toplevel))
8937 display = gdk_window_get_display (changed_toplevel);
8938 serial = _gdk_windowing_window_get_next_serial (display);
8939 g_hash_table_iter_init (&iter, display->pointers_info);
8941 while (g_hash_table_iter_next (&iter, &key, &value))
8943 GdkWindow *new_window_under_pointer;
8944 GdkPointerWindowInfo *pointer_info = value;
8945 GdkDevice *device = key;
8947 if (changed_toplevel == pointer_info->toplevel_under_pointer)
8949 new_window_under_pointer =
8950 get_pointer_window (display, changed_toplevel,
8952 pointer_info->toplevel_x,
8953 pointer_info->toplevel_y,
8955 if (new_window_under_pointer != pointer_info->window_under_pointer)
8957 _gdk_synthesize_crossing_events (display,
8958 pointer_info->window_under_pointer,
8959 new_window_under_pointer,
8961 GDK_CROSSING_NORMAL,
8962 pointer_info->toplevel_x,
8963 pointer_info->toplevel_y,
8964 pointer_info->state,
8969 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
8978 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
8980 GdkDisplay *display;
8981 GdkWindow *toplevel;
8983 if (_gdk_native_windows)
8984 return; /* We use the native crossing events if all native */
8986 display = gdk_window_get_display (changed_window);
8988 toplevel = get_event_toplevel (changed_window);
8990 if (!toplevel->synthesize_crossing_event_queued)
8992 toplevel->synthesize_crossing_event_queued = TRUE;
8994 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
8995 do_synthesize_crossing_event,
8996 g_object_ref (toplevel),
9001 /* Don't use for crossing events */
9003 get_event_window (GdkDisplay *display,
9005 GdkWindow *pointer_window,
9007 GdkModifierType mask,
9012 GdkWindow *grab_window;
9013 GdkDeviceGrabInfo *grab;
9015 grab = _gdk_display_has_device_grab (display, device, serial);
9017 if (grab != NULL && !grab->owner_events)
9019 evmask = grab->event_mask;
9020 evmask = update_evmask_for_button_motion (evmask, mask);
9022 grab_window = grab->window;
9024 if (evmask & type_masks[type])
9027 *evmask_out = evmask;
9034 while (pointer_window != NULL)
9036 evmask = pointer_window->event_mask;
9037 evmask = update_evmask_for_button_motion (evmask, mask);
9039 if (evmask & type_masks[type])
9042 *evmask_out = evmask;
9043 return pointer_window;
9046 pointer_window = get_event_parent (pointer_window);
9052 evmask = grab->event_mask;
9053 evmask = update_evmask_for_button_motion (evmask, mask);
9055 if (evmask & type_masks[type])
9058 *evmask_out = evmask;
9059 return grab->window;
9069 proxy_pointer_event (GdkDisplay *display,
9070 GdkEvent *source_event,
9073 GdkWindow *toplevel_window, *event_window;
9074 GdkWindow *pointer_window;
9075 GdkPointerWindowInfo *pointer_info;
9079 gdouble toplevel_x, toplevel_y;
9081 gboolean non_linear;
9083 event_window = source_event->any.window;
9084 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9085 gdk_event_get_state (source_event, &state);
9086 time_ = gdk_event_get_time (source_event);
9087 device = gdk_event_get_device (source_event);
9088 pointer_info = _gdk_display_get_pointer_info (display, device);
9089 toplevel_window = convert_native_coords_to_toplevel (event_window,
9090 toplevel_x, toplevel_y,
9091 &toplevel_x, &toplevel_y);
9094 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9095 source_event->type == GDK_ENTER_NOTIFY) &&
9096 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9097 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9100 /* If we get crossing events with subwindow unexpectedly being NULL
9101 that means there is a native subwindow that gdk doesn't know about.
9102 We track these and forward them, with the correct virtual window
9104 This is important to get right, as metacity uses gdk for the frame
9105 windows, but gdk doesn't know about the client windows reparented
9107 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9108 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9109 (source_event->type == GDK_ENTER_NOTIFY &&
9110 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9111 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9112 source_event->crossing.subwindow == NULL)
9114 /* Left for an unknown (to gdk) subwindow */
9116 /* Send leave events from window under pointer to event window
9117 that will get the subwindow == NULL window */
9118 _gdk_synthesize_crossing_events (display,
9119 pointer_info->window_under_pointer,
9122 source_event->crossing.mode,
9123 toplevel_x, toplevel_y,
9129 /* Send subwindow == NULL event */
9130 send_crossing_event (display,
9134 source_event->crossing.mode,
9135 source_event->crossing.detail,
9138 toplevel_x, toplevel_y,
9143 _gdk_display_set_window_under_pointer (display, device, NULL);
9147 pointer_window = get_pointer_window (display, toplevel_window, device,
9148 toplevel_x, toplevel_y, serial);
9150 if (((source_event->type == GDK_ENTER_NOTIFY &&
9151 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9152 (source_event->type == GDK_LEAVE_NOTIFY &&
9153 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9154 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9155 source_event->crossing.subwindow == NULL)
9157 /* Entered from an unknown (to gdk) subwindow */
9159 /* Send subwindow == NULL event */
9160 send_crossing_event (display,
9164 source_event->crossing.mode,
9165 source_event->crossing.detail,
9168 toplevel_x, toplevel_y,
9173 /* Send enter events from event window to pointer_window */
9174 _gdk_synthesize_crossing_events (display,
9178 source_event->crossing.mode,
9179 toplevel_x, toplevel_y,
9182 serial, non_linear);
9183 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9187 if (pointer_info->window_under_pointer != pointer_window)
9189 /* Either a toplevel crossing notify that ended up inside a child window,
9190 or a motion notify that got into another child window */
9192 /* Different than last time, send crossing events */
9193 _gdk_synthesize_crossing_events (display,
9194 pointer_info->window_under_pointer,
9197 GDK_CROSSING_NORMAL,
9198 toplevel_x, toplevel_y,
9201 serial, non_linear);
9202 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9204 else if (source_event->type == GDK_MOTION_NOTIFY)
9206 GdkWindow *event_win;
9210 event_win = get_event_window (display,
9219 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9220 gdk_window_get_device_events (event_win, device) == 0)
9226 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9228 gulong *device_serial;
9230 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9232 if (!device_serial ||
9233 (*device_serial != 0 &&
9234 serial < *device_serial))
9235 event_win = NULL; /* Ignore event */
9239 *device_serial = G_MAXULONG;
9243 if (event_win && !display->ignore_core_events)
9245 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9246 event->motion.time = time_;
9247 convert_toplevel_coords_to_window (event_win,
9248 toplevel_x, toplevel_y,
9249 &event->motion.x, &event->motion.y);
9250 event->motion.x_root = source_event->motion.x_root;
9251 event->motion.y_root = source_event->motion.y_root;
9252 event->motion.state = state;
9253 event->motion.is_hint = is_hint;
9254 event->motion.device = source_event->motion.device;
9255 event->motion.axes = g_memdup (source_event->motion.axes,
9256 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9260 /* unlink all move events from queue.
9261 We handle our own, including our emulated masks. */
9265 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9266 GDK_BUTTON2_MASK | \
9267 GDK_BUTTON3_MASK | \
9268 GDK_BUTTON4_MASK | \
9272 proxy_button_event (GdkEvent *source_event,
9275 GdkWindow *toplevel_window, *event_window;
9276 GdkWindow *event_win;
9277 GdkWindow *pointer_window;
9283 gdouble toplevel_x, toplevel_y;
9284 GdkDisplay *display;
9288 type = source_event->any.type;
9289 event_window = source_event->any.window;
9290 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9291 gdk_event_get_state (source_event, &state);
9292 time_ = gdk_event_get_time (source_event);
9293 device = gdk_event_get_device (source_event);
9294 display = gdk_window_get_display (source_event->any.window);
9295 toplevel_window = convert_native_coords_to_toplevel (event_window,
9296 toplevel_x, toplevel_y,
9297 &toplevel_x, &toplevel_y);
9299 if (type == GDK_BUTTON_PRESS &&
9300 !source_event->any.send_event &&
9301 _gdk_display_has_device_grab (display, device, serial) == NULL)
9304 _gdk_window_find_descendant_at (toplevel_window,
9305 toplevel_x, toplevel_y,
9308 /* Find the event window, that gets the grab */
9311 (parent = get_event_parent (w)) != NULL &&
9312 parent->window_type != GDK_WINDOW_ROOT)
9314 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9318 pointer_window = (GdkWindow *)w;
9320 _gdk_display_add_device_grab (display,
9326 gdk_window_get_events (pointer_window),
9330 _gdk_display_device_grab_update (display, device, serial);
9333 pointer_window = get_pointer_window (display, toplevel_window, device,
9334 toplevel_x, toplevel_y,
9337 event_win = get_event_window (display,
9343 if (event_win == NULL || display->ignore_core_events)
9346 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9347 gdk_window_get_device_events (event_win, device) == 0)
9350 event = _gdk_make_event (event_win, type, source_event, FALSE);
9354 case GDK_BUTTON_PRESS:
9355 case GDK_BUTTON_RELEASE:
9356 event->button.button = source_event->button.button;
9357 convert_toplevel_coords_to_window (event_win,
9358 toplevel_x, toplevel_y,
9359 &event->button.x, &event->button.y);
9360 event->button.x_root = source_event->button.x_root;
9361 event->button.y_root = source_event->button.y_root;
9362 event->button.state = state;
9363 event->button.device = source_event->button.device;
9364 event->button.axes = g_memdup (source_event->button.axes,
9365 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9367 if (type == GDK_BUTTON_PRESS)
9368 _gdk_event_button_generate (display, event);
9372 event->scroll.direction = source_event->scroll.direction;
9373 convert_toplevel_coords_to_window (event_win,
9374 toplevel_x, toplevel_y,
9375 &event->scroll.x, &event->scroll.y);
9376 event->scroll.x_root = source_event->scroll.x_root;
9377 event->scroll.y_root = source_event->scroll.y_root;
9378 event->scroll.state = state;
9379 event->scroll.device = source_event->scroll.device;
9386 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9389 #ifdef DEBUG_WINDOW_PRINTING
9391 gdk_window_print (GdkWindow *window,
9395 const char *window_types[] = {
9405 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9406 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9407 window->x, window->y,
9408 window->width, window->height
9411 if (gdk_window_has_impl (window))
9413 #ifdef GDK_WINDOWING_X11
9414 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9418 if (window->window_type != GDK_WINDOW_CHILD)
9419 g_print (" %s", window_types[window->window_type]);
9421 if (window->input_only)
9422 g_print (" input-only");
9425 g_print (" shaped");
9427 if (!gdk_window_is_visible ((GdkWindow *)window))
9428 g_print (" hidden");
9430 g_print (" abs[%d,%d]",
9431 window->abs_x, window->abs_y);
9433 cairo_region_get_extents (window->clip_region, &r);
9434 if (cairo_region_is_empty (window->clip_region))
9435 g_print (" clipbox[empty]");
9437 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9444 gdk_window_print_tree (GdkWindow *window,
9446 gboolean include_input_only)
9450 if (window->input_only && !include_input_only)
9453 gdk_window_print (window, indent);
9455 for (l = window->children; l != NULL; l = l->next)
9456 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9459 #endif /* DEBUG_WINDOW_PRINTING */
9462 _gdk_windowing_got_event (GdkDisplay *display,
9467 GdkWindow *event_window;
9469 gboolean unlink_event;
9470 guint old_state, old_button;
9471 GdkDeviceGrabInfo *button_release_grab;
9472 GdkPointerWindowInfo *pointer_info;
9474 gboolean is_toplevel;
9476 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9477 display->last_event_time = gdk_event_get_time (event);
9479 device = gdk_event_get_device (event);
9485 g_object_get (device, "input-mode", &mode, NULL);
9486 _gdk_display_device_grab_update (display, device, serial);
9488 if (mode == GDK_MODE_DISABLED ||
9489 !_gdk_display_check_grab_ownership (display, device, serial))
9491 /* Device events are blocked by another
9492 * device grab, or the device is disabled
9494 unlink_event = TRUE;
9499 event_window = event->any.window;
9503 pointer_info = _gdk_display_get_pointer_info (display, device);
9505 #ifdef DEBUG_WINDOW_PRINTING
9506 if (event->type == GDK_KEY_PRESS &&
9507 (event->key.keyval == 0xa7 ||
9508 event->key.keyval == 0xbd))
9510 gdk_window_print_tree (event_window, 0,
9511 event->key.keyval == 0xbd);
9515 if (_gdk_native_windows)
9517 if (event->type == GDK_BUTTON_PRESS &&
9518 !event->any.send_event &&
9519 _gdk_display_has_device_grab (display, device, serial) == NULL)
9521 _gdk_display_add_device_grab (display,
9527 gdk_window_get_events (event_window),
9529 gdk_event_get_time (event),
9531 _gdk_display_device_grab_update (display, device, serial);
9533 if (event->type == GDK_BUTTON_RELEASE &&
9534 !event->any.send_event)
9536 button_release_grab =
9537 _gdk_display_has_device_grab (display, device, serial);
9538 if (button_release_grab &&
9539 button_release_grab->implicit &&
9540 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9542 button_release_grab->serial_end = serial;
9543 button_release_grab->implicit_ungrab = FALSE;
9544 _gdk_display_device_grab_update (display, device, serial);
9548 if (event->type == GDK_BUTTON_PRESS)
9549 _gdk_event_button_generate (display, event);
9554 if (event->type == GDK_VISIBILITY_NOTIFY)
9556 event_window->native_visibility = event->visibility.state;
9557 gdk_window_update_visibility_recursively (event_window,
9562 if (!(is_button_type (event->type) ||
9563 is_motion_type (event->type)) ||
9564 event_window->window_type == GDK_WINDOW_ROOT)
9567 is_toplevel = gdk_window_is_toplevel (event_window);
9569 if ((event->type == GDK_ENTER_NOTIFY ||
9570 event->type == GDK_LEAVE_NOTIFY) &&
9571 (event->crossing.mode == GDK_CROSSING_GRAB ||
9572 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9573 (_gdk_display_has_device_grab (display, device, serial) ||
9574 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9576 /* We synthesize all crossing events due to grabs ourselves,
9577 * so we ignore the native ones caused by our native pointer_grab
9578 * calls. Otherwise we would proxy these crossing event and cause
9579 * multiple copies of crossing events for grabs.
9581 * We do want to handle grabs from other clients though, as for
9582 * instance alt-tab in metacity causes grabs like these and
9583 * we want to handle those. Thus the has_pointer_grab check.
9585 * Implicit grabs on child windows create some grabbing events
9586 * that are sent before the button press. This means we can't
9587 * detect these with the has_pointer_grab check (as the implicit
9588 * grab is only noticed when we get button press event), so we
9589 * detect these events by checking for INFERIOR enter or leave
9590 * events. These should never be a problem to filter out.
9593 /* We ended up in this window after some (perhaps other clients)
9594 grab, so update the toplevel_under_window state */
9596 event->type == GDK_ENTER_NOTIFY &&
9597 event->crossing.mode == GDK_CROSSING_UNGRAB)
9599 if (pointer_info->toplevel_under_pointer)
9600 g_object_unref (pointer_info->toplevel_under_pointer);
9601 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9604 unlink_event = TRUE;
9608 /* Track toplevel_under_pointer */
9611 if (event->type == GDK_ENTER_NOTIFY &&
9612 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9614 if (pointer_info->toplevel_under_pointer)
9615 g_object_unref (pointer_info->toplevel_under_pointer);
9616 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9618 else if (event->type == GDK_LEAVE_NOTIFY &&
9619 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9620 pointer_info->toplevel_under_pointer == event_window)
9622 if (pointer_info->toplevel_under_pointer)
9623 g_object_unref (pointer_info->toplevel_under_pointer);
9624 pointer_info->toplevel_under_pointer = NULL;
9628 /* Store last pointer window and position/state */
9629 old_state = pointer_info->state;
9630 old_button = pointer_info->button;
9632 gdk_event_get_coords (event, &x, &y);
9633 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9634 pointer_info->toplevel_x = x;
9635 pointer_info->toplevel_y = y;
9636 gdk_event_get_state (event, &pointer_info->state);
9637 if (event->type == GDK_BUTTON_PRESS ||
9638 event->type == GDK_BUTTON_RELEASE)
9639 pointer_info->button = event->button.button;
9642 (pointer_info->state != old_state ||
9643 pointer_info->button != old_button))
9644 _gdk_display_enable_motion_hints (display, device);
9646 unlink_event = FALSE;
9647 if (is_motion_type (event->type))
9648 unlink_event = proxy_pointer_event (display,
9651 else if (is_button_type (event->type))
9652 unlink_event = proxy_button_event (event,
9655 if (event->type == GDK_BUTTON_RELEASE &&
9656 !event->any.send_event)
9658 button_release_grab =
9659 _gdk_display_has_device_grab (display, device, serial);
9660 if (button_release_grab &&
9661 button_release_grab->implicit &&
9662 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9664 button_release_grab->serial_end = serial;
9665 button_release_grab->implicit_ungrab = FALSE;
9666 _gdk_display_device_grab_update (display, device, serial);
9673 _gdk_event_queue_remove_link (display, event_link);
9674 g_list_free_1 (event_link);
9675 gdk_event_free (event);
9681 get_extension_event_window (GdkDisplay *display,
9682 GdkWindow *pointer_window,
9687 GdkWindow *w, *grab_window;
9688 GdkDeviceGrabInfo *grab;
9690 /* FIXME: which device? */
9691 grab = _gdk_display_has_device_grab (display, display->core_pointer, serial);
9693 if (grab != NULL && !grab->owner_events)
9695 evmask = grab->event_mask;
9697 grab_window = grab->window;
9699 if (evmask & type_masks[type])
9708 evmask = w->extension_events;
9710 if (evmask & type_masks[type])
9713 w = get_event_parent (w);
9719 evmask = grab->event_mask;
9721 if (evmask & type_masks[type])
9722 return grab->window;
9732 _gdk_window_get_input_window_for_event (GdkWindow *native_window,
9733 GdkEventType event_type,
9737 GdkDisplay *display;
9738 GdkWindow *toplevel_window;
9739 GdkWindow *pointer_window;
9740 GdkWindow *event_win;
9741 gdouble toplevel_x, toplevel_y;
9746 display = gdk_window_get_display (native_window);
9747 toplevel_window = convert_native_coords_to_toplevel (native_window,
9748 toplevel_x, toplevel_y,
9749 &toplevel_x, &toplevel_y);
9750 /* FIXME: which device? */
9751 pointer_window = get_pointer_window (display, toplevel_window, NULL,
9752 toplevel_x, toplevel_y, serial);
9753 event_win = get_extension_event_window (display,
9762 * gdk_window_create_similar_surface:
9763 * @window: window to make new surface similar to
9764 * @content: the content for the new surface
9765 * @width: width of the new surface
9766 * @height: height of the new surface
9768 * Create a new surface that is as compatible as possible with the
9769 * given @window. For example the new surface will have the same
9770 * fallback resolution and font options as @window. Generally, the new
9771 * surface will also use the same backend as @window, unless that is
9772 * not possible for some reason. The type of the returned surface may
9773 * be examined with cairo_surface_get_type().
9775 * Initially the surface contents are all 0 (transparent if contents
9776 * have transparency, black otherwise.)
9778 * Returns: a pointer to the newly allocated surface. The caller
9779 * owns the surface and should call cairo_surface_destroy() when done
9782 * This function always returns a valid pointer, but it will return a
9783 * pointer to a "nil" surface if @other is already in an error state
9784 * or any other error occurs.
9789 gdk_window_create_similar_surface (GdkWindow * window,
9790 cairo_content_t content,
9794 cairo_surface_t *window_surface, *surface;
9796 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9798 window_surface = _gdk_window_ref_cairo_surface (window);
9800 surface = cairo_surface_create_similar (window_surface,
9804 cairo_surface_destroy (window_surface);