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 #include "gdkrectangle.h"
35 #include "gdkinternals.h"
37 #include "gdkscreenprivate.h"
38 #include "gdkdisplayprivate.h"
39 #include "gdkdeviceprivate.h"
40 #include "gdkvisualprivate.h"
41 #include "gdkmarshalers.h"
42 #include "gdkwindowimpl.h"
46 #undef DEBUG_WINDOW_PRINTING
51 * @Short_description: Onscreen display areas in the target window system
54 * A #GdkWindow is a (usually) rectangular region on the screen.
55 * It's a low-level object, used to implement high-level objects such as
56 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
57 * window, the thing a user might think of as a "window" with a titlebar and
58 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
59 * #GtkButton has a #GdkWindow associated with it.
61 * <refsect2 id="COMPOSITED-WINDOWS">
62 * <title>Composited Windows</title>
64 * Normally, the windowing system takes care of rendering the contents of a
65 * child window onto its parent window. This mechanism can be intercepted by
66 * calling gdk_window_set_composited() on the child window. For a
67 * <firstterm>composited</firstterm> window it is the responsibility of the
68 * application to render the window contents at the right spot.
70 * <example id="composited-window-example">
71 * <title>Composited windows</title>
73 * <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>
74 * </programlisting></example>
76 * In the example <xref linkend="composited-window-example"/>, a button is
77 * placed inside of an event box inside of a window. The event box is set as
78 * composited and therefore is no longer automatically drawn to the screen.
80 * When the contents of the event box change, an expose event is generated on
81 * its parent window (which, in this case, belongs to the toplevel #GtkWindow).
82 * The expose handler for this widget is responsible for merging the changes
83 * back on the screen in the way that it wishes.
85 * In our case, we merge the contents with a 50% transparency. We also set the
86 * background colour of the window to red. The effect is that the background
87 * shows through the button.
90 * <refsect2 id="OFFSCREEN-WINDOWS">
91 * <title>Offscreen Windows</title>
93 * Offscreen windows are more general than composited windows, since they allow
94 * not only to modify the rendering of the child window onto its parent, but
95 * also to apply coordinate transformations.
97 * To integrate an offscreen window into a window hierarchy, one has to call
98 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
99 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
100 * select an offscreen child at given coordinates, and the
101 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
102 * offscreen window are used to translate coordinates between the embedder and
103 * the offscreen window.
105 * For rendering an offscreen window onto its embedder, the contents of the
106 * offscreen window are available as a surface, via
107 * gdk_offscreen_window_get_surface().
113 /* Historically a GdkWindow always matches a platform native window,
114 * be it a toplevel window or a child window. In this setup the
115 * GdkWindow (and other GdkDrawables) were platform independent classes,
116 * and the actual platform specific implementation was in a delegate
117 * object availible as "impl" in the window object.
119 * With the addition of client side windows and offscreen windows this
120 * changes a bit. The application-visible GdkWindow object behaves as
121 * it did before, but not all such windows now have a corresponding native
122 * window. Instead windows that are "client side" are emulated by the gdk
123 * code such that clipping, drawing, moving, events etc work as expected.
125 * For GdkWindows that have a native window the "impl" object is the
126 * same as before. However, for all client side windows the impl object
127 * is shared with its parent (i.e. all client windows descendants of one
128 * native window has the same impl.
130 * Additionally there is a new type of platform independent impl object,
131 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
132 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
133 * windows). Such windows work by allocating a #cairo_surface_t as the backing
134 * store for drawing operations, which is resized with the window.
136 * GdkWindows have a pointer to the "impl window" they are in, i.e.
137 * the topmost GdkWindow which have the same "impl" value. This is stored
138 * in impl_window, which is different from the window itself only for client
140 * All GdkWindows (native or not) track the position of the window in the parent
141 * (x, y), the size of the window (width, height), the position of the window
142 * with respect to the impl window (abs_x, abs_y). We also track the clip
143 * region of the window wrt parent windows and siblings, in window-relative
144 * coordinates with and without child windows included (clip_region,
145 * clip_region_with_children).
147 * All toplevel windows are native windows, but also child windows can be
148 * native (although not children of offscreens). We always listen to
149 * a basic set of events (see get_native_event_mask) for these windows
150 * so that we can emulate events for any client side children.
152 * For native windows we apply the calculated clip region as a window shape
153 * so that eg. client side siblings that overlap the native child properly
154 * draws over the native child window.
156 * In order to minimize flicker and for performance we use a couple of cacheing
157 * tricks. First of all, every time we do a window to window copy area, for instance
158 * when moving a client side window or when scrolling/moving a region in a window
159 * we store this in outstanding_moves instead of applying immediately. We then
160 * delay this move until we really need it (because something depends on being
161 * able to read it), or until we're handing a redraw from an expose/invalidation
162 * (actually we delay it past redraw, but before blitting the double buffer
163 * to the window). This gives us two advantages. First of all it minimizes the time
164 * from the window is moved to the exposes related to that move, secondly it allows
165 * us to be smart about how to do the copy. We combine multiple moves into one (when
166 * possible) and we don't actually do copies to anything that is or will be
167 * invalidated and exposed anyway.
169 * Secondly, we use something called a "implicit paint" during repaint handling.
170 * An implicit paint is similar to a regular paint for the paint stack, but it is
171 * not put on the stack. Instead, it is set on the impl window, and later when
172 * regular gdk_window_begin_paint_region() happen on a window of this impl window
173 * we reuse the surface from the implicit paint. During repaint we create and at the
174 * end flush an implicit paint, which means we can collect all the paints on
175 * multiple client side windows in the same backing store.
178 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
180 /* This adds a local value to the GdkVisibilityState enum */
181 #define GDK_VISIBILITY_NOT_VIEWABLE 3
184 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
198 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
202 struct _GdkWindowPaint
204 cairo_region_t *region;
205 cairo_surface_t *surface;
206 guint uses_implicit : 1;
211 cairo_region_t *dest_region; /* The destination region */
212 int dx, dy; /* The amount that the source was moved to reach dest_region */
213 } GdkWindowRegionMove;
217 static void gdk_window_drop_cairo_surface (GdkWindow *private);
219 static void gdk_window_free_paint_stack (GdkWindow *window);
221 static void gdk_window_finalize (GObject *object);
223 static void gdk_window_set_property (GObject *object,
227 static void gdk_window_get_property (GObject *object,
232 static void gdk_window_clear_backing_region (GdkWindow *window,
233 cairo_region_t *region);
235 static void recompute_visible_regions (GdkWindow *private,
236 gboolean recalculate_siblings,
237 gboolean recalculate_children);
238 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
239 static void gdk_window_flush_recursive (GdkWindow *window);
240 static void do_move_region_bits_on_impl (GdkWindow *window,
241 cairo_region_t *region, /* In impl window coords */
243 static void gdk_window_invalidate_in_parent (GdkWindow *private);
244 static void move_native_children (GdkWindow *private);
245 static void update_cursor (GdkDisplay *display,
247 static void impl_window_add_update_area (GdkWindow *impl_window,
248 cairo_region_t *region);
249 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
250 static void gdk_window_invalidate_region_full (GdkWindow *window,
251 const cairo_region_t *region,
252 gboolean invalidate_children,
254 static void gdk_window_invalidate_rect_full (GdkWindow *window,
255 const GdkRectangle *rect,
256 gboolean invalidate_children,
258 static void _gdk_window_propagate_has_alpha_background (GdkWindow *window);
260 static guint signals[LAST_SIGNAL] = { 0 };
262 static gpointer parent_class = NULL;
264 static const cairo_user_data_key_t gdk_window_cairo_key;
266 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
269 _gdk_paintable_get_type (void)
271 static GType paintable_type = 0;
275 const GTypeInfo paintable_info =
277 sizeof (GdkPaintableIface), /* class_size */
278 NULL, /* base_init */
279 NULL, /* base_finalize */
282 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
283 g_intern_static_string ("GdkPaintable"),
286 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
289 return paintable_type;
293 gdk_window_init (GdkWindow *window)
295 /* 0-initialization is good for all other fields. */
297 window->window_type = GDK_WINDOW_CHILD;
299 window->state = GDK_WINDOW_STATE_WITHDRAWN;
302 window->toplevel_window_type = -1;
304 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
305 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
306 /* Default to unobscured since some backends don't send visibility events */
307 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
309 window->device_cursor = g_hash_table_new_full (NULL, NULL,
310 NULL, g_object_unref);
313 /* Stop and return on the first non-NULL parent */
315 accumulate_get_window (GSignalInvocationHint *ihint,
317 const GValue *handler_return,
320 g_value_copy (handler_return, return_accu);
321 /* Continue while returning NULL */
322 return g_value_get_object (handler_return) == NULL;
326 create_surface_accumulator (GSignalInvocationHint *ihint,
328 const GValue *handler_return,
331 g_value_copy (handler_return, return_accu);
333 /* Stop on the first non-NULL return value */
334 return g_value_get_boxed (handler_return) == NULL;
337 static GQuark quark_pointer_window = 0;
340 gdk_window_class_init (GdkWindowClass *klass)
342 GObjectClass *object_class = G_OBJECT_CLASS (klass);
344 parent_class = g_type_class_peek_parent (klass);
346 object_class->finalize = gdk_window_finalize;
347 object_class->set_property = gdk_window_set_property;
348 object_class->get_property = gdk_window_get_property;
350 klass->create_surface = _gdk_offscreen_window_create_surface;
352 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
360 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
361 * gdk_window_get_cursor() for details.
365 g_object_class_install_property (object_class,
367 g_param_spec_object ("cursor",
374 * GdkWindow::pick-embedded-child:
375 * @window: the window on which the signal is emitted
376 * @x: x coordinate in the window
377 * @y: y coordinate in the window
379 * The ::pick-embedded-child signal is emitted to find an embedded
380 * child at the given position.
382 * Returns: (transfer none): the #GdkWindow of the embedded child at
387 signals[PICK_EMBEDDED_CHILD] =
388 g_signal_new (g_intern_static_string ("pick-embedded-child"),
389 G_OBJECT_CLASS_TYPE (object_class),
391 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
392 accumulate_get_window, NULL,
393 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
400 * GdkWindow::to-embedder:
401 * @window: the offscreen window on which the signal is emitted
402 * @offscreen-x: x coordinate in the offscreen window
403 * @offscreen-y: y coordinate in the offscreen window
404 * @embedder-x: (out) (type double): return location for the x
405 * coordinate in the embedder window
406 * @embedder-y: (out) (type double): return location for the y
407 * coordinate in the embedder window
409 * The ::to-embedder signal is emitted to translate coordinates
410 * in an offscreen window to its embedder.
412 * See also #GtkWindow::from-embedder.
416 signals[TO_EMBEDDER] =
417 g_signal_new (g_intern_static_string ("to-embedder"),
418 G_OBJECT_CLASS_TYPE (object_class),
420 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
422 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
431 * GdkWindow::from-embedder:
432 * @window: the offscreen window on which the signal is emitted
433 * @embedder-x: x coordinate in the embedder window
434 * @embedder-y: y coordinate in the embedder window
435 * @offscreen-x: (out) (type double): return location for the x
436 * coordinate in the offscreen window
437 * @offscreen-y: (out) (type double): return location for the y
438 * coordinate in the offscreen window
440 * The ::from-embedder signal is emitted to translate coordinates
441 * in the embedder of an offscreen window to the offscreen window.
443 * See also #GtkWindow::to-embedder.
447 signals[FROM_EMBEDDER] =
448 g_signal_new (g_intern_static_string ("from-embedder"),
449 G_OBJECT_CLASS_TYPE (object_class),
451 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
453 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
462 * GdkWindow::create-surface:
463 * @window: the offscreen window on which the signal is emitted
464 * @width: the width of the offscreen surface to create
465 * @height: the height of the offscreen surface to create
467 * The ::create-surface signal is emitted when an offscreen window
468 * needs its surface (re)created, which happens either when the the
469 * window is first drawn to, or when the window is being
470 * resized. The first signal handler that returns a non-%NULL
471 * surface will stop any further signal emission, and its surface
474 * Note that it is not possible to access the window's previous
475 * surface from within any callback of this signal. Calling
476 * gdk_offscreen_window_get_surface() will lead to a crash.
478 * Returns: the newly created #cairo_surface_t for the offscreen window
482 signals[CREATE_SURFACE] =
483 g_signal_new (g_intern_static_string ("create-surface"),
484 G_OBJECT_CLASS_TYPE (object_class),
486 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
487 create_surface_accumulator, NULL,
488 _gdk_marshal_BOXED__INT_INT,
489 CAIRO_GOBJECT_TYPE_SURFACE,
496 device_removed_cb (GdkDeviceManager *device_manager,
500 window->devices_inside = g_list_remove (window->devices_inside, device);
501 g_hash_table_remove (window->device_cursor, device);
503 if (window->device_events)
504 g_hash_table_remove (window->device_events, device);
508 gdk_window_finalize (GObject *object)
510 GdkWindow *window = GDK_WINDOW (object);
511 GdkDeviceManager *device_manager;
513 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
514 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
516 if (!GDK_WINDOW_DESTROYED (window))
518 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
520 g_warning ("losing last reference to undestroyed window\n");
521 _gdk_window_destroy (window, FALSE);
524 /* We use TRUE here, to keep us from actually calling
525 * XDestroyWindow() on the window
527 _gdk_window_destroy (window, TRUE);
530 gdk_window_drop_cairo_surface (window);
534 g_object_unref (window->impl);
538 if (window->impl_window != window)
540 g_object_unref (window->impl_window);
541 window->impl_window = NULL;
545 cairo_region_destroy (window->shape);
547 if (window->input_shape)
548 cairo_region_destroy (window->input_shape);
551 g_object_unref (window->cursor);
553 if (window->device_cursor)
554 g_hash_table_destroy (window->device_cursor);
556 if (window->device_events)
557 g_hash_table_destroy (window->device_events);
559 if (window->source_event_masks)
560 g_hash_table_destroy (window->source_event_masks);
562 if (window->devices_inside)
563 g_list_free (window->devices_inside);
565 G_OBJECT_CLASS (parent_class)->finalize (object);
569 gdk_window_set_property (GObject *object,
574 GdkWindow *window = (GdkWindow *)object;
579 gdk_window_set_cursor (window, g_value_get_object (value));
583 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
589 gdk_window_get_property (GObject *object,
594 GdkWindow *window = (GdkWindow *) object;
599 g_value_set_object (value, gdk_window_get_cursor (window));
603 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
609 gdk_window_is_offscreen (GdkWindow *window)
611 return window->window_type == GDK_WINDOW_OFFSCREEN;
615 gdk_window_get_impl_window (GdkWindow *window)
617 return window->impl_window;
621 _gdk_window_get_impl_window (GdkWindow *window)
623 return gdk_window_get_impl_window (window);
627 gdk_window_has_impl (GdkWindow *window)
629 return window->impl_window == window;
633 gdk_window_is_toplevel (GdkWindow *window)
636 window->parent == NULL ||
637 window->parent->window_type == GDK_WINDOW_ROOT;
641 _gdk_window_has_impl (GdkWindow *window)
643 return gdk_window_has_impl (window);
647 gdk_window_has_no_impl (GdkWindow *window)
649 return window->impl_window != window;
653 remove_child_area (GdkWindow *private,
656 cairo_region_t *region,
657 cairo_region_t *layered_region)
660 cairo_region_t *child_region;
663 cairo_region_t *shape;
665 for (l = private->children; l; l = l->next)
672 /* If region is empty already, no need to do
673 anything potentially costly */
674 if (cairo_region_is_empty (region))
677 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
680 /* Ignore offscreen children, as they don't draw in their parent and
681 * don't take part in the clipping */
682 if (gdk_window_is_offscreen (child))
687 r.width = child->width;
688 r.height = child->height;
690 /* Bail early if child totally outside region */
691 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
694 child_region = cairo_region_create_rectangle (&r);
698 /* Adjust shape region to parent window coords */
699 cairo_region_translate (child->shape, child->x, child->y);
700 cairo_region_intersect (child_region, child->shape);
701 cairo_region_translate (child->shape, -child->x, -child->y);
703 else if (private->window_type == GDK_WINDOW_FOREIGN)
705 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
708 cairo_region_intersect (child_region, shape);
709 cairo_region_destroy (shape);
715 if (child->input_shape)
716 cairo_region_intersect (child_region, child->input_shape);
717 else if (private->window_type == GDK_WINDOW_FOREIGN)
719 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
722 cairo_region_intersect (child_region, shape);
723 cairo_region_destroy (shape);
728 if (child->has_alpha_background)
730 if (layered_region != NULL)
731 cairo_region_union (layered_region, child_region);
734 cairo_region_subtract (region, child_region);
735 cairo_region_destroy (child_region);
740 static GdkVisibilityState
741 effective_visibility (GdkWindow *window)
743 GdkVisibilityState native;
745 if (!gdk_window_is_viewable (window))
746 return GDK_VISIBILITY_NOT_VIEWABLE;
748 native = window->impl_window->native_visibility;
750 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
751 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
752 return GDK_VISIBILITY_FULLY_OBSCURED;
753 else if (native == GDK_VISIBILITY_UNOBSCURED)
754 return window->visibility;
755 else /* native PARTIAL, private partial or unobscured */
756 return GDK_VISIBILITY_PARTIAL;
760 gdk_window_update_visibility (GdkWindow *window)
762 GdkVisibilityState new_visibility;
765 new_visibility = effective_visibility (window);
767 if (new_visibility != window->effective_visibility)
769 window->effective_visibility = new_visibility;
771 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
772 window->event_mask & GDK_VISIBILITY_NOTIFY)
774 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
776 event->visibility.state = new_visibility;
782 gdk_window_update_visibility_recursively (GdkWindow *window,
783 GdkWindow *only_for_impl)
788 gdk_window_update_visibility (window);
789 for (l = window->children; l != NULL; l = l->next)
792 if ((only_for_impl == NULL) ||
793 (only_for_impl == child->impl_window))
794 gdk_window_update_visibility_recursively (child, only_for_impl);
799 should_apply_clip_as_shape (GdkWindow *window)
802 gdk_window_has_impl (window) &&
803 /* Not for offscreens */
804 !gdk_window_is_offscreen (window) &&
805 /* or for toplevels */
806 !gdk_window_is_toplevel (window) &&
807 /* or for foreign windows */
808 window->window_type != GDK_WINDOW_FOREIGN &&
809 /* or for the root window */
810 window->window_type != GDK_WINDOW_ROOT;
814 apply_shape (GdkWindow *window,
815 cairo_region_t *region)
817 GdkWindowImplClass *impl_class;
819 /* We trash whether we applied a shape so that
820 we can avoid unsetting it many times, which
821 could happen in e.g. apply_clip_as_shape as
822 windows get resized */
823 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
825 impl_class->shape_combine_region (window,
827 else if (window->applied_shape)
828 impl_class->shape_combine_region (window,
831 window->applied_shape = region != NULL;
835 region_rect_equal (const cairo_region_t *region,
836 const GdkRectangle *rect)
838 GdkRectangle extents;
840 if (cairo_region_num_rectangles (region) != 1)
843 cairo_region_get_extents (region, &extents);
845 return extents.x == rect->x &&
846 extents.y == rect->y &&
847 extents.width == rect->width &&
848 extents.height == rect->height;
852 apply_clip_as_shape (GdkWindow *window)
857 r.width = window->width;
858 r.height = window->height;
860 /* We only apply the clip region if would differ
861 from the actual clip region implied by the size
862 of the window. This is to avoid unneccessarily
863 adding meaningless shapes to all native subwindows */
864 if (!region_rect_equal (window->clip_region, &r))
865 apply_shape (window, window->clip_region);
867 apply_shape (window, NULL);
871 recompute_visible_regions_internal (GdkWindow *private,
872 gboolean recalculate_clip,
873 gboolean recalculate_siblings,
874 gboolean recalculate_children)
879 cairo_region_t *new_clip, *new_layered;
880 gboolean clip_region_changed;
881 gboolean abs_pos_changed;
882 int old_abs_x, old_abs_y;
884 old_abs_x = private->abs_x;
885 old_abs_y = private->abs_y;
887 /* Update absolute position */
888 if (gdk_window_has_impl (private))
890 /* Native window starts here */
896 private->abs_x = private->parent->abs_x + private->x;
897 private->abs_y = private->parent->abs_y + private->y;
901 private->abs_x != old_abs_x ||
902 private->abs_y != old_abs_y;
904 /* Update clip region based on:
907 * siblings in parents above window
909 clip_region_changed = FALSE;
910 if (recalculate_clip)
912 new_layered = cairo_region_create ();
913 if (private->viewable)
915 /* Calculate visible region (sans children) in parent window coords */
918 r.width = private->width;
919 r.height = private->height;
920 new_clip = cairo_region_create_rectangle (&r);
922 if (!gdk_window_is_toplevel (private))
924 cairo_region_intersect (new_clip, private->parent->clip_region);
925 cairo_region_union (new_layered, private->parent->layered_region);
927 /* Remove all overlapping children from parent. */
928 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
931 /* Convert from parent coords to window coords */
932 cairo_region_translate (new_clip, -private->x, -private->y);
933 cairo_region_translate (new_layered, -private->x, -private->y);
936 cairo_region_intersect (new_clip, private->shape);
939 new_clip = cairo_region_create ();
941 cairo_region_intersect (new_layered, new_clip);
943 if (private->clip_region == NULL ||
944 !cairo_region_equal (private->clip_region, new_clip))
945 clip_region_changed = TRUE;
947 if (private->layered_region == NULL ||
948 !cairo_region_equal (private->layered_region, new_layered))
949 clip_region_changed = TRUE;
951 if (private->clip_region)
952 cairo_region_destroy (private->clip_region);
953 private->clip_region = new_clip;
955 if (private->layered_region != NULL)
956 cairo_region_destroy (private->layered_region);
957 private->layered_region = new_layered;
959 if (private->clip_region_with_children)
960 cairo_region_destroy (private->clip_region_with_children);
961 private->clip_region_with_children = cairo_region_copy (private->clip_region);
962 if (private->window_type != GDK_WINDOW_ROOT)
963 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
966 if (clip_region_changed)
968 GdkVisibilityState visibility;
969 gboolean fully_visible;
971 if (cairo_region_is_empty (private->clip_region))
972 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
977 fully_visible = cairo_region_equal (private->clip_region,
984 r.width = private->width;
985 r.height = private->height;
986 fully_visible = region_rect_equal (private->clip_region, &r);
990 visibility = GDK_VISIBILITY_UNOBSCURED;
992 visibility = GDK_VISIBILITY_PARTIAL;
995 if (private->visibility != visibility)
997 private->visibility = visibility;
998 gdk_window_update_visibility (private);
1002 /* Update all children, recursively (except for root, where children are not exact). */
1003 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1004 private->window_type != GDK_WINDOW_ROOT)
1006 for (l = private->children; l; l = l->next)
1009 /* Only recalculate clip if the the clip region changed, otherwise
1010 * there is no way the child clip region could change (its has not e.g. moved)
1011 * Except if recalculate_children is set to force child updates
1013 recompute_visible_regions_internal (child,
1014 recalculate_clip && (clip_region_changed || recalculate_children),
1019 if (clip_region_changed &&
1020 should_apply_clip_as_shape (private))
1021 apply_clip_as_shape (private);
1023 if (recalculate_siblings &&
1024 !gdk_window_is_toplevel (private))
1026 /* If we moved a child window in parent or changed the stacking order, then we
1027 * need to recompute the visible area of all the other children in the parent
1029 for (l = private->parent->children; l; l = l->next)
1033 if (child != private)
1034 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1037 /* We also need to recompute the _with_children clip for the parent */
1038 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1041 if (private->cairo_surface && gdk_window_has_impl (private))
1043 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1045 private->cairo_surface = iface->resize_cairo_surface (private,
1046 private->cairo_surface,
1050 else if (private->cairo_surface)
1051 gdk_window_drop_cairo_surface (private);
1054 /* Call this when private has changed in one or more of these ways:
1058 * stacking order of window changed
1061 * It will recalculate abs_x/y and the clip regions
1063 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1064 * for recalculate_siblings. (Mostly used internally for the recursion)
1066 * If a child window was removed (and you can't use that child for
1067 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1070 recompute_visible_regions (GdkWindow *private,
1071 gboolean recalculate_siblings,
1072 gboolean recalculate_children)
1074 recompute_visible_regions_internal (private,
1076 recalculate_siblings,
1077 recalculate_children);
1081 _gdk_window_update_size (GdkWindow *window)
1083 recompute_visible_regions (window, TRUE, FALSE);
1086 /* Find the native window that would be just above "child"
1087 * in the native stacking order if "child" was a native window
1088 * (it doesn't have to be native). If there is no such native
1089 * window inside this native parent then NULL is returned.
1090 * If child is NULL, find lowest native window in parent.
1093 find_native_sibling_above_helper (GdkWindow *parent,
1101 l = g_list_find (parent->children, child);
1102 g_assert (l != NULL); /* Better be a child of its parent... */
1103 l = l->prev; /* Start looking at the one above the child */
1106 l = g_list_last (parent->children);
1108 for (; l != NULL; l = l->prev)
1112 if (gdk_window_has_impl (w))
1115 g_assert (parent != w);
1116 w = find_native_sibling_above_helper (w, NULL);
1126 find_native_sibling_above (GdkWindow *parent,
1131 w = find_native_sibling_above_helper (parent, child);
1135 if (gdk_window_has_impl (parent))
1138 return find_native_sibling_above (parent->parent, parent);
1142 get_native_device_event_mask (GdkWindow *private,
1145 GdkEventMask event_mask;
1148 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1150 event_mask = private->event_mask;
1152 if (private->window_type == GDK_WINDOW_ROOT ||
1153 private->window_type == GDK_WINDOW_FOREIGN)
1159 /* Do whatever the app asks to, since the app
1160 * may be asking for weird things for native windows,
1161 * but don't use motion hints as that may affect non-native
1162 * child windows that don't want it. Also, we need to
1163 * set all the app-specified masks since they will be picked
1164 * up by any implicit grabs (i.e. if they were not set as
1165 * native we would not get the events we need). */
1166 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1168 /* We need thse for all native windows so we can
1169 emulate events on children: */
1172 GDK_VISIBILITY_NOTIFY_MASK |
1173 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1175 /* Additionally we select for pointer and button events
1176 * for toplevels as we need to get these to emulate
1177 * them for non-native subwindows. Even though we don't
1178 * select on them for all native windows we will get them
1179 * as the events are propagated out to the first window
1180 * that select for them.
1181 * Not selecting for button press on all windows is an
1182 * important thing, because in X only one client can do
1183 * so, and we don't want to unexpectedly prevent another
1184 * client from doing it.
1186 * We also need to do the same if the app selects for button presses
1187 * because then we will get implicit grabs for this window, and the
1188 * event mask used for that grab is based on the rest of the mask
1189 * for the window, but we might need more events than this window
1190 * lists due to some non-native child window.
1192 if (gdk_window_is_toplevel (private) ||
1193 mask & GDK_BUTTON_PRESS_MASK)
1195 GDK_POINTER_MOTION_MASK |
1196 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1204 get_native_grab_event_mask (GdkEventMask grab_mask)
1206 /* Similar to the above but for pointer events only */
1208 GDK_POINTER_MOTION_MASK |
1209 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1210 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1213 ~GDK_POINTER_MOTION_HINT_MASK);
1217 get_native_event_mask (GdkWindow *private)
1219 return get_native_device_event_mask (private, NULL);
1222 /* Puts the native window in the right order wrt the other native windows
1223 * in the hierarchy, given the position it has in the client side data.
1224 * This is useful if some operation changed the stacking order.
1225 * This calls assumes the native window is now topmost in its native parent.
1228 sync_native_window_stack_position (GdkWindow *window)
1231 GdkWindowImplClass *impl_class;
1232 GList listhead = {0};
1234 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1236 above = find_native_sibling_above (window->parent, window);
1239 listhead.data = window;
1240 impl_class->restack_under (above, &listhead);
1245 * gdk_window_new: (constructor)
1246 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1247 * the default root window for the default display.
1248 * @attributes: attributes of the new window
1249 * @attributes_mask: mask indicating which fields in @attributes are valid
1251 * Creates a new #GdkWindow using the attributes from
1252 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1253 * more details. Note: to use this on displays other than the default
1254 * display, @parent must be specified.
1256 * Return value: (transfer full): the new #GdkWindow
1259 gdk_window_new (GdkWindow *parent,
1260 GdkWindowAttr *attributes,
1261 gint attributes_mask)
1265 GdkDisplay *display;
1268 GdkEventMask event_mask;
1269 GdkWindow *real_parent;
1270 GdkDeviceManager *device_manager;
1272 g_return_val_if_fail (attributes != NULL, NULL);
1276 GDK_NOTE (MULTIHEAD,
1277 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1279 screen = gdk_screen_get_default ();
1280 parent = gdk_screen_get_root_window (screen);
1283 screen = gdk_window_get_screen (parent);
1285 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1287 if (GDK_WINDOW_DESTROYED (parent))
1289 g_warning ("gdk_window_new(): parent is destroyed\n");
1293 display = gdk_screen_get_display (screen);
1295 window = _gdk_display_create_window (display);
1297 /* Windows with a foreign parent are treated as if they are children
1298 * of the root window, except for actual creation.
1300 real_parent = parent;
1301 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1302 parent = gdk_screen_get_root_window (screen);
1304 window->parent = parent;
1306 window->accept_focus = TRUE;
1307 window->focus_on_map = TRUE;
1309 if (attributes_mask & GDK_WA_X)
1314 if (attributes_mask & GDK_WA_Y)
1321 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1322 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1324 if (attributes->wclass == GDK_INPUT_ONLY)
1326 /* Backwards compatiblity - we've always ignored
1327 * attributes->window_type for input-only windows
1330 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1331 window->window_type = GDK_WINDOW_TEMP;
1333 window->window_type = GDK_WINDOW_CHILD;
1336 window->window_type = attributes->window_type;
1339 switch (window->window_type)
1341 case GDK_WINDOW_TOPLEVEL:
1342 case GDK_WINDOW_TEMP:
1343 case GDK_WINDOW_OFFSCREEN:
1344 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1345 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1346 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1347 case GDK_WINDOW_CHILD:
1351 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1355 if (attributes_mask & GDK_WA_VISUAL)
1356 window->visual = attributes->visual;
1358 window->visual = gdk_screen_get_system_visual (screen);
1360 window->event_mask = attributes->event_mask;
1362 if (attributes->wclass == GDK_INPUT_OUTPUT)
1364 window->input_only = FALSE;
1365 window->depth = window->visual->depth;
1367 /* XXX: Cache this somehow? */
1368 window->background = cairo_pattern_create_rgb (0, 0, 0);
1373 window->input_only = TRUE;
1377 window->parent->children = g_list_prepend (window->parent->children, window);
1380 if (window->parent->window_type == GDK_WINDOW_ROOT)
1381 native = TRUE; /* Always use native windows for toplevels */
1382 else if (!window->input_only &&
1383 (attributes_mask & GDK_WA_VISUAL &&
1384 attributes->visual != gdk_window_get_visual (window->parent)))
1385 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1387 if (gdk_window_is_offscreen (window))
1389 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1390 window->impl_window = window;
1394 event_mask = get_native_event_mask (window);
1396 /* Create the impl */
1397 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1398 window->impl_window = window;
1400 /* This will put the native window topmost in the native parent, which may
1401 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1402 if (!_gdk_window_has_impl (real_parent))
1403 sync_native_window_stack_position (window);
1407 window->impl_window = g_object_ref (window->parent->impl_window);
1408 window->impl = g_object_ref (window->impl_window->impl);
1411 recompute_visible_regions (window, TRUE, FALSE);
1413 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1414 (attributes->cursor) :
1417 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1418 g_signal_connect (device_manager, "device-removed",
1419 G_CALLBACK (device_removed_cb), window);
1425 is_parent_of (GdkWindow *parent,
1436 w = gdk_window_get_parent (w);
1443 change_impl (GdkWindow *private,
1444 GdkWindow *impl_window,
1449 GdkWindowImpl *old_impl;
1450 GdkWindow *old_impl_window;
1452 old_impl = private->impl;
1453 old_impl_window = private->impl_window;
1454 if (private != impl_window)
1455 private->impl_window = g_object_ref (impl_window);
1457 private->impl_window = private;
1458 private->impl = g_object_ref (new);
1459 if (old_impl_window != private)
1460 g_object_unref (old_impl_window);
1461 g_object_unref (old_impl);
1463 for (l = private->children; l != NULL; l = l->next)
1467 if (child->impl == old_impl)
1468 change_impl (child, impl_window, new);
1473 reparent_to_impl (GdkWindow *private)
1478 GdkWindowImplClass *impl_class;
1480 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1482 /* Enumerate in reverse order so we get the right order for the native
1483 windows (first in childrens list is topmost, and reparent places on top) */
1484 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1488 if (child->impl == private->impl)
1489 reparent_to_impl (child);
1492 show = impl_class->reparent ((GdkWindow *)child,
1493 (GdkWindow *)private,
1494 child->x, child->y);
1496 gdk_window_show_unraised ((GdkWindow *)child);
1503 * gdk_window_reparent:
1504 * @window: a #GdkWindow
1505 * @new_parent: new parent to move @window into
1506 * @x: X location inside the new parent
1507 * @y: Y location inside the new parent
1509 * Reparents @window into the given @new_parent. The window being
1510 * reparented will be unmapped as a side effect.
1514 gdk_window_reparent (GdkWindow *window,
1515 GdkWindow *new_parent,
1519 GdkWindow *old_parent;
1521 gboolean show, was_mapped, applied_clip_as_shape;
1522 gboolean do_reparent_to_impl;
1523 GdkEventMask old_native_event_mask;
1524 GdkWindowImplClass *impl_class;
1526 g_return_if_fail (GDK_IS_WINDOW (window));
1527 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1528 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1530 if (GDK_WINDOW_DESTROYED (window) ||
1531 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1534 screen = gdk_window_get_screen (window);
1536 new_parent = gdk_screen_get_root_window (screen);
1538 /* No input-output children of input-only windows */
1539 if (new_parent->input_only && !window->input_only)
1542 /* Don't create loops in hierarchy */
1543 if (is_parent_of (window, new_parent))
1546 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1547 To make sure we're ok, just wipe it. */
1548 gdk_window_drop_cairo_surface (window);
1550 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1551 old_parent = window->parent;
1553 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1556 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1557 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1558 new_parent->window_type == GDK_WINDOW_FOREIGN)
1559 gdk_window_ensure_native (window);
1561 applied_clip_as_shape = should_apply_clip_as_shape (window);
1563 old_native_event_mask = 0;
1564 do_reparent_to_impl = FALSE;
1565 if (gdk_window_has_impl (window))
1567 old_native_event_mask = get_native_event_mask (window);
1569 show = impl_class->reparent (window, new_parent, x, y);
1573 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1574 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1575 new_parent->window_type != GDK_WINDOW_FOREIGN);
1578 gdk_window_hide (window);
1580 do_reparent_to_impl = TRUE;
1581 change_impl (window,
1582 new_parent->impl_window,
1586 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1589 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1591 new_parent = gdk_screen_get_root_window (screen);
1595 old_parent->children = g_list_remove (old_parent->children, window);
1597 window->parent = new_parent;
1601 new_parent->children = g_list_prepend (new_parent->children, window);
1603 /* Switch the window type as appropriate */
1605 switch (GDK_WINDOW_TYPE (new_parent))
1607 case GDK_WINDOW_ROOT:
1608 case GDK_WINDOW_FOREIGN:
1609 if (window->toplevel_window_type != -1)
1610 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1611 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1612 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1614 case GDK_WINDOW_OFFSCREEN:
1615 case GDK_WINDOW_TOPLEVEL:
1616 case GDK_WINDOW_CHILD:
1617 case GDK_WINDOW_TEMP:
1618 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1619 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1621 /* Save the original window type so we can restore it if the
1622 * window is reparented back to be a toplevel
1624 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1625 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1629 /* We might have changed window type for a native windows, so we
1630 need to change the event mask too. */
1631 if (gdk_window_has_impl (window))
1633 GdkEventMask native_event_mask = get_native_event_mask (window);
1635 if (native_event_mask != old_native_event_mask)
1636 impl_class->set_events (window, native_event_mask);
1639 _gdk_window_update_viewable (window);
1641 if (window->background == NULL)
1643 /* parent relative background, update has_alpha_background */
1644 if (window->parent == NULL ||
1645 window->parent->window_type == GDK_WINDOW_ROOT)
1646 window->has_alpha_background = FALSE;
1648 window->has_alpha_background = window->parent->has_alpha_background;
1651 recompute_visible_regions (window, TRUE, FALSE);
1652 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1653 recompute_visible_regions (old_parent, FALSE, TRUE);
1655 _gdk_window_propagate_has_alpha_background (window);
1657 /* We used to apply the clip as the shape, but no more.
1658 Reset this to the real shape */
1659 if (gdk_window_has_impl (window) &&
1660 applied_clip_as_shape &&
1661 !should_apply_clip_as_shape (window))
1662 apply_shape (window, window->shape);
1664 if (do_reparent_to_impl)
1665 reparent_to_impl (window);
1668 /* The reparent will have put the native window topmost in the native parent,
1669 * which may be wrong wrt other native windows in the non-native hierarchy,
1671 if (!gdk_window_has_impl (new_parent))
1672 sync_native_window_stack_position (window);
1676 gdk_window_show_unraised (window);
1678 _gdk_synthesize_crossing_events_for_geometry_change (window);
1682 * gdk_window_ensure_native:
1683 * @window: a #GdkWindow
1685 * Tries to ensure that there is a window-system native window for this
1686 * GdkWindow. This may fail in some situations, returning %FALSE.
1688 * Offscreen window and children of them can never have native windows.
1690 * Some backends may not support native child windows.
1692 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1697 gdk_window_ensure_native (GdkWindow *window)
1699 GdkWindow *impl_window;
1700 GdkWindowImpl *new_impl, *old_impl;
1701 GdkDisplay *display;
1705 GdkWindowImplClass *impl_class;
1707 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1709 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1710 GDK_WINDOW_DESTROYED (window))
1713 impl_window = gdk_window_get_impl_window (window);
1715 if (gdk_window_is_offscreen (impl_window))
1716 return FALSE; /* native in offscreens not supported */
1718 if (impl_window == window)
1719 /* Already has an impl, and its not offscreen . */
1722 /* Need to create a native window */
1724 gdk_window_drop_cairo_surface (window);
1726 screen = gdk_window_get_screen (window);
1727 display = gdk_screen_get_display (screen);
1729 old_impl = window->impl;
1730 _gdk_display_create_window_impl (display,
1731 window, window->parent,
1733 get_native_event_mask (window),
1735 new_impl = window->impl;
1737 window->impl = old_impl;
1738 change_impl (window, window, new_impl);
1740 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1742 /* Native window creation will put the native window topmost in the
1743 * native parent, which may be wrong wrt the position of the previous
1744 * non-native window wrt to the other non-native children, so correct this.
1746 above = find_native_sibling_above (window->parent, window);
1749 listhead.data = window;
1750 listhead.prev = NULL;
1751 listhead.next = NULL;
1752 impl_class->restack_under ((GdkWindow *)above, &listhead);
1755 recompute_visible_regions (window, FALSE, FALSE);
1757 /* The shape may not have been set, as the clip region doesn't actually
1758 change, so do it here manually */
1759 if (should_apply_clip_as_shape (window))
1760 apply_clip_as_shape (window);
1762 reparent_to_impl (window);
1764 if (!window->input_only)
1765 impl_class->set_background (window, window->background);
1767 impl_class->input_shape_combine_region (window,
1768 window->input_shape,
1771 if (gdk_window_is_viewable (window))
1772 impl_class->show (window, FALSE);
1778 * _gdk_event_filter_unref:
1779 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1780 * @filter: A window filter
1782 * Release a reference to @filter. Note this function may
1783 * mutate the list storage, so you need to handle this
1784 * if iterating over a list of filters.
1787 _gdk_event_filter_unref (GdkWindow *window,
1788 GdkEventFilter *filter)
1794 filters = &_gdk_default_filters;
1796 filters = &window->filters;
1798 tmp_list = *filters;
1801 GdkEventFilter *iter_filter = tmp_list->data;
1805 tmp_list = tmp_list->next;
1807 if (iter_filter != filter)
1810 g_assert (iter_filter->ref_count > 0);
1812 filter->ref_count--;
1813 if (filter->ref_count != 0)
1816 *filters = g_list_remove_link (*filters, node);
1818 g_list_free_1 (node);
1823 window_remove_filters (GdkWindow *window)
1825 while (window->filters)
1826 _gdk_event_filter_unref (window, window->filters->data);
1830 update_pointer_info_foreach (GdkDisplay *display,
1832 GdkPointerWindowInfo *pointer_info,
1835 GdkWindow *window = user_data;
1837 if (pointer_info->toplevel_under_pointer == window)
1839 g_object_unref (pointer_info->toplevel_under_pointer);
1840 pointer_info->toplevel_under_pointer = NULL;
1845 window_remove_from_pointer_info (GdkWindow *window,
1846 GdkDisplay *display)
1848 _gdk_display_pointer_info_foreach (display,
1849 update_pointer_info_foreach,
1854 * _gdk_window_destroy_hierarchy:
1855 * @window: a #GdkWindow
1856 * @recursing: If TRUE, then this is being called because a parent
1858 * @recursing_native: If TRUE, then this is being called because a native parent
1859 * was destroyed. This generally means that the call to the
1860 * windowing system to destroy the window can be omitted, since
1861 * it will be destroyed as a result of the parent being destroyed.
1862 * Unless @foreign_destroy.
1863 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1864 * external agency. The window has already been destroyed and no
1865 * windowing system calls should be made. (This may never happen
1866 * for some windowing systems.)
1868 * Internal function to destroy a window. Like gdk_window_destroy(),
1869 * but does not drop the reference count created by gdk_window_new().
1872 _gdk_window_destroy_hierarchy (GdkWindow *window,
1874 gboolean recursing_native,
1875 gboolean foreign_destroy)
1877 GdkWindowImplClass *impl_class;
1878 GdkWindow *temp_window;
1880 GdkDisplay *display;
1884 g_return_if_fail (GDK_IS_WINDOW (window));
1886 if (GDK_WINDOW_DESTROYED (window))
1889 display = gdk_window_get_display (window);
1890 screen = gdk_window_get_screen (window);
1891 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1892 if (temp_window == window)
1893 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1896 switch (window->window_type)
1898 case GDK_WINDOW_ROOT:
1899 if (!screen->closed)
1901 g_error ("attempted to destroy root window");
1904 /* else fall thru */
1905 case GDK_WINDOW_TOPLEVEL:
1906 case GDK_WINDOW_CHILD:
1907 case GDK_WINDOW_TEMP:
1908 case GDK_WINDOW_FOREIGN:
1909 case GDK_WINDOW_OFFSCREEN:
1910 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1912 /* Logically, it probably makes more sense to send
1913 * a "destroy yourself" message to the foreign window
1914 * whether or not it's in our hierarchy; but for historical
1915 * reasons, we only send "destroy yourself" messages to
1916 * foreign windows in our hierarchy.
1920 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1922 if (gdk_window_has_impl (window))
1923 impl_class->destroy_foreign (window);
1926 /* Also for historical reasons, we remove any filters
1927 * on a foreign window when it or a parent is destroyed;
1928 * this likely causes problems if two separate portions
1929 * of code are maintaining filter lists on a foreign window.
1931 window_remove_filters (window);
1937 if (window->parent->children)
1938 window->parent->children = g_list_remove (window->parent->children, window);
1941 GDK_WINDOW_IS_MAPPED (window))
1943 recompute_visible_regions (window, TRUE, FALSE);
1944 gdk_window_invalidate_in_parent (window);
1948 gdk_window_free_paint_stack (window);
1950 if (window->background)
1952 cairo_pattern_destroy (window->background);
1953 window->background = NULL;
1956 if (window->window_type == GDK_WINDOW_FOREIGN)
1957 g_assert (window->children == NULL);
1960 children = tmp = window->children;
1961 window->children = NULL;
1965 temp_window = tmp->data;
1969 _gdk_window_destroy_hierarchy (temp_window,
1971 recursing_native || gdk_window_has_impl (window),
1975 g_list_free (children);
1978 _gdk_window_clear_update_area (window);
1980 gdk_window_drop_cairo_surface (window);
1982 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1984 if (gdk_window_has_impl (window))
1985 impl_class->destroy (window, recursing_native,
1989 /* hide to make sure we repaint and break grabs */
1990 gdk_window_hide (window);
1993 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
1994 window->parent = NULL;
1995 window->destroyed = TRUE;
1997 window_remove_filters (window);
1999 window_remove_from_pointer_info (window, display);
2001 if (window->clip_region)
2003 cairo_region_destroy (window->clip_region);
2004 window->clip_region = NULL;
2007 if (window->clip_region_with_children)
2009 cairo_region_destroy (window->clip_region_with_children);
2010 window->clip_region_with_children = NULL;
2013 if (window->outstanding_moves)
2015 g_list_foreach (window->outstanding_moves, (GFunc)gdk_window_region_move_free, NULL);
2016 g_list_free (window->outstanding_moves);
2017 window->outstanding_moves = NULL;
2025 * _gdk_window_destroy:
2026 * @window: a #GdkWindow
2027 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2028 * external agency. The window has already been destroyed and no
2029 * windowing system calls should be made. (This may never happen
2030 * for some windowing systems.)
2032 * Internal function to destroy a window. Like gdk_window_destroy(),
2033 * but does not drop the reference count created by gdk_window_new().
2036 _gdk_window_destroy (GdkWindow *window,
2037 gboolean foreign_destroy)
2039 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2043 * gdk_window_destroy:
2044 * @window: a #GdkWindow
2046 * Destroys the window system resources associated with @window and decrements @window's
2047 * reference count. The window system resources for all children of @window are also
2048 * destroyed, but the children's reference counts are not decremented.
2050 * Note that a window will not be destroyed automatically when its reference count
2051 * reaches zero. You must call this function yourself before that happens.
2055 gdk_window_destroy (GdkWindow *window)
2057 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2058 g_object_unref (window);
2062 * gdk_window_set_user_data:
2063 * @window: a #GdkWindow
2064 * @user_data: (allow-none) (type GObject.Object): user data
2066 * For most purposes this function is deprecated in favor of
2067 * g_object_set_data(). However, for historical reasons GTK+ stores
2068 * the #GtkWidget that owns a #GdkWindow as user data on the
2069 * #GdkWindow. So, custom widget implementations should use
2070 * this function for that. If GTK+ receives an event for a #GdkWindow,
2071 * and the user data for the window is non-%NULL, GTK+ will assume the
2072 * user data is a #GtkWidget, and forward the event to that widget.
2076 gdk_window_set_user_data (GdkWindow *window,
2079 g_return_if_fail (GDK_IS_WINDOW (window));
2081 window->user_data = user_data;
2085 * gdk_window_get_user_data:
2086 * @window: a #GdkWindow
2087 * @data: (out): return location for user data
2089 * Retrieves the user data for @window, which is normally the widget
2090 * that @window belongs to. See gdk_window_set_user_data().
2094 gdk_window_get_user_data (GdkWindow *window,
2097 g_return_if_fail (GDK_IS_WINDOW (window));
2099 *data = window->user_data;
2103 * gdk_window_get_window_type:
2104 * @window: a #GdkWindow
2106 * Gets the type of the window. See #GdkWindowType.
2108 * Return value: type of window
2111 gdk_window_get_window_type (GdkWindow *window)
2113 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2115 return GDK_WINDOW_TYPE (window);
2119 * gdk_window_get_visual:
2120 * @window: a #GdkWindow
2122 * Gets the #GdkVisual describing the pixel format of @window.
2124 * Return value: (transfer none): a #GdkVisual
2129 gdk_window_get_visual (GdkWindow *window)
2131 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2133 return window->visual;
2137 * gdk_window_get_screen:
2138 * @window: a #GdkWindow
2140 * Gets the #GdkScreen associated with a #GdkWindow.
2142 * Return value: (transfer none): the #GdkScreen associated with @window
2147 gdk_window_get_screen (GdkWindow *window)
2149 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2151 return gdk_visual_get_screen (window->visual);
2155 * gdk_window_get_display:
2156 * @window: a #GdkWindow
2158 * Gets the #GdkDisplay associated with a #GdkWindow.
2160 * Return value: (transfer none): the #GdkDisplay associated with @window
2165 gdk_window_get_display (GdkWindow *window)
2167 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2169 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2172 * gdk_window_is_destroyed:
2173 * @window: a #GdkWindow
2175 * Check to see if a window is destroyed..
2177 * Return value: %TRUE if the window is destroyed
2182 gdk_window_is_destroyed (GdkWindow *window)
2184 return GDK_WINDOW_DESTROYED (window);
2188 to_embedder (GdkWindow *window,
2189 gdouble offscreen_x,
2190 gdouble offscreen_y,
2191 gdouble *embedder_x,
2192 gdouble *embedder_y)
2194 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2195 offscreen_x, offscreen_y,
2196 embedder_x, embedder_y);
2200 from_embedder (GdkWindow *window,
2203 gdouble *offscreen_x,
2204 gdouble *offscreen_y)
2206 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2207 embedder_x, embedder_y,
2208 offscreen_x, offscreen_y);
2212 * gdk_window_has_native:
2213 * @window: a #GdkWindow
2215 * Checks whether the window has a native window or not. Note that
2216 * you can use gdk_window_ensure_native() if a native window is needed.
2218 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2223 gdk_window_has_native (GdkWindow *window)
2225 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2227 return window->parent == NULL || window->parent->impl != window->impl;
2231 * gdk_window_get_position:
2232 * @window: a #GdkWindow
2233 * @x: (out) (allow-none): X coordinate of window
2234 * @y: (out) (allow-none): Y coordinate of window
2236 * Obtains the position of the window as reported in the
2237 * most-recently-processed #GdkEventConfigure. Contrast with
2238 * gdk_window_get_geometry() which queries the X server for the
2239 * current window position, regardless of which events have been
2240 * received or processed.
2242 * The position coordinates are relative to the window's parent window.
2246 gdk_window_get_position (GdkWindow *window,
2250 g_return_if_fail (GDK_IS_WINDOW (window));
2259 * gdk_window_get_parent:
2260 * @window: a #GdkWindow
2262 * Obtains the parent of @window, as known to GDK. Does not query the
2263 * X server; thus this returns the parent as passed to gdk_window_new(),
2264 * not the actual parent. This should never matter unless you're using
2265 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2266 * matter for toplevel windows, because the window manager may choose
2269 * Note that you should use gdk_window_get_effective_parent() when
2270 * writing generic code that walks up a window hierarchy, because
2271 * gdk_window_get_parent() will most likely not do what you expect if
2272 * there are offscreen windows in the hierarchy.
2274 * Return value: (transfer none): parent of @window
2277 gdk_window_get_parent (GdkWindow *window)
2279 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2281 return window->parent;
2285 * gdk_window_get_effective_parent:
2286 * @window: a #GdkWindow
2288 * Obtains the parent of @window, as known to GDK. Works like
2289 * gdk_window_get_parent() for normal windows, but returns the
2290 * window's embedder for offscreen windows.
2292 * See also: gdk_offscreen_window_get_embedder()
2294 * Return value: (transfer none): effective parent of @window
2299 gdk_window_get_effective_parent (GdkWindow *window)
2301 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2303 if (gdk_window_is_offscreen (window))
2304 return gdk_offscreen_window_get_embedder (window);
2306 return window->parent;
2310 * gdk_window_get_toplevel:
2311 * @window: a #GdkWindow
2313 * Gets the toplevel window that's an ancestor of @window.
2315 * Any window type but %GDK_WINDOW_CHILD is considered a
2316 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2317 * has a root window as parent.
2319 * Note that you should use gdk_window_get_effective_toplevel() when
2320 * you want to get to a window's toplevel as seen on screen, because
2321 * gdk_window_get_toplevel() will most likely not do what you expect
2322 * if there are offscreen windows in the hierarchy.
2324 * Return value: (transfer none): the toplevel window containing @window
2327 gdk_window_get_toplevel (GdkWindow *window)
2329 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2331 while (window->window_type == GDK_WINDOW_CHILD)
2333 if (gdk_window_is_toplevel (window))
2335 window = window->parent;
2342 * gdk_window_get_effective_toplevel:
2343 * @window: a #GdkWindow
2345 * Gets the toplevel window that's an ancestor of @window.
2347 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2348 * embedder as its parent, using gdk_window_get_effective_parent().
2350 * See also: gdk_offscreen_window_get_embedder()
2352 * Return value: (transfer none): the effective toplevel window containing @window
2357 gdk_window_get_effective_toplevel (GdkWindow *window)
2361 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2363 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2364 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2371 * gdk_window_get_children:
2372 * @window: a #GdkWindow
2374 * Gets the list of children of @window known to GDK.
2375 * This function only returns children created via GDK,
2376 * so for example it's useless when used with the root window;
2377 * it only returns windows an application created itself.
2379 * The returned list must be freed, but the elements in the
2382 * Return value: (transfer container) (element-type GdkWindow):
2383 * list of child windows inside @window
2386 gdk_window_get_children (GdkWindow *window)
2388 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2390 if (GDK_WINDOW_DESTROYED (window))
2393 return g_list_copy (window->children);
2397 * gdk_window_peek_children:
2398 * @window: a #GdkWindow
2400 * Like gdk_window_get_children(), but does not copy the list of
2401 * children, so the list does not need to be freed.
2403 * Return value: (transfer none) (element-type GdkWindow):
2404 * a reference to the list of child windows in @window
2407 gdk_window_peek_children (GdkWindow *window)
2409 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2411 if (GDK_WINDOW_DESTROYED (window))
2414 return window->children;
2418 * gdk_window_add_filter: (skip)
2419 * @window: (allow-none): a #GdkWindow
2420 * @function: filter callback
2421 * @data: data to pass to filter callback
2423 * Adds an event filter to @window, allowing you to intercept events
2424 * before they reach GDK. This is a low-level operation and makes it
2425 * easy to break GDK and/or GTK+, so you have to know what you're
2426 * doing. Pass %NULL for @window to get all events for all windows,
2427 * instead of events for a specific window.
2429 * If you are interested in X GenericEvents, bear in mind that
2430 * XGetEventData() has been already called on the event, and
2431 * XFreeEventData() must not be called within @function.
2434 gdk_window_add_filter (GdkWindow *window,
2435 GdkFilterFunc function,
2439 GdkEventFilter *filter;
2441 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2443 if (window && GDK_WINDOW_DESTROYED (window))
2446 /* Filters are for the native events on the native window, so
2447 ensure there is a native window. */
2449 gdk_window_ensure_native (window);
2452 tmp_list = window->filters;
2454 tmp_list = _gdk_default_filters;
2458 filter = (GdkEventFilter *)tmp_list->data;
2459 if ((filter->function == function) && (filter->data == data))
2461 filter->ref_count++;
2464 tmp_list = tmp_list->next;
2467 filter = g_new (GdkEventFilter, 1);
2468 filter->function = function;
2469 filter->data = data;
2470 filter->ref_count = 1;
2474 window->filters = g_list_append (window->filters, filter);
2476 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2480 * gdk_window_remove_filter: (skip)
2481 * @window: a #GdkWindow
2482 * @function: previously-added filter function
2483 * @data: user data for previously-added filter function
2485 * Remove a filter previously added with gdk_window_add_filter().
2488 gdk_window_remove_filter (GdkWindow *window,
2489 GdkFilterFunc function,
2493 GdkEventFilter *filter;
2495 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2498 tmp_list = window->filters;
2500 tmp_list = _gdk_default_filters;
2504 filter = (GdkEventFilter *)tmp_list->data;
2505 tmp_list = tmp_list->next;
2507 if ((filter->function == function) && (filter->data == data))
2509 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2511 _gdk_event_filter_unref (window, filter);
2519 * gdk_screen_get_toplevel_windows:
2520 * @screen: The #GdkScreen where the toplevels are located.
2522 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2523 * A toplevel window is a child of the root window (see
2524 * gdk_get_default_root_window()).
2526 * The returned list should be freed with g_list_free(), but
2527 * its elements need not be freed.
2529 * Return value: (transfer container) (element-type GdkWindow):
2530 * list of toplevel windows, free with g_list_free()
2535 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2537 GdkWindow * root_window;
2538 GList *new_list = NULL;
2541 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2543 root_window = gdk_screen_get_root_window (screen);
2545 tmp_list = root_window->children;
2548 GdkWindow *w = tmp_list->data;
2550 if (w->window_type != GDK_WINDOW_FOREIGN)
2551 new_list = g_list_prepend (new_list, w);
2552 tmp_list = tmp_list->next;
2559 * gdk_window_is_visible:
2560 * @window: a #GdkWindow
2562 * Checks whether the window has been mapped (with gdk_window_show() or
2563 * gdk_window_show_unraised()).
2565 * Return value: %TRUE if the window is mapped
2568 gdk_window_is_visible (GdkWindow *window)
2570 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2572 return GDK_WINDOW_IS_MAPPED (window);
2576 * gdk_window_is_viewable:
2577 * @window: a #GdkWindow
2579 * Check if the window and all ancestors of the window are
2580 * mapped. (This is not necessarily "viewable" in the X sense, since
2581 * we only check as far as we have GDK window parents, not to the root
2584 * Return value: %TRUE if the window is viewable
2587 gdk_window_is_viewable (GdkWindow *window)
2589 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2591 if (window->destroyed)
2594 return window->viewable;
2598 * gdk_window_get_state:
2599 * @window: a #GdkWindow
2601 * Gets the bitwise OR of the currently active window state flags,
2602 * from the #GdkWindowState enumeration.
2604 * Return value: window state bitfield
2607 gdk_window_get_state (GdkWindow *window)
2609 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2611 return window->state;
2614 static cairo_content_t
2615 gdk_window_get_content (GdkWindow *window)
2617 cairo_surface_t *surface;
2618 cairo_content_t content;
2620 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2622 surface = _gdk_window_ref_cairo_surface (window);
2623 content = cairo_surface_get_content (surface);
2624 cairo_surface_destroy (surface);
2629 /* This creates an empty "implicit" paint region for the impl window.
2630 * By itself this does nothing, but real paints to this window
2631 * or children of it can use this surface as backing to avoid allocating
2632 * multiple surfaces for subwindow rendering. When doing so they
2633 * add to the region of the implicit paint region, which will be
2634 * pushed to the window when the implicit paint region is ended.
2635 * Such paints should not copy anything to the window on paint end, but
2636 * should rely on the implicit paint end.
2637 * The implicit paint will be automatically ended if someone draws
2638 * directly to the window or a child window.
2641 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2643 GdkWindowPaint *paint;
2645 g_assert (gdk_window_has_impl (window));
2647 if (GDK_IS_PAINTABLE (window->impl))
2648 return FALSE; /* Implementation does double buffering */
2650 if (window->paint_stack != NULL ||
2651 window->implicit_paint != NULL)
2652 return FALSE; /* Don't stack implicit paints */
2654 /* Never do implicit paints for foreign windows, they don't need
2655 * double buffer combination since they have no client side children,
2656 * and creating surfaces for them is risky since they could disappear
2659 if (window->window_type == GDK_WINDOW_FOREIGN)
2662 paint = g_new (GdkWindowPaint, 1);
2663 paint->region = cairo_region_create (); /* Empty */
2664 paint->uses_implicit = FALSE;
2665 paint->flushed = FALSE;
2666 paint->surface = gdk_window_create_similar_surface (window,
2667 gdk_window_get_content (window),
2668 MAX (rect->width, 1),
2669 MAX (rect->height, 1));
2670 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2672 window->implicit_paint = paint;
2677 static cairo_surface_t *
2678 gdk_window_ref_impl_surface (GdkWindow *window)
2680 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2684 gdk_cairo_create_for_impl (GdkWindow *window)
2686 cairo_surface_t *surface;
2689 surface = gdk_window_ref_impl_surface (window);
2690 cr = cairo_create (surface);
2692 cairo_surface_destroy (surface);
2697 /* Ensure that all content related to this (sub)window is pushed to the
2698 native region. If there is an active paint then that area is not
2699 pushed, in order to not show partially finished double buffers. */
2701 gdk_window_flush_implicit_paint (GdkWindow *window)
2703 GdkWindow *impl_window;
2704 GdkWindowPaint *paint;
2705 cairo_region_t *region;
2708 impl_window = gdk_window_get_impl_window (window);
2709 if (impl_window->implicit_paint == NULL)
2712 paint = impl_window->implicit_paint;
2713 paint->flushed = TRUE;
2714 region = cairo_region_copy (window->clip_region_with_children);
2716 /* Don't flush active double buffers, as that may show partially done
2718 for (list = window->paint_stack; list != NULL; list = list->next)
2720 GdkWindowPaint *tmp_paint = list->data;
2722 cairo_region_subtract (region, tmp_paint->region);
2725 cairo_region_translate (region, -window->abs_x, -window->abs_y);
2726 cairo_region_intersect (region, paint->region);
2728 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2732 /* Remove flushed region from the implicit paint */
2733 cairo_region_subtract (paint->region, region);
2735 /* Some regions are valid, push these to window now */
2736 cr = gdk_cairo_create_for_impl (window);
2737 gdk_cairo_region (cr, region);
2739 cairo_set_source_surface (cr, paint->surface, 0, 0);
2740 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2745 cairo_region_destroy (region);
2748 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2750 gdk_window_end_implicit_paint (GdkWindow *window)
2752 GdkWindowPaint *paint;
2754 g_assert (gdk_window_has_impl (window));
2756 g_assert (window->implicit_paint != NULL);
2758 paint = window->implicit_paint;
2760 window->implicit_paint = NULL;
2762 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2766 /* Some regions are valid, push these to window now */
2767 cr = gdk_cairo_create_for_impl (window);
2768 gdk_cairo_region (cr, paint->region);
2770 cairo_set_source_surface (cr, paint->surface, 0, 0);
2771 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2776 cairo_region_destroy (paint->region);
2778 cairo_surface_destroy (paint->surface);
2783 * gdk_window_begin_paint_rect:
2784 * @window: a #GdkWindow
2785 * @rectangle: rectangle you intend to draw to
2787 * A convenience wrapper around gdk_window_begin_paint_region() which
2788 * creates a rectangular region for you. See
2789 * gdk_window_begin_paint_region() for details.
2793 gdk_window_begin_paint_rect (GdkWindow *window,
2794 const GdkRectangle *rectangle)
2796 cairo_region_t *region;
2798 g_return_if_fail (GDK_IS_WINDOW (window));
2800 region = cairo_region_create_rectangle (rectangle);
2801 gdk_window_begin_paint_region (window, region);
2802 cairo_region_destroy (region);
2806 * gdk_window_begin_paint_region:
2807 * @window: a #GdkWindow
2808 * @region: region you intend to draw to
2810 * Indicates that you are beginning the process of redrawing @region.
2811 * A backing store (offscreen buffer) large enough to contain @region
2812 * will be created. The backing store will be initialized with the
2813 * background color or background surface for @window. Then, all
2814 * drawing operations performed on @window will be diverted to the
2815 * backing store. When you call gdk_window_end_paint(), the backing
2816 * store will be copied to @window, making it visible onscreen. Only
2817 * the part of @window contained in @region will be modified; that is,
2818 * drawing operations are clipped to @region.
2820 * The net result of all this is to remove flicker, because the user
2821 * sees the finished product appear all at once when you call
2822 * gdk_window_end_paint(). If you draw to @window directly without
2823 * calling gdk_window_begin_paint_region(), the user may see flicker
2824 * as individual drawing operations are performed in sequence. The
2825 * clipping and background-initializing features of
2826 * gdk_window_begin_paint_region() are conveniences for the
2827 * programmer, so you can avoid doing that work yourself.
2829 * When using GTK+, the widget system automatically places calls to
2830 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2831 * emissions of the expose_event signal. That is, if you're writing an
2832 * expose event handler, you can assume that the exposed area in
2833 * #GdkEventExpose has already been cleared to the window background,
2834 * is already set as the clip region, and already has a backing store.
2835 * Therefore in most cases, application code need not call
2836 * gdk_window_begin_paint_region(). (You can disable the automatic
2837 * calls around expose events on a widget-by-widget basis by calling
2838 * gtk_widget_set_double_buffered().)
2840 * If you call this function multiple times before calling the
2841 * matching gdk_window_end_paint(), the backing stores are pushed onto
2842 * a stack. gdk_window_end_paint() copies the topmost backing store
2843 * onscreen, subtracts the topmost region from all other regions in
2844 * the stack, and pops the stack. All drawing operations affect only
2845 * the topmost backing store in the stack. One matching call to
2846 * gdk_window_end_paint() is required for each call to
2847 * gdk_window_begin_paint_region().
2851 gdk_window_begin_paint_region (GdkWindow *window,
2852 const cairo_region_t *region)
2854 #ifdef USE_BACKING_STORE
2855 GdkRectangle clip_box;
2856 GdkWindowPaint *paint, *implicit_paint;
2857 GdkWindow *impl_window;
2860 g_return_if_fail (GDK_IS_WINDOW (window));
2862 if (GDK_WINDOW_DESTROYED (window))
2865 if (GDK_IS_PAINTABLE (window->impl))
2867 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2869 if (iface->begin_paint_region)
2870 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2875 impl_window = gdk_window_get_impl_window (window);
2876 implicit_paint = impl_window->implicit_paint;
2878 paint = g_new (GdkWindowPaint, 1);
2879 paint->region = cairo_region_copy (region);
2881 cairo_region_intersect (paint->region, window->clip_region_with_children);
2882 cairo_region_get_extents (paint->region, &clip_box);
2884 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2886 /* Mark the region as valid on the implicit paint */
2889 cairo_region_union (implicit_paint->region, paint->region);
2891 /* Convert back to normal coords */
2892 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2896 paint->uses_implicit = TRUE;
2897 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2898 window->abs_x + clip_box.x,
2899 window->abs_y + clip_box.y,
2900 MAX (clip_box.width, 1),
2901 MAX (clip_box.height, 1));
2905 paint->uses_implicit = FALSE;
2906 paint->surface = gdk_window_create_similar_surface (window,
2907 gdk_window_get_content (window),
2908 MAX (clip_box.width, 1),
2909 MAX (clip_box.height, 1));
2911 /* Normally alpha backgrounded client side windows are composited on the implicit paint
2912 by being drawn in back to front order. However, if implicit paints are not used, for
2913 instance if it was flushed due to a non-double-buffered paint in the middle of the
2914 expose we need to copy in the existing data here. */
2915 if (!gdk_window_has_impl (window) && window->has_alpha_background)
2917 cairo_t *cr = cairo_create (paint->surface);
2918 gdk_cairo_set_source_window (cr, impl_window,
2919 - (window->abs_x + clip_box.x),
2920 - (window->abs_y + clip_box.y));
2925 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
2927 for (list = window->paint_stack; list != NULL; list = list->next)
2929 GdkWindowPaint *tmp_paint = list->data;
2931 cairo_region_subtract (tmp_paint->region, paint->region);
2934 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
2936 if (!cairo_region_is_empty (paint->region))
2938 gdk_window_clear_backing_region (window,
2942 #endif /* USE_BACKING_STORE */
2946 * gdk_window_end_paint:
2947 * @window: a #GdkWindow
2949 * Indicates that the backing store created by the most recent call to
2950 * gdk_window_begin_paint_region() should be copied onscreen and
2951 * deleted, leaving the next-most-recent backing store or no backing
2952 * store at all as the active paint region. See
2953 * gdk_window_begin_paint_region() for full details. It is an error to
2954 * call this function without a matching
2955 * gdk_window_begin_paint_region() first.
2959 gdk_window_end_paint (GdkWindow *window)
2961 #ifdef USE_BACKING_STORE
2962 GdkWindow *composited;
2963 GdkWindowPaint *paint;
2964 GdkRectangle clip_box;
2965 cairo_region_t *full_clip;
2967 g_return_if_fail (GDK_IS_WINDOW (window));
2969 if (GDK_WINDOW_DESTROYED (window))
2972 if (GDK_IS_PAINTABLE (window->impl))
2974 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2976 if (iface->end_paint)
2977 iface->end_paint ((GdkPaintable*)window->impl);
2981 if (window->paint_stack == NULL)
2983 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
2987 paint = window->paint_stack->data;
2989 window->paint_stack = g_slist_delete_link (window->paint_stack,
2990 window->paint_stack);
2992 cairo_region_get_extents (paint->region, &clip_box);
2994 if (!paint->uses_implicit)
2998 gdk_window_flush_outstanding_moves (window);
3000 full_clip = cairo_region_copy (window->clip_region_with_children);
3001 cairo_region_intersect (full_clip, paint->region);
3003 cr = gdk_cairo_create (window);
3004 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3005 cairo_set_source_surface (cr, paint->surface, 0, 0);
3006 gdk_cairo_region (cr, full_clip);
3010 cairo_region_destroy (full_clip);
3013 cairo_surface_destroy (paint->surface);
3014 cairo_region_destroy (paint->region);
3017 /* find a composited window in our hierarchy to signal its
3018 * parent to redraw, calculating the clip box as we go...
3020 * stop if parent becomes NULL since then we'd have nowhere
3021 * to draw (ie: 'composited' will always be non-NULL here).
3023 for (composited = window;
3025 composited = composited->parent)
3027 clip_box.x += composited->x;
3028 clip_box.y += composited->y;
3029 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3030 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3032 if (composited->composited)
3034 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3039 #endif /* USE_BACKING_STORE */
3043 gdk_window_free_paint_stack (GdkWindow *window)
3045 if (window->paint_stack)
3047 GSList *tmp_list = window->paint_stack;
3051 GdkWindowPaint *paint = tmp_list->data;
3053 if (tmp_list == window->paint_stack)
3054 cairo_surface_destroy (paint->surface);
3056 cairo_region_destroy (paint->region);
3059 tmp_list = tmp_list->next;
3062 g_slist_free (window->paint_stack);
3063 window->paint_stack = NULL;
3068 do_move_region_bits_on_impl (GdkWindow *impl_window,
3069 cairo_region_t *dest_region, /* In impl window coords */
3072 GdkWindowImplClass *impl_class;
3074 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3076 impl_class->translate (impl_window, dest_region, dx, dy);
3079 static GdkWindowRegionMove *
3080 gdk_window_region_move_new (cairo_region_t *region,
3083 GdkWindowRegionMove *move;
3085 move = g_slice_new (GdkWindowRegionMove);
3086 move->dest_region = cairo_region_copy (region);
3094 gdk_window_region_move_free (GdkWindowRegionMove *move)
3096 cairo_region_destroy (move->dest_region);
3097 g_slice_free (GdkWindowRegionMove, move);
3101 append_move_region (GdkWindow *impl_window,
3102 cairo_region_t *new_dest_region,
3105 GdkWindowRegionMove *move, *old_move;
3106 cairo_region_t *new_total_region, *old_total_region;
3107 cairo_region_t *source_overlaps_destination;
3108 cairo_region_t *non_overwritten;
3109 gboolean added_move;
3112 if (cairo_region_is_empty (new_dest_region))
3115 /* In principle this could just append the move to the list of outstanding
3116 moves that will be replayed before drawing anything when we're handling
3117 exposes. However, we'd like to do a bit better since its commonly the case
3118 that we get multiple copies where A is copied to B and then B is copied
3119 to C, and we'd like to express this as a simple copy A to C operation. */
3121 /* We approach this by taking the new move and pushing it ahead of moves
3122 starting at the end of the list and stopping when its not safe to do so.
3123 It's not safe to push past a move if either the source of the new move
3124 is in the destination of the old move, or if the destination of the new
3125 move is in the source of the new move, or if the destination of the new
3126 move overlaps the destination of the old move. We simplify this by
3127 just comparing the total regions (src + dest) */
3128 new_total_region = cairo_region_copy (new_dest_region);
3129 cairo_region_translate (new_total_region, -dx, -dy);
3130 cairo_region_union (new_total_region, new_dest_region);
3133 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3138 old_total_region = cairo_region_copy (old_move->dest_region);
3139 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3140 cairo_region_union (old_total_region, old_move->dest_region);
3142 cairo_region_intersect (old_total_region, new_total_region);
3143 /* If these regions intersect then its not safe to push the
3144 new region before the old one */
3145 if (!cairo_region_is_empty (old_total_region))
3147 /* The area where the new moves source overlaps the old ones
3149 source_overlaps_destination = cairo_region_copy (new_dest_region);
3150 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3151 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3152 cairo_region_translate (source_overlaps_destination, dx, dy);
3154 /* We can do all sort of optimizations here, but to do things safely it becomes
3155 quite complicated. However, a very common case is that you copy something first,
3156 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3157 in the same direction). We'd like to detect this case and optimize it to one
3159 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3161 /* This means we might be able to replace the old move and the new one
3162 with the new one read from the old ones source, and a second copy of
3163 the non-overwritten parts of the old move. However, such a split
3164 is only valid if the source in the old move isn't overwritten
3165 by the destination of the new one */
3167 /* the new destination of old move if split is ok: */
3168 non_overwritten = cairo_region_copy (old_move->dest_region);
3169 cairo_region_subtract (non_overwritten, new_dest_region);
3170 /* move to source region */
3171 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3173 cairo_region_intersect (non_overwritten, new_dest_region);
3174 if (cairo_region_is_empty (non_overwritten))
3177 move = gdk_window_region_move_new (new_dest_region,
3181 impl_window->outstanding_moves =
3182 g_list_insert_before (impl_window->outstanding_moves,
3184 cairo_region_subtract (old_move->dest_region, new_dest_region);
3186 cairo_region_destroy (non_overwritten);
3189 cairo_region_destroy (source_overlaps_destination);
3190 cairo_region_destroy (old_total_region);
3193 cairo_region_destroy (old_total_region);
3196 cairo_region_destroy (new_total_region);
3200 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3203 impl_window->outstanding_moves =
3204 g_list_prepend (impl_window->outstanding_moves,
3207 impl_window->outstanding_moves =
3208 g_list_insert_before (impl_window->outstanding_moves,
3213 /* Moves bits and update area by dx/dy in impl window.
3214 Takes ownership of region to avoid copy (because we may change it) */
3216 move_region_on_impl (GdkWindow *impl_window,
3217 cairo_region_t *region, /* In impl window coords */
3220 if ((dx == 0 && dy == 0) ||
3221 cairo_region_is_empty (region))
3223 cairo_region_destroy (region);
3227 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3229 /* Move any old invalid regions in the copy source area by dx/dy */
3230 if (impl_window->update_area)
3232 cairo_region_t *update_area;
3234 update_area = cairo_region_copy (region);
3236 /* Convert from target to source */
3237 cairo_region_translate (update_area, -dx, -dy);
3238 cairo_region_intersect (update_area, impl_window->update_area);
3239 /* We only copy the area, so keep the old update area invalid.
3240 It would be safe to remove it too, as code that uses
3241 move_region_on_impl generally also invalidate the source
3242 area. However, it would just use waste cycles. */
3245 cairo_region_translate (update_area, dx, dy);
3246 cairo_region_union (impl_window->update_area, update_area);
3248 /* This area of the destination is now invalid,
3249 so no need to copy to it. */
3250 cairo_region_subtract (region, update_area);
3252 cairo_region_destroy (update_area);
3255 /* If we're currently exposing this window, don't copy to this
3256 destination, as it will be overdrawn when the expose is done,
3257 instead invalidate it and repaint later. */
3258 if (impl_window->implicit_paint)
3260 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3261 cairo_region_t *exposing;
3263 exposing = cairo_region_copy (implicit_paint->region);
3264 cairo_region_intersect (exposing, region);
3265 cairo_region_subtract (region, exposing);
3267 impl_window_add_update_area (impl_window, exposing);
3268 cairo_region_destroy (exposing);
3271 append_move_region (impl_window, region, dx, dy);
3273 cairo_region_destroy (region);
3276 /* Flushes all outstanding changes to the window, call this
3277 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3280 gdk_window_flush_outstanding_moves (GdkWindow *window)
3282 GdkWindow *impl_window;
3283 GList *l, *outstanding;
3284 GdkWindowRegionMove *move;
3286 impl_window = gdk_window_get_impl_window (window);
3287 outstanding = impl_window->outstanding_moves;
3288 impl_window->outstanding_moves = NULL;
3290 for (l = outstanding; l != NULL; l = l->next)
3294 do_move_region_bits_on_impl (impl_window,
3295 move->dest_region, move->dx, move->dy);
3297 gdk_window_region_move_free (move);
3300 g_list_free (outstanding);
3305 * @window: a #GdkWindow
3307 * Flush all outstanding cached operations on a window, leaving the
3308 * window in a state which reflects all that has been drawn before.
3310 * Gdk uses multiple kinds of caching to get better performance and
3311 * nicer drawing. For instance, during exposes all paints to a window
3312 * using double buffered rendering are keep on a surface until the last
3313 * window has been exposed. It also delays window moves/scrolls until
3314 * as long as possible until next update to avoid tearing when moving
3317 * Normally this should be completely invisible to applications, as
3318 * we automatically flush the windows when required, but this might
3319 * be needed if you for instance mix direct native drawing with
3320 * gdk drawing. For Gtk widgets that don't use double buffering this
3321 * will be called automatically before sending the expose event.
3326 gdk_window_flush (GdkWindow *window)
3328 gdk_window_flush_outstanding_moves (window);
3329 gdk_window_flush_implicit_paint (window);
3332 /* If we're about to move/resize or otherwise change the
3333 * hierarchy of a client side window in an impl and we're
3334 * called from an expose event handler then we need to
3335 * flush any already painted parts of the implicit paint
3336 * that are not part of the current paint, as these may
3337 * be used when scrolling or may overdraw the changes
3338 * caused by the hierarchy change.
3341 gdk_window_flush_if_exposing (GdkWindow *window)
3343 GdkWindow *impl_window;
3345 impl_window = gdk_window_get_impl_window (window);
3347 /* If we're in an implicit paint (i.e. in an expose handler, flush
3348 all the already finished exposes to get things to an uptodate state. */
3349 if (impl_window->implicit_paint)
3350 gdk_window_flush (window);
3355 gdk_window_flush_recursive_helper (GdkWindow *window,
3356 GdkWindowImpl *impl)
3361 for (l = window->children; l != NULL; l = l->next)
3365 if (child->impl == impl)
3366 /* Same impl, ignore */
3367 gdk_window_flush_recursive_helper (child, impl);
3369 gdk_window_flush_recursive (child);
3374 gdk_window_flush_recursive (GdkWindow *window)
3376 gdk_window_flush (window);
3377 gdk_window_flush_recursive_helper (window, window->impl);
3381 * gdk_window_get_clip_region:
3382 * @window: a #GdkWindow
3384 * Computes the region of a window that potentially can be written
3385 * to by drawing primitives. This region may not take into account
3386 * other factors such as if the window is obscured by other windows,
3387 * but no area outside of this region will be affected by drawing
3390 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3391 * when you are done.
3394 gdk_window_get_clip_region (GdkWindow *window)
3396 cairo_region_t *result;
3398 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3400 result = cairo_region_copy (window->clip_region);
3402 if (window->paint_stack)
3404 cairo_region_t *paint_region = cairo_region_create ();
3405 GSList *tmp_list = window->paint_stack;
3409 GdkWindowPaint *paint = tmp_list->data;
3411 cairo_region_union (paint_region, paint->region);
3413 tmp_list = tmp_list->next;
3416 cairo_region_intersect (result, paint_region);
3417 cairo_region_destroy (paint_region);
3424 * gdk_window_get_visible_region:
3425 * @window: a #GdkWindow
3427 * Computes the region of the @window that is potentially visible.
3428 * This does not necessarily take into account if the window is
3429 * obscured by other windows, but no area outside of this region
3432 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3433 * when you are done.
3436 gdk_window_get_visible_region (GdkWindow *window)
3438 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3440 return cairo_region_copy (window->clip_region);
3444 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint, int x_offset_cairo, int y_offset_cairo)
3446 GdkWindow *bg_window;
3447 cairo_pattern_t *pattern = NULL;
3448 int x_offset = 0, y_offset = 0;
3451 cr = cairo_create (paint->surface);
3453 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3455 pattern = gdk_window_get_background_pattern (bg_window);
3459 x_offset += bg_window->x;
3460 y_offset += bg_window->y;
3465 cairo_translate (cr, -x_offset, -y_offset);
3466 cairo_set_source (cr, pattern);
3467 cairo_translate (cr, x_offset, y_offset);
3470 cairo_set_source_rgb (cr, 0, 0, 0);
3476 gdk_window_clear_backing_region (GdkWindow *window,
3477 cairo_region_t *region)
3479 GdkWindowPaint *paint = window->paint_stack->data;
3480 cairo_region_t *clip;
3481 GdkRectangle clipbox;
3484 if (GDK_WINDOW_DESTROYED (window))
3487 cr = setup_backing_rect (window, paint, 0, 0);
3489 clip = cairo_region_copy (paint->region);
3490 cairo_region_intersect (clip, region);
3491 cairo_region_get_extents (clip, &clipbox);
3493 gdk_cairo_region (cr, clip);
3498 cairo_region_destroy (clip);
3502 gdk_window_clear_backing_region_direct (GdkWindow *window,
3503 cairo_region_t *region)
3505 GdkWindowPaint paint;
3506 cairo_region_t *clip;
3507 GdkRectangle clipbox;
3510 if (GDK_WINDOW_DESTROYED (window))
3513 paint.surface = _gdk_window_ref_cairo_surface (window);
3515 cr = setup_backing_rect (window, &paint, 0, 0);
3517 clip = cairo_region_copy (window->clip_region_with_children);
3518 cairo_region_intersect (clip, region);
3519 cairo_region_get_extents (clip, &clipbox);
3521 gdk_cairo_region (cr, clip);
3526 cairo_region_destroy (clip);
3527 cairo_surface_destroy (paint.surface);
3532 gdk_window_clear_region_internal (GdkWindow *window,
3533 cairo_region_t *region)
3535 if (window->paint_stack)
3536 gdk_window_clear_backing_region (window, region);
3538 gdk_window_clear_backing_region_direct (window, region);
3542 gdk_window_drop_cairo_surface (GdkWindow *window)
3544 if (window->cairo_surface)
3546 cairo_surface_finish (window->cairo_surface);
3547 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3549 window->cairo_surface = NULL;
3554 gdk_window_cairo_surface_destroy (void *data)
3556 GdkWindow *window = data;
3558 window->cairo_surface = NULL;
3561 static cairo_surface_t *
3562 gdk_window_create_cairo_surface (GdkWindow *window,
3566 cairo_surface_t *surface, *subsurface;
3568 surface = gdk_window_ref_impl_surface (window);
3569 if (gdk_window_has_impl (window))
3572 subsurface = cairo_surface_create_for_rectangle (surface,
3577 cairo_surface_destroy (surface);
3583 _gdk_window_ref_cairo_surface (GdkWindow *window)
3585 cairo_surface_t *surface;
3587 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3589 if (window->paint_stack)
3591 GdkWindowPaint *paint = window->paint_stack->data;
3593 surface = paint->surface;
3594 cairo_surface_reference (surface);
3599 /* This will be drawing directly to the window, so flush implicit paint */
3600 gdk_window_flush (window);
3602 if (!window->cairo_surface)
3604 window->cairo_surface = gdk_window_create_cairo_surface (window,
3608 if (window->cairo_surface)
3610 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3611 window, gdk_window_cairo_surface_destroy);
3615 cairo_surface_reference (window->cairo_surface);
3617 surface = window->cairo_surface;
3625 * @window: a #GdkWindow
3627 * Creates a Cairo context for drawing to @window.
3630 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3631 * produce undefined results, so avoid it at all costs.
3634 * Return value: A newly created Cairo context. Free with
3635 * cairo_destroy() when you are done drawing.
3640 gdk_cairo_create (GdkWindow *window)
3642 cairo_surface_t *surface;
3645 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3647 surface = _gdk_window_ref_cairo_surface (window);
3648 cr = cairo_create (surface);
3650 if (!window->paint_stack)
3652 gdk_cairo_region (cr, window->clip_region_with_children);
3657 GdkWindowPaint *paint = window->paint_stack->data;
3659 /* Only needs to clip to region if piggybacking
3660 on an implicit paint */
3661 if (paint->uses_implicit)
3663 gdk_cairo_region (cr, paint->region);
3668 cairo_surface_destroy (surface);
3673 /* Code for dirty-region queueing
3675 static GSList *update_windows = NULL;
3676 static guint update_idle = 0;
3677 static gboolean debug_updates = FALSE;
3679 static inline gboolean
3680 gdk_window_is_ancestor (GdkWindow *window,
3681 GdkWindow *ancestor)
3685 GdkWindow *parent = window->parent;
3687 if (parent == ancestor)
3697 gdk_window_add_update_window (GdkWindow *window)
3700 GSList *prev = NULL;
3701 gboolean has_ancestor_in_list = FALSE;
3703 for (tmp = update_windows; tmp; tmp = tmp->next)
3705 GdkWindow *parent = window->parent;
3707 /* check if tmp is an ancestor of "window"; if it is, set a
3708 * flag indicating that all following windows are either
3709 * children of "window" or from a differen hierarchy
3711 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3712 has_ancestor_in_list = TRUE;
3714 /* insert in reverse stacking order when adding around siblings,
3715 * so processing updates properly paints over lower stacked windows
3717 if (parent == GDK_WINDOW (tmp->data)->parent)
3719 gint index = g_list_index (parent->children, window);
3720 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3722 gint sibling_index = g_list_index (parent->children, tmp->data);
3723 if (index > sibling_index)
3727 /* here, tmp got advanced past all lower stacked siblings */
3728 tmp = g_slist_prepend (tmp, window);
3732 update_windows = tmp;
3736 /* if "window" has an ancestor in the list and tmp is one of
3737 * "window's" children, insert "window" before tmp
3739 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3741 tmp = g_slist_prepend (tmp, window);
3746 update_windows = tmp;
3750 /* if we're at the end of the list and had an ancestor it it,
3751 * append to the list
3753 if (! tmp->next && has_ancestor_in_list)
3755 tmp = g_slist_append (tmp, window);
3762 /* if all above checks failed ("window" is from a different
3763 * hierarchy than what is already in the list) or the list is
3766 update_windows = g_slist_prepend (update_windows, window);
3770 gdk_window_remove_update_window (GdkWindow *window)
3772 update_windows = g_slist_remove (update_windows, window);
3776 gdk_window_update_idle (gpointer data)
3778 gdk_window_process_all_updates ();
3784 gdk_window_is_toplevel_frozen (GdkWindow *window)
3786 GdkWindow *toplevel;
3788 toplevel = gdk_window_get_toplevel (window);
3790 return toplevel->update_and_descendants_freeze_count > 0;
3794 gdk_window_schedule_update (GdkWindow *window)
3797 (window->update_freeze_count ||
3798 gdk_window_is_toplevel_frozen (window)))
3803 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3804 gdk_window_update_idle,
3809 _gdk_window_process_updates_recurse (GdkWindow *window,
3810 cairo_region_t *expose_region)
3813 cairo_region_t *clipped_expose_region;
3814 GList *l, *children;
3816 if (cairo_region_is_empty (expose_region))
3819 if (gdk_window_is_offscreen (window->impl_window) &&
3820 window == window->impl_window)
3821 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3824 /* Paint the window before the children, clipped to the window region
3825 with visible child windows removed */
3826 clipped_expose_region = cairo_region_copy (expose_region);
3827 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3829 if (!cairo_region_is_empty (clipped_expose_region) &&
3832 if (window->event_mask & GDK_EXPOSURE_MASK)
3836 event.expose.type = GDK_EXPOSE;
3837 event.expose.window = g_object_ref (window);
3838 event.expose.send_event = FALSE;
3839 event.expose.count = 0;
3840 event.expose.region = clipped_expose_region;
3841 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
3843 _gdk_event_emit (&event);
3845 g_object_unref (window);
3847 else if (window->window_type != GDK_WINDOW_FOREIGN)
3849 /* No exposure mask set, so nothing will be drawn, the
3850 * app relies on the background being what it specified
3851 * for the window. So, we need to clear this manually.
3853 * For foreign windows if expose is not set that generally
3854 * means some other client paints them, so don't clear
3857 * We use begin/end_paint around the clear so that we can
3858 * piggyback on the implicit paint */
3860 gdk_window_begin_paint_region (window, clipped_expose_region);
3861 gdk_window_clear_region_internal (window, clipped_expose_region);
3862 gdk_window_end_paint (window);
3865 cairo_region_destroy (clipped_expose_region);
3867 /* Make this reentrancy safe for expose handlers freeing windows */
3868 children = g_list_copy (window->children);
3869 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3871 /* Iterate over children, starting at bottommost */
3872 for (l = g_list_last (children); l != NULL; l = l->prev)
3876 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3879 /* Ignore offscreen children, as they don't draw in their parent and
3880 * don't take part in the clipping */
3881 if (gdk_window_is_offscreen (child))
3884 /* Client side child, expose */
3885 if (child->impl == window->impl)
3887 cairo_region_translate (expose_region, -child->x, -child->y);
3888 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
3889 cairo_region_translate (expose_region, child->x, child->y);
3893 g_list_foreach (children, (GFunc)g_object_unref, NULL);
3894 g_list_free (children);
3898 /* Process and remove any invalid area on the native window by creating
3899 * expose events for the window and all non-native descendants.
3900 * Also processes any outstanding moves on the window before doing
3901 * any drawing. Note that its possible to have outstanding moves without
3902 * any invalid area as we use the update idle mechanism to coalesce
3903 * multiple moves as well as multiple invalidations.
3906 gdk_window_process_updates_internal (GdkWindow *window)
3908 GdkWindowImplClass *impl_class;
3909 gboolean save_region = FALSE;
3910 GdkRectangle clip_box;
3912 /* Ensure the window lives while updating it */
3913 g_object_ref (window);
3915 /* If an update got queued during update processing, we can get a
3916 * window in the update queue that has an empty update_area.
3919 if (window->update_area)
3921 cairo_region_t *update_area = window->update_area;
3922 window->update_area = NULL;
3924 if (gdk_window_is_viewable (window))
3926 cairo_region_t *expose_region;
3927 gboolean end_implicit;
3929 /* Clip to part visible in toplevel */
3930 cairo_region_intersect (update_area, window->clip_region);
3934 /* Make sure we see the red invalid area before redrawing. */
3935 gdk_display_sync (gdk_window_get_display (window));
3939 /* At this point we will be completely redrawing all of update_area.
3940 * If we have any outstanding moves that end up moving stuff inside
3941 * this area we don't actually need to move that as that part would
3942 * be overdrawn by the expose anyway. So, in order to copy less data
3943 * we remove these areas from the outstanding moves.
3945 if (window->outstanding_moves)
3947 GdkWindowRegionMove *move;
3948 cairo_region_t *remove;
3951 remove = cairo_region_copy (update_area);
3952 /* We iterate backwards, starting from the state that would be
3953 if we had applied all the moves. */
3954 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
3959 /* Don't need this area */
3960 cairo_region_subtract (move->dest_region, remove);
3962 /* However if any of the destination we do need has a source
3963 in the updated region we do need that as a destination for
3964 the earlier moves */
3965 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
3966 cairo_region_subtract (remove, move->dest_region);
3968 if (cairo_region_is_empty (move->dest_region))
3970 gdk_window_region_move_free (move);
3971 window->outstanding_moves =
3972 g_list_delete_link (window->outstanding_moves, l);
3974 else /* move back */
3975 cairo_region_translate (move->dest_region, move->dx, move->dy);
3977 cairo_region_destroy (remove);
3980 /* By now we a set of window moves that should be applied, and then
3981 * an update region that should be repainted. A trivial implementation
3982 * would just do that in order, however in order to get nicer drawing
3983 * we do some tricks:
3985 * First of all, each subwindow expose may be double buffered by
3986 * itself (depending on widget setting) via
3987 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
3988 * creating a single surface the size of the invalid area on the
3989 * native window which all the individual normal paints will draw
3990 * into. This way in the normal case there will be only one surface
3991 * allocated and only once surface draw done for all the windows
3992 * in this native window.
3993 * There are a couple of reasons this may fail, for instance, some
3994 * backends (like quartz) do its own double buffering, so we disable
3995 * gdk double buffering there. Secondly, some subwindow could be
3996 * non-double buffered and draw directly to the window outside a
3997 * begin/end_paint pair. That will be lead to a gdk_window_flush
3998 * which immediately executes all outstanding moves and paints+removes
3999 * the implicit paint (further paints will allocate their own surfaces).
4001 * Secondly, in the case of implicit double buffering we expose all
4002 * the child windows into the implicit surface before we execute
4003 * the outstanding moves. This way we minimize the time between
4004 * doing the moves and rendering the new update area, thus minimizing
4005 * flashing. Of course, if any subwindow is non-double buffered we
4006 * well flush earlier than that.
4008 * Thirdly, after having done the outstanding moves we queue an
4009 * "antiexpose" on the area that will be drawn by the expose, which
4010 * means that any invalid region on the native window side before
4011 * the first expose drawing operation will be discarded, as it
4012 * has by then been overdrawn with valid data. This means we can
4013 * avoid doing the unnecessary repaint any outstanding expose events.
4016 cairo_region_get_extents (update_area, &clip_box);
4017 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4018 expose_region = cairo_region_copy (update_area);
4019 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4022 /* Rendering is not double buffered by gdk, do outstanding
4023 * moves and queue antiexposure immediately. No need to do
4025 gdk_window_flush_outstanding_moves (window);
4026 save_region = impl_class->queue_antiexpose (window, update_area);
4028 /* Render the invalid areas to the implicit paint, by sending exposes.
4029 * May flush if non-double buffered widget draw. */
4030 impl_class->process_updates_recurse (window, expose_region);
4034 /* Do moves right before exposes are rendered to the window */
4035 gdk_window_flush_outstanding_moves (window);
4037 /* By this time we know that any outstanding expose for this
4038 * area is invalid and we can avoid it, so queue an antiexpose.
4039 * we have already started drawing to the window, so it would
4040 * be to late to anti-expose now. Since this is merely an
4041 * optimization we just avoid doing it at all in that case.
4043 if (window->implicit_paint != NULL && !window->implicit_paint->flushed)
4044 save_region = impl_class->queue_antiexpose (window, update_area);
4046 gdk_window_end_implicit_paint (window);
4048 cairo_region_destroy (expose_region);
4051 cairo_region_destroy (update_area);
4054 if (window->outstanding_moves)
4056 /* Flush any outstanding moves, may happen if we moved a window but got
4057 no actual invalid area */
4058 gdk_window_flush_outstanding_moves (window);
4061 g_object_unref (window);
4065 flush_all_displays (void)
4067 GSList *displays, *l;
4069 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4070 for (l = displays; l; l = l->next)
4071 gdk_display_flush (l->data);
4073 g_slist_free (displays);
4077 before_process_all_updates (void)
4079 GSList *displays, *l;
4080 GdkDisplayClass *display_class;
4082 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4083 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4084 for (l = displays; l; l = l->next)
4085 display_class->before_process_all_updates (l->data);
4087 g_slist_free (displays);
4091 after_process_all_updates (void)
4093 GSList *displays, *l;
4094 GdkDisplayClass *display_class;
4096 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4097 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4098 for (l = displays; l; l = l->next)
4099 display_class->after_process_all_updates (l->data);
4101 g_slist_free (displays);
4104 /* Currently it is not possible to override
4105 * gdk_window_process_all_updates in the same manner as
4106 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4107 * by implementing the GdkPaintable interface. If in the future a
4108 * backend would need this, the right solution would be to add a
4109 * method to GdkDisplay that can be optionally
4110 * NULL. gdk_window_process_all_updates can then walk the list of open
4111 * displays and call the mehod.
4115 * gdk_window_process_all_updates:
4117 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4118 * in the application.
4122 gdk_window_process_all_updates (void)
4124 GSList *old_update_windows = update_windows;
4125 GSList *tmp_list = update_windows;
4126 static gboolean in_process_all_updates = FALSE;
4127 static gboolean got_recursive_update = FALSE;
4129 if (in_process_all_updates)
4131 /* We can't do this now since that would recurse, so
4132 delay it until after the recursion is done. */
4133 got_recursive_update = TRUE;
4138 in_process_all_updates = TRUE;
4139 got_recursive_update = FALSE;
4142 g_source_remove (update_idle);
4144 update_windows = NULL;
4147 before_process_all_updates ();
4149 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4153 GdkWindow *window = tmp_list->data;
4155 if (!GDK_WINDOW_DESTROYED (window))
4157 if (window->update_freeze_count ||
4158 gdk_window_is_toplevel_frozen (window))
4159 gdk_window_add_update_window (window);
4161 gdk_window_process_updates_internal (window);
4164 g_object_unref (window);
4165 tmp_list = tmp_list->next;
4168 g_slist_free (old_update_windows);
4170 flush_all_displays ();
4172 after_process_all_updates ();
4174 in_process_all_updates = FALSE;
4176 /* If we ignored a recursive call, schedule a
4177 redraw now so that it eventually happens,
4178 otherwise we could miss an update if nothing
4179 else schedules an update. */
4180 if (got_recursive_update && !update_idle)
4182 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4183 gdk_window_update_idle,
4188 * gdk_window_process_updates:
4189 * @window: a #GdkWindow
4190 * @update_children: whether to also process updates for child windows
4192 * Sends one or more expose events to @window. The areas in each
4193 * expose event will cover the entire update area for the window (see
4194 * gdk_window_invalidate_region() for details). Normally GDK calls
4195 * gdk_window_process_all_updates() on your behalf, so there's no
4196 * need to call this function unless you want to force expose events
4197 * to be delivered immediately and synchronously (vs. the usual
4198 * case, where GDK delivers them in an idle handler). Occasionally
4199 * this is useful to produce nicer scrolling behavior, for example.
4203 gdk_window_process_updates (GdkWindow *window,
4204 gboolean update_children)
4206 GdkWindow *impl_window;
4208 g_return_if_fail (GDK_IS_WINDOW (window));
4210 if (GDK_WINDOW_DESTROYED (window))
4213 /* Make sure the window lives during the expose callouts */
4214 g_object_ref (window);
4216 impl_window = gdk_window_get_impl_window (window);
4217 if ((impl_window->update_area ||
4218 impl_window->outstanding_moves) &&
4219 !impl_window->update_freeze_count &&
4220 !gdk_window_is_toplevel_frozen (window) &&
4222 /* Don't recurse into process_updates_internal, we'll
4223 * do the update later when idle instead. */
4224 impl_window->implicit_paint == NULL)
4226 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4227 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4230 if (update_children)
4232 /* process updates in reverse stacking order so composition or
4233 * painting over achieves the desired effect for offscreen windows
4235 GList *node, *children;
4237 children = g_list_copy (window->children);
4238 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4240 for (node = g_list_last (children); node; node = node->prev)
4242 gdk_window_process_updates (node->data, TRUE);
4243 g_object_unref (node->data);
4246 g_list_free (children);
4249 g_object_unref (window);
4253 gdk_window_invalidate_rect_full (GdkWindow *window,
4254 const GdkRectangle *rect,
4255 gboolean invalidate_children,
4258 GdkRectangle window_rect;
4259 cairo_region_t *region;
4261 g_return_if_fail (GDK_IS_WINDOW (window));
4263 if (GDK_WINDOW_DESTROYED (window))
4266 if (window->input_only || !window->viewable)
4273 window_rect.width = window->width;
4274 window_rect.height = window->height;
4275 rect = &window_rect;
4278 region = cairo_region_create_rectangle (rect);
4279 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4280 cairo_region_destroy (region);
4284 * gdk_window_invalidate_rect:
4285 * @window: a #GdkWindow
4286 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4288 * @invalidate_children: whether to also invalidate child windows
4290 * A convenience wrapper around gdk_window_invalidate_region() which
4291 * invalidates a rectangular region. See
4292 * gdk_window_invalidate_region() for details.
4295 gdk_window_invalidate_rect (GdkWindow *window,
4296 const GdkRectangle *rect,
4297 gboolean invalidate_children)
4299 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4303 draw_ugly_color (GdkWindow *window,
4304 const cairo_region_t *region)
4308 cr = gdk_cairo_create (window);
4309 /* Draw ugly color all over the newly-invalid region */
4310 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4311 gdk_cairo_region (cr, region);
4318 impl_window_add_update_area (GdkWindow *impl_window,
4319 cairo_region_t *region)
4321 if (impl_window->update_area)
4322 cairo_region_union (impl_window->update_area, region);
4325 gdk_window_add_update_window (impl_window);
4326 impl_window->update_area = cairo_region_copy (region);
4327 gdk_window_schedule_update (impl_window);
4331 /* clear_bg controls if the region will be cleared to
4332 * the background pattern if the exposure mask is not
4333 * set for the window, whereas this might not otherwise be
4334 * done (unless necessary to emulate background settings).
4335 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4336 * need to clear the background, such as when exposing the area beneath a
4337 * hidden or moved window, but not when an app requests repaint or when the
4338 * windowing system exposes a newly visible area (because then the windowing
4339 * system has already cleared the area).
4342 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4343 const cairo_region_t *region,
4345 GdkWindowChildFunc child_func,
4348 GdkWindow *impl_window;
4349 cairo_region_t *visible_region;
4352 g_return_if_fail (GDK_IS_WINDOW (window));
4354 if (GDK_WINDOW_DESTROYED (window))
4357 if (window->input_only ||
4358 !window->viewable ||
4359 cairo_region_is_empty (region) ||
4360 window->window_type == GDK_WINDOW_ROOT)
4363 visible_region = gdk_window_get_visible_region (window);
4364 cairo_region_intersect (visible_region, region);
4366 tmp_list = window->children;
4369 GdkWindow *child = tmp_list->data;
4371 if (!child->input_only)
4373 cairo_region_t *child_region;
4374 GdkRectangle child_rect;
4376 child_rect.x = child->x;
4377 child_rect.y = child->y;
4378 child_rect.width = child->width;
4379 child_rect.height = child->height;
4380 child_region = cairo_region_create_rectangle (&child_rect);
4382 /* remove child area from the invalid area of the parent */
4383 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4384 !child->composited &&
4385 !gdk_window_is_offscreen (child))
4386 cairo_region_subtract (visible_region, child_region);
4388 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4390 cairo_region_t *tmp = cairo_region_copy (region);
4392 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4393 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4394 cairo_region_intersect (child_region, tmp);
4396 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4397 child_region, clear_bg, child_func, user_data);
4399 cairo_region_destroy (tmp);
4402 cairo_region_destroy (child_region);
4405 tmp_list = tmp_list->next;
4408 impl_window = gdk_window_get_impl_window (window);
4410 if (!cairo_region_is_empty (visible_region) ||
4411 /* Even if we're not exposing anything, make sure we process
4412 idles for windows with outstanding moves */
4413 (impl_window->outstanding_moves != NULL &&
4414 impl_window->update_area == NULL))
4417 draw_ugly_color (window, region);
4419 /* Convert to impl coords */
4420 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4422 /* Only invalidate area if app requested expose events or if
4423 we need to clear the area (by request or to emulate background
4424 clearing for non-native windows or native windows with no support
4425 for window backgrounds */
4426 if (window->event_mask & GDK_EXPOSURE_MASK ||
4427 clear_bg == CLEAR_BG_ALL ||
4428 clear_bg == CLEAR_BG_WINCLEARED)
4429 impl_window_add_update_area (impl_window, visible_region);
4432 cairo_region_destroy (visible_region);
4436 * gdk_window_invalidate_maybe_recurse:
4437 * @window: a #GdkWindow
4438 * @region: a #cairo_region_t
4439 * @child_func: (scope call) (allow-none): function to use to decide if to
4440 * recurse to a child, %NULL means never recurse.
4441 * @user_data: data passed to @child_func
4443 * Adds @region to the update area for @window. The update area is the
4444 * region that needs to be redrawn, or "dirty region." The call
4445 * gdk_window_process_updates() sends one or more expose events to the
4446 * window, which together cover the entire update area. An
4447 * application would normally redraw the contents of @window in
4448 * response to those expose events.
4450 * GDK will call gdk_window_process_all_updates() on your behalf
4451 * whenever your program returns to the main loop and becomes idle, so
4452 * normally there's no need to do that manually, you just need to
4453 * invalidate regions that you know should be redrawn.
4455 * The @child_func parameter controls whether the region of
4456 * each child window that intersects @region will also be invalidated.
4457 * Only children for which @child_func returns TRUE will have the area
4461 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4462 const cairo_region_t *region,
4463 GdkWindowChildFunc child_func,
4466 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4467 child_func, user_data);
4471 true_predicate (GdkWindow *window,
4478 gdk_window_invalidate_region_full (GdkWindow *window,
4479 const cairo_region_t *region,
4480 gboolean invalidate_children,
4483 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4484 invalidate_children ?
4485 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4490 * gdk_window_invalidate_region:
4491 * @window: a #GdkWindow
4492 * @region: a #cairo_region_t
4493 * @invalidate_children: %TRUE to also invalidate child windows
4495 * Adds @region to the update area for @window. The update area is the
4496 * region that needs to be redrawn, or "dirty region." The call
4497 * gdk_window_process_updates() sends one or more expose events to the
4498 * window, which together cover the entire update area. An
4499 * application would normally redraw the contents of @window in
4500 * response to those expose events.
4502 * GDK will call gdk_window_process_all_updates() on your behalf
4503 * whenever your program returns to the main loop and becomes idle, so
4504 * normally there's no need to do that manually, you just need to
4505 * invalidate regions that you know should be redrawn.
4507 * The @invalidate_children parameter controls whether the region of
4508 * each child window that intersects @region will also be invalidated.
4509 * If %FALSE, then the update area for child windows will remain
4510 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4511 * fine grained control over which children are invalidated.
4514 gdk_window_invalidate_region (GdkWindow *window,
4515 const cairo_region_t *region,
4516 gboolean invalidate_children)
4518 gdk_window_invalidate_maybe_recurse (window, region,
4519 invalidate_children ?
4520 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4525 * _gdk_window_invalidate_for_expose:
4526 * @window: a #GdkWindow
4527 * @region: a #cairo_region_t
4529 * Adds @region to the update area for @window. The update area is the
4530 * region that needs to be redrawn, or "dirty region." The call
4531 * gdk_window_process_updates() sends one or more expose events to the
4532 * window, which together cover the entire update area. An
4533 * application would normally redraw the contents of @window in
4534 * response to those expose events.
4536 * GDK will call gdk_window_process_all_updates() on your behalf
4537 * whenever your program returns to the main loop and becomes idle, so
4538 * normally there's no need to do that manually, you just need to
4539 * invalidate regions that you know should be redrawn.
4541 * This version of invalidation is used when you recieve expose events
4542 * from the native window system. It exposes the native window, plus
4543 * any non-native child windows (but not native child windows, as those would
4544 * have gotten their own expose events).
4547 _gdk_window_invalidate_for_expose (GdkWindow *window,
4548 cairo_region_t *region)
4550 GdkWindowRegionMove *move;
4551 cairo_region_t *move_region;
4554 /* Any invalidations comming from the windowing system will
4555 be in areas that may be moved by outstanding moves,
4556 so we need to modify the expose region correspondingly,
4557 otherwise we would expose in the wrong place, as the
4558 outstanding moves will be copied before we draw the
4560 for (l = window->outstanding_moves; l != NULL; l = l->next)
4564 /* covert to move source region */
4565 move_region = cairo_region_copy (move->dest_region);
4566 cairo_region_translate (move_region, -move->dx, -move->dy);
4568 /* Move area of region that intersects with move source
4569 by dx, dy of the move*/
4570 cairo_region_intersect (move_region, region);
4571 cairo_region_subtract (region, move_region);
4572 cairo_region_translate (move_region, move->dx, move->dy);
4573 cairo_region_union (region, move_region);
4575 cairo_region_destroy (move_region);
4578 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4579 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4585 * gdk_window_get_update_area:
4586 * @window: a #GdkWindow
4588 * Transfers ownership of the update area from @window to the caller
4589 * of the function. That is, after calling this function, @window will
4590 * no longer have an invalid/dirty region; the update area is removed
4591 * from @window and handed to you. If a window has no update area,
4592 * gdk_window_get_update_area() returns %NULL. You are responsible for
4593 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4595 * Return value: the update area for @window
4598 gdk_window_get_update_area (GdkWindow *window)
4600 GdkWindow *impl_window;
4601 cairo_region_t *tmp_region;
4603 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4605 impl_window = gdk_window_get_impl_window (window);
4607 if (impl_window->update_area)
4609 tmp_region = cairo_region_copy (window->clip_region_with_children);
4610 /* Convert to impl coords */
4611 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4612 cairo_region_intersect (tmp_region, impl_window->update_area);
4614 if (cairo_region_is_empty (tmp_region))
4616 cairo_region_destroy (tmp_region);
4621 cairo_region_subtract (impl_window->update_area, tmp_region);
4623 if (cairo_region_is_empty (impl_window->update_area) &&
4624 impl_window->outstanding_moves == NULL)
4626 cairo_region_destroy (impl_window->update_area);
4627 impl_window->update_area = NULL;
4629 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4632 /* Convert from impl coords */
4633 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4643 * _gdk_window_clear_update_area:
4644 * @window: a #GdkWindow.
4646 * Internal function to clear the update area for a window. This
4647 * is called when the window is hidden or destroyed.
4650 _gdk_window_clear_update_area (GdkWindow *window)
4652 g_return_if_fail (GDK_IS_WINDOW (window));
4654 if (window->update_area)
4656 gdk_window_remove_update_window (window);
4658 cairo_region_destroy (window->update_area);
4659 window->update_area = NULL;
4664 * gdk_window_freeze_updates:
4665 * @window: a #GdkWindow
4667 * Temporarily freezes a window such that it won't receive expose
4668 * events. The window will begin receiving expose events again when
4669 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4670 * has been called more than once, gdk_window_thaw_updates() must be called
4671 * an equal number of times to begin processing exposes.
4674 gdk_window_freeze_updates (GdkWindow *window)
4676 GdkWindow *impl_window;
4678 g_return_if_fail (GDK_IS_WINDOW (window));
4680 impl_window = gdk_window_get_impl_window (window);
4681 impl_window->update_freeze_count++;
4685 * gdk_window_thaw_updates:
4686 * @window: a #GdkWindow
4688 * Thaws a window frozen with gdk_window_freeze_updates().
4691 gdk_window_thaw_updates (GdkWindow *window)
4693 GdkWindow *impl_window;
4695 g_return_if_fail (GDK_IS_WINDOW (window));
4697 impl_window = gdk_window_get_impl_window (window);
4699 g_return_if_fail (impl_window->update_freeze_count > 0);
4701 if (--impl_window->update_freeze_count == 0)
4702 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4706 * gdk_window_freeze_toplevel_updates_libgtk_only:
4707 * @window: a #GdkWindow
4709 * Temporarily freezes a window and all its descendants such that it won't
4710 * receive expose events. The window will begin receiving expose events
4711 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4712 * gdk_window_freeze_toplevel_updates_libgtk_only()
4713 * has been called more than once,
4714 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4715 * an equal number of times to begin processing exposes.
4717 * This function is not part of the GDK public API and is only
4721 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4723 g_return_if_fail (GDK_IS_WINDOW (window));
4724 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4726 window->update_and_descendants_freeze_count++;
4730 * gdk_window_thaw_toplevel_updates_libgtk_only:
4731 * @window: a #GdkWindow
4733 * Thaws a window frozen with
4734 * gdk_window_freeze_toplevel_updates_libgtk_only().
4736 * This function is not part of the GDK public API and is only
4740 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4742 g_return_if_fail (GDK_IS_WINDOW (window));
4743 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4744 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4746 window->update_and_descendants_freeze_count--;
4748 gdk_window_schedule_update (window);
4752 * gdk_window_set_debug_updates:
4753 * @setting: %TRUE to turn on update debugging
4755 * With update debugging enabled, calls to
4756 * gdk_window_invalidate_region() clear the invalidated region of the
4757 * screen to a noticeable color, and GDK pauses for a short time
4758 * before sending exposes to windows during
4759 * gdk_window_process_updates(). The net effect is that you can see
4760 * the invalid region for each window and watch redraws as they
4761 * occur. This allows you to diagnose inefficiencies in your application.
4763 * In essence, because the GDK rendering model prevents all flicker,
4764 * if you are redrawing the same region 400 times you may never
4765 * notice, aside from noticing a speed problem. Enabling update
4766 * debugging causes GTK to flicker slowly and noticeably, so you can
4767 * see exactly what's being redrawn when, in what order.
4769 * The --gtk-debug=updates command line option passed to GTK+ programs
4770 * enables this debug option at application startup time. That's
4771 * usually more useful than calling gdk_window_set_debug_updates()
4772 * yourself, though you might want to use this function to enable
4773 * updates sometime after application startup time.
4777 gdk_window_set_debug_updates (gboolean setting)
4779 debug_updates = setting;
4783 * gdk_window_constrain_size:
4784 * @geometry: a #GdkGeometry structure
4785 * @flags: a mask indicating what portions of @geometry are set
4786 * @width: desired width of window
4787 * @height: desired height of the window
4788 * @new_width: (out): location to store resulting width
4789 * @new_height: (out): location to store resulting height
4791 * Constrains a desired width and height according to a
4792 * set of geometry hints (such as minimum and maximum size).
4795 gdk_window_constrain_size (GdkGeometry *geometry,
4802 /* This routine is partially borrowed from fvwm.
4804 * Copyright 1993, Robert Nation
4805 * You may use this code for any purpose, as long as the original
4806 * copyright remains in the source code and all documentation
4808 * which in turn borrows parts of the algorithm from uwm
4811 gint min_height = 0;
4812 gint base_width = 0;
4813 gint base_height = 0;
4816 gint max_width = G_MAXINT;
4817 gint max_height = G_MAXINT;
4819 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4821 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4823 base_width = geometry->base_width;
4824 base_height = geometry->base_height;
4825 min_width = geometry->min_width;
4826 min_height = geometry->min_height;
4828 else if (flags & GDK_HINT_BASE_SIZE)
4830 base_width = geometry->base_width;
4831 base_height = geometry->base_height;
4832 min_width = geometry->base_width;
4833 min_height = geometry->base_height;
4835 else if (flags & GDK_HINT_MIN_SIZE)
4837 base_width = geometry->min_width;
4838 base_height = geometry->min_height;
4839 min_width = geometry->min_width;
4840 min_height = geometry->min_height;
4843 if (flags & GDK_HINT_MAX_SIZE)
4845 max_width = geometry->max_width ;
4846 max_height = geometry->max_height;
4849 if (flags & GDK_HINT_RESIZE_INC)
4851 xinc = MAX (xinc, geometry->width_inc);
4852 yinc = MAX (yinc, geometry->height_inc);
4855 /* clamp width and height to min and max values
4857 width = CLAMP (width, min_width, max_width);
4858 height = CLAMP (height, min_height, max_height);
4860 /* shrink to base + N * inc
4862 width = base_width + FLOOR (width - base_width, xinc);
4863 height = base_height + FLOOR (height - base_height, yinc);
4865 /* constrain aspect ratio, according to:
4868 * min_aspect <= -------- <= max_aspect
4872 if (flags & GDK_HINT_ASPECT &&
4873 geometry->min_aspect > 0 &&
4874 geometry->max_aspect > 0)
4878 if (geometry->min_aspect * height > width)
4880 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4881 if (height - delta >= min_height)
4885 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4886 if (width + delta <= max_width)
4891 if (geometry->max_aspect * height < width)
4893 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4894 if (width - delta >= min_width)
4898 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4899 if (height + delta <= max_height)
4908 *new_height = height;
4912 * gdk_window_get_pointer:
4913 * @window: a #GdkWindow
4914 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4915 * return the X coordinate
4916 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4917 * return the Y coordinate
4918 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4921 * Obtains the current pointer position and modifier state.
4922 * The position is given in coordinates relative to the upper left
4923 * corner of @window.
4925 * Return value: (transfer none): the window containing the pointer (as with
4926 * gdk_window_at_pointer()), or %NULL if the window containing the
4927 * pointer isn't known to GDK
4929 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4932 gdk_window_get_pointer (GdkWindow *window,
4935 GdkModifierType *mask)
4937 GdkDisplay *display;
4939 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4941 display = gdk_window_get_display (window);
4943 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
4947 * gdk_window_get_device_position:
4948 * @window: a #GdkWindow.
4949 * @device: pointer #GdkDevice to query to.
4950 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
4951 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
4952 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
4954 * Obtains the current device position and modifier state.
4955 * The position is given in coordinates relative to the upper left
4956 * corner of @window.
4958 * Return value: (transfer none): The window underneath @device (as with
4959 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
4964 gdk_window_get_device_position (GdkWindow *window,
4968 GdkModifierType *mask)
4971 GdkModifierType tmp_mask;
4972 gboolean normal_child;
4974 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4975 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
4976 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
4978 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
4982 /* We got the coords on the impl, convert to the window */
4983 tmp_x -= window->abs_x;
4984 tmp_y -= window->abs_y;
4993 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
4996 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5001 * gdk_get_default_root_window:
5003 * Obtains the root window (parent all other windows are inside)
5004 * for the default display and screen.
5006 * Return value: (transfer none): the default root window
5009 gdk_get_default_root_window (void)
5011 return gdk_screen_get_root_window (gdk_screen_get_default ());
5015 get_all_native_children (GdkWindow *window,
5021 for (l = window->children; l != NULL; l = l->next)
5025 if (gdk_window_has_impl (child))
5026 *native = g_list_prepend (*native, child);
5028 get_all_native_children (child, native);
5034 gdk_window_raise_internal (GdkWindow *window)
5036 GdkWindow *parent = window->parent;
5038 GList *native_children;
5040 GdkWindowImplClass *impl_class;
5044 parent->children = g_list_remove (parent->children, window);
5045 parent->children = g_list_prepend (parent->children, window);
5048 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5049 /* Just do native raise for toplevels */
5050 if (gdk_window_is_toplevel (window) ||
5051 /* The restack_under codepath should work correctly even if the parent
5052 is native, but it relies on the order of ->children to be correct,
5053 and some apps like SWT reorder the x windows without gdks knowledge,
5054 so we use raise directly in order to make these behave as before
5055 when using native windows */
5056 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5058 impl_class->raise (window);
5060 else if (gdk_window_has_impl (window))
5062 above = find_native_sibling_above (parent, window);
5065 listhead.data = window;
5066 listhead.next = NULL;
5067 listhead.prev = NULL;
5068 impl_class->restack_under ((GdkWindow *)above,
5072 impl_class->raise (window);
5076 native_children = NULL;
5077 get_all_native_children (window, &native_children);
5078 if (native_children != NULL)
5080 above = find_native_sibling_above (parent, window);
5083 impl_class->restack_under (above, native_children);
5086 /* Right order, since native_children is bottom-topmost first */
5087 for (l = native_children; l != NULL; l = l->next)
5088 impl_class->raise (l->data);
5091 g_list_free (native_children);
5097 /* Returns TRUE If the native window was mapped or unmapped */
5099 set_viewable (GdkWindow *w,
5103 GdkWindowImplClass *impl_class;
5106 if (w->viewable == val)
5112 recompute_visible_regions (w, FALSE, FALSE);
5114 for (l = w->children; l != NULL; l = l->next)
5118 if (GDK_WINDOW_IS_MAPPED (child) &&
5119 child->window_type != GDK_WINDOW_FOREIGN)
5120 set_viewable (child, val);
5123 if (gdk_window_has_impl (w) &&
5124 w->window_type != GDK_WINDOW_FOREIGN &&
5125 !gdk_window_is_toplevel (w))
5127 /* For most native windows we show/hide them not when they are
5128 * mapped/unmapped, because that may not produce the correct results.
5129 * For instance, if a native window have a non-native parent which is
5130 * hidden, but its native parent is viewable then showing the window
5131 * would make it viewable to X but its not viewable wrt the non-native
5132 * hierarchy. In order to handle this we track the gdk side viewability
5133 * and only map really viewable windows.
5135 * There are two exceptions though:
5137 * For foreign windows we don't want ever change the mapped state
5138 * except when explicitly done via gdk_window_show/hide, as this may
5139 * cause problems for client owning the foreign window when its window
5140 * is suddenly mapped or unmapped.
5142 * For toplevel windows embedded in a foreign window (e.g. a plug)
5143 * we sometimes synthesize a map of a window, but the native
5144 * window is really shown by the embedder, so we don't want to
5145 * do the show ourselves. We can't really tell this case from the normal
5146 * toplevel show as such toplevels are seen by gdk as parents of the
5147 * root window, so we make an exception for all toplevels.
5150 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5152 impl_class->show ((GdkWindow *)w, FALSE);
5154 impl_class->hide ((GdkWindow *)w);
5162 /* Returns TRUE If the native window was mapped or unmapped */
5164 _gdk_window_update_viewable (GdkWindow *window)
5168 if (window->window_type == GDK_WINDOW_FOREIGN ||
5169 window->window_type == GDK_WINDOW_ROOT)
5171 else if (gdk_window_is_toplevel (window) ||
5172 window->parent->viewable)
5173 viewable = GDK_WINDOW_IS_MAPPED (window);
5177 return set_viewable (window, viewable);
5181 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5183 GdkWindowImplClass *impl_class;
5184 gboolean was_mapped, was_viewable;
5187 g_return_if_fail (GDK_IS_WINDOW (window));
5189 if (window->destroyed)
5192 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5193 was_viewable = window->viewable;
5196 /* Keep children in (reverse) stacking order */
5197 gdk_window_raise_internal (window);
5199 if (gdk_window_has_impl (window))
5202 gdk_synthesize_window_state (window,
5203 GDK_WINDOW_STATE_WITHDRAWN,
5204 GDK_WINDOW_STATE_FOCUSED);
5211 did_show = _gdk_window_update_viewable (window);
5213 /* If it was already viewable the backend show op won't be called, call it
5214 again to ensure things happen right if the mapped tracking was not right
5215 for e.g. a foreign window.
5216 Dunno if this is strictly needed but its what happened pre-csw.
5217 Also show if not done by gdk_window_update_viewable. */
5218 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5220 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5221 impl_class->show (window, !did_show ? was_mapped : TRUE);
5224 if (!was_mapped && !gdk_window_has_impl (window))
5226 if (window->event_mask & GDK_STRUCTURE_MASK)
5227 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5229 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5230 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5233 if (!was_mapped || raise)
5235 recompute_visible_regions (window, TRUE, FALSE);
5237 /* If any decendants became visible we need to send visibility notify */
5238 gdk_window_update_visibility_recursively (window, NULL);
5240 if (gdk_window_is_viewable (window))
5242 _gdk_synthesize_crossing_events_for_geometry_change (window);
5243 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5249 * gdk_window_show_unraised:
5250 * @window: a #GdkWindow
5252 * Shows a #GdkWindow onscreen, but does not modify its stacking
5253 * order. In contrast, gdk_window_show() will raise the window
5254 * to the top of the window stack.
5256 * On the X11 platform, in Xlib terms, this function calls
5257 * XMapWindow() (it also updates some internal GDK state, which means
5258 * that you can't really use XMapWindow() directly on a GDK window).
5261 gdk_window_show_unraised (GdkWindow *window)
5263 gdk_window_show_internal (window, FALSE);
5268 * @window: a #GdkWindow
5270 * Raises @window to the top of the Z-order (stacking order), so that
5271 * other windows with the same parent window appear below @window.
5272 * This is true whether or not the windows are visible.
5274 * If @window is a toplevel, the window manager may choose to deny the
5275 * request to move the window in the Z-order, gdk_window_raise() only
5276 * requests the restack, does not guarantee it.
5279 gdk_window_raise (GdkWindow *window)
5281 g_return_if_fail (GDK_IS_WINDOW (window));
5283 if (window->destroyed)
5286 gdk_window_flush_if_exposing (window);
5288 /* Keep children in (reverse) stacking order */
5289 gdk_window_raise_internal (window);
5291 recompute_visible_regions (window, TRUE, FALSE);
5293 if (gdk_window_is_viewable (window) &&
5294 !window->input_only)
5295 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5299 gdk_window_lower_internal (GdkWindow *window)
5301 GdkWindow *parent = window->parent;
5302 GdkWindowImplClass *impl_class;
5304 GList *native_children;
5309 parent->children = g_list_remove (parent->children, window);
5310 parent->children = g_list_append (parent->children, window);
5313 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5314 /* Just do native lower for toplevels */
5315 if (gdk_window_is_toplevel (window) ||
5316 /* The restack_under codepath should work correctly even if the parent
5317 is native, but it relies on the order of ->children to be correct,
5318 and some apps like SWT reorder the x windows without gdks knowledge,
5319 so we use lower directly in order to make these behave as before
5320 when using native windows */
5321 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5323 impl_class->lower (window);
5325 else if (gdk_window_has_impl (window))
5327 above = find_native_sibling_above (parent, window);
5330 listhead.data = window;
5331 listhead.next = NULL;
5332 listhead.prev = NULL;
5333 impl_class->restack_under ((GdkWindow *)above, &listhead);
5336 impl_class->raise (window);
5340 native_children = NULL;
5341 get_all_native_children (window, &native_children);
5342 if (native_children != NULL)
5344 above = find_native_sibling_above (parent, window);
5347 impl_class->restack_under ((GdkWindow *)above,
5351 /* Right order, since native_children is bottom-topmost first */
5352 for (l = native_children; l != NULL; l = l->next)
5353 impl_class->raise (l->data);
5356 g_list_free (native_children);
5363 gdk_window_invalidate_in_parent (GdkWindow *private)
5365 GdkRectangle r, child;
5367 if (gdk_window_is_toplevel (private))
5370 /* get the visible rectangle of the parent */
5372 r.width = private->parent->width;
5373 r.height = private->parent->height;
5375 child.x = private->x;
5376 child.y = private->y;
5377 child.width = private->width;
5378 child.height = private->height;
5379 gdk_rectangle_intersect (&r, &child, &r);
5381 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5387 * @window: a #GdkWindow
5389 * Lowers @window to the bottom of the Z-order (stacking order), so that
5390 * other windows with the same parent window appear above @window.
5391 * This is true whether or not the other windows are visible.
5393 * If @window is a toplevel, the window manager may choose to deny the
5394 * request to move the window in the Z-order, gdk_window_lower() only
5395 * requests the restack, does not guarantee it.
5397 * Note that gdk_window_show() raises the window again, so don't call this
5398 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5401 gdk_window_lower (GdkWindow *window)
5403 g_return_if_fail (GDK_IS_WINDOW (window));
5405 if (window->destroyed)
5408 gdk_window_flush_if_exposing (window);
5410 /* Keep children in (reverse) stacking order */
5411 gdk_window_lower_internal (window);
5413 recompute_visible_regions (window, TRUE, FALSE);
5415 _gdk_synthesize_crossing_events_for_geometry_change (window);
5416 gdk_window_invalidate_in_parent (window);
5420 * gdk_window_restack:
5421 * @window: a #GdkWindow
5422 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5425 * Changes the position of @window in the Z-order (stacking order), so that
5426 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5429 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5430 * lowers the window.
5432 * If @window is a toplevel, the window manager may choose to deny the
5433 * request to move the window in the Z-order, gdk_window_restack() only
5434 * requests the restack, does not guarantee it.
5439 gdk_window_restack (GdkWindow *window,
5443 GdkWindowImplClass *impl_class;
5445 GdkWindow *above_native;
5446 GList *sibling_link;
5447 GList *native_children;
5450 g_return_if_fail (GDK_IS_WINDOW (window));
5451 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5453 if (window->destroyed)
5456 if (sibling == NULL)
5459 gdk_window_raise (window);
5461 gdk_window_lower (window);
5465 gdk_window_flush_if_exposing (window);
5467 if (gdk_window_is_toplevel (window))
5469 g_return_if_fail (gdk_window_is_toplevel (sibling));
5470 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5471 impl_class->restack_toplevel (window, sibling, above);
5475 parent = window->parent;
5478 sibling_link = g_list_find (parent->children, sibling);
5479 g_return_if_fail (sibling_link != NULL);
5480 if (sibling_link == NULL)
5483 parent->children = g_list_remove (parent->children, window);
5485 parent->children = g_list_insert_before (parent->children,
5489 parent->children = g_list_insert_before (parent->children,
5493 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5494 if (gdk_window_has_impl (window))
5496 above_native = find_native_sibling_above (parent, window);
5499 listhead.data = window;
5500 listhead.next = NULL;
5501 listhead.prev = NULL;
5502 impl_class->restack_under (above_native, &listhead);
5505 impl_class->raise (window);
5509 native_children = NULL;
5510 get_all_native_children (window, &native_children);
5511 if (native_children != NULL)
5513 above_native = find_native_sibling_above (parent, window);
5515 impl_class->restack_under (above_native,
5519 /* Right order, since native_children is bottom-topmost first */
5520 for (l = native_children; l != NULL; l = l->next)
5521 impl_class->raise (l->data);
5524 g_list_free (native_children);
5529 recompute_visible_regions (window, TRUE, FALSE);
5531 _gdk_synthesize_crossing_events_for_geometry_change (window);
5532 gdk_window_invalidate_in_parent (window);
5538 * @window: a #GdkWindow
5540 * Like gdk_window_show_unraised(), but also raises the window to the
5541 * top of the window stack (moves the window to the front of the
5544 * This function maps a window so it's visible onscreen. Its opposite
5545 * is gdk_window_hide().
5547 * When implementing a #GtkWidget, you should call this function on the widget's
5548 * #GdkWindow as part of the "map" method.
5551 gdk_window_show (GdkWindow *window)
5553 gdk_window_show_internal (window, TRUE);
5558 * @window: a #GdkWindow
5560 * For toplevel windows, withdraws them, so they will no longer be
5561 * known to the window manager; for all windows, unmaps them, so
5562 * they won't be displayed. Normally done automatically as
5563 * part of gtk_widget_hide().
5566 gdk_window_hide (GdkWindow *window)
5568 GdkWindowImplClass *impl_class;
5569 gboolean was_mapped, did_hide;
5571 g_return_if_fail (GDK_IS_WINDOW (window));
5573 if (window->destroyed)
5576 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5578 if (gdk_window_has_impl (window))
5581 if (GDK_WINDOW_IS_MAPPED (window))
5582 gdk_synthesize_window_state (window,
5584 GDK_WINDOW_STATE_WITHDRAWN);
5586 else if (was_mapped)
5588 GdkDisplay *display;
5589 GdkDeviceManager *device_manager;
5592 /* May need to break grabs on children */
5593 display = gdk_window_get_display (window);
5594 device_manager = gdk_display_get_device_manager (display);
5596 /* Get all devices */
5597 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5598 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5599 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5601 for (d = devices; d; d = d->next)
5603 GdkDevice *device = d->data;
5605 if (_gdk_display_end_device_grab (display,
5607 _gdk_display_get_next_serial (display),
5610 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5613 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5614 g_list_free (devices);
5617 did_hide = _gdk_window_update_viewable (window);
5619 /* Hide foreign window as those are not handled by update_viewable. */
5620 if (gdk_window_has_impl (window) && (!did_hide))
5622 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5623 impl_class->hide (window);
5626 recompute_visible_regions (window, TRUE, FALSE);
5628 /* all decendants became non-visible, we need to send visibility notify */
5629 gdk_window_update_visibility_recursively (window, NULL);
5631 if (was_mapped && !gdk_window_has_impl (window))
5633 if (window->event_mask & GDK_STRUCTURE_MASK)
5634 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5636 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5637 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5639 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5642 /* Invalidate the rect */
5644 gdk_window_invalidate_in_parent (window);
5648 * gdk_window_withdraw:
5649 * @window: a toplevel #GdkWindow
5651 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5652 * This function is not really useful as gdk_window_hide() automatically
5653 * withdraws toplevel windows before hiding them.
5656 gdk_window_withdraw (GdkWindow *window)
5658 GdkWindowImplClass *impl_class;
5659 gboolean was_mapped;
5661 g_return_if_fail (GDK_IS_WINDOW (window));
5663 if (window->destroyed)
5666 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5668 if (gdk_window_has_impl (window))
5670 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5671 impl_class->withdraw (window);
5675 if (window->event_mask & GDK_STRUCTURE_MASK)
5676 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5678 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5679 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5681 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5684 recompute_visible_regions (window, TRUE, FALSE);
5689 * gdk_window_set_events:
5690 * @window: a #GdkWindow
5691 * @event_mask: event mask for @window
5693 * The event mask for a window determines which events will be reported
5694 * for that window from all master input devices. For example, an event mask
5695 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5696 * press events. The event mask is the bitwise OR of values from the
5697 * #GdkEventMask enumeration.
5700 gdk_window_set_events (GdkWindow *window,
5701 GdkEventMask event_mask)
5703 GdkWindowImplClass *impl_class;
5704 GdkDisplay *display;
5706 g_return_if_fail (GDK_IS_WINDOW (window));
5708 if (window->destroyed)
5711 /* If motion hint is disabled, enable motion events again */
5712 display = gdk_window_get_display (window);
5713 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5714 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5716 GList *devices = window->devices_inside;
5720 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5721 devices = devices->next;
5725 window->event_mask = event_mask;
5727 if (gdk_window_has_impl (window))
5729 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5730 impl_class->set_events (window,
5731 get_native_event_mask (window));
5737 * gdk_window_get_events:
5738 * @window: a #GdkWindow
5740 * Gets the event mask for @window for all master input devices. See
5741 * gdk_window_set_events().
5743 * Return value: event mask for @window
5746 gdk_window_get_events (GdkWindow *window)
5748 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5750 if (window->destroyed)
5753 return window->event_mask;
5757 * gdk_window_set_device_events:
5758 * @window: a #GdkWindow
5759 * @device: #GdkDevice to enable events for.
5760 * @event_mask: event mask for @window
5762 * Sets the event mask for a given device (Normally a floating device, not
5763 * attached to any visible pointer) to @window. For example, an event mask
5764 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5765 * press events. The event mask is the bitwise OR of values from the
5766 * #GdkEventMask enumeration.
5771 gdk_window_set_device_events (GdkWindow *window,
5773 GdkEventMask event_mask)
5775 GdkEventMask device_mask;
5776 GdkDisplay *display;
5779 g_return_if_fail (GDK_IS_WINDOW (window));
5780 g_return_if_fail (GDK_IS_DEVICE (device));
5782 if (GDK_WINDOW_DESTROYED (window))
5785 /* If motion hint is disabled, enable motion events again */
5786 display = gdk_window_get_display (window);
5787 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5788 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5789 _gdk_display_enable_motion_hints (display, device);
5791 if (G_UNLIKELY (!window->device_events))
5792 window->device_events = g_hash_table_new (NULL, NULL);
5794 if (event_mask == 0)
5796 /* FIXME: unsetting events on a master device
5797 * would restore window->event_mask
5799 g_hash_table_remove (window->device_events, device);
5802 g_hash_table_insert (window->device_events, device,
5803 GINT_TO_POINTER (event_mask));
5805 native = gdk_window_get_toplevel (window);
5807 while (gdk_window_is_offscreen (native))
5809 native = gdk_offscreen_window_get_embedder (native);
5811 if (native == NULL ||
5812 (!_gdk_window_has_impl (native) &&
5813 !gdk_window_is_viewable (native)))
5816 native = gdk_window_get_toplevel (native);
5819 device_mask = get_native_device_event_mask (window, device);
5820 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5824 * gdk_window_get_device_events:
5825 * @window: a #GdkWindow.
5826 * @device: a #GdkDevice.
5828 * Returns the event mask for @window corresponding to an specific device.
5830 * Returns: device event mask for @window
5835 gdk_window_get_device_events (GdkWindow *window,
5840 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5841 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5843 if (GDK_WINDOW_DESTROYED (window))
5846 if (!window->device_events)
5849 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5851 /* FIXME: device could be controlled by window->event_mask */
5857 gdk_window_move_resize_toplevel (GdkWindow *window,
5864 cairo_region_t *old_region, *new_region;
5865 GdkWindowImplClass *impl_class;
5872 is_resize = (width != -1) || (height != -1);
5874 if (gdk_window_is_viewable (window) &&
5875 !window->input_only)
5878 old_region = cairo_region_copy (window->clip_region);
5881 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5882 impl_class->move_resize (window, with_move, x, y, width, height);
5884 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5886 recompute_visible_regions (window, TRUE, FALSE);
5890 new_region = cairo_region_copy (window->clip_region);
5892 /* This is the newly exposed area (due to any resize),
5893 * X will expose it, but lets do that without the roundtrip
5895 cairo_region_subtract (new_region, old_region);
5896 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
5898 cairo_region_destroy (old_region);
5899 cairo_region_destroy (new_region);
5902 _gdk_synthesize_crossing_events_for_geometry_change (window);
5907 move_native_children (GdkWindow *private)
5911 GdkWindowImplClass *impl_class;
5913 for (l = private->children; l; l = l->next)
5917 if (child->impl != private->impl)
5919 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
5920 impl_class->move_resize (child, TRUE,
5922 child->width, child->height);
5925 move_native_children (child);
5930 collect_native_child_region_helper (GdkWindow *window,
5931 GdkWindowImpl *impl,
5932 cairo_region_t **region,
5937 cairo_region_t *tmp;
5940 for (l = window->children; l != NULL; l = l->next)
5944 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
5947 if (child->impl != impl)
5949 tmp = cairo_region_copy (child->clip_region);
5950 cairo_region_translate (tmp,
5951 x_offset + child->x,
5952 y_offset + child->y);
5953 if (*region == NULL)
5957 cairo_region_union (*region, tmp);
5958 cairo_region_destroy (tmp);
5962 collect_native_child_region_helper (child, impl, region,
5963 x_offset + child->x,
5964 y_offset + child->y);
5970 static cairo_region_t *
5971 collect_native_child_region (GdkWindow *window,
5972 gboolean include_this)
5974 cairo_region_t *region;
5976 if (include_this && gdk_window_has_impl (window) && window->viewable)
5977 return cairo_region_copy (window->clip_region);
5981 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
5988 gdk_window_move_resize_internal (GdkWindow *window,
5995 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
5996 cairo_region_t *old_native_child_region, *new_native_child_region;
5997 GdkWindow *impl_window;
5998 GdkWindowImplClass *impl_class;
6000 int old_x, old_y, old_abs_x, old_abs_y;
6003 g_return_if_fail (GDK_IS_WINDOW (window));
6005 if (window->destroyed)
6008 if (gdk_window_is_toplevel (window))
6010 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6014 /* Bail early if no change */
6015 if (window->width == width &&
6016 window->height == height &&
6022 gdk_window_flush_if_exposing (window);
6024 /* Handle child windows */
6030 impl_window = gdk_window_get_impl_window (window);
6035 old_native_child_region = NULL;
6036 if (gdk_window_is_viewable (window) &&
6037 !window->input_only)
6041 old_region = cairo_region_copy (window->clip_region);
6042 old_layered = cairo_region_copy (window->layered_region);
6043 /* Adjust regions to parent window coords */
6044 cairo_region_translate (old_region, window->x, window->y);
6045 cairo_region_translate (old_layered, window->x, window->y);
6047 old_native_child_region = collect_native_child_region (window, TRUE);
6048 if (old_native_child_region)
6050 /* Adjust region to parent window coords */
6051 cairo_region_translate (old_native_child_region, window->x, window->y);
6053 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6054 * source or destination for a delayed GdkWindowRegionMove. So, we need
6055 * to flush those here for the parent window and all overlapped subwindows
6056 * of it. And we need to do this before setting the new clips as those will be
6059 gdk_window_flush_recursive (window->parent);
6063 /* Set the new position and size */
6069 if (!(width < 0 && height < 0))
6073 window->width = width;
6076 window->height = height;
6079 dx = window->x - old_x;
6080 dy = window->y - old_y;
6082 old_abs_x = window->abs_x;
6083 old_abs_y = window->abs_y;
6085 recompute_visible_regions (window, TRUE, FALSE);
6087 new_native_child_region = NULL;
6088 if (old_native_child_region)
6090 new_native_child_region = collect_native_child_region (window, TRUE);
6091 /* Adjust region to parent window coords */
6092 cairo_region_translate (new_native_child_region, window->x, window->y);
6095 if (gdk_window_has_impl (window))
6097 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6099 /* Do the actual move after recomputing things, as this will have set the shape to
6100 the now correct one, thus avoiding copying regions that should not be copied. */
6101 impl_class->move_resize (window, TRUE,
6102 window->x, window->y,
6103 window->width, window->height);
6105 else if (old_abs_x != window->abs_x ||
6106 old_abs_y != window->abs_y)
6107 move_native_children (window);
6111 new_region = cairo_region_copy (window->clip_region);
6112 /* Adjust region to parent window coords */
6113 cairo_region_translate (new_region, window->x, window->y);
6116 * Part of the data at the new location can be copied from the
6117 * old location, this area is the intersection of the old region
6118 * moved as the copy will move it and then intersected with
6122 * Everything in the old and new regions that is not copied must be
6123 * invalidated (including children) as this is newly exposed
6125 if (window->has_alpha_background)
6126 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6128 copy_area = cairo_region_copy (new_region);
6130 /* Don't copy from a previously layered region */
6131 cairo_region_translate (old_layered, dx, dy);
6132 cairo_region_subtract (copy_area, old_layered);
6134 /* Don't copy into a layered region */
6135 cairo_region_translate (copy_area, -window->x, -window->y);
6136 cairo_region_subtract (copy_area, window->layered_region);
6137 cairo_region_translate (copy_area, window->x, window->y);
6139 cairo_region_union (new_region, old_region);
6141 if (old_native_child_region)
6143 /* Don't copy from inside native children, as this is copied by
6144 * the native window move.
6146 cairo_region_subtract (old_region, old_native_child_region);
6148 cairo_region_translate (old_region, dx, dy);
6150 cairo_region_intersect (copy_area, old_region);
6152 if (new_native_child_region)
6154 /* Don't copy any bits that would cause a read from the moved
6155 native windows, as we can't read that data */
6156 cairo_region_translate (new_native_child_region, dx, dy);
6157 cairo_region_subtract (copy_area, new_native_child_region);
6158 cairo_region_translate (new_native_child_region, -dx, -dy);
6161 cairo_region_subtract (new_region, copy_area);
6163 /* Convert old region to impl coords */
6164 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6166 /* convert from parent coords to impl */
6167 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6169 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6171 /* Invalidate affected part in the parent window
6172 * (no higher window should be affected)
6173 * We also invalidate any children in that area, which could include
6174 * this window if it still overlaps that area.
6176 if (old_native_child_region)
6178 /* No need to expose the region that the native window move copies */
6179 cairo_region_translate (old_native_child_region, dx, dy);
6180 cairo_region_intersect (old_native_child_region, new_native_child_region);
6181 cairo_region_subtract (new_region, old_native_child_region);
6183 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6185 cairo_region_destroy (old_region);
6186 cairo_region_destroy (old_layered);
6187 cairo_region_destroy (new_region);
6190 if (old_native_child_region)
6192 cairo_region_destroy (old_native_child_region);
6193 cairo_region_destroy (new_native_child_region);
6196 _gdk_synthesize_crossing_events_for_geometry_change (window);
6203 * @window: a #GdkWindow
6204 * @x: X coordinate relative to window's parent
6205 * @y: Y coordinate relative to window's parent
6207 * Repositions a window relative to its parent window.
6208 * For toplevel windows, window managers may ignore or modify the move;
6209 * you should probably use gtk_window_move() on a #GtkWindow widget
6210 * anyway, instead of using GDK functions. For child windows,
6211 * the move will reliably succeed.
6213 * If you're also planning to resize the window, use gdk_window_move_resize()
6214 * to both move and resize simultaneously, for a nicer visual effect.
6217 gdk_window_move (GdkWindow *window,
6221 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6225 * gdk_window_resize:
6226 * @window: a #GdkWindow
6227 * @width: new width of the window
6228 * @height: new height of the window
6230 * Resizes @window; for toplevel windows, asks the window manager to resize
6231 * the window. The window manager may not allow the resize. When using GTK+,
6232 * use gtk_window_resize() instead of this low-level GDK function.
6234 * Windows may not be resized below 1x1.
6236 * If you're also planning to move the window, use gdk_window_move_resize()
6237 * to both move and resize simultaneously, for a nicer visual effect.
6240 gdk_window_resize (GdkWindow *window,
6244 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6249 * gdk_window_move_resize:
6250 * @window: a #GdkWindow
6251 * @x: new X position relative to window's parent
6252 * @y: new Y position relative to window's parent
6254 * @height: new height
6256 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6257 * except that both operations are performed at once, avoiding strange
6258 * visual effects. (i.e. the user may be able to see the window first
6259 * move, then resize, if you don't use gdk_window_move_resize().)
6262 gdk_window_move_resize (GdkWindow *window,
6268 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6273 * gdk_window_scroll:
6274 * @window: a #GdkWindow
6275 * @dx: Amount to scroll in the X direction
6276 * @dy: Amount to scroll in the Y direction
6278 * Scroll the contents of @window, both pixels and children, by the
6279 * given amount. @window itself does not move. Portions of the window
6280 * that the scroll operation brings in from offscreen areas are
6281 * invalidated. The invalidated region may be bigger than what would
6282 * strictly be necessary.
6284 * For X11, a minimum area will be invalidated if the window has no
6285 * subwindows, or if the edges of the window's parent do not extend
6286 * beyond the edges of the window. In other cases, a multi-step process
6287 * is used to scroll the window which may produce temporary visual
6288 * artifacts and unnecessary invalidations.
6291 gdk_window_scroll (GdkWindow *window,
6295 GdkWindow *impl_window;
6296 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6297 cairo_region_t *old_native_child_region, *new_native_child_region;
6300 g_return_if_fail (GDK_IS_WINDOW (window));
6302 if (dx == 0 && dy == 0)
6305 if (window->destroyed)
6308 gdk_window_flush_if_exposing (window);
6310 old_layered_area = cairo_region_copy (window->layered_region);
6311 old_native_child_region = collect_native_child_region (window, FALSE);
6312 if (old_native_child_region)
6314 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6315 * source or destination for a delayed GdkWindowRegionMove. So, we need
6316 * to flush those here for the window and all overlapped subwindows
6317 * of it. And we need to do this before setting the new clips as those will be
6320 gdk_window_flush_recursive (window);
6324 /* First move all child windows, without causing invalidation */
6326 tmp_list = window->children;
6329 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6331 /* Just update the positions, the bits will move with the copy */
6335 tmp_list = tmp_list->next;
6338 recompute_visible_regions (window, FALSE, TRUE);
6340 new_native_child_region = NULL;
6341 if (old_native_child_region)
6342 new_native_child_region = collect_native_child_region (window, FALSE);
6344 move_native_children (window);
6346 /* Then copy the actual bits of the window w/ child windows */
6348 impl_window = gdk_window_get_impl_window (window);
6350 /* Calculate the area that can be gotten by copying the old area */
6351 if (window->has_alpha_background)
6352 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6354 copy_area = cairo_region_copy (window->clip_region);
6355 cairo_region_subtract (copy_area, old_layered_area);
6356 if (old_native_child_region)
6358 /* Don't copy from inside native children, as this is copied by
6359 * the native window move.
6361 cairo_region_subtract (copy_area, old_native_child_region);
6363 /* Don't copy any bits that would cause a read from the moved
6364 native windows, as we can't read that data */
6365 cairo_region_subtract (copy_area, new_native_child_region);
6367 cairo_region_translate (copy_area, dx, dy);
6368 cairo_region_intersect (copy_area, window->clip_region);
6369 cairo_region_subtract (copy_area, window->layered_region);
6371 /* And the rest need to be invalidated */
6372 noncopy_area = cairo_region_copy (window->clip_region);
6373 cairo_region_subtract (noncopy_area, copy_area);
6375 /* convert from window coords to impl */
6376 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6378 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6380 /* Invalidate not copied regions */
6381 if (old_native_child_region)
6383 /* No need to expose the region that the native window move copies */
6384 cairo_region_translate (old_native_child_region, dx, dy);
6385 cairo_region_intersect (old_native_child_region, new_native_child_region);
6386 cairo_region_subtract (noncopy_area, old_native_child_region);
6388 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6390 cairo_region_destroy (noncopy_area);
6391 cairo_region_destroy (old_layered_area);
6393 if (old_native_child_region)
6395 cairo_region_destroy (old_native_child_region);
6396 cairo_region_destroy (new_native_child_region);
6399 _gdk_synthesize_crossing_events_for_geometry_change (window);
6403 * gdk_window_move_region:
6404 * @window: a #GdkWindow
6405 * @region: The #cairo_region_t to move
6406 * @dx: Amount to move in the X direction
6407 * @dy: Amount to move in the Y direction
6409 * Move the part of @window indicated by @region by @dy pixels in the Y
6410 * direction and @dx pixels in the X direction. The portions of @region
6411 * that not covered by the new position of @region are invalidated.
6413 * Child windows are not moved.
6418 gdk_window_move_region (GdkWindow *window,
6419 const cairo_region_t *region,
6423 GdkWindow *impl_window;
6424 cairo_region_t *nocopy_area;
6425 cairo_region_t *copy_area;
6427 g_return_if_fail (GDK_IS_WINDOW (window));
6428 g_return_if_fail (region != NULL);
6430 if (dx == 0 && dy == 0)
6433 if (window->destroyed)
6436 impl_window = gdk_window_get_impl_window (window);
6438 /* compute source regions */
6439 if (window->has_alpha_background)
6440 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6442 copy_area = cairo_region_copy (region);
6443 cairo_region_intersect (copy_area, window->clip_region_with_children);
6444 cairo_region_subtract (copy_area, window->layered_region);
6446 /* compute destination regions */
6447 cairo_region_translate (copy_area, dx, dy);
6448 cairo_region_intersect (copy_area, window->clip_region_with_children);
6449 cairo_region_subtract (copy_area, window->layered_region);
6451 /* Invalidate parts of the region (source and dest) not covered
6453 nocopy_area = cairo_region_copy (region);
6454 cairo_region_translate (nocopy_area, dx, dy);
6455 cairo_region_union (nocopy_area, region);
6456 cairo_region_subtract (nocopy_area, copy_area);
6458 /* convert from window coords to impl */
6459 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6460 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6462 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6463 cairo_region_destroy (nocopy_area);
6467 * gdk_window_set_background:
6468 * @window: a #GdkWindow
6469 * @color: a #GdkColor
6471 * Sets the background color of @window. (However, when using GTK+,
6472 * set the background of a widget with gtk_widget_modify_bg() - if
6473 * you're an application - or gtk_style_set_background() - if you're
6474 * implementing a custom widget.)
6476 * See also gdk_window_set_background_pattern().
6479 gdk_window_set_background (GdkWindow *window,
6480 const GdkColor *color)
6482 cairo_pattern_t *pattern;
6484 g_return_if_fail (GDK_IS_WINDOW (window));
6486 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6487 color->green / 65535.,
6488 color->blue / 65535.);
6490 gdk_window_set_background_pattern (window, pattern);
6492 cairo_pattern_destroy (pattern);
6496 * gdk_window_set_background_rgba:
6497 * @window: a #GdkWindow
6498 * @rgba: a #GdkRGBA color
6500 * Sets the background color of @window.
6502 * See also gdk_window_set_background_pattern().
6505 gdk_window_set_background_rgba (GdkWindow *window,
6508 cairo_pattern_t *pattern;
6510 g_return_if_fail (GDK_IS_WINDOW (window));
6511 g_return_if_fail (rgba != NULL);
6513 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6514 rgba->blue, rgba->alpha);
6516 gdk_window_set_background_pattern (window, pattern);
6518 cairo_pattern_destroy (pattern);
6522 /* Updates has_alpha_background recursively for all child windows
6523 that have parent-relative alpha */
6525 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6530 for (l = window->children; l; l = l->next)
6534 if (child->background == NULL &&
6535 child->has_alpha_background != window->has_alpha_background)
6537 child->has_alpha_background = window->has_alpha_background;
6538 recompute_visible_regions (child, TRUE, FALSE);
6539 _gdk_window_propagate_has_alpha_background (child);
6545 * gdk_window_set_background_pattern:
6546 * @window: a #GdkWindow
6547 * @pattern: (allow-none): a pattern to use, or %NULL
6549 * Sets the background of @window.
6551 * A background of %NULL means that the window will inherit its
6552 * background form its parent window.
6554 * The windowing system will normally fill a window with its background
6555 * when the window is obscured then exposed.
6558 gdk_window_set_background_pattern (GdkWindow *window,
6559 cairo_pattern_t *pattern)
6562 cairo_pattern_type_t type;
6564 g_return_if_fail (GDK_IS_WINDOW (window));
6566 if (window->input_only)
6570 cairo_pattern_reference (pattern);
6571 if (window->background)
6572 cairo_pattern_destroy (window->background);
6573 window->background = pattern;
6577 if (pattern == NULL)
6579 /* parent-relative, copy has_alpha from parent */
6580 if (window->parent == NULL ||
6581 window->parent->window_type == GDK_WINDOW_ROOT)
6584 has_alpha = window->parent->has_alpha_background;
6588 type = cairo_pattern_get_type (pattern);
6590 if (type == CAIRO_PATTERN_TYPE_SOLID)
6593 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6597 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6598 type == CAIRO_PATTERN_TYPE_RADIAL)
6604 cairo_pattern_get_color_stop_count (pattern, &n);
6606 for (i = 0; i < n; i++)
6608 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6609 NULL, NULL, NULL, &alpha);
6617 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6619 cairo_surface_t *surface;
6620 cairo_content_t content;
6622 cairo_pattern_get_surface (pattern, &surface);
6623 content = cairo_surface_get_content (surface);
6625 (content == CAIRO_CONTENT_ALPHA) ||
6626 (content == CAIRO_CONTENT_COLOR_ALPHA);
6630 if (has_alpha != window->has_alpha_background)
6632 window->has_alpha_background = has_alpha;
6633 recompute_visible_regions (window, TRUE, FALSE);
6635 _gdk_window_propagate_has_alpha_background (window);
6638 if (gdk_window_has_impl (window))
6640 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6641 impl_class->set_background (window, pattern);
6644 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6648 * gdk_window_get_background_pattern:
6651 * Gets the pattern used to clear the background on @window. If @window
6652 * does not have its own background and reuses the parent's, %NULL is
6653 * returned and you'll have to query it yourself.
6655 * Returns: (transfer none): The pattern to use for the background or
6656 * %NULL to use the parent's background.
6661 gdk_window_get_background_pattern (GdkWindow *window)
6663 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6665 return window->background;
6669 gdk_window_set_cursor_internal (GdkWindow *window,
6673 if (GDK_WINDOW_DESTROYED (window))
6676 if (window->window_type == GDK_WINDOW_ROOT ||
6677 window->window_type == GDK_WINDOW_FOREIGN)
6678 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6681 GdkPointerWindowInfo *pointer_info;
6682 GdkDisplay *display;
6684 display = gdk_window_get_display (window);
6685 pointer_info = _gdk_display_get_pointer_info (display, device);
6687 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6688 update_cursor (display, device);
6693 * gdk_window_get_cursor:
6694 * @window: a #GdkWindow
6696 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6697 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6698 * there is no custom cursor set on the specified window, and it is
6699 * using the cursor for its parent window.
6701 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6702 * object is owned by the #GdkWindow and should not be unreferenced
6703 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6709 gdk_window_get_cursor (GdkWindow *window)
6711 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6713 return window->cursor;
6717 * gdk_window_set_cursor:
6718 * @window: a #GdkWindow
6719 * @cursor: (allow-none): a cursor
6721 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6722 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6723 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6724 * to gdk_window_set_cursor() means that @window will use the cursor of its
6725 * parent window. Most windows should use this default.
6728 gdk_window_set_cursor (GdkWindow *window,
6731 GdkDisplay *display;
6733 g_return_if_fail (GDK_IS_WINDOW (window));
6735 display = gdk_window_get_display (window);
6739 g_object_unref (window->cursor);
6740 window->cursor = NULL;
6743 if (!GDK_WINDOW_DESTROYED (window))
6745 GdkDeviceManager *device_manager;
6749 window->cursor = g_object_ref (cursor);
6751 device_manager = gdk_display_get_device_manager (display);
6752 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6754 for (d = devices; d; d = d->next)
6760 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6763 gdk_window_set_cursor_internal (window, device, window->cursor);
6766 g_list_free (devices);
6767 g_object_notify (G_OBJECT (window), "cursor");
6772 * gdk_window_get_device_cursor:
6773 * @window: a #GdkWindow.
6774 * @device: a master, pointer #GdkDevice.
6776 * Retrieves a #GdkCursor pointer for the @device currently set on the
6777 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6778 * there is no custom cursor set on the specified window, and it is
6779 * using the cursor for its parent window.
6781 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6782 * object is owned by the #GdkWindow and should not be unreferenced
6783 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6789 gdk_window_get_device_cursor (GdkWindow *window,
6792 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6793 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6794 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6795 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6797 return g_hash_table_lookup (window->device_cursor, device);
6801 * gdk_window_set_device_cursor:
6802 * @window: a #Gdkwindow
6803 * @device: a master, pointer #GdkDevice
6804 * @cursor: a #GdkCursor
6806 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6807 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6808 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6809 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6810 * @window will use the cursor of its parent window. Most windows should
6816 gdk_window_set_device_cursor (GdkWindow *window,
6820 g_return_if_fail (GDK_IS_WINDOW (window));
6821 g_return_if_fail (GDK_IS_DEVICE (device));
6822 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6823 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6826 g_hash_table_remove (window->device_cursor, device);
6828 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6830 gdk_window_set_cursor_internal (window, device, cursor);
6834 * gdk_window_get_geometry:
6835 * @window: a #GdkWindow
6836 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6837 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6838 * @width: (out) (allow-none): return location for width of window
6839 * @height: (out) (allow-none): return location for height of window
6841 * Any of the return location arguments to this function may be %NULL,
6842 * if you aren't interested in getting the value of that field.
6844 * The X and Y coordinates returned are relative to the parent window
6845 * of @window, which for toplevels usually means relative to the
6846 * window decorations (titlebar, etc.) rather than relative to the
6847 * root window (screen-size background window).
6849 * On the X11 platform, the geometry is obtained from the X server,
6850 * so reflects the latest position of @window; this may be out-of-sync
6851 * with the position of @window delivered in the most-recently-processed
6852 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6853 * position from the most recent configure event.
6856 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6857 * to call gdk_window_get_position(), gdk_window_get_width() and
6858 * gdk_window_get_height() instead, because it avoids the roundtrip to
6859 * the X server and because these functions support the full 32-bit
6860 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6861 * the 16-bit coordinates of X11.
6865 gdk_window_get_geometry (GdkWindow *window,
6872 GdkWindowImplClass *impl_class;
6876 GDK_NOTE (MULTIHEAD,
6877 g_message ("gdk_window_get_geometry(): Window needs "
6878 "to be non-NULL to be multi head safe"));
6879 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6882 g_return_if_fail (GDK_IS_WINDOW (window));
6884 if (!GDK_WINDOW_DESTROYED (window))
6886 if (gdk_window_has_impl (window))
6888 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6889 impl_class->get_geometry (window, x, y,
6891 /* This reports the position wrt to the native parent, we need to convert
6892 it to be relative to the client side parent */
6893 parent = window->parent;
6894 if (parent && !gdk_window_has_impl (parent))
6897 *x -= parent->abs_x;
6899 *y -= parent->abs_y;
6909 *width = window->width;
6911 *height = window->height;
6917 * gdk_window_get_width:
6918 * @window: a #GdkWindow
6920 * Returns the width of the given @window.
6922 * On the X11 platform the returned size is the size reported in the
6923 * most-recently-processed configure event, rather than the current
6924 * size on the X server.
6926 * Returns: The width of @window
6931 gdk_window_get_width (GdkWindow *window)
6933 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6935 return window->width;
6939 * gdk_window_get_height:
6940 * @window: a #GdkWindow
6942 * Returns the height of the given @window.
6944 * On the X11 platform the returned size is the size reported in the
6945 * most-recently-processed configure event, rather than the current
6946 * size on the X server.
6948 * Returns: The height of @window
6953 gdk_window_get_height (GdkWindow *window)
6955 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6957 return window->height;
6961 * gdk_window_get_origin:
6962 * @window: a #GdkWindow
6963 * @x: (out) (allow-none): return location for X coordinate
6964 * @y: (out) (allow-none): return location for Y coordinate
6966 * Obtains the position of a window in root window coordinates.
6967 * (Compare with gdk_window_get_position() and
6968 * gdk_window_get_geometry() which return the position of a window
6969 * relative to its parent window.)
6971 * Return value: not meaningful, ignore
6974 gdk_window_get_origin (GdkWindow *window,
6978 GdkWindowImplClass *impl_class;
6980 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6982 if (GDK_WINDOW_DESTROYED (window))
6991 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6992 impl_class->get_root_coords (window,
7001 * gdk_window_get_root_coords:
7002 * @window: a #GdkWindow
7003 * @x: X coordinate in window
7004 * @y: Y coordinate in window
7005 * @root_x: (out): return location for X coordinate
7006 * @root_y: (out): return location for Y coordinate
7008 * Obtains the position of a window position in root
7009 * window coordinates. This is similar to
7010 * gdk_window_get_origin() but allows you go pass
7011 * in any position in the window, not just the origin.
7016 gdk_window_get_root_coords (GdkWindow *window,
7022 GdkWindowImplClass *impl_class;
7024 g_return_if_fail (GDK_IS_WINDOW (window));
7026 if (GDK_WINDOW_DESTROYED (window))
7033 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7034 impl_class->get_root_coords (window,
7041 * gdk_window_coords_to_parent:
7042 * @window: a child window
7043 * @x: X coordinate in child's coordinate system
7044 * @y: Y coordinate in child's coordinate system
7045 * @parent_x: (out) (allow-none): return location for X coordinate
7046 * in parent's coordinate system, or %NULL
7047 * @parent_y: (out) (allow-none): return location for Y coordinate
7048 * in parent's coordinate system, or %NULL
7050 * Transforms window coordinates from a child window to its parent
7051 * window, where the parent window is the normal parent as returned by
7052 * gdk_window_get_parent() for normal windows, and the window's
7053 * embedder as returned by gdk_offscreen_window_get_embedder() for
7054 * offscreen windows.
7056 * For normal windows, calling this function is equivalent to adding
7057 * the return values of gdk_window_get_position() to the child coordinates.
7058 * For offscreen windows however (which can be arbitrarily transformed),
7059 * this function calls the GdkWindow::to-embedder: signal to translate
7062 * You should always use this function when writing generic code that
7063 * walks up a window hierarchy.
7065 * See also: gdk_window_coords_from_parent()
7070 gdk_window_coords_to_parent (GdkWindow *window,
7076 g_return_if_fail (GDK_IS_WINDOW (window));
7078 if (gdk_window_is_offscreen (window))
7082 to_embedder (window, x, y, &px, &py);
7093 *parent_x = x + window->x;
7096 *parent_y = y + window->y;
7101 * gdk_window_coords_from_parent:
7102 * @window: a child window
7103 * @parent_x: X coordinate in parent's coordinate system
7104 * @parent_y: Y coordinate in parent's coordinate system
7105 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7106 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7108 * Transforms window coordinates from a parent window to a child
7109 * window, where the parent window is the normal parent as returned by
7110 * gdk_window_get_parent() for normal windows, and the window's
7111 * embedder as returned by gdk_offscreen_window_get_embedder() for
7112 * offscreen windows.
7114 * For normal windows, calling this function is equivalent to subtracting
7115 * the return values of gdk_window_get_position() from the parent coordinates.
7116 * For offscreen windows however (which can be arbitrarily transformed),
7117 * this function calls the GdkWindow::from-embedder: signal to translate
7120 * You should always use this function when writing generic code that
7121 * walks down a window hierarchy.
7123 * See also: gdk_window_coords_to_parent()
7128 gdk_window_coords_from_parent (GdkWindow *window,
7134 g_return_if_fail (GDK_IS_WINDOW (window));
7136 if (gdk_window_is_offscreen (window))
7140 from_embedder (window, parent_x, parent_y, &cx, &cy);
7151 *x = parent_x - window->x;
7154 *y = parent_y - window->y;
7159 * gdk_window_shape_combine_region:
7160 * @window: a #GdkWindow
7161 * @shape_region: (allow-none): region of window to be non-transparent
7162 * @offset_x: X position of @shape_region in @window coordinates
7163 * @offset_y: Y position of @shape_region in @window coordinates
7165 * Makes pixels in @window outside @shape_region be transparent,
7166 * so that the window may be nonrectangular.
7168 * If @shape_region is %NULL, the shape will be unset, so the whole
7169 * window will be opaque again. @offset_x and @offset_y are ignored
7170 * if @shape_region is %NULL.
7172 * On the X11 platform, this uses an X server extension which is
7173 * widely available on most common platforms, but not available on
7174 * very old X servers, and occasionally the implementation will be
7175 * buggy. On servers without the shape extension, this function
7178 * This function works on both toplevel and child windows.
7181 gdk_window_shape_combine_region (GdkWindow *window,
7182 const cairo_region_t *shape_region,
7186 cairo_region_t *old_region, *new_region, *diff;
7188 g_return_if_fail (GDK_IS_WINDOW (window));
7190 if (GDK_WINDOW_DESTROYED (window))
7193 if (!window->shape && shape_region == NULL)
7196 window->shaped = (shape_region != NULL);
7199 cairo_region_destroy (window->shape);
7202 if (GDK_WINDOW_IS_MAPPED (window))
7203 old_region = cairo_region_copy (window->clip_region);
7207 window->shape = cairo_region_copy (shape_region);
7208 cairo_region_translate (window->shape, offset_x, offset_y);
7211 window->shape = NULL;
7213 recompute_visible_regions (window, TRUE, FALSE);
7215 if (gdk_window_has_impl (window) &&
7216 !should_apply_clip_as_shape (window))
7217 apply_shape (window, window->shape);
7221 new_region = cairo_region_copy (window->clip_region);
7223 /* New area in the window, needs invalidation */
7224 diff = cairo_region_copy (new_region);
7225 cairo_region_subtract (diff, old_region);
7227 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7229 cairo_region_destroy (diff);
7231 if (!gdk_window_is_toplevel (window))
7233 /* New area in the non-root parent window, needs invalidation */
7234 diff = cairo_region_copy (old_region);
7235 cairo_region_subtract (diff, new_region);
7237 /* Adjust region to parent window coords */
7238 cairo_region_translate (diff, window->x, window->y);
7240 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7242 cairo_region_destroy (diff);
7245 cairo_region_destroy (new_region);
7246 cairo_region_destroy (old_region);
7251 do_child_shapes (GdkWindow *window,
7255 cairo_region_t *region;
7259 r.width = window->width;
7260 r.height = window->height;
7262 region = cairo_region_create_rectangle (&r);
7263 remove_child_area (window, NULL, FALSE, region, NULL);
7265 if (merge && window->shape)
7266 cairo_region_subtract (region, window->shape);
7268 gdk_window_shape_combine_region (window, region, 0, 0);
7272 * gdk_window_set_child_shapes:
7273 * @window: a #GdkWindow
7275 * Sets the shape mask of @window to the union of shape masks
7276 * for all children of @window, ignoring the shape mask of @window
7277 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7278 * the shape mask of @window in the masks to be merged.
7281 gdk_window_set_child_shapes (GdkWindow *window)
7283 g_return_if_fail (GDK_IS_WINDOW (window));
7285 do_child_shapes (window, FALSE);
7289 * gdk_window_merge_child_shapes:
7290 * @window: a #GdkWindow
7292 * Merges the shape masks for any child windows into the
7293 * shape mask for @window. i.e. the union of all masks
7294 * for @window and its children will become the new mask
7295 * for @window. See gdk_window_shape_combine_region().
7297 * This function is distinct from gdk_window_set_child_shapes()
7298 * because it includes @window's shape mask in the set of shapes to
7302 gdk_window_merge_child_shapes (GdkWindow *window)
7304 g_return_if_fail (GDK_IS_WINDOW (window));
7306 do_child_shapes (window, TRUE);
7310 * gdk_window_input_shape_combine_region:
7311 * @window: a #GdkWindow
7312 * @shape_region: region of window to be non-transparent
7313 * @offset_x: X position of @shape_region in @window coordinates
7314 * @offset_y: Y position of @shape_region in @window coordinates
7316 * Like gdk_window_shape_combine_region(), but the shape applies
7317 * only to event handling. Mouse events which happen while
7318 * the pointer position corresponds to an unset bit in the
7319 * mask will be passed on the window below @window.
7321 * An input shape is typically used with RGBA windows.
7322 * The alpha channel of the window defines which pixels are
7323 * invisible and allows for nicely antialiased borders,
7324 * and the input shape controls where the window is
7327 * On the X11 platform, this requires version 1.1 of the
7330 * On the Win32 platform, this functionality is not present and the
7331 * function does nothing.
7336 gdk_window_input_shape_combine_region (GdkWindow *window,
7337 const cairo_region_t *shape_region,
7341 GdkWindowImplClass *impl_class;
7343 g_return_if_fail (GDK_IS_WINDOW (window));
7345 if (GDK_WINDOW_DESTROYED (window))
7348 if (window->input_shape)
7349 cairo_region_destroy (window->input_shape);
7353 window->input_shape = cairo_region_copy (shape_region);
7354 cairo_region_translate (window->input_shape, offset_x, offset_y);
7357 window->input_shape = NULL;
7359 if (gdk_window_has_impl (window))
7361 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7362 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7365 /* Pointer may have e.g. moved outside window due to the input mask change */
7366 _gdk_synthesize_crossing_events_for_geometry_change (window);
7370 do_child_input_shapes (GdkWindow *window,
7374 cairo_region_t *region;
7378 r.width = window->width;
7379 r.height = window->height;
7381 region = cairo_region_create_rectangle (&r);
7382 remove_child_area (window, NULL, TRUE, region, NULL);
7384 if (merge && window->shape)
7385 cairo_region_subtract (region, window->shape);
7386 if (merge && window->input_shape)
7387 cairo_region_subtract (region, window->input_shape);
7389 gdk_window_input_shape_combine_region (window, region, 0, 0);
7394 * gdk_window_set_child_input_shapes:
7395 * @window: a #GdkWindow
7397 * Sets the input shape mask of @window to the union of input shape masks
7398 * for all children of @window, ignoring the input shape mask of @window
7399 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7400 * the input shape mask of @window in the masks to be merged.
7405 gdk_window_set_child_input_shapes (GdkWindow *window)
7407 g_return_if_fail (GDK_IS_WINDOW (window));
7409 do_child_input_shapes (window, FALSE);
7413 * gdk_window_merge_child_input_shapes:
7414 * @window: a #GdkWindow
7416 * Merges the input shape masks for any child windows into the
7417 * input shape mask for @window. i.e. the union of all input masks
7418 * for @window and its children will become the new input mask
7419 * for @window. See gdk_window_input_shape_combine_region().
7421 * This function is distinct from gdk_window_set_child_input_shapes()
7422 * because it includes @window's input shape mask in the set of
7423 * shapes to be merged.
7428 gdk_window_merge_child_input_shapes (GdkWindow *window)
7430 g_return_if_fail (GDK_IS_WINDOW (window));
7432 do_child_input_shapes (window, TRUE);
7437 * gdk_window_set_static_gravities:
7438 * @window: a #GdkWindow
7439 * @use_static: %TRUE to turn on static gravity
7441 * Set the bit gravity of the given window to static, and flag it so
7442 * all children get static subwindow gravity. This is used if you are
7443 * implementing scary features that involve deep knowledge of the
7444 * windowing system. Don't worry about it unless you have to.
7446 * Return value: %TRUE if the server supports static gravity
7449 gdk_window_set_static_gravities (GdkWindow *window,
7450 gboolean use_static)
7452 GdkWindowImplClass *impl_class;
7454 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7456 if (gdk_window_has_impl (window))
7458 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7459 return impl_class->set_static_gravities (window, use_static);
7466 * gdk_window_get_composited:
7467 * @window: a #GdkWindow
7469 * Determines whether @window is composited.
7471 * See gdk_window_set_composited().
7473 * Returns: %TRUE if the window is composited.
7478 gdk_window_get_composited (GdkWindow *window)
7480 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7482 return window->composited;
7486 * gdk_window_set_composited:
7487 * @window: a #GdkWindow
7488 * @composited: %TRUE to set the window as composited
7490 * Sets a #GdkWindow as composited, or unsets it. Composited
7491 * windows do not automatically have their contents drawn to
7492 * the screen. Drawing is redirected to an offscreen buffer
7493 * and an expose event is emitted on the parent of the composited
7494 * window. It is the responsibility of the parent's expose handler
7495 * to manually merge the off-screen content onto the screen in
7496 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7499 * It only makes sense for child windows to be composited; see
7500 * gdk_window_set_opacity() if you need translucent toplevel
7503 * An additional effect of this call is that the area of this
7504 * window is no longer clipped from regions marked for
7505 * invalidation on its parent. Draws done on the parent
7506 * window are also no longer clipped by the child.
7508 * This call is only supported on some systems (currently,
7509 * only X11 with new enough Xcomposite and Xdamage extensions).
7510 * You must call gdk_display_supports_composite() to check if
7511 * setting a window as composited is supported before
7512 * attempting to do so.
7517 gdk_window_set_composited (GdkWindow *window,
7518 gboolean composited)
7520 GdkDisplay *display;
7521 GdkWindowImplClass *impl_class;
7523 g_return_if_fail (GDK_IS_WINDOW (window));
7525 composited = composited != FALSE;
7527 if (window->composited == composited)
7531 gdk_window_ensure_native (window);
7533 display = gdk_window_get_display (window);
7535 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7537 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7539 g_warning ("gdk_window_set_composited called but "
7540 "compositing is not supported");
7544 impl_class->set_composited (window, composited);
7546 recompute_visible_regions (window, TRUE, FALSE);
7548 if (GDK_WINDOW_IS_MAPPED (window))
7549 gdk_window_invalidate_in_parent (window);
7551 window->composited = composited;
7555 * gdk_window_get_modal_hint:
7556 * @window: A toplevel #GdkWindow.
7558 * Determines whether or not the window manager is hinted that @window
7559 * has modal behaviour.
7561 * Return value: whether or not the window has the modal hint set.
7566 gdk_window_get_modal_hint (GdkWindow *window)
7568 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7570 return window->modal_hint;
7574 * gdk_window_get_accept_focus:
7575 * @window: a toplevel #GdkWindow.
7577 * Determines whether or not the desktop environment shuld be hinted that
7578 * the window does not want to receive input focus.
7580 * Return value: whether or not the window should receive input focus.
7585 gdk_window_get_accept_focus (GdkWindow *window)
7587 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7589 return window->accept_focus;
7593 * gdk_window_get_focus_on_map:
7594 * @window: a toplevel #GdkWindow.
7596 * Determines whether or not the desktop environment should be hinted that the
7597 * window does not want to receive input focus when it is mapped.
7599 * Return value: whether or not the window wants to receive input focus when
7605 gdk_window_get_focus_on_map (GdkWindow *window)
7607 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7609 return window->focus_on_map;
7613 * gdk_window_is_input_only:
7614 * @window: a toplevel #GdkWindow
7616 * Determines whether or not the window is an input only window.
7618 * Return value: %TRUE if @window is input only
7623 gdk_window_is_input_only (GdkWindow *window)
7625 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7627 return window->input_only;
7631 * gdk_window_is_shaped:
7632 * @window: a toplevel #GdkWindow
7634 * Determines whether or not the window is shaped.
7636 * Return value: %TRUE if @window is shaped
7641 gdk_window_is_shaped (GdkWindow *window)
7643 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7645 return window->shaped;
7649 _gdk_window_add_damage (GdkWindow *toplevel,
7650 cairo_region_t *damaged_region)
7652 GdkDisplay *display;
7653 GdkEvent event = { 0, };
7654 event.expose.type = GDK_DAMAGE;
7655 event.expose.window = toplevel;
7656 event.expose.send_event = FALSE;
7657 event.expose.region = damaged_region;
7658 cairo_region_get_extents (event.expose.region, &event.expose.area);
7659 display = gdk_window_get_display (event.expose.window);
7660 _gdk_event_queue_append (display, gdk_event_copy (&event));
7663 /* Gets the toplevel for a window as used for events,
7664 i.e. including offscreen parents */
7666 get_event_parent (GdkWindow *window)
7668 if (gdk_window_is_offscreen (window))
7669 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7671 return window->parent;
7674 /* Gets the toplevel for a window as used for events,
7675 i.e. including offscreen parents going up to the native
7678 get_event_toplevel (GdkWindow *window)
7682 while ((parent = get_event_parent (window)) != NULL &&
7683 (parent->window_type != GDK_WINDOW_ROOT))
7690 _gdk_window_event_parent_of (GdkWindow *parent,
7701 w = get_event_parent (w);
7708 update_cursor (GdkDisplay *display,
7711 GdkWindow *cursor_window, *parent, *toplevel;
7712 GdkWindow *pointer_window;
7713 GdkWindowImplClass *impl_class;
7714 GdkPointerWindowInfo *pointer_info;
7715 GdkDeviceGrabInfo *grab;
7718 pointer_info = _gdk_display_get_pointer_info (display, device);
7719 pointer_window = pointer_info->window_under_pointer;
7721 /* We ignore the serials here and just pick the last grab
7722 we've sent, as that would shortly be used anyway. */
7723 grab = _gdk_display_get_last_device_grab (display, device);
7726 /* the pointer is not in a descendant of the grab window */
7727 !_gdk_window_event_parent_of (grab->window, pointer_window))
7729 /* use the cursor from the grab window */
7730 cursor_window = grab->window;
7734 /* otherwise use the cursor from the pointer window */
7735 cursor_window = pointer_window;
7738 /* Find the first window with the cursor actually set, as
7739 the cursor is inherited from the parent */
7740 while (cursor_window->cursor == NULL &&
7741 (parent = get_event_parent (cursor_window)) != NULL &&
7742 parent->window_type != GDK_WINDOW_ROOT)
7743 cursor_window = parent;
7745 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7748 cursor = cursor_window->cursor;
7750 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7751 * which native window has what cursor set. */
7752 toplevel = get_event_toplevel (pointer_window);
7753 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7754 impl_class->set_device_cursor (toplevel, device, cursor);
7758 point_in_window (GdkWindow *window,
7763 x >= 0 && x < window->width &&
7764 y >= 0 && y < window->height &&
7765 (window->shape == NULL ||
7766 cairo_region_contains_point (window->shape,
7768 (window->input_shape == NULL ||
7769 cairo_region_contains_point (window->input_shape,
7774 convert_native_coords_to_toplevel (GdkWindow *window,
7777 gdouble *toplevel_x,
7778 gdouble *toplevel_y)
7785 while (!gdk_window_is_toplevel (window))
7789 window = window->parent;
7799 convert_toplevel_coords_to_window (GdkWindow *window,
7807 GList *children, *l;
7813 while ((parent = get_event_parent (window)) != NULL &&
7814 (parent->window_type != GDK_WINDOW_ROOT))
7816 children = g_list_prepend (children, window);
7820 for (l = children; l != NULL; l = l->next)
7821 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7823 g_list_free (children);
7830 pick_embedded_child (GdkWindow *window,
7837 g_signal_emit (window,
7838 signals[PICK_EMBEDDED_CHILD], 0,
7845 _gdk_window_find_child_at (GdkWindow *window,
7850 double child_x, child_y;
7853 if (point_in_window (window, x, y))
7855 /* Children is ordered in reverse stack order, i.e. first is topmost */
7856 for (l = window->children; l != NULL; l = l->next)
7860 if (!GDK_WINDOW_IS_MAPPED (sub))
7863 gdk_window_coords_from_parent ((GdkWindow *)sub,
7865 &child_x, &child_y);
7866 if (point_in_window (sub, child_x, child_y))
7867 return (GdkWindow *)sub;
7870 if (window->num_offscreen_children > 0)
7872 sub = pick_embedded_child (window,
7875 return (GdkWindow *)sub;
7883 _gdk_window_find_descendant_at (GdkWindow *window,
7890 gdouble child_x, child_y;
7894 if (point_in_window (window, x, y))
7899 /* Children is ordered in reverse stack order, i.e. first is topmost */
7900 for (l = window->children; l != NULL; l = l->next)
7904 if (!GDK_WINDOW_IS_MAPPED (sub))
7907 gdk_window_coords_from_parent ((GdkWindow *)sub,
7909 &child_x, &child_y);
7910 if (point_in_window (sub, child_x, child_y))
7920 window->num_offscreen_children > 0)
7922 sub = pick_embedded_child (window,
7928 from_embedder (sub, x, y, &x, &y);
7936 /* Not in window at all */
7950 * @window: a toplevel #GdkWindow
7952 * Emits a short beep associated to @window in the appropriate
7953 * display, if supported. Otherwise, emits a short beep on
7954 * the display just as gdk_display_beep().
7959 gdk_window_beep (GdkWindow *window)
7961 GdkDisplay *display;
7962 GdkWindow *toplevel;
7964 g_return_if_fail (GDK_IS_WINDOW (window));
7966 if (GDK_WINDOW_DESTROYED (window))
7969 toplevel = get_event_toplevel (window);
7970 display = gdk_window_get_display (window);
7974 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
7978 /* If windows fail to beep, we beep the display. */
7979 gdk_display_beep (display);
7983 * gdk_window_set_support_multidevice:
7984 * @window: a #GdkWindow.
7985 * @support_multidevice: %TRUE to enable multidevice support in @window.
7987 * This function will enable multidevice features in @window.
7989 * Multidevice aware windows will need to handle properly multiple,
7990 * per device enter/leave events, device grabs and grab ownerships.
7995 gdk_window_set_support_multidevice (GdkWindow *window,
7996 gboolean support_multidevice)
7998 g_return_if_fail (GDK_IS_WINDOW (window));
8000 if (GDK_WINDOW_DESTROYED (window))
8003 if (window->support_multidevice == support_multidevice)
8006 window->support_multidevice = support_multidevice;
8008 /* FIXME: What to do if called when some pointers are inside the window ? */
8012 * gdk_window_get_support_multidevice:
8013 * @window: a #GdkWindow.
8015 * Returns %TRUE if the window is aware of the existence of multiple
8018 * Returns: %TRUE if the window handles multidevice features.
8023 gdk_window_get_support_multidevice (GdkWindow *window)
8025 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8027 if (GDK_WINDOW_DESTROYED (window))
8030 return window->support_multidevice;
8033 static const guint type_masks[] = {
8034 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8035 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8036 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8037 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8038 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8039 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8040 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8041 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8042 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8043 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8044 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8045 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8046 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8047 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8048 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8049 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8050 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8051 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8052 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8053 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8054 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8055 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8056 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8057 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8058 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8059 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8060 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8061 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8062 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8063 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8064 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8065 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8066 0, /* GDK_WINDOW_STATE = 32 */
8067 0, /* GDK_SETTING = 33 */
8068 0, /* GDK_OWNER_CHANGE = 34 */
8069 0, /* GDK_GRAB_BROKEN = 35 */
8070 0, /* GDK_DAMAGE = 36 */
8072 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8074 /* send motion events if the right buttons are down */
8076 update_evmask_for_button_motion (guint evmask,
8077 GdkModifierType mask)
8079 if (evmask & GDK_BUTTON_MOTION_MASK &&
8080 mask & (GDK_BUTTON1_MASK |
8085 evmask |= GDK_POINTER_MOTION_MASK;
8087 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8088 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8089 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8090 evmask |= GDK_POINTER_MOTION_MASK;
8096 is_button_type (GdkEventType type)
8098 return type == GDK_BUTTON_PRESS ||
8099 type == GDK_2BUTTON_PRESS ||
8100 type == GDK_3BUTTON_PRESS ||
8101 type == GDK_BUTTON_RELEASE ||
8106 is_motion_type (GdkEventType type)
8108 return type == GDK_MOTION_NOTIFY ||
8109 type == GDK_ENTER_NOTIFY ||
8110 type == GDK_LEAVE_NOTIFY;
8114 find_common_ancestor (GdkWindow *win1,
8118 GList *path1 = NULL, *path2 = NULL;
8119 GList *list1, *list2;
8122 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8124 path1 = g_list_prepend (path1, tmp);
8125 tmp = get_event_parent (tmp);
8129 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8131 path2 = g_list_prepend (path2, tmp);
8132 tmp = get_event_parent (tmp);
8138 while (list1 && list2 && (list1->data == list2->data))
8141 list1 = g_list_next (list1);
8142 list2 = g_list_next (list2);
8144 g_list_free (path1);
8145 g_list_free (path2);
8151 _gdk_make_event (GdkWindow *window,
8153 GdkEvent *event_in_queue,
8154 gboolean before_event)
8156 GdkEvent *event = gdk_event_new (type);
8158 GdkModifierType the_state;
8160 the_time = gdk_event_get_time (event_in_queue);
8161 gdk_event_get_state (event_in_queue, &the_state);
8163 event->any.window = g_object_ref (window);
8164 event->any.send_event = FALSE;
8165 if (event_in_queue && event_in_queue->any.send_event)
8166 event->any.send_event = TRUE;
8170 case GDK_MOTION_NOTIFY:
8171 event->motion.time = the_time;
8172 event->motion.axes = NULL;
8173 event->motion.state = the_state;
8176 case GDK_BUTTON_PRESS:
8177 case GDK_2BUTTON_PRESS:
8178 case GDK_3BUTTON_PRESS:
8179 case GDK_BUTTON_RELEASE:
8180 event->button.time = the_time;
8181 event->button.axes = NULL;
8182 event->button.state = the_state;
8186 event->scroll.time = the_time;
8187 event->scroll.state = the_state;
8191 case GDK_KEY_RELEASE:
8192 event->key.time = the_time;
8193 event->key.state = the_state;
8196 case GDK_ENTER_NOTIFY:
8197 case GDK_LEAVE_NOTIFY:
8198 event->crossing.time = the_time;
8199 event->crossing.state = the_state;
8202 case GDK_PROPERTY_NOTIFY:
8203 event->property.time = the_time;
8204 event->property.state = the_state;
8207 case GDK_SELECTION_CLEAR:
8208 case GDK_SELECTION_REQUEST:
8209 case GDK_SELECTION_NOTIFY:
8210 event->selection.time = the_time;
8213 case GDK_PROXIMITY_IN:
8214 case GDK_PROXIMITY_OUT:
8215 event->proximity.time = the_time;
8218 case GDK_DRAG_ENTER:
8219 case GDK_DRAG_LEAVE:
8220 case GDK_DRAG_MOTION:
8221 case GDK_DRAG_STATUS:
8222 case GDK_DROP_START:
8223 case GDK_DROP_FINISHED:
8224 event->dnd.time = the_time;
8227 case GDK_FOCUS_CHANGE:
8231 case GDK_CLIENT_EVENT:
8232 case GDK_VISIBILITY_NOTIFY:
8243 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8245 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8248 _gdk_event_queue_append (gdk_window_get_display (window), event);
8254 send_crossing_event (GdkDisplay *display,
8255 GdkWindow *toplevel,
8258 GdkCrossingMode mode,
8259 GdkNotifyType notify_type,
8260 GdkWindow *subwindow,
8262 GdkDevice *source_device,
8265 GdkModifierType mask,
8267 GdkEvent *event_in_queue,
8271 guint32 window_event_mask, type_event_mask;
8272 GdkDeviceGrabInfo *grab;
8273 gboolean block_event = FALSE;
8275 grab = _gdk_display_has_device_grab (display, device, serial);
8278 !grab->owner_events)
8280 /* !owner_event => only report events wrt grab window, ignore rest */
8281 if ((GdkWindow *)window != grab->window)
8283 window_event_mask = grab->event_mask;
8286 window_event_mask = window->event_mask;
8288 if (type == GDK_LEAVE_NOTIFY)
8290 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8291 window->devices_inside = g_list_remove (window->devices_inside, device);
8293 if (!window->support_multidevice && window->devices_inside)
8295 /* Block leave events unless it's the last pointer */
8301 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8303 if (!window->support_multidevice && window->devices_inside)
8305 /* Only emit enter events for the first device */
8309 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8310 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8311 !g_list_find (window->devices_inside, device))
8312 window->devices_inside = g_list_prepend (window->devices_inside, device);
8318 if (window_event_mask & type_event_mask)
8320 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8321 gdk_event_set_device (event, device);
8324 gdk_event_set_source_device (event, source_device);
8326 event->crossing.time = time_;
8327 event->crossing.subwindow = subwindow;
8329 g_object_ref (subwindow);
8330 convert_toplevel_coords_to_window ((GdkWindow *)window,
8331 toplevel_x, toplevel_y,
8332 &event->crossing.x, &event->crossing.y);
8333 event->crossing.x_root = toplevel_x + toplevel->x;
8334 event->crossing.y_root = toplevel_y + toplevel->y;
8335 event->crossing.mode = mode;
8336 event->crossing.detail = notify_type;
8337 event->crossing.focus = FALSE;
8338 event->crossing.state = mask;
8343 /* The coordinates are in the toplevel window that src/dest are in.
8344 * src and dest are always (if != NULL) in the same toplevel, as
8345 * we get a leave-notify and set the window_under_pointer to null
8346 * before crossing to another toplevel.
8349 _gdk_synthesize_crossing_events (GdkDisplay *display,
8353 GdkDevice *source_device,
8354 GdkCrossingMode mode,
8357 GdkModifierType mask,
8359 GdkEvent *event_in_queue,
8361 gboolean non_linear)
8364 GdkWindow *win, *last, *next;
8368 GdkWindow *toplevel;
8369 GdkNotifyType notify_type;
8371 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8376 return; /* No crossings generated between src and dest */
8378 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8380 if (a && gdk_window_get_device_events (src, device) == 0)
8383 if (b && gdk_window_get_device_events (dest, device) == 0)
8390 c = find_common_ancestor (a, b);
8392 non_linear |= (c != a) && (c != b);
8394 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8396 toplevel = gdk_window_get_toplevel (a);
8398 /* Traverse up from a to (excluding) c sending leave events */
8400 notify_type = GDK_NOTIFY_NONLINEAR;
8402 notify_type = GDK_NOTIFY_INFERIOR;
8404 notify_type = GDK_NOTIFY_ANCESTOR;
8405 send_crossing_event (display, toplevel,
8406 a, GDK_LEAVE_NOTIFY,
8409 NULL, device, source_device,
8410 toplevel_x, toplevel_y,
8418 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8420 notify_type = GDK_NOTIFY_VIRTUAL;
8423 win = get_event_parent (a);
8424 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8426 send_crossing_event (display, toplevel,
8427 win, GDK_LEAVE_NOTIFY,
8431 device, source_device,
8432 toplevel_x, toplevel_y,
8438 win = get_event_parent (win);
8443 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8445 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8447 /* Traverse down from c to b */
8451 win = get_event_parent (b);
8452 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8454 path = g_list_prepend (path, win);
8455 win = get_event_parent (win);
8459 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8461 notify_type = GDK_NOTIFY_VIRTUAL;
8467 list = g_list_next (list);
8473 send_crossing_event (display, toplevel,
8474 win, GDK_ENTER_NOTIFY,
8478 device, source_device,
8479 toplevel_x, toplevel_y,
8489 notify_type = GDK_NOTIFY_NONLINEAR;
8491 notify_type = GDK_NOTIFY_ANCESTOR;
8493 notify_type = GDK_NOTIFY_INFERIOR;
8495 send_crossing_event (display, toplevel,
8496 b, GDK_ENTER_NOTIFY,
8500 device, source_device,
8501 toplevel_x, toplevel_y,
8508 /* Returns the window inside the event window with the pointer in it
8509 * at the specified coordinates, or NULL if its not in any child of
8510 * the toplevel. It also takes into account !owner_events grabs.
8513 get_pointer_window (GdkDisplay *display,
8514 GdkWindow *event_window,
8520 GdkWindow *pointer_window;
8521 GdkDeviceGrabInfo *grab;
8522 GdkPointerWindowInfo *pointer_info;
8524 pointer_info = _gdk_display_get_pointer_info (display, device);
8526 if (event_window == pointer_info->toplevel_under_pointer)
8528 _gdk_window_find_descendant_at (event_window,
8529 toplevel_x, toplevel_y,
8532 pointer_window = NULL;
8534 grab = _gdk_display_has_device_grab (display, device, serial);
8536 !grab->owner_events &&
8537 pointer_window != grab->window)
8538 pointer_window = NULL;
8540 return pointer_window;
8544 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8548 GdkPointerWindowInfo *device_info;
8550 device_info = _gdk_display_get_pointer_info (display, device);
8552 if (device_info->window_under_pointer)
8553 g_object_unref (device_info->window_under_pointer);
8554 device_info->window_under_pointer = window;
8558 g_object_ref (window);
8559 update_cursor (display, device);
8562 _gdk_display_enable_motion_hints (display, device);
8567 * @window: the #GdkWindow which will own the grab (the grab window).
8568 * @owner_events: if %FALSE then all pointer events are reported with respect to
8569 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8570 * events for this application are reported as normal, but pointer events outside
8571 * this application are reported with respect to @window and only if selected by
8572 * @event_mask. In either mode, unreported events are discarded.
8573 * @event_mask: specifies the event mask, which is used in accordance with
8574 * @owner_events. Note that only pointer events (i.e. button and motion events)
8576 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8577 * window during the grab. If the pointer is outside @confine_to, it will
8578 * automatically be moved to the closest edge of @confine_to and enter
8579 * and leave events will be generated as necessary.
8580 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8581 * the normal cursors are used for @window and its descendants, and the cursor
8582 * for @window is used for all other windows.
8583 * @time_: the timestamp of the event which led to this pointer grab. This usually
8584 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8585 * the time isn't known.
8587 * Grabs the pointer (usually a mouse) so that all events are passed to this
8588 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8589 * the grab window becomes unviewable.
8590 * This overrides any previous pointer grab by this client.
8592 * Pointer grabs are used for operations which need complete control over mouse
8593 * events, even if the mouse leaves the application.
8594 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8595 * the #GtkHPaned and #GtkVPaned widgets.
8597 * Note that if the event mask of an X window has selected both button press and
8598 * button release events, then a button press event will cause an automatic
8599 * pointer grab until the button is released.
8600 * X does this automatically since most applications expect to receive button
8601 * press and release events in pairs.
8602 * It is equivalent to a pointer grab on the window with @owner_events set to
8605 * If you set up anything at the time you take the grab that needs to be cleaned
8606 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8607 * are emitted when the grab ends unvoluntarily.
8609 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8611 * Deprecated: 3.0: Use gdk_device_grab() instead.
8614 gdk_pointer_grab (GdkWindow * window,
8615 gboolean owner_events,
8616 GdkEventMask event_mask,
8617 GdkWindow * confine_to,
8622 GdkDisplay *display;
8623 GdkDeviceManager *device_manager;
8625 GdkGrabStatus res = 0;
8627 GList *devices, *dev;
8629 g_return_val_if_fail (window != NULL, 0);
8630 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8631 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8633 /* We need a native window for confine to to work, ensure we have one */
8636 if (!gdk_window_ensure_native (confine_to))
8638 g_warning ("Can't confine to grabbed window, not native");
8643 /* Non-viewable client side window => fail */
8644 if (!_gdk_window_has_impl (window) &&
8645 !gdk_window_is_viewable (window))
8646 return GDK_GRAB_NOT_VIEWABLE;
8648 native = gdk_window_get_toplevel (window);
8649 while (gdk_window_is_offscreen (native))
8651 native = gdk_offscreen_window_get_embedder (native);
8653 if (native == NULL ||
8654 (!_gdk_window_has_impl (native) &&
8655 !gdk_window_is_viewable (native)))
8656 return GDK_GRAB_NOT_VIEWABLE;
8658 native = gdk_window_get_toplevel (native);
8661 display = gdk_window_get_display (window);
8663 serial = _gdk_display_get_next_serial (display);
8664 device_manager = gdk_display_get_device_manager (display);
8665 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8667 /* FIXME: Should this be generic to all backends? */
8668 /* FIXME: What happens with extended devices? */
8669 for (dev = devices; dev; dev = dev->next)
8673 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8676 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8679 get_native_grab_event_mask (event_mask),
8684 if (res == GDK_GRAB_SUCCESS)
8685 _gdk_display_add_device_grab (display,
8697 /* FIXME: handle errors when grabbing */
8699 g_list_free (devices);
8705 * gdk_keyboard_grab:
8706 * @window: the #GdkWindow which will own the grab (the grab window).
8707 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8708 * @window. If %TRUE then keyboard events for this application are
8709 * reported as normal, but keyboard events outside this application
8710 * are reported with respect to @window. Both key press and key
8711 * release events are always reported, independant of the event mask
8712 * set by the application.
8713 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8716 * Grabs the keyboard so that all events are passed to this
8717 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8718 * This overrides any previous keyboard grab by this client.
8720 * If you set up anything at the time you take the grab that needs to be cleaned
8721 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8722 * are emitted when the grab ends unvoluntarily.
8724 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8726 * Deprecated: 3.0: Use gdk_device_grab() instead.
8729 gdk_keyboard_grab (GdkWindow *window,
8730 gboolean owner_events,
8734 GdkDisplay *display;
8735 GdkDeviceManager *device_manager;
8737 GdkGrabStatus res = 0;
8739 GList *devices, *dev;
8741 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8743 /* Non-viewable client side window => fail */
8744 if (!_gdk_window_has_impl (window) &&
8745 !gdk_window_is_viewable (window))
8746 return GDK_GRAB_NOT_VIEWABLE;
8748 native = gdk_window_get_toplevel (window);
8750 while (gdk_window_is_offscreen (native))
8752 native = gdk_offscreen_window_get_embedder (native);
8754 if (native == NULL ||
8755 (!_gdk_window_has_impl (native) &&
8756 !gdk_window_is_viewable (native)))
8757 return GDK_GRAB_NOT_VIEWABLE;
8759 native = gdk_window_get_toplevel (native);
8762 display = gdk_window_get_display (window);
8763 serial = _gdk_display_get_next_serial (display);
8764 device_manager = gdk_display_get_device_manager (display);
8765 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8767 /* FIXME: Should this be generic to all backends? */
8768 /* FIXME: What happens with extended devices? */
8769 for (dev = devices; dev; dev = dev->next)
8773 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8776 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8779 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8784 if (res == GDK_GRAB_SUCCESS)
8785 _gdk_display_add_device_grab (display,
8796 /* FIXME: handle errors when grabbing */
8798 g_list_free (devices);
8804 * gdk_window_geometry_changed:
8805 * @window: an embedded offscreen #GdkWindow
8807 * This function informs GDK that the geometry of an embedded
8808 * offscreen window has changed. This is necessary for GDK to keep
8809 * track of which offscreen window the pointer is in.
8814 gdk_window_geometry_changed (GdkWindow *window)
8816 _gdk_synthesize_crossing_events_for_geometry_change (window);
8820 source_events_device_added (GdkDeviceManager *device_manager,
8825 GdkEventMask event_mask;
8826 GdkInputSource source;
8828 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
8832 source = gdk_device_get_source (device);
8834 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8835 GINT_TO_POINTER (source)));
8837 gdk_window_set_device_events (window, device, event_mask);
8841 source_events_device_changed (GdkDeviceManager *device_manager,
8846 GdkInputSource source;
8847 GdkEventMask event_mask;
8851 type = gdk_device_get_device_type (device);
8852 source = gdk_device_get_source (device);
8854 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8855 GINT_TO_POINTER (source)));
8860 if (type == GDK_DEVICE_TYPE_FLOATING)
8862 /* The device was just floated, enable its event mask */
8863 gdk_window_set_device_events (window, device, event_mask);
8865 else if (type == GDK_DEVICE_TYPE_SLAVE)
8866 gdk_window_set_device_events (window, device, 0);
8870 * gdk_window_set_source_events:
8871 * @window: a #GdkWindow
8872 * @source: a #GdkInputSource to define the source class.
8873 * @event_mask: event mask for @window
8875 * Sets the event mask for any floating device (i.e. not attached to any
8876 * visible pointer) that has the source defined as @source. This event
8877 * mask will be applied both to currently existing, newly added devices
8878 * after this call, and devices being attached/detached.
8883 gdk_window_set_source_events (GdkWindow *window,
8884 GdkInputSource source,
8885 GdkEventMask event_mask)
8887 GdkDeviceManager *device_manager;
8888 GdkDisplay *display;
8892 g_return_if_fail (GDK_IS_WINDOW (window));
8894 display = gdk_window_get_display (window);
8895 device_manager = gdk_display_get_device_manager (display);
8897 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
8899 /* Set event mask for existing devices */
8900 for (d = devices; d; d = d->next)
8902 GdkDevice *device = d->data;
8904 if (source == gdk_device_get_source (device))
8905 gdk_window_set_device_events (window, device, event_mask);
8908 g_list_free (devices);
8910 /* Update accounting */
8911 if (G_UNLIKELY (!window->source_event_masks))
8912 window->source_event_masks = g_hash_table_new (NULL, NULL);
8915 g_hash_table_insert (window->source_event_masks,
8916 GUINT_TO_POINTER (source),
8917 GUINT_TO_POINTER (event_mask));
8919 g_hash_table_remove (window->source_event_masks,
8920 GUINT_TO_POINTER (source));
8922 size = g_hash_table_size (window->source_event_masks);
8924 /* Update handler if needed */
8925 if (!window->device_added_handler_id && size > 0)
8927 window->device_added_handler_id =
8928 g_signal_connect (device_manager, "device-added",
8929 G_CALLBACK (source_events_device_added), window);
8930 window->device_changed_handler_id =
8931 g_signal_connect (device_manager, "device-changed",
8932 G_CALLBACK (source_events_device_changed), window);
8934 else if (window->device_added_handler_id && size == 0)
8935 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
8939 * gdk_window_get_source_events:
8940 * @window: a #GdkWindow
8941 * @source: a #GdkInputSource to define the source class.
8943 * Returns the event mask for @window corresponding to the device class specified
8946 * Returns: source event mask for @window
8949 gdk_window_get_source_events (GdkWindow *window,
8950 GdkInputSource source)
8952 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8954 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
8955 GUINT_TO_POINTER (source)));
8959 do_synthesize_crossing_event (gpointer data)
8961 GdkDisplay *display;
8962 GdkWindow *changed_toplevel;
8963 GHashTableIter iter;
8964 gpointer key, value;
8967 changed_toplevel = data;
8969 changed_toplevel->synthesize_crossing_event_queued = FALSE;
8971 if (GDK_WINDOW_DESTROYED (changed_toplevel))
8974 display = gdk_window_get_display (changed_toplevel);
8975 serial = _gdk_display_get_next_serial (display);
8976 g_hash_table_iter_init (&iter, display->pointers_info);
8978 while (g_hash_table_iter_next (&iter, &key, &value))
8980 GdkWindow *new_window_under_pointer;
8981 GdkPointerWindowInfo *pointer_info = value;
8982 GdkDevice *device = key;
8984 if (changed_toplevel == pointer_info->toplevel_under_pointer)
8986 new_window_under_pointer =
8987 get_pointer_window (display, changed_toplevel,
8989 pointer_info->toplevel_x,
8990 pointer_info->toplevel_y,
8992 if (new_window_under_pointer != pointer_info->window_under_pointer)
8994 _gdk_synthesize_crossing_events (display,
8995 pointer_info->window_under_pointer,
8996 new_window_under_pointer,
8998 GDK_CROSSING_NORMAL,
8999 pointer_info->toplevel_x,
9000 pointer_info->toplevel_y,
9001 pointer_info->state,
9006 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9015 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9017 GdkWindow *toplevel;
9019 toplevel = get_event_toplevel (changed_window);
9021 if (!toplevel->synthesize_crossing_event_queued)
9023 toplevel->synthesize_crossing_event_queued = TRUE;
9025 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9026 do_synthesize_crossing_event,
9027 g_object_ref (toplevel),
9032 /* Don't use for crossing events */
9034 get_event_window (GdkDisplay *display,
9036 GdkWindow *pointer_window,
9038 GdkModifierType mask,
9043 GdkWindow *grab_window;
9044 GdkDeviceGrabInfo *grab;
9046 grab = _gdk_display_has_device_grab (display, device, serial);
9048 if (grab != NULL && !grab->owner_events)
9050 evmask = grab->event_mask;
9051 evmask = update_evmask_for_button_motion (evmask, mask);
9053 grab_window = grab->window;
9055 if (evmask & type_masks[type])
9058 *evmask_out = evmask;
9065 while (pointer_window != NULL)
9067 evmask = pointer_window->event_mask;
9068 evmask = update_evmask_for_button_motion (evmask, mask);
9070 if (evmask & type_masks[type])
9073 *evmask_out = evmask;
9074 return pointer_window;
9077 pointer_window = get_event_parent (pointer_window);
9083 evmask = grab->event_mask;
9084 evmask = update_evmask_for_button_motion (evmask, mask);
9086 if (evmask & type_masks[type])
9089 *evmask_out = evmask;
9090 return grab->window;
9100 proxy_pointer_event (GdkDisplay *display,
9101 GdkEvent *source_event,
9104 GdkWindow *toplevel_window, *event_window;
9105 GdkWindow *pointer_window;
9106 GdkPointerWindowInfo *pointer_info;
9107 GdkDevice *device, *source_device;
9110 gdouble toplevel_x, toplevel_y;
9112 gboolean non_linear;
9114 event_window = source_event->any.window;
9115 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9116 gdk_event_get_state (source_event, &state);
9117 time_ = gdk_event_get_time (source_event);
9118 device = gdk_event_get_device (source_event);
9119 source_device = gdk_event_get_source_device (source_event);
9120 pointer_info = _gdk_display_get_pointer_info (display, device);
9121 toplevel_window = convert_native_coords_to_toplevel (event_window,
9122 toplevel_x, toplevel_y,
9123 &toplevel_x, &toplevel_y);
9126 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9127 source_event->type == GDK_ENTER_NOTIFY) &&
9128 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9129 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9132 /* If we get crossing events with subwindow unexpectedly being NULL
9133 that means there is a native subwindow that gdk doesn't know about.
9134 We track these and forward them, with the correct virtual window
9136 This is important to get right, as metacity uses gdk for the frame
9137 windows, but gdk doesn't know about the client windows reparented
9139 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9140 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9141 (source_event->type == GDK_ENTER_NOTIFY &&
9142 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9143 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9144 source_event->crossing.subwindow == NULL)
9146 /* Left for an unknown (to gdk) subwindow */
9148 /* Send leave events from window under pointer to event window
9149 that will get the subwindow == NULL window */
9150 _gdk_synthesize_crossing_events (display,
9151 pointer_info->window_under_pointer,
9153 device, source_device,
9154 source_event->crossing.mode,
9155 toplevel_x, toplevel_y,
9161 /* Send subwindow == NULL event */
9162 send_crossing_event (display,
9166 source_event->crossing.mode,
9167 source_event->crossing.detail,
9169 device, source_device,
9170 toplevel_x, toplevel_y,
9175 _gdk_display_set_window_under_pointer (display, device, NULL);
9179 pointer_window = get_pointer_window (display, toplevel_window, device,
9180 toplevel_x, toplevel_y, serial);
9182 if (((source_event->type == GDK_ENTER_NOTIFY &&
9183 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9184 (source_event->type == GDK_LEAVE_NOTIFY &&
9185 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9186 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9187 source_event->crossing.subwindow == NULL)
9189 /* Entered from an unknown (to gdk) subwindow */
9191 /* Send subwindow == NULL event */
9192 send_crossing_event (display,
9196 source_event->crossing.mode,
9197 source_event->crossing.detail,
9199 device, source_device,
9200 toplevel_x, toplevel_y,
9205 /* Send enter events from event window to pointer_window */
9206 _gdk_synthesize_crossing_events (display,
9209 device, source_device,
9210 source_event->crossing.mode,
9211 toplevel_x, toplevel_y,
9214 serial, non_linear);
9215 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9219 if (pointer_info->window_under_pointer != pointer_window)
9221 /* Either a toplevel crossing notify that ended up inside a child window,
9222 or a motion notify that got into another child window */
9224 /* Different than last time, send crossing events */
9225 _gdk_synthesize_crossing_events (display,
9226 pointer_info->window_under_pointer,
9228 device, source_device,
9229 GDK_CROSSING_NORMAL,
9230 toplevel_x, toplevel_y,
9233 serial, non_linear);
9234 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9236 else if (source_event->type == GDK_MOTION_NOTIFY)
9238 GdkWindow *event_win;
9242 event_win = get_event_window (display,
9251 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9252 gdk_window_get_device_events (event_win, device) == 0)
9258 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9260 gulong *device_serial;
9262 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9264 if (!device_serial ||
9265 (*device_serial != 0 &&
9266 serial < *device_serial))
9267 event_win = NULL; /* Ignore event */
9271 *device_serial = G_MAXULONG;
9275 if (event_win && !display->ignore_core_events)
9277 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9278 event->motion.time = time_;
9279 convert_toplevel_coords_to_window (event_win,
9280 toplevel_x, toplevel_y,
9281 &event->motion.x, &event->motion.y);
9282 event->motion.x_root = source_event->motion.x_root;
9283 event->motion.y_root = source_event->motion.y_root;
9284 event->motion.state = state;
9285 event->motion.is_hint = is_hint;
9286 event->motion.device = source_event->motion.device;
9287 event->motion.axes = g_memdup (source_event->motion.axes,
9288 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9289 gdk_event_set_source_device (event, source_device);
9293 /* unlink all move events from queue.
9294 We handle our own, including our emulated masks. */
9298 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9299 GDK_BUTTON2_MASK | \
9300 GDK_BUTTON3_MASK | \
9301 GDK_BUTTON4_MASK | \
9305 proxy_button_event (GdkEvent *source_event,
9308 GdkWindow *toplevel_window, *event_window;
9309 GdkWindow *event_win;
9310 GdkWindow *pointer_window;
9316 gdouble toplevel_x, toplevel_y;
9317 GdkDisplay *display;
9319 GdkDevice *device, *source_device;
9321 type = source_event->any.type;
9322 event_window = source_event->any.window;
9323 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9324 gdk_event_get_state (source_event, &state);
9325 time_ = gdk_event_get_time (source_event);
9326 device = gdk_event_get_device (source_event);
9327 source_device = gdk_event_get_source_device (source_event);
9328 display = gdk_window_get_display (source_event->any.window);
9329 toplevel_window = convert_native_coords_to_toplevel (event_window,
9330 toplevel_x, toplevel_y,
9331 &toplevel_x, &toplevel_y);
9333 if (type == GDK_BUTTON_PRESS &&
9334 !source_event->any.send_event &&
9335 _gdk_display_has_device_grab (display, device, serial) == NULL)
9338 _gdk_window_find_descendant_at (toplevel_window,
9339 toplevel_x, toplevel_y,
9342 /* Find the event window, that gets the grab */
9345 (parent = get_event_parent (w)) != NULL &&
9346 parent->window_type != GDK_WINDOW_ROOT)
9348 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9352 pointer_window = (GdkWindow *)w;
9354 _gdk_display_add_device_grab (display,
9360 gdk_window_get_events (pointer_window),
9364 _gdk_display_device_grab_update (display, device, source_device, serial);
9367 pointer_window = get_pointer_window (display, toplevel_window, device,
9368 toplevel_x, toplevel_y,
9371 event_win = get_event_window (display,
9377 if (event_win == NULL || display->ignore_core_events)
9380 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9381 gdk_window_get_device_events (event_win, device) == 0)
9384 event = _gdk_make_event (event_win, type, source_event, FALSE);
9388 case GDK_BUTTON_PRESS:
9389 case GDK_BUTTON_RELEASE:
9390 event->button.button = source_event->button.button;
9391 convert_toplevel_coords_to_window (event_win,
9392 toplevel_x, toplevel_y,
9393 &event->button.x, &event->button.y);
9394 event->button.x_root = source_event->button.x_root;
9395 event->button.y_root = source_event->button.y_root;
9396 event->button.state = state;
9397 event->button.device = source_event->button.device;
9398 event->button.axes = g_memdup (source_event->button.axes,
9399 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9401 gdk_event_set_source_device (event, source_device);
9403 if (type == GDK_BUTTON_PRESS)
9404 _gdk_event_button_generate (display, event);
9408 event->scroll.direction = source_event->scroll.direction;
9409 convert_toplevel_coords_to_window (event_win,
9410 toplevel_x, toplevel_y,
9411 &event->scroll.x, &event->scroll.y);
9412 event->scroll.x_root = source_event->scroll.x_root;
9413 event->scroll.y_root = source_event->scroll.y_root;
9414 event->scroll.state = state;
9415 event->scroll.device = source_event->scroll.device;
9416 gdk_event_set_source_device (event, source_device);
9423 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9426 #ifdef DEBUG_WINDOW_PRINTING
9428 gdk_window_print (GdkWindow *window,
9432 const char *window_types[] = {
9442 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9443 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9444 window->x, window->y,
9445 window->width, window->height
9448 if (gdk_window_has_impl (window))
9450 #ifdef GDK_WINDOWING_X11
9451 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9455 if (window->window_type != GDK_WINDOW_CHILD)
9456 g_print (" %s", window_types[window->window_type]);
9458 if (window->input_only)
9459 g_print (" input-only");
9462 g_print (" shaped");
9464 if (!gdk_window_is_visible ((GdkWindow *)window))
9465 g_print (" hidden");
9467 g_print (" abs[%d,%d]",
9468 window->abs_x, window->abs_y);
9470 cairo_region_get_extents (window->clip_region, &r);
9471 if (cairo_region_is_empty (window->clip_region))
9472 g_print (" clipbox[empty]");
9474 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9481 gdk_window_print_tree (GdkWindow *window,
9483 gboolean include_input_only)
9487 if (window->input_only && !include_input_only)
9490 gdk_window_print (window, indent);
9492 for (l = window->children; l != NULL; l = l->next)
9493 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9496 #endif /* DEBUG_WINDOW_PRINTING */
9499 _gdk_windowing_got_event (GdkDisplay *display,
9504 GdkWindow *event_window;
9506 gboolean unlink_event;
9507 guint old_state, old_button;
9508 GdkDeviceGrabInfo *button_release_grab;
9509 GdkPointerWindowInfo *pointer_info;
9510 GdkDevice *device, *source_device;
9511 gboolean is_toplevel;
9513 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9514 display->last_event_time = gdk_event_get_time (event);
9516 device = gdk_event_get_device (event);
9517 source_device = gdk_event_get_source_device (event);
9523 g_object_get (device, "input-mode", &mode, NULL);
9524 _gdk_display_device_grab_update (display, device, source_device, serial);
9526 if (mode == GDK_MODE_DISABLED ||
9527 !_gdk_display_check_grab_ownership (display, device, serial))
9529 /* Device events are blocked by another
9530 * device grab, or the device is disabled
9532 unlink_event = TRUE;
9537 event_window = event->any.window;
9541 pointer_info = _gdk_display_get_pointer_info (display, device);
9543 #ifdef DEBUG_WINDOW_PRINTING
9544 if (event->type == GDK_KEY_PRESS &&
9545 (event->key.keyval == 0xa7 ||
9546 event->key.keyval == 0xbd))
9548 gdk_window_print_tree (event_window, 0,
9549 event->key.keyval == 0xbd);
9553 if (event->type == GDK_VISIBILITY_NOTIFY)
9555 event_window->native_visibility = event->visibility.state;
9556 gdk_window_update_visibility_recursively (event_window,
9561 if (!(is_button_type (event->type) ||
9562 is_motion_type (event->type)) ||
9563 event_window->window_type == GDK_WINDOW_ROOT)
9566 is_toplevel = gdk_window_is_toplevel (event_window);
9568 if ((event->type == GDK_ENTER_NOTIFY ||
9569 event->type == GDK_LEAVE_NOTIFY) &&
9570 (event->crossing.mode == GDK_CROSSING_GRAB ||
9571 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9572 (_gdk_display_has_device_grab (display, device, serial) ||
9573 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9575 /* We synthesize all crossing events due to grabs ourselves,
9576 * so we ignore the native ones caused by our native pointer_grab
9577 * calls. Otherwise we would proxy these crossing event and cause
9578 * multiple copies of crossing events for grabs.
9580 * We do want to handle grabs from other clients though, as for
9581 * instance alt-tab in metacity causes grabs like these and
9582 * we want to handle those. Thus the has_pointer_grab check.
9584 * Implicit grabs on child windows create some grabbing events
9585 * that are sent before the button press. This means we can't
9586 * detect these with the has_pointer_grab check (as the implicit
9587 * grab is only noticed when we get button press event), so we
9588 * detect these events by checking for INFERIOR enter or leave
9589 * events. These should never be a problem to filter out.
9592 /* We ended up in this window after some (perhaps other clients)
9593 grab, so update the toplevel_under_window state */
9595 event->type == GDK_ENTER_NOTIFY &&
9596 event->crossing.mode == GDK_CROSSING_UNGRAB)
9598 if (pointer_info->toplevel_under_pointer)
9599 g_object_unref (pointer_info->toplevel_under_pointer);
9600 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9603 unlink_event = TRUE;
9607 /* Track toplevel_under_pointer */
9610 if (event->type == GDK_ENTER_NOTIFY &&
9611 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9613 if (pointer_info->toplevel_under_pointer)
9614 g_object_unref (pointer_info->toplevel_under_pointer);
9615 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9617 else if (event->type == GDK_LEAVE_NOTIFY &&
9618 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9619 pointer_info->toplevel_under_pointer == event_window)
9621 if (pointer_info->toplevel_under_pointer)
9622 g_object_unref (pointer_info->toplevel_under_pointer);
9623 pointer_info->toplevel_under_pointer = NULL;
9627 /* Store last pointer window and position/state */
9628 old_state = pointer_info->state;
9629 old_button = pointer_info->button;
9631 gdk_event_get_coords (event, &x, &y);
9632 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9633 pointer_info->toplevel_x = x;
9634 pointer_info->toplevel_y = y;
9635 gdk_event_get_state (event, &pointer_info->state);
9636 if (event->type == GDK_BUTTON_PRESS ||
9637 event->type == GDK_BUTTON_RELEASE)
9638 pointer_info->button = event->button.button;
9641 (pointer_info->state != old_state ||
9642 pointer_info->button != old_button))
9643 _gdk_display_enable_motion_hints (display, device);
9645 unlink_event = FALSE;
9646 if (is_motion_type (event->type))
9647 unlink_event = proxy_pointer_event (display,
9650 else if (is_button_type (event->type))
9651 unlink_event = proxy_button_event (event,
9654 if (event->type == GDK_BUTTON_RELEASE &&
9655 !event->any.send_event)
9657 button_release_grab =
9658 _gdk_display_has_device_grab (display, device, serial);
9659 if (button_release_grab &&
9660 button_release_grab->implicit &&
9661 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9663 button_release_grab->serial_end = serial;
9664 button_release_grab->implicit_ungrab = FALSE;
9665 _gdk_display_device_grab_update (display, device, source_device, serial);
9672 _gdk_event_queue_remove_link (display, event_link);
9673 g_list_free_1 (event_link);
9674 gdk_event_free (event);
9679 * gdk_window_create_similar_surface:
9680 * @window: window to make new surface similar to
9681 * @content: the content for the new surface
9682 * @width: width of the new surface
9683 * @height: height of the new surface
9685 * Create a new surface that is as compatible as possible with the
9686 * given @window. For example the new surface will have the same
9687 * fallback resolution and font options as @window. Generally, the new
9688 * surface will also use the same backend as @window, unless that is
9689 * not possible for some reason. The type of the returned surface may
9690 * be examined with cairo_surface_get_type().
9692 * Initially the surface contents are all 0 (transparent if contents
9693 * have transparency, black otherwise.)
9695 * Returns: a pointer to the newly allocated surface. The caller
9696 * owns the surface and should call cairo_surface_destroy() when done
9699 * This function always returns a valid pointer, but it will return a
9700 * pointer to a "nil" surface if @other is already in an error state
9701 * or any other error occurs.
9706 gdk_window_create_similar_surface (GdkWindow * window,
9707 cairo_content_t content,
9711 cairo_surface_t *window_surface, *surface;
9713 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9715 window_surface = _gdk_window_ref_cairo_surface (window);
9717 switch (_gdk_rendering_mode)
9719 case GDK_RENDERING_MODE_RECORDING:
9721 cairo_rectangle_t rect = { 0, 0, width, height };
9722 surface = cairo_recording_surface_create (content, &rect);
9725 case GDK_RENDERING_MODE_IMAGE:
9726 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
9727 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
9730 case GDK_RENDERING_MODE_SIMILAR:
9732 surface = cairo_surface_create_similar (window_surface,
9738 cairo_surface_destroy (window_surface);
9745 * @window: a #GdkWindow
9746 * @timestamp: timestamp of the event triggering the window focus
9748 * Sets keyboard focus to @window. In most cases, gtk_window_present()
9749 * should be used on a #GtkWindow, rather than calling this function.
9753 gdk_window_focus (GdkWindow *window,
9756 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
9760 * gdk_window_set_type_hint:
9761 * @window: A toplevel #GdkWindow
9762 * @hint: A hint of the function this window will have
9764 * The application can use this call to provide a hint to the window
9765 * manager about the functionality of a window. The window manager
9766 * can use this information when determining the decoration and behaviour
9769 * The hint must be set before the window is mapped.
9772 gdk_window_set_type_hint (GdkWindow *window,
9773 GdkWindowTypeHint hint)
9775 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
9779 * gdk_window_get_type_hint:
9780 * @window: A toplevel #GdkWindow
9782 * This function returns the type hint set for a window.
9784 * Return value: The type hint set for @window
9789 gdk_window_get_type_hint (GdkWindow *window)
9791 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
9795 * gdk_window_set_modal_hint:
9796 * @window: A toplevel #GdkWindow
9797 * @modal: %TRUE if the window is modal, %FALSE otherwise.
9799 * The application can use this hint to tell the window manager
9800 * that a certain window has modal behaviour. The window manager
9801 * can use this information to handle modal windows in a special
9804 * You should only use this on windows for which you have
9805 * previously called gdk_window_set_transient_for()
9808 gdk_window_set_modal_hint (GdkWindow *window,
9811 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
9815 * gdk_window_set_skip_taskbar_hint:
9816 * @window: a toplevel #GdkWindow
9817 * @skips_taskbar: %TRUE to skip the taskbar
9819 * Toggles whether a window should appear in a task list or window
9820 * list. If a window's semantic type as specified with
9821 * gdk_window_set_type_hint() already fully describes the window, this
9822 * function should <emphasis>not</emphasis> be called in addition,
9823 * instead you should allow the window to be treated according to
9824 * standard policy for its semantic type.
9829 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
9830 gboolean skips_taskbar)
9832 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
9836 * gdk_window_set_skip_pager_hint:
9837 * @window: a toplevel #GdkWindow
9838 * @skips_pager: %TRUE to skip the pager
9840 * Toggles whether a window should appear in a pager (workspace
9841 * switcher, or other desktop utility program that displays a small
9842 * thumbnail representation of the windows on the desktop). If a
9843 * window's semantic type as specified with gdk_window_set_type_hint()
9844 * already fully describes the window, this function should
9845 * <emphasis>not</emphasis> be called in addition, instead you should
9846 * allow the window to be treated according to standard policy for
9847 * its semantic type.
9852 gdk_window_set_skip_pager_hint (GdkWindow *window,
9853 gboolean skips_pager)
9855 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
9859 * gdk_window_set_urgency_hint:
9860 * @window: a toplevel #GdkWindow
9861 * @urgent: %TRUE if the window is urgent
9863 * Toggles whether a window needs the user's
9869 gdk_window_set_urgency_hint (GdkWindow *window,
9872 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
9876 * gdk_window_set_geometry_hints:
9877 * @window: a toplevel #GdkWindow
9878 * @geometry: geometry hints
9879 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
9881 * Sets the geometry hints for @window. Hints flagged in @geom_mask
9882 * are set, hints not flagged in @geom_mask are unset.
9883 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
9885 * This function provides hints to the windowing system about
9886 * acceptable sizes for a toplevel window. The purpose of
9887 * this is to constrain user resizing, but the windowing system
9888 * will typically (but is not required to) also constrain the
9889 * current size of the window to the provided values and
9890 * constrain programatic resizing via gdk_window_resize() or
9891 * gdk_window_move_resize().
9893 * Note that on X11, this effect has no effect on windows
9894 * of type %GDK_WINDOW_TEMP or windows where override redirect
9895 * has been turned on via gdk_window_set_override_redirect()
9896 * since these windows are not resizable by the user.
9898 * Since you can't count on the windowing system doing the
9899 * constraints for programmatic resizes, you should generally
9900 * call gdk_window_constrain_size() yourself to determine
9901 * appropriate sizes.
9905 gdk_window_set_geometry_hints (GdkWindow *window,
9906 const GdkGeometry *geometry,
9907 GdkWindowHints geom_mask)
9909 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
9913 * gdk_window_set_title:
9914 * @window: a toplevel #GdkWindow
9915 * @title: title of @window
9917 * Sets the title of a toplevel window, to be displayed in the titlebar.
9918 * If you haven't explicitly set the icon name for the window
9919 * (using gdk_window_set_icon_name()), the icon name will be set to
9920 * @title as well. @title must be in UTF-8 encoding (as with all
9921 * user-readable strings in GDK/GTK+). @title may not be %NULL.
9924 gdk_window_set_title (GdkWindow *window,
9927 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
9931 * gdk_window_set_role:
9932 * @window: a toplevel #GdkWindow
9933 * @role: a string indicating its role
9935 * When using GTK+, typically you should use gtk_window_set_role() instead
9936 * of this low-level function.
9938 * The window manager and session manager use a window's role to
9939 * distinguish it from other kinds of window in the same application.
9940 * When an application is restarted after being saved in a previous
9941 * session, all windows with the same title and role are treated as
9942 * interchangeable. So if you have two windows with the same title
9943 * that should be distinguished for session management purposes, you
9944 * should set the role on those windows. It doesn't matter what string
9945 * you use for the role, as long as you have a different role for each
9946 * non-interchangeable kind of window.
9950 gdk_window_set_role (GdkWindow *window,
9953 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
9957 * gdk_window_set_startup_id:
9958 * @window: a toplevel #GdkWindow
9959 * @startup_id: a string with startup-notification identifier
9961 * When using GTK+, typically you should use gtk_window_set_startup_id()
9962 * instead of this low-level function.
9968 gdk_window_set_startup_id (GdkWindow *window,
9969 const gchar *startup_id)
9971 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
9975 * gdk_window_set_transient_for:
9976 * @window: a toplevel #GdkWindow
9977 * @parent: another toplevel #GdkWindow
9979 * Indicates to the window manager that @window is a transient dialog
9980 * associated with the application window @parent. This allows the
9981 * window manager to do things like center @window on @parent and
9982 * keep @window above @parent.
9984 * See gtk_window_set_transient_for() if you're using #GtkWindow or
9988 gdk_window_set_transient_for (GdkWindow *window,
9991 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
9995 * gdk_window_get_root_origin:
9996 * @window: a toplevel #GdkWindow
9997 * @x: (out): return location for X position of window frame
9998 * @y: (out): return location for Y position of window frame
10000 * Obtains the top-left corner of the window manager frame in root
10001 * window coordinates.
10005 gdk_window_get_root_origin (GdkWindow *window,
10009 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10013 * gdk_window_get_frame_extents:
10014 * @window: a toplevel #GdkWindow
10015 * @rect: rectangle to fill with bounding box of the window frame
10017 * Obtains the bounding box of the window, including window manager
10018 * titlebar/borders if any. The frame position is given in root window
10019 * coordinates. To get the position of the window itself (rather than
10020 * the frame) in root window coordinates, use gdk_window_get_origin().
10024 gdk_window_get_frame_extents (GdkWindow *window,
10025 GdkRectangle *rect)
10027 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10031 * gdk_window_set_override_redirect:
10032 * @window: a toplevel #GdkWindow
10033 * @override_redirect: %TRUE if window should be override redirect
10035 * An override redirect window is not under the control of the window manager.
10036 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10037 * be entirely under the control of the application. The window manager
10038 * can't see the override redirect window at all.
10040 * Override redirect should only be used for short-lived temporary
10041 * windows, such as popup menus. #GtkMenu uses an override redirect
10042 * window in its implementation, for example.
10046 gdk_window_set_override_redirect (GdkWindow *window,
10047 gboolean override_redirect)
10049 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10053 * gdk_window_set_accept_focus:
10054 * @window: a toplevel #GdkWindow
10055 * @accept_focus: %TRUE if the window should receive input focus
10057 * Setting @accept_focus to %FALSE hints the desktop environment that the
10058 * window doesn't want to receive input focus.
10060 * On X, it is the responsibility of the window manager to interpret this
10061 * hint. ICCCM-compliant window manager usually respect it.
10066 gdk_window_set_accept_focus (GdkWindow *window,
10067 gboolean accept_focus)
10069 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10073 * gdk_window_set_focus_on_map:
10074 * @window: a toplevel #GdkWindow
10075 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10077 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10078 * window doesn't want to receive input focus when it is mapped.
10079 * focus_on_map should be turned off for windows that aren't triggered
10080 * interactively (such as popups from network activity).
10082 * On X, it is the responsibility of the window manager to interpret
10083 * this hint. Window managers following the freedesktop.org window
10084 * manager extension specification should respect it.
10089 gdk_window_set_focus_on_map (GdkWindow *window,
10090 gboolean focus_on_map)
10092 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10096 * gdk_window_set_icon_list:
10097 * @window: The #GdkWindow toplevel window to set the icon of.
10098 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10099 * A list of pixbufs, of different sizes.
10101 * Sets a list of icons for the window. One of these will be used
10102 * to represent the window when it has been iconified. The icon is
10103 * usually shown in an icon box or some sort of task bar. Which icon
10104 * size is shown depends on the window manager. The window manager
10105 * can scale the icon but setting several size icons can give better
10106 * image quality since the window manager may only need to scale the
10107 * icon by a small amount or not at all.
10111 gdk_window_set_icon_list (GdkWindow *window,
10114 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10118 * gdk_window_set_icon_name:
10119 * @window: a toplevel #GdkWindow
10120 * @name: (allow-none): name of window while iconified (minimized)
10122 * Windows may have a name used while minimized, distinct from the
10123 * name they display in their titlebar. Most of the time this is a bad
10124 * idea from a user interface standpoint. But you can set such a name
10125 * with this function, if you like.
10127 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10128 * will not update the icon title.
10130 * Using %NULL for @name unsets the icon title; further calls to
10131 * gdk_window_set_title() will again update the icon title as well.
10134 gdk_window_set_icon_name (GdkWindow *window,
10137 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10141 * gdk_window_iconify:
10142 * @window: a toplevel #GdkWindow
10144 * Asks to iconify (minimize) @window. The window manager may choose
10145 * to ignore the request, but normally will honor it. Using
10146 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10148 * This function only makes sense when @window is a toplevel window.
10152 gdk_window_iconify (GdkWindow *window)
10154 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10158 * gdk_window_deiconify:
10159 * @window: a toplevel #GdkWindow
10161 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10162 * choose to ignore the request to deiconify. When using GTK+,
10163 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10164 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10165 * unminimizes it, and puts it on the current desktop.
10169 gdk_window_deiconify (GdkWindow *window)
10171 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10175 * gdk_window_stick:
10176 * @window: a toplevel #GdkWindow
10178 * "Pins" a window such that it's on all workspaces and does not scroll
10179 * with viewports, for window managers that have scrollable viewports.
10180 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10182 * On the X11 platform, this function depends on window manager
10183 * support, so may have no effect with many window managers. However,
10184 * GDK will do the best it can to convince the window manager to stick
10185 * the window. For window managers that don't support this operation,
10186 * there's nothing you can do to force it to happen.
10190 gdk_window_stick (GdkWindow *window)
10192 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10196 * gdk_window_unstick:
10197 * @window: a toplevel #GdkWindow
10199 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10200 * and gtk_window_unstick().
10204 gdk_window_unstick (GdkWindow *window)
10206 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10210 * gdk_window_maximize:
10211 * @window: a toplevel #GdkWindow
10213 * Maximizes the window. If the window was already maximized, then
10214 * this function does nothing.
10216 * On X11, asks the window manager to maximize @window, if the window
10217 * manager supports this operation. Not all window managers support
10218 * this, and some deliberately ignore it or don't have a concept of
10219 * "maximized"; so you can't rely on the maximization actually
10220 * happening. But it will happen with most standard window managers,
10221 * and GDK makes a best effort to get it to happen.
10223 * On Windows, reliably maximizes the window.
10227 gdk_window_maximize (GdkWindow *window)
10229 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10233 * gdk_window_unmaximize:
10234 * @window: a toplevel #GdkWindow
10236 * Unmaximizes the window. If the window wasn't maximized, then this
10237 * function does nothing.
10239 * On X11, asks the window manager to unmaximize @window, if the
10240 * window manager supports this operation. Not all window managers
10241 * support this, and some deliberately ignore it or don't have a
10242 * concept of "maximized"; so you can't rely on the unmaximization
10243 * actually happening. But it will happen with most standard window
10244 * managers, and GDK makes a best effort to get it to happen.
10246 * On Windows, reliably unmaximizes the window.
10250 gdk_window_unmaximize (GdkWindow *window)
10252 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10256 * gdk_window_fullscreen:
10257 * @window: a toplevel #GdkWindow
10259 * Moves the window into fullscreen mode. This means the
10260 * window covers the entire screen and is above any panels
10263 * If the window was already fullscreen, then this function does nothing.
10265 * On X11, asks the window manager to put @window in a fullscreen
10266 * state, if the window manager supports this operation. Not all
10267 * window managers support this, and some deliberately ignore it or
10268 * don't have a concept of "fullscreen"; so you can't rely on the
10269 * fullscreenification actually happening. But it will happen with
10270 * most standard window managers, and GDK makes a best effort to get
10276 gdk_window_fullscreen (GdkWindow *window)
10278 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10282 * gdk_window_unfullscreen:
10283 * @window: a toplevel #GdkWindow
10285 * Moves the window out of fullscreen mode. If the window was not
10286 * fullscreen, does nothing.
10288 * On X11, asks the window manager to move @window out of the fullscreen
10289 * state, if the window manager supports this operation. Not all
10290 * window managers support this, and some deliberately ignore it or
10291 * don't have a concept of "fullscreen"; so you can't rely on the
10292 * unfullscreenification actually happening. But it will happen with
10293 * most standard window managers, and GDK makes a best effort to get
10299 gdk_window_unfullscreen (GdkWindow *window)
10301 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10305 * gdk_window_set_keep_above:
10306 * @window: a toplevel #GdkWindow
10307 * @setting: whether to keep @window above other windows
10309 * Set if @window must be kept above other windows. If the
10310 * window was already above, then this function does nothing.
10312 * On X11, asks the window manager to keep @window above, if the window
10313 * manager supports this operation. Not all window managers support
10314 * this, and some deliberately ignore it or don't have a concept of
10315 * "keep above"; so you can't rely on the window being kept above.
10316 * But it will happen with most standard window managers,
10317 * and GDK makes a best effort to get it to happen.
10322 gdk_window_set_keep_above (GdkWindow *window,
10325 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10329 * gdk_window_set_keep_below:
10330 * @window: a toplevel #GdkWindow
10331 * @setting: whether to keep @window below other windows
10333 * Set if @window must be kept below other windows. If the
10334 * window was already below, then this function does nothing.
10336 * On X11, asks the window manager to keep @window below, if the window
10337 * manager supports this operation. Not all window managers support
10338 * this, and some deliberately ignore it or don't have a concept of
10339 * "keep below"; so you can't rely on the window being kept below.
10340 * But it will happen with most standard window managers,
10341 * and GDK makes a best effort to get it to happen.
10346 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10348 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10352 * gdk_window_get_group:
10353 * @window: a toplevel #GdkWindow
10355 * Returns the group leader window for @window. See gdk_window_set_group().
10357 * Return value: (transfer none): the group leader window for @window
10362 gdk_window_get_group (GdkWindow *window)
10364 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10368 * gdk_window_set_group:
10369 * @window: a toplevel #GdkWindow
10370 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10372 * Sets the group leader window for @window. By default,
10373 * GDK sets the group leader for all toplevel windows
10374 * to a global window implicitly created by GDK. With this function
10375 * you can override this default.
10377 * The group leader window allows the window manager to distinguish
10378 * all windows that belong to a single application. It may for example
10379 * allow users to minimize/unminimize all windows belonging to an
10380 * application at once. You should only set a non-default group window
10381 * if your application pretends to be multiple applications.
10384 gdk_window_set_group (GdkWindow *window,
10387 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10391 * gdk_window_set_decorations:
10392 * @window: a toplevel #GdkWindow
10393 * @decorations: decoration hint mask
10395 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10396 * This function sets the traditional Motif window manager hints that tell the
10397 * window manager which decorations you would like your window to have.
10398 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10399 * using the GDK function directly.
10401 * The @decorations argument is the logical OR of the fields in
10402 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10403 * mask, the other bits indicate which decorations should be turned off.
10404 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10405 * which decorations should be turned on.
10407 * Most window managers honor a decorations hint of 0 to disable all decorations,
10408 * but very few honor all possible combinations of bits.
10412 gdk_window_set_decorations (GdkWindow *window,
10413 GdkWMDecoration decorations)
10415 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10419 * gdk_window_get_decorations:
10420 * @window: The toplevel #GdkWindow to get the decorations from
10421 * @decorations: (out): The window decorations will be written here
10423 * Returns the decorations set on the GdkWindow with
10424 * gdk_window_set_decorations().
10426 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10429 gdk_window_get_decorations(GdkWindow *window,
10430 GdkWMDecoration *decorations)
10432 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10436 * gdk_window_set_functions:
10437 * @window: a toplevel #GdkWindow
10438 * @functions: bitmask of operations to allow on @window
10440 * Sets hints about the window management functions to make available
10441 * via buttons on the window frame.
10443 * On the X backend, this function sets the traditional Motif window
10444 * manager hint for this purpose. However, few window managers do
10445 * anything reliable or interesting with this hint. Many ignore it
10448 * The @functions argument is the logical OR of values from the
10449 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
10450 * then the other bits indicate which functions to disable; if
10451 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
10456 gdk_window_set_functions (GdkWindow *window,
10457 GdkWMFunction functions)
10459 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
10463 * gdk_window_begin_resize_drag_for_device:
10464 * @window: a toplevel #GdkWindow
10465 * @edge: the edge or corner from which the drag is started
10466 * @device: the device used for the operation
10467 * @button: the button being used to drag
10468 * @root_x: root window X coordinate of mouse click that began the drag
10469 * @root_y: root window Y coordinate of mouse click that began the drag
10470 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10472 * Begins a window resize operation (for a toplevel window).
10473 * You might use this function to implement a "window resize grip," for
10474 * example; in fact #GtkStatusbar uses it. The function works best
10475 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
10476 * fallback implementation for other window managers.
10481 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
10482 GdkWindowEdge edge,
10489 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
10493 * gdk_window_begin_resize_drag:
10494 * @window: a toplevel #GdkWindow
10495 * @edge: the edge or corner from which the drag is started
10496 * @button: the button being used to drag
10497 * @root_x: root window X coordinate of mouse click that began the drag
10498 * @root_y: root window Y coordinate of mouse click that began the drag
10499 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10501 * Begins a window resize operation (for a toplevel window).
10503 * This function assumes that the drag is controlled by the
10504 * client pointer device, use gdk_window_begin_resize_drag_for_device()
10505 * to begin a drag with a different device.
10508 gdk_window_begin_resize_drag (GdkWindow *window,
10509 GdkWindowEdge edge,
10515 GdkDeviceManager *device_manager;
10518 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10519 device = gdk_device_manager_get_client_pointer (device_manager);
10520 gdk_window_begin_resize_drag_for_device (window, edge,
10521 device, button, root_x, root_y, timestamp);
10525 * gdk_window_begin_move_drag_for_device:
10526 * @window: a toplevel #GdkWindow
10527 * @device: the device used for the operation
10528 * @button: the button being used to drag
10529 * @root_x: root window X coordinate of mouse click that began the drag
10530 * @root_y: root window Y coordinate of mouse click that began the drag
10531 * @timestamp: timestamp of mouse click that began the drag
10533 * Begins a window move operation (for a toplevel window).
10534 * You might use this function to implement a "window move grip," for
10535 * example. The function works best with window managers that support
10536 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
10537 * Window Manager Hints</ulink>, but has a fallback implementation for
10538 * other window managers.
10543 gdk_window_begin_move_drag_for_device (GdkWindow *window,
10550 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
10551 device, button, root_x, root_y, timestamp);
10555 * gdk_window_begin_move_drag:
10556 * @window: a toplevel #GdkWindow
10557 * @button: the button being used to drag
10558 * @root_x: root window X coordinate of mouse click that began the drag
10559 * @root_y: root window Y coordinate of mouse click that began the drag
10560 * @timestamp: timestamp of mouse click that began the drag
10562 * Begins a window move operation (for a toplevel window).
10564 * This function assumes that the drag is controlled by the
10565 * client pointer device, use gdk_window_begin_move_drag_for_device()
10566 * to begin a drag with a different device.
10569 gdk_window_begin_move_drag (GdkWindow *window,
10575 GdkDeviceManager *device_manager;
10578 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10579 device = gdk_device_manager_get_client_pointer (device_manager);
10580 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
10584 * gdk_window_enable_synchronized_configure:
10585 * @window: a toplevel #GdkWindow
10587 * Indicates that the application will cooperate with the window
10588 * system in synchronizing the window repaint with the window
10589 * manager during resizing operations. After an application calls
10590 * this function, it must call gdk_window_configure_finished() every
10591 * time it has finished all processing associated with a set of
10592 * Configure events. Toplevel GTK+ windows automatically use this
10595 * On X, calling this function makes @window participate in the
10596 * _NET_WM_SYNC_REQUEST window manager protocol.
10601 gdk_window_enable_synchronized_configure (GdkWindow *window)
10603 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
10607 * gdk_window_configure_finished:
10608 * @window: a toplevel #GdkWindow
10610 * Signal to the window system that the application has finished
10611 * handling Configure events it has received. Window Managers can
10612 * use this to better synchronize the frame repaint with the
10613 * application. GTK+ applications will automatically call this
10614 * function when appropriate.
10616 * This function can only be called if gdk_window_enable_synchronized_configure()
10617 * was called previously.
10622 gdk_window_configure_finished (GdkWindow *window)
10624 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
10628 * gdk_window_set_opacity:
10629 * @window: a top-level #GdkWindow
10630 * @opacity: opacity
10632 * Request the windowing system to make @window partially transparent,
10633 * with opacity 0 being fully transparent and 1 fully opaque. (Values
10634 * of the opacity parameter are clamped to the [0,1] range.)
10636 * On X11, this works only on X screens with a compositing manager
10639 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
10640 * For making non-toplevel windows translucent, see
10641 * gdk_window_set_composited().
10646 gdk_window_set_opacity (GdkWindow *window,
10649 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
10652 /* This function is called when the XWindow is really gone.
10655 gdk_window_destroy_notify (GdkWindow *window)
10657 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
10661 * gdk_window_register_dnd:
10662 * @window: a #GdkWindow.
10664 * Registers a window as a potential drop destination.
10667 gdk_window_register_dnd (GdkWindow *window)
10669 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
10673 * gdk_window_get_drag_protocol:
10674 * @window: the destination window
10675 * @target: (out) (allow-none) (transfer full): location of the window
10676 * where the drop should happen. This may be @window or a proxy window,
10677 * or %NULL if @window does not support Drag and Drop.
10679 * Finds out the DND protocol supported by a window.
10681 * Returns: the supported DND protocol.
10686 gdk_window_get_drag_protocol (GdkWindow *window,
10687 GdkWindow **target)
10689 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
10691 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
10696 * @window: the source window for this drag.
10697 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10698 * as list of #GdkAtoms
10700 * Starts a drag and creates a new drag context for it.
10701 * This function assumes that the drag is controlled by the
10702 * client pointer device, use gdk_drag_begin_for_device() to
10703 * begin a drag with a different device.
10705 * This function is called by the drag source.
10707 * Return value: (transfer full): a newly created #GdkDragContext
10710 gdk_drag_begin (GdkWindow *window,
10713 GdkDeviceManager *device_manager;
10716 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10717 device = gdk_device_manager_get_client_pointer (device_manager);
10719 return gdk_drag_begin_for_device (window, device, targets);
10723 * gdk_drag_begin_for_device:
10724 * @window: the source window for this drag
10725 * @device: the device that controls this drag
10726 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10727 * as list of #GdkAtoms
10729 * Starts a drag and creates a new drag context for it.
10731 * This function is called by the drag source.
10733 * Return value: (transfer full): a newly created #GdkDragContext
10736 gdk_drag_begin_for_device (GdkWindow *window,
10740 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
10744 * gdk_test_render_sync:
10745 * @window: a mapped #GdkWindow
10747 * Retrieves a pixel from @window to force the windowing
10748 * system to carry out any pending rendering commands.
10750 * This function is intended to be used to synchronize with rendering
10751 * pipelines, to benchmark windowing system rendering operations.
10756 gdk_test_render_sync (GdkWindow *window)
10758 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
10762 * gdk_test_simulate_key:
10763 * @window: a #GdkWindow to simulate a key event for
10764 * @x: x coordinate within @window for the key event
10765 * @y: y coordinate within @window for the key event
10766 * @keyval: A GDK keyboard value
10767 * @modifiers: Keyboard modifiers the event is setup with
10768 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
10770 * This function is intended to be used in GTK+ test programs.
10771 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
10772 * the given (@x,@y) coordinates within @window and simulate a
10773 * key press or release event.
10775 * When the mouse pointer is warped to the target location, use
10776 * of this function outside of test programs that run in their
10777 * own virtual windowing system (e.g. Xvfb) is not recommended.
10778 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
10779 * be warped and @window origin will be used as mouse pointer
10780 * location for the event.
10782 * Also, gdk_test_simulate_key() is a fairly low level function,
10783 * for most testing purposes, gtk_test_widget_send_key() is the
10784 * right function to call which will generate a key press event
10785 * followed by its accompanying key release event.
10787 * Returns: whether all actions necessary for a key event simulation
10788 * were carried out successfully
10793 gdk_test_simulate_key (GdkWindow *window,
10797 GdkModifierType modifiers,
10798 GdkEventType key_pressrelease)
10800 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10801 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
10805 * gdk_test_simulate_button:
10806 * @window: a #GdkWindow to simulate a button event for
10807 * @x: x coordinate within @window for the button event
10808 * @y: y coordinate within @window for the button event
10809 * @button: Number of the pointer button for the event, usually 1, 2 or 3
10810 * @modifiers: Keyboard modifiers the event is setup with
10811 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
10813 * This function is intended to be used in GTK+ test programs.
10814 * It will warp the mouse pointer to the given (@x,@y) coordinates
10815 * within @window and simulate a button press or release event.
10816 * Because the mouse pointer needs to be warped to the target
10817 * location, use of this function outside of test programs that
10818 * run in their own virtual windowing system (e.g. Xvfb) is not
10821 * Also, gdk_test_simulate_button() is a fairly low level function,
10822 * for most testing purposes, gtk_test_widget_click() is the right
10823 * function to call which will generate a button press event followed
10824 * by its accompanying button release event.
10826 * Returns: whether all actions necessary for a button event simulation
10827 * were carried out successfully
10832 gdk_test_simulate_button (GdkWindow *window,
10835 guint button, /*1..3*/
10836 GdkModifierType modifiers,
10837 GdkEventType button_pressrelease)
10839 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10840 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
10844 * gdk_property_get:
10845 * @window: a #GdkWindow
10846 * @property: the property to retrieve
10847 * @type: the desired property type, or %GDK_NONE, if any type of data
10848 * is acceptable. If this does not match the actual
10849 * type, then @actual_format and @actual_length will
10850 * be filled in, a warning will be printed to stderr
10851 * and no data will be returned.
10852 * @offset: the offset into the property at which to begin
10853 * retrieving data, in 4 byte units.
10854 * @length: the length of the data to retrieve in bytes. Data is
10855 * considered to be retrieved in 4 byte chunks, so @length
10856 * will be rounded up to the next highest 4 byte boundary
10857 * (so be careful not to pass a value that might overflow
10858 * when rounded up).
10859 * @pdelete: if %TRUE, delete the property after retrieving the
10861 * @actual_property_type: (out) (transfer none): location to store the
10862 * actual type of the property.
10863 * @actual_format: (out): location to store the actual return format of the
10864 * data; either 8, 16 or 32 bits.
10865 * @actual_length: location to store the length of the retrieved data, in
10866 * bytes. Data returned in the 32 bit format is stored
10867 * in a long variable, so the actual number of 32 bit
10868 * elements should be be calculated via
10869 * @actual_length / sizeof(glong) to ensure portability to
10871 * @data: (out) (array length=actual_length) (transfer full): location
10872 * to store a pointer to the data. The retrieved data should be
10873 * freed with g_free() when you are finished using it.
10875 * Retrieves a portion of the contents of a property. If the
10876 * property does not exist, then the function returns %FALSE,
10877 * and %GDK_NONE will be stored in @actual_property_type.
10881 * The XGetWindowProperty() function that gdk_property_get()
10882 * uses has a very confusing and complicated set of semantics.
10883 * Unfortunately, gdk_property_get() makes the situation
10884 * worse instead of better (the semantics should be considered
10885 * undefined), and also prints warnings to stderr in cases where it
10886 * should return a useful error to the program. You are advised to use
10887 * XGetWindowProperty() directly until a replacement function for
10888 * gdk_property_get()
10893 * Returns: %TRUE if data was successfully received and stored
10894 * in @data, otherwise %FALSE.
10897 gdk_property_get (GdkWindow *window,
10903 GdkAtom *actual_property_type,
10904 gint *actual_format_type,
10905 gint *actual_length,
10908 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10909 ->get_property (window, property, type, offset, length, pdelete,
10910 actual_property_type, actual_format_type,
10911 actual_length, data);
10915 * gdk_property_change: (skip)
10916 * @window: a #GdkWindow
10917 * @property: the property to change
10918 * @type: the new type for the property. If @mode is
10919 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
10920 * must match the existing type or an error will occur.
10921 * @format: the new format for the property. If @mode is
10922 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
10923 * must match the existing format or an error will occur.
10924 * @mode: a value describing how the new data is to be combined
10925 * with the current data.
10926 * @data: the data (a <literal>guchar *</literal>
10927 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
10928 * depending on @format), cast to a <literal>guchar *</literal>.
10929 * @nelements: the number of elements of size determined by the format,
10930 * contained in @data.
10932 * Changes the contents of a property on a window.
10935 gdk_property_change (GdkWindow *window,
10940 const guchar *data,
10943 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10944 ->change_property (window, property, type, format, mode, data, nelements);
10948 * gdk_property_delete:
10949 * @window: a #GdkWindow
10950 * @property: the property to delete
10952 * Deletes a property from a window.
10955 gdk_property_delete (GdkWindow *window,
10958 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);