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 cairo_region_t *flushed;
207 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 if (window->layered_region)
566 cairo_region_destroy (window->layered_region);
568 G_OBJECT_CLASS (parent_class)->finalize (object);
572 gdk_window_set_property (GObject *object,
577 GdkWindow *window = (GdkWindow *)object;
582 gdk_window_set_cursor (window, g_value_get_object (value));
586 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
592 gdk_window_get_property (GObject *object,
597 GdkWindow *window = (GdkWindow *) object;
602 g_value_set_object (value, gdk_window_get_cursor (window));
606 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
612 gdk_window_is_offscreen (GdkWindow *window)
614 return window->window_type == GDK_WINDOW_OFFSCREEN;
618 gdk_window_get_impl_window (GdkWindow *window)
620 return window->impl_window;
624 _gdk_window_get_impl_window (GdkWindow *window)
626 return gdk_window_get_impl_window (window);
630 gdk_window_has_impl (GdkWindow *window)
632 return window->impl_window == window;
636 gdk_window_is_toplevel (GdkWindow *window)
639 window->parent == NULL ||
640 window->parent->window_type == GDK_WINDOW_ROOT;
644 _gdk_window_has_impl (GdkWindow *window)
646 return gdk_window_has_impl (window);
650 gdk_window_has_no_impl (GdkWindow *window)
652 return window->impl_window != window;
656 remove_layered_child_area (GdkWindow *window,
657 cairo_region_t *region)
660 cairo_region_t *child_region;
664 for (l = window->children; l; l = l->next)
668 /* If region is empty already, no need to do
669 anything potentially costly */
670 if (cairo_region_is_empty (region))
673 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
676 /* Ignore offscreen children, as they don't draw in their parent and
677 * don't take part in the clipping */
678 if (gdk_window_is_offscreen (child))
681 /* Only non-impl children with alpha add to the layered region */
682 if (!child->has_alpha_background && gdk_window_has_impl (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);
697 /* Adjust shape region to parent window coords */
698 cairo_region_translate (child->shape, child->x, child->y);
699 cairo_region_intersect (child_region, child->shape);
700 cairo_region_translate (child->shape, -child->x, -child->y);
703 cairo_region_subtract (region, child_region);
704 cairo_region_destroy (child_region);
709 remove_child_area (GdkWindow *window,
712 cairo_region_t *region,
713 cairo_region_t *layered_region)
716 cairo_region_t *child_region;
719 cairo_region_t *shape;
721 for (l = window->children; l; l = l->next)
728 /* If region is empty already, no need to do
729 anything potentially costly */
730 if (cairo_region_is_empty (region))
733 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
736 /* Ignore offscreen children, as they don't draw in their parent and
737 * don't take part in the clipping */
738 if (gdk_window_is_offscreen (child))
743 r.width = child->width;
744 r.height = child->height;
746 /* Bail early if child totally outside region */
747 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
750 child_region = cairo_region_create_rectangle (&r);
754 /* Adjust shape region to parent window coords */
755 cairo_region_translate (child->shape, child->x, child->y);
756 cairo_region_intersect (child_region, child->shape);
757 cairo_region_translate (child->shape, -child->x, -child->y);
759 else if (window->window_type == GDK_WINDOW_FOREIGN)
761 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
764 cairo_region_intersect (child_region, shape);
765 cairo_region_destroy (shape);
771 if (child->input_shape)
772 cairo_region_intersect (child_region, child->input_shape);
773 else if (window->window_type == GDK_WINDOW_FOREIGN)
775 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
778 cairo_region_intersect (child_region, shape);
779 cairo_region_destroy (shape);
784 if (child->has_alpha_background)
786 if (layered_region != NULL)
787 cairo_region_union (layered_region, child_region);
790 cairo_region_subtract (region, child_region);
791 cairo_region_destroy (child_region);
795 static GdkVisibilityState
796 effective_visibility (GdkWindow *window)
798 GdkVisibilityState native;
800 if (!gdk_window_is_viewable (window))
801 return GDK_VISIBILITY_NOT_VIEWABLE;
803 native = window->impl_window->native_visibility;
805 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
806 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
807 return GDK_VISIBILITY_FULLY_OBSCURED;
808 else if (native == GDK_VISIBILITY_UNOBSCURED)
809 return window->visibility;
810 else /* native PARTIAL, private partial or unobscured */
811 return GDK_VISIBILITY_PARTIAL;
815 gdk_window_update_visibility (GdkWindow *window)
817 GdkVisibilityState new_visibility;
820 new_visibility = effective_visibility (window);
822 if (new_visibility != window->effective_visibility)
824 window->effective_visibility = new_visibility;
826 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
827 window->event_mask & GDK_VISIBILITY_NOTIFY_MASK)
829 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
831 event->visibility.state = new_visibility;
837 gdk_window_update_visibility_recursively (GdkWindow *window,
838 GdkWindow *only_for_impl)
843 gdk_window_update_visibility (window);
844 for (l = window->children; l != NULL; l = l->next)
847 if ((only_for_impl == NULL) ||
848 (only_for_impl == child->impl_window))
849 gdk_window_update_visibility_recursively (child, only_for_impl);
854 should_apply_clip_as_shape (GdkWindow *window)
857 gdk_window_has_impl (window) &&
858 /* Not for offscreens */
859 !gdk_window_is_offscreen (window) &&
860 /* or for toplevels */
861 !gdk_window_is_toplevel (window) &&
862 /* or for foreign windows */
863 window->window_type != GDK_WINDOW_FOREIGN &&
864 /* or for the root window */
865 window->window_type != GDK_WINDOW_ROOT;
869 apply_shape (GdkWindow *window,
870 cairo_region_t *region)
872 GdkWindowImplClass *impl_class;
874 /* We trash whether we applied a shape so that
875 we can avoid unsetting it many times, which
876 could happen in e.g. apply_clip_as_shape as
877 windows get resized */
878 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
880 impl_class->shape_combine_region (window,
882 else if (window->applied_shape)
883 impl_class->shape_combine_region (window,
886 window->applied_shape = region != NULL;
890 region_rect_equal (const cairo_region_t *region,
891 const GdkRectangle *rect)
893 GdkRectangle extents;
895 if (cairo_region_num_rectangles (region) != 1)
898 cairo_region_get_extents (region, &extents);
900 return extents.x == rect->x &&
901 extents.y == rect->y &&
902 extents.width == rect->width &&
903 extents.height == rect->height;
907 apply_clip_as_shape (GdkWindow *window)
912 r.width = window->width;
913 r.height = window->height;
915 /* We only apply the clip region if would differ
916 from the actual clip region implied by the size
917 of the window. This is to avoid unneccessarily
918 adding meaningless shapes to all native subwindows */
919 if (!region_rect_equal (window->clip_region, &r))
920 apply_shape (window, window->clip_region);
922 apply_shape (window, NULL);
926 recompute_visible_regions_internal (GdkWindow *private,
927 gboolean recalculate_clip,
928 gboolean recalculate_siblings,
929 gboolean recalculate_children)
934 cairo_region_t *new_clip, *new_layered;
935 gboolean clip_region_changed;
936 gboolean abs_pos_changed;
937 int old_abs_x, old_abs_y;
939 old_abs_x = private->abs_x;
940 old_abs_y = private->abs_y;
942 /* Update absolute position */
943 if (gdk_window_has_impl (private))
945 /* Native window starts here */
951 private->abs_x = private->parent->abs_x + private->x;
952 private->abs_y = private->parent->abs_y + private->y;
956 private->abs_x != old_abs_x ||
957 private->abs_y != old_abs_y;
959 /* Update clip region based on:
962 * siblings in parents above window
964 clip_region_changed = FALSE;
965 if (recalculate_clip)
967 new_layered = cairo_region_create ();
968 if (private->viewable)
970 /* Calculate visible region (sans children) in parent window coords */
973 r.width = private->width;
974 r.height = private->height;
975 new_clip = cairo_region_create_rectangle (&r);
977 if (!gdk_window_is_toplevel (private))
979 cairo_region_intersect (new_clip, private->parent->clip_region);
980 cairo_region_union (new_layered, private->parent->layered_region);
982 /* Remove all overlapping children from parent. */
983 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
986 /* Convert from parent coords to window coords */
987 cairo_region_translate (new_clip, -private->x, -private->y);
988 cairo_region_translate (new_layered, -private->x, -private->y);
991 cairo_region_intersect (new_clip, private->shape);
994 new_clip = cairo_region_create ();
996 cairo_region_intersect (new_layered, new_clip);
998 if (private->clip_region == NULL ||
999 !cairo_region_equal (private->clip_region, new_clip))
1000 clip_region_changed = TRUE;
1002 if (private->layered_region == NULL ||
1003 !cairo_region_equal (private->layered_region, new_layered))
1004 clip_region_changed = TRUE;
1006 if (private->clip_region)
1007 cairo_region_destroy (private->clip_region);
1008 private->clip_region = new_clip;
1010 if (private->layered_region != NULL)
1011 cairo_region_destroy (private->layered_region);
1012 private->layered_region = new_layered;
1014 if (private->clip_region_with_children)
1015 cairo_region_destroy (private->clip_region_with_children);
1016 private->clip_region_with_children = cairo_region_copy (private->clip_region);
1017 if (private->window_type != GDK_WINDOW_ROOT)
1018 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
1021 if (clip_region_changed)
1023 GdkVisibilityState visibility;
1024 gboolean fully_visible;
1026 if (cairo_region_is_empty (private->clip_region))
1027 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1032 fully_visible = cairo_region_equal (private->clip_region,
1039 r.width = private->width;
1040 r.height = private->height;
1041 fully_visible = region_rect_equal (private->clip_region, &r);
1045 visibility = GDK_VISIBILITY_UNOBSCURED;
1047 visibility = GDK_VISIBILITY_PARTIAL;
1050 if (private->visibility != visibility)
1052 private->visibility = visibility;
1053 gdk_window_update_visibility (private);
1057 /* Update all children, recursively (except for root, where children are not exact). */
1058 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1059 private->window_type != GDK_WINDOW_ROOT)
1061 for (l = private->children; l; l = l->next)
1064 /* Only recalculate clip if the the clip region changed, otherwise
1065 * there is no way the child clip region could change (its has not e.g. moved)
1066 * Except if recalculate_children is set to force child updates
1068 recompute_visible_regions_internal (child,
1069 recalculate_clip && (clip_region_changed || recalculate_children),
1074 if (clip_region_changed &&
1075 should_apply_clip_as_shape (private))
1076 apply_clip_as_shape (private);
1078 if (recalculate_siblings &&
1079 !gdk_window_is_toplevel (private))
1081 /* If we moved a child window in parent or changed the stacking order, then we
1082 * need to recompute the visible area of all the other children in the parent
1084 for (l = private->parent->children; l; l = l->next)
1088 if (child != private)
1089 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1092 /* We also need to recompute the _with_children clip for the parent */
1093 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1096 if (private->cairo_surface && gdk_window_has_impl (private))
1098 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1100 private->cairo_surface = iface->resize_cairo_surface (private,
1101 private->cairo_surface,
1105 else if (private->cairo_surface)
1106 gdk_window_drop_cairo_surface (private);
1109 /* Call this when private has changed in one or more of these ways:
1113 * stacking order of window changed
1116 * It will recalculate abs_x/y and the clip regions
1118 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1119 * for recalculate_siblings. (Mostly used internally for the recursion)
1121 * If a child window was removed (and you can't use that child for
1122 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1125 recompute_visible_regions (GdkWindow *private,
1126 gboolean recalculate_siblings,
1127 gboolean recalculate_children)
1129 recompute_visible_regions_internal (private,
1131 recalculate_siblings,
1132 recalculate_children);
1136 _gdk_window_update_size (GdkWindow *window)
1138 recompute_visible_regions (window, TRUE, FALSE);
1141 /* Find the native window that would be just above "child"
1142 * in the native stacking order if "child" was a native window
1143 * (it doesn't have to be native). If there is no such native
1144 * window inside this native parent then NULL is returned.
1145 * If child is NULL, find lowest native window in parent.
1148 find_native_sibling_above_helper (GdkWindow *parent,
1156 l = g_list_find (parent->children, child);
1157 g_assert (l != NULL); /* Better be a child of its parent... */
1158 l = l->prev; /* Start looking at the one above the child */
1161 l = g_list_last (parent->children);
1163 for (; l != NULL; l = l->prev)
1167 if (gdk_window_has_impl (w))
1170 g_assert (parent != w);
1171 w = find_native_sibling_above_helper (w, NULL);
1181 find_native_sibling_above (GdkWindow *parent,
1186 w = find_native_sibling_above_helper (parent, child);
1190 if (gdk_window_has_impl (parent))
1193 return find_native_sibling_above (parent->parent, parent);
1197 get_native_device_event_mask (GdkWindow *private,
1200 GdkEventMask event_mask;
1203 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1205 event_mask = private->event_mask;
1207 if (private->window_type == GDK_WINDOW_ROOT ||
1208 private->window_type == GDK_WINDOW_FOREIGN)
1214 /* Do whatever the app asks to, since the app
1215 * may be asking for weird things for native windows,
1216 * but don't use motion hints as that may affect non-native
1217 * child windows that don't want it. Also, we need to
1218 * set all the app-specified masks since they will be picked
1219 * up by any implicit grabs (i.e. if they were not set as
1220 * native we would not get the events we need). */
1221 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1223 /* We need thse for all native windows so we can
1224 emulate events on children: */
1227 GDK_VISIBILITY_NOTIFY_MASK |
1228 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1230 /* Additionally we select for pointer and button events
1231 * for toplevels as we need to get these to emulate
1232 * them for non-native subwindows. Even though we don't
1233 * select on them for all native windows we will get them
1234 * as the events are propagated out to the first window
1235 * that select for them.
1236 * Not selecting for button press on all windows is an
1237 * important thing, because in X only one client can do
1238 * so, and we don't want to unexpectedly prevent another
1239 * client from doing it.
1241 * We also need to do the same if the app selects for button presses
1242 * because then we will get implicit grabs for this window, and the
1243 * event mask used for that grab is based on the rest of the mask
1244 * for the window, but we might need more events than this window
1245 * lists due to some non-native child window.
1247 if (gdk_window_is_toplevel (private) ||
1248 mask & GDK_BUTTON_PRESS_MASK)
1250 GDK_POINTER_MOTION_MASK |
1251 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1259 get_native_grab_event_mask (GdkEventMask grab_mask)
1261 /* Similar to the above but for pointer events only */
1263 GDK_POINTER_MOTION_MASK |
1264 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1265 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1268 ~GDK_POINTER_MOTION_HINT_MASK);
1272 get_native_event_mask (GdkWindow *private)
1274 return get_native_device_event_mask (private, NULL);
1277 /* Puts the native window in the right order wrt the other native windows
1278 * in the hierarchy, given the position it has in the client side data.
1279 * This is useful if some operation changed the stacking order.
1280 * This calls assumes the native window is now topmost in its native parent.
1283 sync_native_window_stack_position (GdkWindow *window)
1286 GdkWindowImplClass *impl_class;
1287 GList listhead = {0};
1289 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1291 above = find_native_sibling_above (window->parent, window);
1294 listhead.data = window;
1295 impl_class->restack_under (above, &listhead);
1300 * gdk_window_new: (constructor)
1301 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1302 * the default root window for the default display.
1303 * @attributes: attributes of the new window
1304 * @attributes_mask: mask indicating which fields in @attributes are valid
1306 * Creates a new #GdkWindow using the attributes from
1307 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1308 * more details. Note: to use this on displays other than the default
1309 * display, @parent must be specified.
1311 * Return value: (transfer full): the new #GdkWindow
1314 gdk_window_new (GdkWindow *parent,
1315 GdkWindowAttr *attributes,
1316 gint attributes_mask)
1320 GdkDisplay *display;
1323 GdkEventMask event_mask;
1324 GdkWindow *real_parent;
1325 GdkDeviceManager *device_manager;
1327 g_return_val_if_fail (attributes != NULL, NULL);
1331 GDK_NOTE (MULTIHEAD,
1332 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1334 screen = gdk_screen_get_default ();
1335 parent = gdk_screen_get_root_window (screen);
1338 screen = gdk_window_get_screen (parent);
1340 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1342 if (GDK_WINDOW_DESTROYED (parent))
1344 g_warning ("gdk_window_new(): parent is destroyed\n");
1348 display = gdk_screen_get_display (screen);
1350 window = _gdk_display_create_window (display);
1352 /* Windows with a foreign parent are treated as if they are children
1353 * of the root window, except for actual creation.
1355 real_parent = parent;
1356 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1357 parent = gdk_screen_get_root_window (screen);
1359 window->parent = parent;
1361 window->accept_focus = TRUE;
1362 window->focus_on_map = TRUE;
1364 if (attributes_mask & GDK_WA_X)
1369 if (attributes_mask & GDK_WA_Y)
1376 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1377 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1379 if (attributes->wclass == GDK_INPUT_ONLY)
1381 /* Backwards compatiblity - we've always ignored
1382 * attributes->window_type for input-only windows
1385 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1386 window->window_type = GDK_WINDOW_TEMP;
1388 window->window_type = GDK_WINDOW_CHILD;
1391 window->window_type = attributes->window_type;
1394 switch (window->window_type)
1396 case GDK_WINDOW_TOPLEVEL:
1397 case GDK_WINDOW_TEMP:
1398 case GDK_WINDOW_OFFSCREEN:
1399 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1400 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1401 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1402 case GDK_WINDOW_CHILD:
1406 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1410 if (attributes_mask & GDK_WA_VISUAL)
1411 window->visual = attributes->visual;
1413 window->visual = gdk_screen_get_system_visual (screen);
1415 window->event_mask = attributes->event_mask;
1417 if (attributes->wclass == GDK_INPUT_OUTPUT)
1419 window->input_only = FALSE;
1420 window->depth = window->visual->depth;
1422 /* XXX: Cache this somehow? */
1423 window->background = cairo_pattern_create_rgba (0, 0, 0, 0);
1424 window->has_alpha_background = TRUE;
1429 window->input_only = TRUE;
1433 window->parent->children = g_list_prepend (window->parent->children, window);
1436 if (window->parent->window_type == GDK_WINDOW_ROOT)
1437 native = TRUE; /* Always use native windows for toplevels */
1438 else if (!window->input_only &&
1439 (attributes_mask & GDK_WA_VISUAL &&
1440 attributes->visual != gdk_window_get_visual (window->parent)))
1441 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1443 if (gdk_window_is_offscreen (window))
1445 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1446 window->impl_window = window;
1450 event_mask = get_native_event_mask (window);
1452 /* Create the impl */
1453 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1454 window->impl_window = window;
1456 /* This will put the native window topmost in the native parent, which may
1457 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1458 if (!_gdk_window_has_impl (real_parent))
1459 sync_native_window_stack_position (window);
1463 window->impl_window = g_object_ref (window->parent->impl_window);
1464 window->impl = g_object_ref (window->impl_window->impl);
1467 recompute_visible_regions (window, TRUE, FALSE);
1469 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1470 (attributes->cursor) :
1473 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1474 g_signal_connect (device_manager, "device-removed",
1475 G_CALLBACK (device_removed_cb), window);
1481 is_parent_of (GdkWindow *parent,
1492 w = gdk_window_get_parent (w);
1499 change_impl (GdkWindow *private,
1500 GdkWindow *impl_window,
1505 GdkWindowImpl *old_impl;
1506 GdkWindow *old_impl_window;
1508 old_impl = private->impl;
1509 old_impl_window = private->impl_window;
1510 if (private != impl_window)
1511 private->impl_window = g_object_ref (impl_window);
1513 private->impl_window = private;
1514 private->impl = g_object_ref (new);
1515 if (old_impl_window != private)
1516 g_object_unref (old_impl_window);
1517 g_object_unref (old_impl);
1519 for (l = private->children; l != NULL; l = l->next)
1523 if (child->impl == old_impl)
1524 change_impl (child, impl_window, new);
1529 reparent_to_impl (GdkWindow *private)
1534 GdkWindowImplClass *impl_class;
1536 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1538 /* Enumerate in reverse order so we get the right order for the native
1539 windows (first in childrens list is topmost, and reparent places on top) */
1540 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1544 if (child->impl == private->impl)
1545 reparent_to_impl (child);
1548 show = impl_class->reparent ((GdkWindow *)child,
1549 (GdkWindow *)private,
1550 child->x, child->y);
1552 gdk_window_show_unraised ((GdkWindow *)child);
1559 * gdk_window_reparent:
1560 * @window: a #GdkWindow
1561 * @new_parent: new parent to move @window into
1562 * @x: X location inside the new parent
1563 * @y: Y location inside the new parent
1565 * Reparents @window into the given @new_parent. The window being
1566 * reparented will be unmapped as a side effect.
1570 gdk_window_reparent (GdkWindow *window,
1571 GdkWindow *new_parent,
1575 GdkWindow *old_parent;
1577 gboolean show, was_mapped, applied_clip_as_shape;
1578 gboolean do_reparent_to_impl;
1579 GdkEventMask old_native_event_mask;
1580 GdkWindowImplClass *impl_class;
1582 g_return_if_fail (GDK_IS_WINDOW (window));
1583 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1584 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1586 if (GDK_WINDOW_DESTROYED (window) ||
1587 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1590 screen = gdk_window_get_screen (window);
1592 new_parent = gdk_screen_get_root_window (screen);
1594 /* No input-output children of input-only windows */
1595 if (new_parent->input_only && !window->input_only)
1598 /* Don't create loops in hierarchy */
1599 if (is_parent_of (window, new_parent))
1602 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1603 To make sure we're ok, just wipe it. */
1604 gdk_window_drop_cairo_surface (window);
1606 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1607 old_parent = window->parent;
1609 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1612 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1613 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1614 new_parent->window_type == GDK_WINDOW_FOREIGN)
1615 gdk_window_ensure_native (window);
1617 applied_clip_as_shape = should_apply_clip_as_shape (window);
1619 old_native_event_mask = 0;
1620 do_reparent_to_impl = FALSE;
1621 if (gdk_window_has_impl (window))
1623 old_native_event_mask = get_native_event_mask (window);
1625 show = impl_class->reparent (window, new_parent, x, y);
1629 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1630 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1631 new_parent->window_type != GDK_WINDOW_FOREIGN);
1634 gdk_window_hide (window);
1636 do_reparent_to_impl = TRUE;
1637 change_impl (window,
1638 new_parent->impl_window,
1642 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1645 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1647 new_parent = gdk_screen_get_root_window (screen);
1651 old_parent->children = g_list_remove (old_parent->children, window);
1653 window->parent = new_parent;
1657 new_parent->children = g_list_prepend (new_parent->children, window);
1659 /* Switch the window type as appropriate */
1661 switch (GDK_WINDOW_TYPE (new_parent))
1663 case GDK_WINDOW_ROOT:
1664 case GDK_WINDOW_FOREIGN:
1665 if (window->toplevel_window_type != -1)
1666 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1667 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1668 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1670 case GDK_WINDOW_OFFSCREEN:
1671 case GDK_WINDOW_TOPLEVEL:
1672 case GDK_WINDOW_CHILD:
1673 case GDK_WINDOW_TEMP:
1674 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1675 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1677 /* Save the original window type so we can restore it if the
1678 * window is reparented back to be a toplevel
1680 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1681 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1685 /* We might have changed window type for a native windows, so we
1686 need to change the event mask too. */
1687 if (gdk_window_has_impl (window))
1689 GdkEventMask native_event_mask = get_native_event_mask (window);
1691 if (native_event_mask != old_native_event_mask)
1692 impl_class->set_events (window, native_event_mask);
1695 _gdk_window_update_viewable (window);
1697 if (window->background == NULL)
1699 /* parent relative background, update has_alpha_background */
1700 if (window->parent == NULL ||
1701 window->parent->window_type == GDK_WINDOW_ROOT)
1702 window->has_alpha_background = FALSE;
1704 window->has_alpha_background = window->parent->has_alpha_background;
1707 recompute_visible_regions (window, TRUE, FALSE);
1708 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1709 recompute_visible_regions (old_parent, FALSE, TRUE);
1711 _gdk_window_propagate_has_alpha_background (window);
1713 /* We used to apply the clip as the shape, but no more.
1714 Reset this to the real shape */
1715 if (gdk_window_has_impl (window) &&
1716 applied_clip_as_shape &&
1717 !should_apply_clip_as_shape (window))
1718 apply_shape (window, window->shape);
1720 if (do_reparent_to_impl)
1721 reparent_to_impl (window);
1724 /* The reparent will have put the native window topmost in the native parent,
1725 * which may be wrong wrt other native windows in the non-native hierarchy,
1727 if (!gdk_window_has_impl (new_parent))
1728 sync_native_window_stack_position (window);
1732 gdk_window_show_unraised (window);
1734 _gdk_synthesize_crossing_events_for_geometry_change (window);
1738 * gdk_window_ensure_native:
1739 * @window: a #GdkWindow
1741 * Tries to ensure that there is a window-system native window for this
1742 * GdkWindow. This may fail in some situations, returning %FALSE.
1744 * Offscreen window and children of them can never have native windows.
1746 * Some backends may not support native child windows.
1748 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1753 gdk_window_ensure_native (GdkWindow *window)
1755 GdkWindow *impl_window;
1756 GdkWindowImpl *new_impl, *old_impl;
1757 GdkDisplay *display;
1761 GdkWindowImplClass *impl_class;
1763 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1765 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1766 GDK_WINDOW_DESTROYED (window))
1769 impl_window = gdk_window_get_impl_window (window);
1771 if (gdk_window_is_offscreen (impl_window))
1772 return FALSE; /* native in offscreens not supported */
1774 if (impl_window == window)
1775 /* Already has an impl, and its not offscreen . */
1778 /* Need to create a native window */
1780 gdk_window_drop_cairo_surface (window);
1782 screen = gdk_window_get_screen (window);
1783 display = gdk_screen_get_display (screen);
1785 old_impl = window->impl;
1786 _gdk_display_create_window_impl (display,
1787 window, window->parent,
1789 get_native_event_mask (window),
1791 new_impl = window->impl;
1793 window->impl = old_impl;
1794 change_impl (window, window, new_impl);
1796 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1798 /* Native window creation will put the native window topmost in the
1799 * native parent, which may be wrong wrt the position of the previous
1800 * non-native window wrt to the other non-native children, so correct this.
1802 above = find_native_sibling_above (window->parent, window);
1805 listhead.data = window;
1806 listhead.prev = NULL;
1807 listhead.next = NULL;
1808 impl_class->restack_under ((GdkWindow *)above, &listhead);
1811 recompute_visible_regions (window, FALSE, FALSE);
1813 /* The shape may not have been set, as the clip region doesn't actually
1814 change, so do it here manually */
1815 if (should_apply_clip_as_shape (window))
1816 apply_clip_as_shape (window);
1818 reparent_to_impl (window);
1820 if (!window->input_only)
1821 impl_class->set_background (window, window->background);
1823 impl_class->input_shape_combine_region (window,
1824 window->input_shape,
1827 if (gdk_window_is_viewable (window))
1828 impl_class->show (window, FALSE);
1834 * _gdk_event_filter_unref:
1835 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1836 * @filter: A window filter
1838 * Release a reference to @filter. Note this function may
1839 * mutate the list storage, so you need to handle this
1840 * if iterating over a list of filters.
1843 _gdk_event_filter_unref (GdkWindow *window,
1844 GdkEventFilter *filter)
1850 filters = &_gdk_default_filters;
1852 filters = &window->filters;
1854 tmp_list = *filters;
1857 GdkEventFilter *iter_filter = tmp_list->data;
1861 tmp_list = tmp_list->next;
1863 if (iter_filter != filter)
1866 g_assert (iter_filter->ref_count > 0);
1868 filter->ref_count--;
1869 if (filter->ref_count != 0)
1872 *filters = g_list_remove_link (*filters, node);
1874 g_list_free_1 (node);
1879 window_remove_filters (GdkWindow *window)
1881 while (window->filters)
1882 _gdk_event_filter_unref (window, window->filters->data);
1886 update_pointer_info_foreach (GdkDisplay *display,
1888 GdkPointerWindowInfo *pointer_info,
1891 GdkWindow *window = user_data;
1893 if (pointer_info->toplevel_under_pointer == window)
1895 g_object_unref (pointer_info->toplevel_under_pointer);
1896 pointer_info->toplevel_under_pointer = NULL;
1901 window_remove_from_pointer_info (GdkWindow *window,
1902 GdkDisplay *display)
1904 _gdk_display_pointer_info_foreach (display,
1905 update_pointer_info_foreach,
1910 * _gdk_window_destroy_hierarchy:
1911 * @window: a #GdkWindow
1912 * @recursing: If TRUE, then this is being called because a parent
1914 * @recursing_native: If TRUE, then this is being called because a native parent
1915 * was destroyed. This generally means that the call to the
1916 * windowing system to destroy the window can be omitted, since
1917 * it will be destroyed as a result of the parent being destroyed.
1918 * Unless @foreign_destroy.
1919 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1920 * external agency. The window has already been destroyed and no
1921 * windowing system calls should be made. (This may never happen
1922 * for some windowing systems.)
1924 * Internal function to destroy a window. Like gdk_window_destroy(),
1925 * but does not drop the reference count created by gdk_window_new().
1928 _gdk_window_destroy_hierarchy (GdkWindow *window,
1930 gboolean recursing_native,
1931 gboolean foreign_destroy)
1933 GdkWindowImplClass *impl_class;
1934 GdkWindow *temp_window;
1936 GdkDisplay *display;
1940 g_return_if_fail (GDK_IS_WINDOW (window));
1942 if (GDK_WINDOW_DESTROYED (window))
1945 display = gdk_window_get_display (window);
1946 screen = gdk_window_get_screen (window);
1947 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1948 if (temp_window == window)
1949 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1952 switch (window->window_type)
1954 case GDK_WINDOW_ROOT:
1955 if (!screen->closed)
1957 g_error ("attempted to destroy root window");
1960 /* else fall thru */
1961 case GDK_WINDOW_TOPLEVEL:
1962 case GDK_WINDOW_CHILD:
1963 case GDK_WINDOW_TEMP:
1964 case GDK_WINDOW_FOREIGN:
1965 case GDK_WINDOW_OFFSCREEN:
1966 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1968 /* Logically, it probably makes more sense to send
1969 * a "destroy yourself" message to the foreign window
1970 * whether or not it's in our hierarchy; but for historical
1971 * reasons, we only send "destroy yourself" messages to
1972 * foreign windows in our hierarchy.
1976 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1978 if (gdk_window_has_impl (window))
1979 impl_class->destroy_foreign (window);
1982 /* Also for historical reasons, we remove any filters
1983 * on a foreign window when it or a parent is destroyed;
1984 * this likely causes problems if two separate portions
1985 * of code are maintaining filter lists on a foreign window.
1987 window_remove_filters (window);
1993 if (window->parent->children)
1994 window->parent->children = g_list_remove (window->parent->children, window);
1997 GDK_WINDOW_IS_MAPPED (window))
1999 recompute_visible_regions (window, TRUE, FALSE);
2000 gdk_window_invalidate_in_parent (window);
2004 gdk_window_free_paint_stack (window);
2006 if (window->background)
2008 cairo_pattern_destroy (window->background);
2009 window->background = NULL;
2012 if (window->window_type == GDK_WINDOW_FOREIGN)
2013 g_assert (window->children == NULL);
2016 children = tmp = window->children;
2017 window->children = NULL;
2021 temp_window = tmp->data;
2025 _gdk_window_destroy_hierarchy (temp_window,
2027 recursing_native || gdk_window_has_impl (window),
2031 g_list_free (children);
2034 _gdk_window_clear_update_area (window);
2036 gdk_window_drop_cairo_surface (window);
2038 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2040 if (gdk_window_has_impl (window))
2041 impl_class->destroy (window, recursing_native,
2045 /* hide to make sure we repaint and break grabs */
2046 gdk_window_hide (window);
2049 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2050 window->parent = NULL;
2051 window->destroyed = TRUE;
2053 window_remove_filters (window);
2055 window_remove_from_pointer_info (window, display);
2057 if (window->clip_region)
2059 cairo_region_destroy (window->clip_region);
2060 window->clip_region = NULL;
2063 if (window->clip_region_with_children)
2065 cairo_region_destroy (window->clip_region_with_children);
2066 window->clip_region_with_children = NULL;
2069 g_list_free_full (window->outstanding_moves, (GDestroyNotify) gdk_window_region_move_free);
2070 window->outstanding_moves = NULL;
2077 * _gdk_window_destroy:
2078 * @window: a #GdkWindow
2079 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2080 * external agency. The window has already been destroyed and no
2081 * windowing system calls should be made. (This may never happen
2082 * for some windowing systems.)
2084 * Internal function to destroy a window. Like gdk_window_destroy(),
2085 * but does not drop the reference count created by gdk_window_new().
2088 _gdk_window_destroy (GdkWindow *window,
2089 gboolean foreign_destroy)
2091 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2095 * gdk_window_destroy:
2096 * @window: a #GdkWindow
2098 * Destroys the window system resources associated with @window and decrements @window's
2099 * reference count. The window system resources for all children of @window are also
2100 * destroyed, but the children's reference counts are not decremented.
2102 * Note that a window will not be destroyed automatically when its reference count
2103 * reaches zero. You must call this function yourself before that happens.
2107 gdk_window_destroy (GdkWindow *window)
2109 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2110 g_object_unref (window);
2114 * gdk_window_set_user_data:
2115 * @window: a #GdkWindow
2116 * @user_data: (allow-none) (type GObject.Object): user data
2118 * For most purposes this function is deprecated in favor of
2119 * g_object_set_data(). However, for historical reasons GTK+ stores
2120 * the #GtkWidget that owns a #GdkWindow as user data on the
2121 * #GdkWindow. So, custom widget implementations should use
2122 * this function for that. If GTK+ receives an event for a #GdkWindow,
2123 * and the user data for the window is non-%NULL, GTK+ will assume the
2124 * user data is a #GtkWidget, and forward the event to that widget.
2128 gdk_window_set_user_data (GdkWindow *window,
2131 g_return_if_fail (GDK_IS_WINDOW (window));
2133 window->user_data = user_data;
2137 * gdk_window_get_user_data:
2138 * @window: a #GdkWindow
2139 * @data: (out): return location for user data
2141 * Retrieves the user data for @window, which is normally the widget
2142 * that @window belongs to. See gdk_window_set_user_data().
2146 gdk_window_get_user_data (GdkWindow *window,
2149 g_return_if_fail (GDK_IS_WINDOW (window));
2151 *data = window->user_data;
2155 * gdk_window_get_window_type:
2156 * @window: a #GdkWindow
2158 * Gets the type of the window. See #GdkWindowType.
2160 * Return value: type of window
2163 gdk_window_get_window_type (GdkWindow *window)
2165 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2167 return GDK_WINDOW_TYPE (window);
2171 * gdk_window_get_visual:
2172 * @window: a #GdkWindow
2174 * Gets the #GdkVisual describing the pixel format of @window.
2176 * Return value: (transfer none): a #GdkVisual
2181 gdk_window_get_visual (GdkWindow *window)
2183 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2185 return window->visual;
2189 * gdk_window_get_screen:
2190 * @window: a #GdkWindow
2192 * Gets the #GdkScreen associated with a #GdkWindow.
2194 * Return value: (transfer none): the #GdkScreen associated with @window
2199 gdk_window_get_screen (GdkWindow *window)
2201 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2203 return gdk_visual_get_screen (window->visual);
2207 * gdk_window_get_display:
2208 * @window: a #GdkWindow
2210 * Gets the #GdkDisplay associated with a #GdkWindow.
2212 * Return value: (transfer none): the #GdkDisplay associated with @window
2217 gdk_window_get_display (GdkWindow *window)
2219 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2221 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2224 * gdk_window_is_destroyed:
2225 * @window: a #GdkWindow
2227 * Check to see if a window is destroyed..
2229 * Return value: %TRUE if the window is destroyed
2234 gdk_window_is_destroyed (GdkWindow *window)
2236 return GDK_WINDOW_DESTROYED (window);
2240 to_embedder (GdkWindow *window,
2241 gdouble offscreen_x,
2242 gdouble offscreen_y,
2243 gdouble *embedder_x,
2244 gdouble *embedder_y)
2246 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2247 offscreen_x, offscreen_y,
2248 embedder_x, embedder_y);
2252 from_embedder (GdkWindow *window,
2255 gdouble *offscreen_x,
2256 gdouble *offscreen_y)
2258 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2259 embedder_x, embedder_y,
2260 offscreen_x, offscreen_y);
2264 * gdk_window_has_native:
2265 * @window: a #GdkWindow
2267 * Checks whether the window has a native window or not. Note that
2268 * you can use gdk_window_ensure_native() if a native window is needed.
2270 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2275 gdk_window_has_native (GdkWindow *window)
2277 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2279 return window->parent == NULL || window->parent->impl != window->impl;
2283 * gdk_window_get_position:
2284 * @window: a #GdkWindow
2285 * @x: (out) (allow-none): X coordinate of window
2286 * @y: (out) (allow-none): Y coordinate of window
2288 * Obtains the position of the window as reported in the
2289 * most-recently-processed #GdkEventConfigure. Contrast with
2290 * gdk_window_get_geometry() which queries the X server for the
2291 * current window position, regardless of which events have been
2292 * received or processed.
2294 * The position coordinates are relative to the window's parent window.
2298 gdk_window_get_position (GdkWindow *window,
2302 g_return_if_fail (GDK_IS_WINDOW (window));
2311 * gdk_window_get_parent:
2312 * @window: a #GdkWindow
2314 * Obtains the parent of @window, as known to GDK. Does not query the
2315 * X server; thus this returns the parent as passed to gdk_window_new(),
2316 * not the actual parent. This should never matter unless you're using
2317 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2318 * matter for toplevel windows, because the window manager may choose
2321 * Note that you should use gdk_window_get_effective_parent() when
2322 * writing generic code that walks up a window hierarchy, because
2323 * gdk_window_get_parent() will most likely not do what you expect if
2324 * there are offscreen windows in the hierarchy.
2326 * Return value: (transfer none): parent of @window
2329 gdk_window_get_parent (GdkWindow *window)
2331 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2333 return window->parent;
2337 * gdk_window_get_effective_parent:
2338 * @window: a #GdkWindow
2340 * Obtains the parent of @window, as known to GDK. Works like
2341 * gdk_window_get_parent() for normal windows, but returns the
2342 * window's embedder for offscreen windows.
2344 * See also: gdk_offscreen_window_get_embedder()
2346 * Return value: (transfer none): effective parent of @window
2351 gdk_window_get_effective_parent (GdkWindow *window)
2353 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2355 if (gdk_window_is_offscreen (window))
2356 return gdk_offscreen_window_get_embedder (window);
2358 return window->parent;
2362 * gdk_window_get_toplevel:
2363 * @window: a #GdkWindow
2365 * Gets the toplevel window that's an ancestor of @window.
2367 * Any window type but %GDK_WINDOW_CHILD is considered a
2368 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2369 * has a root window as parent.
2371 * Note that you should use gdk_window_get_effective_toplevel() when
2372 * you want to get to a window's toplevel as seen on screen, because
2373 * gdk_window_get_toplevel() will most likely not do what you expect
2374 * if there are offscreen windows in the hierarchy.
2376 * Return value: (transfer none): the toplevel window containing @window
2379 gdk_window_get_toplevel (GdkWindow *window)
2381 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2383 while (window->window_type == GDK_WINDOW_CHILD)
2385 if (gdk_window_is_toplevel (window))
2387 window = window->parent;
2394 * gdk_window_get_effective_toplevel:
2395 * @window: a #GdkWindow
2397 * Gets the toplevel window that's an ancestor of @window.
2399 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2400 * embedder as its parent, using gdk_window_get_effective_parent().
2402 * See also: gdk_offscreen_window_get_embedder()
2404 * Return value: (transfer none): the effective toplevel window containing @window
2409 gdk_window_get_effective_toplevel (GdkWindow *window)
2413 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2415 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2416 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2423 * gdk_window_get_children:
2424 * @window: a #GdkWindow
2426 * Gets the list of children of @window known to GDK.
2427 * This function only returns children created via GDK,
2428 * so for example it's useless when used with the root window;
2429 * it only returns windows an application created itself.
2431 * The returned list must be freed, but the elements in the
2434 * Return value: (transfer container) (element-type GdkWindow):
2435 * list of child windows inside @window
2438 gdk_window_get_children (GdkWindow *window)
2440 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2442 if (GDK_WINDOW_DESTROYED (window))
2445 return g_list_copy (window->children);
2449 * gdk_window_peek_children:
2450 * @window: a #GdkWindow
2452 * Like gdk_window_get_children(), but does not copy the list of
2453 * children, so the list does not need to be freed.
2455 * Return value: (transfer none) (element-type GdkWindow):
2456 * a reference to the list of child windows in @window
2459 gdk_window_peek_children (GdkWindow *window)
2461 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2463 if (GDK_WINDOW_DESTROYED (window))
2466 return window->children;
2470 * gdk_window_add_filter: (skip)
2471 * @window: (allow-none): a #GdkWindow
2472 * @function: filter callback
2473 * @data: data to pass to filter callback
2475 * Adds an event filter to @window, allowing you to intercept events
2476 * before they reach GDK. This is a low-level operation and makes it
2477 * easy to break GDK and/or GTK+, so you have to know what you're
2478 * doing. Pass %NULL for @window to get all events for all windows,
2479 * instead of events for a specific window.
2481 * If you are interested in X GenericEvents, bear in mind that
2482 * XGetEventData() has been already called on the event, and
2483 * XFreeEventData() must not be called within @function.
2486 gdk_window_add_filter (GdkWindow *window,
2487 GdkFilterFunc function,
2491 GdkEventFilter *filter;
2493 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2495 if (window && GDK_WINDOW_DESTROYED (window))
2498 /* Filters are for the native events on the native window, so
2499 ensure there is a native window. */
2501 gdk_window_ensure_native (window);
2504 tmp_list = window->filters;
2506 tmp_list = _gdk_default_filters;
2510 filter = (GdkEventFilter *)tmp_list->data;
2511 if ((filter->function == function) && (filter->data == data))
2513 filter->ref_count++;
2516 tmp_list = tmp_list->next;
2519 filter = g_new (GdkEventFilter, 1);
2520 filter->function = function;
2521 filter->data = data;
2522 filter->ref_count = 1;
2526 window->filters = g_list_append (window->filters, filter);
2528 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2532 * gdk_window_remove_filter: (skip)
2533 * @window: a #GdkWindow
2534 * @function: previously-added filter function
2535 * @data: user data for previously-added filter function
2537 * Remove a filter previously added with gdk_window_add_filter().
2540 gdk_window_remove_filter (GdkWindow *window,
2541 GdkFilterFunc function,
2545 GdkEventFilter *filter;
2547 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2550 tmp_list = window->filters;
2552 tmp_list = _gdk_default_filters;
2556 filter = (GdkEventFilter *)tmp_list->data;
2557 tmp_list = tmp_list->next;
2559 if ((filter->function == function) && (filter->data == data))
2561 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2563 _gdk_event_filter_unref (window, filter);
2571 * gdk_screen_get_toplevel_windows:
2572 * @screen: The #GdkScreen where the toplevels are located.
2574 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2575 * A toplevel window is a child of the root window (see
2576 * gdk_get_default_root_window()).
2578 * The returned list should be freed with g_list_free(), but
2579 * its elements need not be freed.
2581 * Return value: (transfer container) (element-type GdkWindow):
2582 * list of toplevel windows, free with g_list_free()
2587 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2589 GdkWindow * root_window;
2590 GList *new_list = NULL;
2593 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2595 root_window = gdk_screen_get_root_window (screen);
2597 tmp_list = root_window->children;
2600 GdkWindow *w = tmp_list->data;
2602 if (w->window_type != GDK_WINDOW_FOREIGN)
2603 new_list = g_list_prepend (new_list, w);
2604 tmp_list = tmp_list->next;
2611 * gdk_window_is_visible:
2612 * @window: a #GdkWindow
2614 * Checks whether the window has been mapped (with gdk_window_show() or
2615 * gdk_window_show_unraised()).
2617 * Return value: %TRUE if the window is mapped
2620 gdk_window_is_visible (GdkWindow *window)
2622 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2624 return GDK_WINDOW_IS_MAPPED (window);
2628 * gdk_window_is_viewable:
2629 * @window: a #GdkWindow
2631 * Check if the window and all ancestors of the window are
2632 * mapped. (This is not necessarily "viewable" in the X sense, since
2633 * we only check as far as we have GDK window parents, not to the root
2636 * Return value: %TRUE if the window is viewable
2639 gdk_window_is_viewable (GdkWindow *window)
2641 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2643 if (window->destroyed)
2646 return window->viewable;
2650 * gdk_window_get_state:
2651 * @window: a #GdkWindow
2653 * Gets the bitwise OR of the currently active window state flags,
2654 * from the #GdkWindowState enumeration.
2656 * Return value: window state bitfield
2659 gdk_window_get_state (GdkWindow *window)
2661 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2663 return window->state;
2666 static cairo_content_t
2667 gdk_window_get_content (GdkWindow *window)
2669 cairo_surface_t *surface;
2670 cairo_content_t content;
2672 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2674 surface = _gdk_window_ref_cairo_surface (window);
2675 content = cairo_surface_get_content (surface);
2676 cairo_surface_destroy (surface);
2681 /* This creates an empty "implicit" paint region for the impl window.
2682 * By itself this does nothing, but real paints to this window
2683 * or children of it can use this surface as backing to avoid allocating
2684 * multiple surfaces for subwindow rendering. When doing so they
2685 * add to the region of the implicit paint region, which will be
2686 * pushed to the window when the implicit paint region is ended.
2687 * Such paints should not copy anything to the window on paint end, but
2688 * should rely on the implicit paint end.
2689 * The implicit paint will be automatically ended if someone draws
2690 * directly to the window or a child window.
2693 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2695 GdkWindowPaint *paint;
2697 g_assert (gdk_window_has_impl (window));
2699 if (GDK_IS_PAINTABLE (window->impl))
2700 return FALSE; /* Implementation does double buffering */
2702 if (window->paint_stack != NULL ||
2703 window->implicit_paint != NULL)
2704 return FALSE; /* Don't stack implicit paints */
2706 /* Never do implicit paints for foreign windows, they don't need
2707 * double buffer combination since they have no client side children,
2708 * and creating surfaces for them is risky since they could disappear
2711 if (window->window_type == GDK_WINDOW_FOREIGN)
2714 paint = g_new (GdkWindowPaint, 1);
2715 paint->region = cairo_region_create (); /* Empty */
2716 paint->uses_implicit = FALSE;
2717 paint->flushed = NULL;
2718 paint->surface = gdk_window_create_similar_surface (window,
2719 gdk_window_get_content (window),
2720 MAX (rect->width, 1),
2721 MAX (rect->height, 1));
2722 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2724 window->implicit_paint = paint;
2729 static cairo_surface_t *
2730 gdk_window_ref_impl_surface (GdkWindow *window)
2732 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2736 gdk_cairo_create_for_impl (GdkWindow *window)
2738 cairo_surface_t *surface;
2741 surface = gdk_window_ref_impl_surface (window);
2742 cr = cairo_create (surface);
2744 cairo_surface_destroy (surface);
2749 /* Ensure that all content related to this (sub)window is pushed to the
2750 native region. If there is an active paint then that area is not
2751 pushed, in order to not show partially finished double buffers. */
2753 gdk_window_flush_implicit_paint (GdkWindow *window)
2755 GdkWindow *impl_window;
2756 GdkWindowPaint *paint;
2757 cairo_region_t *region;
2760 impl_window = gdk_window_get_impl_window (window);
2761 if (impl_window->implicit_paint == NULL)
2764 paint = impl_window->implicit_paint;
2765 region = cairo_region_copy (window->clip_region_with_children);
2767 cairo_region_translate (region, window->abs_x, window->abs_y);
2768 cairo_region_intersect (region, paint->region);
2770 /* Don't flush active double buffers, as that may show partially done
2772 for (list = window->paint_stack; list != NULL; list = list->next)
2774 GdkWindowPaint *tmp_paint = list->data;
2776 cairo_region_subtract (region, tmp_paint->region);
2779 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2783 /* Remove flushed region from the implicit paint */
2784 cairo_region_subtract (paint->region, region);
2786 /* Some regions are valid, push these to window now */
2787 cr = gdk_cairo_create_for_impl (window);
2788 gdk_cairo_region (cr, region);
2790 cairo_set_source_surface (cr, paint->surface, 0, 0);
2791 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2795 paint->flushed = region;
2798 cairo_region_destroy (region);
2801 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2803 gdk_window_end_implicit_paint (GdkWindow *window)
2805 GdkWindowPaint *paint;
2807 g_assert (gdk_window_has_impl (window));
2809 g_assert (window->implicit_paint != NULL);
2811 paint = window->implicit_paint;
2813 window->implicit_paint = NULL;
2815 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2819 /* Some regions are valid, push these to window now */
2820 cr = gdk_cairo_create_for_impl (window);
2821 gdk_cairo_region (cr, paint->region);
2823 cairo_set_source_surface (cr, paint->surface, 0, 0);
2824 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2829 cairo_region_destroy (paint->region);
2831 cairo_region_destroy (paint->flushed);
2832 cairo_surface_destroy (paint->surface);
2837 * gdk_window_begin_paint_rect:
2838 * @window: a #GdkWindow
2839 * @rectangle: rectangle you intend to draw to
2841 * A convenience wrapper around gdk_window_begin_paint_region() which
2842 * creates a rectangular region for you. See
2843 * gdk_window_begin_paint_region() for details.
2847 gdk_window_begin_paint_rect (GdkWindow *window,
2848 const GdkRectangle *rectangle)
2850 cairo_region_t *region;
2852 g_return_if_fail (GDK_IS_WINDOW (window));
2854 region = cairo_region_create_rectangle (rectangle);
2855 gdk_window_begin_paint_region (window, region);
2856 cairo_region_destroy (region);
2860 * gdk_window_begin_paint_region:
2861 * @window: a #GdkWindow
2862 * @region: region you intend to draw to
2864 * Indicates that you are beginning the process of redrawing @region.
2865 * A backing store (offscreen buffer) large enough to contain @region
2866 * will be created. The backing store will be initialized with the
2867 * background color or background surface for @window. Then, all
2868 * drawing operations performed on @window will be diverted to the
2869 * backing store. When you call gdk_window_end_paint(), the backing
2870 * store will be copied to @window, making it visible onscreen. Only
2871 * the part of @window contained in @region will be modified; that is,
2872 * drawing operations are clipped to @region.
2874 * The net result of all this is to remove flicker, because the user
2875 * sees the finished product appear all at once when you call
2876 * gdk_window_end_paint(). If you draw to @window directly without
2877 * calling gdk_window_begin_paint_region(), the user may see flicker
2878 * as individual drawing operations are performed in sequence. The
2879 * clipping and background-initializing features of
2880 * gdk_window_begin_paint_region() are conveniences for the
2881 * programmer, so you can avoid doing that work yourself.
2883 * When using GTK+, the widget system automatically places calls to
2884 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2885 * emissions of the expose_event signal. That is, if you're writing an
2886 * expose event handler, you can assume that the exposed area in
2887 * #GdkEventExpose has already been cleared to the window background,
2888 * is already set as the clip region, and already has a backing store.
2889 * Therefore in most cases, application code need not call
2890 * gdk_window_begin_paint_region(). (You can disable the automatic
2891 * calls around expose events on a widget-by-widget basis by calling
2892 * gtk_widget_set_double_buffered().)
2894 * If you call this function multiple times before calling the
2895 * matching gdk_window_end_paint(), the backing stores are pushed onto
2896 * a stack. gdk_window_end_paint() copies the topmost backing store
2897 * onscreen, subtracts the topmost region from all other regions in
2898 * the stack, and pops the stack. All drawing operations affect only
2899 * the topmost backing store in the stack. One matching call to
2900 * gdk_window_end_paint() is required for each call to
2901 * gdk_window_begin_paint_region().
2905 gdk_window_begin_paint_region (GdkWindow *window,
2906 const cairo_region_t *region)
2908 #ifdef USE_BACKING_STORE
2909 GdkRectangle clip_box;
2910 GdkWindowPaint *paint, *implicit_paint;
2911 GdkWindow *impl_window;
2914 g_return_if_fail (GDK_IS_WINDOW (window));
2916 if (GDK_WINDOW_DESTROYED (window))
2919 if (GDK_IS_PAINTABLE (window->impl))
2921 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2923 if (iface->begin_paint_region)
2924 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2929 impl_window = gdk_window_get_impl_window (window);
2930 implicit_paint = impl_window->implicit_paint;
2932 paint = g_new (GdkWindowPaint, 1);
2933 paint->region = cairo_region_copy (region);
2935 cairo_region_intersect (paint->region, window->clip_region_with_children);
2936 cairo_region_get_extents (paint->region, &clip_box);
2938 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2940 /* Mark the region as valid on the implicit paint */
2943 cairo_region_union (implicit_paint->region, paint->region);
2945 /* Convert back to normal coords */
2946 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2950 paint->uses_implicit = TRUE;
2951 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2952 window->abs_x + clip_box.x,
2953 window->abs_y + clip_box.y,
2954 MAX (clip_box.width, 1),
2955 MAX (clip_box.height, 1));
2959 paint->uses_implicit = FALSE;
2960 paint->surface = gdk_window_create_similar_surface (window,
2961 gdk_window_get_content (window),
2962 MAX (clip_box.width, 1),
2963 MAX (clip_box.height, 1));
2966 /* Normally alpha backgrounded client side windows are composited on the implicit paint
2967 by being drawn in back to front order. However, if implicit paints are not used, for
2968 instance if it was flushed due to a non-double-buffered paint in the middle of the
2969 expose we need to copy in the existing data here. */
2970 if (!gdk_window_has_impl (window) &&
2971 window->has_alpha_background &&
2973 (implicit_paint && implicit_paint->flushed != NULL && !cairo_region_is_empty (implicit_paint->flushed))))
2975 cairo_t *cr = cairo_create (paint->surface);
2976 /* We can't use gdk_cairo_set_source_window here, as that might
2977 flush the implicit paint at an unfortunate time, since this
2978 would be detected as a draw during non-expose time */
2979 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (impl_window);
2980 cairo_set_source_surface (cr, source_surface,
2981 - (window->abs_x + clip_box.x),
2982 - (window->abs_y + clip_box.y));
2983 cairo_surface_destroy (source_surface);
2985 /* Only read back the flushed area if any */
2988 cairo_region_t *flushed = cairo_region_copy (implicit_paint->flushed);
2989 cairo_region_intersect (flushed, region);
2990 /* Convert from impl coords */
2991 cairo_region_translate (flushed, -window->abs_x, -window->abs_y);
2992 gdk_cairo_region (cr, flushed);
2995 /* Convert to impl coords */
2996 cairo_region_translate (flushed, window->abs_x, window->abs_y);
2997 cairo_region_subtract (implicit_paint->flushed, flushed);
2998 cairo_region_destroy (flushed);
3004 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3006 for (list = window->paint_stack; list != NULL; list = list->next)
3008 GdkWindowPaint *tmp_paint = list->data;
3010 cairo_region_subtract (tmp_paint->region, paint->region);
3013 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
3015 if (!cairo_region_is_empty (paint->region))
3017 gdk_window_clear_backing_region (window,
3021 #endif /* USE_BACKING_STORE */
3025 * gdk_window_end_paint:
3026 * @window: a #GdkWindow
3028 * Indicates that the backing store created by the most recent call to
3029 * gdk_window_begin_paint_region() should be copied onscreen and
3030 * deleted, leaving the next-most-recent backing store or no backing
3031 * store at all as the active paint region. See
3032 * gdk_window_begin_paint_region() for full details. It is an error to
3033 * call this function without a matching
3034 * gdk_window_begin_paint_region() first.
3038 gdk_window_end_paint (GdkWindow *window)
3040 #ifdef USE_BACKING_STORE
3041 GdkWindow *composited;
3042 GdkWindowPaint *paint;
3043 GdkRectangle clip_box;
3044 cairo_region_t *full_clip;
3046 g_return_if_fail (GDK_IS_WINDOW (window));
3048 if (GDK_WINDOW_DESTROYED (window))
3051 if (GDK_IS_PAINTABLE (window->impl))
3053 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3055 if (iface->end_paint)
3056 iface->end_paint ((GdkPaintable*)window->impl);
3060 if (window->paint_stack == NULL)
3062 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3066 paint = window->paint_stack->data;
3068 window->paint_stack = g_slist_delete_link (window->paint_stack,
3069 window->paint_stack);
3071 cairo_region_get_extents (paint->region, &clip_box);
3073 if (!paint->uses_implicit)
3077 gdk_window_flush_outstanding_moves (window);
3079 full_clip = cairo_region_copy (window->clip_region_with_children);
3080 cairo_region_intersect (full_clip, paint->region);
3082 cr = gdk_cairo_create (window);
3083 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3084 cairo_set_source_surface (cr, paint->surface, 0, 0);
3085 gdk_cairo_region (cr, full_clip);
3089 cairo_region_destroy (full_clip);
3092 cairo_surface_destroy (paint->surface);
3093 cairo_region_destroy (paint->region);
3096 /* find a composited window in our hierarchy to signal its
3097 * parent to redraw, calculating the clip box as we go...
3099 * stop if parent becomes NULL since then we'd have nowhere
3100 * to draw (ie: 'composited' will always be non-NULL here).
3102 for (composited = window;
3104 composited = composited->parent)
3106 clip_box.x += composited->x;
3107 clip_box.y += composited->y;
3108 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3109 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3111 if (composited->composited)
3113 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3118 #endif /* USE_BACKING_STORE */
3122 gdk_window_free_paint_stack (GdkWindow *window)
3124 if (window->paint_stack)
3126 GSList *tmp_list = window->paint_stack;
3130 GdkWindowPaint *paint = tmp_list->data;
3132 if (tmp_list == window->paint_stack)
3133 cairo_surface_destroy (paint->surface);
3135 cairo_region_destroy (paint->region);
3138 tmp_list = tmp_list->next;
3141 g_slist_free (window->paint_stack);
3142 window->paint_stack = NULL;
3147 do_move_region_bits_on_impl (GdkWindow *impl_window,
3148 cairo_region_t *dest_region, /* In impl window coords */
3151 GdkWindowImplClass *impl_class;
3153 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3155 impl_class->translate (impl_window, dest_region, dx, dy);
3158 static GdkWindowRegionMove *
3159 gdk_window_region_move_new (cairo_region_t *region,
3162 GdkWindowRegionMove *move;
3164 move = g_slice_new (GdkWindowRegionMove);
3165 move->dest_region = cairo_region_copy (region);
3173 gdk_window_region_move_free (GdkWindowRegionMove *move)
3175 cairo_region_destroy (move->dest_region);
3176 g_slice_free (GdkWindowRegionMove, move);
3180 append_move_region (GdkWindow *impl_window,
3181 cairo_region_t *new_dest_region,
3184 GdkWindowRegionMove *move, *old_move;
3185 cairo_region_t *new_total_region, *old_total_region;
3186 cairo_region_t *source_overlaps_destination;
3187 cairo_region_t *non_overwritten;
3188 gboolean added_move;
3191 if (cairo_region_is_empty (new_dest_region))
3194 /* In principle this could just append the move to the list of outstanding
3195 moves that will be replayed before drawing anything when we're handling
3196 exposes. However, we'd like to do a bit better since its commonly the case
3197 that we get multiple copies where A is copied to B and then B is copied
3198 to C, and we'd like to express this as a simple copy A to C operation. */
3200 /* We approach this by taking the new move and pushing it ahead of moves
3201 starting at the end of the list and stopping when its not safe to do so.
3202 It's not safe to push past a move if either the source of the new move
3203 is in the destination of the old move, or if the destination of the new
3204 move is in the source of the new move, or if the destination of the new
3205 move overlaps the destination of the old move. We simplify this by
3206 just comparing the total regions (src + dest) */
3207 new_total_region = cairo_region_copy (new_dest_region);
3208 cairo_region_translate (new_total_region, -dx, -dy);
3209 cairo_region_union (new_total_region, new_dest_region);
3212 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3217 old_total_region = cairo_region_copy (old_move->dest_region);
3218 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3219 cairo_region_union (old_total_region, old_move->dest_region);
3221 cairo_region_intersect (old_total_region, new_total_region);
3222 /* If these regions intersect then its not safe to push the
3223 new region before the old one */
3224 if (!cairo_region_is_empty (old_total_region))
3226 /* The area where the new moves source overlaps the old ones
3228 source_overlaps_destination = cairo_region_copy (new_dest_region);
3229 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3230 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3231 cairo_region_translate (source_overlaps_destination, dx, dy);
3233 /* We can do all sort of optimizations here, but to do things safely it becomes
3234 quite complicated. However, a very common case is that you copy something first,
3235 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3236 in the same direction). We'd like to detect this case and optimize it to one
3238 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3240 /* This means we might be able to replace the old move and the new one
3241 with the new one read from the old ones source, and a second copy of
3242 the non-overwritten parts of the old move. However, such a split
3243 is only valid if the source in the old move isn't overwritten
3244 by the destination of the new one */
3246 /* the new destination of old move if split is ok: */
3247 non_overwritten = cairo_region_copy (old_move->dest_region);
3248 cairo_region_subtract (non_overwritten, new_dest_region);
3249 /* move to source region */
3250 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3252 cairo_region_intersect (non_overwritten, new_dest_region);
3253 if (cairo_region_is_empty (non_overwritten))
3256 move = gdk_window_region_move_new (new_dest_region,
3260 impl_window->outstanding_moves =
3261 g_list_insert_before (impl_window->outstanding_moves,
3263 cairo_region_subtract (old_move->dest_region, new_dest_region);
3265 cairo_region_destroy (non_overwritten);
3268 cairo_region_destroy (source_overlaps_destination);
3269 cairo_region_destroy (old_total_region);
3272 cairo_region_destroy (old_total_region);
3275 cairo_region_destroy (new_total_region);
3279 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3282 impl_window->outstanding_moves =
3283 g_list_prepend (impl_window->outstanding_moves,
3286 impl_window->outstanding_moves =
3287 g_list_insert_before (impl_window->outstanding_moves,
3292 /* Moves bits and update area by dx/dy in impl window.
3293 Takes ownership of region to avoid copy (because we may change it) */
3295 move_region_on_impl (GdkWindow *impl_window,
3296 cairo_region_t *region, /* In impl window coords */
3299 if ((dx == 0 && dy == 0) ||
3300 cairo_region_is_empty (region))
3302 cairo_region_destroy (region);
3306 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3308 /* Move any old invalid regions in the copy source area by dx/dy */
3309 if (impl_window->update_area)
3311 cairo_region_t *update_area;
3313 update_area = cairo_region_copy (region);
3315 /* Convert from target to source */
3316 cairo_region_translate (update_area, -dx, -dy);
3317 cairo_region_intersect (update_area, impl_window->update_area);
3318 /* We only copy the area, so keep the old update area invalid.
3319 It would be safe to remove it too, as code that uses
3320 move_region_on_impl generally also invalidate the source
3321 area. However, it would just use waste cycles. */
3324 cairo_region_translate (update_area, dx, dy);
3325 cairo_region_union (impl_window->update_area, update_area);
3327 /* This area of the destination is now invalid,
3328 so no need to copy to it. */
3329 cairo_region_subtract (region, update_area);
3331 cairo_region_destroy (update_area);
3334 /* If we're currently exposing this window, don't copy to this
3335 destination, as it will be overdrawn when the expose is done,
3336 instead invalidate it and repaint later. */
3337 if (impl_window->implicit_paint)
3339 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3340 cairo_region_t *exposing;
3342 exposing = cairo_region_copy (implicit_paint->region);
3343 cairo_region_intersect (exposing, region);
3344 cairo_region_subtract (region, exposing);
3346 impl_window_add_update_area (impl_window, exposing);
3347 cairo_region_destroy (exposing);
3350 append_move_region (impl_window, region, dx, dy);
3352 cairo_region_destroy (region);
3355 /* Flushes all outstanding changes to the window, call this
3356 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3359 gdk_window_flush_outstanding_moves (GdkWindow *window)
3361 GdkWindow *impl_window;
3362 GList *l, *outstanding;
3363 GdkWindowRegionMove *move;
3365 impl_window = gdk_window_get_impl_window (window);
3366 outstanding = impl_window->outstanding_moves;
3367 impl_window->outstanding_moves = NULL;
3369 for (l = outstanding; l != NULL; l = l->next)
3373 do_move_region_bits_on_impl (impl_window,
3374 move->dest_region, move->dx, move->dy);
3376 gdk_window_region_move_free (move);
3379 g_list_free (outstanding);
3384 * @window: a #GdkWindow
3386 * Flush all outstanding cached operations on a window, leaving the
3387 * window in a state which reflects all that has been drawn before.
3389 * Gdk uses multiple kinds of caching to get better performance and
3390 * nicer drawing. For instance, during exposes all paints to a window
3391 * using double buffered rendering are keep on a surface until the last
3392 * window has been exposed. It also delays window moves/scrolls until
3393 * as long as possible until next update to avoid tearing when moving
3396 * Normally this should be completely invisible to applications, as
3397 * we automatically flush the windows when required, but this might
3398 * be needed if you for instance mix direct native drawing with
3399 * gdk drawing. For Gtk widgets that don't use double buffering this
3400 * will be called automatically before sending the expose event.
3405 gdk_window_flush (GdkWindow *window)
3407 gdk_window_flush_outstanding_moves (window);
3408 gdk_window_flush_implicit_paint (window);
3411 /* If we're about to move/resize or otherwise change the
3412 * hierarchy of a client side window in an impl and we're
3413 * called from an expose event handler then we need to
3414 * flush any already painted parts of the implicit paint
3415 * that are not part of the current paint, as these may
3416 * be used when scrolling or may overdraw the changes
3417 * caused by the hierarchy change.
3420 gdk_window_flush_if_exposing (GdkWindow *window)
3422 GdkWindow *impl_window;
3424 impl_window = gdk_window_get_impl_window (window);
3426 /* If we're in an implicit paint (i.e. in an expose handler, flush
3427 all the already finished exposes to get things to an uptodate state. */
3428 if (impl_window->implicit_paint)
3429 gdk_window_flush (window);
3434 gdk_window_flush_recursive_helper (GdkWindow *window,
3435 GdkWindowImpl *impl)
3440 for (l = window->children; l != NULL; l = l->next)
3444 if (child->impl == impl)
3445 /* Same impl, ignore */
3446 gdk_window_flush_recursive_helper (child, impl);
3448 gdk_window_flush_recursive (child);
3453 gdk_window_flush_recursive (GdkWindow *window)
3455 gdk_window_flush (window);
3456 gdk_window_flush_recursive_helper (window, window->impl);
3460 * gdk_window_get_clip_region:
3461 * @window: a #GdkWindow
3463 * Computes the region of a window that potentially can be written
3464 * to by drawing primitives. This region may not take into account
3465 * other factors such as if the window is obscured by other windows,
3466 * but no area outside of this region will be affected by drawing
3469 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3470 * when you are done.
3473 gdk_window_get_clip_region (GdkWindow *window)
3475 cairo_region_t *result;
3477 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3479 result = cairo_region_copy (window->clip_region);
3481 if (window->paint_stack)
3483 cairo_region_t *paint_region = cairo_region_create ();
3484 GSList *tmp_list = window->paint_stack;
3488 GdkWindowPaint *paint = tmp_list->data;
3490 cairo_region_union (paint_region, paint->region);
3492 tmp_list = tmp_list->next;
3495 cairo_region_intersect (result, paint_region);
3496 cairo_region_destroy (paint_region);
3503 * gdk_window_get_visible_region:
3504 * @window: a #GdkWindow
3506 * Computes the region of the @window that is potentially visible.
3507 * This does not necessarily take into account if the window is
3508 * obscured by other windows, but no area outside of this region
3511 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3512 * when you are done.
3515 gdk_window_get_visible_region (GdkWindow *window)
3517 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3519 return cairo_region_copy (window->clip_region);
3523 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint)
3525 GdkWindow *bg_window;
3526 cairo_pattern_t *pattern = NULL;
3527 int x_offset = 0, y_offset = 0;
3530 cr = cairo_create (paint->surface);
3532 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3534 pattern = gdk_window_get_background_pattern (bg_window);
3538 x_offset += bg_window->x;
3539 y_offset += bg_window->y;
3544 cairo_translate (cr, -x_offset, -y_offset);
3545 cairo_set_source (cr, pattern);
3546 cairo_translate (cr, x_offset, y_offset);
3549 cairo_set_source_rgb (cr, 0, 0, 0);
3555 gdk_window_clear_backing_region (GdkWindow *window,
3556 cairo_region_t *region)
3558 GdkWindowPaint *paint = window->paint_stack->data;
3559 cairo_region_t *clip;
3562 if (GDK_WINDOW_DESTROYED (window))
3565 cr = setup_backing_rect (window, paint);
3567 clip = cairo_region_copy (paint->region);
3568 cairo_region_intersect (clip, region);
3570 gdk_cairo_region (cr, clip);
3575 cairo_region_destroy (clip);
3579 gdk_window_clear_backing_region_direct (GdkWindow *window,
3580 cairo_region_t *region)
3582 GdkWindowPaint paint;
3583 cairo_region_t *clip;
3586 if (GDK_WINDOW_DESTROYED (window))
3589 paint.surface = _gdk_window_ref_cairo_surface (window);
3591 cr = setup_backing_rect (window, &paint);
3593 clip = cairo_region_copy (window->clip_region_with_children);
3594 cairo_region_intersect (clip, region);
3596 gdk_cairo_region (cr, clip);
3601 cairo_region_destroy (clip);
3602 cairo_surface_destroy (paint.surface);
3606 gdk_window_drop_cairo_surface (GdkWindow *window)
3608 if (window->cairo_surface)
3610 cairo_surface_finish (window->cairo_surface);
3611 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3613 window->cairo_surface = NULL;
3618 gdk_window_cairo_surface_destroy (void *data)
3620 GdkWindow *window = data;
3622 window->cairo_surface = NULL;
3625 static cairo_surface_t *
3626 gdk_window_create_cairo_surface (GdkWindow *window,
3630 cairo_surface_t *surface, *subsurface;
3632 surface = gdk_window_ref_impl_surface (window);
3633 if (gdk_window_has_impl (window))
3636 subsurface = cairo_surface_create_for_rectangle (surface,
3641 cairo_surface_destroy (surface);
3647 _gdk_window_ref_cairo_surface (GdkWindow *window)
3649 cairo_surface_t *surface;
3651 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3653 if (window->paint_stack)
3655 GdkWindowPaint *paint = window->paint_stack->data;
3657 surface = paint->surface;
3658 cairo_surface_reference (surface);
3663 /* This will be drawing directly to the window, so flush implicit paint */
3664 gdk_window_flush (window);
3666 if (!window->cairo_surface)
3668 window->cairo_surface = gdk_window_create_cairo_surface (window,
3672 if (window->cairo_surface)
3674 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3675 window, gdk_window_cairo_surface_destroy);
3679 cairo_surface_reference (window->cairo_surface);
3681 surface = window->cairo_surface;
3689 * @window: a #GdkWindow
3691 * Creates a Cairo context for drawing to @window.
3694 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3695 * produce undefined results, so avoid it at all costs.
3698 * Return value: A newly created Cairo context. Free with
3699 * cairo_destroy() when you are done drawing.
3704 gdk_cairo_create (GdkWindow *window)
3706 cairo_surface_t *surface;
3709 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3711 surface = _gdk_window_ref_cairo_surface (window);
3712 cr = cairo_create (surface);
3714 if (!window->paint_stack)
3716 gdk_cairo_region (cr, window->clip_region_with_children);
3721 GdkWindowPaint *paint = window->paint_stack->data;
3723 /* Only needs to clip to region if piggybacking
3724 on an implicit paint */
3725 if (paint->uses_implicit)
3727 gdk_cairo_region (cr, paint->region);
3732 cairo_surface_destroy (surface);
3737 /* Code for dirty-region queueing
3739 static GSList *update_windows = NULL;
3740 static guint update_idle = 0;
3741 static gboolean debug_updates = FALSE;
3743 static inline gboolean
3744 gdk_window_is_ancestor (GdkWindow *window,
3745 GdkWindow *ancestor)
3749 GdkWindow *parent = window->parent;
3751 if (parent == ancestor)
3761 gdk_window_add_update_window (GdkWindow *window)
3764 GSList *prev = NULL;
3765 gboolean has_ancestor_in_list = FALSE;
3767 for (tmp = update_windows; tmp; tmp = tmp->next)
3769 GdkWindow *parent = window->parent;
3771 /* check if tmp is an ancestor of "window"; if it is, set a
3772 * flag indicating that all following windows are either
3773 * children of "window" or from a differen hierarchy
3775 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3776 has_ancestor_in_list = TRUE;
3778 /* insert in reverse stacking order when adding around siblings,
3779 * so processing updates properly paints over lower stacked windows
3781 if (parent == GDK_WINDOW (tmp->data)->parent)
3783 gint index = g_list_index (parent->children, window);
3784 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3786 gint sibling_index = g_list_index (parent->children, tmp->data);
3787 if (index > sibling_index)
3791 /* here, tmp got advanced past all lower stacked siblings */
3792 tmp = g_slist_prepend (tmp, window);
3796 update_windows = tmp;
3800 /* if "window" has an ancestor in the list and tmp is one of
3801 * "window's" children, insert "window" before tmp
3803 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3805 tmp = g_slist_prepend (tmp, window);
3810 update_windows = tmp;
3814 /* if we're at the end of the list and had an ancestor it it,
3815 * append to the list
3817 if (! tmp->next && has_ancestor_in_list)
3819 tmp = g_slist_append (tmp, window);
3826 /* if all above checks failed ("window" is from a different
3827 * hierarchy than what is already in the list) or the list is
3830 update_windows = g_slist_prepend (update_windows, window);
3834 gdk_window_remove_update_window (GdkWindow *window)
3836 update_windows = g_slist_remove (update_windows, window);
3840 gdk_window_update_idle (gpointer data)
3842 gdk_window_process_all_updates ();
3848 gdk_window_is_toplevel_frozen (GdkWindow *window)
3850 GdkWindow *toplevel;
3852 toplevel = gdk_window_get_toplevel (window);
3854 return toplevel->update_and_descendants_freeze_count > 0;
3858 gdk_window_schedule_update (GdkWindow *window)
3861 (window->update_freeze_count ||
3862 gdk_window_is_toplevel_frozen (window)))
3867 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3868 gdk_window_update_idle,
3873 _gdk_window_process_updates_recurse (GdkWindow *window,
3874 cairo_region_t *expose_region)
3877 cairo_region_t *clipped_expose_region;
3878 GList *l, *children;
3880 if (cairo_region_is_empty (expose_region))
3883 if (gdk_window_is_offscreen (window->impl_window) &&
3884 gdk_window_has_impl (window))
3885 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3888 /* Paint the window before the children, clipped to the window region
3889 with visible child windows removed */
3890 clipped_expose_region = cairo_region_copy (expose_region);
3891 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3893 if (!cairo_region_is_empty (clipped_expose_region) &&
3896 if (window->event_mask & GDK_EXPOSURE_MASK)
3900 event.expose.type = GDK_EXPOSE;
3901 event.expose.window = g_object_ref (window);
3902 event.expose.send_event = FALSE;
3903 event.expose.count = 0;
3904 event.expose.region = clipped_expose_region;
3905 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
3907 _gdk_event_emit (&event);
3909 g_object_unref (window);
3911 else if (window->window_type != GDK_WINDOW_FOREIGN)
3913 /* No exposure mask set, so nothing will be drawn, the
3914 * app relies on the background being what it specified
3915 * for the window. So, we need to clear this manually.
3917 * For foreign windows if expose is not set that generally
3918 * means some other client paints them, so don't clear
3921 * We use begin/end_paint around the clear so that we can
3922 * piggyback on the implicit paint */
3924 gdk_window_begin_paint_region (window, clipped_expose_region);
3925 /* The actual clear happens in begin_paint_region */
3926 gdk_window_end_paint (window);
3929 cairo_region_destroy (clipped_expose_region);
3931 /* Make this reentrancy safe for expose handlers freeing windows */
3932 children = g_list_copy (window->children);
3933 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3935 /* Iterate over children, starting at bottommost */
3936 for (l = g_list_last (children); l != NULL; l = l->prev)
3940 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3943 /* Ignore offscreen children, as they don't draw in their parent and
3944 * don't take part in the clipping */
3945 if (gdk_window_is_offscreen (child))
3948 /* Client side child, expose */
3949 if (child->impl == window->impl)
3951 cairo_region_translate (expose_region, -child->x, -child->y);
3952 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
3953 cairo_region_translate (expose_region, child->x, child->y);
3957 g_list_free_full (children, g_object_unref);
3961 /* Process and remove any invalid area on the native window by creating
3962 * expose events for the window and all non-native descendants.
3963 * Also processes any outstanding moves on the window before doing
3964 * any drawing. Note that its possible to have outstanding moves without
3965 * any invalid area as we use the update idle mechanism to coalesce
3966 * multiple moves as well as multiple invalidations.
3969 gdk_window_process_updates_internal (GdkWindow *window)
3971 GdkWindowImplClass *impl_class;
3972 gboolean save_region = FALSE;
3973 GdkRectangle clip_box;
3975 /* Ensure the window lives while updating it */
3976 g_object_ref (window);
3978 /* If an update got queued during update processing, we can get a
3979 * window in the update queue that has an empty update_area.
3982 if (window->update_area)
3984 cairo_region_t *update_area = window->update_area;
3985 window->update_area = NULL;
3987 if (gdk_window_is_viewable (window))
3989 cairo_region_t *expose_region;
3990 gboolean end_implicit;
3992 /* Clip to part visible in toplevel */
3993 cairo_region_intersect (update_area, window->clip_region);
3997 /* Make sure we see the red invalid area before redrawing. */
3998 gdk_display_sync (gdk_window_get_display (window));
4002 /* At this point we will be completely redrawing all of update_area.
4003 * If we have any outstanding moves that end up moving stuff inside
4004 * this area we don't actually need to move that as that part would
4005 * be overdrawn by the expose anyway. So, in order to copy less data
4006 * we remove these areas from the outstanding moves.
4008 if (window->outstanding_moves)
4010 GdkWindowRegionMove *move;
4011 cairo_region_t *remove;
4014 remove = cairo_region_copy (update_area);
4015 /* We iterate backwards, starting from the state that would be
4016 if we had applied all the moves. */
4017 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
4022 /* Don't need this area */
4023 cairo_region_subtract (move->dest_region, remove);
4025 /* However if any of the destination we do need has a source
4026 in the updated region we do need that as a destination for
4027 the earlier moves */
4028 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4029 cairo_region_subtract (remove, move->dest_region);
4031 if (cairo_region_is_empty (move->dest_region))
4033 gdk_window_region_move_free (move);
4034 window->outstanding_moves =
4035 g_list_delete_link (window->outstanding_moves, l);
4037 else /* move back */
4038 cairo_region_translate (move->dest_region, move->dx, move->dy);
4040 cairo_region_destroy (remove);
4043 /* By now we a set of window moves that should be applied, and then
4044 * an update region that should be repainted. A trivial implementation
4045 * would just do that in order, however in order to get nicer drawing
4046 * we do some tricks:
4048 * First of all, each subwindow expose may be double buffered by
4049 * itself (depending on widget setting) via
4050 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4051 * creating a single surface the size of the invalid area on the
4052 * native window which all the individual normal paints will draw
4053 * into. This way in the normal case there will be only one surface
4054 * allocated and only once surface draw done for all the windows
4055 * in this native window.
4056 * There are a couple of reasons this may fail, for instance, some
4057 * backends (like quartz) do its own double buffering, so we disable
4058 * gdk double buffering there. Secondly, some subwindow could be
4059 * non-double buffered and draw directly to the window outside a
4060 * begin/end_paint pair. That will be lead to a gdk_window_flush
4061 * which immediately executes all outstanding moves and paints+removes
4062 * the implicit paint (further paints will allocate their own surfaces).
4064 * Secondly, in the case of implicit double buffering we expose all
4065 * the child windows into the implicit surface before we execute
4066 * the outstanding moves. This way we minimize the time between
4067 * doing the moves and rendering the new update area, thus minimizing
4068 * flashing. Of course, if any subwindow is non-double buffered we
4069 * well flush earlier than that.
4071 * Thirdly, after having done the outstanding moves we queue an
4072 * "antiexpose" on the area that will be drawn by the expose, which
4073 * means that any invalid region on the native window side before
4074 * the first expose drawing operation will be discarded, as it
4075 * has by then been overdrawn with valid data. This means we can
4076 * avoid doing the unnecessary repaint any outstanding expose events.
4079 cairo_region_get_extents (update_area, &clip_box);
4080 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4081 expose_region = cairo_region_copy (update_area);
4082 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4085 /* Rendering is not double buffered by gdk, do outstanding
4086 * moves and queue antiexposure immediately. No need to do
4088 gdk_window_flush_outstanding_moves (window);
4089 save_region = impl_class->queue_antiexpose (window, update_area);
4091 /* Render the invalid areas to the implicit paint, by sending exposes.
4092 * May flush if non-double buffered widget draw. */
4093 impl_class->process_updates_recurse (window, expose_region);
4097 /* Do moves right before exposes are rendered to the window */
4098 gdk_window_flush_outstanding_moves (window);
4100 /* By this time we know that any outstanding expose for this
4101 * area is invalid and we can avoid it, so queue an antiexpose.
4102 * we have already started drawing to the window, so it would
4103 * be to late to anti-expose now. Since this is merely an
4104 * optimization we just avoid doing it at all in that case.
4106 if (window->implicit_paint != NULL && !window->implicit_paint->flushed)
4107 save_region = impl_class->queue_antiexpose (window, update_area);
4109 gdk_window_end_implicit_paint (window);
4111 cairo_region_destroy (expose_region);
4114 cairo_region_destroy (update_area);
4117 if (window->outstanding_moves)
4119 /* Flush any outstanding moves, may happen if we moved a window but got
4120 no actual invalid area */
4121 gdk_window_flush_outstanding_moves (window);
4124 g_object_unref (window);
4128 flush_all_displays (void)
4130 GSList *displays, *l;
4132 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4133 for (l = displays; l; l = l->next)
4134 gdk_display_flush (l->data);
4136 g_slist_free (displays);
4140 before_process_all_updates (void)
4142 GSList *displays, *l;
4143 GdkDisplayClass *display_class;
4145 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4146 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4147 for (l = displays; l; l = l->next)
4148 display_class->before_process_all_updates (l->data);
4150 g_slist_free (displays);
4154 after_process_all_updates (void)
4156 GSList *displays, *l;
4157 GdkDisplayClass *display_class;
4159 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4160 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4161 for (l = displays; l; l = l->next)
4162 display_class->after_process_all_updates (l->data);
4164 g_slist_free (displays);
4167 /* Currently it is not possible to override
4168 * gdk_window_process_all_updates in the same manner as
4169 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4170 * by implementing the GdkPaintable interface. If in the future a
4171 * backend would need this, the right solution would be to add a
4172 * method to GdkDisplay that can be optionally
4173 * NULL. gdk_window_process_all_updates can then walk the list of open
4174 * displays and call the mehod.
4178 * gdk_window_process_all_updates:
4180 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4181 * in the application.
4185 gdk_window_process_all_updates (void)
4187 GSList *old_update_windows = update_windows;
4188 GSList *tmp_list = update_windows;
4189 static gboolean in_process_all_updates = FALSE;
4190 static gboolean got_recursive_update = FALSE;
4192 if (in_process_all_updates)
4194 /* We can't do this now since that would recurse, so
4195 delay it until after the recursion is done. */
4196 got_recursive_update = TRUE;
4201 in_process_all_updates = TRUE;
4202 got_recursive_update = FALSE;
4205 g_source_remove (update_idle);
4207 update_windows = NULL;
4210 before_process_all_updates ();
4212 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4216 GdkWindow *window = tmp_list->data;
4218 if (!GDK_WINDOW_DESTROYED (window))
4220 if (window->update_freeze_count ||
4221 gdk_window_is_toplevel_frozen (window))
4222 gdk_window_add_update_window (window);
4224 gdk_window_process_updates_internal (window);
4227 g_object_unref (window);
4228 tmp_list = tmp_list->next;
4231 g_slist_free (old_update_windows);
4233 flush_all_displays ();
4235 after_process_all_updates ();
4237 in_process_all_updates = FALSE;
4239 /* If we ignored a recursive call, schedule a
4240 redraw now so that it eventually happens,
4241 otherwise we could miss an update if nothing
4242 else schedules an update. */
4243 if (got_recursive_update && !update_idle)
4245 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4246 gdk_window_update_idle,
4251 * gdk_window_process_updates:
4252 * @window: a #GdkWindow
4253 * @update_children: whether to also process updates for child windows
4255 * Sends one or more expose events to @window. The areas in each
4256 * expose event will cover the entire update area for the window (see
4257 * gdk_window_invalidate_region() for details). Normally GDK calls
4258 * gdk_window_process_all_updates() on your behalf, so there's no
4259 * need to call this function unless you want to force expose events
4260 * to be delivered immediately and synchronously (vs. the usual
4261 * case, where GDK delivers them in an idle handler). Occasionally
4262 * this is useful to produce nicer scrolling behavior, for example.
4266 gdk_window_process_updates (GdkWindow *window,
4267 gboolean update_children)
4269 GdkWindow *impl_window;
4271 g_return_if_fail (GDK_IS_WINDOW (window));
4273 if (GDK_WINDOW_DESTROYED (window))
4276 /* Make sure the window lives during the expose callouts */
4277 g_object_ref (window);
4279 impl_window = gdk_window_get_impl_window (window);
4280 if ((impl_window->update_area ||
4281 impl_window->outstanding_moves) &&
4282 !impl_window->update_freeze_count &&
4283 !gdk_window_is_toplevel_frozen (window) &&
4285 /* Don't recurse into process_updates_internal, we'll
4286 * do the update later when idle instead. */
4287 impl_window->implicit_paint == NULL)
4289 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4290 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4293 if (update_children)
4295 /* process updates in reverse stacking order so composition or
4296 * painting over achieves the desired effect for offscreen windows
4298 GList *node, *children;
4300 children = g_list_copy (window->children);
4301 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4303 for (node = g_list_last (children); node; node = node->prev)
4305 gdk_window_process_updates (node->data, TRUE);
4306 g_object_unref (node->data);
4309 g_list_free (children);
4312 g_object_unref (window);
4316 gdk_window_invalidate_rect_full (GdkWindow *window,
4317 const GdkRectangle *rect,
4318 gboolean invalidate_children,
4321 GdkRectangle window_rect;
4322 cairo_region_t *region;
4324 g_return_if_fail (GDK_IS_WINDOW (window));
4326 if (GDK_WINDOW_DESTROYED (window))
4329 if (window->input_only || !window->viewable)
4336 window_rect.width = window->width;
4337 window_rect.height = window->height;
4338 rect = &window_rect;
4341 region = cairo_region_create_rectangle (rect);
4342 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4343 cairo_region_destroy (region);
4347 * gdk_window_invalidate_rect:
4348 * @window: a #GdkWindow
4349 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4351 * @invalidate_children: whether to also invalidate child windows
4353 * A convenience wrapper around gdk_window_invalidate_region() which
4354 * invalidates a rectangular region. See
4355 * gdk_window_invalidate_region() for details.
4358 gdk_window_invalidate_rect (GdkWindow *window,
4359 const GdkRectangle *rect,
4360 gboolean invalidate_children)
4362 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4366 draw_ugly_color (GdkWindow *window,
4367 const cairo_region_t *region)
4371 cr = gdk_cairo_create (window);
4372 /* Draw ugly color all over the newly-invalid region */
4373 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4374 gdk_cairo_region (cr, region);
4381 impl_window_add_update_area (GdkWindow *impl_window,
4382 cairo_region_t *region)
4384 if (impl_window->update_area)
4385 cairo_region_union (impl_window->update_area, region);
4388 gdk_window_add_update_window (impl_window);
4389 impl_window->update_area = cairo_region_copy (region);
4390 gdk_window_schedule_update (impl_window);
4394 /* clear_bg controls if the region will be cleared to
4395 * the background pattern if the exposure mask is not
4396 * set for the window, whereas this might not otherwise be
4397 * done (unless necessary to emulate background settings).
4398 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4399 * need to clear the background, such as when exposing the area beneath a
4400 * hidden or moved window, but not when an app requests repaint or when the
4401 * windowing system exposes a newly visible area (because then the windowing
4402 * system has already cleared the area).
4405 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4406 const cairo_region_t *region,
4408 GdkWindowChildFunc child_func,
4411 GdkWindow *impl_window;
4412 cairo_region_t *visible_region;
4415 g_return_if_fail (GDK_IS_WINDOW (window));
4417 if (GDK_WINDOW_DESTROYED (window))
4420 if (window->input_only ||
4421 !window->viewable ||
4422 cairo_region_is_empty (region) ||
4423 window->window_type == GDK_WINDOW_ROOT)
4426 visible_region = gdk_window_get_visible_region (window);
4427 cairo_region_intersect (visible_region, region);
4429 tmp_list = window->children;
4432 GdkWindow *child = tmp_list->data;
4434 if (!child->input_only)
4436 cairo_region_t *child_region;
4437 GdkRectangle child_rect;
4439 child_rect.x = child->x;
4440 child_rect.y = child->y;
4441 child_rect.width = child->width;
4442 child_rect.height = child->height;
4443 child_region = cairo_region_create_rectangle (&child_rect);
4445 /* remove child area from the invalid area of the parent */
4446 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4447 !child->composited &&
4448 !gdk_window_is_offscreen (child))
4449 cairo_region_subtract (visible_region, child_region);
4451 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4453 cairo_region_t *tmp = cairo_region_copy (region);
4455 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4456 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4457 cairo_region_intersect (child_region, tmp);
4459 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4460 child_region, clear_bg, child_func, user_data);
4462 cairo_region_destroy (tmp);
4465 cairo_region_destroy (child_region);
4468 tmp_list = tmp_list->next;
4471 impl_window = gdk_window_get_impl_window (window);
4473 if (!cairo_region_is_empty (visible_region) ||
4474 /* Even if we're not exposing anything, make sure we process
4475 idles for windows with outstanding moves */
4476 (impl_window->outstanding_moves != NULL &&
4477 impl_window->update_area == NULL))
4480 draw_ugly_color (window, region);
4482 /* Convert to impl coords */
4483 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4485 /* Only invalidate area if app requested expose events or if
4486 we need to clear the area (by request or to emulate background
4487 clearing for non-native windows or native windows with no support
4488 for window backgrounds */
4489 if (window->event_mask & GDK_EXPOSURE_MASK ||
4490 clear_bg == CLEAR_BG_ALL ||
4491 clear_bg == CLEAR_BG_WINCLEARED)
4492 impl_window_add_update_area (impl_window, visible_region);
4495 cairo_region_destroy (visible_region);
4499 * gdk_window_invalidate_maybe_recurse:
4500 * @window: a #GdkWindow
4501 * @region: a #cairo_region_t
4502 * @child_func: (scope call) (allow-none): function to use to decide if to
4503 * recurse to a child, %NULL means never recurse.
4504 * @user_data: data passed to @child_func
4506 * Adds @region to the update area for @window. The update area is the
4507 * region that needs to be redrawn, or "dirty region." The call
4508 * gdk_window_process_updates() sends one or more expose events to the
4509 * window, which together cover the entire update area. An
4510 * application would normally redraw the contents of @window in
4511 * response to those expose events.
4513 * GDK will call gdk_window_process_all_updates() on your behalf
4514 * whenever your program returns to the main loop and becomes idle, so
4515 * normally there's no need to do that manually, you just need to
4516 * invalidate regions that you know should be redrawn.
4518 * The @child_func parameter controls whether the region of
4519 * each child window that intersects @region will also be invalidated.
4520 * Only children for which @child_func returns TRUE will have the area
4524 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4525 const cairo_region_t *region,
4526 GdkWindowChildFunc child_func,
4529 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4530 child_func, user_data);
4534 true_predicate (GdkWindow *window,
4541 gdk_window_invalidate_region_full (GdkWindow *window,
4542 const cairo_region_t *region,
4543 gboolean invalidate_children,
4546 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4547 invalidate_children ?
4548 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4553 * gdk_window_invalidate_region:
4554 * @window: a #GdkWindow
4555 * @region: a #cairo_region_t
4556 * @invalidate_children: %TRUE to also invalidate child windows
4558 * Adds @region to the update area for @window. The update area is the
4559 * region that needs to be redrawn, or "dirty region." The call
4560 * gdk_window_process_updates() sends one or more expose events to the
4561 * window, which together cover the entire update area. An
4562 * application would normally redraw the contents of @window in
4563 * response to those expose events.
4565 * GDK will call gdk_window_process_all_updates() on your behalf
4566 * whenever your program returns to the main loop and becomes idle, so
4567 * normally there's no need to do that manually, you just need to
4568 * invalidate regions that you know should be redrawn.
4570 * The @invalidate_children parameter controls whether the region of
4571 * each child window that intersects @region will also be invalidated.
4572 * If %FALSE, then the update area for child windows will remain
4573 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4574 * fine grained control over which children are invalidated.
4577 gdk_window_invalidate_region (GdkWindow *window,
4578 const cairo_region_t *region,
4579 gboolean invalidate_children)
4581 gdk_window_invalidate_maybe_recurse (window, region,
4582 invalidate_children ?
4583 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4588 * _gdk_window_invalidate_for_expose:
4589 * @window: a #GdkWindow
4590 * @region: a #cairo_region_t
4592 * Adds @region to the update area for @window. The update area is the
4593 * region that needs to be redrawn, or "dirty region." The call
4594 * gdk_window_process_updates() sends one or more expose events to the
4595 * window, which together cover the entire update area. An
4596 * application would normally redraw the contents of @window in
4597 * response to those expose events.
4599 * GDK will call gdk_window_process_all_updates() on your behalf
4600 * whenever your program returns to the main loop and becomes idle, so
4601 * normally there's no need to do that manually, you just need to
4602 * invalidate regions that you know should be redrawn.
4604 * This version of invalidation is used when you recieve expose events
4605 * from the native window system. It exposes the native window, plus
4606 * any non-native child windows (but not native child windows, as those would
4607 * have gotten their own expose events).
4610 _gdk_window_invalidate_for_expose (GdkWindow *window,
4611 cairo_region_t *region)
4613 GdkWindowRegionMove *move;
4614 cairo_region_t *move_region;
4617 /* Any invalidations comming from the windowing system will
4618 be in areas that may be moved by outstanding moves,
4619 so we need to modify the expose region correspondingly,
4620 otherwise we would expose in the wrong place, as the
4621 outstanding moves will be copied before we draw the
4623 for (l = window->outstanding_moves; l != NULL; l = l->next)
4627 /* covert to move source region */
4628 move_region = cairo_region_copy (move->dest_region);
4629 cairo_region_translate (move_region, -move->dx, -move->dy);
4631 /* Move area of region that intersects with move source
4632 by dx, dy of the move*/
4633 cairo_region_intersect (move_region, region);
4634 cairo_region_subtract (region, move_region);
4635 cairo_region_translate (move_region, move->dx, move->dy);
4636 cairo_region_union (region, move_region);
4638 cairo_region_destroy (move_region);
4641 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4642 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4648 * gdk_window_get_update_area:
4649 * @window: a #GdkWindow
4651 * Transfers ownership of the update area from @window to the caller
4652 * of the function. That is, after calling this function, @window will
4653 * no longer have an invalid/dirty region; the update area is removed
4654 * from @window and handed to you. If a window has no update area,
4655 * gdk_window_get_update_area() returns %NULL. You are responsible for
4656 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4658 * Return value: the update area for @window
4661 gdk_window_get_update_area (GdkWindow *window)
4663 GdkWindow *impl_window;
4664 cairo_region_t *tmp_region, *to_remove;
4666 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4668 impl_window = gdk_window_get_impl_window (window);
4670 if (impl_window->update_area)
4672 tmp_region = cairo_region_copy (window->clip_region_with_children);
4673 /* Convert to impl coords */
4674 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4675 cairo_region_intersect (tmp_region, impl_window->update_area);
4677 if (cairo_region_is_empty (tmp_region))
4679 cairo_region_destroy (tmp_region);
4684 /* Convert from impl coords */
4685 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4687 /* Don't remove any update area that is overlapped by non-opaque windows
4688 (children or siblings) with alpha, as these really need to be repainted
4689 independently of this window. */
4690 to_remove = cairo_region_copy (tmp_region);
4691 cairo_region_subtract (to_remove, window->parent->layered_region);
4692 remove_layered_child_area (window, to_remove);
4694 /* Remove from update_area */
4695 cairo_region_translate (to_remove, window->abs_x, window->abs_y);
4696 cairo_region_subtract (impl_window->update_area, to_remove);
4698 cairo_region_destroy (to_remove);
4700 if (cairo_region_is_empty (impl_window->update_area) &&
4701 impl_window->outstanding_moves == NULL)
4703 cairo_region_destroy (impl_window->update_area);
4704 impl_window->update_area = NULL;
4706 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4717 * _gdk_window_clear_update_area:
4718 * @window: a #GdkWindow.
4720 * Internal function to clear the update area for a window. This
4721 * is called when the window is hidden or destroyed.
4724 _gdk_window_clear_update_area (GdkWindow *window)
4726 g_return_if_fail (GDK_IS_WINDOW (window));
4728 if (window->update_area)
4730 gdk_window_remove_update_window (window);
4732 cairo_region_destroy (window->update_area);
4733 window->update_area = NULL;
4738 * gdk_window_freeze_updates:
4739 * @window: a #GdkWindow
4741 * Temporarily freezes a window such that it won't receive expose
4742 * events. The window will begin receiving expose events again when
4743 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4744 * has been called more than once, gdk_window_thaw_updates() must be called
4745 * an equal number of times to begin processing exposes.
4748 gdk_window_freeze_updates (GdkWindow *window)
4750 GdkWindow *impl_window;
4752 g_return_if_fail (GDK_IS_WINDOW (window));
4754 impl_window = gdk_window_get_impl_window (window);
4755 impl_window->update_freeze_count++;
4759 * gdk_window_thaw_updates:
4760 * @window: a #GdkWindow
4762 * Thaws a window frozen with gdk_window_freeze_updates().
4765 gdk_window_thaw_updates (GdkWindow *window)
4767 GdkWindow *impl_window;
4769 g_return_if_fail (GDK_IS_WINDOW (window));
4771 impl_window = gdk_window_get_impl_window (window);
4773 g_return_if_fail (impl_window->update_freeze_count > 0);
4775 if (--impl_window->update_freeze_count == 0)
4776 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4780 * gdk_window_freeze_toplevel_updates_libgtk_only:
4781 * @window: a #GdkWindow
4783 * Temporarily freezes a window and all its descendants such that it won't
4784 * receive expose events. The window will begin receiving expose events
4785 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4786 * gdk_window_freeze_toplevel_updates_libgtk_only()
4787 * has been called more than once,
4788 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4789 * an equal number of times to begin processing exposes.
4791 * This function is not part of the GDK public API and is only
4795 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4797 g_return_if_fail (GDK_IS_WINDOW (window));
4798 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4800 window->update_and_descendants_freeze_count++;
4804 * gdk_window_thaw_toplevel_updates_libgtk_only:
4805 * @window: a #GdkWindow
4807 * Thaws a window frozen with
4808 * gdk_window_freeze_toplevel_updates_libgtk_only().
4810 * This function is not part of the GDK public API and is only
4814 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4816 g_return_if_fail (GDK_IS_WINDOW (window));
4817 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4818 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4820 window->update_and_descendants_freeze_count--;
4822 gdk_window_schedule_update (window);
4826 * gdk_window_set_debug_updates:
4827 * @setting: %TRUE to turn on update debugging
4829 * With update debugging enabled, calls to
4830 * gdk_window_invalidate_region() clear the invalidated region of the
4831 * screen to a noticeable color, and GDK pauses for a short time
4832 * before sending exposes to windows during
4833 * gdk_window_process_updates(). The net effect is that you can see
4834 * the invalid region for each window and watch redraws as they
4835 * occur. This allows you to diagnose inefficiencies in your application.
4837 * In essence, because the GDK rendering model prevents all flicker,
4838 * if you are redrawing the same region 400 times you may never
4839 * notice, aside from noticing a speed problem. Enabling update
4840 * debugging causes GTK to flicker slowly and noticeably, so you can
4841 * see exactly what's being redrawn when, in what order.
4843 * The --gtk-debug=updates command line option passed to GTK+ programs
4844 * enables this debug option at application startup time. That's
4845 * usually more useful than calling gdk_window_set_debug_updates()
4846 * yourself, though you might want to use this function to enable
4847 * updates sometime after application startup time.
4851 gdk_window_set_debug_updates (gboolean setting)
4853 debug_updates = setting;
4857 * gdk_window_constrain_size:
4858 * @geometry: a #GdkGeometry structure
4859 * @flags: a mask indicating what portions of @geometry are set
4860 * @width: desired width of window
4861 * @height: desired height of the window
4862 * @new_width: (out): location to store resulting width
4863 * @new_height: (out): location to store resulting height
4865 * Constrains a desired width and height according to a
4866 * set of geometry hints (such as minimum and maximum size).
4869 gdk_window_constrain_size (GdkGeometry *geometry,
4876 /* This routine is partially borrowed from fvwm.
4878 * Copyright 1993, Robert Nation
4879 * You may use this code for any purpose, as long as the original
4880 * copyright remains in the source code and all documentation
4882 * which in turn borrows parts of the algorithm from uwm
4885 gint min_height = 0;
4886 gint base_width = 0;
4887 gint base_height = 0;
4890 gint max_width = G_MAXINT;
4891 gint max_height = G_MAXINT;
4893 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4895 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4897 base_width = geometry->base_width;
4898 base_height = geometry->base_height;
4899 min_width = geometry->min_width;
4900 min_height = geometry->min_height;
4902 else if (flags & GDK_HINT_BASE_SIZE)
4904 base_width = geometry->base_width;
4905 base_height = geometry->base_height;
4906 min_width = geometry->base_width;
4907 min_height = geometry->base_height;
4909 else if (flags & GDK_HINT_MIN_SIZE)
4911 base_width = geometry->min_width;
4912 base_height = geometry->min_height;
4913 min_width = geometry->min_width;
4914 min_height = geometry->min_height;
4917 if (flags & GDK_HINT_MAX_SIZE)
4919 max_width = geometry->max_width ;
4920 max_height = geometry->max_height;
4923 if (flags & GDK_HINT_RESIZE_INC)
4925 xinc = MAX (xinc, geometry->width_inc);
4926 yinc = MAX (yinc, geometry->height_inc);
4929 /* clamp width and height to min and max values
4931 width = CLAMP (width, min_width, max_width);
4932 height = CLAMP (height, min_height, max_height);
4934 /* shrink to base + N * inc
4936 width = base_width + FLOOR (width - base_width, xinc);
4937 height = base_height + FLOOR (height - base_height, yinc);
4939 /* constrain aspect ratio, according to:
4942 * min_aspect <= -------- <= max_aspect
4946 if (flags & GDK_HINT_ASPECT &&
4947 geometry->min_aspect > 0 &&
4948 geometry->max_aspect > 0)
4952 if (geometry->min_aspect * height > width)
4954 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4955 if (height - delta >= min_height)
4959 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4960 if (width + delta <= max_width)
4965 if (geometry->max_aspect * height < width)
4967 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4968 if (width - delta >= min_width)
4972 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4973 if (height + delta <= max_height)
4982 *new_height = height;
4986 * gdk_window_get_pointer:
4987 * @window: a #GdkWindow
4988 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4989 * return the X coordinate
4990 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4991 * return the Y coordinate
4992 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4995 * Obtains the current pointer position and modifier state.
4996 * The position is given in coordinates relative to the upper left
4997 * corner of @window.
4999 * Return value: (transfer none): the window containing the pointer (as with
5000 * gdk_window_at_pointer()), or %NULL if the window containing the
5001 * pointer isn't known to GDK
5003 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
5006 gdk_window_get_pointer (GdkWindow *window,
5009 GdkModifierType *mask)
5011 GdkDisplay *display;
5013 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5015 display = gdk_window_get_display (window);
5017 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
5021 * gdk_window_get_device_position:
5022 * @window: a #GdkWindow.
5023 * @device: pointer #GdkDevice to query to.
5024 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5025 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5026 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5028 * Obtains the current device position and modifier state.
5029 * The position is given in coordinates relative to the upper left
5030 * corner of @window.
5032 * Return value: (transfer none): The window underneath @device (as with
5033 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
5038 gdk_window_get_device_position (GdkWindow *window,
5042 GdkModifierType *mask)
5045 GdkModifierType tmp_mask;
5046 gboolean normal_child;
5048 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5049 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5050 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
5052 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
5056 /* We got the coords on the impl, convert to the window */
5057 tmp_x -= window->abs_x;
5058 tmp_y -= window->abs_y;
5067 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
5070 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5075 * gdk_get_default_root_window:
5077 * Obtains the root window (parent all other windows are inside)
5078 * for the default display and screen.
5080 * Return value: (transfer none): the default root window
5083 gdk_get_default_root_window (void)
5085 return gdk_screen_get_root_window (gdk_screen_get_default ());
5089 get_all_native_children (GdkWindow *window,
5095 for (l = window->children; l != NULL; l = l->next)
5099 if (gdk_window_has_impl (child))
5100 *native = g_list_prepend (*native, child);
5102 get_all_native_children (child, native);
5108 gdk_window_raise_internal (GdkWindow *window)
5110 GdkWindow *parent = window->parent;
5112 GList *native_children;
5114 GdkWindowImplClass *impl_class;
5118 parent->children = g_list_remove (parent->children, window);
5119 parent->children = g_list_prepend (parent->children, window);
5122 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5123 /* Just do native raise for toplevels */
5124 if (gdk_window_is_toplevel (window) ||
5125 /* The restack_under codepath should work correctly even if the parent
5126 is native, but it relies on the order of ->children to be correct,
5127 and some apps like SWT reorder the x windows without gdks knowledge,
5128 so we use raise directly in order to make these behave as before
5129 when using native windows */
5130 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5132 impl_class->raise (window);
5134 else if (gdk_window_has_impl (window))
5136 above = find_native_sibling_above (parent, window);
5139 listhead.data = window;
5140 listhead.next = NULL;
5141 listhead.prev = NULL;
5142 impl_class->restack_under ((GdkWindow *)above,
5146 impl_class->raise (window);
5150 native_children = NULL;
5151 get_all_native_children (window, &native_children);
5152 if (native_children != NULL)
5154 above = find_native_sibling_above (parent, window);
5157 impl_class->restack_under (above, native_children);
5160 /* Right order, since native_children is bottom-topmost first */
5161 for (l = native_children; l != NULL; l = l->next)
5162 impl_class->raise (l->data);
5165 g_list_free (native_children);
5171 /* Returns TRUE If the native window was mapped or unmapped */
5173 set_viewable (GdkWindow *w,
5177 GdkWindowImplClass *impl_class;
5180 if (w->viewable == val)
5186 recompute_visible_regions (w, FALSE, FALSE);
5188 for (l = w->children; l != NULL; l = l->next)
5192 if (GDK_WINDOW_IS_MAPPED (child) &&
5193 child->window_type != GDK_WINDOW_FOREIGN)
5194 set_viewable (child, val);
5197 if (gdk_window_has_impl (w) &&
5198 w->window_type != GDK_WINDOW_FOREIGN &&
5199 !gdk_window_is_toplevel (w))
5201 /* For most native windows we show/hide them not when they are
5202 * mapped/unmapped, because that may not produce the correct results.
5203 * For instance, if a native window have a non-native parent which is
5204 * hidden, but its native parent is viewable then showing the window
5205 * would make it viewable to X but its not viewable wrt the non-native
5206 * hierarchy. In order to handle this we track the gdk side viewability
5207 * and only map really viewable windows.
5209 * There are two exceptions though:
5211 * For foreign windows we don't want ever change the mapped state
5212 * except when explicitly done via gdk_window_show/hide, as this may
5213 * cause problems for client owning the foreign window when its window
5214 * is suddenly mapped or unmapped.
5216 * For toplevel windows embedded in a foreign window (e.g. a plug)
5217 * we sometimes synthesize a map of a window, but the native
5218 * window is really shown by the embedder, so we don't want to
5219 * do the show ourselves. We can't really tell this case from the normal
5220 * toplevel show as such toplevels are seen by gdk as parents of the
5221 * root window, so we make an exception for all toplevels.
5224 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5226 impl_class->show ((GdkWindow *)w, FALSE);
5228 impl_class->hide ((GdkWindow *)w);
5236 /* Returns TRUE If the native window was mapped or unmapped */
5238 _gdk_window_update_viewable (GdkWindow *window)
5242 if (window->window_type == GDK_WINDOW_FOREIGN ||
5243 window->window_type == GDK_WINDOW_ROOT)
5245 else if (gdk_window_is_toplevel (window) ||
5246 window->parent->viewable)
5247 viewable = GDK_WINDOW_IS_MAPPED (window);
5251 return set_viewable (window, viewable);
5255 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5257 GdkWindowImplClass *impl_class;
5258 gboolean was_mapped, was_viewable;
5261 g_return_if_fail (GDK_IS_WINDOW (window));
5263 if (window->destroyed)
5266 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5267 was_viewable = window->viewable;
5270 /* Keep children in (reverse) stacking order */
5271 gdk_window_raise_internal (window);
5273 if (gdk_window_has_impl (window))
5276 gdk_synthesize_window_state (window,
5277 GDK_WINDOW_STATE_WITHDRAWN,
5278 GDK_WINDOW_STATE_FOCUSED);
5285 did_show = _gdk_window_update_viewable (window);
5287 /* If it was already viewable the backend show op won't be called, call it
5288 again to ensure things happen right if the mapped tracking was not right
5289 for e.g. a foreign window.
5290 Dunno if this is strictly needed but its what happened pre-csw.
5291 Also show if not done by gdk_window_update_viewable. */
5292 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5294 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5295 impl_class->show (window, !did_show ? was_mapped : TRUE);
5298 if (!was_mapped && !gdk_window_has_impl (window))
5300 if (window->event_mask & GDK_STRUCTURE_MASK)
5301 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5303 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5304 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5307 if (!was_mapped || raise)
5309 recompute_visible_regions (window, TRUE, FALSE);
5311 /* If any decendants became visible we need to send visibility notify */
5312 gdk_window_update_visibility_recursively (window, NULL);
5314 if (gdk_window_is_viewable (window))
5316 _gdk_synthesize_crossing_events_for_geometry_change (window);
5317 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5323 * gdk_window_show_unraised:
5324 * @window: a #GdkWindow
5326 * Shows a #GdkWindow onscreen, but does not modify its stacking
5327 * order. In contrast, gdk_window_show() will raise the window
5328 * to the top of the window stack.
5330 * On the X11 platform, in Xlib terms, this function calls
5331 * XMapWindow() (it also updates some internal GDK state, which means
5332 * that you can't really use XMapWindow() directly on a GDK window).
5335 gdk_window_show_unraised (GdkWindow *window)
5337 gdk_window_show_internal (window, FALSE);
5342 * @window: a #GdkWindow
5344 * Raises @window to the top of the Z-order (stacking order), so that
5345 * other windows with the same parent window appear below @window.
5346 * This is true whether or not the windows are visible.
5348 * If @window is a toplevel, the window manager may choose to deny the
5349 * request to move the window in the Z-order, gdk_window_raise() only
5350 * requests the restack, does not guarantee it.
5353 gdk_window_raise (GdkWindow *window)
5355 g_return_if_fail (GDK_IS_WINDOW (window));
5357 if (window->destroyed)
5360 gdk_window_flush_if_exposing (window);
5362 /* Keep children in (reverse) stacking order */
5363 gdk_window_raise_internal (window);
5365 recompute_visible_regions (window, TRUE, FALSE);
5367 if (gdk_window_is_viewable (window) &&
5368 !window->input_only)
5369 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5373 gdk_window_lower_internal (GdkWindow *window)
5375 GdkWindow *parent = window->parent;
5376 GdkWindowImplClass *impl_class;
5378 GList *native_children;
5383 parent->children = g_list_remove (parent->children, window);
5384 parent->children = g_list_append (parent->children, window);
5387 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5388 /* Just do native lower for toplevels */
5389 if (gdk_window_is_toplevel (window) ||
5390 /* The restack_under codepath should work correctly even if the parent
5391 is native, but it relies on the order of ->children to be correct,
5392 and some apps like SWT reorder the x windows without gdks knowledge,
5393 so we use lower directly in order to make these behave as before
5394 when using native windows */
5395 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5397 impl_class->lower (window);
5399 else if (gdk_window_has_impl (window))
5401 above = find_native_sibling_above (parent, window);
5404 listhead.data = window;
5405 listhead.next = NULL;
5406 listhead.prev = NULL;
5407 impl_class->restack_under ((GdkWindow *)above, &listhead);
5410 impl_class->raise (window);
5414 native_children = NULL;
5415 get_all_native_children (window, &native_children);
5416 if (native_children != NULL)
5418 above = find_native_sibling_above (parent, window);
5421 impl_class->restack_under ((GdkWindow *)above,
5425 /* Right order, since native_children is bottom-topmost first */
5426 for (l = native_children; l != NULL; l = l->next)
5427 impl_class->raise (l->data);
5430 g_list_free (native_children);
5437 gdk_window_invalidate_in_parent (GdkWindow *private)
5439 GdkRectangle r, child;
5441 if (gdk_window_is_toplevel (private))
5444 /* get the visible rectangle of the parent */
5446 r.width = private->parent->width;
5447 r.height = private->parent->height;
5449 child.x = private->x;
5450 child.y = private->y;
5451 child.width = private->width;
5452 child.height = private->height;
5453 gdk_rectangle_intersect (&r, &child, &r);
5455 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5461 * @window: a #GdkWindow
5463 * Lowers @window to the bottom of the Z-order (stacking order), so that
5464 * other windows with the same parent window appear above @window.
5465 * This is true whether or not the other windows are visible.
5467 * If @window is a toplevel, the window manager may choose to deny the
5468 * request to move the window in the Z-order, gdk_window_lower() only
5469 * requests the restack, does not guarantee it.
5471 * Note that gdk_window_show() raises the window again, so don't call this
5472 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5475 gdk_window_lower (GdkWindow *window)
5477 g_return_if_fail (GDK_IS_WINDOW (window));
5479 if (window->destroyed)
5482 gdk_window_flush_if_exposing (window);
5484 /* Keep children in (reverse) stacking order */
5485 gdk_window_lower_internal (window);
5487 recompute_visible_regions (window, TRUE, FALSE);
5489 _gdk_synthesize_crossing_events_for_geometry_change (window);
5490 gdk_window_invalidate_in_parent (window);
5494 * gdk_window_restack:
5495 * @window: a #GdkWindow
5496 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5499 * Changes the position of @window in the Z-order (stacking order), so that
5500 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5503 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5504 * lowers the window.
5506 * If @window is a toplevel, the window manager may choose to deny the
5507 * request to move the window in the Z-order, gdk_window_restack() only
5508 * requests the restack, does not guarantee it.
5513 gdk_window_restack (GdkWindow *window,
5517 GdkWindowImplClass *impl_class;
5519 GdkWindow *above_native;
5520 GList *sibling_link;
5521 GList *native_children;
5524 g_return_if_fail (GDK_IS_WINDOW (window));
5525 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5527 if (window->destroyed)
5530 if (sibling == NULL)
5533 gdk_window_raise (window);
5535 gdk_window_lower (window);
5539 gdk_window_flush_if_exposing (window);
5541 if (gdk_window_is_toplevel (window))
5543 g_return_if_fail (gdk_window_is_toplevel (sibling));
5544 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5545 impl_class->restack_toplevel (window, sibling, above);
5549 parent = window->parent;
5552 sibling_link = g_list_find (parent->children, sibling);
5553 g_return_if_fail (sibling_link != NULL);
5554 if (sibling_link == NULL)
5557 parent->children = g_list_remove (parent->children, window);
5559 parent->children = g_list_insert_before (parent->children,
5563 parent->children = g_list_insert_before (parent->children,
5567 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5568 if (gdk_window_has_impl (window))
5570 above_native = find_native_sibling_above (parent, window);
5573 listhead.data = window;
5574 listhead.next = NULL;
5575 listhead.prev = NULL;
5576 impl_class->restack_under (above_native, &listhead);
5579 impl_class->raise (window);
5583 native_children = NULL;
5584 get_all_native_children (window, &native_children);
5585 if (native_children != NULL)
5587 above_native = find_native_sibling_above (parent, window);
5589 impl_class->restack_under (above_native,
5593 /* Right order, since native_children is bottom-topmost first */
5594 for (l = native_children; l != NULL; l = l->next)
5595 impl_class->raise (l->data);
5598 g_list_free (native_children);
5603 recompute_visible_regions (window, TRUE, FALSE);
5605 _gdk_synthesize_crossing_events_for_geometry_change (window);
5606 gdk_window_invalidate_in_parent (window);
5612 * @window: a #GdkWindow
5614 * Like gdk_window_show_unraised(), but also raises the window to the
5615 * top of the window stack (moves the window to the front of the
5618 * This function maps a window so it's visible onscreen. Its opposite
5619 * is gdk_window_hide().
5621 * When implementing a #GtkWidget, you should call this function on the widget's
5622 * #GdkWindow as part of the "map" method.
5625 gdk_window_show (GdkWindow *window)
5627 gdk_window_show_internal (window, TRUE);
5632 * @window: a #GdkWindow
5634 * For toplevel windows, withdraws them, so they will no longer be
5635 * known to the window manager; for all windows, unmaps them, so
5636 * they won't be displayed. Normally done automatically as
5637 * part of gtk_widget_hide().
5640 gdk_window_hide (GdkWindow *window)
5642 GdkWindowImplClass *impl_class;
5643 gboolean was_mapped, did_hide;
5645 g_return_if_fail (GDK_IS_WINDOW (window));
5647 if (window->destroyed)
5650 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5652 if (gdk_window_has_impl (window))
5655 if (GDK_WINDOW_IS_MAPPED (window))
5656 gdk_synthesize_window_state (window,
5658 GDK_WINDOW_STATE_WITHDRAWN);
5660 else if (was_mapped)
5662 GdkDisplay *display;
5663 GdkDeviceManager *device_manager;
5666 /* May need to break grabs on children */
5667 display = gdk_window_get_display (window);
5668 device_manager = gdk_display_get_device_manager (display);
5670 /* Get all devices */
5671 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5672 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5673 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5675 for (d = devices; d; d = d->next)
5677 GdkDevice *device = d->data;
5679 if (_gdk_display_end_device_grab (display,
5681 _gdk_display_get_next_serial (display),
5684 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5687 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5688 g_list_free (devices);
5691 did_hide = _gdk_window_update_viewable (window);
5693 /* Hide foreign window as those are not handled by update_viewable. */
5694 if (gdk_window_has_impl (window) && (!did_hide))
5696 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5697 impl_class->hide (window);
5700 recompute_visible_regions (window, TRUE, FALSE);
5702 /* all decendants became non-visible, we need to send visibility notify */
5703 gdk_window_update_visibility_recursively (window, NULL);
5705 if (was_mapped && !gdk_window_has_impl (window))
5707 if (window->event_mask & GDK_STRUCTURE_MASK)
5708 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5710 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5711 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5713 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5716 /* Invalidate the rect */
5718 gdk_window_invalidate_in_parent (window);
5722 * gdk_window_withdraw:
5723 * @window: a toplevel #GdkWindow
5725 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5726 * This function is not really useful as gdk_window_hide() automatically
5727 * withdraws toplevel windows before hiding them.
5730 gdk_window_withdraw (GdkWindow *window)
5732 GdkWindowImplClass *impl_class;
5733 gboolean was_mapped;
5735 g_return_if_fail (GDK_IS_WINDOW (window));
5737 if (window->destroyed)
5740 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5742 if (gdk_window_has_impl (window))
5744 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5745 impl_class->withdraw (window);
5749 if (window->event_mask & GDK_STRUCTURE_MASK)
5750 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5752 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5753 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5755 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5758 recompute_visible_regions (window, TRUE, FALSE);
5763 * gdk_window_set_events:
5764 * @window: a #GdkWindow
5765 * @event_mask: event mask for @window
5767 * The event mask for a window determines which events will be reported
5768 * for that window from all master input devices. For example, an event mask
5769 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5770 * press events. The event mask is the bitwise OR of values from the
5771 * #GdkEventMask enumeration.
5774 gdk_window_set_events (GdkWindow *window,
5775 GdkEventMask event_mask)
5777 GdkWindowImplClass *impl_class;
5778 GdkDisplay *display;
5780 g_return_if_fail (GDK_IS_WINDOW (window));
5782 if (window->destroyed)
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))
5790 GList *devices = window->devices_inside;
5794 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5795 devices = devices->next;
5799 window->event_mask = event_mask;
5801 if (gdk_window_has_impl (window))
5803 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5804 impl_class->set_events (window,
5805 get_native_event_mask (window));
5811 * gdk_window_get_events:
5812 * @window: a #GdkWindow
5814 * Gets the event mask for @window for all master input devices. See
5815 * gdk_window_set_events().
5817 * Return value: event mask for @window
5820 gdk_window_get_events (GdkWindow *window)
5822 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5824 if (window->destroyed)
5827 return window->event_mask;
5831 * gdk_window_set_device_events:
5832 * @window: a #GdkWindow
5833 * @device: #GdkDevice to enable events for.
5834 * @event_mask: event mask for @window
5836 * Sets the event mask for a given device (Normally a floating device, not
5837 * attached to any visible pointer) to @window. For example, an event mask
5838 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5839 * press events. The event mask is the bitwise OR of values from the
5840 * #GdkEventMask enumeration.
5845 gdk_window_set_device_events (GdkWindow *window,
5847 GdkEventMask event_mask)
5849 GdkEventMask device_mask;
5850 GdkDisplay *display;
5853 g_return_if_fail (GDK_IS_WINDOW (window));
5854 g_return_if_fail (GDK_IS_DEVICE (device));
5856 if (GDK_WINDOW_DESTROYED (window))
5859 /* If motion hint is disabled, enable motion events again */
5860 display = gdk_window_get_display (window);
5861 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5862 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5863 _gdk_display_enable_motion_hints (display, device);
5865 if (G_UNLIKELY (!window->device_events))
5866 window->device_events = g_hash_table_new (NULL, NULL);
5868 if (event_mask == 0)
5870 /* FIXME: unsetting events on a master device
5871 * would restore window->event_mask
5873 g_hash_table_remove (window->device_events, device);
5876 g_hash_table_insert (window->device_events, device,
5877 GINT_TO_POINTER (event_mask));
5879 native = gdk_window_get_toplevel (window);
5881 while (gdk_window_is_offscreen (native))
5883 native = gdk_offscreen_window_get_embedder (native);
5885 if (native == NULL ||
5886 (!_gdk_window_has_impl (native) &&
5887 !gdk_window_is_viewable (native)))
5890 native = gdk_window_get_toplevel (native);
5893 device_mask = get_native_device_event_mask (window, device);
5894 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5898 * gdk_window_get_device_events:
5899 * @window: a #GdkWindow.
5900 * @device: a #GdkDevice.
5902 * Returns the event mask for @window corresponding to an specific device.
5904 * Returns: device event mask for @window
5909 gdk_window_get_device_events (GdkWindow *window,
5914 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5915 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5917 if (GDK_WINDOW_DESTROYED (window))
5920 if (!window->device_events)
5923 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5925 /* FIXME: device could be controlled by window->event_mask */
5931 gdk_window_move_resize_toplevel (GdkWindow *window,
5938 cairo_region_t *old_region, *new_region;
5939 GdkWindowImplClass *impl_class;
5946 is_resize = (width != -1) || (height != -1);
5948 if (gdk_window_is_viewable (window) &&
5949 !window->input_only)
5952 old_region = cairo_region_copy (window->clip_region);
5955 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5956 impl_class->move_resize (window, with_move, x, y, width, height);
5958 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5960 recompute_visible_regions (window, TRUE, FALSE);
5964 new_region = cairo_region_copy (window->clip_region);
5966 /* This is the newly exposed area (due to any resize),
5967 * X will expose it, but lets do that without the roundtrip
5969 cairo_region_subtract (new_region, old_region);
5970 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
5972 cairo_region_destroy (old_region);
5973 cairo_region_destroy (new_region);
5976 _gdk_synthesize_crossing_events_for_geometry_change (window);
5981 move_native_children (GdkWindow *private)
5985 GdkWindowImplClass *impl_class;
5987 for (l = private->children; l; l = l->next)
5991 if (child->impl != private->impl)
5993 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
5994 impl_class->move_resize (child, TRUE,
5996 child->width, child->height);
5999 move_native_children (child);
6004 collect_native_child_region_helper (GdkWindow *window,
6005 GdkWindowImpl *impl,
6006 cairo_region_t **region,
6011 cairo_region_t *tmp;
6014 for (l = window->children; l != NULL; l = l->next)
6018 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
6021 if (child->impl != impl)
6023 tmp = cairo_region_copy (child->clip_region);
6024 cairo_region_translate (tmp,
6025 x_offset + child->x,
6026 y_offset + child->y);
6027 if (*region == NULL)
6031 cairo_region_union (*region, tmp);
6032 cairo_region_destroy (tmp);
6036 collect_native_child_region_helper (child, impl, region,
6037 x_offset + child->x,
6038 y_offset + child->y);
6044 static cairo_region_t *
6045 collect_native_child_region (GdkWindow *window,
6046 gboolean include_this)
6048 cairo_region_t *region;
6050 if (include_this && gdk_window_has_impl (window) && window->viewable)
6051 return cairo_region_copy (window->clip_region);
6055 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6062 gdk_window_move_resize_internal (GdkWindow *window,
6069 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
6070 cairo_region_t *old_native_child_region, *new_native_child_region;
6071 GdkWindow *impl_window;
6072 GdkWindowImplClass *impl_class;
6074 int old_x, old_y, old_abs_x, old_abs_y;
6077 g_return_if_fail (GDK_IS_WINDOW (window));
6079 if (window->destroyed)
6082 if (gdk_window_is_toplevel (window))
6084 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6088 /* Bail early if no change */
6089 if (window->width == width &&
6090 window->height == height &&
6096 gdk_window_flush_if_exposing (window);
6098 /* Handle child windows */
6104 impl_window = gdk_window_get_impl_window (window);
6109 old_native_child_region = NULL;
6110 if (gdk_window_is_viewable (window) &&
6111 !window->input_only)
6115 old_region = cairo_region_copy (window->clip_region);
6116 old_layered = cairo_region_copy (window->layered_region);
6117 /* Adjust regions to parent window coords */
6118 cairo_region_translate (old_region, window->x, window->y);
6119 cairo_region_translate (old_layered, window->x, window->y);
6121 old_native_child_region = collect_native_child_region (window, TRUE);
6122 if (old_native_child_region)
6124 /* Adjust region to parent window coords */
6125 cairo_region_translate (old_native_child_region, window->x, window->y);
6127 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6128 * source or destination for a delayed GdkWindowRegionMove. So, we need
6129 * to flush those here for the parent window and all overlapped subwindows
6130 * of it. And we need to do this before setting the new clips as those will be
6133 gdk_window_flush_recursive (window->parent);
6137 /* Set the new position and size */
6143 if (!(width < 0 && height < 0))
6147 window->width = width;
6150 window->height = height;
6153 dx = window->x - old_x;
6154 dy = window->y - old_y;
6156 old_abs_x = window->abs_x;
6157 old_abs_y = window->abs_y;
6159 recompute_visible_regions (window, TRUE, FALSE);
6161 new_native_child_region = NULL;
6162 if (old_native_child_region)
6164 new_native_child_region = collect_native_child_region (window, TRUE);
6165 /* Adjust region to parent window coords */
6166 cairo_region_translate (new_native_child_region, window->x, window->y);
6169 if (gdk_window_has_impl (window))
6171 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6173 /* Do the actual move after recomputing things, as this will have set the shape to
6174 the now correct one, thus avoiding copying regions that should not be copied. */
6175 impl_class->move_resize (window, TRUE,
6176 window->x, window->y,
6177 window->width, window->height);
6179 else if (old_abs_x != window->abs_x ||
6180 old_abs_y != window->abs_y)
6181 move_native_children (window);
6185 new_region = cairo_region_copy (window->clip_region);
6186 /* Adjust region to parent window coords */
6187 cairo_region_translate (new_region, window->x, window->y);
6190 * Part of the data at the new location can be copied from the
6191 * old location, this area is the intersection of the old region
6192 * moved as the copy will move it and then intersected with
6196 * Everything in the old and new regions that is not copied must be
6197 * invalidated (including children) as this is newly exposed
6199 if (window->has_alpha_background)
6200 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6202 copy_area = cairo_region_copy (new_region);
6204 /* Don't copy from a previously layered region */
6205 cairo_region_translate (old_layered, dx, dy);
6206 cairo_region_subtract (copy_area, old_layered);
6208 /* Don't copy into a layered region */
6209 cairo_region_translate (copy_area, -window->x, -window->y);
6210 cairo_region_subtract (copy_area, window->layered_region);
6211 cairo_region_translate (copy_area, window->x, window->y);
6213 cairo_region_union (new_region, old_region);
6215 if (old_native_child_region)
6217 /* Don't copy from inside native children, as this is copied by
6218 * the native window move.
6220 cairo_region_subtract (old_region, old_native_child_region);
6222 cairo_region_translate (old_region, dx, dy);
6224 cairo_region_intersect (copy_area, old_region);
6226 if (new_native_child_region)
6228 /* Don't copy any bits that would cause a read from the moved
6229 native windows, as we can't read that data */
6230 cairo_region_translate (new_native_child_region, dx, dy);
6231 cairo_region_subtract (copy_area, new_native_child_region);
6232 cairo_region_translate (new_native_child_region, -dx, -dy);
6235 cairo_region_subtract (new_region, copy_area);
6237 /* Convert old region to impl coords */
6238 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6240 /* convert from parent coords to impl */
6241 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6243 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6245 /* Invalidate affected part in the parent window
6246 * (no higher window should be affected)
6247 * We also invalidate any children in that area, which could include
6248 * this window if it still overlaps that area.
6250 if (old_native_child_region)
6252 /* No need to expose the region that the native window move copies */
6253 cairo_region_translate (old_native_child_region, dx, dy);
6254 cairo_region_intersect (old_native_child_region, new_native_child_region);
6255 cairo_region_subtract (new_region, old_native_child_region);
6257 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6259 cairo_region_destroy (old_region);
6260 cairo_region_destroy (old_layered);
6261 cairo_region_destroy (new_region);
6264 if (old_native_child_region)
6266 cairo_region_destroy (old_native_child_region);
6267 cairo_region_destroy (new_native_child_region);
6270 _gdk_synthesize_crossing_events_for_geometry_change (window);
6277 * @window: a #GdkWindow
6278 * @x: X coordinate relative to window's parent
6279 * @y: Y coordinate relative to window's parent
6281 * Repositions a window relative to its parent window.
6282 * For toplevel windows, window managers may ignore or modify the move;
6283 * you should probably use gtk_window_move() on a #GtkWindow widget
6284 * anyway, instead of using GDK functions. For child windows,
6285 * the move will reliably succeed.
6287 * If you're also planning to resize the window, use gdk_window_move_resize()
6288 * to both move and resize simultaneously, for a nicer visual effect.
6291 gdk_window_move (GdkWindow *window,
6295 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6299 * gdk_window_resize:
6300 * @window: a #GdkWindow
6301 * @width: new width of the window
6302 * @height: new height of the window
6304 * Resizes @window; for toplevel windows, asks the window manager to resize
6305 * the window. The window manager may not allow the resize. When using GTK+,
6306 * use gtk_window_resize() instead of this low-level GDK function.
6308 * Windows may not be resized below 1x1.
6310 * If you're also planning to move the window, use gdk_window_move_resize()
6311 * to both move and resize simultaneously, for a nicer visual effect.
6314 gdk_window_resize (GdkWindow *window,
6318 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6323 * gdk_window_move_resize:
6324 * @window: a #GdkWindow
6325 * @x: new X position relative to window's parent
6326 * @y: new Y position relative to window's parent
6328 * @height: new height
6330 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6331 * except that both operations are performed at once, avoiding strange
6332 * visual effects. (i.e. the user may be able to see the window first
6333 * move, then resize, if you don't use gdk_window_move_resize().)
6336 gdk_window_move_resize (GdkWindow *window,
6342 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6347 * gdk_window_scroll:
6348 * @window: a #GdkWindow
6349 * @dx: Amount to scroll in the X direction
6350 * @dy: Amount to scroll in the Y direction
6352 * Scroll the contents of @window, both pixels and children, by the
6353 * given amount. @window itself does not move. Portions of the window
6354 * that the scroll operation brings in from offscreen areas are
6355 * invalidated. The invalidated region may be bigger than what would
6356 * strictly be necessary.
6358 * For X11, a minimum area will be invalidated if the window has no
6359 * subwindows, or if the edges of the window's parent do not extend
6360 * beyond the edges of the window. In other cases, a multi-step process
6361 * is used to scroll the window which may produce temporary visual
6362 * artifacts and unnecessary invalidations.
6365 gdk_window_scroll (GdkWindow *window,
6369 GdkWindow *impl_window;
6370 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6371 cairo_region_t *old_native_child_region, *new_native_child_region;
6374 g_return_if_fail (GDK_IS_WINDOW (window));
6376 if (dx == 0 && dy == 0)
6379 if (window->destroyed)
6382 gdk_window_flush_if_exposing (window);
6384 old_layered_area = cairo_region_copy (window->layered_region);
6385 old_native_child_region = collect_native_child_region (window, FALSE);
6386 if (old_native_child_region)
6388 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6389 * source or destination for a delayed GdkWindowRegionMove. So, we need
6390 * to flush those here for the window and all overlapped subwindows
6391 * of it. And we need to do this before setting the new clips as those will be
6394 gdk_window_flush_recursive (window);
6398 /* First move all child windows, without causing invalidation */
6400 tmp_list = window->children;
6403 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6405 /* Just update the positions, the bits will move with the copy */
6409 tmp_list = tmp_list->next;
6412 recompute_visible_regions (window, FALSE, TRUE);
6414 new_native_child_region = NULL;
6415 if (old_native_child_region)
6416 new_native_child_region = collect_native_child_region (window, FALSE);
6418 move_native_children (window);
6420 /* Then copy the actual bits of the window w/ child windows */
6422 impl_window = gdk_window_get_impl_window (window);
6424 /* Calculate the area that can be gotten by copying the old area */
6425 if (window->has_alpha_background)
6426 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6428 copy_area = cairo_region_copy (window->clip_region);
6429 cairo_region_subtract (copy_area, old_layered_area);
6430 if (old_native_child_region)
6432 /* Don't copy from inside native children, as this is copied by
6433 * the native window move.
6435 cairo_region_subtract (copy_area, old_native_child_region);
6437 /* Don't copy any bits that would cause a read from the moved
6438 native windows, as we can't read that data */
6439 cairo_region_subtract (copy_area, new_native_child_region);
6441 cairo_region_translate (copy_area, dx, dy);
6442 cairo_region_intersect (copy_area, window->clip_region);
6443 cairo_region_subtract (copy_area, window->layered_region);
6445 /* And the rest need to be invalidated */
6446 noncopy_area = cairo_region_copy (window->clip_region);
6447 cairo_region_subtract (noncopy_area, copy_area);
6449 /* convert from window coords to impl */
6450 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6452 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6454 /* Invalidate not copied regions */
6455 if (old_native_child_region)
6457 /* No need to expose the region that the native window move copies */
6458 cairo_region_translate (old_native_child_region, dx, dy);
6459 cairo_region_intersect (old_native_child_region, new_native_child_region);
6460 cairo_region_subtract (noncopy_area, old_native_child_region);
6462 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6464 cairo_region_destroy (noncopy_area);
6465 cairo_region_destroy (old_layered_area);
6467 if (old_native_child_region)
6469 cairo_region_destroy (old_native_child_region);
6470 cairo_region_destroy (new_native_child_region);
6473 _gdk_synthesize_crossing_events_for_geometry_change (window);
6477 * gdk_window_move_region:
6478 * @window: a #GdkWindow
6479 * @region: The #cairo_region_t to move
6480 * @dx: Amount to move in the X direction
6481 * @dy: Amount to move in the Y direction
6483 * Move the part of @window indicated by @region by @dy pixels in the Y
6484 * direction and @dx pixels in the X direction. The portions of @region
6485 * that not covered by the new position of @region are invalidated.
6487 * Child windows are not moved.
6492 gdk_window_move_region (GdkWindow *window,
6493 const cairo_region_t *region,
6497 GdkWindow *impl_window;
6498 cairo_region_t *nocopy_area;
6499 cairo_region_t *copy_area;
6501 g_return_if_fail (GDK_IS_WINDOW (window));
6502 g_return_if_fail (region != NULL);
6504 if (dx == 0 && dy == 0)
6507 if (window->destroyed)
6510 impl_window = gdk_window_get_impl_window (window);
6512 /* compute source regions */
6513 if (window->has_alpha_background)
6514 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6516 copy_area = cairo_region_copy (region);
6517 cairo_region_intersect (copy_area, window->clip_region_with_children);
6518 cairo_region_subtract (copy_area, window->layered_region);
6519 remove_layered_child_area (window, copy_area);
6521 /* compute destination regions */
6522 cairo_region_translate (copy_area, dx, dy);
6523 cairo_region_intersect (copy_area, window->clip_region_with_children);
6524 cairo_region_subtract (copy_area, window->layered_region);
6525 remove_layered_child_area (window, copy_area);
6527 /* Invalidate parts of the region (source and dest) not covered
6529 nocopy_area = cairo_region_copy (region);
6530 cairo_region_translate (nocopy_area, dx, dy);
6531 cairo_region_union (nocopy_area, region);
6532 cairo_region_subtract (nocopy_area, copy_area);
6534 /* convert from window coords to impl */
6535 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6536 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6538 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6539 cairo_region_destroy (nocopy_area);
6543 * gdk_window_set_background:
6544 * @window: a #GdkWindow
6545 * @color: a #GdkColor
6547 * Sets the background color of @window. (However, when using GTK+,
6548 * set the background of a widget with gtk_widget_modify_bg() - if
6549 * you're an application - or gtk_style_set_background() - if you're
6550 * implementing a custom widget.)
6552 * See also gdk_window_set_background_pattern().
6554 * Deprecated: 3.4: Use gdk_window_set_background_rgba() instead.
6557 gdk_window_set_background (GdkWindow *window,
6558 const GdkColor *color)
6560 cairo_pattern_t *pattern;
6562 g_return_if_fail (GDK_IS_WINDOW (window));
6564 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6565 color->green / 65535.,
6566 color->blue / 65535.);
6568 gdk_window_set_background_pattern (window, pattern);
6570 cairo_pattern_destroy (pattern);
6574 * gdk_window_set_background_rgba:
6575 * @window: a #GdkWindow
6576 * @rgba: a #GdkRGBA color
6578 * Sets the background color of @window.
6580 * See also gdk_window_set_background_pattern().
6583 gdk_window_set_background_rgba (GdkWindow *window,
6586 cairo_pattern_t *pattern;
6588 g_return_if_fail (GDK_IS_WINDOW (window));
6589 g_return_if_fail (rgba != NULL);
6591 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6592 rgba->blue, rgba->alpha);
6594 gdk_window_set_background_pattern (window, pattern);
6596 cairo_pattern_destroy (pattern);
6600 /* Updates has_alpha_background recursively for all child windows
6601 that have parent-relative alpha */
6603 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6608 for (l = window->children; l; l = l->next)
6612 if (child->background == NULL &&
6613 child->has_alpha_background != window->has_alpha_background)
6615 child->has_alpha_background = window->has_alpha_background;
6616 recompute_visible_regions (child, TRUE, FALSE);
6617 _gdk_window_propagate_has_alpha_background (child);
6623 * gdk_window_set_background_pattern:
6624 * @window: a #GdkWindow
6625 * @pattern: (allow-none): a pattern to use, or %NULL
6627 * Sets the background of @window.
6629 * A background of %NULL means that the window will inherit its
6630 * background form its parent window.
6632 * The windowing system will normally fill a window with its background
6633 * when the window is obscured then exposed.
6636 gdk_window_set_background_pattern (GdkWindow *window,
6637 cairo_pattern_t *pattern)
6640 cairo_pattern_type_t type;
6642 g_return_if_fail (GDK_IS_WINDOW (window));
6644 if (window->input_only)
6648 cairo_pattern_reference (pattern);
6649 if (window->background)
6650 cairo_pattern_destroy (window->background);
6651 window->background = pattern;
6655 if (pattern == NULL)
6657 /* parent-relative, copy has_alpha from parent */
6658 if (window->parent == NULL ||
6659 window->parent->window_type == GDK_WINDOW_ROOT)
6662 has_alpha = window->parent->has_alpha_background;
6666 type = cairo_pattern_get_type (pattern);
6668 if (type == CAIRO_PATTERN_TYPE_SOLID)
6671 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6675 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6676 type == CAIRO_PATTERN_TYPE_RADIAL)
6682 cairo_pattern_get_color_stop_count (pattern, &n);
6684 for (i = 0; i < n; i++)
6686 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6687 NULL, NULL, NULL, &alpha);
6695 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6697 cairo_surface_t *surface;
6698 cairo_content_t content;
6700 cairo_pattern_get_surface (pattern, &surface);
6701 content = cairo_surface_get_content (surface);
6703 (content == CAIRO_CONTENT_ALPHA) ||
6704 (content == CAIRO_CONTENT_COLOR_ALPHA);
6708 if (has_alpha != window->has_alpha_background)
6710 window->has_alpha_background = has_alpha;
6711 recompute_visible_regions (window, TRUE, FALSE);
6713 _gdk_window_propagate_has_alpha_background (window);
6716 if (gdk_window_has_impl (window))
6718 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6719 impl_class->set_background (window, pattern);
6722 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6726 * gdk_window_get_background_pattern:
6729 * Gets the pattern used to clear the background on @window. If @window
6730 * does not have its own background and reuses the parent's, %NULL is
6731 * returned and you'll have to query it yourself.
6733 * Returns: (transfer none): The pattern to use for the background or
6734 * %NULL to use the parent's background.
6739 gdk_window_get_background_pattern (GdkWindow *window)
6741 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6743 return window->background;
6747 gdk_window_set_cursor_internal (GdkWindow *window,
6751 if (GDK_WINDOW_DESTROYED (window))
6754 if (window->window_type == GDK_WINDOW_ROOT ||
6755 window->window_type == GDK_WINDOW_FOREIGN)
6756 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6759 GdkPointerWindowInfo *pointer_info;
6760 GdkDisplay *display;
6762 display = gdk_window_get_display (window);
6763 pointer_info = _gdk_display_get_pointer_info (display, device);
6765 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6766 update_cursor (display, device);
6771 * gdk_window_get_cursor:
6772 * @window: a #GdkWindow
6774 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6775 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6776 * there is no custom cursor set on the specified window, and it is
6777 * using the cursor for its parent window.
6779 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6780 * object is owned by the #GdkWindow and should not be unreferenced
6781 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6787 gdk_window_get_cursor (GdkWindow *window)
6789 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6791 return window->cursor;
6795 * gdk_window_set_cursor:
6796 * @window: a #GdkWindow
6797 * @cursor: (allow-none): a cursor
6799 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6800 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6801 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6802 * to gdk_window_set_cursor() means that @window will use the cursor of its
6803 * parent window. Most windows should use this default.
6806 gdk_window_set_cursor (GdkWindow *window,
6809 GdkDisplay *display;
6811 g_return_if_fail (GDK_IS_WINDOW (window));
6813 display = gdk_window_get_display (window);
6817 g_object_unref (window->cursor);
6818 window->cursor = NULL;
6821 if (!GDK_WINDOW_DESTROYED (window))
6823 GdkDeviceManager *device_manager;
6827 window->cursor = g_object_ref (cursor);
6829 device_manager = gdk_display_get_device_manager (display);
6830 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6832 for (d = devices; d; d = d->next)
6838 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6841 gdk_window_set_cursor_internal (window, device, window->cursor);
6844 g_list_free (devices);
6845 g_object_notify (G_OBJECT (window), "cursor");
6850 * gdk_window_get_device_cursor:
6851 * @window: a #GdkWindow.
6852 * @device: a master, pointer #GdkDevice.
6854 * Retrieves a #GdkCursor pointer for the @device currently set on the
6855 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6856 * there is no custom cursor set on the specified window, and it is
6857 * using the cursor for its parent window.
6859 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6860 * object is owned by the #GdkWindow and should not be unreferenced
6861 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6867 gdk_window_get_device_cursor (GdkWindow *window,
6870 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6871 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6872 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6873 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6875 return g_hash_table_lookup (window->device_cursor, device);
6879 * gdk_window_set_device_cursor:
6880 * @window: a #Gdkwindow
6881 * @device: a master, pointer #GdkDevice
6882 * @cursor: a #GdkCursor
6884 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6885 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6886 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6887 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6888 * @window will use the cursor of its parent window. Most windows should
6894 gdk_window_set_device_cursor (GdkWindow *window,
6898 g_return_if_fail (GDK_IS_WINDOW (window));
6899 g_return_if_fail (GDK_IS_DEVICE (device));
6900 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6901 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6904 g_hash_table_remove (window->device_cursor, device);
6906 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6908 gdk_window_set_cursor_internal (window, device, cursor);
6912 * gdk_window_get_geometry:
6913 * @window: a #GdkWindow
6914 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6915 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6916 * @width: (out) (allow-none): return location for width of window
6917 * @height: (out) (allow-none): return location for height of window
6919 * Any of the return location arguments to this function may be %NULL,
6920 * if you aren't interested in getting the value of that field.
6922 * The X and Y coordinates returned are relative to the parent window
6923 * of @window, which for toplevels usually means relative to the
6924 * window decorations (titlebar, etc.) rather than relative to the
6925 * root window (screen-size background window).
6927 * On the X11 platform, the geometry is obtained from the X server,
6928 * so reflects the latest position of @window; this may be out-of-sync
6929 * with the position of @window delivered in the most-recently-processed
6930 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6931 * position from the most recent configure event.
6934 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6935 * to call gdk_window_get_position(), gdk_window_get_width() and
6936 * gdk_window_get_height() instead, because it avoids the roundtrip to
6937 * the X server and because these functions support the full 32-bit
6938 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6939 * the 16-bit coordinates of X11.
6943 gdk_window_get_geometry (GdkWindow *window,
6950 GdkWindowImplClass *impl_class;
6954 GDK_NOTE (MULTIHEAD,
6955 g_message ("gdk_window_get_geometry(): Window needs "
6956 "to be non-NULL to be multi head safe"));
6957 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6960 g_return_if_fail (GDK_IS_WINDOW (window));
6962 if (!GDK_WINDOW_DESTROYED (window))
6964 if (gdk_window_has_impl (window))
6966 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6967 impl_class->get_geometry (window, x, y,
6969 /* This reports the position wrt to the native parent, we need to convert
6970 it to be relative to the client side parent */
6971 parent = window->parent;
6972 if (parent && !gdk_window_has_impl (parent))
6975 *x -= parent->abs_x;
6977 *y -= parent->abs_y;
6987 *width = window->width;
6989 *height = window->height;
6995 * gdk_window_get_width:
6996 * @window: a #GdkWindow
6998 * Returns the width of the given @window.
7000 * On the X11 platform the returned size is the size reported in the
7001 * most-recently-processed configure event, rather than the current
7002 * size on the X server.
7004 * Returns: The width of @window
7009 gdk_window_get_width (GdkWindow *window)
7011 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7013 return window->width;
7017 * gdk_window_get_height:
7018 * @window: a #GdkWindow
7020 * Returns the height of the given @window.
7022 * On the X11 platform the returned size is the size reported in the
7023 * most-recently-processed configure event, rather than the current
7024 * size on the X server.
7026 * Returns: The height of @window
7031 gdk_window_get_height (GdkWindow *window)
7033 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7035 return window->height;
7039 * gdk_window_get_origin:
7040 * @window: a #GdkWindow
7041 * @x: (out) (allow-none): return location for X coordinate
7042 * @y: (out) (allow-none): return location for Y coordinate
7044 * Obtains the position of a window in root window coordinates.
7045 * (Compare with gdk_window_get_position() and
7046 * gdk_window_get_geometry() which return the position of a window
7047 * relative to its parent window.)
7049 * Return value: not meaningful, ignore
7052 gdk_window_get_origin (GdkWindow *window,
7056 GdkWindowImplClass *impl_class;
7058 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7060 if (GDK_WINDOW_DESTROYED (window))
7069 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7070 impl_class->get_root_coords (window,
7079 * gdk_window_get_root_coords:
7080 * @window: a #GdkWindow
7081 * @x: X coordinate in window
7082 * @y: Y coordinate in window
7083 * @root_x: (out): return location for X coordinate
7084 * @root_y: (out): return location for Y coordinate
7086 * Obtains the position of a window position in root
7087 * window coordinates. This is similar to
7088 * gdk_window_get_origin() but allows you go pass
7089 * in any position in the window, not just the origin.
7094 gdk_window_get_root_coords (GdkWindow *window,
7100 GdkWindowImplClass *impl_class;
7102 g_return_if_fail (GDK_IS_WINDOW (window));
7104 if (GDK_WINDOW_DESTROYED (window))
7111 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7112 impl_class->get_root_coords (window,
7119 * gdk_window_coords_to_parent:
7120 * @window: a child window
7121 * @x: X coordinate in child's coordinate system
7122 * @y: Y coordinate in child's coordinate system
7123 * @parent_x: (out) (allow-none): return location for X coordinate
7124 * in parent's coordinate system, or %NULL
7125 * @parent_y: (out) (allow-none): return location for Y coordinate
7126 * in parent's coordinate system, or %NULL
7128 * Transforms window coordinates from a child window to its parent
7129 * window, where the parent window is the normal parent as returned by
7130 * gdk_window_get_parent() for normal windows, and the window's
7131 * embedder as returned by gdk_offscreen_window_get_embedder() for
7132 * offscreen windows.
7134 * For normal windows, calling this function is equivalent to adding
7135 * the return values of gdk_window_get_position() to the child coordinates.
7136 * For offscreen windows however (which can be arbitrarily transformed),
7137 * this function calls the GdkWindow::to-embedder: signal to translate
7140 * You should always use this function when writing generic code that
7141 * walks up a window hierarchy.
7143 * See also: gdk_window_coords_from_parent()
7148 gdk_window_coords_to_parent (GdkWindow *window,
7154 g_return_if_fail (GDK_IS_WINDOW (window));
7156 if (gdk_window_is_offscreen (window))
7160 to_embedder (window, x, y, &px, &py);
7171 *parent_x = x + window->x;
7174 *parent_y = y + window->y;
7179 * gdk_window_coords_from_parent:
7180 * @window: a child window
7181 * @parent_x: X coordinate in parent's coordinate system
7182 * @parent_y: Y coordinate in parent's coordinate system
7183 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7184 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7186 * Transforms window coordinates from a parent window to a child
7187 * window, where the parent window is the normal parent as returned by
7188 * gdk_window_get_parent() for normal windows, and the window's
7189 * embedder as returned by gdk_offscreen_window_get_embedder() for
7190 * offscreen windows.
7192 * For normal windows, calling this function is equivalent to subtracting
7193 * the return values of gdk_window_get_position() from the parent coordinates.
7194 * For offscreen windows however (which can be arbitrarily transformed),
7195 * this function calls the GdkWindow::from-embedder: signal to translate
7198 * You should always use this function when writing generic code that
7199 * walks down a window hierarchy.
7201 * See also: gdk_window_coords_to_parent()
7206 gdk_window_coords_from_parent (GdkWindow *window,
7212 g_return_if_fail (GDK_IS_WINDOW (window));
7214 if (gdk_window_is_offscreen (window))
7218 from_embedder (window, parent_x, parent_y, &cx, &cy);
7229 *x = parent_x - window->x;
7232 *y = parent_y - window->y;
7237 * gdk_window_shape_combine_region:
7238 * @window: a #GdkWindow
7239 * @shape_region: (allow-none): region of window to be non-transparent
7240 * @offset_x: X position of @shape_region in @window coordinates
7241 * @offset_y: Y position of @shape_region in @window coordinates
7243 * Makes pixels in @window outside @shape_region be transparent,
7244 * so that the window may be nonrectangular.
7246 * If @shape_region is %NULL, the shape will be unset, so the whole
7247 * window will be opaque again. @offset_x and @offset_y are ignored
7248 * if @shape_region is %NULL.
7250 * On the X11 platform, this uses an X server extension which is
7251 * widely available on most common platforms, but not available on
7252 * very old X servers, and occasionally the implementation will be
7253 * buggy. On servers without the shape extension, this function
7256 * This function works on both toplevel and child windows.
7259 gdk_window_shape_combine_region (GdkWindow *window,
7260 const cairo_region_t *shape_region,
7264 cairo_region_t *old_region, *new_region, *diff;
7266 g_return_if_fail (GDK_IS_WINDOW (window));
7268 if (GDK_WINDOW_DESTROYED (window))
7271 if (!window->shape && shape_region == NULL)
7274 window->shaped = (shape_region != NULL);
7277 cairo_region_destroy (window->shape);
7280 if (GDK_WINDOW_IS_MAPPED (window))
7281 old_region = cairo_region_copy (window->clip_region);
7285 window->shape = cairo_region_copy (shape_region);
7286 cairo_region_translate (window->shape, offset_x, offset_y);
7289 window->shape = NULL;
7291 recompute_visible_regions (window, TRUE, FALSE);
7293 if (gdk_window_has_impl (window) &&
7294 !should_apply_clip_as_shape (window))
7295 apply_shape (window, window->shape);
7299 new_region = cairo_region_copy (window->clip_region);
7301 /* New area in the window, needs invalidation */
7302 diff = cairo_region_copy (new_region);
7303 cairo_region_subtract (diff, old_region);
7305 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7307 cairo_region_destroy (diff);
7309 if (!gdk_window_is_toplevel (window))
7311 /* New area in the non-root parent window, needs invalidation */
7312 diff = cairo_region_copy (old_region);
7313 cairo_region_subtract (diff, new_region);
7315 /* Adjust region to parent window coords */
7316 cairo_region_translate (diff, window->x, window->y);
7318 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7320 cairo_region_destroy (diff);
7323 cairo_region_destroy (new_region);
7324 cairo_region_destroy (old_region);
7329 do_child_shapes (GdkWindow *window,
7333 cairo_region_t *region;
7337 r.width = window->width;
7338 r.height = window->height;
7340 region = cairo_region_create_rectangle (&r);
7341 remove_child_area (window, NULL, FALSE, region, NULL);
7343 if (merge && window->shape)
7344 cairo_region_subtract (region, window->shape);
7346 gdk_window_shape_combine_region (window, region, 0, 0);
7350 * gdk_window_set_child_shapes:
7351 * @window: a #GdkWindow
7353 * Sets the shape mask of @window to the union of shape masks
7354 * for all children of @window, ignoring the shape mask of @window
7355 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7356 * the shape mask of @window in the masks to be merged.
7359 gdk_window_set_child_shapes (GdkWindow *window)
7361 g_return_if_fail (GDK_IS_WINDOW (window));
7363 do_child_shapes (window, FALSE);
7367 * gdk_window_merge_child_shapes:
7368 * @window: a #GdkWindow
7370 * Merges the shape masks for any child windows into the
7371 * shape mask for @window. i.e. the union of all masks
7372 * for @window and its children will become the new mask
7373 * for @window. See gdk_window_shape_combine_region().
7375 * This function is distinct from gdk_window_set_child_shapes()
7376 * because it includes @window's shape mask in the set of shapes to
7380 gdk_window_merge_child_shapes (GdkWindow *window)
7382 g_return_if_fail (GDK_IS_WINDOW (window));
7384 do_child_shapes (window, TRUE);
7388 * gdk_window_input_shape_combine_region:
7389 * @window: a #GdkWindow
7390 * @shape_region: region of window to be non-transparent
7391 * @offset_x: X position of @shape_region in @window coordinates
7392 * @offset_y: Y position of @shape_region in @window coordinates
7394 * Like gdk_window_shape_combine_region(), but the shape applies
7395 * only to event handling. Mouse events which happen while
7396 * the pointer position corresponds to an unset bit in the
7397 * mask will be passed on the window below @window.
7399 * An input shape is typically used with RGBA windows.
7400 * The alpha channel of the window defines which pixels are
7401 * invisible and allows for nicely antialiased borders,
7402 * and the input shape controls where the window is
7405 * On the X11 platform, this requires version 1.1 of the
7408 * On the Win32 platform, this functionality is not present and the
7409 * function does nothing.
7414 gdk_window_input_shape_combine_region (GdkWindow *window,
7415 const cairo_region_t *shape_region,
7419 GdkWindowImplClass *impl_class;
7421 g_return_if_fail (GDK_IS_WINDOW (window));
7423 if (GDK_WINDOW_DESTROYED (window))
7426 if (window->input_shape)
7427 cairo_region_destroy (window->input_shape);
7431 window->input_shape = cairo_region_copy (shape_region);
7432 cairo_region_translate (window->input_shape, offset_x, offset_y);
7435 window->input_shape = NULL;
7437 if (gdk_window_has_impl (window))
7439 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7440 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7443 /* Pointer may have e.g. moved outside window due to the input mask change */
7444 _gdk_synthesize_crossing_events_for_geometry_change (window);
7448 do_child_input_shapes (GdkWindow *window,
7452 cairo_region_t *region;
7456 r.width = window->width;
7457 r.height = window->height;
7459 region = cairo_region_create_rectangle (&r);
7460 remove_child_area (window, NULL, TRUE, region, NULL);
7462 if (merge && window->shape)
7463 cairo_region_subtract (region, window->shape);
7464 if (merge && window->input_shape)
7465 cairo_region_subtract (region, window->input_shape);
7467 gdk_window_input_shape_combine_region (window, region, 0, 0);
7472 * gdk_window_set_child_input_shapes:
7473 * @window: a #GdkWindow
7475 * Sets the input shape mask of @window to the union of input shape masks
7476 * for all children of @window, ignoring the input shape mask of @window
7477 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7478 * the input shape mask of @window in the masks to be merged.
7483 gdk_window_set_child_input_shapes (GdkWindow *window)
7485 g_return_if_fail (GDK_IS_WINDOW (window));
7487 do_child_input_shapes (window, FALSE);
7491 * gdk_window_merge_child_input_shapes:
7492 * @window: a #GdkWindow
7494 * Merges the input shape masks for any child windows into the
7495 * input shape mask for @window. i.e. the union of all input masks
7496 * for @window and its children will become the new input mask
7497 * for @window. See gdk_window_input_shape_combine_region().
7499 * This function is distinct from gdk_window_set_child_input_shapes()
7500 * because it includes @window's input shape mask in the set of
7501 * shapes to be merged.
7506 gdk_window_merge_child_input_shapes (GdkWindow *window)
7508 g_return_if_fail (GDK_IS_WINDOW (window));
7510 do_child_input_shapes (window, TRUE);
7515 * gdk_window_set_static_gravities:
7516 * @window: a #GdkWindow
7517 * @use_static: %TRUE to turn on static gravity
7519 * Set the bit gravity of the given window to static, and flag it so
7520 * all children get static subwindow gravity. This is used if you are
7521 * implementing scary features that involve deep knowledge of the
7522 * windowing system. Don't worry about it unless you have to.
7524 * Return value: %TRUE if the server supports static gravity
7527 gdk_window_set_static_gravities (GdkWindow *window,
7528 gboolean use_static)
7530 GdkWindowImplClass *impl_class;
7532 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7534 if (gdk_window_has_impl (window))
7536 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7537 return impl_class->set_static_gravities (window, use_static);
7544 * gdk_window_get_composited:
7545 * @window: a #GdkWindow
7547 * Determines whether @window is composited.
7549 * See gdk_window_set_composited().
7551 * Returns: %TRUE if the window is composited.
7556 gdk_window_get_composited (GdkWindow *window)
7558 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7560 return window->composited;
7564 * gdk_window_set_composited:
7565 * @window: a #GdkWindow
7566 * @composited: %TRUE to set the window as composited
7568 * Sets a #GdkWindow as composited, or unsets it. Composited
7569 * windows do not automatically have their contents drawn to
7570 * the screen. Drawing is redirected to an offscreen buffer
7571 * and an expose event is emitted on the parent of the composited
7572 * window. It is the responsibility of the parent's expose handler
7573 * to manually merge the off-screen content onto the screen in
7574 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7577 * It only makes sense for child windows to be composited; see
7578 * gdk_window_set_opacity() if you need translucent toplevel
7581 * An additional effect of this call is that the area of this
7582 * window is no longer clipped from regions marked for
7583 * invalidation on its parent. Draws done on the parent
7584 * window are also no longer clipped by the child.
7586 * This call is only supported on some systems (currently,
7587 * only X11 with new enough Xcomposite and Xdamage extensions).
7588 * You must call gdk_display_supports_composite() to check if
7589 * setting a window as composited is supported before
7590 * attempting to do so.
7595 gdk_window_set_composited (GdkWindow *window,
7596 gboolean composited)
7598 GdkDisplay *display;
7599 GdkWindowImplClass *impl_class;
7601 g_return_if_fail (GDK_IS_WINDOW (window));
7603 composited = composited != FALSE;
7605 if (window->composited == composited)
7609 gdk_window_ensure_native (window);
7611 display = gdk_window_get_display (window);
7613 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7615 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7617 g_warning ("gdk_window_set_composited called but "
7618 "compositing is not supported");
7622 impl_class->set_composited (window, composited);
7624 recompute_visible_regions (window, TRUE, FALSE);
7626 if (GDK_WINDOW_IS_MAPPED (window))
7627 gdk_window_invalidate_in_parent (window);
7629 window->composited = composited;
7633 * gdk_window_get_modal_hint:
7634 * @window: A toplevel #GdkWindow.
7636 * Determines whether or not the window manager is hinted that @window
7637 * has modal behaviour.
7639 * Return value: whether or not the window has the modal hint set.
7644 gdk_window_get_modal_hint (GdkWindow *window)
7646 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7648 return window->modal_hint;
7652 * gdk_window_get_accept_focus:
7653 * @window: a toplevel #GdkWindow.
7655 * Determines whether or not the desktop environment shuld be hinted that
7656 * the window does not want to receive input focus.
7658 * Return value: whether or not the window should receive input focus.
7663 gdk_window_get_accept_focus (GdkWindow *window)
7665 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7667 return window->accept_focus;
7671 * gdk_window_get_focus_on_map:
7672 * @window: a toplevel #GdkWindow.
7674 * Determines whether or not the desktop environment should be hinted that the
7675 * window does not want to receive input focus when it is mapped.
7677 * Return value: whether or not the window wants to receive input focus when
7683 gdk_window_get_focus_on_map (GdkWindow *window)
7685 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7687 return window->focus_on_map;
7691 * gdk_window_is_input_only:
7692 * @window: a toplevel #GdkWindow
7694 * Determines whether or not the window is an input only window.
7696 * Return value: %TRUE if @window is input only
7701 gdk_window_is_input_only (GdkWindow *window)
7703 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7705 return window->input_only;
7709 * gdk_window_is_shaped:
7710 * @window: a toplevel #GdkWindow
7712 * Determines whether or not the window is shaped.
7714 * Return value: %TRUE if @window is shaped
7719 gdk_window_is_shaped (GdkWindow *window)
7721 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7723 return window->shaped;
7727 _gdk_window_add_damage (GdkWindow *toplevel,
7728 cairo_region_t *damaged_region)
7730 GdkDisplay *display;
7731 GdkEvent event = { 0, };
7732 event.expose.type = GDK_DAMAGE;
7733 event.expose.window = toplevel;
7734 event.expose.send_event = FALSE;
7735 event.expose.region = damaged_region;
7736 cairo_region_get_extents (event.expose.region, &event.expose.area);
7737 display = gdk_window_get_display (event.expose.window);
7738 _gdk_event_queue_append (display, gdk_event_copy (&event));
7741 /* Gets the toplevel for a window as used for events,
7742 i.e. including offscreen parents */
7744 get_event_parent (GdkWindow *window)
7746 if (gdk_window_is_offscreen (window))
7747 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7749 return window->parent;
7752 /* Gets the toplevel for a window as used for events,
7753 i.e. including offscreen parents going up to the native
7756 get_event_toplevel (GdkWindow *window)
7760 while ((parent = get_event_parent (window)) != NULL &&
7761 (parent->window_type != GDK_WINDOW_ROOT))
7768 _gdk_window_event_parent_of (GdkWindow *parent,
7779 w = get_event_parent (w);
7786 update_cursor (GdkDisplay *display,
7789 GdkWindow *cursor_window, *parent, *toplevel;
7790 GdkWindow *pointer_window;
7791 GdkWindowImplClass *impl_class;
7792 GdkPointerWindowInfo *pointer_info;
7793 GdkDeviceGrabInfo *grab;
7796 pointer_info = _gdk_display_get_pointer_info (display, device);
7797 pointer_window = pointer_info->window_under_pointer;
7799 /* We ignore the serials here and just pick the last grab
7800 we've sent, as that would shortly be used anyway. */
7801 grab = _gdk_display_get_last_device_grab (display, device);
7804 /* the pointer is not in a descendant of the grab window */
7805 !_gdk_window_event_parent_of (grab->window, pointer_window))
7807 /* use the cursor from the grab window */
7808 cursor_window = grab->window;
7812 /* otherwise use the cursor from the pointer window */
7813 cursor_window = pointer_window;
7816 /* Find the first window with the cursor actually set, as
7817 the cursor is inherited from the parent */
7818 while (cursor_window->cursor == NULL &&
7819 (parent = get_event_parent (cursor_window)) != NULL &&
7820 parent->window_type != GDK_WINDOW_ROOT)
7821 cursor_window = parent;
7823 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7826 cursor = cursor_window->cursor;
7828 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7829 * which native window has what cursor set. */
7830 toplevel = get_event_toplevel (pointer_window);
7831 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7832 impl_class->set_device_cursor (toplevel, device, cursor);
7836 point_in_window (GdkWindow *window,
7841 x >= 0 && x < window->width &&
7842 y >= 0 && y < window->height &&
7843 (window->shape == NULL ||
7844 cairo_region_contains_point (window->shape,
7846 (window->input_shape == NULL ||
7847 cairo_region_contains_point (window->input_shape,
7852 convert_native_coords_to_toplevel (GdkWindow *window,
7855 gdouble *toplevel_x,
7856 gdouble *toplevel_y)
7863 while (!gdk_window_is_toplevel (window))
7867 window = window->parent;
7877 convert_toplevel_coords_to_window (GdkWindow *window,
7885 GList *children, *l;
7891 while ((parent = get_event_parent (window)) != NULL &&
7892 (parent->window_type != GDK_WINDOW_ROOT))
7894 children = g_list_prepend (children, window);
7898 for (l = children; l != NULL; l = l->next)
7899 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7901 g_list_free (children);
7908 pick_embedded_child (GdkWindow *window,
7915 g_signal_emit (window,
7916 signals[PICK_EMBEDDED_CHILD], 0,
7923 _gdk_window_find_child_at (GdkWindow *window,
7928 double child_x, child_y;
7931 if (point_in_window (window, x, y))
7933 /* Children is ordered in reverse stack order, i.e. first is topmost */
7934 for (l = window->children; l != NULL; l = l->next)
7938 if (!GDK_WINDOW_IS_MAPPED (sub))
7941 gdk_window_coords_from_parent ((GdkWindow *)sub,
7943 &child_x, &child_y);
7944 if (point_in_window (sub, child_x, child_y))
7945 return (GdkWindow *)sub;
7948 if (window->num_offscreen_children > 0)
7950 sub = pick_embedded_child (window,
7953 return (GdkWindow *)sub;
7961 _gdk_window_find_descendant_at (GdkWindow *window,
7968 gdouble child_x, child_y;
7972 if (point_in_window (window, x, y))
7977 /* Children is ordered in reverse stack order, i.e. first is topmost */
7978 for (l = window->children; l != NULL; l = l->next)
7982 if (!GDK_WINDOW_IS_MAPPED (sub))
7985 gdk_window_coords_from_parent ((GdkWindow *)sub,
7987 &child_x, &child_y);
7988 if (point_in_window (sub, child_x, child_y))
7998 window->num_offscreen_children > 0)
8000 sub = pick_embedded_child (window,
8006 from_embedder (sub, x, y, &x, &y);
8014 /* Not in window at all */
8028 * @window: a toplevel #GdkWindow
8030 * Emits a short beep associated to @window in the appropriate
8031 * display, if supported. Otherwise, emits a short beep on
8032 * the display just as gdk_display_beep().
8037 gdk_window_beep (GdkWindow *window)
8039 GdkDisplay *display;
8040 GdkWindow *toplevel;
8042 g_return_if_fail (GDK_IS_WINDOW (window));
8044 if (GDK_WINDOW_DESTROYED (window))
8047 toplevel = get_event_toplevel (window);
8048 display = gdk_window_get_display (window);
8052 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
8056 /* If windows fail to beep, we beep the display. */
8057 gdk_display_beep (display);
8061 * gdk_window_set_support_multidevice:
8062 * @window: a #GdkWindow.
8063 * @support_multidevice: %TRUE to enable multidevice support in @window.
8065 * This function will enable multidevice features in @window.
8067 * Multidevice aware windows will need to handle properly multiple,
8068 * per device enter/leave events, device grabs and grab ownerships.
8073 gdk_window_set_support_multidevice (GdkWindow *window,
8074 gboolean support_multidevice)
8076 g_return_if_fail (GDK_IS_WINDOW (window));
8078 if (GDK_WINDOW_DESTROYED (window))
8081 if (window->support_multidevice == support_multidevice)
8084 window->support_multidevice = support_multidevice;
8086 /* FIXME: What to do if called when some pointers are inside the window ? */
8090 * gdk_window_get_support_multidevice:
8091 * @window: a #GdkWindow.
8093 * Returns %TRUE if the window is aware of the existence of multiple
8096 * Returns: %TRUE if the window handles multidevice features.
8101 gdk_window_get_support_multidevice (GdkWindow *window)
8103 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8105 if (GDK_WINDOW_DESTROYED (window))
8108 return window->support_multidevice;
8111 static const guint type_masks[] = {
8112 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8113 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8114 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8115 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8116 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8117 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8118 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8119 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8120 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8121 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8122 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8123 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8124 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8125 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8126 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8127 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8128 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8129 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8130 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8131 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8132 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8133 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8134 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8135 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8136 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8137 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8138 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8139 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8140 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8141 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8142 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8143 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8144 0, /* GDK_WINDOW_STATE = 32 */
8145 0, /* GDK_SETTING = 33 */
8146 0, /* GDK_OWNER_CHANGE = 34 */
8147 0, /* GDK_GRAB_BROKEN = 35 */
8148 0, /* GDK_DAMAGE = 36 */
8150 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8152 /* send motion events if the right buttons are down */
8154 update_evmask_for_button_motion (guint evmask,
8155 GdkModifierType mask)
8157 if (evmask & GDK_BUTTON_MOTION_MASK &&
8158 mask & (GDK_BUTTON1_MASK |
8163 evmask |= GDK_POINTER_MOTION_MASK;
8165 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8166 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8167 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8168 evmask |= GDK_POINTER_MOTION_MASK;
8174 is_button_type (GdkEventType type)
8176 return type == GDK_BUTTON_PRESS ||
8177 type == GDK_2BUTTON_PRESS ||
8178 type == GDK_3BUTTON_PRESS ||
8179 type == GDK_BUTTON_RELEASE ||
8184 is_motion_type (GdkEventType type)
8186 return type == GDK_MOTION_NOTIFY ||
8187 type == GDK_ENTER_NOTIFY ||
8188 type == GDK_LEAVE_NOTIFY;
8192 find_common_ancestor (GdkWindow *win1,
8196 GList *path1 = NULL, *path2 = NULL;
8197 GList *list1, *list2;
8200 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8202 path1 = g_list_prepend (path1, tmp);
8203 tmp = get_event_parent (tmp);
8207 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8209 path2 = g_list_prepend (path2, tmp);
8210 tmp = get_event_parent (tmp);
8216 while (list1 && list2 && (list1->data == list2->data))
8219 list1 = g_list_next (list1);
8220 list2 = g_list_next (list2);
8222 g_list_free (path1);
8223 g_list_free (path2);
8229 _gdk_make_event (GdkWindow *window,
8231 GdkEvent *event_in_queue,
8232 gboolean before_event)
8234 GdkEvent *event = gdk_event_new (type);
8236 GdkModifierType the_state;
8238 the_time = gdk_event_get_time (event_in_queue);
8239 gdk_event_get_state (event_in_queue, &the_state);
8241 event->any.window = g_object_ref (window);
8242 event->any.send_event = FALSE;
8243 if (event_in_queue && event_in_queue->any.send_event)
8244 event->any.send_event = TRUE;
8248 case GDK_MOTION_NOTIFY:
8249 event->motion.time = the_time;
8250 event->motion.axes = NULL;
8251 event->motion.state = the_state;
8254 case GDK_BUTTON_PRESS:
8255 case GDK_2BUTTON_PRESS:
8256 case GDK_3BUTTON_PRESS:
8257 case GDK_BUTTON_RELEASE:
8258 event->button.time = the_time;
8259 event->button.axes = NULL;
8260 event->button.state = the_state;
8264 event->scroll.time = the_time;
8265 event->scroll.state = the_state;
8269 case GDK_KEY_RELEASE:
8270 event->key.time = the_time;
8271 event->key.state = the_state;
8274 case GDK_ENTER_NOTIFY:
8275 case GDK_LEAVE_NOTIFY:
8276 event->crossing.time = the_time;
8277 event->crossing.state = the_state;
8280 case GDK_PROPERTY_NOTIFY:
8281 event->property.time = the_time;
8282 event->property.state = the_state;
8285 case GDK_SELECTION_CLEAR:
8286 case GDK_SELECTION_REQUEST:
8287 case GDK_SELECTION_NOTIFY:
8288 event->selection.time = the_time;
8291 case GDK_PROXIMITY_IN:
8292 case GDK_PROXIMITY_OUT:
8293 event->proximity.time = the_time;
8296 case GDK_DRAG_ENTER:
8297 case GDK_DRAG_LEAVE:
8298 case GDK_DRAG_MOTION:
8299 case GDK_DRAG_STATUS:
8300 case GDK_DROP_START:
8301 case GDK_DROP_FINISHED:
8302 event->dnd.time = the_time;
8305 case GDK_FOCUS_CHANGE:
8309 case GDK_CLIENT_EVENT:
8310 case GDK_VISIBILITY_NOTIFY:
8321 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8323 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8326 _gdk_event_queue_append (gdk_window_get_display (window), event);
8332 send_crossing_event (GdkDisplay *display,
8333 GdkWindow *toplevel,
8336 GdkCrossingMode mode,
8337 GdkNotifyType notify_type,
8338 GdkWindow *subwindow,
8340 GdkDevice *source_device,
8343 GdkModifierType mask,
8345 GdkEvent *event_in_queue,
8349 guint32 window_event_mask, type_event_mask;
8350 GdkDeviceGrabInfo *grab;
8351 gboolean block_event = FALSE;
8353 grab = _gdk_display_has_device_grab (display, device, serial);
8356 !grab->owner_events)
8358 /* !owner_event => only report events wrt grab window, ignore rest */
8359 if ((GdkWindow *)window != grab->window)
8361 window_event_mask = grab->event_mask;
8364 window_event_mask = window->event_mask;
8366 if (type == GDK_LEAVE_NOTIFY)
8368 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8369 window->devices_inside = g_list_remove (window->devices_inside, device);
8371 if (!window->support_multidevice && window->devices_inside)
8373 /* Block leave events unless it's the last pointer */
8379 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8381 if (!window->support_multidevice && window->devices_inside)
8383 /* Only emit enter events for the first device */
8387 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8388 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8389 !g_list_find (window->devices_inside, device))
8390 window->devices_inside = g_list_prepend (window->devices_inside, device);
8396 if (window_event_mask & type_event_mask)
8398 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8399 gdk_event_set_device (event, device);
8402 gdk_event_set_source_device (event, source_device);
8404 event->crossing.time = time_;
8405 event->crossing.subwindow = subwindow;
8407 g_object_ref (subwindow);
8408 convert_toplevel_coords_to_window ((GdkWindow *)window,
8409 toplevel_x, toplevel_y,
8410 &event->crossing.x, &event->crossing.y);
8411 event->crossing.x_root = toplevel_x + toplevel->x;
8412 event->crossing.y_root = toplevel_y + toplevel->y;
8413 event->crossing.mode = mode;
8414 event->crossing.detail = notify_type;
8415 event->crossing.focus = FALSE;
8416 event->crossing.state = mask;
8421 /* The coordinates are in the toplevel window that src/dest are in.
8422 * src and dest are always (if != NULL) in the same toplevel, as
8423 * we get a leave-notify and set the window_under_pointer to null
8424 * before crossing to another toplevel.
8427 _gdk_synthesize_crossing_events (GdkDisplay *display,
8431 GdkDevice *source_device,
8432 GdkCrossingMode mode,
8435 GdkModifierType mask,
8437 GdkEvent *event_in_queue,
8439 gboolean non_linear)
8442 GdkWindow *win, *last, *next;
8446 GdkWindow *toplevel;
8447 GdkNotifyType notify_type;
8449 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8454 return; /* No crossings generated between src and dest */
8456 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8458 if (a && gdk_window_get_device_events (src, device) == 0)
8461 if (b && gdk_window_get_device_events (dest, device) == 0)
8468 c = find_common_ancestor (a, b);
8470 non_linear |= (c != a) && (c != b);
8472 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8474 toplevel = gdk_window_get_toplevel (a);
8476 /* Traverse up from a to (excluding) c sending leave events */
8478 notify_type = GDK_NOTIFY_NONLINEAR;
8480 notify_type = GDK_NOTIFY_INFERIOR;
8482 notify_type = GDK_NOTIFY_ANCESTOR;
8483 send_crossing_event (display, toplevel,
8484 a, GDK_LEAVE_NOTIFY,
8487 NULL, device, source_device,
8488 toplevel_x, toplevel_y,
8496 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8498 notify_type = GDK_NOTIFY_VIRTUAL;
8501 win = get_event_parent (a);
8502 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8504 send_crossing_event (display, toplevel,
8505 win, GDK_LEAVE_NOTIFY,
8509 device, source_device,
8510 toplevel_x, toplevel_y,
8516 win = get_event_parent (win);
8521 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8523 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8525 /* Traverse down from c to b */
8529 win = get_event_parent (b);
8530 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8532 path = g_list_prepend (path, win);
8533 win = get_event_parent (win);
8537 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8539 notify_type = GDK_NOTIFY_VIRTUAL;
8545 list = g_list_next (list);
8551 send_crossing_event (display, toplevel,
8552 win, GDK_ENTER_NOTIFY,
8556 device, source_device,
8557 toplevel_x, toplevel_y,
8567 notify_type = GDK_NOTIFY_NONLINEAR;
8569 notify_type = GDK_NOTIFY_ANCESTOR;
8571 notify_type = GDK_NOTIFY_INFERIOR;
8573 send_crossing_event (display, toplevel,
8574 b, GDK_ENTER_NOTIFY,
8578 device, source_device,
8579 toplevel_x, toplevel_y,
8586 /* Returns the window inside the event window with the pointer in it
8587 * at the specified coordinates, or NULL if its not in any child of
8588 * the toplevel. It also takes into account !owner_events grabs.
8591 get_pointer_window (GdkDisplay *display,
8592 GdkWindow *event_window,
8598 GdkWindow *pointer_window;
8599 GdkDeviceGrabInfo *grab;
8600 GdkPointerWindowInfo *pointer_info;
8602 pointer_info = _gdk_display_get_pointer_info (display, device);
8604 if (event_window == pointer_info->toplevel_under_pointer)
8606 _gdk_window_find_descendant_at (event_window,
8607 toplevel_x, toplevel_y,
8610 pointer_window = NULL;
8612 grab = _gdk_display_has_device_grab (display, device, serial);
8614 !grab->owner_events &&
8615 pointer_window != grab->window)
8616 pointer_window = NULL;
8618 return pointer_window;
8622 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8626 GdkPointerWindowInfo *device_info;
8628 device_info = _gdk_display_get_pointer_info (display, device);
8630 if (device_info->window_under_pointer)
8631 g_object_unref (device_info->window_under_pointer);
8632 device_info->window_under_pointer = window;
8636 g_object_ref (window);
8637 update_cursor (display, device);
8640 _gdk_display_enable_motion_hints (display, device);
8645 * @window: the #GdkWindow which will own the grab (the grab window).
8646 * @owner_events: if %FALSE then all pointer events are reported with respect to
8647 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8648 * events for this application are reported as normal, but pointer events outside
8649 * this application are reported with respect to @window and only if selected by
8650 * @event_mask. In either mode, unreported events are discarded.
8651 * @event_mask: specifies the event mask, which is used in accordance with
8652 * @owner_events. Note that only pointer events (i.e. button and motion events)
8654 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8655 * window during the grab. If the pointer is outside @confine_to, it will
8656 * automatically be moved to the closest edge of @confine_to and enter
8657 * and leave events will be generated as necessary.
8658 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8659 * the normal cursors are used for @window and its descendants, and the cursor
8660 * for @window is used for all other windows.
8661 * @time_: the timestamp of the event which led to this pointer grab. This usually
8662 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8663 * the time isn't known.
8665 * Grabs the pointer (usually a mouse) so that all events are passed to this
8666 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8667 * the grab window becomes unviewable.
8668 * This overrides any previous pointer grab by this client.
8670 * Pointer grabs are used for operations which need complete control over mouse
8671 * events, even if the mouse leaves the application.
8672 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8673 * the #GtkHPaned and #GtkVPaned widgets.
8675 * Note that if the event mask of an X window has selected both button press and
8676 * button release events, then a button press event will cause an automatic
8677 * pointer grab until the button is released.
8678 * X does this automatically since most applications expect to receive button
8679 * press and release events in pairs.
8680 * It is equivalent to a pointer grab on the window with @owner_events set to
8683 * If you set up anything at the time you take the grab that needs to be cleaned
8684 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8685 * are emitted when the grab ends unvoluntarily.
8687 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8689 * Deprecated: 3.0: Use gdk_device_grab() instead.
8692 gdk_pointer_grab (GdkWindow * window,
8693 gboolean owner_events,
8694 GdkEventMask event_mask,
8695 GdkWindow * confine_to,
8700 GdkDisplay *display;
8701 GdkDeviceManager *device_manager;
8703 GdkGrabStatus res = 0;
8705 GList *devices, *dev;
8707 g_return_val_if_fail (window != NULL, 0);
8708 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8709 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8711 /* We need a native window for confine to to work, ensure we have one */
8714 if (!gdk_window_ensure_native (confine_to))
8716 g_warning ("Can't confine to grabbed window, not native");
8721 /* Non-viewable client side window => fail */
8722 if (!_gdk_window_has_impl (window) &&
8723 !gdk_window_is_viewable (window))
8724 return GDK_GRAB_NOT_VIEWABLE;
8726 native = gdk_window_get_toplevel (window);
8727 while (gdk_window_is_offscreen (native))
8729 native = gdk_offscreen_window_get_embedder (native);
8731 if (native == NULL ||
8732 (!_gdk_window_has_impl (native) &&
8733 !gdk_window_is_viewable (native)))
8734 return GDK_GRAB_NOT_VIEWABLE;
8736 native = gdk_window_get_toplevel (native);
8739 display = gdk_window_get_display (window);
8741 serial = _gdk_display_get_next_serial (display);
8742 device_manager = gdk_display_get_device_manager (display);
8743 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8745 /* FIXME: Should this be generic to all backends? */
8746 /* FIXME: What happens with extended devices? */
8747 for (dev = devices; dev; dev = dev->next)
8751 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8754 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8757 get_native_grab_event_mask (event_mask),
8762 if (res == GDK_GRAB_SUCCESS)
8763 _gdk_display_add_device_grab (display,
8775 /* FIXME: handle errors when grabbing */
8777 g_list_free (devices);
8783 * gdk_keyboard_grab:
8784 * @window: the #GdkWindow which will own the grab (the grab window).
8785 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8786 * @window. If %TRUE then keyboard events for this application are
8787 * reported as normal, but keyboard events outside this application
8788 * are reported with respect to @window. Both key press and key
8789 * release events are always reported, independant of the event mask
8790 * set by the application.
8791 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8794 * Grabs the keyboard so that all events are passed to this
8795 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8796 * This overrides any previous keyboard grab by this client.
8798 * If you set up anything at the time you take the grab that needs to be cleaned
8799 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8800 * are emitted when the grab ends unvoluntarily.
8802 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8804 * Deprecated: 3.0: Use gdk_device_grab() instead.
8807 gdk_keyboard_grab (GdkWindow *window,
8808 gboolean owner_events,
8812 GdkDisplay *display;
8813 GdkDeviceManager *device_manager;
8815 GdkGrabStatus res = 0;
8817 GList *devices, *dev;
8819 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8821 /* Non-viewable client side window => fail */
8822 if (!_gdk_window_has_impl (window) &&
8823 !gdk_window_is_viewable (window))
8824 return GDK_GRAB_NOT_VIEWABLE;
8826 native = gdk_window_get_toplevel (window);
8828 while (gdk_window_is_offscreen (native))
8830 native = gdk_offscreen_window_get_embedder (native);
8832 if (native == NULL ||
8833 (!_gdk_window_has_impl (native) &&
8834 !gdk_window_is_viewable (native)))
8835 return GDK_GRAB_NOT_VIEWABLE;
8837 native = gdk_window_get_toplevel (native);
8840 display = gdk_window_get_display (window);
8841 serial = _gdk_display_get_next_serial (display);
8842 device_manager = gdk_display_get_device_manager (display);
8843 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8845 /* FIXME: Should this be generic to all backends? */
8846 /* FIXME: What happens with extended devices? */
8847 for (dev = devices; dev; dev = dev->next)
8851 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8854 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8857 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8862 if (res == GDK_GRAB_SUCCESS)
8863 _gdk_display_add_device_grab (display,
8874 /* FIXME: handle errors when grabbing */
8876 g_list_free (devices);
8882 * gdk_window_geometry_changed:
8883 * @window: an embedded offscreen #GdkWindow
8885 * This function informs GDK that the geometry of an embedded
8886 * offscreen window has changed. This is necessary for GDK to keep
8887 * track of which offscreen window the pointer is in.
8892 gdk_window_geometry_changed (GdkWindow *window)
8894 _gdk_synthesize_crossing_events_for_geometry_change (window);
8898 source_events_device_added (GdkDeviceManager *device_manager,
8903 GdkEventMask event_mask;
8904 GdkInputSource source;
8906 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
8910 source = gdk_device_get_source (device);
8912 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8913 GINT_TO_POINTER (source)));
8915 gdk_window_set_device_events (window, device, event_mask);
8919 source_events_device_changed (GdkDeviceManager *device_manager,
8924 GdkInputSource source;
8925 GdkEventMask event_mask;
8929 type = gdk_device_get_device_type (device);
8930 source = gdk_device_get_source (device);
8932 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8933 GINT_TO_POINTER (source)));
8938 if (type == GDK_DEVICE_TYPE_FLOATING)
8940 /* The device was just floated, enable its event mask */
8941 gdk_window_set_device_events (window, device, event_mask);
8943 else if (type == GDK_DEVICE_TYPE_SLAVE)
8944 gdk_window_set_device_events (window, device, 0);
8948 * gdk_window_set_source_events:
8949 * @window: a #GdkWindow
8950 * @source: a #GdkInputSource to define the source class.
8951 * @event_mask: event mask for @window
8953 * Sets the event mask for any floating device (i.e. not attached to any
8954 * visible pointer) that has the source defined as @source. This event
8955 * mask will be applied both to currently existing, newly added devices
8956 * after this call, and devices being attached/detached.
8961 gdk_window_set_source_events (GdkWindow *window,
8962 GdkInputSource source,
8963 GdkEventMask event_mask)
8965 GdkDeviceManager *device_manager;
8966 GdkDisplay *display;
8970 g_return_if_fail (GDK_IS_WINDOW (window));
8972 display = gdk_window_get_display (window);
8973 device_manager = gdk_display_get_device_manager (display);
8975 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
8977 /* Set event mask for existing devices */
8978 for (d = devices; d; d = d->next)
8980 GdkDevice *device = d->data;
8982 if (source == gdk_device_get_source (device))
8983 gdk_window_set_device_events (window, device, event_mask);
8986 g_list_free (devices);
8988 /* Update accounting */
8989 if (G_UNLIKELY (!window->source_event_masks))
8990 window->source_event_masks = g_hash_table_new (NULL, NULL);
8993 g_hash_table_insert (window->source_event_masks,
8994 GUINT_TO_POINTER (source),
8995 GUINT_TO_POINTER (event_mask));
8997 g_hash_table_remove (window->source_event_masks,
8998 GUINT_TO_POINTER (source));
9000 size = g_hash_table_size (window->source_event_masks);
9002 /* Update handler if needed */
9003 if (!window->device_added_handler_id && size > 0)
9005 window->device_added_handler_id =
9006 g_signal_connect (device_manager, "device-added",
9007 G_CALLBACK (source_events_device_added), window);
9008 window->device_changed_handler_id =
9009 g_signal_connect (device_manager, "device-changed",
9010 G_CALLBACK (source_events_device_changed), window);
9012 else if (window->device_added_handler_id && size == 0)
9013 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
9017 * gdk_window_get_source_events:
9018 * @window: a #GdkWindow
9019 * @source: a #GdkInputSource to define the source class.
9021 * Returns the event mask for @window corresponding to the device class specified
9024 * Returns: source event mask for @window
9027 gdk_window_get_source_events (GdkWindow *window,
9028 GdkInputSource source)
9030 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
9032 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
9033 GUINT_TO_POINTER (source)));
9037 do_synthesize_crossing_event (gpointer data)
9039 GdkDisplay *display;
9040 GdkWindow *changed_toplevel;
9041 GHashTableIter iter;
9042 gpointer key, value;
9045 changed_toplevel = data;
9047 changed_toplevel->synthesize_crossing_event_queued = FALSE;
9049 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9052 display = gdk_window_get_display (changed_toplevel);
9053 serial = _gdk_display_get_next_serial (display);
9054 g_hash_table_iter_init (&iter, display->pointers_info);
9056 while (g_hash_table_iter_next (&iter, &key, &value))
9058 GdkWindow *new_window_under_pointer;
9059 GdkPointerWindowInfo *pointer_info = value;
9060 GdkDevice *device = key;
9062 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9064 new_window_under_pointer =
9065 get_pointer_window (display, changed_toplevel,
9067 pointer_info->toplevel_x,
9068 pointer_info->toplevel_y,
9070 if (new_window_under_pointer != pointer_info->window_under_pointer)
9072 _gdk_synthesize_crossing_events (display,
9073 pointer_info->window_under_pointer,
9074 new_window_under_pointer,
9076 GDK_CROSSING_NORMAL,
9077 pointer_info->toplevel_x,
9078 pointer_info->toplevel_y,
9079 pointer_info->state,
9084 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9093 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9095 GdkWindow *toplevel;
9097 toplevel = get_event_toplevel (changed_window);
9099 if (!toplevel->synthesize_crossing_event_queued)
9101 toplevel->synthesize_crossing_event_queued = TRUE;
9103 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9104 do_synthesize_crossing_event,
9105 g_object_ref (toplevel),
9110 /* Don't use for crossing events */
9112 get_event_window (GdkDisplay *display,
9114 GdkWindow *pointer_window,
9116 GdkModifierType mask,
9121 GdkWindow *grab_window;
9122 GdkDeviceGrabInfo *grab;
9124 grab = _gdk_display_has_device_grab (display, device, serial);
9126 if (grab != NULL && !grab->owner_events)
9128 evmask = grab->event_mask;
9129 evmask = update_evmask_for_button_motion (evmask, mask);
9131 grab_window = grab->window;
9133 if (evmask & type_masks[type])
9136 *evmask_out = evmask;
9143 while (pointer_window != NULL)
9145 evmask = pointer_window->event_mask;
9146 evmask = update_evmask_for_button_motion (evmask, mask);
9148 if (evmask & type_masks[type])
9151 *evmask_out = evmask;
9152 return pointer_window;
9155 pointer_window = get_event_parent (pointer_window);
9161 evmask = grab->event_mask;
9162 evmask = update_evmask_for_button_motion (evmask, mask);
9164 if (evmask & type_masks[type])
9167 *evmask_out = evmask;
9168 return grab->window;
9178 proxy_pointer_event (GdkDisplay *display,
9179 GdkEvent *source_event,
9182 GdkWindow *toplevel_window, *event_window;
9183 GdkWindow *pointer_window;
9184 GdkPointerWindowInfo *pointer_info;
9185 GdkDevice *device, *source_device;
9188 gdouble toplevel_x, toplevel_y;
9190 gboolean non_linear;
9192 event_window = source_event->any.window;
9193 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9194 gdk_event_get_state (source_event, &state);
9195 time_ = gdk_event_get_time (source_event);
9196 device = gdk_event_get_device (source_event);
9197 source_device = gdk_event_get_source_device (source_event);
9198 pointer_info = _gdk_display_get_pointer_info (display, device);
9199 toplevel_window = convert_native_coords_to_toplevel (event_window,
9200 toplevel_x, toplevel_y,
9201 &toplevel_x, &toplevel_y);
9204 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9205 source_event->type == GDK_ENTER_NOTIFY) &&
9206 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9207 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9210 /* If we get crossing events with subwindow unexpectedly being NULL
9211 that means there is a native subwindow that gdk doesn't know about.
9212 We track these and forward them, with the correct virtual window
9214 This is important to get right, as metacity uses gdk for the frame
9215 windows, but gdk doesn't know about the client windows reparented
9217 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9218 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9219 (source_event->type == GDK_ENTER_NOTIFY &&
9220 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9221 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9222 source_event->crossing.subwindow == NULL)
9224 /* Left for an unknown (to gdk) subwindow */
9226 /* Send leave events from window under pointer to event window
9227 that will get the subwindow == NULL window */
9228 _gdk_synthesize_crossing_events (display,
9229 pointer_info->window_under_pointer,
9231 device, source_device,
9232 source_event->crossing.mode,
9233 toplevel_x, toplevel_y,
9239 /* Send subwindow == NULL event */
9240 send_crossing_event (display,
9244 source_event->crossing.mode,
9245 source_event->crossing.detail,
9247 device, source_device,
9248 toplevel_x, toplevel_y,
9253 _gdk_display_set_window_under_pointer (display, device, NULL);
9257 pointer_window = get_pointer_window (display, toplevel_window, device,
9258 toplevel_x, toplevel_y, serial);
9260 if (((source_event->type == GDK_ENTER_NOTIFY &&
9261 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9262 (source_event->type == GDK_LEAVE_NOTIFY &&
9263 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9264 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9265 source_event->crossing.subwindow == NULL)
9267 /* Entered from an unknown (to gdk) subwindow */
9269 /* Send subwindow == NULL event */
9270 send_crossing_event (display,
9274 source_event->crossing.mode,
9275 source_event->crossing.detail,
9277 device, source_device,
9278 toplevel_x, toplevel_y,
9283 /* Send enter events from event window to pointer_window */
9284 _gdk_synthesize_crossing_events (display,
9287 device, source_device,
9288 source_event->crossing.mode,
9289 toplevel_x, toplevel_y,
9292 serial, non_linear);
9293 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9297 if (pointer_info->window_under_pointer != pointer_window)
9299 /* Either a toplevel crossing notify that ended up inside a child window,
9300 or a motion notify that got into another child window */
9302 /* Different than last time, send crossing events */
9303 _gdk_synthesize_crossing_events (display,
9304 pointer_info->window_under_pointer,
9306 device, source_device,
9307 GDK_CROSSING_NORMAL,
9308 toplevel_x, toplevel_y,
9311 serial, non_linear);
9312 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9314 else if (source_event->type == GDK_MOTION_NOTIFY)
9316 GdkWindow *event_win;
9320 event_win = get_event_window (display,
9329 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9330 gdk_window_get_device_events (event_win, device) == 0)
9336 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9338 gulong *device_serial;
9340 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9342 if (!device_serial ||
9343 (*device_serial != 0 &&
9344 serial < *device_serial))
9345 event_win = NULL; /* Ignore event */
9349 *device_serial = G_MAXULONG;
9353 if (event_win && !display->ignore_core_events)
9355 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9356 event->motion.time = time_;
9357 convert_toplevel_coords_to_window (event_win,
9358 toplevel_x, toplevel_y,
9359 &event->motion.x, &event->motion.y);
9360 event->motion.x_root = source_event->motion.x_root;
9361 event->motion.y_root = source_event->motion.y_root;
9362 event->motion.state = state;
9363 event->motion.is_hint = is_hint;
9364 event->motion.device = source_event->motion.device;
9365 event->motion.axes = g_memdup (source_event->motion.axes,
9366 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9367 gdk_event_set_source_device (event, source_device);
9371 /* unlink all move events from queue.
9372 We handle our own, including our emulated masks. */
9376 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9377 GDK_BUTTON2_MASK | \
9378 GDK_BUTTON3_MASK | \
9379 GDK_BUTTON4_MASK | \
9383 proxy_button_event (GdkEvent *source_event,
9386 GdkWindow *toplevel_window, *event_window;
9387 GdkWindow *event_win;
9388 GdkWindow *pointer_window;
9394 gdouble toplevel_x, toplevel_y;
9395 GdkDisplay *display;
9397 GdkDevice *device, *source_device;
9399 type = source_event->any.type;
9400 event_window = source_event->any.window;
9401 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9402 gdk_event_get_state (source_event, &state);
9403 time_ = gdk_event_get_time (source_event);
9404 device = gdk_event_get_device (source_event);
9405 source_device = gdk_event_get_source_device (source_event);
9406 display = gdk_window_get_display (source_event->any.window);
9407 toplevel_window = convert_native_coords_to_toplevel (event_window,
9408 toplevel_x, toplevel_y,
9409 &toplevel_x, &toplevel_y);
9411 if (type == GDK_BUTTON_PRESS &&
9412 !source_event->any.send_event &&
9413 _gdk_display_has_device_grab (display, device, serial) == NULL)
9416 _gdk_window_find_descendant_at (toplevel_window,
9417 toplevel_x, toplevel_y,
9420 /* Find the event window, that gets the grab */
9423 (parent = get_event_parent (w)) != NULL &&
9424 parent->window_type != GDK_WINDOW_ROOT)
9426 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9430 pointer_window = (GdkWindow *)w;
9432 _gdk_display_add_device_grab (display,
9438 gdk_window_get_events (pointer_window),
9442 _gdk_display_device_grab_update (display, device, source_device, serial);
9445 pointer_window = get_pointer_window (display, toplevel_window, device,
9446 toplevel_x, toplevel_y,
9449 event_win = get_event_window (display,
9455 if (event_win == NULL || display->ignore_core_events)
9458 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9459 gdk_window_get_device_events (event_win, device) == 0)
9462 event = _gdk_make_event (event_win, type, source_event, FALSE);
9466 case GDK_BUTTON_PRESS:
9467 case GDK_BUTTON_RELEASE:
9468 event->button.button = source_event->button.button;
9469 convert_toplevel_coords_to_window (event_win,
9470 toplevel_x, toplevel_y,
9471 &event->button.x, &event->button.y);
9472 event->button.x_root = source_event->button.x_root;
9473 event->button.y_root = source_event->button.y_root;
9474 event->button.state = state;
9475 event->button.device = source_event->button.device;
9476 event->button.axes = g_memdup (source_event->button.axes,
9477 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9479 gdk_event_set_source_device (event, source_device);
9481 if (type == GDK_BUTTON_PRESS)
9482 _gdk_event_button_generate (display, event);
9486 event->scroll.direction = source_event->scroll.direction;
9487 convert_toplevel_coords_to_window (event_win,
9488 toplevel_x, toplevel_y,
9489 &event->scroll.x, &event->scroll.y);
9490 event->scroll.x_root = source_event->scroll.x_root;
9491 event->scroll.y_root = source_event->scroll.y_root;
9492 event->scroll.state = state;
9493 event->scroll.device = source_event->scroll.device;
9494 gdk_event_set_source_device (event, source_device);
9501 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9504 #ifdef DEBUG_WINDOW_PRINTING
9506 gdk_window_print (GdkWindow *window,
9510 const char *window_types[] = {
9520 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9521 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9522 window->x, window->y,
9523 window->width, window->height
9526 if (gdk_window_has_impl (window))
9528 #ifdef GDK_WINDOWING_X11
9529 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9533 if (window->window_type != GDK_WINDOW_CHILD)
9534 g_print (" %s", window_types[window->window_type]);
9536 if (window->input_only)
9537 g_print (" input-only");
9540 g_print (" shaped");
9542 if (!gdk_window_is_visible ((GdkWindow *)window))
9543 g_print (" hidden");
9545 g_print (" abs[%d,%d]",
9546 window->abs_x, window->abs_y);
9548 cairo_region_get_extents (window->clip_region, &r);
9549 if (cairo_region_is_empty (window->clip_region))
9550 g_print (" clipbox[empty]");
9552 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9559 gdk_window_print_tree (GdkWindow *window,
9561 gboolean include_input_only)
9565 if (window->input_only && !include_input_only)
9568 gdk_window_print (window, indent);
9570 for (l = window->children; l != NULL; l = l->next)
9571 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9574 #endif /* DEBUG_WINDOW_PRINTING */
9577 _gdk_windowing_got_event (GdkDisplay *display,
9582 GdkWindow *event_window;
9584 gboolean unlink_event;
9585 guint old_state, old_button;
9586 GdkDeviceGrabInfo *button_release_grab;
9587 GdkPointerWindowInfo *pointer_info;
9588 GdkDevice *device, *source_device;
9589 gboolean is_toplevel;
9591 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9592 display->last_event_time = gdk_event_get_time (event);
9594 device = gdk_event_get_device (event);
9595 source_device = gdk_event_get_source_device (event);
9601 g_object_get (device, "input-mode", &mode, NULL);
9602 _gdk_display_device_grab_update (display, device, source_device, serial);
9604 if (mode == GDK_MODE_DISABLED ||
9605 !_gdk_display_check_grab_ownership (display, device, serial))
9607 /* Device events are blocked by another
9608 * device grab, or the device is disabled
9610 unlink_event = TRUE;
9615 event_window = event->any.window;
9619 pointer_info = _gdk_display_get_pointer_info (display, device);
9621 #ifdef DEBUG_WINDOW_PRINTING
9622 if (event->type == GDK_KEY_PRESS &&
9623 (event->key.keyval == 0xa7 ||
9624 event->key.keyval == 0xbd))
9626 gdk_window_print_tree (event_window, 0,
9627 event->key.keyval == 0xbd);
9631 if (event->type == GDK_VISIBILITY_NOTIFY)
9633 event_window->native_visibility = event->visibility.state;
9634 gdk_window_update_visibility_recursively (event_window,
9639 if (!(is_button_type (event->type) ||
9640 is_motion_type (event->type)) ||
9641 event_window->window_type == GDK_WINDOW_ROOT)
9644 is_toplevel = gdk_window_is_toplevel (event_window);
9646 if ((event->type == GDK_ENTER_NOTIFY ||
9647 event->type == GDK_LEAVE_NOTIFY) &&
9648 (event->crossing.mode == GDK_CROSSING_GRAB ||
9649 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9650 (_gdk_display_has_device_grab (display, device, serial) ||
9651 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9653 /* We synthesize all crossing events due to grabs ourselves,
9654 * so we ignore the native ones caused by our native pointer_grab
9655 * calls. Otherwise we would proxy these crossing event and cause
9656 * multiple copies of crossing events for grabs.
9658 * We do want to handle grabs from other clients though, as for
9659 * instance alt-tab in metacity causes grabs like these and
9660 * we want to handle those. Thus the has_pointer_grab check.
9662 * Implicit grabs on child windows create some grabbing events
9663 * that are sent before the button press. This means we can't
9664 * detect these with the has_pointer_grab check (as the implicit
9665 * grab is only noticed when we get button press event), so we
9666 * detect these events by checking for INFERIOR enter or leave
9667 * events. These should never be a problem to filter out.
9670 /* We ended up in this window after some (perhaps other clients)
9671 grab, so update the toplevel_under_window state */
9673 event->type == GDK_ENTER_NOTIFY &&
9674 event->crossing.mode == GDK_CROSSING_UNGRAB)
9676 if (pointer_info->toplevel_under_pointer)
9677 g_object_unref (pointer_info->toplevel_under_pointer);
9678 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9681 unlink_event = TRUE;
9685 /* Track toplevel_under_pointer */
9688 if (event->type == GDK_ENTER_NOTIFY &&
9689 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9691 if (pointer_info->toplevel_under_pointer)
9692 g_object_unref (pointer_info->toplevel_under_pointer);
9693 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9695 else if (event->type == GDK_LEAVE_NOTIFY &&
9696 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9697 pointer_info->toplevel_under_pointer == event_window)
9699 if (pointer_info->toplevel_under_pointer)
9700 g_object_unref (pointer_info->toplevel_under_pointer);
9701 pointer_info->toplevel_under_pointer = NULL;
9705 /* Store last pointer window and position/state */
9706 old_state = pointer_info->state;
9707 old_button = pointer_info->button;
9709 gdk_event_get_coords (event, &x, &y);
9710 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9711 pointer_info->toplevel_x = x;
9712 pointer_info->toplevel_y = y;
9713 gdk_event_get_state (event, &pointer_info->state);
9714 if (event->type == GDK_BUTTON_PRESS ||
9715 event->type == GDK_BUTTON_RELEASE)
9716 pointer_info->button = event->button.button;
9719 (pointer_info->state != old_state ||
9720 pointer_info->button != old_button))
9721 _gdk_display_enable_motion_hints (display, device);
9723 unlink_event = FALSE;
9724 if (is_motion_type (event->type))
9725 unlink_event = proxy_pointer_event (display,
9728 else if (is_button_type (event->type))
9729 unlink_event = proxy_button_event (event,
9732 if (event->type == GDK_BUTTON_RELEASE &&
9733 !event->any.send_event)
9735 button_release_grab =
9736 _gdk_display_has_device_grab (display, device, serial);
9737 if (button_release_grab &&
9738 button_release_grab->implicit &&
9739 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9741 button_release_grab->serial_end = serial;
9742 button_release_grab->implicit_ungrab = FALSE;
9743 _gdk_display_device_grab_update (display, device, source_device, serial);
9750 _gdk_event_queue_remove_link (display, event_link);
9751 g_list_free_1 (event_link);
9752 gdk_event_free (event);
9757 * gdk_window_create_similar_surface:
9758 * @window: window to make new surface similar to
9759 * @content: the content for the new surface
9760 * @width: width of the new surface
9761 * @height: height of the new surface
9763 * Create a new surface that is as compatible as possible with the
9764 * given @window. For example the new surface will have the same
9765 * fallback resolution and font options as @window. Generally, the new
9766 * surface will also use the same backend as @window, unless that is
9767 * not possible for some reason. The type of the returned surface may
9768 * be examined with cairo_surface_get_type().
9770 * Initially the surface contents are all 0 (transparent if contents
9771 * have transparency, black otherwise.)
9773 * Returns: a pointer to the newly allocated surface. The caller
9774 * owns the surface and should call cairo_surface_destroy() when done
9777 * This function always returns a valid pointer, but it will return a
9778 * pointer to a "nil" surface if @other is already in an error state
9779 * or any other error occurs.
9784 gdk_window_create_similar_surface (GdkWindow * window,
9785 cairo_content_t content,
9789 cairo_surface_t *window_surface, *surface;
9791 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9793 window_surface = _gdk_window_ref_cairo_surface (window);
9795 switch (_gdk_rendering_mode)
9797 case GDK_RENDERING_MODE_RECORDING:
9799 cairo_rectangle_t rect = { 0, 0, width, height };
9800 surface = cairo_recording_surface_create (content, &rect);
9803 case GDK_RENDERING_MODE_IMAGE:
9804 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
9805 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
9808 case GDK_RENDERING_MODE_SIMILAR:
9810 surface = cairo_surface_create_similar (window_surface,
9816 cairo_surface_destroy (window_surface);
9823 * @window: a #GdkWindow
9824 * @timestamp: timestamp of the event triggering the window focus
9826 * Sets keyboard focus to @window. In most cases, gtk_window_present()
9827 * should be used on a #GtkWindow, rather than calling this function.
9831 gdk_window_focus (GdkWindow *window,
9834 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
9838 * gdk_window_set_type_hint:
9839 * @window: A toplevel #GdkWindow
9840 * @hint: A hint of the function this window will have
9842 * The application can use this call to provide a hint to the window
9843 * manager about the functionality of a window. The window manager
9844 * can use this information when determining the decoration and behaviour
9847 * The hint must be set before the window is mapped.
9850 gdk_window_set_type_hint (GdkWindow *window,
9851 GdkWindowTypeHint hint)
9853 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
9857 * gdk_window_get_type_hint:
9858 * @window: A toplevel #GdkWindow
9860 * This function returns the type hint set for a window.
9862 * Return value: The type hint set for @window
9867 gdk_window_get_type_hint (GdkWindow *window)
9869 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
9873 * gdk_window_set_modal_hint:
9874 * @window: A toplevel #GdkWindow
9875 * @modal: %TRUE if the window is modal, %FALSE otherwise.
9877 * The application can use this hint to tell the window manager
9878 * that a certain window has modal behaviour. The window manager
9879 * can use this information to handle modal windows in a special
9882 * You should only use this on windows for which you have
9883 * previously called gdk_window_set_transient_for()
9886 gdk_window_set_modal_hint (GdkWindow *window,
9889 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
9893 * gdk_window_set_skip_taskbar_hint:
9894 * @window: a toplevel #GdkWindow
9895 * @skips_taskbar: %TRUE to skip the taskbar
9897 * Toggles whether a window should appear in a task list or window
9898 * list. If a window's semantic type as specified with
9899 * gdk_window_set_type_hint() already fully describes the window, this
9900 * function should <emphasis>not</emphasis> be called in addition,
9901 * instead you should allow the window to be treated according to
9902 * standard policy for its semantic type.
9907 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
9908 gboolean skips_taskbar)
9910 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
9914 * gdk_window_set_skip_pager_hint:
9915 * @window: a toplevel #GdkWindow
9916 * @skips_pager: %TRUE to skip the pager
9918 * Toggles whether a window should appear in a pager (workspace
9919 * switcher, or other desktop utility program that displays a small
9920 * thumbnail representation of the windows on the desktop). If a
9921 * window's semantic type as specified with gdk_window_set_type_hint()
9922 * already fully describes the window, this function should
9923 * <emphasis>not</emphasis> be called in addition, instead you should
9924 * allow the window to be treated according to standard policy for
9925 * its semantic type.
9930 gdk_window_set_skip_pager_hint (GdkWindow *window,
9931 gboolean skips_pager)
9933 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
9937 * gdk_window_set_urgency_hint:
9938 * @window: a toplevel #GdkWindow
9939 * @urgent: %TRUE if the window is urgent
9941 * Toggles whether a window needs the user's
9947 gdk_window_set_urgency_hint (GdkWindow *window,
9950 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
9954 * gdk_window_set_geometry_hints:
9955 * @window: a toplevel #GdkWindow
9956 * @geometry: geometry hints
9957 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
9959 * Sets the geometry hints for @window. Hints flagged in @geom_mask
9960 * are set, hints not flagged in @geom_mask are unset.
9961 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
9963 * This function provides hints to the windowing system about
9964 * acceptable sizes for a toplevel window. The purpose of
9965 * this is to constrain user resizing, but the windowing system
9966 * will typically (but is not required to) also constrain the
9967 * current size of the window to the provided values and
9968 * constrain programatic resizing via gdk_window_resize() or
9969 * gdk_window_move_resize().
9971 * Note that on X11, this effect has no effect on windows
9972 * of type %GDK_WINDOW_TEMP or windows where override redirect
9973 * has been turned on via gdk_window_set_override_redirect()
9974 * since these windows are not resizable by the user.
9976 * Since you can't count on the windowing system doing the
9977 * constraints for programmatic resizes, you should generally
9978 * call gdk_window_constrain_size() yourself to determine
9979 * appropriate sizes.
9983 gdk_window_set_geometry_hints (GdkWindow *window,
9984 const GdkGeometry *geometry,
9985 GdkWindowHints geom_mask)
9987 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
9991 * gdk_window_set_title:
9992 * @window: a toplevel #GdkWindow
9993 * @title: title of @window
9995 * Sets the title of a toplevel window, to be displayed in the titlebar.
9996 * If you haven't explicitly set the icon name for the window
9997 * (using gdk_window_set_icon_name()), the icon name will be set to
9998 * @title as well. @title must be in UTF-8 encoding (as with all
9999 * user-readable strings in GDK/GTK+). @title may not be %NULL.
10002 gdk_window_set_title (GdkWindow *window,
10003 const gchar *title)
10005 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
10009 * gdk_window_set_role:
10010 * @window: a toplevel #GdkWindow
10011 * @role: a string indicating its role
10013 * When using GTK+, typically you should use gtk_window_set_role() instead
10014 * of this low-level function.
10016 * The window manager and session manager use a window's role to
10017 * distinguish it from other kinds of window in the same application.
10018 * When an application is restarted after being saved in a previous
10019 * session, all windows with the same title and role are treated as
10020 * interchangeable. So if you have two windows with the same title
10021 * that should be distinguished for session management purposes, you
10022 * should set the role on those windows. It doesn't matter what string
10023 * you use for the role, as long as you have a different role for each
10024 * non-interchangeable kind of window.
10028 gdk_window_set_role (GdkWindow *window,
10031 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
10035 * gdk_window_set_startup_id:
10036 * @window: a toplevel #GdkWindow
10037 * @startup_id: a string with startup-notification identifier
10039 * When using GTK+, typically you should use gtk_window_set_startup_id()
10040 * instead of this low-level function.
10046 gdk_window_set_startup_id (GdkWindow *window,
10047 const gchar *startup_id)
10049 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
10053 * gdk_window_set_transient_for:
10054 * @window: a toplevel #GdkWindow
10055 * @parent: another toplevel #GdkWindow
10057 * Indicates to the window manager that @window is a transient dialog
10058 * associated with the application window @parent. This allows the
10059 * window manager to do things like center @window on @parent and
10060 * keep @window above @parent.
10062 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10066 gdk_window_set_transient_for (GdkWindow *window,
10069 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10073 * gdk_window_get_root_origin:
10074 * @window: a toplevel #GdkWindow
10075 * @x: (out): return location for X position of window frame
10076 * @y: (out): return location for Y position of window frame
10078 * Obtains the top-left corner of the window manager frame in root
10079 * window coordinates.
10083 gdk_window_get_root_origin (GdkWindow *window,
10087 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10091 * gdk_window_get_frame_extents:
10092 * @window: a toplevel #GdkWindow
10093 * @rect: rectangle to fill with bounding box of the window frame
10095 * Obtains the bounding box of the window, including window manager
10096 * titlebar/borders if any. The frame position is given in root window
10097 * coordinates. To get the position of the window itself (rather than
10098 * the frame) in root window coordinates, use gdk_window_get_origin().
10102 gdk_window_get_frame_extents (GdkWindow *window,
10103 GdkRectangle *rect)
10105 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10109 * gdk_window_set_override_redirect:
10110 * @window: a toplevel #GdkWindow
10111 * @override_redirect: %TRUE if window should be override redirect
10113 * An override redirect window is not under the control of the window manager.
10114 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10115 * be entirely under the control of the application. The window manager
10116 * can't see the override redirect window at all.
10118 * Override redirect should only be used for short-lived temporary
10119 * windows, such as popup menus. #GtkMenu uses an override redirect
10120 * window in its implementation, for example.
10124 gdk_window_set_override_redirect (GdkWindow *window,
10125 gboolean override_redirect)
10127 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10131 * gdk_window_set_accept_focus:
10132 * @window: a toplevel #GdkWindow
10133 * @accept_focus: %TRUE if the window should receive input focus
10135 * Setting @accept_focus to %FALSE hints the desktop environment that the
10136 * window doesn't want to receive input focus.
10138 * On X, it is the responsibility of the window manager to interpret this
10139 * hint. ICCCM-compliant window manager usually respect it.
10144 gdk_window_set_accept_focus (GdkWindow *window,
10145 gboolean accept_focus)
10147 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10151 * gdk_window_set_focus_on_map:
10152 * @window: a toplevel #GdkWindow
10153 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10155 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10156 * window doesn't want to receive input focus when it is mapped.
10157 * focus_on_map should be turned off for windows that aren't triggered
10158 * interactively (such as popups from network activity).
10160 * On X, it is the responsibility of the window manager to interpret
10161 * this hint. Window managers following the freedesktop.org window
10162 * manager extension specification should respect it.
10167 gdk_window_set_focus_on_map (GdkWindow *window,
10168 gboolean focus_on_map)
10170 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10174 * gdk_window_set_icon_list:
10175 * @window: The #GdkWindow toplevel window to set the icon of.
10176 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10177 * A list of pixbufs, of different sizes.
10179 * Sets a list of icons for the window. One of these will be used
10180 * to represent the window when it has been iconified. The icon is
10181 * usually shown in an icon box or some sort of task bar. Which icon
10182 * size is shown depends on the window manager. The window manager
10183 * can scale the icon but setting several size icons can give better
10184 * image quality since the window manager may only need to scale the
10185 * icon by a small amount or not at all.
10189 gdk_window_set_icon_list (GdkWindow *window,
10192 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10196 * gdk_window_set_icon_name:
10197 * @window: a toplevel #GdkWindow
10198 * @name: (allow-none): name of window while iconified (minimized)
10200 * Windows may have a name used while minimized, distinct from the
10201 * name they display in their titlebar. Most of the time this is a bad
10202 * idea from a user interface standpoint. But you can set such a name
10203 * with this function, if you like.
10205 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10206 * will not update the icon title.
10208 * Using %NULL for @name unsets the icon title; further calls to
10209 * gdk_window_set_title() will again update the icon title as well.
10212 gdk_window_set_icon_name (GdkWindow *window,
10215 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10219 * gdk_window_iconify:
10220 * @window: a toplevel #GdkWindow
10222 * Asks to iconify (minimize) @window. The window manager may choose
10223 * to ignore the request, but normally will honor it. Using
10224 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10226 * This function only makes sense when @window is a toplevel window.
10230 gdk_window_iconify (GdkWindow *window)
10232 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10236 * gdk_window_deiconify:
10237 * @window: a toplevel #GdkWindow
10239 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10240 * choose to ignore the request to deiconify. When using GTK+,
10241 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10242 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10243 * unminimizes it, and puts it on the current desktop.
10247 gdk_window_deiconify (GdkWindow *window)
10249 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10253 * gdk_window_stick:
10254 * @window: a toplevel #GdkWindow
10256 * "Pins" a window such that it's on all workspaces and does not scroll
10257 * with viewports, for window managers that have scrollable viewports.
10258 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10260 * On the X11 platform, this function depends on window manager
10261 * support, so may have no effect with many window managers. However,
10262 * GDK will do the best it can to convince the window manager to stick
10263 * the window. For window managers that don't support this operation,
10264 * there's nothing you can do to force it to happen.
10268 gdk_window_stick (GdkWindow *window)
10270 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10274 * gdk_window_unstick:
10275 * @window: a toplevel #GdkWindow
10277 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10278 * and gtk_window_unstick().
10282 gdk_window_unstick (GdkWindow *window)
10284 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10288 * gdk_window_maximize:
10289 * @window: a toplevel #GdkWindow
10291 * Maximizes the window. If the window was already maximized, then
10292 * this function does nothing.
10294 * On X11, asks the window manager to maximize @window, if the window
10295 * manager supports this operation. Not all window managers support
10296 * this, and some deliberately ignore it or don't have a concept of
10297 * "maximized"; so you can't rely on the maximization actually
10298 * happening. But it will happen with most standard window managers,
10299 * and GDK makes a best effort to get it to happen.
10301 * On Windows, reliably maximizes the window.
10305 gdk_window_maximize (GdkWindow *window)
10307 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10311 * gdk_window_unmaximize:
10312 * @window: a toplevel #GdkWindow
10314 * Unmaximizes the window. If the window wasn't maximized, then this
10315 * function does nothing.
10317 * On X11, asks the window manager to unmaximize @window, if the
10318 * window manager supports this operation. Not all window managers
10319 * support this, and some deliberately ignore it or don't have a
10320 * concept of "maximized"; so you can't rely on the unmaximization
10321 * actually happening. But it will happen with most standard window
10322 * managers, and GDK makes a best effort to get it to happen.
10324 * On Windows, reliably unmaximizes the window.
10328 gdk_window_unmaximize (GdkWindow *window)
10330 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10334 * gdk_window_fullscreen:
10335 * @window: a toplevel #GdkWindow
10337 * Moves the window into fullscreen mode. This means the
10338 * window covers the entire screen and is above any panels
10341 * If the window was already fullscreen, then this function does nothing.
10343 * On X11, asks the window manager to put @window in a fullscreen
10344 * state, if the window manager supports this operation. Not all
10345 * window managers support this, and some deliberately ignore it or
10346 * don't have a concept of "fullscreen"; so you can't rely on the
10347 * fullscreenification actually happening. But it will happen with
10348 * most standard window managers, and GDK makes a best effort to get
10354 gdk_window_fullscreen (GdkWindow *window)
10356 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10360 * gdk_window_unfullscreen:
10361 * @window: a toplevel #GdkWindow
10363 * Moves the window out of fullscreen mode. If the window was not
10364 * fullscreen, does nothing.
10366 * On X11, asks the window manager to move @window out of the fullscreen
10367 * state, if the window manager supports this operation. Not all
10368 * window managers support this, and some deliberately ignore it or
10369 * don't have a concept of "fullscreen"; so you can't rely on the
10370 * unfullscreenification actually happening. But it will happen with
10371 * most standard window managers, and GDK makes a best effort to get
10377 gdk_window_unfullscreen (GdkWindow *window)
10379 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10383 * gdk_window_set_keep_above:
10384 * @window: a toplevel #GdkWindow
10385 * @setting: whether to keep @window above other windows
10387 * Set if @window must be kept above other windows. If the
10388 * window was already above, then this function does nothing.
10390 * On X11, asks the window manager to keep @window above, if the window
10391 * manager supports this operation. Not all window managers support
10392 * this, and some deliberately ignore it or don't have a concept of
10393 * "keep above"; so you can't rely on the window being kept above.
10394 * But it will happen with most standard window managers,
10395 * and GDK makes a best effort to get it to happen.
10400 gdk_window_set_keep_above (GdkWindow *window,
10403 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10407 * gdk_window_set_keep_below:
10408 * @window: a toplevel #GdkWindow
10409 * @setting: whether to keep @window below other windows
10411 * Set if @window must be kept below other windows. If the
10412 * window was already below, then this function does nothing.
10414 * On X11, asks the window manager to keep @window below, if the window
10415 * manager supports this operation. Not all window managers support
10416 * this, and some deliberately ignore it or don't have a concept of
10417 * "keep below"; so you can't rely on the window being kept below.
10418 * But it will happen with most standard window managers,
10419 * and GDK makes a best effort to get it to happen.
10424 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10426 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10430 * gdk_window_get_group:
10431 * @window: a toplevel #GdkWindow
10433 * Returns the group leader window for @window. See gdk_window_set_group().
10435 * Return value: (transfer none): the group leader window for @window
10440 gdk_window_get_group (GdkWindow *window)
10442 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10446 * gdk_window_set_group:
10447 * @window: a toplevel #GdkWindow
10448 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10450 * Sets the group leader window for @window. By default,
10451 * GDK sets the group leader for all toplevel windows
10452 * to a global window implicitly created by GDK. With this function
10453 * you can override this default.
10455 * The group leader window allows the window manager to distinguish
10456 * all windows that belong to a single application. It may for example
10457 * allow users to minimize/unminimize all windows belonging to an
10458 * application at once. You should only set a non-default group window
10459 * if your application pretends to be multiple applications.
10462 gdk_window_set_group (GdkWindow *window,
10465 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10469 * gdk_window_set_decorations:
10470 * @window: a toplevel #GdkWindow
10471 * @decorations: decoration hint mask
10473 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10474 * This function sets the traditional Motif window manager hints that tell the
10475 * window manager which decorations you would like your window to have.
10476 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10477 * using the GDK function directly.
10479 * The @decorations argument is the logical OR of the fields in
10480 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10481 * mask, the other bits indicate which decorations should be turned off.
10482 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10483 * which decorations should be turned on.
10485 * Most window managers honor a decorations hint of 0 to disable all decorations,
10486 * but very few honor all possible combinations of bits.
10490 gdk_window_set_decorations (GdkWindow *window,
10491 GdkWMDecoration decorations)
10493 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10497 * gdk_window_get_decorations:
10498 * @window: The toplevel #GdkWindow to get the decorations from
10499 * @decorations: (out): The window decorations will be written here
10501 * Returns the decorations set on the GdkWindow with
10502 * gdk_window_set_decorations().
10504 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10507 gdk_window_get_decorations(GdkWindow *window,
10508 GdkWMDecoration *decorations)
10510 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10514 * gdk_window_set_functions:
10515 * @window: a toplevel #GdkWindow
10516 * @functions: bitmask of operations to allow on @window
10518 * Sets hints about the window management functions to make available
10519 * via buttons on the window frame.
10521 * On the X backend, this function sets the traditional Motif window
10522 * manager hint for this purpose. However, few window managers do
10523 * anything reliable or interesting with this hint. Many ignore it
10526 * The @functions argument is the logical OR of values from the
10527 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
10528 * then the other bits indicate which functions to disable; if
10529 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
10534 gdk_window_set_functions (GdkWindow *window,
10535 GdkWMFunction functions)
10537 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
10541 * gdk_window_begin_resize_drag_for_device:
10542 * @window: a toplevel #GdkWindow
10543 * @edge: the edge or corner from which the drag is started
10544 * @device: the device used for the operation
10545 * @button: the button being used to drag
10546 * @root_x: root window X coordinate of mouse click that began the drag
10547 * @root_y: root window Y coordinate of mouse click that began the drag
10548 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10550 * Begins a window resize operation (for a toplevel window).
10551 * You might use this function to implement a "window resize grip," for
10552 * example; in fact #GtkStatusbar uses it. The function works best
10553 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
10554 * fallback implementation for other window managers.
10559 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
10560 GdkWindowEdge edge,
10567 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
10571 * gdk_window_begin_resize_drag:
10572 * @window: a toplevel #GdkWindow
10573 * @edge: the edge or corner from which the drag is started
10574 * @button: the button being used to drag
10575 * @root_x: root window X coordinate of mouse click that began the drag
10576 * @root_y: root window Y coordinate of mouse click that began the drag
10577 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10579 * Begins a window resize operation (for a toplevel window).
10581 * This function assumes that the drag is controlled by the
10582 * client pointer device, use gdk_window_begin_resize_drag_for_device()
10583 * to begin a drag with a different device.
10586 gdk_window_begin_resize_drag (GdkWindow *window,
10587 GdkWindowEdge edge,
10593 GdkDeviceManager *device_manager;
10596 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10597 device = gdk_device_manager_get_client_pointer (device_manager);
10598 gdk_window_begin_resize_drag_for_device (window, edge,
10599 device, button, root_x, root_y, timestamp);
10603 * gdk_window_begin_move_drag_for_device:
10604 * @window: a toplevel #GdkWindow
10605 * @device: the device used for the operation
10606 * @button: the button being used to drag
10607 * @root_x: root window X coordinate of mouse click that began the drag
10608 * @root_y: root window Y coordinate of mouse click that began the drag
10609 * @timestamp: timestamp of mouse click that began the drag
10611 * Begins a window move operation (for a toplevel window).
10612 * You might use this function to implement a "window move grip," for
10613 * example. The function works best with window managers that support
10614 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
10615 * Window Manager Hints</ulink>, but has a fallback implementation for
10616 * other window managers.
10621 gdk_window_begin_move_drag_for_device (GdkWindow *window,
10628 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
10629 device, button, root_x, root_y, timestamp);
10633 * gdk_window_begin_move_drag:
10634 * @window: a toplevel #GdkWindow
10635 * @button: the button being used to drag
10636 * @root_x: root window X coordinate of mouse click that began the drag
10637 * @root_y: root window Y coordinate of mouse click that began the drag
10638 * @timestamp: timestamp of mouse click that began the drag
10640 * Begins a window move operation (for a toplevel window).
10642 * This function assumes that the drag is controlled by the
10643 * client pointer device, use gdk_window_begin_move_drag_for_device()
10644 * to begin a drag with a different device.
10647 gdk_window_begin_move_drag (GdkWindow *window,
10653 GdkDeviceManager *device_manager;
10656 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10657 device = gdk_device_manager_get_client_pointer (device_manager);
10658 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
10662 * gdk_window_enable_synchronized_configure:
10663 * @window: a toplevel #GdkWindow
10665 * Indicates that the application will cooperate with the window
10666 * system in synchronizing the window repaint with the window
10667 * manager during resizing operations. After an application calls
10668 * this function, it must call gdk_window_configure_finished() every
10669 * time it has finished all processing associated with a set of
10670 * Configure events. Toplevel GTK+ windows automatically use this
10673 * On X, calling this function makes @window participate in the
10674 * _NET_WM_SYNC_REQUEST window manager protocol.
10679 gdk_window_enable_synchronized_configure (GdkWindow *window)
10681 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
10685 * gdk_window_configure_finished:
10686 * @window: a toplevel #GdkWindow
10688 * Signal to the window system that the application has finished
10689 * handling Configure events it has received. Window Managers can
10690 * use this to better synchronize the frame repaint with the
10691 * application. GTK+ applications will automatically call this
10692 * function when appropriate.
10694 * This function can only be called if gdk_window_enable_synchronized_configure()
10695 * was called previously.
10700 gdk_window_configure_finished (GdkWindow *window)
10702 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
10706 * gdk_window_set_opacity:
10707 * @window: a top-level #GdkWindow
10708 * @opacity: opacity
10710 * Request the windowing system to make @window partially transparent,
10711 * with opacity 0 being fully transparent and 1 fully opaque. (Values
10712 * of the opacity parameter are clamped to the [0,1] range.)
10714 * On X11, this works only on X screens with a compositing manager
10717 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
10718 * For making non-toplevel windows translucent, see
10719 * gdk_window_set_composited().
10724 gdk_window_set_opacity (GdkWindow *window,
10727 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
10730 /* This function is called when the XWindow is really gone.
10733 gdk_window_destroy_notify (GdkWindow *window)
10735 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
10739 * gdk_window_register_dnd:
10740 * @window: a #GdkWindow.
10742 * Registers a window as a potential drop destination.
10745 gdk_window_register_dnd (GdkWindow *window)
10747 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
10751 * gdk_window_get_drag_protocol:
10752 * @window: the destination window
10753 * @target: (out) (allow-none) (transfer full): location of the window
10754 * where the drop should happen. This may be @window or a proxy window,
10755 * or %NULL if @window does not support Drag and Drop.
10757 * Finds out the DND protocol supported by a window.
10759 * Returns: the supported DND protocol.
10764 gdk_window_get_drag_protocol (GdkWindow *window,
10765 GdkWindow **target)
10767 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
10769 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
10774 * @window: the source window for this drag.
10775 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10776 * as list of #GdkAtoms
10778 * Starts a drag and creates a new drag context for it.
10779 * This function assumes that the drag is controlled by the
10780 * client pointer device, use gdk_drag_begin_for_device() to
10781 * begin a drag with a different device.
10783 * This function is called by the drag source.
10785 * Return value: (transfer full): a newly created #GdkDragContext
10788 gdk_drag_begin (GdkWindow *window,
10791 GdkDeviceManager *device_manager;
10794 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10795 device = gdk_device_manager_get_client_pointer (device_manager);
10797 return gdk_drag_begin_for_device (window, device, targets);
10801 * gdk_drag_begin_for_device:
10802 * @window: the source window for this drag
10803 * @device: the device that controls this drag
10804 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10805 * as list of #GdkAtoms
10807 * Starts a drag and creates a new drag context for it.
10809 * This function is called by the drag source.
10811 * Return value: (transfer full): a newly created #GdkDragContext
10814 gdk_drag_begin_for_device (GdkWindow *window,
10818 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
10822 * gdk_test_render_sync:
10823 * @window: a mapped #GdkWindow
10825 * Retrieves a pixel from @window to force the windowing
10826 * system to carry out any pending rendering commands.
10828 * This function is intended to be used to synchronize with rendering
10829 * pipelines, to benchmark windowing system rendering operations.
10834 gdk_test_render_sync (GdkWindow *window)
10836 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
10840 * gdk_test_simulate_key:
10841 * @window: a #GdkWindow to simulate a key event for
10842 * @x: x coordinate within @window for the key event
10843 * @y: y coordinate within @window for the key event
10844 * @keyval: A GDK keyboard value
10845 * @modifiers: Keyboard modifiers the event is setup with
10846 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
10848 * This function is intended to be used in GTK+ test programs.
10849 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
10850 * the given (@x,@y) coordinates within @window and simulate a
10851 * key press or release event.
10853 * When the mouse pointer is warped to the target location, use
10854 * of this function outside of test programs that run in their
10855 * own virtual windowing system (e.g. Xvfb) is not recommended.
10856 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
10857 * be warped and @window origin will be used as mouse pointer
10858 * location for the event.
10860 * Also, gdk_test_simulate_key() is a fairly low level function,
10861 * for most testing purposes, gtk_test_widget_send_key() is the
10862 * right function to call which will generate a key press event
10863 * followed by its accompanying key release event.
10865 * Returns: whether all actions necessary for a key event simulation
10866 * were carried out successfully
10871 gdk_test_simulate_key (GdkWindow *window,
10875 GdkModifierType modifiers,
10876 GdkEventType key_pressrelease)
10878 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10879 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
10883 * gdk_test_simulate_button:
10884 * @window: a #GdkWindow to simulate a button event for
10885 * @x: x coordinate within @window for the button event
10886 * @y: y coordinate within @window for the button event
10887 * @button: Number of the pointer button for the event, usually 1, 2 or 3
10888 * @modifiers: Keyboard modifiers the event is setup with
10889 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
10891 * This function is intended to be used in GTK+ test programs.
10892 * It will warp the mouse pointer to the given (@x,@y) coordinates
10893 * within @window and simulate a button press or release event.
10894 * Because the mouse pointer needs to be warped to the target
10895 * location, use of this function outside of test programs that
10896 * run in their own virtual windowing system (e.g. Xvfb) is not
10899 * Also, gdk_test_simulate_button() is a fairly low level function,
10900 * for most testing purposes, gtk_test_widget_click() is the right
10901 * function to call which will generate a button press event followed
10902 * by its accompanying button release event.
10904 * Returns: whether all actions necessary for a button event simulation
10905 * were carried out successfully
10910 gdk_test_simulate_button (GdkWindow *window,
10913 guint button, /*1..3*/
10914 GdkModifierType modifiers,
10915 GdkEventType button_pressrelease)
10917 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10918 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
10922 * gdk_property_get:
10923 * @window: a #GdkWindow
10924 * @property: the property to retrieve
10925 * @type: the desired property type, or %GDK_NONE, if any type of data
10926 * is acceptable. If this does not match the actual
10927 * type, then @actual_format and @actual_length will
10928 * be filled in, a warning will be printed to stderr
10929 * and no data will be returned.
10930 * @offset: the offset into the property at which to begin
10931 * retrieving data, in 4 byte units.
10932 * @length: the length of the data to retrieve in bytes. Data is
10933 * considered to be retrieved in 4 byte chunks, so @length
10934 * will be rounded up to the next highest 4 byte boundary
10935 * (so be careful not to pass a value that might overflow
10936 * when rounded up).
10937 * @pdelete: if %TRUE, delete the property after retrieving the
10939 * @actual_property_type: (out) (transfer none): location to store the
10940 * actual type of the property.
10941 * @actual_format: (out): location to store the actual return format of the
10942 * data; either 8, 16 or 32 bits.
10943 * @actual_length: location to store the length of the retrieved data, in
10944 * bytes. Data returned in the 32 bit format is stored
10945 * in a long variable, so the actual number of 32 bit
10946 * elements should be be calculated via
10947 * @actual_length / sizeof(glong) to ensure portability to
10949 * @data: (out) (array length=actual_length) (transfer full): location
10950 * to store a pointer to the data. The retrieved data should be
10951 * freed with g_free() when you are finished using it.
10953 * Retrieves a portion of the contents of a property. If the
10954 * property does not exist, then the function returns %FALSE,
10955 * and %GDK_NONE will be stored in @actual_property_type.
10959 * The XGetWindowProperty() function that gdk_property_get()
10960 * uses has a very confusing and complicated set of semantics.
10961 * Unfortunately, gdk_property_get() makes the situation
10962 * worse instead of better (the semantics should be considered
10963 * undefined), and also prints warnings to stderr in cases where it
10964 * should return a useful error to the program. You are advised to use
10965 * XGetWindowProperty() directly until a replacement function for
10966 * gdk_property_get()
10971 * Returns: %TRUE if data was successfully received and stored
10972 * in @data, otherwise %FALSE.
10975 gdk_property_get (GdkWindow *window,
10981 GdkAtom *actual_property_type,
10982 gint *actual_format_type,
10983 gint *actual_length,
10986 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10987 ->get_property (window, property, type, offset, length, pdelete,
10988 actual_property_type, actual_format_type,
10989 actual_length, data);
10993 * gdk_property_change: (skip)
10994 * @window: a #GdkWindow
10995 * @property: the property to change
10996 * @type: the new type for the property. If @mode is
10997 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
10998 * must match the existing type or an error will occur.
10999 * @format: the new format for the property. If @mode is
11000 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11001 * must match the existing format or an error will occur.
11002 * @mode: a value describing how the new data is to be combined
11003 * with the current data.
11004 * @data: the data (a <literal>guchar *</literal>
11005 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
11006 * depending on @format), cast to a <literal>guchar *</literal>.
11007 * @nelements: the number of elements of size determined by the format,
11008 * contained in @data.
11010 * Changes the contents of a property on a window.
11013 gdk_property_change (GdkWindow *window,
11018 const guchar *data,
11021 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11022 ->change_property (window, property, type, format, mode, data, nelements);
11026 * gdk_property_delete:
11027 * @window: a #GdkWindow
11028 * @property: the property to delete
11030 * Deletes a property from a window.
11033 gdk_property_delete (GdkWindow *window,
11036 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);