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 "gdkmarshalers.h"
44 #include "gdkscreen.h"
45 #include "gdkwindowimpl.h"
49 #undef DEBUG_WINDOW_PRINTING
54 * @Short_description: Onscreen display areas in the target window system
57 * A #GdkWindow is a rectangular region on the screen. It's a low-level object,
58 * used to implement high-level objects such as #GtkWidget and #GtkWindow on the
59 * GTK+ level. A #GtkWindow is a toplevel window, the thing a user might think
60 * of as a "window" with a titlebar and so on; a #GtkWindow may contain many
61 * #GdkWindow<!-- -->s. For example, each #GtkButton has a #GdkWindow associated
64 * <refsect2 id="COMPOSITED-WINDOWS">
65 * <title>Composited Windows</title>
67 * Normally, the windowing system takes care of rendering the contents of a
68 * child window onto its parent window. This mechanism can be intercepted by
69 * calling gdk_window_set_composited() on the child window. For a
70 * <firstterm>composited</firstterm> window it is the responsibility of the
71 * application to render the window contents at the right spot.
73 * <example id="composited-window-example">
74 * <title>Composited windows</title>
76 * <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>
77 * </programlisting></example>
79 * In the example <xref linkend="composited-window-example"/>, a button is
80 * placed inside of an event box inside of a window. The event box is set as
81 * composited and therefore is no longer automatically drawn to the screen.
83 * When the contents of the event box change, an expose event is generated on
84 * it's parent window (which, in this case, belongs to the toplevel #GtkWindow).
85 * The expose handler for this widget is responsible for merging the changes
86 * back on the screen in the way that it wishes.
88 * In our case, we merge the contents with a 50% transparency. We also set the
89 * background colour of the window to red. The effect is that the background
90 * shows through the button.
93 * <refsect2 id="OFFSCREEN-WINDOWS">
94 * <title>Offscreen Windows</title>
96 * Offscreen windows are more general than composited windows, since they allow
97 * not only to modify the rendering of the child window onto its parent, but
98 * also to apply coordinate transformations.
100 * To integrate an offscreen window into a window hierarchy, one has to call
101 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
102 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
103 * select an offscreen child at given coordinates, and the
104 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
105 * offscreen window are used to translate coordinates between the embedder and
106 * the offscreen window.
108 * For rendering an offscreen window onto its embedder, the contents of the
109 * offscreen window are available as a surface, via
110 * gdk_offscreen_window_get_surface().
116 /* Historically a GdkWindow always matches a platform native window,
117 * be it a toplevel window or a child window. In this setup the
118 * GdkWindow (and other GdkDrawables) were platform independent classes,
119 * and the actual platform specific implementation was in a delegate
120 * object availible as "impl" in the window object.
122 * With the addition of client side windows and offscreen windows this
123 * changes a bit. The application-visible GdkWindow object behaves as
124 * it did before, but not all such windows now have a corresponding native
125 * window. Instead windows that are "client side" are emulated by the gdk
126 * code such that clipping, drawing, moving, events etc work as expected.
128 * For GdkWindows that have a native window the "impl" object is the
129 * same as before. However, for all client side windows the impl object
130 * is shared with its parent (i.e. all client windows descendants of one
131 * native window has the same impl.
133 * Additionally there is a new type of platform independent impl object,
134 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
135 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
136 * windows). Such windows work by allocating a #cairo_surface_t as the backing
137 * store for drawing operations, which is resized with the window.
139 * GdkWindows have a pointer to the "impl window" they are in, i.e.
140 * the topmost GdkWindow which have the same "impl" value. This is stored
141 * in impl_window, which is different from the window itself only for client
143 * All GdkWindows (native or not) track the position of the window in the parent
144 * (x, y), the size of the window (width, height), the position of the window
145 * with respect to the impl window (abs_x, abs_y). We also track the clip
146 * region of the window wrt parent windows and siblings, in window-relative
147 * coordinates with and without child windows included (clip_region,
148 * clip_region_with_children).
150 * All toplevel windows are native windows, but also child windows can be
151 * native (although not children of offscreens). We always listen to
152 * a basic set of events (see get_native_event_mask) for these windows
153 * so that we can emulate events for any client side children.
155 * For native windows we apply the calculated clip region as a window shape
156 * so that eg. client side siblings that overlap the native child properly
157 * draws over the native child window.
159 * In order to minimize flicker and for performance we use a couple of cacheing
160 * tricks. First of all, every time we do a window to window copy area, for instance
161 * when moving a client side window or when scrolling/moving a region in a window
162 * we store this in outstanding_moves instead of applying immediately. We then
163 * delay this move until we really need it (because something depends on being
164 * able to read it), or until we're handing a redraw from an expose/invalidation
165 * (actually we delay it past redraw, but before blitting the double buffer
166 * to the window). This gives us two advantages. First of all it minimizes the time
167 * from the window is moved to the exposes related to that move, secondly it allows
168 * us to be smart about how to do the copy. We combine multiple moves into one (when
169 * possible) and we don't actually do copies to anything that is or will be
170 * invalidated and exposed anyway.
172 * Secondly, we use something called a "implicit paint" during repaint handling.
173 * An implicit paint is similar to a regular paint for the paint stack, but it is
174 * not put on the stack. Instead, it is set on the impl window, and later when
175 * regular gdk_window_begin_paint_region() happen on a window of this impl window
176 * we reuse the surface from the implicit paint. During repaint we create and at the
177 * end flush an implicit paint, which means we can collect all the paints on
178 * multiple client side windows in the same backing store.
181 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
183 /* This adds a local value to the GdkVisibilityState enum */
184 #define GDK_VISIBILITY_NOT_VIEWABLE 3
187 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
201 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
205 struct _GdkWindowPaint
207 cairo_region_t *region;
208 cairo_surface_t *surface;
209 guint uses_implicit : 1;
215 cairo_region_t *dest_region; /* The destination region */
216 int dx, dy; /* The amount that the source was moved to reach dest_region */
217 } GdkWindowRegionMove;
221 static void gdk_window_drop_cairo_surface (GdkWindow *private);
223 static void gdk_window_free_paint_stack (GdkWindow *window);
225 static void gdk_window_init (GdkWindow *window);
226 static void gdk_window_class_init (GdkWindowClass *klass);
227 static void gdk_window_finalize (GObject *object);
229 static void gdk_window_set_property (GObject *object,
233 static void gdk_window_get_property (GObject *object,
238 static void gdk_window_clear_backing_region (GdkWindow *window,
239 cairo_region_t *region);
241 static void recompute_visible_regions (GdkWindow *private,
242 gboolean recalculate_siblings,
243 gboolean recalculate_children);
244 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
245 static void gdk_window_flush_recursive (GdkWindow *window);
246 static void do_move_region_bits_on_impl (GdkWindow *window,
247 cairo_region_t *region, /* In impl window coords */
249 static void gdk_window_invalidate_in_parent (GdkWindow *private);
250 static void move_native_children (GdkWindow *private);
251 static void update_cursor (GdkDisplay *display,
253 static void impl_window_add_update_area (GdkWindow *impl_window,
254 cairo_region_t *region);
255 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
256 static void gdk_window_invalidate_region_full (GdkWindow *window,
257 const cairo_region_t *region,
258 gboolean invalidate_children,
260 static void gdk_window_invalidate_rect_full (GdkWindow *window,
261 const GdkRectangle *rect,
262 gboolean invalidate_children,
265 static guint signals[LAST_SIGNAL] = { 0 };
267 static gpointer parent_class = NULL;
269 static const cairo_user_data_key_t gdk_window_cairo_key;
272 new_region_tag (void)
274 static guint32 tag = 0;
280 gdk_window_get_type (void)
282 static GType object_type = 0;
285 object_type = g_type_register_static_simple (G_TYPE_OBJECT,
287 sizeof (GdkWindowClass),
288 (GClassInitFunc) gdk_window_class_init,
290 (GInstanceInitFunc) gdk_window_init,
297 _gdk_paintable_get_type (void)
299 static GType paintable_type = 0;
303 const GTypeInfo paintable_info =
305 sizeof (GdkPaintableIface), /* class_size */
306 NULL, /* base_init */
307 NULL, /* base_finalize */
310 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
311 g_intern_static_string ("GdkPaintable"),
314 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
317 return paintable_type;
321 gdk_window_init (GdkWindow *window)
323 /* 0-initialization is good for all other fields. */
325 window->window_type = GDK_WINDOW_CHILD;
327 window->state = GDK_WINDOW_STATE_WITHDRAWN;
330 window->toplevel_window_type = -1;
332 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
333 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
334 /* Default to unobscured since some backends don't send visibility events */
335 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
338 /* Stop and return on the first non-NULL parent */
340 accumulate_get_window (GSignalInvocationHint *ihint,
342 const GValue *handler_return,
345 g_value_copy (handler_return, return_accu);
346 /* Continue while returning NULL */
347 return g_value_get_object (handler_return) == NULL;
351 create_surface_accumulator (GSignalInvocationHint *ihint,
353 const GValue *handler_return,
356 g_value_copy (handler_return, return_accu);
358 /* Stop on the first non-NULL return value */
359 return g_value_get_boxed (handler_return) == NULL;
362 static GQuark quark_pointer_window = 0;
365 gdk_window_class_init (GdkWindowClass *klass)
367 GObjectClass *object_class = G_OBJECT_CLASS (klass);
369 parent_class = g_type_class_peek_parent (klass);
371 object_class->finalize = gdk_window_finalize;
372 object_class->set_property = gdk_window_set_property;
373 object_class->get_property = gdk_window_get_property;
375 klass->create_surface = _gdk_offscreen_window_create_surface;
377 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
385 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
386 * gdk_window_get_cursor() for details.
390 g_object_class_install_property (object_class,
392 g_param_spec_boxed ("cursor",
399 * GdkWindow::pick-embedded-child:
400 * @window: the window on which the signal is emitted
401 * @x: x coordinate in the window
402 * @y: y coordinate in the window
404 * The ::pick-embedded-child signal is emitted to find an embedded
405 * child at the given position.
407 * Returns: the #GdkWindow of the embedded child at @x, @y, or %NULL
411 signals[PICK_EMBEDDED_CHILD] =
412 g_signal_new (g_intern_static_string ("pick-embedded-child"),
413 G_OBJECT_CLASS_TYPE (object_class),
415 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
416 accumulate_get_window, NULL,
417 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
424 * GdkWindow::to-embedder:
425 * @window: the offscreen window on which the signal is emitted
426 * @offscreen-x: x coordinate in the offscreen window
427 * @offscreen-y: y coordinate in the offscreen window
428 * @embedder-x: return location for the x coordinate in the embedder window
429 * @embedder-y: return location for the y coordinate in the embedder window
431 * The ::to-embedder signal is emitted to translate coordinates
432 * in an offscreen window to its embedder.
434 * See also #GtkWindow::from-embedder.
438 signals[TO_EMBEDDER] =
439 g_signal_new (g_intern_static_string ("to-embedder"),
440 G_OBJECT_CLASS_TYPE (object_class),
442 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
444 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
453 * GdkWindow::from-embedder:
454 * @window: the offscreen window on which the signal is emitted
455 * @embedder-x: x coordinate in the embedder window
456 * @embedder-y: y coordinate in the embedder window
457 * @offscreen-x: return location for the x coordinate in the offscreen window
458 * @offscreen-y: return location for the y coordinate in the offscreen window
460 * The ::from-embedder signal is emitted to translate coordinates
461 * in the embedder of an offscreen window to the offscreen window.
463 * See also #GtkWindow::to-embedder.
467 signals[FROM_EMBEDDER] =
468 g_signal_new (g_intern_static_string ("from-embedder"),
469 G_OBJECT_CLASS_TYPE (object_class),
471 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
473 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
482 * GdkWindow::create-surface:
483 * @window: the offscreen window on which the signal is emitted
484 * @width: the width of the offscreen surface to create
485 * @height: the height of the offscreen surface to create
487 * The ::create-surface signal is emitted when an offscreen window
488 * needs its surface (re)created, which happens either when the the
489 * window is first drawn to, or when the window is being
490 * resized. The first signal handler that returns a non-%NULL
491 * surface will stop any further signal emission, and its surface
494 * Note that it is not possible to access the window's previous
495 * surface from within any callback of this signal. Calling
496 * gdk_offscreen_window_get_surface() will lead to a crash.
498 * Returns: the newly created #cairo_surface_t for the offscreen window
502 signals[CREATE_SURFACE] =
503 g_signal_new (g_intern_static_string ("create-surface"),
504 G_OBJECT_CLASS_TYPE (object_class),
506 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
507 create_surface_accumulator, NULL,
508 _gdk_marshal_BOXED__INT_INT,
509 CAIRO_GOBJECT_TYPE_SURFACE,
516 device_removed_cb (GdkDeviceManager *device_manager,
520 window->devices_inside = g_list_remove (window->devices_inside, device);
521 g_hash_table_remove (window->device_cursor, device);
523 if (window->device_events)
524 g_hash_table_remove (window->device_events, device);
528 gdk_window_finalize (GObject *object)
530 GdkWindow *window = GDK_WINDOW (object);
531 GdkDeviceManager *device_manager;
533 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
534 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
536 if (!GDK_WINDOW_DESTROYED (window))
538 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
540 g_warning ("losing last reference to undestroyed window\n");
541 _gdk_window_destroy (window, FALSE);
544 /* We use TRUE here, to keep us from actually calling
545 * XDestroyWindow() on the window
547 _gdk_window_destroy (window, TRUE);
550 gdk_window_drop_cairo_surface (window);
554 g_object_unref (window->impl);
558 if (window->impl_window != window)
560 g_object_unref (window->impl_window);
561 window->impl_window = NULL;
565 cairo_region_destroy (window->shape);
567 if (window->input_shape)
568 cairo_region_destroy (window->input_shape);
571 gdk_cursor_unref (window->cursor);
573 if (window->device_cursor)
574 g_hash_table_destroy (window->device_cursor);
576 if (window->device_events)
577 g_hash_table_destroy (window->device_events);
579 if (window->devices_inside)
580 g_list_free (window->devices_inside);
582 G_OBJECT_CLASS (parent_class)->finalize (object);
586 gdk_window_set_property (GObject *object,
591 GdkWindow *window = (GdkWindow *)object;
596 gdk_window_set_cursor (window, g_value_get_boxed (value));
600 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
606 gdk_window_get_property (GObject *object,
611 GdkWindow *window = (GdkWindow *) object;
616 g_value_set_boxed (value, gdk_window_get_cursor (window));
620 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
626 gdk_window_is_offscreen (GdkWindow *window)
628 return window->window_type == GDK_WINDOW_OFFSCREEN;
632 gdk_window_get_impl_window (GdkWindow *window)
634 return window->impl_window;
638 _gdk_window_get_impl_window (GdkWindow *window)
640 return gdk_window_get_impl_window (window);
644 gdk_window_has_impl (GdkWindow *window)
646 return window->impl_window == window;
650 gdk_window_is_toplevel (GdkWindow *window)
653 window->parent == NULL ||
654 window->parent->window_type == GDK_WINDOW_ROOT;
658 _gdk_window_has_impl (GdkWindow *window)
660 return gdk_window_has_impl (window);
664 gdk_window_has_no_impl (GdkWindow *window)
666 return window->impl_window != window;
670 remove_child_area (GdkWindow *private,
673 cairo_region_t *region)
676 cairo_region_t *child_region;
679 cairo_region_t *shape;
681 for (l = private->children; l; l = l->next)
688 /* If region is empty already, no need to do
689 anything potentially costly */
690 if (cairo_region_is_empty (region))
693 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
696 /* Ignore offscreen children, as they don't draw in their parent and
697 * don't take part in the clipping */
698 if (gdk_window_is_offscreen (child))
703 r.width = child->width;
704 r.height = child->height;
706 /* Bail early if child totally outside region */
707 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
710 child_region = cairo_region_create_rectangle (&r);
714 /* Adjust shape region to parent window coords */
715 cairo_region_translate (child->shape, child->x, child->y);
716 cairo_region_intersect (child_region, child->shape);
717 cairo_region_translate (child->shape, -child->x, -child->y);
719 else if (private->window_type == GDK_WINDOW_FOREIGN)
721 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
724 cairo_region_intersect (child_region, shape);
725 cairo_region_destroy (shape);
731 if (child->input_shape)
732 cairo_region_intersect (child_region, child->input_shape);
733 else if (private->window_type == GDK_WINDOW_FOREIGN)
735 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
738 cairo_region_intersect (child_region, shape);
739 cairo_region_destroy (shape);
744 cairo_region_subtract (region, child_region);
745 cairo_region_destroy (child_region);
750 static GdkVisibilityState
751 effective_visibility (GdkWindow *window)
753 GdkVisibilityState native;
755 if (!gdk_window_is_viewable (window))
756 return GDK_VISIBILITY_NOT_VIEWABLE;
758 native = window->impl_window->native_visibility;
760 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
761 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
762 return GDK_VISIBILITY_FULLY_OBSCURED;
763 else if (native == GDK_VISIBILITY_UNOBSCURED)
764 return window->visibility;
765 else /* native PARTIAL, private partial or unobscured */
766 return GDK_VISIBILITY_PARTIAL;
770 gdk_window_update_visibility (GdkWindow *window)
772 GdkVisibilityState new_visibility;
775 new_visibility = effective_visibility (window);
777 if (new_visibility != window->effective_visibility)
779 window->effective_visibility = new_visibility;
781 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
782 window->event_mask & GDK_VISIBILITY_NOTIFY)
784 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
786 event->visibility.state = new_visibility;
792 gdk_window_update_visibility_recursively (GdkWindow *window,
793 GdkWindow *only_for_impl)
798 gdk_window_update_visibility (window);
799 for (l = window->children; l != NULL; l = l->next)
802 if ((only_for_impl == NULL) ||
803 (only_for_impl == child->impl_window))
804 gdk_window_update_visibility_recursively (child, only_for_impl);
809 should_apply_clip_as_shape (GdkWindow *window)
812 gdk_window_has_impl (window) &&
813 /* Not for offscreens */
814 !gdk_window_is_offscreen (window) &&
815 /* or for toplevels */
816 !gdk_window_is_toplevel (window) &&
817 /* or for foreign windows */
818 window->window_type != GDK_WINDOW_FOREIGN &&
819 /* or for the root window */
820 window->window_type != GDK_WINDOW_ROOT;
824 apply_shape (GdkWindow *window,
825 cairo_region_t *region)
827 GdkWindowImplClass *impl_class;
829 /* We trash whether we applied a shape so that
830 we can avoid unsetting it many times, which
831 could happen in e.g. apply_clip_as_shape as
832 windows get resized */
833 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
835 impl_class->shape_combine_region (window,
837 else if (window->applied_shape)
838 impl_class->shape_combine_region (window,
841 window->applied_shape = region != NULL;
845 region_rect_equal (const cairo_region_t *region,
846 const GdkRectangle *rect)
848 GdkRectangle extents;
850 if (cairo_region_num_rectangles (region) != 1)
853 cairo_region_get_extents (region, &extents);
855 return extents.x == rect->x &&
856 extents.y == rect->y &&
857 extents.width == rect->width &&
858 extents.height == rect->height;
862 apply_clip_as_shape (GdkWindow *window)
867 r.width = window->width;
868 r.height = window->height;
870 /* We only apply the clip region if would differ
871 from the actual clip region implied by the size
872 of the window. This is to avoid unneccessarily
873 adding meaningless shapes to all native subwindows */
874 if (!region_rect_equal (window->clip_region, &r))
875 apply_shape (window, window->clip_region);
877 apply_shape (window, NULL);
881 recompute_visible_regions_internal (GdkWindow *private,
882 gboolean recalculate_clip,
883 gboolean recalculate_siblings,
884 gboolean recalculate_children)
889 cairo_region_t *new_clip, *old_clip_region_with_children;
890 gboolean clip_region_changed;
891 gboolean abs_pos_changed;
892 int old_abs_x, old_abs_y;
894 old_abs_x = private->abs_x;
895 old_abs_y = private->abs_y;
897 /* Update absolute position */
898 if (gdk_window_has_impl (private))
900 /* Native window starts here */
906 private->abs_x = private->parent->abs_x + private->x;
907 private->abs_y = private->parent->abs_y + private->y;
911 private->abs_x != old_abs_x ||
912 private->abs_y != old_abs_y;
914 /* Update clip region based on:
917 * siblings in parents above window
919 clip_region_changed = FALSE;
920 if (recalculate_clip)
922 if (private->viewable)
924 /* Calculate visible region (sans children) in parent window coords */
927 r.width = private->width;
928 r.height = private->height;
929 new_clip = cairo_region_create_rectangle (&r);
931 if (!gdk_window_is_toplevel (private))
933 cairo_region_intersect (new_clip, private->parent->clip_region);
935 /* Remove all overlapping children from parent.
936 * Unless we're all native, because then we don't need to take
937 * siblings into account since X does that clipping for us.
938 * This makes things like SWT that modify the raw X stacking
939 * order without GDKs knowledge work.
941 if (!_gdk_native_windows)
942 remove_child_area (private->parent, private, FALSE, new_clip);
945 /* Convert from parent coords to window coords */
946 cairo_region_translate (new_clip, -private->x, -private->y);
949 cairo_region_intersect (new_clip, private->shape);
952 new_clip = cairo_region_create ();
954 if (private->clip_region == NULL ||
955 !cairo_region_equal (private->clip_region, new_clip))
956 clip_region_changed = TRUE;
958 if (private->clip_region)
959 cairo_region_destroy (private->clip_region);
960 private->clip_region = new_clip;
962 old_clip_region_with_children = private->clip_region_with_children;
963 private->clip_region_with_children = cairo_region_copy (private->clip_region);
964 if (private->window_type != GDK_WINDOW_ROOT)
965 remove_child_area (private, NULL, FALSE, private->clip_region_with_children);
967 if (clip_region_changed ||
968 !cairo_region_equal (private->clip_region_with_children, old_clip_region_with_children))
969 private->clip_tag = new_region_tag ();
971 if (old_clip_region_with_children)
972 cairo_region_destroy (old_clip_region_with_children);
975 if (clip_region_changed)
977 GdkVisibilityState visibility;
978 gboolean fully_visible;
980 if (cairo_region_is_empty (private->clip_region))
981 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
986 fully_visible = cairo_region_equal (private->clip_region,
993 r.width = private->width;
994 r.height = private->height;
995 fully_visible = region_rect_equal (private->clip_region, &r);
999 visibility = GDK_VISIBILITY_UNOBSCURED;
1001 visibility = GDK_VISIBILITY_PARTIAL;
1004 if (private->visibility != visibility)
1006 private->visibility = visibility;
1007 gdk_window_update_visibility (private);
1011 /* Update all children, recursively (except for root, where children are not exact). */
1012 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1013 private->window_type != GDK_WINDOW_ROOT)
1015 for (l = private->children; l; l = l->next)
1018 /* Only recalculate clip if the the clip region changed, otherwise
1019 * there is no way the child clip region could change (its has not e.g. moved)
1020 * Except if recalculate_children is set to force child updates
1022 recompute_visible_regions_internal (child,
1023 recalculate_clip && (clip_region_changed || recalculate_children),
1028 if (clip_region_changed &&
1029 should_apply_clip_as_shape (private))
1030 apply_clip_as_shape (private);
1032 if (recalculate_siblings &&
1033 !gdk_window_is_toplevel (private))
1035 /* If we moved a child window in parent or changed the stacking order, then we
1036 * need to recompute the visible area of all the other children in the parent
1038 for (l = private->parent->children; l; l = l->next)
1042 if (child != private)
1043 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1046 /* We also need to recompute the _with_children clip for the parent */
1047 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1050 if (private->cairo_surface && gdk_window_has_impl (private))
1052 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1054 private->cairo_surface = iface->resize_cairo_surface (private,
1055 private->cairo_surface,
1059 else if (private->cairo_surface)
1060 gdk_window_drop_cairo_surface (private);
1063 /* Call this when private has changed in one or more of these ways:
1067 * stacking order of window changed
1070 * It will recalculate abs_x/y and the clip regions
1072 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1073 * for recalculate_siblings. (Mostly used internally for the recursion)
1075 * If a child window was removed (and you can't use that child for
1076 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1079 recompute_visible_regions (GdkWindow *private,
1080 gboolean recalculate_siblings,
1081 gboolean recalculate_children)
1083 recompute_visible_regions_internal (private,
1085 recalculate_siblings,
1086 recalculate_children);
1090 _gdk_window_update_size (GdkWindow *window)
1092 recompute_visible_regions (window, TRUE, FALSE);
1095 /* Find the native window that would be just above "child"
1096 * in the native stacking order if "child" was a native window
1097 * (it doesn't have to be native). If there is no such native
1098 * window inside this native parent then NULL is returned.
1099 * If child is NULL, find lowest native window in parent.
1102 find_native_sibling_above_helper (GdkWindow *parent,
1110 l = g_list_find (parent->children, child);
1111 g_assert (l != NULL); /* Better be a child of its parent... */
1112 l = l->prev; /* Start looking at the one above the child */
1115 l = g_list_last (parent->children);
1117 for (; l != NULL; l = l->prev)
1121 if (gdk_window_has_impl (w))
1124 g_assert (parent != w);
1125 w = find_native_sibling_above_helper (w, NULL);
1135 find_native_sibling_above (GdkWindow *parent,
1140 w = find_native_sibling_above_helper (parent, child);
1144 if (gdk_window_has_impl (parent))
1147 return find_native_sibling_above (parent->parent, parent);
1151 get_native_device_event_mask (GdkWindow *private,
1154 GdkEventMask event_mask;
1157 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1159 event_mask = private->event_mask;
1161 if (_gdk_native_windows ||
1162 private->window_type == GDK_WINDOW_ROOT ||
1163 private->window_type == GDK_WINDOW_FOREIGN)
1169 /* Do whatever the app asks to, since the app
1170 * may be asking for weird things for native windows,
1171 * but don't use motion hints as that may affect non-native
1172 * child windows that don't want it. Also, we need to
1173 * set all the app-specified masks since they will be picked
1174 * up by any implicit grabs (i.e. if they were not set as
1175 * native we would not get the events we need). */
1176 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1178 /* We need thse for all native windows so we can
1179 emulate events on children: */
1182 GDK_VISIBILITY_NOTIFY_MASK |
1183 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1185 /* Additionally we select for pointer and button events
1186 * for toplevels as we need to get these to emulate
1187 * them for non-native subwindows. Even though we don't
1188 * select on them for all native windows we will get them
1189 * as the events are propagated out to the first window
1190 * that select for them.
1191 * Not selecting for button press on all windows is an
1192 * important thing, because in X only one client can do
1193 * so, and we don't want to unexpectedly prevent another
1194 * client from doing it.
1196 * We also need to do the same if the app selects for button presses
1197 * because then we will get implicit grabs for this window, and the
1198 * event mask used for that grab is based on the rest of the mask
1199 * for the window, but we might need more events than this window
1200 * lists due to some non-native child window.
1202 if (gdk_window_is_toplevel (private) ||
1203 mask & GDK_BUTTON_PRESS_MASK)
1205 GDK_POINTER_MOTION_MASK |
1206 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1214 get_native_grab_event_mask (GdkEventMask grab_mask)
1216 /* Similar to the above but for pointer events only */
1218 GDK_POINTER_MOTION_MASK |
1219 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1220 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1223 ~GDK_POINTER_MOTION_HINT_MASK);
1227 get_native_event_mask (GdkWindow *private)
1229 return get_native_device_event_mask (private, NULL);
1232 /* Puts the native window in the right order wrt the other native windows
1233 * in the hierarchy, given the position it has in the client side data.
1234 * This is useful if some operation changed the stacking order.
1235 * This calls assumes the native window is now topmost in its native parent.
1238 sync_native_window_stack_position (GdkWindow *window)
1241 GdkWindowImplClass *impl_class;
1242 GList listhead = {0};
1244 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1246 above = find_native_sibling_above (window->parent, window);
1249 listhead.data = window;
1250 impl_class->restack_under (above, &listhead);
1256 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1257 * the default root window for the default display.
1258 * @attributes: attributes of the new window
1259 * @attributes_mask: mask indicating which fields in @attributes are valid
1261 * Creates a new #GdkWindow using the attributes from
1262 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1263 * more details. Note: to use this on displays other than the default
1264 * display, @parent must be specified.
1266 * Return value: (transfer none): the new #GdkWindow
1269 gdk_window_new (GdkWindow *parent,
1270 GdkWindowAttr *attributes,
1271 gint attributes_mask)
1277 GdkEventMask event_mask;
1278 GdkWindow *real_parent;
1279 GdkDeviceManager *device_manager;
1281 g_return_val_if_fail (attributes != NULL, NULL);
1285 GDK_NOTE (MULTIHEAD,
1286 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1288 screen = gdk_screen_get_default ();
1289 parent = gdk_screen_get_root_window (screen);
1292 screen = gdk_window_get_screen (parent);
1294 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1296 if (GDK_WINDOW_DESTROYED (parent))
1298 g_warning ("gdk_window_new(): parent is destroyed\n");
1302 if (attributes->window_type == GDK_WINDOW_OFFSCREEN &&
1303 _gdk_native_windows)
1305 g_warning ("Offscreen windows not supported with native-windows gdk");
1309 window = g_object_new (GDK_TYPE_WINDOW, NULL);
1311 /* Windows with a foreign parent are treated as if they are children
1312 * of the root window, except for actual creation.
1314 real_parent = parent;
1315 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1316 parent = gdk_screen_get_root_window (screen);
1318 window->parent = parent;
1320 window->accept_focus = TRUE;
1321 window->focus_on_map = TRUE;
1323 if (attributes_mask & GDK_WA_X)
1328 if (attributes_mask & GDK_WA_Y)
1335 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1336 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1338 #ifdef GDK_WINDOWING_X11
1339 /* Work around a bug where Xorg refuses to map toplevel InputOnly windows
1340 * from an untrusted client: http://bugs.freedesktop.org/show_bug.cgi?id=6988
1342 if (attributes->wclass == GDK_INPUT_ONLY &&
1343 window->parent->window_type == GDK_WINDOW_ROOT &&
1344 !G_LIKELY (GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (parent))->trusted_client))
1346 g_warning ("Coercing GDK_INPUT_ONLY toplevel window to GDK_INPUT_OUTPUT to work around bug in Xorg server");
1347 attributes->wclass = GDK_INPUT_OUTPUT;
1351 if (attributes->wclass == GDK_INPUT_ONLY)
1353 /* Backwards compatiblity - we've always ignored
1354 * attributes->window_type for input-only windows
1357 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1358 window->window_type = GDK_WINDOW_TEMP;
1360 window->window_type = GDK_WINDOW_CHILD;
1363 window->window_type = attributes->window_type;
1366 switch (window->window_type)
1368 case GDK_WINDOW_TOPLEVEL:
1369 case GDK_WINDOW_TEMP:
1370 case GDK_WINDOW_OFFSCREEN:
1371 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1372 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1373 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1374 case GDK_WINDOW_CHILD:
1378 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1382 if (attributes_mask & GDK_WA_VISUAL)
1383 window->visual = attributes->visual;
1385 window->visual = gdk_screen_get_system_visual (screen);
1387 window->event_mask = attributes->event_mask;
1389 if (attributes->wclass == GDK_INPUT_OUTPUT)
1391 window->input_only = FALSE;
1392 window->depth = window->visual->depth;
1394 /* XXX: Cache this somehow? */
1395 window->background = cairo_pattern_create_rgb (0, 0, 0);
1400 window->input_only = TRUE;
1404 window->parent->children = g_list_prepend (window->parent->children, window);
1406 window->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
1407 (GDestroyNotify) gdk_cursor_unref);
1409 native = _gdk_native_windows; /* Default */
1410 if (window->parent->window_type == GDK_WINDOW_ROOT)
1411 native = TRUE; /* Always use native windows for toplevels */
1412 else if (!window->input_only &&
1413 (attributes_mask & GDK_WA_VISUAL &&
1414 attributes->visual != gdk_window_get_visual (window->parent)))
1415 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1417 if (gdk_window_is_offscreen (window))
1419 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1420 window->impl_window = window;
1424 event_mask = get_native_event_mask (window);
1426 /* Create the impl */
1427 _gdk_window_impl_new (window, real_parent, screen, event_mask, attributes, attributes_mask);
1428 window->impl_window = window;
1430 /* This will put the native window topmost in the native parent, which may
1431 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1432 if (!_gdk_window_has_impl (real_parent))
1433 sync_native_window_stack_position (window);
1437 window->impl_window = g_object_ref (window->parent->impl_window);
1438 window->impl = g_object_ref (window->impl_window->impl);
1441 recompute_visible_regions (window, TRUE, FALSE);
1443 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1444 (attributes->cursor) :
1447 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1448 g_signal_connect (device_manager, "device-removed",
1449 G_CALLBACK (device_removed_cb), window);
1455 is_parent_of (GdkWindow *parent,
1466 w = gdk_window_get_parent (w);
1473 change_impl (GdkWindow *private,
1474 GdkWindow *impl_window,
1479 GdkWindowImpl *old_impl;
1480 GdkWindow *old_impl_window;
1482 old_impl = private->impl;
1483 old_impl_window = private->impl_window;
1484 if (private != impl_window)
1485 private->impl_window = g_object_ref (impl_window);
1487 private->impl_window = private;
1488 private->impl = g_object_ref (new);
1489 if (old_impl_window != private)
1490 g_object_unref (old_impl_window);
1491 g_object_unref (old_impl);
1493 for (l = private->children; l != NULL; l = l->next)
1497 if (child->impl == old_impl)
1498 change_impl (child, impl_window, new);
1503 reparent_to_impl (GdkWindow *private)
1508 GdkWindowImplClass *impl_class;
1510 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1512 /* Enumerate in reverse order so we get the right order for the native
1513 windows (first in childrens list is topmost, and reparent places on top) */
1514 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1518 if (child->impl == private->impl)
1519 reparent_to_impl (child);
1522 show = impl_class->reparent ((GdkWindow *)child,
1523 (GdkWindow *)private,
1524 child->x, child->y);
1526 gdk_window_show_unraised ((GdkWindow *)child);
1533 * gdk_window_reparent:
1534 * @window: a #GdkWindow
1535 * @new_parent: new parent to move @window into
1536 * @x: X location inside the new parent
1537 * @y: Y location inside the new parent
1539 * Reparents @window into the given @new_parent. The window being
1540 * reparented will be unmapped as a side effect.
1544 gdk_window_reparent (GdkWindow *window,
1545 GdkWindow *new_parent,
1549 GdkWindow *old_parent;
1551 gboolean show, was_mapped, applied_clip_as_shape;
1552 gboolean do_reparent_to_impl;
1553 GdkEventMask old_native_event_mask;
1554 GdkWindowImplClass *impl_class;
1556 g_return_if_fail (GDK_IS_WINDOW (window));
1557 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1558 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1560 if (GDK_WINDOW_DESTROYED (window) ||
1561 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1564 screen = gdk_window_get_screen (window);
1566 new_parent = gdk_screen_get_root_window (screen);
1568 /* No input-output children of input-only windows */
1569 if (new_parent->input_only && !window->input_only)
1572 /* Don't create loops in hierarchy */
1573 if (is_parent_of (window, new_parent))
1576 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1577 To make sure we're ok, just wipe it. */
1578 gdk_window_drop_cairo_surface (window);
1580 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1581 old_parent = window->parent;
1583 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1586 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1587 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1588 new_parent->window_type == GDK_WINDOW_FOREIGN)
1589 gdk_window_ensure_native (window);
1591 applied_clip_as_shape = should_apply_clip_as_shape (window);
1593 old_native_event_mask = 0;
1594 do_reparent_to_impl = FALSE;
1595 if (gdk_window_has_impl (window))
1597 old_native_event_mask = get_native_event_mask (window);
1599 show = impl_class->reparent (window, new_parent, x, y);
1603 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1604 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1605 new_parent->window_type != GDK_WINDOW_FOREIGN);
1608 gdk_window_hide (window);
1610 do_reparent_to_impl = TRUE;
1611 change_impl (window,
1612 new_parent->impl_window,
1616 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1619 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1621 new_parent = gdk_screen_get_root_window (screen);
1625 old_parent->children = g_list_remove (old_parent->children, window);
1627 window->parent = new_parent;
1631 new_parent->children = g_list_prepend (new_parent->children, window);
1633 /* Switch the window type as appropriate */
1635 switch (GDK_WINDOW_TYPE (new_parent))
1637 case GDK_WINDOW_ROOT:
1638 case GDK_WINDOW_FOREIGN:
1639 if (window->toplevel_window_type != -1)
1640 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1641 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1642 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1644 case GDK_WINDOW_OFFSCREEN:
1645 case GDK_WINDOW_TOPLEVEL:
1646 case GDK_WINDOW_CHILD:
1647 case GDK_WINDOW_TEMP:
1648 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1649 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1651 /* Save the original window type so we can restore it if the
1652 * window is reparented back to be a toplevel
1654 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1655 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1659 /* We might have changed window type for a native windows, so we
1660 need to change the event mask too. */
1661 if (gdk_window_has_impl (window))
1663 GdkEventMask native_event_mask = get_native_event_mask (window);
1665 if (native_event_mask != old_native_event_mask)
1666 impl_class->set_events (window, native_event_mask);
1669 _gdk_window_update_viewable (window);
1671 recompute_visible_regions (window, TRUE, FALSE);
1672 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1673 recompute_visible_regions (old_parent, FALSE, TRUE);
1675 /* We used to apply the clip as the shape, but no more.
1676 Reset this to the real shape */
1677 if (gdk_window_has_impl (window) &&
1678 applied_clip_as_shape &&
1679 !should_apply_clip_as_shape (window))
1680 apply_shape (window, window->shape);
1682 if (do_reparent_to_impl)
1683 reparent_to_impl (window);
1686 /* The reparent will have put the native window topmost in the native parent,
1687 * which may be wrong wrt other native windows in the non-native hierarchy,
1689 if (!gdk_window_has_impl (new_parent))
1690 sync_native_window_stack_position (window);
1694 gdk_window_show_unraised (window);
1696 _gdk_synthesize_crossing_events_for_geometry_change (window);
1700 temporary_disable_extension_events (GdkWindow*window)
1706 if (window->extension_events != 0)
1708 g_object_set_data (G_OBJECT (window),
1709 "gdk-window-extension-events",
1710 GINT_TO_POINTER (window->extension_events));
1711 gdk_input_set_extension_events ((GdkWindow *)window, 0,
1712 GDK_EXTENSION_EVENTS_NONE);
1717 for (l = window->children; l != NULL; l = l->next)
1721 if (window->impl_window == child->impl_window)
1722 res |= temporary_disable_extension_events (child);
1729 reenable_extension_events (GdkWindow *window)
1735 mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window),
1736 "gdk-window-extension-events"));
1740 /* We don't have the mode here, so we pass in cursor.
1741 This works with the current code since mode is not
1742 stored except as part of the mask, and cursor doesn't
1744 gdk_input_set_extension_events ((GdkWindow *)window, mask,
1745 GDK_EXTENSION_EVENTS_CURSOR);
1746 g_object_set_data (G_OBJECT (window),
1747 "gdk-window-extension-events",
1751 for (l = window->children; l != NULL; l = l->next)
1755 if (window->impl_window == child->impl_window)
1756 reenable_extension_events (window);
1761 * gdk_window_ensure_native:
1762 * @window: a #GdkWindow
1764 * Tries to ensure that there is a window-system native window for this
1765 * GdkWindow. This may fail in some situations, returning %FALSE.
1767 * Offscreen window and children of them can never have native windows.
1769 * Some backends may not support native child windows.
1771 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1776 gdk_window_ensure_native (GdkWindow *window)
1778 GdkWindow *impl_window;
1779 GdkWindowImpl *new_impl, *old_impl;
1783 GdkWindowImplClass *impl_class;
1784 gboolean disabled_extension_events;
1786 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1788 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1789 GDK_WINDOW_DESTROYED (window))
1792 impl_window = gdk_window_get_impl_window (window);
1794 if (gdk_window_is_offscreen (impl_window))
1795 return FALSE; /* native in offscreens not supported */
1797 if (impl_window == window)
1798 /* Already has an impl, and its not offscreen . */
1801 /* Need to create a native window */
1803 /* First we disable any extension events on the window or its
1804 descendants to handle the native input window moving */
1805 disabled_extension_events = FALSE;
1806 if (impl_window->input_window)
1807 disabled_extension_events = temporary_disable_extension_events (window);
1809 gdk_window_drop_cairo_surface (window);
1811 screen = gdk_window_get_screen (window);
1813 old_impl = window->impl;
1814 _gdk_window_impl_new (window, window->parent,
1816 get_native_event_mask (window),
1818 new_impl = window->impl;
1820 window->impl = old_impl;
1821 change_impl (window, window, new_impl);
1823 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1825 /* Native window creation will put the native window topmost in the
1826 * native parent, which may be wrong wrt the position of the previous
1827 * non-native window wrt to the other non-native children, so correct this.
1829 above = find_native_sibling_above (window->parent, window);
1832 listhead.data = window;
1833 listhead.prev = NULL;
1834 listhead.next = NULL;
1835 impl_class->restack_under ((GdkWindow *)above, &listhead);
1838 recompute_visible_regions (window, FALSE, FALSE);
1840 /* The shape may not have been set, as the clip region doesn't actually
1841 change, so do it here manually */
1842 if (should_apply_clip_as_shape (window))
1843 apply_clip_as_shape (window);
1845 reparent_to_impl (window);
1847 if (!window->input_only)
1849 impl_class->set_background (window, window->background);
1852 impl_class->input_shape_combine_region (window,
1853 window->input_shape,
1856 if (gdk_window_is_viewable (window))
1857 impl_class->show (window, FALSE);
1859 if (disabled_extension_events)
1860 reenable_extension_events (window);
1866 window_remove_filters (GdkWindow *window)
1868 if (window->filters)
1872 for (tmp_list = window->filters; tmp_list; tmp_list = tmp_list->next)
1873 g_free (tmp_list->data);
1875 g_list_free (window->filters);
1876 window->filters = NULL;
1881 update_pointer_info_foreach (GdkDisplay *display,
1883 GdkPointerWindowInfo *pointer_info,
1886 GdkWindow *window = user_data;
1888 if (pointer_info->toplevel_under_pointer == window)
1890 g_object_unref (pointer_info->toplevel_under_pointer);
1891 pointer_info->toplevel_under_pointer = NULL;
1896 window_remove_from_pointer_info (GdkWindow *window,
1897 GdkDisplay *display)
1899 _gdk_display_pointer_info_foreach (display,
1900 update_pointer_info_foreach,
1905 * _gdk_window_destroy_hierarchy:
1906 * @window: a #GdkWindow
1907 * @recursing: If TRUE, then this is being called because a parent
1909 * @recursing_native: If TRUE, then this is being called because a native parent
1910 * was destroyed. This generally means that the call to the
1911 * windowing system to destroy the window can be omitted, since
1912 * it will be destroyed as a result of the parent being destroyed.
1913 * Unless @foreign_destroy.
1914 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1915 * external agency. The window has already been destroyed and no
1916 * windowing system calls should be made. (This may never happen
1917 * for some windowing systems.)
1919 * Internal function to destroy a window. Like gdk_window_destroy(),
1920 * but does not drop the reference count created by gdk_window_new().
1923 _gdk_window_destroy_hierarchy (GdkWindow *window,
1925 gboolean recursing_native,
1926 gboolean foreign_destroy)
1928 GdkWindowImplClass *impl_class;
1929 GdkWindow *temp_window;
1931 GdkDisplay *display;
1935 g_return_if_fail (GDK_IS_WINDOW (window));
1937 if (GDK_WINDOW_DESTROYED (window))
1940 display = gdk_window_get_display (window);
1941 screen = gdk_window_get_screen (window);
1942 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1943 if (temp_window == window)
1944 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1947 switch (window->window_type)
1949 case GDK_WINDOW_ROOT:
1950 if (!screen->closed)
1952 g_error ("attempted to destroy root window");
1955 /* else fall thru */
1956 case GDK_WINDOW_TOPLEVEL:
1957 case GDK_WINDOW_CHILD:
1958 case GDK_WINDOW_TEMP:
1959 case GDK_WINDOW_FOREIGN:
1960 case GDK_WINDOW_OFFSCREEN:
1961 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1963 /* Logically, it probably makes more sense to send
1964 * a "destroy yourself" message to the foreign window
1965 * whether or not it's in our hierarchy; but for historical
1966 * reasons, we only send "destroy yourself" messages to
1967 * foreign windows in our hierarchy.
1970 _gdk_windowing_window_destroy_foreign (window);
1972 /* Also for historical reasons, we remove any filters
1973 * on a foreign window when it or a parent is destroyed;
1974 * this likely causes problems if two separate portions
1975 * of code are maintaining filter lists on a foreign window.
1977 window_remove_filters (window);
1983 if (window->parent->children)
1984 window->parent->children = g_list_remove (window->parent->children, window);
1987 GDK_WINDOW_IS_MAPPED (window))
1989 recompute_visible_regions (window, TRUE, FALSE);
1990 gdk_window_invalidate_in_parent (window);
1994 gdk_window_free_paint_stack (window);
1996 if (window->background)
1998 cairo_pattern_destroy (window->background);
1999 window->background = NULL;
2002 if (window->window_type == GDK_WINDOW_FOREIGN)
2003 g_assert (window->children == NULL);
2006 children = tmp = window->children;
2007 window->children = NULL;
2011 temp_window = tmp->data;
2015 _gdk_window_destroy_hierarchy (temp_window,
2017 recursing_native || gdk_window_has_impl (window),
2021 g_list_free (children);
2024 _gdk_window_clear_update_area (window);
2026 gdk_window_drop_cairo_surface (window);
2028 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2030 if (gdk_window_has_impl (window))
2031 impl_class->destroy (window, recursing_native,
2035 /* hide to make sure we repaint and break grabs */
2036 gdk_window_hide (window);
2039 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2040 window->parent = NULL;
2041 window->destroyed = TRUE;
2043 window_remove_filters (window);
2045 window_remove_from_pointer_info (window, display);
2047 if (window->clip_region)
2049 cairo_region_destroy (window->clip_region);
2050 window->clip_region = NULL;
2053 if (window->clip_region_with_children)
2055 cairo_region_destroy (window->clip_region_with_children);
2056 window->clip_region_with_children = NULL;
2059 if (window->outstanding_moves)
2061 g_list_foreach (window->outstanding_moves, (GFunc)gdk_window_region_move_free, NULL);
2062 g_list_free (window->outstanding_moves);
2063 window->outstanding_moves = NULL;
2071 * _gdk_window_destroy:
2072 * @window: a #GdkWindow
2073 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2074 * external agency. The window has already been destroyed and no
2075 * windowing system calls should be made. (This may never happen
2076 * for some windowing systems.)
2078 * Internal function to destroy a window. Like gdk_window_destroy(),
2079 * but does not drop the reference count created by gdk_window_new().
2082 _gdk_window_destroy (GdkWindow *window,
2083 gboolean foreign_destroy)
2085 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2089 * gdk_window_destroy:
2090 * @window: a #GdkWindow
2092 * Destroys the window system resources associated with @window and decrements @window's
2093 * reference count. The window system resources for all children of @window are also
2094 * destroyed, but the children's reference counts are not decremented.
2096 * Note that a window will not be destroyed automatically when its reference count
2097 * reaches zero. You must call this function yourself before that happens.
2101 gdk_window_destroy (GdkWindow *window)
2103 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2104 g_object_unref (window);
2108 * gdk_window_set_user_data:
2109 * @window: a #GdkWindow
2110 * @user_data: user data
2112 * For most purposes this function is deprecated in favor of
2113 * g_object_set_data(). However, for historical reasons GTK+ stores
2114 * the #GtkWidget that owns a #GdkWindow as user data on the
2115 * #GdkWindow. So, custom widget implementations should use
2116 * this function for that. If GTK+ receives an event for a #GdkWindow,
2117 * and the user data for the window is non-%NULL, GTK+ will assume the
2118 * user data is a #GtkWidget, and forward the event to that widget.
2122 gdk_window_set_user_data (GdkWindow *window,
2125 g_return_if_fail (GDK_IS_WINDOW (window));
2127 window->user_data = user_data;
2131 * gdk_window_get_user_data:
2132 * @window: a #GdkWindow
2133 * @data: return location for user data
2135 * Retrieves the user data for @window, which is normally the widget
2136 * that @window belongs to. See gdk_window_set_user_data().
2140 gdk_window_get_user_data (GdkWindow *window,
2143 g_return_if_fail (GDK_IS_WINDOW (window));
2145 *data = window->user_data;
2149 * gdk_window_get_window_type:
2150 * @window: a #GdkWindow
2152 * Gets the type of the window. See #GdkWindowType.
2154 * Return value: type of window
2157 gdk_window_get_window_type (GdkWindow *window)
2159 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2161 return GDK_WINDOW_TYPE (window);
2165 * gdk_window_get_visual:
2166 * @window: a #GdkWindow
2168 * Gets the #GdkVisual describing the pixel format of @window.
2170 * Return value: (transfer none): a #GdkVisual
2175 gdk_window_get_visual (GdkWindow *window)
2177 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2179 return window->visual;
2183 * gdk_window_get_screen:
2184 * @window: a #GdkWindow
2186 * Gets the #GdkScreen associated with a #GdkWindow.
2188 * Return value: (transfer none): the #GdkScreen associated with @window
2193 gdk_window_get_screen (GdkWindow *window)
2195 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2197 return gdk_visual_get_screen (window->visual);
2201 * gdk_window_get_display:
2202 * @window: a #GdkWindow
2204 * Gets the #GdkDisplay associated with a #GdkWindow.
2206 * Return value: (transfer none): the #GdkDisplay associated with @window
2211 gdk_window_get_display (GdkWindow *window)
2213 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2215 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2218 * gdk_window_is_destroyed:
2219 * @window: a #GdkWindow
2221 * Check to see if a window is destroyed..
2223 * Return value: %TRUE if the window is destroyed
2228 gdk_window_is_destroyed (GdkWindow *window)
2230 return GDK_WINDOW_DESTROYED (window);
2234 to_embedder (GdkWindow *window,
2235 gdouble offscreen_x,
2236 gdouble offscreen_y,
2237 gdouble *embedder_x,
2238 gdouble *embedder_y)
2240 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2241 offscreen_x, offscreen_y,
2242 embedder_x, embedder_y);
2246 from_embedder (GdkWindow *window,
2249 gdouble *offscreen_x,
2250 gdouble *offscreen_y)
2252 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2253 embedder_x, embedder_y,
2254 offscreen_x, offscreen_y);
2258 * gdk_window_has_native:
2259 * @window: a #GdkWindow
2261 * Checks whether the window has a native window or not. Note that
2262 * you can use gdk_window_ensure_native() if a native window is needed.
2264 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2269 gdk_window_has_native (GdkWindow *window)
2271 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2273 return window->parent == NULL || window->parent->impl != window->impl;
2277 * gdk_window_get_position:
2278 * @window: a #GdkWindow
2279 * @x: (out) (allow-none): X coordinate of window
2280 * @y: (out) (allow-none): Y coordinate of window
2282 * Obtains the position of the window as reported in the
2283 * most-recently-processed #GdkEventConfigure. Contrast with
2284 * gdk_window_get_geometry() which queries the X server for the
2285 * current window position, regardless of which events have been
2286 * received or processed.
2288 * The position coordinates are relative to the window's parent window.
2292 gdk_window_get_position (GdkWindow *window,
2296 g_return_if_fail (GDK_IS_WINDOW (window));
2305 * gdk_window_get_parent:
2306 * @window: a #GdkWindow
2308 * Obtains the parent of @window, as known to GDK. Does not query the
2309 * X server; thus this returns the parent as passed to gdk_window_new(),
2310 * not the actual parent. This should never matter unless you're using
2311 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2312 * matter for toplevel windows, because the window manager may choose
2315 * Note that you should use gdk_window_get_effective_parent() when
2316 * writing generic code that walks up a window hierarchy, because
2317 * gdk_window_get_parent() will most likely not do what you expect if
2318 * there are offscreen windows in the hierarchy.
2320 * Return value: (transfer none): parent of @window
2323 gdk_window_get_parent (GdkWindow *window)
2325 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2327 return window->parent;
2331 * gdk_window_get_effective_parent:
2332 * @window: a #GdkWindow
2334 * Obtains the parent of @window, as known to GDK. Works like
2335 * gdk_window_get_parent() for normal windows, but returns the
2336 * window's embedder for offscreen windows.
2338 * See also: gdk_offscreen_window_get_embedder()
2340 * Return value: (transfer none): effective parent of @window
2345 gdk_window_get_effective_parent (GdkWindow *window)
2347 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2349 if (gdk_window_is_offscreen (window))
2350 return gdk_offscreen_window_get_embedder (window);
2352 return window->parent;
2356 * gdk_window_get_toplevel:
2357 * @window: a #GdkWindow
2359 * Gets the toplevel window that's an ancestor of @window.
2361 * Any window type but %GDK_WINDOW_CHILD is considered a
2362 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2363 * has a root window as parent.
2365 * Note that you should use gdk_window_get_effective_toplevel() when
2366 * you want to get to a window's toplevel as seen on screen, because
2367 * gdk_window_get_toplevel() will most likely not do what you expect
2368 * if there are offscreen windows in the hierarchy.
2370 * Return value: (transfer none): the toplevel window containing @window
2373 gdk_window_get_toplevel (GdkWindow *window)
2375 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2377 while (window->window_type == GDK_WINDOW_CHILD)
2379 if (gdk_window_is_toplevel (window))
2381 window = window->parent;
2388 * gdk_window_get_effective_toplevel:
2389 * @window: a #GdkWindow
2391 * Gets the toplevel window that's an ancestor of @window.
2393 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2394 * embedder as its parent, using gdk_window_get_effective_parent().
2396 * See also: gdk_offscreen_window_get_embedder()
2398 * Return value: (transfer none): the effective toplevel window containing @window
2403 gdk_window_get_effective_toplevel (GdkWindow *window)
2407 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2409 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2410 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2417 * gdk_window_get_children:
2418 * @window: a #GdkWindow
2420 * Gets the list of children of @window known to GDK.
2421 * This function only returns children created via GDK,
2422 * so for example it's useless when used with the root window;
2423 * it only returns windows an application created itself.
2425 * The returned list must be freed, but the elements in the
2428 * Return value: (transfer container) (element-type GdkWindow):
2429 * list of child windows inside @window
2432 gdk_window_get_children (GdkWindow *window)
2434 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2436 if (GDK_WINDOW_DESTROYED (window))
2439 return g_list_copy (window->children);
2443 * gdk_window_peek_children:
2444 * @window: a #GdkWindow
2446 * Like gdk_window_get_children(), but does not copy the list of
2447 * children, so the list does not need to be freed.
2449 * Return value: (transfer none) (element-type GdkWindow):
2450 * a reference to the list of child windows in @window
2453 gdk_window_peek_children (GdkWindow *window)
2455 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2457 if (GDK_WINDOW_DESTROYED (window))
2460 return window->children;
2464 * gdk_window_add_filter:
2465 * @window: a #GdkWindow
2466 * @function: filter callback
2467 * @data: data to pass to filter callback
2469 * Adds an event filter to @window, allowing you to intercept events
2470 * before they reach GDK. This is a low-level operation and makes it
2471 * easy to break GDK and/or GTK+, so you have to know what you're
2472 * doing. Pass %NULL for @window to get all events for all windows,
2473 * instead of events for a specific window.
2475 * See gdk_display_add_client_message_filter() if you are interested
2476 * in X ClientMessage events.
2479 gdk_window_add_filter (GdkWindow *window,
2480 GdkFilterFunc function,
2484 GdkEventFilter *filter;
2486 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2488 if (window && GDK_WINDOW_DESTROYED (window))
2491 /* Filters are for the native events on the native window, so
2492 ensure there is a native window. */
2494 gdk_window_ensure_native (window);
2497 tmp_list = window->filters;
2499 tmp_list = _gdk_default_filters;
2503 filter = (GdkEventFilter *)tmp_list->data;
2504 if ((filter->function == function) && (filter->data == data))
2506 filter->ref_count++;
2509 tmp_list = tmp_list->next;
2512 filter = g_new (GdkEventFilter, 1);
2513 filter->function = function;
2514 filter->data = data;
2515 filter->ref_count = 1;
2519 window->filters = g_list_append (window->filters, filter);
2521 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2525 * gdk_window_remove_filter:
2526 * @window: a #GdkWindow
2527 * @function: previously-added filter function
2528 * @data: user data for previously-added filter function
2530 * Remove a filter previously added with gdk_window_add_filter().
2534 gdk_window_remove_filter (GdkWindow *window,
2535 GdkFilterFunc function,
2538 GList *tmp_list, *node;
2539 GdkEventFilter *filter;
2541 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2544 tmp_list = window->filters;
2546 tmp_list = _gdk_default_filters;
2550 filter = (GdkEventFilter *)tmp_list->data;
2552 tmp_list = tmp_list->next;
2554 if ((filter->function == function) && (filter->data == data))
2556 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2557 filter->ref_count--;
2558 if (filter->ref_count != 0)
2562 window->filters = g_list_remove_link (window->filters, node);
2564 _gdk_default_filters = g_list_remove_link (_gdk_default_filters, node);
2565 g_list_free_1 (node);
2574 * gdk_screen_get_toplevel_windows:
2575 * @screen: The #GdkScreen where the toplevels are located.
2577 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2578 * A toplevel window is a child of the root window (see
2579 * gdk_get_default_root_window()).
2581 * The returned list should be freed with g_list_free(), but
2582 * its elements need not be freed.
2584 * Return value: (transfer container) (element-type GdkWindow):
2585 * list of toplevel windows, free with g_list_free()
2590 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2592 GdkWindow * root_window;
2593 GList *new_list = NULL;
2596 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2598 root_window = gdk_screen_get_root_window (screen);
2600 tmp_list = root_window->children;
2603 GdkWindow *w = tmp_list->data;
2605 if (w->window_type != GDK_WINDOW_FOREIGN)
2606 new_list = g_list_prepend (new_list, w);
2607 tmp_list = tmp_list->next;
2614 * gdk_window_is_visible:
2615 * @window: a #GdkWindow
2617 * Checks whether the window has been mapped (with gdk_window_show() or
2618 * gdk_window_show_unraised()).
2620 * Return value: %TRUE if the window is mapped
2623 gdk_window_is_visible (GdkWindow *window)
2625 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2627 return GDK_WINDOW_IS_MAPPED (window);
2631 * gdk_window_is_viewable:
2632 * @window: a #GdkWindow
2634 * Check if the window and all ancestors of the window are
2635 * mapped. (This is not necessarily "viewable" in the X sense, since
2636 * we only check as far as we have GDK window parents, not to the root
2639 * Return value: %TRUE if the window is viewable
2642 gdk_window_is_viewable (GdkWindow *window)
2644 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2646 if (window->destroyed)
2649 return window->viewable;
2653 * gdk_window_get_state:
2654 * @window: a #GdkWindow
2656 * Gets the bitwise OR of the currently active window state flags,
2657 * from the #GdkWindowState enumeration.
2659 * Return value: window state bitfield
2662 gdk_window_get_state (GdkWindow *window)
2664 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2666 return window->state;
2669 static cairo_content_t
2670 gdk_window_get_content (GdkWindow *window)
2672 cairo_surface_t *surface;
2673 cairo_content_t content;
2675 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2677 surface = _gdk_window_ref_cairo_surface (window);
2678 content = cairo_surface_get_content (surface);
2679 cairo_surface_destroy (surface);
2684 /* This creates an empty "implicit" paint region for the impl window.
2685 * By itself this does nothing, but real paints to this window
2686 * or children of it can use this surface as backing to avoid allocating
2687 * multiple surfaces for subwindow rendering. When doing so they
2688 * add to the region of the implicit paint region, which will be
2689 * pushed to the window when the implicit paint region is ended.
2690 * Such paints should not copy anything to the window on paint end, but
2691 * should rely on the implicit paint end.
2692 * The implicit paint will be automatically ended if someone draws
2693 * directly to the window or a child window.
2696 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2698 GdkWindowPaint *paint;
2700 g_assert (gdk_window_has_impl (window));
2702 if (_gdk_native_windows)
2703 return FALSE; /* No need for implicit paints since we can't merge draws anyway */
2705 if (GDK_IS_PAINTABLE (window->impl))
2706 return FALSE; /* Implementation does double buffering */
2708 if (window->paint_stack != NULL ||
2709 window->implicit_paint != NULL)
2710 return FALSE; /* Don't stack implicit paints */
2712 /* Never do implicit paints for foreign windows, they don't need
2713 * double buffer combination since they have no client side children,
2714 * and creating surfaces for them is risky since they could disappear
2717 if (window->window_type == GDK_WINDOW_FOREIGN)
2720 paint = g_new (GdkWindowPaint, 1);
2721 paint->region = cairo_region_create (); /* Empty */
2722 paint->uses_implicit = FALSE;
2723 paint->flushed = FALSE;
2724 paint->surface = gdk_window_create_similar_surface (window,
2725 gdk_window_get_content (window),
2726 MAX (rect->width, 1),
2727 MAX (rect->height, 1));
2728 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2730 window->implicit_paint = paint;
2735 static cairo_surface_t *
2736 gdk_window_ref_impl_surface (GdkWindow *window)
2738 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (window);
2742 gdk_cairo_create_for_impl (GdkWindow *window)
2744 cairo_surface_t *surface;
2747 surface = gdk_window_ref_impl_surface (window);
2748 cr = cairo_create (surface);
2750 cairo_surface_destroy (surface);
2755 /* Ensure that all content related to this (sub)window is pushed to the
2756 native region. If there is an active paint then that area is not
2757 pushed, in order to not show partially finished double buffers. */
2759 gdk_window_flush_implicit_paint (GdkWindow *window)
2761 GdkWindow *impl_window;
2762 GdkWindowPaint *paint;
2763 cairo_region_t *region;
2766 impl_window = gdk_window_get_impl_window (window);
2767 if (impl_window->implicit_paint == NULL)
2770 paint = impl_window->implicit_paint;
2771 paint->flushed = TRUE;
2772 region = cairo_region_copy (window->clip_region_with_children);
2774 /* Don't flush active double buffers, as that may show partially done
2776 for (list = window->paint_stack; list != NULL; list = list->next)
2778 GdkWindowPaint *tmp_paint = list->data;
2780 cairo_region_subtract (region, tmp_paint->region);
2783 cairo_region_translate (region, -window->abs_x, -window->abs_y);
2784 cairo_region_intersect (region, paint->region);
2786 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2790 /* Remove flushed region from the implicit paint */
2791 cairo_region_subtract (paint->region, region);
2793 /* Some regions are valid, push these to window now */
2794 cr = gdk_cairo_create_for_impl (window);
2795 gdk_cairo_region (cr, region);
2797 cairo_set_source_surface (cr, paint->surface, 0, 0);
2798 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2803 cairo_region_destroy (region);
2806 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2808 gdk_window_end_implicit_paint (GdkWindow *window)
2810 GdkWindowPaint *paint;
2812 g_assert (gdk_window_has_impl (window));
2814 g_assert (window->implicit_paint != NULL);
2816 paint = window->implicit_paint;
2818 window->implicit_paint = NULL;
2820 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2824 /* Some regions are valid, push these to window now */
2825 cr = gdk_cairo_create_for_impl (window);
2826 gdk_cairo_region (cr, paint->region);
2828 cairo_set_source_surface (cr, paint->surface, 0, 0);
2829 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2834 cairo_region_destroy (paint->region);
2836 cairo_surface_destroy (paint->surface);
2841 * gdk_window_begin_paint_rect:
2842 * @window: a #GdkWindow
2843 * @rectangle: rectangle you intend to draw to
2845 * A convenience wrapper around gdk_window_begin_paint_region() which
2846 * creates a rectangular region for you. See
2847 * gdk_window_begin_paint_region() for details.
2851 gdk_window_begin_paint_rect (GdkWindow *window,
2852 const GdkRectangle *rectangle)
2854 cairo_region_t *region;
2856 g_return_if_fail (GDK_IS_WINDOW (window));
2858 region = cairo_region_create_rectangle (rectangle);
2859 gdk_window_begin_paint_region (window, region);
2860 cairo_region_destroy (region);
2864 * gdk_window_begin_paint_region:
2865 * @window: a #GdkWindow
2866 * @region: region you intend to draw to
2868 * Indicates that you are beginning the process of redrawing @region.
2869 * A backing store (offscreen buffer) large enough to contain @region
2870 * will be created. The backing store will be initialized with the
2871 * background color or background surface for @window. Then, all
2872 * drawing operations performed on @window will be diverted to the
2873 * backing store. When you call gdk_window_end_paint(), the backing
2874 * store will be copied to @window, making it visible onscreen. Only
2875 * the part of @window contained in @region will be modified; that is,
2876 * drawing operations are clipped to @region.
2878 * The net result of all this is to remove flicker, because the user
2879 * sees the finished product appear all at once when you call
2880 * gdk_window_end_paint(). If you draw to @window directly without
2881 * calling gdk_window_begin_paint_region(), the user may see flicker
2882 * as individual drawing operations are performed in sequence. The
2883 * clipping and background-initializing features of
2884 * gdk_window_begin_paint_region() are conveniences for the
2885 * programmer, so you can avoid doing that work yourself.
2887 * When using GTK+, the widget system automatically places calls to
2888 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2889 * emissions of the expose_event signal. That is, if you're writing an
2890 * expose event handler, you can assume that the exposed area in
2891 * #GdkEventExpose has already been cleared to the window background,
2892 * is already set as the clip region, and already has a backing store.
2893 * Therefore in most cases, application code need not call
2894 * gdk_window_begin_paint_region(). (You can disable the automatic
2895 * calls around expose events on a widget-by-widget basis by calling
2896 * gtk_widget_set_double_buffered().)
2898 * If you call this function multiple times before calling the
2899 * matching gdk_window_end_paint(), the backing stores are pushed onto
2900 * a stack. gdk_window_end_paint() copies the topmost backing store
2901 * onscreen, subtracts the topmost region from all other regions in
2902 * the stack, and pops the stack. All drawing operations affect only
2903 * the topmost backing store in the stack. One matching call to
2904 * gdk_window_end_paint() is required for each call to
2905 * gdk_window_begin_paint_region().
2909 gdk_window_begin_paint_region (GdkWindow *window,
2910 const cairo_region_t *region)
2912 #ifdef USE_BACKING_STORE
2913 GdkRectangle clip_box;
2914 GdkWindowPaint *paint, *implicit_paint;
2915 GdkWindow *impl_window;
2918 g_return_if_fail (GDK_IS_WINDOW (window));
2920 if (GDK_WINDOW_DESTROYED (window))
2923 if (GDK_IS_PAINTABLE (window->impl))
2925 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2927 if (iface->begin_paint_region)
2928 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2933 impl_window = gdk_window_get_impl_window (window);
2934 implicit_paint = impl_window->implicit_paint;
2936 paint = g_new (GdkWindowPaint, 1);
2937 paint->region = cairo_region_copy (region);
2938 paint->region_tag = new_region_tag ();
2940 cairo_region_intersect (paint->region, window->clip_region_with_children);
2941 cairo_region_get_extents (paint->region, &clip_box);
2943 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2945 /* Mark the region as valid on the implicit paint */
2948 cairo_region_union (implicit_paint->region, paint->region);
2950 /* Convert back to normal coords */
2951 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2955 paint->uses_implicit = TRUE;
2956 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2957 window->abs_x + clip_box.x,
2958 window->abs_y + clip_box.y,
2959 MAX (clip_box.width, 1),
2960 MAX (clip_box.height, 1));
2964 paint->uses_implicit = FALSE;
2965 paint->surface = gdk_window_create_similar_surface (window,
2966 gdk_window_get_content (window),
2967 MAX (clip_box.width, 1),
2968 MAX (clip_box.height, 1));
2970 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
2972 for (list = window->paint_stack; list != NULL; list = list->next)
2974 GdkWindowPaint *tmp_paint = list->data;
2976 cairo_region_subtract (tmp_paint->region, paint->region);
2979 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
2981 if (!cairo_region_is_empty (paint->region))
2983 gdk_window_clear_backing_region (window,
2987 #endif /* USE_BACKING_STORE */
2991 * gdk_window_end_paint:
2992 * @window: a #GdkWindow
2994 * Indicates that the backing store created by the most recent call to
2995 * gdk_window_begin_paint_region() should be copied onscreen and
2996 * deleted, leaving the next-most-recent backing store or no backing
2997 * store at all as the active paint region. See
2998 * gdk_window_begin_paint_region() for full details. It is an error to
2999 * call this function without a matching
3000 * gdk_window_begin_paint_region() first.
3004 gdk_window_end_paint (GdkWindow *window)
3006 #ifdef USE_BACKING_STORE
3007 GdkWindow *composited;
3008 GdkWindowPaint *paint;
3009 GdkRectangle clip_box;
3010 cairo_region_t *full_clip;
3012 g_return_if_fail (GDK_IS_WINDOW (window));
3014 if (GDK_WINDOW_DESTROYED (window))
3017 if (GDK_IS_PAINTABLE (window->impl))
3019 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3021 if (iface->end_paint)
3022 iface->end_paint ((GdkPaintable*)window->impl);
3026 if (window->paint_stack == NULL)
3028 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3032 paint = window->paint_stack->data;
3034 window->paint_stack = g_slist_delete_link (window->paint_stack,
3035 window->paint_stack);
3037 cairo_region_get_extents (paint->region, &clip_box);
3039 if (!paint->uses_implicit)
3043 gdk_window_flush_outstanding_moves (window);
3045 full_clip = cairo_region_copy (window->clip_region_with_children);
3046 cairo_region_intersect (full_clip, paint->region);
3048 cr = gdk_cairo_create (window);
3049 cairo_set_source_surface (cr, paint->surface, 0, 0);
3050 gdk_cairo_region (cr, full_clip);
3054 cairo_region_destroy (full_clip);
3057 cairo_surface_destroy (paint->surface);
3058 cairo_region_destroy (paint->region);
3061 /* find a composited window in our hierarchy to signal its
3062 * parent to redraw, calculating the clip box as we go...
3064 * stop if parent becomes NULL since then we'd have nowhere
3065 * to draw (ie: 'composited' will always be non-NULL here).
3067 for (composited = window;
3069 composited = composited->parent)
3071 clip_box.x += composited->x;
3072 clip_box.y += composited->y;
3073 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3074 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3076 if (composited->composited)
3078 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3083 #endif /* USE_BACKING_STORE */
3087 gdk_window_free_paint_stack (GdkWindow *window)
3089 if (window->paint_stack)
3091 GSList *tmp_list = window->paint_stack;
3095 GdkWindowPaint *paint = tmp_list->data;
3097 if (tmp_list == window->paint_stack)
3098 cairo_surface_destroy (paint->surface);
3100 cairo_region_destroy (paint->region);
3103 tmp_list = tmp_list->next;
3106 g_slist_free (window->paint_stack);
3107 window->paint_stack = NULL;
3112 do_move_region_bits_on_impl (GdkWindow *impl_window,
3113 cairo_region_t *dest_region, /* In impl window coords */
3116 GdkWindowImplClass *impl_class;
3118 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3120 impl_class->translate (impl_window, dest_region, dx, dy);
3123 static GdkWindowRegionMove *
3124 gdk_window_region_move_new (cairo_region_t *region,
3127 GdkWindowRegionMove *move;
3129 move = g_slice_new (GdkWindowRegionMove);
3130 move->dest_region = cairo_region_copy (region);
3138 gdk_window_region_move_free (GdkWindowRegionMove *move)
3140 cairo_region_destroy (move->dest_region);
3141 g_slice_free (GdkWindowRegionMove, move);
3145 append_move_region (GdkWindow *impl_window,
3146 cairo_region_t *new_dest_region,
3149 GdkWindowRegionMove *move, *old_move;
3150 cairo_region_t *new_total_region, *old_total_region;
3151 cairo_region_t *source_overlaps_destination;
3152 cairo_region_t *non_overwritten;
3153 gboolean added_move;
3156 if (cairo_region_is_empty (new_dest_region))
3159 /* In principle this could just append the move to the list of outstanding
3160 moves that will be replayed before drawing anything when we're handling
3161 exposes. However, we'd like to do a bit better since its commonly the case
3162 that we get multiple copies where A is copied to B and then B is copied
3163 to C, and we'd like to express this as a simple copy A to C operation. */
3165 /* We approach this by taking the new move and pushing it ahead of moves
3166 starting at the end of the list and stopping when its not safe to do so.
3167 It's not safe to push past a move if either the source of the new move
3168 is in the destination of the old move, or if the destination of the new
3169 move is in the source of the new move, or if the destination of the new
3170 move overlaps the destination of the old move. We simplify this by
3171 just comparing the total regions (src + dest) */
3172 new_total_region = cairo_region_copy (new_dest_region);
3173 cairo_region_translate (new_total_region, -dx, -dy);
3174 cairo_region_union (new_total_region, new_dest_region);
3177 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3182 old_total_region = cairo_region_copy (old_move->dest_region);
3183 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3184 cairo_region_union (old_total_region, old_move->dest_region);
3186 cairo_region_intersect (old_total_region, new_total_region);
3187 /* If these regions intersect then its not safe to push the
3188 new region before the old one */
3189 if (!cairo_region_is_empty (old_total_region))
3191 /* The area where the new moves source overlaps the old ones
3193 source_overlaps_destination = cairo_region_copy (new_dest_region);
3194 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3195 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3196 cairo_region_translate (source_overlaps_destination, dx, dy);
3198 /* We can do all sort of optimizations here, but to do things safely it becomes
3199 quite complicated. However, a very common case is that you copy something first,
3200 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3201 in the same direction). We'd like to detect this case and optimize it to one
3203 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3205 /* This means we might be able to replace the old move and the new one
3206 with the new one read from the old ones source, and a second copy of
3207 the non-overwritten parts of the old move. However, such a split
3208 is only valid if the source in the old move isn't overwritten
3209 by the destination of the new one */
3211 /* the new destination of old move if split is ok: */
3212 non_overwritten = cairo_region_copy (old_move->dest_region);
3213 cairo_region_subtract (non_overwritten, new_dest_region);
3214 /* move to source region */
3215 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3217 cairo_region_intersect (non_overwritten, new_dest_region);
3218 if (cairo_region_is_empty (non_overwritten))
3221 move = gdk_window_region_move_new (new_dest_region,
3225 impl_window->outstanding_moves =
3226 g_list_insert_before (impl_window->outstanding_moves,
3228 cairo_region_subtract (old_move->dest_region, new_dest_region);
3230 cairo_region_destroy (non_overwritten);
3233 cairo_region_destroy (source_overlaps_destination);
3234 cairo_region_destroy (old_total_region);
3237 cairo_region_destroy (old_total_region);
3240 cairo_region_destroy (new_total_region);
3244 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3247 impl_window->outstanding_moves =
3248 g_list_prepend (impl_window->outstanding_moves,
3251 impl_window->outstanding_moves =
3252 g_list_insert_before (impl_window->outstanding_moves,
3257 /* Moves bits and update area by dx/dy in impl window.
3258 Takes ownership of region to avoid copy (because we may change it) */
3260 move_region_on_impl (GdkWindow *impl_window,
3261 cairo_region_t *region, /* In impl window coords */
3264 if ((dx == 0 && dy == 0) ||
3265 cairo_region_is_empty (region))
3267 cairo_region_destroy (region);
3271 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3273 /* Move any old invalid regions in the copy source area by dx/dy */
3274 if (impl_window->update_area)
3276 cairo_region_t *update_area;
3278 update_area = cairo_region_copy (region);
3280 /* Convert from target to source */
3281 cairo_region_translate (update_area, -dx, -dy);
3282 cairo_region_intersect (update_area, impl_window->update_area);
3283 /* We only copy the area, so keep the old update area invalid.
3284 It would be safe to remove it too, as code that uses
3285 move_region_on_impl generally also invalidate the source
3286 area. However, it would just use waste cycles. */
3289 cairo_region_translate (update_area, dx, dy);
3290 cairo_region_union (impl_window->update_area, update_area);
3292 /* This area of the destination is now invalid,
3293 so no need to copy to it. */
3294 cairo_region_subtract (region, update_area);
3296 cairo_region_destroy (update_area);
3299 /* If we're currently exposing this window, don't copy to this
3300 destination, as it will be overdrawn when the expose is done,
3301 instead invalidate it and repaint later. */
3302 if (impl_window->implicit_paint)
3304 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3305 cairo_region_t *exposing;
3307 exposing = cairo_region_copy (implicit_paint->region);
3308 cairo_region_intersect (exposing, region);
3309 cairo_region_subtract (region, exposing);
3311 impl_window_add_update_area (impl_window, exposing);
3312 cairo_region_destroy (exposing);
3315 append_move_region (impl_window, region, dx, dy);
3317 cairo_region_destroy (region);
3320 /* Flushes all outstanding changes to the window, call this
3321 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3324 gdk_window_flush_outstanding_moves (GdkWindow *window)
3326 GdkWindow *impl_window;
3327 GList *l, *outstanding;
3328 GdkWindowRegionMove *move;
3330 impl_window = gdk_window_get_impl_window (window);
3331 outstanding = impl_window->outstanding_moves;
3332 impl_window->outstanding_moves = NULL;
3334 for (l = outstanding; l != NULL; l = l->next)
3338 do_move_region_bits_on_impl (impl_window,
3339 move->dest_region, move->dx, move->dy);
3341 gdk_window_region_move_free (move);
3344 g_list_free (outstanding);
3349 * @window: a #GdkWindow
3351 * Flush all outstanding cached operations on a window, leaving the
3352 * window in a state which reflects all that has been drawn before.
3354 * Gdk uses multiple kinds of caching to get better performance and
3355 * nicer drawing. For instance, during exposes all paints to a window
3356 * using double buffered rendering are keep on a surface until the last
3357 * window has been exposed. It also delays window moves/scrolls until
3358 * as long as possible until next update to avoid tearing when moving
3361 * Normally this should be completely invisible to applications, as
3362 * we automatically flush the windows when required, but this might
3363 * be needed if you for instance mix direct native drawing with
3364 * gdk drawing. For Gtk widgets that don't use double buffering this
3365 * will be called automatically before sending the expose event.
3370 gdk_window_flush (GdkWindow *window)
3372 gdk_window_flush_outstanding_moves (window);
3373 gdk_window_flush_implicit_paint (window);
3376 /* If we're about to move/resize or otherwise change the
3377 * hierarchy of a client side window in an impl and we're
3378 * called from an expose event handler then we need to
3379 * flush any already painted parts of the implicit paint
3380 * that are not part of the current paint, as these may
3381 * be used when scrolling or may overdraw the changes
3382 * caused by the hierarchy change.
3385 gdk_window_flush_if_exposing (GdkWindow *window)
3387 GdkWindow *impl_window;
3389 impl_window = gdk_window_get_impl_window (window);
3391 /* If we're in an implicit paint (i.e. in an expose handler, flush
3392 all the already finished exposes to get things to an uptodate state. */
3393 if (impl_window->implicit_paint)
3394 gdk_window_flush (window);
3399 gdk_window_flush_recursive_helper (GdkWindow *window,
3400 GdkWindowImpl *impl)
3405 for (l = window->children; l != NULL; l = l->next)
3409 if (child->impl == impl)
3410 /* Same impl, ignore */
3411 gdk_window_flush_recursive_helper (child, impl);
3413 gdk_window_flush_recursive (child);
3418 gdk_window_flush_recursive (GdkWindow *window)
3420 gdk_window_flush (window);
3421 gdk_window_flush_recursive_helper (window, window->impl);
3425 * gdk_window_get_clip_region:
3426 * @window: a #GdkWindow
3428 * Computes the region of a window that potentially can be written
3429 * to by drawing primitives. This region may not take into account
3430 * other factors such as if the window is obscured by other windows,
3431 * but no area outside of this region will be affected by drawing
3434 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3435 * when you are done.
3438 gdk_window_get_clip_region (GdkWindow *window)
3440 cairo_region_t *result;
3442 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3444 result = cairo_region_copy (window->clip_region);
3446 if (window->paint_stack)
3448 cairo_region_t *paint_region = cairo_region_create ();
3449 GSList *tmp_list = window->paint_stack;
3453 GdkWindowPaint *paint = tmp_list->data;
3455 cairo_region_union (paint_region, paint->region);
3457 tmp_list = tmp_list->next;
3460 cairo_region_intersect (result, paint_region);
3461 cairo_region_destroy (paint_region);
3468 * gdk_window_get_visible_region:
3469 * @window: a #GdkWindow
3471 * Computes the region of the @window that is potentially visible.
3472 * This does not necessarily take into account if the window is
3473 * obscured by other windows, but no area outside of this region
3476 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3477 * when you are done.
3480 gdk_window_get_visible_region (GdkWindow *window)
3482 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3484 return cairo_region_copy (window->clip_region);
3488 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint, int x_offset_cairo, int y_offset_cairo)
3490 GdkWindow *bg_window;
3491 cairo_pattern_t *pattern = NULL;
3492 int x_offset = 0, y_offset = 0;
3495 cr = cairo_create (paint->surface);
3497 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3499 pattern = gdk_window_get_background_pattern (bg_window);
3503 x_offset += bg_window->x;
3504 y_offset += bg_window->y;
3509 cairo_translate (cr, -x_offset, -y_offset);
3510 cairo_set_source (cr, pattern);
3511 cairo_translate (cr, x_offset, y_offset);
3514 cairo_set_source_rgb (cr, 0, 0, 0);
3520 gdk_window_clear_backing_region (GdkWindow *window,
3521 cairo_region_t *region)
3523 GdkWindowPaint *paint = window->paint_stack->data;
3524 cairo_region_t *clip;
3525 GdkRectangle clipbox;
3528 if (GDK_WINDOW_DESTROYED (window))
3531 cr = setup_backing_rect (window, paint, 0, 0);
3533 clip = cairo_region_copy (paint->region);
3534 cairo_region_intersect (clip, region);
3535 cairo_region_get_extents (clip, &clipbox);
3537 gdk_cairo_region (cr, clip);
3542 cairo_region_destroy (clip);
3546 gdk_window_clear_backing_region_direct (GdkWindow *window,
3547 cairo_region_t *region)
3549 GdkWindowPaint paint;
3550 cairo_region_t *clip;
3551 GdkRectangle clipbox;
3554 if (GDK_WINDOW_DESTROYED (window))
3557 paint.surface = _gdk_window_ref_cairo_surface (window);
3559 cr = setup_backing_rect (window, &paint, 0, 0);
3561 clip = cairo_region_copy (window->clip_region_with_children);
3562 cairo_region_intersect (clip, region);
3563 cairo_region_get_extents (clip, &clipbox);
3565 gdk_cairo_region (cr, clip);
3570 cairo_region_destroy (clip);
3571 cairo_surface_destroy (paint.surface);
3576 gdk_window_clear_region_internal (GdkWindow *window,
3577 cairo_region_t *region)
3579 if (window->paint_stack)
3580 gdk_window_clear_backing_region (window, region);
3582 gdk_window_clear_backing_region_direct (window, region);
3586 gdk_window_drop_cairo_surface (GdkWindow *window)
3588 if (window->cairo_surface)
3590 cairo_surface_finish (window->cairo_surface);
3591 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3593 window->cairo_surface = NULL;
3598 gdk_window_cairo_surface_destroy (void *data)
3600 GdkWindow *window = data;
3602 window->cairo_surface = NULL;
3605 static cairo_surface_t *
3606 gdk_window_create_cairo_surface (GdkWindow *window,
3610 cairo_surface_t *surface, *subsurface;
3612 surface = gdk_window_ref_impl_surface (window);
3613 if (gdk_window_has_impl (window))
3616 subsurface = cairo_surface_create_for_rectangle (surface,
3621 cairo_surface_destroy (surface);
3627 _gdk_window_ref_cairo_surface (GdkWindow *window)
3629 cairo_surface_t *surface;
3631 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3633 if (window->paint_stack)
3635 GdkWindowPaint *paint = window->paint_stack->data;
3637 surface = paint->surface;
3638 cairo_surface_reference (surface);
3643 /* This will be drawing directly to the window, so flush implicit paint */
3644 gdk_window_flush (window);
3646 if (!window->cairo_surface)
3648 window->cairo_surface = gdk_window_create_cairo_surface (window,
3652 if (window->cairo_surface)
3654 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3655 window, gdk_window_cairo_surface_destroy);
3659 cairo_surface_reference (window->cairo_surface);
3661 surface = window->cairo_surface;
3669 * @window: a #GdkWindow
3671 * Creates a Cairo context for drawing to @window.
3674 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3675 * produce undefined results, so avoid it at all costs.
3678 * Return value: A newly created Cairo context. Free with
3679 * cairo_destroy() when you are done drawing.
3684 gdk_cairo_create (GdkWindow *window)
3686 cairo_surface_t *surface;
3689 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3691 surface = _gdk_window_ref_cairo_surface (window);
3692 cr = cairo_create (surface);
3694 if (!window->paint_stack)
3696 gdk_cairo_region (cr, window->clip_region_with_children);
3701 GdkWindowPaint *paint = window->paint_stack->data;
3703 /* Only needs to clip to region if piggybacking
3704 on an implicit paint */
3705 if (paint->uses_implicit)
3707 gdk_cairo_region (cr, paint->region);
3712 cairo_surface_destroy (surface);
3717 /* Code for dirty-region queueing
3719 static GSList *update_windows = NULL;
3720 static guint update_idle = 0;
3721 static gboolean debug_updates = FALSE;
3723 static inline gboolean
3724 gdk_window_is_ancestor (GdkWindow *window,
3725 GdkWindow *ancestor)
3729 GdkWindow *parent = window->parent;
3731 if (parent == ancestor)
3741 gdk_window_add_update_window (GdkWindow *window)
3744 GSList *prev = NULL;
3745 gboolean has_ancestor_in_list = FALSE;
3747 for (tmp = update_windows; tmp; tmp = tmp->next)
3749 GdkWindow *parent = window->parent;
3751 /* check if tmp is an ancestor of "window"; if it is, set a
3752 * flag indicating that all following windows are either
3753 * children of "window" or from a differen hierarchy
3755 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3756 has_ancestor_in_list = TRUE;
3758 /* insert in reverse stacking order when adding around siblings,
3759 * so processing updates properly paints over lower stacked windows
3761 if (parent == GDK_WINDOW (tmp->data)->parent)
3763 gint index = g_list_index (parent->children, window);
3764 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3766 gint sibling_index = g_list_index (parent->children, tmp->data);
3767 if (index > sibling_index)
3771 /* here, tmp got advanced past all lower stacked siblings */
3772 tmp = g_slist_prepend (tmp, window);
3776 update_windows = tmp;
3780 /* if "window" has an ancestor in the list and tmp is one of
3781 * "window's" children, insert "window" before tmp
3783 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3785 tmp = g_slist_prepend (tmp, window);
3790 update_windows = tmp;
3794 /* if we're at the end of the list and had an ancestor it it,
3795 * append to the list
3797 if (! tmp->next && has_ancestor_in_list)
3799 tmp = g_slist_append (tmp, window);
3806 /* if all above checks failed ("window" is from a different
3807 * hierarchy than what is already in the list) or the list is
3810 update_windows = g_slist_prepend (update_windows, window);
3814 gdk_window_remove_update_window (GdkWindow *window)
3816 update_windows = g_slist_remove (update_windows, window);
3820 gdk_window_update_idle (gpointer data)
3822 gdk_window_process_all_updates ();
3828 gdk_window_is_toplevel_frozen (GdkWindow *window)
3830 GdkWindow *toplevel;
3832 toplevel = gdk_window_get_toplevel (window);
3834 return toplevel->update_and_descendants_freeze_count > 0;
3838 gdk_window_schedule_update (GdkWindow *window)
3841 (window->update_freeze_count ||
3842 gdk_window_is_toplevel_frozen (window)))
3847 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3848 gdk_window_update_idle,
3853 _gdk_window_process_updates_recurse (GdkWindow *window,
3854 cairo_region_t *expose_region)
3857 cairo_region_t *child_region;
3859 GList *l, *children;
3861 if (cairo_region_is_empty (expose_region))
3864 if (gdk_window_is_offscreen (window->impl_window) &&
3865 window == window->impl_window)
3866 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3868 /* Make this reentrancy safe for expose handlers freeing windows */
3869 children = g_list_copy (window->children);
3870 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3872 /* Iterate over children, starting at topmost */
3873 for (l = children; l != NULL; l = l->next)
3877 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3880 /* Ignore offscreen children, as they don't draw in their parent and
3881 * don't take part in the clipping */
3882 if (gdk_window_is_offscreen (child))
3887 r.width = child->width;
3888 r.height = child->height;
3890 child_region = cairo_region_create_rectangle (&r);
3893 /* Adjust shape region to parent window coords */
3894 cairo_region_translate (child->shape, child->x, child->y);
3895 cairo_region_intersect (child_region, child->shape);
3896 cairo_region_translate (child->shape, -child->x, -child->y);
3899 if (child->impl == window->impl)
3901 /* Client side child, expose */
3902 cairo_region_intersect (child_region, expose_region);
3903 cairo_region_subtract (expose_region, child_region);
3904 cairo_region_translate (child_region, -child->x, -child->y);
3905 _gdk_window_process_updates_recurse ((GdkWindow *)child, child_region);
3909 /* Native child, just remove area from expose region */
3910 cairo_region_subtract (expose_region, child_region);
3912 cairo_region_destroy (child_region);
3915 g_list_foreach (children, (GFunc)g_object_unref, NULL);
3916 g_list_free (children);
3918 if (!cairo_region_is_empty (expose_region) &&
3921 if (window->event_mask & GDK_EXPOSURE_MASK)
3925 event.expose.type = GDK_EXPOSE;
3926 event.expose.window = g_object_ref (window);
3927 event.expose.send_event = FALSE;
3928 event.expose.count = 0;
3929 event.expose.region = expose_region;
3930 cairo_region_get_extents (expose_region, &event.expose.area);
3932 _gdk_event_emit (&event);
3934 g_object_unref (window);
3936 else if (window->window_type != GDK_WINDOW_FOREIGN)
3938 /* No exposure mask set, so nothing will be drawn, the
3939 * app relies on the background being what it specified
3940 * for the window. So, we need to clear this manually.
3942 * For foreign windows if expose is not set that generally
3943 * means some other client paints them, so don't clear
3946 * We use begin/end_paint around the clear so that we can
3947 * piggyback on the implicit paint */
3949 gdk_window_begin_paint_region (window, expose_region);
3950 gdk_window_clear_region_internal (window, expose_region);
3951 gdk_window_end_paint (window);
3956 /* Process and remove any invalid area on the native window by creating
3957 * expose events for the window and all non-native descendants.
3958 * Also processes any outstanding moves on the window before doing
3959 * any drawing. Note that its possible to have outstanding moves without
3960 * any invalid area as we use the update idle mechanism to coalesce
3961 * multiple moves as well as multiple invalidations.
3964 gdk_window_process_updates_internal (GdkWindow *window)
3966 GdkWindowImplClass *impl_class;
3967 gboolean save_region = FALSE;
3968 GdkRectangle clip_box;
3970 /* Ensure the window lives while updating it */
3971 g_object_ref (window);
3973 /* If an update got queued during update processing, we can get a
3974 * window in the update queue that has an empty update_area.
3977 if (window->update_area)
3979 cairo_region_t *update_area = window->update_area;
3980 window->update_area = NULL;
3982 if (gdk_window_is_viewable (window))
3984 cairo_region_t *expose_region;
3985 gboolean end_implicit;
3987 /* Clip to part visible in toplevel */
3988 cairo_region_intersect (update_area, window->clip_region);
3992 /* Make sure we see the red invalid area before redrawing. */
3993 gdk_display_sync (gdk_window_get_display (window));
3997 /* At this point we will be completely redrawing all of update_area.
3998 * If we have any outstanding moves that end up moving stuff inside
3999 * this area we don't actually need to move that as that part would
4000 * be overdrawn by the expose anyway. So, in order to copy less data
4001 * we remove these areas from the outstanding moves.
4003 if (window->outstanding_moves)
4005 GdkWindowRegionMove *move;
4006 cairo_region_t *remove;
4009 remove = cairo_region_copy (update_area);
4010 /* We iterate backwards, starting from the state that would be
4011 if we had applied all the moves. */
4012 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
4017 /* Don't need this area */
4018 cairo_region_subtract (move->dest_region, remove);
4020 /* However if any of the destination we do need has a source
4021 in the updated region we do need that as a destination for
4022 the earlier moves */
4023 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4024 cairo_region_subtract (remove, move->dest_region);
4026 if (cairo_region_is_empty (move->dest_region))
4028 gdk_window_region_move_free (move);
4029 window->outstanding_moves =
4030 g_list_delete_link (window->outstanding_moves, l);
4032 else /* move back */
4033 cairo_region_translate (move->dest_region, move->dx, move->dy);
4035 cairo_region_destroy (remove);
4038 /* By now we a set of window moves that should be applied, and then
4039 * an update region that should be repainted. A trivial implementation
4040 * would just do that in order, however in order to get nicer drawing
4041 * we do some tricks:
4043 * First of all, each subwindow expose may be double buffered by
4044 * itself (depending on widget setting) via
4045 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4046 * creating a single surface the size of the invalid area on the
4047 * native window which all the individual normal paints will draw
4048 * into. This way in the normal case there will be only one surface
4049 * allocated and only once surface draw done for all the windows
4050 * in this native window.
4051 * There are a couple of reasons this may fail, for instance, some
4052 * backends (like quartz) do its own double buffering, so we disable
4053 * gdk double buffering there. Secondly, some subwindow could be
4054 * non-double buffered and draw directly to the window outside a
4055 * begin/end_paint pair. That will be lead to a gdk_window_flush
4056 * which immediately executes all outstanding moves and paints+removes
4057 * the implicit paint (further paints will allocate their own surfaces).
4059 * Secondly, in the case of implicit double buffering we expose all
4060 * the child windows into the implicit surface before we execute
4061 * the outstanding moves. This way we minimize the time between
4062 * doing the moves and rendering the new update area, thus minimizing
4063 * flashing. Of course, if any subwindow is non-double buffered we
4064 * well flush earlier than that.
4066 * Thirdly, after having done the outstanding moves we queue an
4067 * "antiexpose" on the area that will be drawn by the expose, which
4068 * means that any invalid region on the native window side before
4069 * the first expose drawing operation will be discarded, as it
4070 * has by then been overdrawn with valid data. This means we can
4071 * avoid doing the unnecessary repaint any outstanding expose events.
4074 cairo_region_get_extents (update_area, &clip_box);
4075 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4076 expose_region = cairo_region_copy (update_area);
4079 /* Rendering is not double buffered by gdk, do outstanding
4080 * moves and queue antiexposure immediately. No need to do
4082 gdk_window_flush_outstanding_moves (window);
4083 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4084 save_region = impl_class->queue_antiexpose (window, update_area);
4087 /* Render the invalid areas to the implicit paint, by sending exposes.
4088 * May flush if non-double buffered widget draw. */
4089 _gdk_windowing_window_process_updates_recurse (window, expose_region);
4093 /* Do moves right before exposes are rendered to the window */
4094 gdk_window_flush_outstanding_moves (window);
4096 /* By this time we know that any outstanding expose for this
4097 * area is invalid and we can avoid it, so queue an antiexpose.
4098 * However, it may be that due to an non-double buffered expose
4099 * we have already started drawing to the window, so it would
4100 * be to late to anti-expose now. Since this is merely an
4101 * optimization we just avoid doing it at all in that case.
4103 if (window->implicit_paint != NULL &&
4104 !window->implicit_paint->flushed)
4106 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4107 save_region = impl_class->queue_antiexpose (window, update_area);
4110 gdk_window_end_implicit_paint (window);
4112 cairo_region_destroy (expose_region);
4115 cairo_region_destroy (update_area);
4118 if (window->outstanding_moves)
4120 /* Flush any outstanding moves, may happen if we moved a window but got
4121 no actual invalid area */
4122 gdk_window_flush_outstanding_moves (window);
4125 g_object_unref (window);
4129 flush_all_displays (void)
4131 GSList *displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4134 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
4135 gdk_display_flush (tmp_list->data);
4137 g_slist_free (displays);
4140 /* Currently it is not possible to override
4141 * gdk_window_process_all_updates in the same manner as
4142 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4143 * by implementing the GdkPaintable interface. If in the future a
4144 * backend would need this, the right solution would be to add a
4145 * method to GdkDisplay that can be optionally
4146 * NULL. gdk_window_process_all_updates can then walk the list of open
4147 * displays and call the mehod.
4151 * gdk_window_process_all_updates:
4153 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4154 * in the application.
4158 gdk_window_process_all_updates (void)
4160 GSList *old_update_windows = update_windows;
4161 GSList *tmp_list = update_windows;
4162 static gboolean in_process_all_updates = FALSE;
4163 static gboolean got_recursive_update = FALSE;
4165 if (in_process_all_updates)
4167 /* We can't do this now since that would recurse, so
4168 delay it until after the recursion is done. */
4169 got_recursive_update = TRUE;
4174 in_process_all_updates = TRUE;
4175 got_recursive_update = FALSE;
4178 g_source_remove (update_idle);
4180 update_windows = NULL;
4183 _gdk_windowing_before_process_all_updates ();
4185 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4189 GdkWindow *window = tmp_list->data;
4191 if (!GDK_WINDOW_DESTROYED (window))
4193 if (window->update_freeze_count ||
4194 gdk_window_is_toplevel_frozen (window))
4195 gdk_window_add_update_window (window);
4197 gdk_window_process_updates_internal (window);
4200 g_object_unref (window);
4201 tmp_list = tmp_list->next;
4204 g_slist_free (old_update_windows);
4206 flush_all_displays ();
4208 _gdk_windowing_after_process_all_updates ();
4210 in_process_all_updates = FALSE;
4212 /* If we ignored a recursive call, schedule a
4213 redraw now so that it eventually happens,
4214 otherwise we could miss an update if nothing
4215 else schedules an update. */
4216 if (got_recursive_update && !update_idle)
4218 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4219 gdk_window_update_idle,
4224 * gdk_window_process_updates:
4225 * @window: a #GdkWindow
4226 * @update_children: whether to also process updates for child windows
4228 * Sends one or more expose events to @window. The areas in each
4229 * expose event will cover the entire update area for the window (see
4230 * gdk_window_invalidate_region() for details). Normally GDK calls
4231 * gdk_window_process_all_updates() on your behalf, so there's no
4232 * need to call this function unless you want to force expose events
4233 * to be delivered immediately and synchronously (vs. the usual
4234 * case, where GDK delivers them in an idle handler). Occasionally
4235 * this is useful to produce nicer scrolling behavior, for example.
4239 gdk_window_process_updates (GdkWindow *window,
4240 gboolean update_children)
4242 GdkWindow *impl_window;
4244 g_return_if_fail (GDK_IS_WINDOW (window));
4246 if (GDK_WINDOW_DESTROYED (window))
4249 /* Make sure the window lives during the expose callouts */
4250 g_object_ref (window);
4252 impl_window = gdk_window_get_impl_window (window);
4253 if ((impl_window->update_area ||
4254 impl_window->outstanding_moves) &&
4255 !impl_window->update_freeze_count &&
4256 !gdk_window_is_toplevel_frozen (window) &&
4258 /* Don't recurse into process_updates_internal, we'll
4259 * do the update later when idle instead. */
4260 impl_window->implicit_paint == NULL)
4262 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4263 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4266 if (update_children)
4268 /* process updates in reverse stacking order so composition or
4269 * painting over achieves the desired effect for offscreen windows
4271 GList *node, *children;
4273 children = g_list_copy (window->children);
4274 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4276 for (node = g_list_last (children); node; node = node->prev)
4278 gdk_window_process_updates (node->data, TRUE);
4279 g_object_unref (node->data);
4282 g_list_free (children);
4285 g_object_unref (window);
4289 gdk_window_invalidate_rect_full (GdkWindow *window,
4290 const GdkRectangle *rect,
4291 gboolean invalidate_children,
4294 GdkRectangle window_rect;
4295 cairo_region_t *region;
4297 g_return_if_fail (GDK_IS_WINDOW (window));
4299 if (GDK_WINDOW_DESTROYED (window))
4302 if (window->input_only || !window->viewable)
4309 window_rect.width = window->width;
4310 window_rect.height = window->height;
4311 rect = &window_rect;
4314 region = cairo_region_create_rectangle (rect);
4315 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4316 cairo_region_destroy (region);
4320 * gdk_window_invalidate_rect:
4321 * @window: a #GdkWindow
4322 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4324 * @invalidate_children: whether to also invalidate child windows
4326 * A convenience wrapper around gdk_window_invalidate_region() which
4327 * invalidates a rectangular region. See
4328 * gdk_window_invalidate_region() for details.
4331 gdk_window_invalidate_rect (GdkWindow *window,
4332 const GdkRectangle *rect,
4333 gboolean invalidate_children)
4335 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4339 draw_ugly_color (GdkWindow *window,
4340 const cairo_region_t *region)
4344 cr = gdk_cairo_create (window);
4345 /* Draw ugly color all over the newly-invalid region */
4346 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4347 gdk_cairo_region (cr, region);
4354 impl_window_add_update_area (GdkWindow *impl_window,
4355 cairo_region_t *region)
4357 if (impl_window->update_area)
4358 cairo_region_union (impl_window->update_area, region);
4361 gdk_window_add_update_window (impl_window);
4362 impl_window->update_area = cairo_region_copy (region);
4363 gdk_window_schedule_update (impl_window);
4367 /* clear_bg controls if the region will be cleared to
4368 * the background pattern if the exposure mask is not
4369 * set for the window, whereas this might not otherwise be
4370 * done (unless necessary to emulate background settings).
4371 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4372 * need to clear the background, such as when exposing the area beneath a
4373 * hidden or moved window, but not when an app requests repaint or when the
4374 * windowing system exposes a newly visible area (because then the windowing
4375 * system has already cleared the area).
4378 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4379 const cairo_region_t *region,
4381 GdkWindowChildFunc child_func,
4384 GdkWindow *impl_window;
4385 cairo_region_t *visible_region;
4388 g_return_if_fail (GDK_IS_WINDOW (window));
4390 if (GDK_WINDOW_DESTROYED (window))
4393 if (window->input_only ||
4394 !window->viewable ||
4395 cairo_region_is_empty (region) ||
4396 window->window_type == GDK_WINDOW_ROOT)
4399 visible_region = gdk_window_get_visible_region (window);
4400 cairo_region_intersect (visible_region, region);
4402 tmp_list = window->children;
4405 GdkWindow *child = tmp_list->data;
4407 if (!child->input_only)
4409 cairo_region_t *child_region;
4410 GdkRectangle child_rect;
4412 child_rect.x = child->x;
4413 child_rect.y = child->y;
4414 child_rect.width = child->width;
4415 child_rect.height = child->height;
4416 child_region = cairo_region_create_rectangle (&child_rect);
4418 /* remove child area from the invalid area of the parent */
4419 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4420 !child->composited &&
4421 !gdk_window_is_offscreen (child))
4422 cairo_region_subtract (visible_region, child_region);
4424 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4426 cairo_region_t *tmp = cairo_region_copy (region);
4428 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4429 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4430 cairo_region_intersect (child_region, tmp);
4432 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4433 child_region, clear_bg, child_func, user_data);
4435 cairo_region_destroy (tmp);
4438 cairo_region_destroy (child_region);
4441 tmp_list = tmp_list->next;
4444 impl_window = gdk_window_get_impl_window (window);
4446 if (!cairo_region_is_empty (visible_region) ||
4447 /* Even if we're not exposing anything, make sure we process
4448 idles for windows with outstanding moves */
4449 (impl_window->outstanding_moves != NULL &&
4450 impl_window->update_area == NULL))
4453 draw_ugly_color (window, region);
4455 /* Convert to impl coords */
4456 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4458 /* Only invalidate area if app requested expose events or if
4459 we need to clear the area (by request or to emulate background
4460 clearing for non-native windows or native windows with no support
4461 for window backgrounds */
4462 if (window->event_mask & GDK_EXPOSURE_MASK ||
4463 clear_bg == CLEAR_BG_ALL ||
4464 clear_bg == CLEAR_BG_WINCLEARED)
4465 impl_window_add_update_area (impl_window, visible_region);
4468 cairo_region_destroy (visible_region);
4472 * gdk_window_invalidate_maybe_recurse:
4473 * @window: a #GdkWindow
4474 * @region: a #cairo_region_t
4475 * @child_func: function to use to decide if to recurse to a child,
4476 * %NULL means never recurse.
4477 * @user_data: data passed to @child_func
4479 * Adds @region to the update area for @window. The update area is the
4480 * region that needs to be redrawn, or "dirty region." The call
4481 * gdk_window_process_updates() sends one or more expose events to the
4482 * window, which together cover the entire update area. An
4483 * application would normally redraw the contents of @window in
4484 * response to those expose events.
4486 * GDK will call gdk_window_process_all_updates() on your behalf
4487 * whenever your program returns to the main loop and becomes idle, so
4488 * normally there's no need to do that manually, you just need to
4489 * invalidate regions that you know should be redrawn.
4491 * The @child_func parameter controls whether the region of
4492 * each child window that intersects @region will also be invalidated.
4493 * Only children for which @child_func returns TRUE will have the area
4497 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4498 const cairo_region_t *region,
4499 GdkWindowChildFunc child_func,
4502 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4503 child_func, user_data);
4507 true_predicate (GdkWindow *window,
4514 gdk_window_invalidate_region_full (GdkWindow *window,
4515 const cairo_region_t *region,
4516 gboolean invalidate_children,
4519 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4520 invalidate_children ?
4521 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4526 * gdk_window_invalidate_region:
4527 * @window: a #GdkWindow
4528 * @region: a #cairo_region_t
4529 * @invalidate_children: %TRUE to also invalidate child windows
4531 * Adds @region to the update area for @window. The update area is the
4532 * region that needs to be redrawn, or "dirty region." The call
4533 * gdk_window_process_updates() sends one or more expose events to the
4534 * window, which together cover the entire update area. An
4535 * application would normally redraw the contents of @window in
4536 * response to those expose events.
4538 * GDK will call gdk_window_process_all_updates() on your behalf
4539 * whenever your program returns to the main loop and becomes idle, so
4540 * normally there's no need to do that manually, you just need to
4541 * invalidate regions that you know should be redrawn.
4543 * The @invalidate_children parameter controls whether the region of
4544 * each child window that intersects @region will also be invalidated.
4545 * If %FALSE, then the update area for child windows will remain
4546 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4547 * fine grained control over which children are invalidated.
4550 gdk_window_invalidate_region (GdkWindow *window,
4551 const cairo_region_t *region,
4552 gboolean invalidate_children)
4554 gdk_window_invalidate_maybe_recurse (window, region,
4555 invalidate_children ?
4556 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4561 * _gdk_window_invalidate_for_expose:
4562 * @window: a #GdkWindow
4563 * @region: a #cairo_region_t
4565 * Adds @region to the update area for @window. The update area is the
4566 * region that needs to be redrawn, or "dirty region." The call
4567 * gdk_window_process_updates() sends one or more expose events to the
4568 * window, which together cover the entire update area. An
4569 * application would normally redraw the contents of @window in
4570 * response to those expose events.
4572 * GDK will call gdk_window_process_all_updates() on your behalf
4573 * whenever your program returns to the main loop and becomes idle, so
4574 * normally there's no need to do that manually, you just need to
4575 * invalidate regions that you know should be redrawn.
4577 * This version of invalidation is used when you recieve expose events
4578 * from the native window system. It exposes the native window, plus
4579 * any non-native child windows (but not native child windows, as those would
4580 * have gotten their own expose events).
4583 _gdk_window_invalidate_for_expose (GdkWindow *window,
4584 cairo_region_t *region)
4586 GdkWindowRegionMove *move;
4587 cairo_region_t *move_region;
4590 /* Any invalidations comming from the windowing system will
4591 be in areas that may be moved by outstanding moves,
4592 so we need to modify the expose region correspondingly,
4593 otherwise we would expose in the wrong place, as the
4594 outstanding moves will be copied before we draw the
4596 for (l = window->outstanding_moves; l != NULL; l = l->next)
4600 /* covert to move source region */
4601 move_region = cairo_region_copy (move->dest_region);
4602 cairo_region_translate (move_region, -move->dx, -move->dy);
4604 /* Move area of region that intersects with move source
4605 by dx, dy of the move*/
4606 cairo_region_intersect (move_region, region);
4607 cairo_region_subtract (region, move_region);
4608 cairo_region_translate (move_region, move->dx, move->dy);
4609 cairo_region_union (region, move_region);
4611 cairo_region_destroy (move_region);
4614 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4615 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4621 * gdk_window_get_update_area:
4622 * @window: a #GdkWindow
4624 * Transfers ownership of the update area from @window to the caller
4625 * of the function. That is, after calling this function, @window will
4626 * no longer have an invalid/dirty region; the update area is removed
4627 * from @window and handed to you. If a window has no update area,
4628 * gdk_window_get_update_area() returns %NULL. You are responsible for
4629 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4631 * Return value: the update area for @window
4634 gdk_window_get_update_area (GdkWindow *window)
4636 GdkWindow *impl_window;
4637 cairo_region_t *tmp_region;
4639 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4641 impl_window = gdk_window_get_impl_window (window);
4643 if (impl_window->update_area)
4645 tmp_region = cairo_region_copy (window->clip_region_with_children);
4646 /* Convert to impl coords */
4647 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4648 cairo_region_intersect (tmp_region, impl_window->update_area);
4650 if (cairo_region_is_empty (tmp_region))
4652 cairo_region_destroy (tmp_region);
4657 cairo_region_subtract (impl_window->update_area, tmp_region);
4659 if (cairo_region_is_empty (impl_window->update_area) &&
4660 impl_window->outstanding_moves == NULL)
4662 cairo_region_destroy (impl_window->update_area);
4663 impl_window->update_area = NULL;
4665 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4668 /* Convert from impl coords */
4669 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4679 * _gdk_window_clear_update_area:
4680 * @window: a #GdkWindow.
4682 * Internal function to clear the update area for a window. This
4683 * is called when the window is hidden or destroyed.
4686 _gdk_window_clear_update_area (GdkWindow *window)
4688 g_return_if_fail (GDK_IS_WINDOW (window));
4690 if (window->update_area)
4692 gdk_window_remove_update_window (window);
4694 cairo_region_destroy (window->update_area);
4695 window->update_area = NULL;
4700 * gdk_window_freeze_updates:
4701 * @window: a #GdkWindow
4703 * Temporarily freezes a window such that it won't receive expose
4704 * events. The window will begin receiving expose events again when
4705 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4706 * has been called more than once, gdk_window_thaw_updates() must be called
4707 * an equal number of times to begin processing exposes.
4710 gdk_window_freeze_updates (GdkWindow *window)
4712 GdkWindow *impl_window;
4714 g_return_if_fail (GDK_IS_WINDOW (window));
4716 impl_window = gdk_window_get_impl_window (window);
4717 impl_window->update_freeze_count++;
4721 * gdk_window_thaw_updates:
4722 * @window: a #GdkWindow
4724 * Thaws a window frozen with gdk_window_freeze_updates().
4727 gdk_window_thaw_updates (GdkWindow *window)
4729 GdkWindow *impl_window;
4731 g_return_if_fail (GDK_IS_WINDOW (window));
4733 impl_window = gdk_window_get_impl_window (window);
4735 g_return_if_fail (impl_window->update_freeze_count > 0);
4737 if (--impl_window->update_freeze_count == 0)
4738 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4742 * gdk_window_freeze_toplevel_updates_libgtk_only:
4743 * @window: a #GdkWindow
4745 * Temporarily freezes a window and all its descendants such that it won't
4746 * receive expose events. The window will begin receiving expose events
4747 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4748 * gdk_window_freeze_toplevel_updates_libgtk_only()
4749 * has been called more than once,
4750 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4751 * an equal number of times to begin processing exposes.
4753 * This function is not part of the GDK public API and is only
4757 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4759 g_return_if_fail (GDK_IS_WINDOW (window));
4760 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4762 window->update_and_descendants_freeze_count++;
4766 * gdk_window_thaw_toplevel_updates_libgtk_only:
4767 * @window: a #GdkWindow
4769 * Thaws a window frozen with
4770 * gdk_window_freeze_toplevel_updates_libgtk_only().
4772 * This function is not part of the GDK public API and is only
4776 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4778 g_return_if_fail (GDK_IS_WINDOW (window));
4779 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4780 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4782 window->update_and_descendants_freeze_count--;
4784 gdk_window_schedule_update (window);
4788 * gdk_window_set_debug_updates:
4789 * @setting: %TRUE to turn on update debugging
4791 * With update debugging enabled, calls to
4792 * gdk_window_invalidate_region() clear the invalidated region of the
4793 * screen to a noticeable color, and GDK pauses for a short time
4794 * before sending exposes to windows during
4795 * gdk_window_process_updates(). The net effect is that you can see
4796 * the invalid region for each window and watch redraws as they
4797 * occur. This allows you to diagnose inefficiencies in your application.
4799 * In essence, because the GDK rendering model prevents all flicker,
4800 * if you are redrawing the same region 400 times you may never
4801 * notice, aside from noticing a speed problem. Enabling update
4802 * debugging causes GTK to flicker slowly and noticeably, so you can
4803 * see exactly what's being redrawn when, in what order.
4805 * The --gtk-debug=updates command line option passed to GTK+ programs
4806 * enables this debug option at application startup time. That's
4807 * usually more useful than calling gdk_window_set_debug_updates()
4808 * yourself, though you might want to use this function to enable
4809 * updates sometime after application startup time.
4813 gdk_window_set_debug_updates (gboolean setting)
4815 debug_updates = setting;
4819 * gdk_window_constrain_size:
4820 * @geometry: a #GdkGeometry structure
4821 * @flags: a mask indicating what portions of @geometry are set
4822 * @width: desired width of window
4823 * @height: desired height of the window
4824 * @new_width: location to store resulting width
4825 * @new_height: location to store resulting height
4827 * Constrains a desired width and height according to a
4828 * set of geometry hints (such as minimum and maximum size).
4831 gdk_window_constrain_size (GdkGeometry *geometry,
4838 /* This routine is partially borrowed from fvwm.
4840 * Copyright 1993, Robert Nation
4841 * You may use this code for any purpose, as long as the original
4842 * copyright remains in the source code and all documentation
4844 * which in turn borrows parts of the algorithm from uwm
4847 gint min_height = 0;
4848 gint base_width = 0;
4849 gint base_height = 0;
4852 gint max_width = G_MAXINT;
4853 gint max_height = G_MAXINT;
4855 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4857 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4859 base_width = geometry->base_width;
4860 base_height = geometry->base_height;
4861 min_width = geometry->min_width;
4862 min_height = geometry->min_height;
4864 else if (flags & GDK_HINT_BASE_SIZE)
4866 base_width = geometry->base_width;
4867 base_height = geometry->base_height;
4868 min_width = geometry->base_width;
4869 min_height = geometry->base_height;
4871 else if (flags & GDK_HINT_MIN_SIZE)
4873 base_width = geometry->min_width;
4874 base_height = geometry->min_height;
4875 min_width = geometry->min_width;
4876 min_height = geometry->min_height;
4879 if (flags & GDK_HINT_MAX_SIZE)
4881 max_width = geometry->max_width ;
4882 max_height = geometry->max_height;
4885 if (flags & GDK_HINT_RESIZE_INC)
4887 xinc = MAX (xinc, geometry->width_inc);
4888 yinc = MAX (yinc, geometry->height_inc);
4891 /* clamp width and height to min and max values
4893 width = CLAMP (width, min_width, max_width);
4894 height = CLAMP (height, min_height, max_height);
4896 /* shrink to base + N * inc
4898 width = base_width + FLOOR (width - base_width, xinc);
4899 height = base_height + FLOOR (height - base_height, yinc);
4901 /* constrain aspect ratio, according to:
4904 * min_aspect <= -------- <= max_aspect
4908 if (flags & GDK_HINT_ASPECT &&
4909 geometry->min_aspect > 0 &&
4910 geometry->max_aspect > 0)
4914 if (geometry->min_aspect * height > width)
4916 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4917 if (height - delta >= min_height)
4921 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4922 if (width + delta <= max_width)
4927 if (geometry->max_aspect * height < width)
4929 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4930 if (width - delta >= min_width)
4934 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4935 if (height + delta <= max_height)
4944 *new_height = height;
4948 * gdk_window_get_pointer:
4949 * @window: a #GdkWindow
4950 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4951 * return the X coordinate
4952 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4953 * return the Y coordinate
4954 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4957 * Obtains the current pointer position and modifier state.
4958 * The position is given in coordinates relative to the upper left
4959 * corner of @window.
4961 * Return value: (transfer none): the window containing the pointer (as with
4962 * gdk_window_at_pointer()), or %NULL if the window containing the
4963 * pointer isn't known to GDK
4965 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4968 gdk_window_get_pointer (GdkWindow *window,
4971 GdkModifierType *mask)
4973 GdkDisplay *display;
4975 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4977 display = gdk_window_get_display (window);
4979 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
4983 * gdk_window_get_device_position:
4984 * @window: a #GdkWindow.
4985 * @device: #GdkDevice to query to.
4986 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
4987 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
4988 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
4990 * Obtains the current device position and modifier state.
4991 * The position is given in coordinates relative to the upper left
4992 * corner of @window.
4994 * Return value: (transfer none): The window underneath @device (as with
4995 * gdk_display_get_window_at_device_position()), or %NULL if the
4996 * window is not known to GDK.
5001 gdk_window_get_device_position (GdkWindow *window,
5005 GdkModifierType *mask)
5007 GdkDisplay *display;
5009 GdkModifierType tmp_mask;
5012 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5013 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5018 display = gdk_window_get_display (window);
5019 child = display->device_hooks->window_get_device_position (display, device, window,
5020 &tmp_x, &tmp_y, &tmp_mask);
5029 _gdk_display_enable_motion_hints (display, device);
5035 * gdk_window_at_pointer:
5036 * @win_x: (out) (allow-none): return location for origin of the window under the pointer
5037 * @win_y: (out) (allow-none): return location for origin of the window under the pointer
5039 * Obtains the window underneath the mouse pointer, returning the
5040 * location of that window in @win_x, @win_y. Returns %NULL if the
5041 * window under the mouse pointer is not known to GDK (if the window
5042 * belongs to another application and a #GdkWindow hasn't been created
5043 * for it with gdk_window_foreign_new())
5045 * NOTE: For multihead-aware widgets or applications use
5046 * gdk_display_get_window_at_pointer() instead.
5048 * Return value: (transfer none): window under the mouse pointer
5050 * Deprecated: 3.0: Use gdk_display_get_window_at_device_position() instead.
5053 gdk_window_at_pointer (gint *win_x,
5056 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
5060 * gdk_get_default_root_window:
5062 * Obtains the root window (parent all other windows are inside)
5063 * for the default display and screen.
5065 * Return value: (transfer none): the default root window
5068 gdk_get_default_root_window (void)
5070 return gdk_screen_get_root_window (gdk_screen_get_default ());
5074 * gdk_window_foreign_new:
5075 * @anid: a native window handle.
5077 * Wraps a native window for the default display in a #GdkWindow.
5078 * This may fail if the window has been destroyed.
5080 * For example in the X backend, a native window handle is an Xlib
5083 * Return value: (transfer full): the newly-created #GdkWindow wrapper
5084 * for the native window, or %NULL if the window has been destroyed.
5087 gdk_window_foreign_new (GdkNativeWindow anid)
5089 return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);
5093 get_all_native_children (GdkWindow *window,
5099 for (l = window->children; l != NULL; l = l->next)
5103 if (gdk_window_has_impl (child))
5104 *native = g_list_prepend (*native, child);
5106 get_all_native_children (child, native);
5112 gdk_window_raise_internal (GdkWindow *window)
5114 GdkWindow *parent = window->parent;
5116 GList *native_children;
5118 GdkWindowImplClass *impl_class;
5122 parent->children = g_list_remove (parent->children, window);
5123 parent->children = g_list_prepend (parent->children, window);
5126 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5127 /* Just do native raise for toplevels */
5128 if (gdk_window_is_toplevel (window) ||
5129 /* The restack_under codepath should work correctly even if the parent
5130 is native, but it relies on the order of ->children to be correct,
5131 and some apps like SWT reorder the x windows without gdks knowledge,
5132 so we use raise directly in order to make these behave as before
5133 when using native windows */
5134 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5136 impl_class->raise (window);
5138 else if (gdk_window_has_impl (window))
5140 above = find_native_sibling_above (parent, window);
5143 listhead.data = window;
5144 listhead.next = NULL;
5145 listhead.prev = NULL;
5146 impl_class->restack_under ((GdkWindow *)above,
5150 impl_class->raise (window);
5154 native_children = NULL;
5155 get_all_native_children (window, &native_children);
5156 if (native_children != NULL)
5158 above = find_native_sibling_above (parent, window);
5161 impl_class->restack_under (above, native_children);
5164 /* Right order, since native_children is bottom-topmost first */
5165 for (l = native_children; l != NULL; l = l->next)
5166 impl_class->raise (l->data);
5169 g_list_free (native_children);
5175 /* Returns TRUE If the native window was mapped or unmapped */
5177 set_viewable (GdkWindow *w,
5181 GdkWindowImplClass *impl_class;
5184 if (w->viewable == val)
5190 recompute_visible_regions (w, FALSE, FALSE);
5192 for (l = w->children; l != NULL; l = l->next)
5196 if (GDK_WINDOW_IS_MAPPED (child) &&
5197 child->window_type != GDK_WINDOW_FOREIGN)
5198 set_viewable (child, val);
5201 if (!_gdk_native_windows &&
5202 gdk_window_has_impl (w) &&
5203 w->window_type != GDK_WINDOW_FOREIGN &&
5204 !gdk_window_is_toplevel (w))
5206 /* For most native windows we show/hide them not when they are
5207 * mapped/unmapped, because that may not produce the correct results.
5208 * For instance, if a native window have a non-native parent which is
5209 * hidden, but its native parent is viewable then showing the window
5210 * would make it viewable to X but its not viewable wrt the non-native
5211 * hierarchy. In order to handle this we track the gdk side viewability
5212 * and only map really viewable windows.
5214 * There are two exceptions though:
5216 * For foreign windows we don't want ever change the mapped state
5217 * except when explicitly done via gdk_window_show/hide, as this may
5218 * cause problems for client owning the foreign window when its window
5219 * is suddenly mapped or unmapped.
5221 * For toplevel windows embedded in a foreign window (e.g. a plug)
5222 * we sometimes synthesize a map of a window, but the native
5223 * window is really shown by the embedder, so we don't want to
5224 * do the show ourselves. We can't really tell this case from the normal
5225 * toplevel show as such toplevels are seen by gdk as parents of the
5226 * root window, so we make an exception for all toplevels.
5228 * Also, when in GDK_NATIVE_WINDOW mode we never need to play games
5229 * like this, so we just always show/hide directly.
5232 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5234 impl_class->show ((GdkWindow *)w, FALSE);
5236 impl_class->hide ((GdkWindow *)w);
5244 /* Returns TRUE If the native window was mapped or unmapped */
5246 _gdk_window_update_viewable (GdkWindow *window)
5250 if (window->window_type == GDK_WINDOW_FOREIGN ||
5251 window->window_type == GDK_WINDOW_ROOT)
5253 else if (gdk_window_is_toplevel (window) ||
5254 window->parent->viewable)
5255 viewable = GDK_WINDOW_IS_MAPPED (window);
5259 return set_viewable (window, viewable);
5263 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5265 GdkWindowImplClass *impl_class;
5266 gboolean was_mapped, was_viewable;
5269 g_return_if_fail (GDK_IS_WINDOW (window));
5271 if (window->destroyed)
5274 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5275 was_viewable = window->viewable;
5278 /* Keep children in (reverse) stacking order */
5279 gdk_window_raise_internal (window);
5281 if (gdk_window_has_impl (window))
5284 gdk_synthesize_window_state (window,
5285 GDK_WINDOW_STATE_WITHDRAWN,
5293 did_show = _gdk_window_update_viewable (window);
5295 /* If it was already viewable the backend show op won't be called, call it
5296 again to ensure things happen right if the mapped tracking was not right
5297 for e.g. a foreign window.
5298 Dunno if this is strictly needed but its what happened pre-csw.
5299 Also show if not done by gdk_window_update_viewable. */
5300 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5302 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5303 impl_class->show (window, !did_show ? was_mapped : TRUE);
5306 if (!was_mapped && !gdk_window_has_impl (window))
5308 if (window->event_mask & GDK_STRUCTURE_MASK)
5309 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5311 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5312 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5315 if (!was_mapped || raise)
5317 recompute_visible_regions (window, TRUE, FALSE);
5319 /* If any decendants became visible we need to send visibility notify */
5320 gdk_window_update_visibility_recursively (window, NULL);
5322 if (gdk_window_is_viewable (window))
5324 _gdk_synthesize_crossing_events_for_geometry_change (window);
5325 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5331 * gdk_window_show_unraised:
5332 * @window: a #GdkWindow
5334 * Shows a #GdkWindow onscreen, but does not modify its stacking
5335 * order. In contrast, gdk_window_show() will raise the window
5336 * to the top of the window stack.
5338 * On the X11 platform, in Xlib terms, this function calls
5339 * XMapWindow() (it also updates some internal GDK state, which means
5340 * that you can't really use XMapWindow() directly on a GDK window).
5343 gdk_window_show_unraised (GdkWindow *window)
5345 gdk_window_show_internal (window, FALSE);
5350 * @window: a #GdkWindow
5352 * Raises @window to the top of the Z-order (stacking order), so that
5353 * other windows with the same parent window appear below @window.
5354 * This is true whether or not the windows are visible.
5356 * If @window is a toplevel, the window manager may choose to deny the
5357 * request to move the window in the Z-order, gdk_window_raise() only
5358 * requests the restack, does not guarantee it.
5361 gdk_window_raise (GdkWindow *window)
5363 cairo_region_t *old_region, *new_region;
5365 g_return_if_fail (GDK_IS_WINDOW (window));
5367 if (window->destroyed)
5370 gdk_window_flush_if_exposing (window);
5373 if (gdk_window_is_viewable (window) &&
5374 !window->input_only)
5375 old_region = cairo_region_copy (window->clip_region);
5377 /* Keep children in (reverse) stacking order */
5378 gdk_window_raise_internal (window);
5380 recompute_visible_regions (window, TRUE, FALSE);
5384 new_region = cairo_region_copy (window->clip_region);
5386 cairo_region_subtract (new_region, old_region);
5387 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_ALL);
5389 cairo_region_destroy (old_region);
5390 cairo_region_destroy (new_region);
5395 gdk_window_lower_internal (GdkWindow *window)
5397 GdkWindow *parent = window->parent;
5398 GdkWindowImplClass *impl_class;
5400 GList *native_children;
5405 parent->children = g_list_remove (parent->children, window);
5406 parent->children = g_list_append (parent->children, window);
5409 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5410 /* Just do native lower for toplevels */
5411 if (gdk_window_is_toplevel (window) ||
5412 /* The restack_under codepath should work correctly even if the parent
5413 is native, but it relies on the order of ->children to be correct,
5414 and some apps like SWT reorder the x windows without gdks knowledge,
5415 so we use lower directly in order to make these behave as before
5416 when using native windows */
5417 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5419 impl_class->lower (window);
5421 else if (gdk_window_has_impl (window))
5423 above = find_native_sibling_above (parent, window);
5426 listhead.data = window;
5427 listhead.next = NULL;
5428 listhead.prev = NULL;
5429 impl_class->restack_under ((GdkWindow *)above, &listhead);
5432 impl_class->raise (window);
5436 native_children = NULL;
5437 get_all_native_children (window, &native_children);
5438 if (native_children != NULL)
5440 above = find_native_sibling_above (parent, window);
5443 impl_class->restack_under ((GdkWindow *)above,
5447 /* Right order, since native_children is bottom-topmost first */
5448 for (l = native_children; l != NULL; l = l->next)
5449 impl_class->raise (l->data);
5452 g_list_free (native_children);
5459 gdk_window_invalidate_in_parent (GdkWindow *private)
5461 GdkRectangle r, child;
5463 if (gdk_window_is_toplevel (private))
5466 /* get the visible rectangle of the parent */
5468 r.width = private->parent->width;
5469 r.height = private->parent->height;
5471 child.x = private->x;
5472 child.y = private->y;
5473 child.width = private->width;
5474 child.height = private->height;
5475 gdk_rectangle_intersect (&r, &child, &r);
5477 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5483 * @window: a #GdkWindow
5485 * Lowers @window to the bottom of the Z-order (stacking order), so that
5486 * other windows with the same parent window appear above @window.
5487 * This is true whether or not the other windows are visible.
5489 * If @window is a toplevel, the window manager may choose to deny the
5490 * request to move the window in the Z-order, gdk_window_lower() only
5491 * requests the restack, does not guarantee it.
5493 * Note that gdk_window_show() raises the window again, so don't call this
5494 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5497 gdk_window_lower (GdkWindow *window)
5499 g_return_if_fail (GDK_IS_WINDOW (window));
5501 if (window->destroyed)
5504 gdk_window_flush_if_exposing (window);
5506 /* Keep children in (reverse) stacking order */
5507 gdk_window_lower_internal (window);
5509 recompute_visible_regions (window, TRUE, FALSE);
5511 _gdk_synthesize_crossing_events_for_geometry_change (window);
5512 gdk_window_invalidate_in_parent (window);
5516 * gdk_window_restack:
5517 * @window: a #GdkWindow
5518 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5521 * Changes the position of @window in the Z-order (stacking order), so that
5522 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5525 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5526 * lowers the window.
5528 * If @window is a toplevel, the window manager may choose to deny the
5529 * request to move the window in the Z-order, gdk_window_restack() only
5530 * requests the restack, does not guarantee it.
5535 gdk_window_restack (GdkWindow *window,
5539 GdkWindowImplClass *impl_class;
5541 GdkWindow *above_native;
5542 GList *sibling_link;
5543 GList *native_children;
5546 g_return_if_fail (GDK_IS_WINDOW (window));
5547 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5549 if (window->destroyed)
5552 if (sibling == NULL)
5555 gdk_window_raise (window);
5557 gdk_window_lower (window);
5561 gdk_window_flush_if_exposing (window);
5563 if (gdk_window_is_toplevel (window))
5565 g_return_if_fail (gdk_window_is_toplevel (sibling));
5566 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5567 impl_class->restack_toplevel (window, sibling, above);
5571 parent = window->parent;
5574 sibling_link = g_list_find (parent->children, sibling);
5575 g_return_if_fail (sibling_link != NULL);
5576 if (sibling_link == NULL)
5579 parent->children = g_list_remove (parent->children, window);
5581 parent->children = g_list_insert_before (parent->children,
5585 parent->children = g_list_insert_before (parent->children,
5589 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5590 if (gdk_window_has_impl (window))
5592 above_native = find_native_sibling_above (parent, window);
5595 listhead.data = window;
5596 listhead.next = NULL;
5597 listhead.prev = NULL;
5598 impl_class->restack_under (above_native, &listhead);
5601 impl_class->raise (window);
5605 native_children = NULL;
5606 get_all_native_children (window, &native_children);
5607 if (native_children != NULL)
5609 above_native = find_native_sibling_above (parent, window);
5611 impl_class->restack_under (above_native,
5615 /* Right order, since native_children is bottom-topmost first */
5616 for (l = native_children; l != NULL; l = l->next)
5617 impl_class->raise (l->data);
5620 g_list_free (native_children);
5625 recompute_visible_regions (window, TRUE, FALSE);
5627 _gdk_synthesize_crossing_events_for_geometry_change (window);
5628 gdk_window_invalidate_in_parent (window);
5634 * @window: a #GdkWindow
5636 * Like gdk_window_show_unraised(), but also raises the window to the
5637 * top of the window stack (moves the window to the front of the
5640 * This function maps a window so it's visible onscreen. Its opposite
5641 * is gdk_window_hide().
5643 * When implementing a #GtkWidget, you should call this function on the widget's
5644 * #GdkWindow as part of the "map" method.
5647 gdk_window_show (GdkWindow *window)
5649 gdk_window_show_internal (window, TRUE);
5654 * @window: a #GdkWindow
5656 * For toplevel windows, withdraws them, so they will no longer be
5657 * known to the window manager; for all windows, unmaps them, so
5658 * they won't be displayed. Normally done automatically as
5659 * part of gtk_widget_hide().
5662 gdk_window_hide (GdkWindow *window)
5664 GdkWindowImplClass *impl_class;
5665 gboolean was_mapped, did_hide;
5667 g_return_if_fail (GDK_IS_WINDOW (window));
5669 if (window->destroyed)
5672 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5674 if (gdk_window_has_impl (window))
5677 if (GDK_WINDOW_IS_MAPPED (window))
5678 gdk_synthesize_window_state (window,
5680 GDK_WINDOW_STATE_WITHDRAWN);
5682 else if (was_mapped)
5684 GdkDisplay *display;
5685 GdkDeviceManager *device_manager;
5688 /* May need to break grabs on children */
5689 display = gdk_window_get_display (window);
5690 device_manager = gdk_display_get_device_manager (display);
5692 /* Get all devices */
5693 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5694 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5695 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5697 for (d = devices; d; d = d->next)
5699 GdkDevice *device = d->data;
5701 if (_gdk_display_end_device_grab (display, device,
5702 _gdk_windowing_window_get_next_serial (display),
5705 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5708 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5709 g_list_free (devices);
5712 did_hide = _gdk_window_update_viewable (window);
5714 /* Hide foreign window as those are not handled by update_viewable. */
5715 if (gdk_window_has_impl (window) && (!did_hide))
5717 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5718 impl_class->hide (window);
5721 recompute_visible_regions (window, TRUE, FALSE);
5723 /* all decendants became non-visible, we need to send visibility notify */
5724 gdk_window_update_visibility_recursively (window, NULL);
5726 if (was_mapped && !gdk_window_has_impl (window))
5728 if (window->event_mask & GDK_STRUCTURE_MASK)
5729 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5731 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5732 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5734 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5737 /* Invalidate the rect */
5739 gdk_window_invalidate_in_parent (window);
5743 * gdk_window_withdraw:
5744 * @window: a toplevel #GdkWindow
5746 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5747 * This function is not really useful as gdk_window_hide() automatically
5748 * withdraws toplevel windows before hiding them.
5751 gdk_window_withdraw (GdkWindow *window)
5753 GdkWindowImplClass *impl_class;
5754 gboolean was_mapped;
5756 g_return_if_fail (GDK_IS_WINDOW (window));
5758 if (window->destroyed)
5761 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5763 if (gdk_window_has_impl (window))
5765 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5766 impl_class->withdraw (window);
5770 if (window->event_mask & GDK_STRUCTURE_MASK)
5771 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5773 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5774 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5776 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5779 recompute_visible_regions (window, TRUE, FALSE);
5784 * gdk_window_set_events:
5785 * @window: a #GdkWindow
5786 * @event_mask: event mask for @window
5788 * The event mask for a window determines which events will be reported
5789 * for that window from all master input devices. For example, an event mask
5790 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5791 * press events. The event mask is the bitwise OR of values from the
5792 * #GdkEventMask enumeration.
5795 gdk_window_set_events (GdkWindow *window,
5796 GdkEventMask event_mask)
5798 GdkWindowImplClass *impl_class;
5799 GdkDisplay *display;
5801 g_return_if_fail (GDK_IS_WINDOW (window));
5803 if (window->destroyed)
5806 /* If motion hint is disabled, enable motion events again */
5807 display = gdk_window_get_display (window);
5808 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5809 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5811 GList *devices = window->devices_inside;
5815 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5816 devices = devices->next;
5820 window->event_mask = event_mask;
5822 if (gdk_window_has_impl (window))
5824 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5825 impl_class->set_events (window,
5826 get_native_event_mask (window));
5832 * gdk_window_get_events:
5833 * @window: a #GdkWindow
5835 * Gets the event mask for @window for all master input devices. See
5836 * gdk_window_set_events().
5838 * Return value: event mask for @window
5841 gdk_window_get_events (GdkWindow *window)
5843 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5845 if (window->destroyed)
5848 return window->event_mask;
5852 * gdk_window_set_device_events:
5853 * @window: a #GdkWindow
5854 * @device: #GdkDevice to enable events for.
5855 * @event_mask: event mask for @window
5857 * Sets the event mask for a given device (Normally a floating device, not
5858 * attached to any visible pointer) to @window. For example, an event mask
5859 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5860 * press events. The event mask is the bitwise OR of values from the
5861 * #GdkEventMask enumeration.
5866 gdk_window_set_device_events (GdkWindow *window,
5868 GdkEventMask event_mask)
5870 GdkEventMask device_mask;
5871 GdkDisplay *display;
5874 g_return_if_fail (GDK_IS_WINDOW (window));
5875 g_return_if_fail (GDK_IS_DEVICE (device));
5877 if (GDK_WINDOW_DESTROYED (window))
5880 /* If motion hint is disabled, enable motion events again */
5881 display = gdk_window_get_display (window);
5882 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5883 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5884 _gdk_display_enable_motion_hints (display, device);
5886 if (G_UNLIKELY (!window->device_events))
5887 window->device_events = g_hash_table_new (NULL, NULL);
5889 if (event_mask == 0)
5891 /* FIXME: unsetting events on a master device
5892 * would restore window->event_mask
5894 g_hash_table_remove (window->device_events, device);
5897 g_hash_table_insert (window->device_events, device,
5898 GINT_TO_POINTER (event_mask));
5900 if (_gdk_native_windows)
5903 native = gdk_window_get_toplevel (window);
5905 while (gdk_window_is_offscreen (native))
5907 native = gdk_offscreen_window_get_embedder (native);
5909 if (native == NULL ||
5910 (!_gdk_window_has_impl (native) &&
5911 !gdk_window_is_viewable (native)))
5914 native = gdk_window_get_toplevel (native);
5917 device_mask = get_native_device_event_mask (window, device);
5918 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5922 * gdk_window_get_device_events:
5923 * @window: a #GdkWindow.
5924 * @device: a #GdkDevice.
5926 * Returns the event mask for @window corresponding to an specific device.
5928 * Returns: device event mask for @window
5933 gdk_window_get_device_events (GdkWindow *window,
5938 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5939 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5941 if (GDK_WINDOW_DESTROYED (window))
5944 if (!window->device_events)
5947 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5949 /* FIXME: device could be controlled by window->event_mask */
5955 gdk_window_move_resize_toplevel (GdkWindow *window,
5962 cairo_region_t *old_region, *new_region;
5963 GdkWindowImplClass *impl_class;
5965 int old_x, old_y, old_abs_x, old_abs_y;
5975 is_resize = (width != -1) || (height != -1);
5977 if (gdk_window_is_viewable (window) &&
5978 !window->input_only)
5981 old_region = cairo_region_copy (window->clip_region);
5984 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5985 impl_class->move_resize (window, with_move, x, y, width, height);
5987 dx = window->x - old_x;
5988 dy = window->y - old_y;
5990 old_abs_x = window->abs_x;
5991 old_abs_y = window->abs_y;
5993 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5995 recompute_visible_regions (window, TRUE, FALSE);
5999 new_region = cairo_region_copy (window->clip_region);
6001 /* This is the newly exposed area (due to any resize),
6002 * X will expose it, but lets do that without the
6005 cairo_region_subtract (new_region, old_region);
6006 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
6008 cairo_region_destroy (old_region);
6009 cairo_region_destroy (new_region);
6012 _gdk_synthesize_crossing_events_for_geometry_change (window);
6017 move_native_children (GdkWindow *private)
6021 GdkWindowImplClass *impl_class;
6023 for (l = private->children; l; l = l->next)
6027 if (child->impl != private->impl)
6029 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
6030 impl_class->move_resize (child, TRUE,
6032 child->width, child->height);
6035 move_native_children (child);
6040 collect_native_child_region_helper (GdkWindow *window,
6041 GdkWindowImpl *impl,
6042 cairo_region_t **region,
6047 cairo_region_t *tmp;
6050 for (l = window->children; l != NULL; l = l->next)
6054 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
6057 if (child->impl != impl)
6059 tmp = cairo_region_copy (child->clip_region);
6060 cairo_region_translate (tmp,
6061 x_offset + child->x,
6062 y_offset + child->y);
6063 if (*region == NULL)
6067 cairo_region_union (*region, tmp);
6068 cairo_region_destroy (tmp);
6072 collect_native_child_region_helper (child, impl, region,
6073 x_offset + child->x,
6074 y_offset + child->y);
6080 static cairo_region_t *
6081 collect_native_child_region (GdkWindow *window,
6082 gboolean include_this)
6084 cairo_region_t *region;
6086 if (include_this && gdk_window_has_impl (window) && window->viewable)
6087 return cairo_region_copy (window->clip_region);
6091 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6098 gdk_window_move_resize_internal (GdkWindow *window,
6105 cairo_region_t *old_region, *new_region, *copy_area;
6106 cairo_region_t *old_native_child_region, *new_native_child_region;
6107 GdkWindow *impl_window;
6108 GdkWindowImplClass *impl_class;
6110 int old_x, old_y, old_abs_x, old_abs_y;
6113 g_return_if_fail (GDK_IS_WINDOW (window));
6115 if (window->destroyed)
6118 if (gdk_window_is_toplevel (window))
6120 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6124 /* Bail early if no change */
6125 if (window->width == width &&
6126 window->height == height &&
6132 gdk_window_flush_if_exposing (window);
6134 /* Handle child windows */
6139 impl_window = gdk_window_get_impl_window (window);
6144 old_native_child_region = NULL;
6145 if (gdk_window_is_viewable (window) &&
6146 !window->input_only)
6150 old_region = cairo_region_copy (window->clip_region);
6151 /* Adjust region to parent window coords */
6152 cairo_region_translate (old_region, window->x, window->y);
6154 old_native_child_region = collect_native_child_region (window, TRUE);
6155 if (old_native_child_region)
6157 /* Adjust region to parent window coords */
6158 cairo_region_translate (old_native_child_region, window->x, window->y);
6160 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6161 * source or destination for a delayed GdkWindowRegionMove. So, we need
6162 * to flush those here for the parent window and all overlapped subwindows
6163 * of it. And we need to do this before setting the new clips as those will be
6166 gdk_window_flush_recursive (window->parent);
6170 /* Set the new position and size */
6176 if (!(width < 0 && height < 0))
6180 window->width = width;
6183 window->height = height;
6186 dx = window->x - old_x;
6187 dy = window->y - old_y;
6189 old_abs_x = window->abs_x;
6190 old_abs_y = window->abs_y;
6192 recompute_visible_regions (window, TRUE, FALSE);
6194 new_native_child_region = NULL;
6195 if (old_native_child_region)
6197 new_native_child_region = collect_native_child_region (window, TRUE);
6198 /* Adjust region to parent window coords */
6199 cairo_region_translate (new_native_child_region, window->x, window->y);
6202 if (gdk_window_has_impl (window))
6204 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6206 /* Do the actual move after recomputing things, as this will have set the shape to
6207 the now correct one, thus avoiding copying regions that should not be copied. */
6208 impl_class->move_resize (window, TRUE,
6209 window->x, window->y,
6210 window->width, window->height);
6212 else if (old_abs_x != window->abs_x ||
6213 old_abs_y != window->abs_y)
6214 move_native_children (window);
6218 new_region = cairo_region_copy (window->clip_region);
6219 /* Adjust region to parent window coords */
6220 cairo_region_translate (new_region, window->x, window->y);
6223 * Part of the data at the new location can be copied from the
6224 * old location, this area is the intersection of the old region
6225 * moved as the copy will move it and then intersected with
6229 * Everything in the old and new regions that is not copied must be
6230 * invalidated (including children) as this is newly exposed
6232 copy_area = cairo_region_copy (new_region);
6234 cairo_region_union (new_region, old_region);
6236 if (old_native_child_region)
6238 /* Don't copy from inside native children, as this is copied by
6239 * the native window move.
6241 cairo_region_subtract (old_region, old_native_child_region);
6243 cairo_region_translate (old_region, dx, dy);
6245 cairo_region_intersect (copy_area, old_region);
6247 if (new_native_child_region)
6249 /* Don't copy any bits that would cause a read from the moved
6250 native windows, as we can't read that data */
6251 cairo_region_translate (new_native_child_region, dx, dy);
6252 cairo_region_subtract (copy_area, new_native_child_region);
6253 cairo_region_translate (new_native_child_region, -dx, -dy);
6256 cairo_region_subtract (new_region, copy_area);
6258 /* Convert old region to impl coords */
6259 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6261 /* convert from parent coords to impl */
6262 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6264 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6266 /* Invalidate affected part in the parent window
6267 * (no higher window should be affected)
6268 * We also invalidate any children in that area, which could include
6269 * this window if it still overlaps that area.
6271 if (old_native_child_region)
6273 /* No need to expose the region that the native window move copies */
6274 cairo_region_translate (old_native_child_region, dx, dy);
6275 cairo_region_intersect (old_native_child_region, new_native_child_region);
6276 cairo_region_subtract (new_region, old_native_child_region);
6278 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6280 cairo_region_destroy (old_region);
6281 cairo_region_destroy (new_region);
6284 if (old_native_child_region)
6286 cairo_region_destroy (old_native_child_region);
6287 cairo_region_destroy (new_native_child_region);
6290 _gdk_synthesize_crossing_events_for_geometry_change (window);
6297 * @window: a #GdkWindow
6298 * @x: X coordinate relative to window's parent
6299 * @y: Y coordinate relative to window's parent
6301 * Repositions a window relative to its parent window.
6302 * For toplevel windows, window managers may ignore or modify the move;
6303 * you should probably use gtk_window_move() on a #GtkWindow widget
6304 * anyway, instead of using GDK functions. For child windows,
6305 * the move will reliably succeed.
6307 * If you're also planning to resize the window, use gdk_window_move_resize()
6308 * to both move and resize simultaneously, for a nicer visual effect.
6311 gdk_window_move (GdkWindow *window,
6315 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6319 * gdk_window_resize:
6320 * @window: a #GdkWindow
6321 * @width: new width of the window
6322 * @height: new height of the window
6324 * Resizes @window; for toplevel windows, asks the window manager to resize
6325 * the window. The window manager may not allow the resize. When using GTK+,
6326 * use gtk_window_resize() instead of this low-level GDK function.
6328 * Windows may not be resized below 1x1.
6330 * If you're also planning to move the window, use gdk_window_move_resize()
6331 * to both move and resize simultaneously, for a nicer visual effect.
6334 gdk_window_resize (GdkWindow *window,
6338 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6343 * gdk_window_move_resize:
6344 * @window: a #GdkWindow
6345 * @x: new X position relative to window's parent
6346 * @y: new Y position relative to window's parent
6348 * @height: new height
6350 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6351 * except that both operations are performed at once, avoiding strange
6352 * visual effects. (i.e. the user may be able to see the window first
6353 * move, then resize, if you don't use gdk_window_move_resize().)
6356 gdk_window_move_resize (GdkWindow *window,
6362 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6367 * gdk_window_scroll:
6368 * @window: a #GdkWindow
6369 * @dx: Amount to scroll in the X direction
6370 * @dy: Amount to scroll in the Y direction
6372 * Scroll the contents of @window, both pixels and children, by the
6373 * given amount. @window itself does not move. Portions of the window
6374 * that the scroll operation brings in from offscreen areas are
6375 * invalidated. The invalidated region may be bigger than what would
6376 * strictly be necessary.
6378 * For X11, a minimum area will be invalidated if the window has no
6379 * subwindows, or if the edges of the window's parent do not extend
6380 * beyond the edges of the window. In other cases, a multi-step process
6381 * is used to scroll the window which may produce temporary visual
6382 * artifacts and unnecessary invalidations.
6385 gdk_window_scroll (GdkWindow *window,
6389 GdkWindow *impl_window;
6390 cairo_region_t *copy_area, *noncopy_area;
6391 cairo_region_t *old_native_child_region, *new_native_child_region;
6394 g_return_if_fail (GDK_IS_WINDOW (window));
6396 if (dx == 0 && dy == 0)
6399 if (window->destroyed)
6402 gdk_window_flush_if_exposing (window);
6404 old_native_child_region = collect_native_child_region (window, FALSE);
6405 if (old_native_child_region)
6407 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6408 * source or destination for a delayed GdkWindowRegionMove. So, we need
6409 * to flush those here for the window and all overlapped subwindows
6410 * of it. And we need to do this before setting the new clips as those will be
6413 gdk_window_flush_recursive (window);
6417 /* First move all child windows, without causing invalidation */
6419 tmp_list = window->children;
6422 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6424 /* Just update the positions, the bits will move with the copy */
6428 tmp_list = tmp_list->next;
6431 recompute_visible_regions (window, FALSE, TRUE);
6433 new_native_child_region = NULL;
6434 if (old_native_child_region)
6435 new_native_child_region = collect_native_child_region (window, FALSE);
6437 move_native_children (window);
6439 /* Then copy the actual bits of the window w/ child windows */
6441 impl_window = gdk_window_get_impl_window (window);
6443 /* Calculate the area that can be gotten by copying the old area */
6444 copy_area = cairo_region_copy (window->clip_region);
6445 if (old_native_child_region)
6447 /* Don't copy from inside native children, as this is copied by
6448 * the native window move.
6450 cairo_region_subtract (copy_area, old_native_child_region);
6452 /* Don't copy any bits that would cause a read from the moved
6453 native windows, as we can't read that data */
6454 cairo_region_subtract (copy_area, new_native_child_region);
6456 cairo_region_translate (copy_area, dx, dy);
6457 cairo_region_intersect (copy_area, window->clip_region);
6459 /* And the rest need to be invalidated */
6460 noncopy_area = cairo_region_copy (window->clip_region);
6461 cairo_region_subtract (noncopy_area, copy_area);
6463 /* convert from window coords to impl */
6464 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6466 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6468 /* Invalidate not copied regions */
6469 if (old_native_child_region)
6471 /* No need to expose the region that the native window move copies */
6472 cairo_region_translate (old_native_child_region, dx, dy);
6473 cairo_region_intersect (old_native_child_region, new_native_child_region);
6474 cairo_region_subtract (noncopy_area, old_native_child_region);
6476 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6478 cairo_region_destroy (noncopy_area);
6480 if (old_native_child_region)
6482 cairo_region_destroy (old_native_child_region);
6483 cairo_region_destroy (new_native_child_region);
6486 _gdk_synthesize_crossing_events_for_geometry_change (window);
6490 * gdk_window_move_region:
6491 * @window: a #GdkWindow
6492 * @region: The #cairo_region_t to move
6493 * @dx: Amount to move in the X direction
6494 * @dy: Amount to move in the Y direction
6496 * Move the part of @window indicated by @region by @dy pixels in the Y
6497 * direction and @dx pixels in the X direction. The portions of @region
6498 * that not covered by the new position of @region are invalidated.
6500 * Child windows are not moved.
6505 gdk_window_move_region (GdkWindow *window,
6506 const cairo_region_t *region,
6510 GdkWindow *impl_window;
6511 cairo_region_t *nocopy_area;
6512 cairo_region_t *copy_area;
6514 g_return_if_fail (GDK_IS_WINDOW (window));
6515 g_return_if_fail (region != NULL);
6517 if (dx == 0 && dy == 0)
6520 if (window->destroyed)
6523 impl_window = gdk_window_get_impl_window (window);
6525 /* compute source regions */
6526 copy_area = cairo_region_copy (region);
6527 cairo_region_intersect (copy_area, window->clip_region_with_children);
6529 /* compute destination regions */
6530 cairo_region_translate (copy_area, dx, dy);
6531 cairo_region_intersect (copy_area, window->clip_region_with_children);
6533 /* Invalidate parts of the region (source and dest) not covered
6535 nocopy_area = cairo_region_copy (region);
6536 cairo_region_translate (nocopy_area, dx, dy);
6537 cairo_region_union (nocopy_area, region);
6538 cairo_region_subtract (nocopy_area, copy_area);
6540 /* convert from window coords to impl */
6541 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6542 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6544 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6545 cairo_region_destroy (nocopy_area);
6549 * gdk_window_set_background:
6550 * @window: a #GdkWindow
6551 * @color: a #GdkColor
6553 * Sets the background color of @window. (However, when using GTK+,
6554 * set the background of a widget with gtk_widget_modify_bg() - if
6555 * you're an application - or gtk_style_set_background() - if you're
6556 * implementing a custom widget.)
6558 * See also gdk_window_set_background_pattern().
6561 gdk_window_set_background (GdkWindow *window,
6562 const GdkColor *color)
6564 cairo_pattern_t *pattern;
6566 g_return_if_fail (GDK_IS_WINDOW (window));
6568 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6569 color->green / 65535.,
6570 color->blue / 65535.);
6572 gdk_window_set_background_pattern (window, pattern);
6574 cairo_pattern_destroy (pattern);
6578 * gdk_window_set_background_rgba:
6579 * @window: a #GdkWindow
6580 * @rgba: a #GdkRGBA color
6582 * Sets the background color of @window.
6584 * See also gdk_window_set_background_pattern().
6587 gdk_window_set_background_rgba (GdkWindow *window,
6590 cairo_pattern_t *pattern;
6592 g_return_if_fail (GDK_IS_WINDOW (window));
6593 g_return_if_fail (rgba != NULL);
6595 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6596 rgba->blue, rgba->alpha);
6598 gdk_window_set_background_pattern (window, pattern);
6600 cairo_pattern_destroy (pattern);
6604 * gdk_window_set_background_pattern:
6605 * @window: a #GdkWindow
6606 * @pattern: (allow-none): a pattern to use, or %NULL
6608 * Sets the background of @window.
6610 * A background of %NULL means that the window will inherit its
6611 * background form its parent window.
6613 * The windowing system will normally fill a window with its background
6614 * when the window is obscured then exposed.
6617 gdk_window_set_background_pattern (GdkWindow *window,
6618 cairo_pattern_t *pattern)
6620 g_return_if_fail (GDK_IS_WINDOW (window));
6623 cairo_pattern_reference (pattern);
6624 if (window->background)
6625 cairo_pattern_destroy (window->background);
6626 window->background = pattern;
6628 if (gdk_window_has_impl (window) &&
6629 !window->input_only)
6631 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6632 impl_class->set_background (window, pattern);
6637 * gdk_window_get_background_pattern:
6640 * Gets the pattern used to clear the background on @window. If @window
6641 * does not have its own background and reuses the parent's, %NULL is
6642 * returned and you'll have to query it yourself.
6644 * Returns: The pattern to use for the background or %NULL to use the
6645 * parent's background.
6650 gdk_window_get_background_pattern (GdkWindow *window)
6652 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6654 return window->background;
6658 update_cursor_foreach (GdkDisplay *display,
6660 GdkPointerWindowInfo *pointer_info,
6663 GdkWindow *window = user_data;
6665 if (_gdk_native_windows ||
6666 window->window_type == GDK_WINDOW_ROOT ||
6667 window->window_type == GDK_WINDOW_FOREIGN)
6668 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, window->cursor);
6669 else if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6670 update_cursor (display, device);
6674 * gdk_window_get_cursor:
6675 * @window: a #GdkWindow
6677 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6678 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6679 * there is no custom cursor set on the specified window, and it is
6680 * using the cursor for its parent window.
6682 * Return value: a #GdkCursor, or %NULL. The returned object is owned
6683 * by the #GdkWindow and should not be unreferenced directly. Use
6684 * gdk_window_set_cursor() to unset the cursor of the window
6689 gdk_window_get_cursor (GdkWindow *window)
6691 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6693 return window->cursor;
6697 * gdk_window_set_cursor:
6698 * @window: a #GdkWindow
6699 * @cursor: (allow-none): a cursor
6701 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6702 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6703 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6704 * to gdk_window_set_cursor() means that @window will use the cursor of its
6705 * parent window. Most windows should use this default.
6708 gdk_window_set_cursor (GdkWindow *window,
6711 GdkDisplay *display;
6713 g_return_if_fail (GDK_IS_WINDOW (window));
6715 display = gdk_window_get_display (window);
6719 gdk_cursor_unref (window->cursor);
6720 window->cursor = NULL;
6723 if (!GDK_WINDOW_DESTROYED (window))
6726 window->cursor = gdk_cursor_ref (cursor);
6728 _gdk_display_pointer_info_foreach (display,
6729 update_cursor_foreach,
6732 g_object_notify (G_OBJECT (window), "cursor");
6737 * gdk_window_get_device_cursor:
6738 * @window: a #GdkWindow.
6739 * @device: a #GdkDevice.
6741 * Retrieves a #GdkCursor pointer for the @device currently set on the
6742 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6743 * there is no custom cursor set on the specified window, and it is
6744 * using the cursor for its parent window.
6746 * Returns: a #GdkCursor, or %NULL. The returned object is owned
6747 * by the #GdkWindow and should not be unreferenced directly. Use
6748 * gdk_window_set_cursor() to unset the cursor of the window
6753 gdk_window_get_device_cursor (GdkWindow *window,
6756 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6757 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6759 return g_hash_table_lookup (window->device_cursor, device);
6763 * gdk_window_set_device_cursor:
6764 * @window: a #Gdkwindow
6765 * @device: a #GdkDevice
6766 * @cursor: a #GdkCursor
6768 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6769 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6770 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6771 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6772 * @window will use the cursor of its parent window. Most windows should
6778 gdk_window_set_device_cursor (GdkWindow *window,
6782 GdkDisplay *display;
6784 g_return_if_fail (GDK_IS_WINDOW (window));
6785 g_return_if_fail (GDK_IS_DEVICE (device));
6787 display = gdk_window_get_display (window);
6790 g_hash_table_remove (window->device_cursor, device);
6792 g_hash_table_replace (window->device_cursor, device, gdk_cursor_ref (cursor));
6794 if (!GDK_WINDOW_DESTROYED (window))
6796 GdkPointerWindowInfo *pointer_info;
6798 pointer_info = _gdk_display_get_pointer_info (display, device);
6800 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6801 update_cursor (display, device);
6806 * gdk_window_get_geometry:
6807 * @window: a #GdkWindow
6808 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6809 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6810 * @width: (out) (allow-none): return location for width of window
6811 * @height: (out) (allow-none): return location for height of window
6813 * Any of the return location arguments to this function may be %NULL,
6814 * if you aren't interested in getting the value of that field.
6816 * The X and Y coordinates returned are relative to the parent window
6817 * of @window, which for toplevels usually means relative to the
6818 * window decorations (titlebar, etc.) rather than relative to the
6819 * root window (screen-size background window).
6821 * On the X11 platform, the geometry is obtained from the X server,
6822 * so reflects the latest position of @window; this may be out-of-sync
6823 * with the position of @window delivered in the most-recently-processed
6824 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6825 * position from the most recent configure event.
6828 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6829 * to call gdk_window_get_position(), gdk_window_get_width() and
6830 * gdk_window_get_height() instead, because it avoids the roundtrip to
6831 * the X server and because these functions support the full 32-bit
6832 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6833 * the 16-bit coordinates of X11.
6837 gdk_window_get_geometry (GdkWindow *window,
6844 GdkWindowImplClass *impl_class;
6848 GDK_NOTE (MULTIHEAD,
6849 g_message ("gdk_window_get_geometry(): Window needs "
6850 "to be non-NULL to be multi head safe"));
6851 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6854 g_return_if_fail (GDK_IS_WINDOW (window));
6856 if (!GDK_WINDOW_DESTROYED (window))
6858 if (gdk_window_has_impl (window))
6860 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6861 impl_class->get_geometry (window, x, y,
6863 /* This reports the position wrt to the native parent, we need to convert
6864 it to be relative to the client side parent */
6865 parent = window->parent;
6866 if (parent && !gdk_window_has_impl (parent))
6869 *x -= parent->abs_x;
6871 *y -= parent->abs_y;
6881 *width = window->width;
6883 *height = window->height;
6889 * gdk_window_get_width:
6890 * @window: a #GdkWindow
6892 * Returns the width of the given @window.
6894 * On the X11 platform the returned size is the size reported in the
6895 * most-recently-processed configure event, rather than the current
6896 * size on the X server.
6898 * Returns: The width of @window
6903 gdk_window_get_width (GdkWindow *window)
6905 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6907 return window->width;
6911 * gdk_window_get_height:
6912 * @window: a #GdkWindow
6914 * Returns the height of the given @window.
6916 * On the X11 platform the returned size is the size reported in the
6917 * most-recently-processed configure event, rather than the current
6918 * size on the X server.
6920 * Returns: The height of @window
6925 gdk_window_get_height (GdkWindow *window)
6927 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6929 return window->height;
6933 * gdk_window_get_origin:
6934 * @window: a #GdkWindow
6935 * @x: (out) (allow-none): return location for X coordinate
6936 * @y: (out) (allow-none): return location for Y coordinate
6938 * Obtains the position of a window in root window coordinates.
6939 * (Compare with gdk_window_get_position() and
6940 * gdk_window_get_geometry() which return the position of a window
6941 * relative to its parent window.)
6943 * Return value: not meaningful, ignore
6946 gdk_window_get_origin (GdkWindow *window,
6950 GdkWindowImplClass *impl_class;
6952 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6954 if (GDK_WINDOW_DESTROYED (window))
6963 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6964 impl_class->get_root_coords (window,
6973 * gdk_window_get_root_coords:
6974 * @window: a #GdkWindow
6975 * @x: X coordinate in window
6976 * @y: Y coordinate in window
6977 * @root_x: return location for X coordinate
6978 * @root_y: return location for Y coordinate
6980 * Obtains the position of a window position in root
6981 * window coordinates. This is similar to
6982 * gdk_window_get_origin() but allows you go pass
6983 * in any position in the window, not just the origin.
6988 gdk_window_get_root_coords (GdkWindow *window,
6994 GdkWindowImplClass *impl_class;
6996 g_return_if_fail (GDK_IS_WINDOW (window));
6998 if (GDK_WINDOW_DESTROYED (window))
7007 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7008 impl_class->get_root_coords (window,
7015 * gdk_window_coords_to_parent:
7016 * @window: a child window
7017 * @x: X coordinate in child's coordinate system
7018 * @y: Y coordinate in child's coordinate system
7019 * @parent_x: (out) (allow-none): return location for X coordinate
7020 * in parent's coordinate system, or %NULL
7021 * @parent_y: (out) (allow-none): return location for Y coordinate
7022 * in parent's coordinate system, or %NULL
7024 * Transforms window coordinates from a child window to its parent
7025 * window, where the parent window is the normal parent as returned by
7026 * gdk_window_get_parent() for normal windows, and the window's
7027 * embedder as returned by gdk_offscreen_window_get_embedder() for
7028 * offscreen windows.
7030 * For normal windows, calling this function is equivalent to adding
7031 * the return values of gdk_window_get_position() to the child coordinates.
7032 * For offscreen windows however (which can be arbitrarily transformed),
7033 * this function calls the GdkWindow::to-embedder: signal to translate
7036 * You should always use this function when writing generic code that
7037 * walks up a window hierarchy.
7039 * See also: gdk_window_coords_from_parent()
7044 gdk_window_coords_to_parent (GdkWindow *window,
7050 g_return_if_fail (GDK_IS_WINDOW (window));
7052 if (gdk_window_is_offscreen (window))
7056 to_embedder (window, x, y, &px, &py);
7067 *parent_x = x + window->x;
7070 *parent_y = y + window->y;
7075 * gdk_window_coords_from_parent:
7076 * @window: a child window
7077 * @parent_x: X coordinate in parent's coordinate system
7078 * @parent_y: Y coordinate in parent's coordinate system
7079 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7080 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7082 * Transforms window coordinates from a parent window to a child
7083 * window, where the parent window is the normal parent as returned by
7084 * gdk_window_get_parent() for normal windows, and the window's
7085 * embedder as returned by gdk_offscreen_window_get_embedder() for
7086 * offscreen windows.
7088 * For normal windows, calling this function is equivalent to subtracting
7089 * the return values of gdk_window_get_position() from the parent coordinates.
7090 * For offscreen windows however (which can be arbitrarily transformed),
7091 * this function calls the GdkWindow::from-embedder: signal to translate
7094 * You should always use this function when writing generic code that
7095 * walks down a window hierarchy.
7097 * See also: gdk_window_coords_to_parent()
7102 gdk_window_coords_from_parent (GdkWindow *window,
7108 g_return_if_fail (GDK_IS_WINDOW (window));
7110 if (gdk_window_is_offscreen (window))
7114 from_embedder (window, parent_x, parent_y, &cx, &cy);
7125 *x = parent_x - window->x;
7128 *y = parent_y - window->y;
7133 * gdk_window_shape_combine_region:
7134 * @window: a #GdkWindow
7135 * @shape_region: region of window to be non-transparent
7136 * @offset_x: X position of @shape_region in @window coordinates
7137 * @offset_y: Y position of @shape_region in @window coordinates
7139 * Makes pixels in @window outside @shape_region be transparent,
7140 * so that the window may be nonrectangular.
7142 * If @shape_region is %NULL, the shape will be unset, so the whole
7143 * window will be opaque again. @offset_x and @offset_y are ignored
7144 * if @shape_region is %NULL.
7146 * On the X11 platform, this uses an X server extension which is
7147 * widely available on most common platforms, but not available on
7148 * very old X servers, and occasionally the implementation will be
7149 * buggy. On servers without the shape extension, this function
7152 * This function works on both toplevel and child windows.
7155 gdk_window_shape_combine_region (GdkWindow *window,
7156 const cairo_region_t *shape_region,
7160 cairo_region_t *old_region, *new_region, *diff;
7162 g_return_if_fail (GDK_IS_WINDOW (window));
7164 if (GDK_WINDOW_DESTROYED (window))
7167 window->shaped = (shape_region != NULL);
7170 cairo_region_destroy (window->shape);
7173 if (GDK_WINDOW_IS_MAPPED (window))
7174 old_region = cairo_region_copy (window->clip_region);
7178 window->shape = cairo_region_copy (shape_region);
7179 cairo_region_translate (window->shape, offset_x, offset_y);
7182 window->shape = NULL;
7184 recompute_visible_regions (window, TRUE, FALSE);
7186 if (gdk_window_has_impl (window) &&
7187 !should_apply_clip_as_shape (window))
7188 apply_shape (window, window->shape);
7192 new_region = cairo_region_copy (window->clip_region);
7194 /* New area in the window, needs invalidation */
7195 diff = cairo_region_copy (new_region);
7196 cairo_region_subtract (diff, old_region);
7198 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7200 cairo_region_destroy (diff);
7202 if (!gdk_window_is_toplevel (window))
7204 /* New area in the non-root parent window, needs invalidation */
7205 diff = cairo_region_copy (old_region);
7206 cairo_region_subtract (diff, new_region);
7208 /* Adjust region to parent window coords */
7209 cairo_region_translate (diff, window->x, window->y);
7211 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7213 cairo_region_destroy (diff);
7216 cairo_region_destroy (new_region);
7217 cairo_region_destroy (old_region);
7222 do_child_shapes (GdkWindow *window,
7226 cairo_region_t *region;
7230 r.width = window->width;
7231 r.height = window->height;
7233 region = cairo_region_create_rectangle (&r);
7234 remove_child_area (window, NULL, FALSE, region);
7236 if (merge && window->shape)
7237 cairo_region_subtract (region, window->shape);
7239 gdk_window_shape_combine_region (window, region, 0, 0);
7243 * gdk_window_set_child_shapes:
7244 * @window: a #GdkWindow
7246 * Sets the shape mask of @window to the union of shape masks
7247 * for all children of @window, ignoring the shape mask of @window
7248 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7249 * the shape mask of @window in the masks to be merged.
7252 gdk_window_set_child_shapes (GdkWindow *window)
7254 g_return_if_fail (GDK_IS_WINDOW (window));
7256 do_child_shapes (window, FALSE);
7260 * gdk_window_merge_child_shapes:
7261 * @window: a #GdkWindow
7263 * Merges the shape masks for any child windows into the
7264 * shape mask for @window. i.e. the union of all masks
7265 * for @window and its children will become the new mask
7266 * for @window. See gdk_window_shape_combine_region().
7268 * This function is distinct from gdk_window_set_child_shapes()
7269 * because it includes @window's shape mask in the set of shapes to
7273 gdk_window_merge_child_shapes (GdkWindow *window)
7275 g_return_if_fail (GDK_IS_WINDOW (window));
7277 do_child_shapes (window, TRUE);
7281 * gdk_window_input_shape_combine_region:
7282 * @window: a #GdkWindow
7283 * @shape_region: region of window to be non-transparent
7284 * @offset_x: X position of @shape_region in @window coordinates
7285 * @offset_y: Y position of @shape_region in @window coordinates
7287 * Like gdk_window_shape_combine_region(), but the shape applies
7288 * only to event handling. Mouse events which happen while
7289 * the pointer position corresponds to an unset bit in the
7290 * mask will be passed on the window below @window.
7292 * An input shape is typically used with RGBA windows.
7293 * The alpha channel of the window defines which pixels are
7294 * invisible and allows for nicely antialiased borders,
7295 * and the input shape controls where the window is
7298 * On the X11 platform, this requires version 1.1 of the
7301 * On the Win32 platform, this functionality is not present and the
7302 * function does nothing.
7307 gdk_window_input_shape_combine_region (GdkWindow *window,
7308 const cairo_region_t *shape_region,
7312 GdkWindowImplClass *impl_class;
7314 g_return_if_fail (GDK_IS_WINDOW (window));
7316 if (GDK_WINDOW_DESTROYED (window))
7319 if (window->input_shape)
7320 cairo_region_destroy (window->input_shape);
7324 window->input_shape = cairo_region_copy (shape_region);
7325 cairo_region_translate (window->input_shape, offset_x, offset_y);
7328 window->input_shape = NULL;
7330 if (gdk_window_has_impl (window))
7332 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7333 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7336 /* Pointer may have e.g. moved outside window due to the input mask change */
7337 _gdk_synthesize_crossing_events_for_geometry_change (window);
7341 do_child_input_shapes (GdkWindow *window,
7345 cairo_region_t *region;
7349 r.width = window->width;
7350 r.height = window->height;
7352 region = cairo_region_create_rectangle (&r);
7353 remove_child_area (window, NULL, TRUE, region);
7355 if (merge && window->shape)
7356 cairo_region_subtract (region, window->shape);
7357 if (merge && window->input_shape)
7358 cairo_region_subtract (region, window->input_shape);
7360 gdk_window_input_shape_combine_region (window, region, 0, 0);
7365 * gdk_window_set_child_input_shapes:
7366 * @window: a #GdkWindow
7368 * Sets the input shape mask of @window to the union of input shape masks
7369 * for all children of @window, ignoring the input shape mask of @window
7370 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7371 * the input shape mask of @window in the masks to be merged.
7376 gdk_window_set_child_input_shapes (GdkWindow *window)
7378 g_return_if_fail (GDK_IS_WINDOW (window));
7380 do_child_input_shapes (window, FALSE);
7384 * gdk_window_merge_child_input_shapes:
7385 * @window: a #GdkWindow
7387 * Merges the input shape masks for any child windows into the
7388 * input shape mask for @window. i.e. the union of all input masks
7389 * for @window and its children will become the new input mask
7390 * for @window. See gdk_window_input_shape_combine_region().
7392 * This function is distinct from gdk_window_set_child_input_shapes()
7393 * because it includes @window's input shape mask in the set of
7394 * shapes to be merged.
7399 gdk_window_merge_child_input_shapes (GdkWindow *window)
7401 g_return_if_fail (GDK_IS_WINDOW (window));
7403 do_child_input_shapes (window, TRUE);
7408 * gdk_window_set_static_gravities:
7409 * @window: a #GdkWindow
7410 * @use_static: %TRUE to turn on static gravity
7412 * Set the bit gravity of the given window to static, and flag it so
7413 * all children get static subwindow gravity. This is used if you are
7414 * implementing scary features that involve deep knowledge of the
7415 * windowing system. Don't worry about it unless you have to.
7417 * Return value: %TRUE if the server supports static gravity
7420 gdk_window_set_static_gravities (GdkWindow *window,
7421 gboolean use_static)
7423 GdkWindowImplClass *impl_class;
7425 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7427 if (gdk_window_has_impl (window))
7429 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7430 return impl_class->set_static_gravities (window, use_static);
7437 * gdk_window_get_composited:
7438 * @window: a #GdkWindow
7440 * Determines whether @window is composited.
7442 * See gdk_window_set_composited().
7444 * Returns: %TRUE if the window is composited.
7449 gdk_window_get_composited (GdkWindow *window)
7451 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7453 return window->composited;
7457 * gdk_window_set_composited:
7458 * @window: a #GdkWindow
7459 * @composited: %TRUE to set the window as composited
7461 * Sets a #GdkWindow as composited, or unsets it. Composited
7462 * windows do not automatically have their contents drawn to
7463 * the screen. Drawing is redirected to an offscreen buffer
7464 * and an expose event is emitted on the parent of the composited
7465 * window. It is the responsibility of the parent's expose handler
7466 * to manually merge the off-screen content onto the screen in
7467 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7470 * It only makes sense for child windows to be composited; see
7471 * gdk_window_set_opacity() if you need translucent toplevel
7474 * An additional effect of this call is that the area of this
7475 * window is no longer clipped from regions marked for
7476 * invalidation on its parent. Draws done on the parent
7477 * window are also no longer clipped by the child.
7479 * This call is only supported on some systems (currently,
7480 * only X11 with new enough Xcomposite and Xdamage extensions).
7481 * You must call gdk_display_supports_composite() to check if
7482 * setting a window as composited is supported before
7483 * attempting to do so.
7488 gdk_window_set_composited (GdkWindow *window,
7489 gboolean composited)
7491 GdkDisplay *display;
7493 g_return_if_fail (GDK_IS_WINDOW (window));
7495 composited = composited != FALSE;
7497 if (window->composited == composited)
7501 gdk_window_ensure_native (window);
7503 display = gdk_window_get_display (window);
7505 if (!gdk_display_supports_composite (display) && composited)
7507 g_warning ("gdk_window_set_composited called but "
7508 "compositing is not supported");
7512 _gdk_windowing_window_set_composited (window, composited);
7514 recompute_visible_regions (window, TRUE, FALSE);
7516 if (GDK_WINDOW_IS_MAPPED (window))
7517 gdk_window_invalidate_in_parent (window);
7519 window->composited = composited;
7523 * gdk_window_get_modal_hint:
7524 * @window: A toplevel #GdkWindow.
7526 * Determines whether or not the window manager is hinted that @window
7527 * has modal behaviour.
7529 * Return value: whether or not the window has the modal hint set.
7534 gdk_window_get_modal_hint (GdkWindow *window)
7536 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7538 return window->modal_hint;
7542 * gdk_window_get_accept_focus:
7543 * @window: a toplevel #GdkWindow.
7545 * Determines whether or not the desktop environment shuld be hinted that
7546 * the window does not want to receive input focus.
7548 * Return value: whether or not the window should receive input focus.
7553 gdk_window_get_accept_focus (GdkWindow *window)
7555 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7557 return window->accept_focus;
7561 * gdk_window_get_focus_on_map:
7562 * @window: a toplevel #GdkWindow.
7564 * Determines whether or not the desktop environment should be hinted that the
7565 * window does not want to receive input focus when it is mapped.
7567 * Return value: whether or not the window wants to receive input focus when
7573 gdk_window_get_focus_on_map (GdkWindow *window)
7575 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7577 return window->focus_on_map;
7581 * gdk_window_is_input_only:
7582 * @window: a toplevel #GdkWindow
7584 * Determines whether or not the window is an input only window.
7586 * Return value: %TRUE if @window is input only
7591 gdk_window_is_input_only (GdkWindow *window)
7593 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7595 return window->input_only;
7599 * gdk_window_is_shaped:
7600 * @window: a toplevel #GdkWindow
7602 * Determines whether or not the window is shaped.
7604 * Return value: %TRUE if @window is shaped
7609 gdk_window_is_shaped (GdkWindow *window)
7611 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7613 return window->shaped;
7617 window_get_size_rectangle (GdkWindow *window,
7620 rect->x = rect->y = 0;
7621 rect->width = window->width;
7622 rect->height = window->height;
7625 /* Calculates the real clipping region for a window, in window coordinates,
7626 * taking into account other windows, gc clip region and gc clip mask.
7629 _gdk_window_calculate_full_clip_region (GdkWindow *window,
7630 GdkWindow *base_window,
7631 gboolean do_children,
7632 gint *base_x_offset,
7633 gint *base_y_offset)
7635 GdkRectangle visible_rect;
7636 cairo_region_t *real_clip_region;
7637 gint x_offset, y_offset;
7638 GdkWindow *parentwin, *lastwin;
7645 if (!window->viewable || window->input_only)
7646 return cairo_region_create ();
7648 window_get_size_rectangle (window, &visible_rect);
7650 /* real_clip_region is in window coordinates */
7651 real_clip_region = cairo_region_create_rectangle (&visible_rect);
7653 x_offset = y_offset = 0;
7657 parentwin = lastwin;
7659 parentwin = lastwin->parent;
7661 /* Remove the areas of all overlapping windows above parentwin in the hiearachy */
7662 for (; parentwin != NULL &&
7663 (parentwin == window || lastwin != base_window);
7664 lastwin = parentwin, parentwin = lastwin->parent)
7667 GdkRectangle real_clip_rect;
7669 if (parentwin != window)
7671 x_offset += lastwin->x;
7672 y_offset += lastwin->y;
7675 /* children is ordered in reverse stack order */
7676 for (cur = parentwin->children;
7677 cur && cur->data != lastwin;
7680 GdkWindow *child = cur->data;
7682 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
7685 /* Ignore offscreen children, as they don't draw in their parent and
7686 * don't take part in the clipping */
7687 if (gdk_window_is_offscreen (child))
7690 window_get_size_rectangle (child, &visible_rect);
7692 /* Convert rect to "window" coords */
7693 visible_rect.x += child->x - x_offset;
7694 visible_rect.y += child->y - y_offset;
7696 /* This shortcut is really necessary for performance when there are a lot of windows */
7697 cairo_region_get_extents (real_clip_region, &real_clip_rect);
7698 if (visible_rect.x >= real_clip_rect.x + real_clip_rect.width ||
7699 visible_rect.x + visible_rect.width <= real_clip_rect.x ||
7700 visible_rect.y >= real_clip_rect.y + real_clip_rect.height ||
7701 visible_rect.y + visible_rect.height <= real_clip_rect.y)
7704 cairo_region_subtract_rectangle (real_clip_region, &visible_rect);
7707 /* Clip to the parent */
7708 window_get_size_rectangle ((GdkWindow *)parentwin, &visible_rect);
7709 /* Convert rect to "window" coords */
7710 visible_rect.x += - x_offset;
7711 visible_rect.y += - y_offset;
7713 cairo_region_intersect_rectangle (real_clip_region, &visible_rect);
7717 *base_x_offset = x_offset;
7719 *base_y_offset = y_offset;
7721 return real_clip_region;
7725 _gdk_window_add_damage (GdkWindow *toplevel,
7726 cairo_region_t *damaged_region)
7728 GdkDisplay *display;
7729 GdkEvent event = { 0, };
7730 event.expose.type = GDK_DAMAGE;
7731 event.expose.window = toplevel;
7732 event.expose.send_event = FALSE;
7733 event.expose.region = damaged_region;
7734 cairo_region_get_extents (event.expose.region, &event.expose.area);
7735 display = gdk_window_get_display (event.expose.window);
7736 _gdk_event_queue_append (display, gdk_event_copy (&event));
7739 /* Gets the toplevel for a window as used for events,
7740 i.e. including offscreen parents */
7742 get_event_parent (GdkWindow *window)
7744 if (gdk_window_is_offscreen (window))
7745 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7747 return window->parent;
7750 /* Gets the toplevel for a window as used for events,
7751 i.e. including offscreen parents going up to the native
7754 get_event_toplevel (GdkWindow *window)
7758 while ((parent = get_event_parent (window)) != NULL &&
7759 (parent->window_type != GDK_WINDOW_ROOT))
7766 _gdk_window_event_parent_of (GdkWindow *parent,
7777 w = get_event_parent (w);
7784 update_cursor (GdkDisplay *display,
7787 GdkWindow *cursor_window, *parent, *toplevel;
7788 GdkWindow *pointer_window;
7789 GdkWindowImplClass *impl_class;
7790 GdkPointerWindowInfo *pointer_info;
7791 GdkDeviceGrabInfo *grab;
7794 pointer_info = _gdk_display_get_pointer_info (display, device);
7795 pointer_window = pointer_info->window_under_pointer;
7797 /* We ignore the serials here and just pick the last grab
7798 we've sent, as that would shortly be used anyway. */
7799 grab = _gdk_display_get_last_device_grab (display, device);
7802 /* the pointer is not in a descendant of the grab window */
7803 !_gdk_window_event_parent_of (grab->window, pointer_window))
7805 /* use the cursor from the grab window */
7806 cursor_window = grab->window;
7810 /* otherwise use the cursor from the pointer window */
7811 cursor_window = pointer_window;
7814 /* Find the first window with the cursor actually set, as
7815 the cursor is inherited from the parent */
7816 while (cursor_window->cursor == NULL &&
7817 (parent = get_event_parent (cursor_window)) != NULL &&
7818 parent->window_type != GDK_WINDOW_ROOT)
7819 cursor_window = parent;
7821 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7824 cursor = cursor_window->cursor;
7826 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7827 * which native window has what cursor set. */
7828 toplevel = get_event_toplevel (pointer_window);
7829 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7830 impl_class->set_device_cursor (toplevel, device, cursor);
7834 point_in_window (GdkWindow *window,
7839 x >= 0 && x < window->width &&
7840 y >= 0 && y < window->height &&
7841 (window->shape == NULL ||
7842 cairo_region_contains_point (window->shape,
7844 (window->input_shape == NULL ||
7845 cairo_region_contains_point (window->input_shape,
7850 convert_native_coords_to_toplevel (GdkWindow *window,
7853 gdouble *toplevel_x,
7854 gdouble *toplevel_y)
7861 while (!gdk_window_is_toplevel (window))
7865 window = window->parent;
7875 convert_toplevel_coords_to_window (GdkWindow *window,
7883 GList *children, *l;
7889 while ((parent = get_event_parent (window)) != NULL &&
7890 (parent->window_type != GDK_WINDOW_ROOT))
7892 children = g_list_prepend (children, window);
7896 for (l = children; l != NULL; l = l->next)
7897 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7899 g_list_free (children);
7906 pick_embedded_child (GdkWindow *window,
7913 g_signal_emit (window,
7914 signals[PICK_EMBEDDED_CHILD], 0,
7921 _gdk_window_find_child_at (GdkWindow *window,
7926 double child_x, child_y;
7929 if (point_in_window (window, x, y))
7931 /* Children is ordered in reverse stack order, i.e. first is topmost */
7932 for (l = window->children; l != NULL; l = l->next)
7936 if (!GDK_WINDOW_IS_MAPPED (sub))
7939 gdk_window_coords_from_parent ((GdkWindow *)sub,
7941 &child_x, &child_y);
7942 if (point_in_window (sub, child_x, child_y))
7943 return (GdkWindow *)sub;
7946 if (window->num_offscreen_children > 0)
7948 sub = pick_embedded_child (window,
7951 return (GdkWindow *)sub;
7959 _gdk_window_find_descendant_at (GdkWindow *window,
7966 gdouble child_x, child_y;
7970 if (point_in_window (window, x, y))
7975 /* Children is ordered in reverse stack order, i.e. first is topmost */
7976 for (l = window->children; l != NULL; l = l->next)
7980 if (!GDK_WINDOW_IS_MAPPED (sub))
7983 gdk_window_coords_from_parent ((GdkWindow *)sub,
7985 &child_x, &child_y);
7986 if (point_in_window (sub, child_x, child_y))
7996 window->num_offscreen_children > 0)
7998 sub = pick_embedded_child (window,
8004 from_embedder (sub, x, y, &x, &y);
8012 /* Not in window at all */
8026 * @window: a toplevel #GdkWindow
8028 * Emits a short beep associated to @window in the appropriate
8029 * display, if supported. Otherwise, emits a short beep on
8030 * the display just as gdk_display_beep().
8035 gdk_window_beep (GdkWindow *window)
8037 GdkDisplay *display;
8038 GdkWindow *toplevel;
8040 g_return_if_fail (GDK_IS_WINDOW (window));
8042 if (GDK_WINDOW_DESTROYED (window))
8045 toplevel = get_event_toplevel (window);
8046 display = gdk_window_get_display (window);
8050 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (window))
8054 /* If windows fail to beep, we beep the display. */
8055 gdk_display_beep (display);
8059 * gdk_window_set_support_multidevice:
8060 * @window: a #GdkWindow.
8061 * @support_multidevice: %TRUE to enable multidevice support in @window.
8063 * This function will enable multidevice features in @window.
8065 * Multidevice aware windows will need to handle properly multiple,
8066 * per device enter/leave events, device grabs and grab ownerships.
8071 gdk_window_set_support_multidevice (GdkWindow *window,
8072 gboolean support_multidevice)
8074 g_return_if_fail (GDK_IS_WINDOW (window));
8076 if (GDK_WINDOW_DESTROYED (window))
8079 if (window->support_multidevice == support_multidevice)
8082 window->support_multidevice = support_multidevice;
8084 /* FIXME: What to do if called when some pointers are inside the window ? */
8088 * gdk_window_get_support_multidevice:
8089 * @window: a #GdkWindow.
8091 * Returns %TRUE if the window is aware of the existence of multiple
8094 * Returns: %TRUE if the window handles multidevice features.
8099 gdk_window_get_support_multidevice (GdkWindow *window)
8101 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8103 if (GDK_WINDOW_DESTROYED (window))
8106 return window->support_multidevice;
8109 static const guint type_masks[] = {
8110 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8111 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8112 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8113 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8114 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8115 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8116 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8117 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8118 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8119 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8120 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8121 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8122 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8123 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8124 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8125 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8126 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8127 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8128 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8129 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8130 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8131 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8132 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8133 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8134 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8135 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8136 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8137 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8138 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8139 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8140 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8141 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8142 0, /* GDK_WINDOW_STATE = 32 */
8143 0, /* GDK_SETTING = 33 */
8144 0, /* GDK_OWNER_CHANGE = 34 */
8145 0, /* GDK_GRAB_BROKEN = 35 */
8146 0, /* GDK_DAMAGE = 36 */
8148 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8150 /* send motion events if the right buttons are down */
8152 update_evmask_for_button_motion (guint evmask,
8153 GdkModifierType mask)
8155 if (evmask & GDK_BUTTON_MOTION_MASK &&
8156 mask & (GDK_BUTTON1_MASK |
8161 evmask |= GDK_POINTER_MOTION_MASK;
8163 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8164 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8165 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8166 evmask |= GDK_POINTER_MOTION_MASK;
8172 is_button_type (GdkEventType type)
8174 return type == GDK_BUTTON_PRESS ||
8175 type == GDK_2BUTTON_PRESS ||
8176 type == GDK_3BUTTON_PRESS ||
8177 type == GDK_BUTTON_RELEASE ||
8182 is_motion_type (GdkEventType type)
8184 return type == GDK_MOTION_NOTIFY ||
8185 type == GDK_ENTER_NOTIFY ||
8186 type == GDK_LEAVE_NOTIFY;
8190 find_common_ancestor (GdkWindow *win1,
8194 GList *path1 = NULL, *path2 = NULL;
8195 GList *list1, *list2;
8198 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8200 path1 = g_list_prepend (path1, tmp);
8201 tmp = get_event_parent (tmp);
8205 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8207 path2 = g_list_prepend (path2, tmp);
8208 tmp = get_event_parent (tmp);
8214 while (list1 && list2 && (list1->data == list2->data))
8217 list1 = g_list_next (list1);
8218 list2 = g_list_next (list2);
8220 g_list_free (path1);
8221 g_list_free (path2);
8227 _gdk_make_event (GdkWindow *window,
8229 GdkEvent *event_in_queue,
8230 gboolean before_event)
8232 GdkEvent *event = gdk_event_new (type);
8234 GdkModifierType the_state;
8236 the_time = gdk_event_get_time (event_in_queue);
8237 gdk_event_get_state (event_in_queue, &the_state);
8239 event->any.window = g_object_ref (window);
8240 event->any.send_event = FALSE;
8241 if (event_in_queue && event_in_queue->any.send_event)
8242 event->any.send_event = TRUE;
8246 case GDK_MOTION_NOTIFY:
8247 event->motion.time = the_time;
8248 event->motion.axes = NULL;
8249 event->motion.state = the_state;
8252 case GDK_BUTTON_PRESS:
8253 case GDK_2BUTTON_PRESS:
8254 case GDK_3BUTTON_PRESS:
8255 case GDK_BUTTON_RELEASE:
8256 event->button.time = the_time;
8257 event->button.axes = NULL;
8258 event->button.state = the_state;
8262 event->scroll.time = the_time;
8263 event->scroll.state = the_state;
8267 case GDK_KEY_RELEASE:
8268 event->key.time = the_time;
8269 event->key.state = the_state;
8272 case GDK_ENTER_NOTIFY:
8273 case GDK_LEAVE_NOTIFY:
8274 event->crossing.time = the_time;
8275 event->crossing.state = the_state;
8278 case GDK_PROPERTY_NOTIFY:
8279 event->property.time = the_time;
8280 event->property.state = the_state;
8283 case GDK_SELECTION_CLEAR:
8284 case GDK_SELECTION_REQUEST:
8285 case GDK_SELECTION_NOTIFY:
8286 event->selection.time = the_time;
8289 case GDK_PROXIMITY_IN:
8290 case GDK_PROXIMITY_OUT:
8291 event->proximity.time = the_time;
8294 case GDK_DRAG_ENTER:
8295 case GDK_DRAG_LEAVE:
8296 case GDK_DRAG_MOTION:
8297 case GDK_DRAG_STATUS:
8298 case GDK_DROP_START:
8299 case GDK_DROP_FINISHED:
8300 event->dnd.time = the_time;
8303 case GDK_FOCUS_CHANGE:
8307 case GDK_CLIENT_EVENT:
8308 case GDK_VISIBILITY_NOTIFY:
8319 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8321 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8324 _gdk_event_queue_append (gdk_window_get_display (window), event);
8330 send_crossing_event (GdkDisplay *display,
8331 GdkWindow *toplevel,
8334 GdkCrossingMode mode,
8335 GdkNotifyType notify_type,
8336 GdkWindow *subwindow,
8340 GdkModifierType mask,
8342 GdkEvent *event_in_queue,
8346 guint32 window_event_mask, type_event_mask;
8347 GdkDeviceGrabInfo *grab;
8348 gboolean block_event = FALSE;
8350 grab = _gdk_display_has_device_grab (display, device, serial);
8353 !grab->owner_events)
8355 /* !owner_event => only report events wrt grab window, ignore rest */
8356 if ((GdkWindow *)window != grab->window)
8358 window_event_mask = grab->event_mask;
8361 window_event_mask = window->event_mask;
8363 if (type == GDK_LEAVE_NOTIFY)
8365 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8366 window->devices_inside = g_list_remove (window->devices_inside, device);
8368 if (!window->support_multidevice && window->devices_inside)
8370 /* Block leave events unless it's the last pointer */
8376 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8378 if (!window->support_multidevice && window->devices_inside)
8380 /* Only emit enter events for the first device */
8384 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8385 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8386 !g_list_find (window->devices_inside, device))
8387 window->devices_inside = g_list_prepend (window->devices_inside, device);
8393 if (window_event_mask & type_event_mask)
8395 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8396 gdk_event_set_device (event, device);
8397 event->crossing.time = time_;
8398 event->crossing.subwindow = subwindow;
8400 g_object_ref (subwindow);
8401 convert_toplevel_coords_to_window ((GdkWindow *)window,
8402 toplevel_x, toplevel_y,
8403 &event->crossing.x, &event->crossing.y);
8404 event->crossing.x_root = toplevel_x + toplevel->x;
8405 event->crossing.y_root = toplevel_y + toplevel->y;
8406 event->crossing.mode = mode;
8407 event->crossing.detail = notify_type;
8408 event->crossing.focus = FALSE;
8409 event->crossing.state = mask;
8414 /* The coordinates are in the toplevel window that src/dest are in.
8415 * src and dest are always (if != NULL) in the same toplevel, as
8416 * we get a leave-notify and set the window_under_pointer to null
8417 * before crossing to another toplevel.
8420 _gdk_synthesize_crossing_events (GdkDisplay *display,
8424 GdkCrossingMode mode,
8427 GdkModifierType mask,
8429 GdkEvent *event_in_queue,
8431 gboolean non_linear)
8434 GdkWindow *win, *last, *next;
8438 GdkWindow *toplevel;
8439 GdkNotifyType notify_type;
8441 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8446 return; /* No crossings generated between src and dest */
8448 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8450 if (a && gdk_window_get_device_events (src, device) == 0)
8453 if (b && gdk_window_get_device_events (dest, device) == 0)
8460 c = find_common_ancestor (a, b);
8462 non_linear |= (c != a) && (c != b);
8464 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8466 toplevel = gdk_window_get_toplevel (a);
8468 /* Traverse up from a to (excluding) c sending leave events */
8470 notify_type = GDK_NOTIFY_NONLINEAR;
8472 notify_type = GDK_NOTIFY_INFERIOR;
8474 notify_type = GDK_NOTIFY_ANCESTOR;
8475 send_crossing_event (display, toplevel,
8476 a, GDK_LEAVE_NOTIFY,
8480 toplevel_x, toplevel_y,
8488 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8490 notify_type = GDK_NOTIFY_VIRTUAL;
8493 win = get_event_parent (a);
8494 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8496 send_crossing_event (display, toplevel,
8497 win, GDK_LEAVE_NOTIFY,
8502 toplevel_x, toplevel_y,
8508 win = get_event_parent (win);
8513 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8515 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8517 /* Traverse down from c to b */
8521 win = get_event_parent (b);
8522 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8524 path = g_list_prepend (path, win);
8525 win = get_event_parent (win);
8529 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8531 notify_type = GDK_NOTIFY_VIRTUAL;
8537 list = g_list_next (list);
8543 send_crossing_event (display, toplevel,
8544 win, GDK_ENTER_NOTIFY,
8549 toplevel_x, toplevel_y,
8559 notify_type = GDK_NOTIFY_NONLINEAR;
8561 notify_type = GDK_NOTIFY_ANCESTOR;
8563 notify_type = GDK_NOTIFY_INFERIOR;
8565 send_crossing_event (display, toplevel,
8566 b, GDK_ENTER_NOTIFY,
8571 toplevel_x, toplevel_y,
8578 /* Returns the window inside the event window with the pointer in it
8579 * at the specified coordinates, or NULL if its not in any child of
8580 * the toplevel. It also takes into account !owner_events grabs.
8583 get_pointer_window (GdkDisplay *display,
8584 GdkWindow *event_window,
8590 GdkWindow *pointer_window;
8591 GdkDeviceGrabInfo *grab;
8592 GdkPointerWindowInfo *pointer_info;
8594 pointer_info = _gdk_display_get_pointer_info (display, device);
8596 if (event_window == pointer_info->toplevel_under_pointer)
8598 _gdk_window_find_descendant_at (event_window,
8599 toplevel_x, toplevel_y,
8602 pointer_window = NULL;
8604 grab = _gdk_display_has_device_grab (display, device, serial);
8606 !grab->owner_events &&
8607 pointer_window != grab->window)
8608 pointer_window = NULL;
8610 return pointer_window;
8614 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8618 GdkPointerWindowInfo *device_info;
8620 /* We don't track this if all native, and it can cause issues
8621 with the update_cursor call below */
8622 if (_gdk_native_windows)
8625 device_info = _gdk_display_get_pointer_info (display, device);
8627 if (device_info->window_under_pointer)
8628 g_object_unref (device_info->window_under_pointer);
8629 device_info->window_under_pointer = window;
8633 g_object_ref (window);
8634 update_cursor (display, device);
8637 _gdk_display_enable_motion_hints (display, device);
8642 * @window: the #GdkWindow which will own the grab (the grab window).
8643 * @owner_events: if %FALSE then all pointer events are reported with respect to
8644 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8645 * events for this application are reported as normal, but pointer events outside
8646 * this application are reported with respect to @window and only if selected by
8647 * @event_mask. In either mode, unreported events are discarded.
8648 * @event_mask: specifies the event mask, which is used in accordance with
8649 * @owner_events. Note that only pointer events (i.e. button and motion events)
8651 * @confine_to: If non-%NULL, the pointer will be confined to this
8652 * window during the grab. If the pointer is outside @confine_to, it will
8653 * automatically be moved to the closest edge of @confine_to and enter
8654 * and leave events will be generated as necessary.
8655 * @cursor: the cursor to display while the grab is active. If this is %NULL then
8656 * the normal cursors are used for @window and its descendants, and the cursor
8657 * for @window is used for all other windows.
8658 * @time_: the timestamp of the event which led to this pointer grab. This usually
8659 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8660 * the time isn't known.
8662 * Grabs the pointer (usually a mouse) so that all events are passed to this
8663 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8664 * the grab window becomes unviewable.
8665 * This overrides any previous pointer grab by this client.
8667 * Pointer grabs are used for operations which need complete control over mouse
8668 * events, even if the mouse leaves the application.
8669 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8670 * the #GtkHPaned and #GtkVPaned widgets.
8672 * Note that if the event mask of an X window has selected both button press and
8673 * button release events, then a button press event will cause an automatic
8674 * pointer grab until the button is released.
8675 * X does this automatically since most applications expect to receive button
8676 * press and release events in pairs.
8677 * It is equivalent to a pointer grab on the window with @owner_events set to
8680 * If you set up anything at the time you take the grab that needs to be cleaned
8681 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8682 * are emitted when the grab ends unvoluntarily.
8684 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8686 * Deprecated: 3.0: Use gdk_device_grab() instead.
8689 gdk_pointer_grab (GdkWindow * window,
8690 gboolean owner_events,
8691 GdkEventMask event_mask,
8692 GdkWindow * confine_to,
8697 GdkDisplay *display;
8698 GdkDeviceManager *device_manager;
8700 GdkGrabStatus res = 0;
8702 GList *devices, *dev;
8704 g_return_val_if_fail (window != NULL, 0);
8705 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8706 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8708 /* We need a native window for confine to to work, ensure we have one */
8711 if (!gdk_window_ensure_native (confine_to))
8713 g_warning ("Can't confine to grabbed window, not native");
8718 /* Non-viewable client side window => fail */
8719 if (!_gdk_window_has_impl (window) &&
8720 !gdk_window_is_viewable (window))
8721 return GDK_GRAB_NOT_VIEWABLE;
8723 if (_gdk_native_windows)
8726 native = gdk_window_get_toplevel (window);
8727 while (gdk_window_is_offscreen (native))
8729 native = gdk_offscreen_window_get_embedder (native);
8731 if (native == NULL ||
8732 (!_gdk_window_has_impl (native) &&
8733 !gdk_window_is_viewable (native)))
8734 return GDK_GRAB_NOT_VIEWABLE;
8736 native = gdk_window_get_toplevel (native);
8739 display = gdk_window_get_display (window);
8741 serial = _gdk_windowing_window_get_next_serial (display);
8742 device_manager = gdk_display_get_device_manager (display);
8743 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8745 /* FIXME: Should this be generic to all backends? */
8746 /* FIXME: What happens with extended devices? */
8747 for (dev = devices; dev; dev = dev->next)
8751 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8754 res = _gdk_windowing_device_grab (device,
8758 get_native_grab_event_mask (event_mask),
8763 if (res == GDK_GRAB_SUCCESS)
8764 _gdk_display_add_device_grab (display,
8776 /* FIXME: handle errors when grabbing */
8778 g_list_free (devices);
8784 * gdk_keyboard_grab:
8785 * @window: the #GdkWindow which will own the grab (the grab window).
8786 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8787 * @window. If %TRUE then keyboard events for this application are
8788 * reported as normal, but keyboard events outside this application
8789 * are reported with respect to @window. Both key press and key
8790 * release events are always reported, independant of the event mask
8791 * set by the application.
8792 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8795 * Grabs the keyboard so that all events are passed to this
8796 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8797 * This overrides any previous keyboard grab by this client.
8799 * If you set up anything at the time you take the grab that needs to be cleaned
8800 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8801 * are emitted when the grab ends unvoluntarily.
8803 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8805 * Deprecated: 3.0: Use gdk_device_grab() instead.
8808 gdk_keyboard_grab (GdkWindow *window,
8809 gboolean owner_events,
8813 GdkDisplay *display;
8814 GdkDeviceManager *device_manager;
8816 GdkGrabStatus res = 0;
8818 GList *devices, *dev;
8820 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8822 /* Non-viewable client side window => fail */
8823 if (!_gdk_window_has_impl (window) &&
8824 !gdk_window_is_viewable (window))
8825 return GDK_GRAB_NOT_VIEWABLE;
8827 if (_gdk_native_windows)
8830 native = gdk_window_get_toplevel (window);
8832 while (gdk_window_is_offscreen (native))
8834 native = gdk_offscreen_window_get_embedder (native);
8836 if (native == NULL ||
8837 (!_gdk_window_has_impl (native) &&
8838 !gdk_window_is_viewable (native)))
8839 return GDK_GRAB_NOT_VIEWABLE;
8841 native = gdk_window_get_toplevel (native);
8844 display = gdk_window_get_display (window);
8846 serial = _gdk_windowing_window_get_next_serial (display);
8847 device_manager = gdk_display_get_device_manager (display);
8848 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8850 /* FIXME: Should this be generic to all backends? */
8851 /* FIXME: What happens with extended devices? */
8852 for (dev = devices; dev; dev = dev->next)
8856 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8859 res = _gdk_windowing_device_grab (device,
8863 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8868 if (res == GDK_GRAB_SUCCESS)
8869 _gdk_display_add_device_grab (display,
8880 /* FIXME: handle errors when grabbing */
8882 g_list_free (devices);
8888 * gdk_window_geometry_changed:
8889 * @window: an embedded offscreen #GdkWindow
8891 * This function informs GDK that the geometry of an embedded
8892 * offscreen window has changed. This is necessary for GDK to keep
8893 * track of which offscreen window the pointer is in.
8898 gdk_window_geometry_changed (GdkWindow *window)
8900 _gdk_synthesize_crossing_events_for_geometry_change (window);
8904 do_synthesize_crossing_event (gpointer data)
8906 GdkDisplay *display;
8907 GdkWindow *changed_toplevel;
8908 GHashTableIter iter;
8909 gpointer key, value;
8912 changed_toplevel = data;
8914 changed_toplevel->synthesize_crossing_event_queued = FALSE;
8916 if (GDK_WINDOW_DESTROYED (changed_toplevel))
8919 display = gdk_window_get_display (changed_toplevel);
8920 serial = _gdk_windowing_window_get_next_serial (display);
8921 g_hash_table_iter_init (&iter, display->pointers_info);
8923 while (g_hash_table_iter_next (&iter, &key, &value))
8925 GdkWindow *new_window_under_pointer;
8926 GdkPointerWindowInfo *pointer_info = value;
8927 GdkDevice *device = key;
8929 if (changed_toplevel == pointer_info->toplevel_under_pointer)
8931 new_window_under_pointer =
8932 get_pointer_window (display, changed_toplevel,
8934 pointer_info->toplevel_x,
8935 pointer_info->toplevel_y,
8937 if (new_window_under_pointer != pointer_info->window_under_pointer)
8939 _gdk_synthesize_crossing_events (display,
8940 pointer_info->window_under_pointer,
8941 new_window_under_pointer,
8943 GDK_CROSSING_NORMAL,
8944 pointer_info->toplevel_x,
8945 pointer_info->toplevel_y,
8946 pointer_info->state,
8951 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
8960 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
8962 GdkDisplay *display;
8963 GdkWindow *toplevel;
8965 if (_gdk_native_windows)
8966 return; /* We use the native crossing events if all native */
8968 display = gdk_window_get_display (changed_window);
8970 toplevel = get_event_toplevel (changed_window);
8972 if (!toplevel->synthesize_crossing_event_queued)
8974 toplevel->synthesize_crossing_event_queued = TRUE;
8976 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
8977 do_synthesize_crossing_event,
8978 g_object_ref (toplevel),
8983 /* Don't use for crossing events */
8985 get_event_window (GdkDisplay *display,
8987 GdkWindow *pointer_window,
8989 GdkModifierType mask,
8994 GdkWindow *grab_window;
8995 GdkDeviceGrabInfo *grab;
8997 grab = _gdk_display_has_device_grab (display, device, serial);
8999 if (grab != NULL && !grab->owner_events)
9001 evmask = grab->event_mask;
9002 evmask = update_evmask_for_button_motion (evmask, mask);
9004 grab_window = grab->window;
9006 if (evmask & type_masks[type])
9009 *evmask_out = evmask;
9016 while (pointer_window != NULL)
9018 evmask = pointer_window->event_mask;
9019 evmask = update_evmask_for_button_motion (evmask, mask);
9021 if (evmask & type_masks[type])
9024 *evmask_out = evmask;
9025 return pointer_window;
9028 pointer_window = get_event_parent (pointer_window);
9034 evmask = grab->event_mask;
9035 evmask = update_evmask_for_button_motion (evmask, mask);
9037 if (evmask & type_masks[type])
9040 *evmask_out = evmask;
9041 return grab->window;
9051 proxy_pointer_event (GdkDisplay *display,
9052 GdkEvent *source_event,
9055 GdkWindow *toplevel_window, *event_window;
9056 GdkWindow *pointer_window;
9057 GdkPointerWindowInfo *pointer_info;
9061 gdouble toplevel_x, toplevel_y;
9063 gboolean non_linear;
9065 event_window = source_event->any.window;
9066 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9067 gdk_event_get_state (source_event, &state);
9068 time_ = gdk_event_get_time (source_event);
9069 device = gdk_event_get_device (source_event);
9070 pointer_info = _gdk_display_get_pointer_info (display, device);
9071 toplevel_window = convert_native_coords_to_toplevel (event_window,
9072 toplevel_x, toplevel_y,
9073 &toplevel_x, &toplevel_y);
9076 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9077 source_event->type == GDK_ENTER_NOTIFY) &&
9078 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9079 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9082 /* If we get crossing events with subwindow unexpectedly being NULL
9083 that means there is a native subwindow that gdk doesn't know about.
9084 We track these and forward them, with the correct virtual window
9086 This is important to get right, as metacity uses gdk for the frame
9087 windows, but gdk doesn't know about the client windows reparented
9089 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9090 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9091 (source_event->type == GDK_ENTER_NOTIFY &&
9092 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9093 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9094 source_event->crossing.subwindow == NULL)
9096 /* Left for an unknown (to gdk) subwindow */
9098 /* Send leave events from window under pointer to event window
9099 that will get the subwindow == NULL window */
9100 _gdk_synthesize_crossing_events (display,
9101 pointer_info->window_under_pointer,
9104 source_event->crossing.mode,
9105 toplevel_x, toplevel_y,
9111 /* Send subwindow == NULL event */
9112 send_crossing_event (display,
9116 source_event->crossing.mode,
9117 source_event->crossing.detail,
9120 toplevel_x, toplevel_y,
9125 _gdk_display_set_window_under_pointer (display, device, NULL);
9129 pointer_window = get_pointer_window (display, toplevel_window, device,
9130 toplevel_x, toplevel_y, serial);
9132 if (((source_event->type == GDK_ENTER_NOTIFY &&
9133 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9134 (source_event->type == GDK_LEAVE_NOTIFY &&
9135 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9136 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9137 source_event->crossing.subwindow == NULL)
9139 /* Entered from an unknown (to gdk) subwindow */
9141 /* Send subwindow == NULL event */
9142 send_crossing_event (display,
9146 source_event->crossing.mode,
9147 source_event->crossing.detail,
9150 toplevel_x, toplevel_y,
9155 /* Send enter events from event window to pointer_window */
9156 _gdk_synthesize_crossing_events (display,
9160 source_event->crossing.mode,
9161 toplevel_x, toplevel_y,
9164 serial, non_linear);
9165 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9169 if (pointer_info->window_under_pointer != pointer_window)
9171 /* Either a toplevel crossing notify that ended up inside a child window,
9172 or a motion notify that got into another child window */
9174 /* Different than last time, send crossing events */
9175 _gdk_synthesize_crossing_events (display,
9176 pointer_info->window_under_pointer,
9179 GDK_CROSSING_NORMAL,
9180 toplevel_x, toplevel_y,
9183 serial, non_linear);
9184 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9186 else if (source_event->type == GDK_MOTION_NOTIFY)
9188 GdkWindow *event_win;
9192 event_win = get_event_window (display,
9201 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9202 gdk_window_get_device_events (event_win, device) == 0)
9208 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9210 gulong *device_serial;
9212 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9214 if (!device_serial ||
9215 (*device_serial != 0 &&
9216 serial < *device_serial))
9217 event_win = NULL; /* Ignore event */
9221 *device_serial = G_MAXULONG;
9225 if (event_win && !display->ignore_core_events)
9227 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9228 event->motion.time = time_;
9229 convert_toplevel_coords_to_window (event_win,
9230 toplevel_x, toplevel_y,
9231 &event->motion.x, &event->motion.y);
9232 event->motion.x_root = source_event->motion.x_root;
9233 event->motion.y_root = source_event->motion.y_root;
9234 event->motion.state = state;
9235 event->motion.is_hint = is_hint;
9236 event->motion.device = source_event->motion.device;
9237 event->motion.axes = g_memdup (source_event->motion.axes,
9238 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9242 /* unlink all move events from queue.
9243 We handle our own, including our emulated masks. */
9247 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9248 GDK_BUTTON2_MASK | \
9249 GDK_BUTTON3_MASK | \
9250 GDK_BUTTON4_MASK | \
9254 proxy_button_event (GdkEvent *source_event,
9257 GdkWindow *toplevel_window, *event_window;
9258 GdkWindow *event_win;
9259 GdkWindow *pointer_window;
9265 gdouble toplevel_x, toplevel_y;
9266 GdkDisplay *display;
9270 type = source_event->any.type;
9271 event_window = source_event->any.window;
9272 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9273 gdk_event_get_state (source_event, &state);
9274 time_ = gdk_event_get_time (source_event);
9275 device = gdk_event_get_device (source_event);
9276 display = gdk_window_get_display (source_event->any.window);
9277 toplevel_window = convert_native_coords_to_toplevel (event_window,
9278 toplevel_x, toplevel_y,
9279 &toplevel_x, &toplevel_y);
9281 if (type == GDK_BUTTON_PRESS &&
9282 !source_event->any.send_event &&
9283 _gdk_display_has_device_grab (display, device, serial) == NULL)
9286 _gdk_window_find_descendant_at (toplevel_window,
9287 toplevel_x, toplevel_y,
9290 /* Find the event window, that gets the grab */
9293 (parent = get_event_parent (w)) != NULL &&
9294 parent->window_type != GDK_WINDOW_ROOT)
9296 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9300 pointer_window = (GdkWindow *)w;
9302 _gdk_display_add_device_grab (display,
9308 gdk_window_get_events (pointer_window),
9312 _gdk_display_device_grab_update (display, device, serial);
9315 pointer_window = get_pointer_window (display, toplevel_window, device,
9316 toplevel_x, toplevel_y,
9319 event_win = get_event_window (display,
9325 if (event_win == NULL || display->ignore_core_events)
9328 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9329 gdk_window_get_device_events (event_win, device) == 0)
9332 event = _gdk_make_event (event_win, type, source_event, FALSE);
9336 case GDK_BUTTON_PRESS:
9337 case GDK_BUTTON_RELEASE:
9338 event->button.button = source_event->button.button;
9339 convert_toplevel_coords_to_window (event_win,
9340 toplevel_x, toplevel_y,
9341 &event->button.x, &event->button.y);
9342 event->button.x_root = source_event->button.x_root;
9343 event->button.y_root = source_event->button.y_root;
9344 event->button.state = state;
9345 event->button.device = source_event->button.device;
9346 event->button.axes = g_memdup (source_event->button.axes,
9347 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9349 if (type == GDK_BUTTON_PRESS)
9350 _gdk_event_button_generate (display, event);
9354 event->scroll.direction = source_event->scroll.direction;
9355 convert_toplevel_coords_to_window (event_win,
9356 toplevel_x, toplevel_y,
9357 &event->scroll.x, &event->scroll.y);
9358 event->scroll.x_root = source_event->scroll.x_root;
9359 event->scroll.y_root = source_event->scroll.y_root;
9360 event->scroll.state = state;
9361 event->scroll.device = source_event->scroll.device;
9368 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9371 #ifdef DEBUG_WINDOW_PRINTING
9373 gdk_window_print (GdkWindow *window,
9377 const char *window_types[] = {
9387 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9388 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9389 window->x, window->y,
9390 window->width, window->height
9393 if (gdk_window_has_impl (window))
9395 #ifdef GDK_WINDOWING_X11
9396 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9400 if (window->window_type != GDK_WINDOW_CHILD)
9401 g_print (" %s", window_types[window->window_type]);
9403 if (window->input_only)
9404 g_print (" input-only");
9407 g_print (" shaped");
9409 if (!gdk_window_is_visible ((GdkWindow *)window))
9410 g_print (" hidden");
9412 g_print (" abs[%d,%d]",
9413 window->abs_x, window->abs_y);
9415 cairo_region_get_extents (window->clip_region, &r);
9416 if (cairo_region_is_empty (window->clip_region))
9417 g_print (" clipbox[empty]");
9419 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9426 gdk_window_print_tree (GdkWindow *window,
9428 gboolean include_input_only)
9432 if (window->input_only && !include_input_only)
9435 gdk_window_print (window, indent);
9437 for (l = window->children; l != NULL; l = l->next)
9438 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9441 #endif /* DEBUG_WINDOW_PRINTING */
9444 _gdk_windowing_got_event (GdkDisplay *display,
9449 GdkWindow *event_window;
9451 gboolean unlink_event;
9452 guint old_state, old_button;
9453 GdkDeviceGrabInfo *button_release_grab;
9454 GdkPointerWindowInfo *pointer_info;
9456 gboolean is_toplevel;
9458 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9459 display->last_event_time = gdk_event_get_time (event);
9461 device = gdk_event_get_device (event);
9467 g_object_get (device, "input-mode", &mode, NULL);
9468 _gdk_display_device_grab_update (display, device, serial);
9470 if (mode == GDK_MODE_DISABLED ||
9471 !_gdk_display_check_grab_ownership (display, device, serial))
9473 /* Device events are blocked by another
9474 * device grab, or the device is disabled
9476 unlink_event = TRUE;
9481 event_window = event->any.window;
9485 pointer_info = _gdk_display_get_pointer_info (display, device);
9487 #ifdef DEBUG_WINDOW_PRINTING
9488 if (event->type == GDK_KEY_PRESS &&
9489 (event->key.keyval == 0xa7 ||
9490 event->key.keyval == 0xbd))
9492 gdk_window_print_tree (event_window, 0,
9493 event->key.keyval == 0xbd);
9497 if (_gdk_native_windows)
9499 if (event->type == GDK_BUTTON_PRESS &&
9500 !event->any.send_event &&
9501 _gdk_display_has_device_grab (display, device, serial) == NULL)
9503 _gdk_display_add_device_grab (display,
9509 gdk_window_get_events (event_window),
9511 gdk_event_get_time (event),
9513 _gdk_display_device_grab_update (display, device, serial);
9515 if (event->type == GDK_BUTTON_RELEASE &&
9516 !event->any.send_event)
9518 button_release_grab =
9519 _gdk_display_has_device_grab (display, device, serial);
9520 if (button_release_grab &&
9521 button_release_grab->implicit &&
9522 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9524 button_release_grab->serial_end = serial;
9525 button_release_grab->implicit_ungrab = FALSE;
9526 _gdk_display_device_grab_update (display, device, serial);
9530 if (event->type == GDK_BUTTON_PRESS)
9531 _gdk_event_button_generate (display, event);
9536 if (event->type == GDK_VISIBILITY_NOTIFY)
9538 event_window->native_visibility = event->visibility.state;
9539 gdk_window_update_visibility_recursively (event_window,
9544 if (!(is_button_type (event->type) ||
9545 is_motion_type (event->type)) ||
9546 event_window->window_type == GDK_WINDOW_ROOT)
9549 is_toplevel = gdk_window_is_toplevel (event_window);
9551 if ((event->type == GDK_ENTER_NOTIFY ||
9552 event->type == GDK_LEAVE_NOTIFY) &&
9553 (event->crossing.mode == GDK_CROSSING_GRAB ||
9554 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9555 (_gdk_display_has_device_grab (display, device, serial) ||
9556 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9558 /* We synthesize all crossing events due to grabs ourselves,
9559 * so we ignore the native ones caused by our native pointer_grab
9560 * calls. Otherwise we would proxy these crossing event and cause
9561 * multiple copies of crossing events for grabs.
9563 * We do want to handle grabs from other clients though, as for
9564 * instance alt-tab in metacity causes grabs like these and
9565 * we want to handle those. Thus the has_pointer_grab check.
9567 * Implicit grabs on child windows create some grabbing events
9568 * that are sent before the button press. This means we can't
9569 * detect these with the has_pointer_grab check (as the implicit
9570 * grab is only noticed when we get button press event), so we
9571 * detect these events by checking for INFERIOR enter or leave
9572 * events. These should never be a problem to filter out.
9575 /* We ended up in this window after some (perhaps other clients)
9576 grab, so update the toplevel_under_window state */
9578 event->type == GDK_ENTER_NOTIFY &&
9579 event->crossing.mode == GDK_CROSSING_UNGRAB)
9581 if (pointer_info->toplevel_under_pointer)
9582 g_object_unref (pointer_info->toplevel_under_pointer);
9583 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9586 unlink_event = TRUE;
9590 /* Track toplevel_under_pointer */
9593 if (event->type == GDK_ENTER_NOTIFY &&
9594 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9596 if (pointer_info->toplevel_under_pointer)
9597 g_object_unref (pointer_info->toplevel_under_pointer);
9598 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9600 else if (event->type == GDK_LEAVE_NOTIFY &&
9601 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9602 pointer_info->toplevel_under_pointer == event_window)
9604 if (pointer_info->toplevel_under_pointer)
9605 g_object_unref (pointer_info->toplevel_under_pointer);
9606 pointer_info->toplevel_under_pointer = NULL;
9610 /* Store last pointer window and position/state */
9611 old_state = pointer_info->state;
9612 old_button = pointer_info->button;
9614 gdk_event_get_coords (event, &x, &y);
9615 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9616 pointer_info->toplevel_x = x;
9617 pointer_info->toplevel_y = y;
9618 gdk_event_get_state (event, &pointer_info->state);
9619 if (event->type == GDK_BUTTON_PRESS ||
9620 event->type == GDK_BUTTON_RELEASE)
9621 pointer_info->button = event->button.button;
9624 (pointer_info->state != old_state ||
9625 pointer_info->button != old_button))
9626 _gdk_display_enable_motion_hints (display, device);
9628 unlink_event = FALSE;
9629 if (is_motion_type (event->type))
9630 unlink_event = proxy_pointer_event (display,
9633 else if (is_button_type (event->type))
9634 unlink_event = proxy_button_event (event,
9637 if (event->type == GDK_BUTTON_RELEASE &&
9638 !event->any.send_event)
9640 button_release_grab =
9641 _gdk_display_has_device_grab (display, device, serial);
9642 if (button_release_grab &&
9643 button_release_grab->implicit &&
9644 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9646 button_release_grab->serial_end = serial;
9647 button_release_grab->implicit_ungrab = FALSE;
9648 _gdk_display_device_grab_update (display, device, serial);
9655 _gdk_event_queue_remove_link (display, event_link);
9656 g_list_free_1 (event_link);
9657 gdk_event_free (event);
9663 get_extension_event_window (GdkDisplay *display,
9664 GdkWindow *pointer_window,
9669 GdkWindow *w, *grab_window;
9670 GdkDeviceGrabInfo *grab;
9672 /* FIXME: which device? */
9673 grab = _gdk_display_has_device_grab (display, display->core_pointer, serial);
9675 if (grab != NULL && !grab->owner_events)
9677 evmask = grab->event_mask;
9679 grab_window = grab->window;
9681 if (evmask & type_masks[type])
9690 evmask = w->extension_events;
9692 if (evmask & type_masks[type])
9695 w = get_event_parent (w);
9701 evmask = grab->event_mask;
9703 if (evmask & type_masks[type])
9704 return grab->window;
9714 _gdk_window_get_input_window_for_event (GdkWindow *native_window,
9715 GdkEventType event_type,
9719 GdkDisplay *display;
9720 GdkWindow *toplevel_window;
9721 GdkWindow *pointer_window;
9722 GdkWindow *event_win;
9723 gdouble toplevel_x, toplevel_y;
9728 display = gdk_window_get_display (native_window);
9729 toplevel_window = convert_native_coords_to_toplevel (native_window,
9730 toplevel_x, toplevel_y,
9731 &toplevel_x, &toplevel_y);
9732 /* FIXME: which device? */
9733 pointer_window = get_pointer_window (display, toplevel_window, NULL,
9734 toplevel_x, toplevel_y, serial);
9735 event_win = get_extension_event_window (display,
9744 * gdk_window_create_similar_surface:
9745 * @window: window to make new surface similar to
9746 * @content: the content for the new surface
9747 * @width: width of the new surface
9748 * @height: height of the new surface
9750 * Create a new surface that is as compatible as possible with the
9751 * given @window. For example the new surface will have the same
9752 * fallback resolution and font options as @window. Generally, the new
9753 * surface will also use the same backend as @window, unless that is
9754 * not possible for some reason. The type of the returned surface may
9755 * be examined with cairo_surface_get_type().
9757 * Initially the surface contents are all 0 (transparent if contents
9758 * have transparency, black otherwise.)
9760 * Returns: a pointer to the newly allocated surface. The caller
9761 * owns the surface and should call cairo_surface_destroy() when done
9764 * This function always returns a valid pointer, but it will return a
9765 * pointer to a "nil" surface if @other is already in an error state
9766 * or any other error occurs.
9771 gdk_window_create_similar_surface (GdkWindow * window,
9772 cairo_content_t content,
9776 cairo_surface_t *window_surface, *surface;
9778 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9780 window_surface = _gdk_window_ref_cairo_surface (window);
9782 surface = cairo_surface_create_similar (window_surface,
9786 cairo_surface_destroy (window_surface);