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, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <cairo-gobject.h>
30 #include "gdkwindow.h"
32 #include "gdkrectangle.h"
33 #include "gdkinternals.h"
35 #include "gdkscreenprivate.h"
36 #include "gdkdisplayprivate.h"
37 #include "gdkdeviceprivate.h"
38 #include "gdkvisualprivate.h"
39 #include "gdkmarshalers.h"
40 #include "gdkwindowimpl.h"
44 #undef DEBUG_WINDOW_PRINTING
49 * @Short_description: Onscreen display areas in the target window system
52 * A #GdkWindow is a (usually) rectangular region on the screen.
53 * It's a low-level object, used to implement high-level objects such as
54 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
55 * window, the thing a user might think of as a "window" with a titlebar and
56 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
57 * #GtkButton has a #GdkWindow associated with it.
59 * <refsect2 id="COMPOSITED-WINDOWS">
60 * <title>Composited Windows</title>
62 * Normally, the windowing system takes care of rendering the contents of a
63 * child window onto its parent window. This mechanism can be intercepted by
64 * calling gdk_window_set_composited() on the child window. For a
65 * <firstterm>composited</firstterm> window it is the responsibility of the
66 * application to render the window contents at the right spot.
69 * <refsect2 id="OFFSCREEN-WINDOWS">
70 * <title>Offscreen Windows</title>
72 * Offscreen windows are more general than composited windows, since they allow
73 * not only to modify the rendering of the child window onto its parent, but
74 * also to apply coordinate transformations.
76 * To integrate an offscreen window into a window hierarchy, one has to call
77 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
78 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
79 * select an offscreen child at given coordinates, and the
80 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
81 * offscreen window are used to translate coordinates between the embedder and
82 * the offscreen window.
84 * For rendering an offscreen window onto its embedder, the contents of the
85 * offscreen window are available as a surface, via
86 * gdk_offscreen_window_get_surface().
92 /* Historically a GdkWindow always matches a platform native window,
93 * be it a toplevel window or a child window. In this setup the
94 * GdkWindow (and other GdkDrawables) were platform independent classes,
95 * and the actual platform specific implementation was in a delegate
96 * object available as "impl" in the window object.
98 * With the addition of client side windows and offscreen windows this
99 * changes a bit. The application-visible GdkWindow object behaves as
100 * it did before, but not all such windows now have a corresponding native
101 * window. Instead windows that are "client side" are emulated by the gdk
102 * code such that clipping, drawing, moving, events etc work as expected.
104 * For GdkWindows that have a native window the "impl" object is the
105 * same as before. However, for all client side windows the impl object
106 * is shared with its parent (i.e. all client windows descendants of one
107 * native window has the same impl.
109 * Additionally there is a new type of platform independent impl object,
110 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
111 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
112 * windows). Such windows work by allocating a #cairo_surface_t as the backing
113 * store for drawing operations, which is resized with the window.
115 * GdkWindows have a pointer to the "impl window" they are in, i.e.
116 * the topmost GdkWindow which have the same "impl" value. This is stored
117 * in impl_window, which is different from the window itself only for client
119 * All GdkWindows (native or not) track the position of the window in the parent
120 * (x, y), the size of the window (width, height), the position of the window
121 * with respect to the impl window (abs_x, abs_y). We also track the clip
122 * region of the window wrt parent windows and siblings, in window-relative
123 * coordinates with and without child windows included (clip_region,
124 * clip_region_with_children).
126 * All toplevel windows are native windows, but also child windows can be
127 * native (although not children of offscreens). We always listen to
128 * a basic set of events (see get_native_event_mask) for these windows
129 * so that we can emulate events for any client side children.
131 * For native windows we apply the calculated clip region as a window shape
132 * so that eg. client side siblings that overlap the native child properly
133 * draws over the native child window.
135 * In order to minimize flicker and for performance we use a couple of cacheing
136 * tricks. First of all, every time we do a window to window copy area, for instance
137 * when moving a client side window or when scrolling/moving a region in a window
138 * we store this in outstanding_moves instead of applying immediately. We then
139 * delay this move until we really need it (because something depends on being
140 * able to read it), or until we're handing a redraw from an expose/invalidation
141 * (actually we delay it past redraw, but before blitting the double buffer
142 * to the window). This gives us two advantages. First of all it minimizes the time
143 * from the window is moved to the exposes related to that move, secondly it allows
144 * us to be smart about how to do the copy. We combine multiple moves into one (when
145 * possible) and we don't actually do copies to anything that is or will be
146 * invalidated and exposed anyway.
148 * Secondly, we use something called a "implicit paint" during repaint handling.
149 * An implicit paint is similar to a regular paint for the paint stack, but it is
150 * not put on the stack. Instead, it is set on the impl window, and later when
151 * regular gdk_window_begin_paint_region() happen on a window of this impl window
152 * we reuse the surface from the implicit paint. During repaint we create and at the
153 * end flush an implicit paint, which means we can collect all the paints on
154 * multiple client side windows in the same backing store.
157 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
159 /* This adds a local value to the GdkVisibilityState enum */
160 #define GDK_VISIBILITY_NOT_VIEWABLE 3
163 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
177 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
181 struct _GdkWindowPaint
183 cairo_region_t *region;
184 cairo_surface_t *surface;
185 cairo_region_t *flushed;
186 guint uses_implicit : 1;
190 cairo_region_t *dest_region; /* The destination region */
191 int dx, dy; /* The amount that the source was moved to reach dest_region */
192 } GdkWindowRegionMove;
196 static void gdk_window_drop_cairo_surface (GdkWindow *private);
198 static void gdk_window_free_paint_stack (GdkWindow *window);
200 static void gdk_window_finalize (GObject *object);
202 static void gdk_window_set_property (GObject *object,
206 static void gdk_window_get_property (GObject *object,
211 static void gdk_window_clear_backing_region (GdkWindow *window,
212 cairo_region_t *region);
214 static void recompute_visible_regions (GdkWindow *private,
215 gboolean recalculate_siblings,
216 gboolean recalculate_children);
217 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
218 static void gdk_window_flush_recursive (GdkWindow *window);
219 static void do_move_region_bits_on_impl (GdkWindow *window,
220 cairo_region_t *region, /* In impl window coords */
222 static void gdk_window_invalidate_in_parent (GdkWindow *private);
223 static void move_native_children (GdkWindow *private);
224 static void update_cursor (GdkDisplay *display,
226 static void impl_window_add_update_area (GdkWindow *impl_window,
227 cairo_region_t *region);
228 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
229 static void gdk_window_invalidate_region_full (GdkWindow *window,
230 const cairo_region_t *region,
231 gboolean invalidate_children,
233 static void gdk_window_invalidate_rect_full (GdkWindow *window,
234 const GdkRectangle *rect,
235 gboolean invalidate_children,
237 static void _gdk_window_propagate_has_alpha_background (GdkWindow *window);
238 static cairo_surface_t *gdk_window_ref_impl_surface (GdkWindow *window);
240 static guint signals[LAST_SIGNAL] = { 0 };
242 static gpointer parent_class = NULL;
244 static const cairo_user_data_key_t gdk_window_cairo_key;
246 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
248 #ifdef DEBUG_WINDOW_PRINTING
250 print_region (cairo_region_t *region)
252 GString *s = g_string_new ("{");
253 if (cairo_region_is_empty (region))
255 g_string_append (s, "empty");
259 int num = cairo_region_num_rectangles (region);
260 cairo_rectangle_int_t r;
264 cairo_region_get_rectangle (region, 0, &r);
265 g_string_append_printf (s, "%dx%d @%d,%d", r.width, r.height, r.x, r.y);
269 cairo_region_get_extents (region, &r);
270 g_string_append_printf (s, "extent: %dx%d @%d,%d, details: ", r.width, r.height, r.x, r.y);
271 for (int i = 0; i < num; i++)
273 g_string_append_printf (s, "[%dx%d @%d,%d]", r.width, r.height, r.x, r.y);
275 g_string_append (s, ", ");
279 g_string_append (s, "}");
280 return g_string_free (s, FALSE);
285 _gdk_paintable_get_type (void)
287 static GType paintable_type = 0;
291 const GTypeInfo paintable_info =
293 sizeof (GdkPaintableIface), /* class_size */
294 NULL, /* base_init */
295 NULL, /* base_finalize */
298 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
299 g_intern_static_string ("GdkPaintable"),
302 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
305 return paintable_type;
309 gdk_window_init (GdkWindow *window)
311 /* 0-initialization is good for all other fields. */
313 window->window_type = GDK_WINDOW_CHILD;
315 window->state = GDK_WINDOW_STATE_WITHDRAWN;
316 window->fullscreen_mode = GDK_FULLSCREEN_ON_CURRENT_MONITOR;
319 window->toplevel_window_type = -1;
321 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
322 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
323 /* Default to unobscured since some backends don't send visibility events */
324 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
326 window->device_cursor = g_hash_table_new_full (NULL, NULL,
327 NULL, g_object_unref);
330 /* Stop and return on the first non-NULL parent */
332 accumulate_get_window (GSignalInvocationHint *ihint,
334 const GValue *handler_return,
337 g_value_copy (handler_return, return_accu);
338 /* Continue while returning NULL */
339 return g_value_get_object (handler_return) == NULL;
343 create_surface_accumulator (GSignalInvocationHint *ihint,
345 const GValue *handler_return,
348 g_value_copy (handler_return, return_accu);
350 /* Stop on the first non-NULL return value */
351 return g_value_get_boxed (handler_return) == NULL;
354 static GQuark quark_pointer_window = 0;
357 gdk_window_class_init (GdkWindowClass *klass)
359 GObjectClass *object_class = G_OBJECT_CLASS (klass);
361 parent_class = g_type_class_peek_parent (klass);
363 object_class->finalize = gdk_window_finalize;
364 object_class->set_property = gdk_window_set_property;
365 object_class->get_property = gdk_window_get_property;
367 klass->create_surface = _gdk_offscreen_window_create_surface;
369 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
377 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
378 * gdk_window_get_cursor() for details.
382 g_object_class_install_property (object_class,
384 g_param_spec_object ("cursor",
391 * GdkWindow::pick-embedded-child:
392 * @window: the window on which the signal is emitted
393 * @x: x coordinate in the window
394 * @y: y coordinate in the window
396 * The ::pick-embedded-child signal is emitted to find an embedded
397 * child at the given position.
399 * Returns: (transfer none): the #GdkWindow of the embedded child at
404 signals[PICK_EMBEDDED_CHILD] =
405 g_signal_new (g_intern_static_string ("pick-embedded-child"),
406 G_OBJECT_CLASS_TYPE (object_class),
408 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
409 accumulate_get_window, NULL,
410 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
417 * GdkWindow::to-embedder:
418 * @window: the offscreen window on which the signal is emitted
419 * @offscreen_x: x coordinate in the offscreen window
420 * @offscreen_y: y coordinate in the offscreen window
421 * @embedder_x: (out) (type double): return location for the x
422 * coordinate in the embedder window
423 * @embedder_y: (out) (type double): return location for the y
424 * coordinate in the embedder window
426 * The ::to-embedder signal is emitted to translate coordinates
427 * in an offscreen window to its embedder.
429 * See also #GtkWindow::from-embedder.
433 signals[TO_EMBEDDER] =
434 g_signal_new (g_intern_static_string ("to-embedder"),
435 G_OBJECT_CLASS_TYPE (object_class),
437 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
439 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
448 * GdkWindow::from-embedder:
449 * @window: the offscreen window on which the signal is emitted
450 * @embedder_x: x coordinate in the embedder window
451 * @embedder_y: y coordinate in the embedder window
452 * @offscreen_x: (out) (type double): return location for the x
453 * coordinate in the offscreen window
454 * @offscreen_y: (out) (type double): return location for the y
455 * coordinate in the offscreen window
457 * The ::from-embedder signal is emitted to translate coordinates
458 * in the embedder of an offscreen window to the offscreen window.
460 * See also #GtkWindow::to-embedder.
464 signals[FROM_EMBEDDER] =
465 g_signal_new (g_intern_static_string ("from-embedder"),
466 G_OBJECT_CLASS_TYPE (object_class),
468 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
470 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
479 * GdkWindow::create-surface:
480 * @window: the offscreen window on which the signal is emitted
481 * @width: the width of the offscreen surface to create
482 * @height: the height of the offscreen surface to create
484 * The ::create-surface signal is emitted when an offscreen window
485 * needs its surface (re)created, which happens either when the the
486 * window is first drawn to, or when the window is being
487 * resized. The first signal handler that returns a non-%NULL
488 * surface will stop any further signal emission, and its surface
491 * Note that it is not possible to access the window's previous
492 * surface from within any callback of this signal. Calling
493 * gdk_offscreen_window_get_surface() will lead to a crash.
495 * Returns: the newly created #cairo_surface_t for the offscreen window
499 signals[CREATE_SURFACE] =
500 g_signal_new (g_intern_static_string ("create-surface"),
501 G_OBJECT_CLASS_TYPE (object_class),
503 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
504 create_surface_accumulator, NULL,
505 _gdk_marshal_BOXED__INT_INT,
506 CAIRO_GOBJECT_TYPE_SURFACE,
513 device_removed_cb (GdkDeviceManager *device_manager,
517 window->devices_inside = g_list_remove (window->devices_inside, device);
518 g_hash_table_remove (window->device_cursor, device);
520 if (window->device_events)
521 g_hash_table_remove (window->device_events, device);
525 gdk_window_finalize (GObject *object)
527 GdkWindow *window = GDK_WINDOW (object);
528 GdkDeviceManager *device_manager;
530 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
531 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
533 if (!GDK_WINDOW_DESTROYED (window))
535 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
537 g_warning ("losing last reference to undestroyed window\n");
538 _gdk_window_destroy (window, FALSE);
541 /* We use TRUE here, to keep us from actually calling
542 * XDestroyWindow() on the window
544 _gdk_window_destroy (window, TRUE);
547 gdk_window_drop_cairo_surface (window);
551 g_object_unref (window->impl);
555 if (window->impl_window != window)
557 g_object_unref (window->impl_window);
558 window->impl_window = NULL;
562 cairo_region_destroy (window->shape);
564 if (window->input_shape)
565 cairo_region_destroy (window->input_shape);
568 g_object_unref (window->cursor);
570 if (window->device_cursor)
571 g_hash_table_destroy (window->device_cursor);
573 if (window->device_events)
574 g_hash_table_destroy (window->device_events);
576 if (window->source_event_masks)
577 g_hash_table_destroy (window->source_event_masks);
579 if (window->devices_inside)
580 g_list_free (window->devices_inside);
582 if (window->layered_region)
583 cairo_region_destroy (window->layered_region);
585 G_OBJECT_CLASS (parent_class)->finalize (object);
589 gdk_window_set_property (GObject *object,
594 GdkWindow *window = (GdkWindow *)object;
599 gdk_window_set_cursor (window, g_value_get_object (value));
603 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
609 gdk_window_get_property (GObject *object,
614 GdkWindow *window = (GdkWindow *) object;
619 g_value_set_object (value, gdk_window_get_cursor (window));
623 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
629 gdk_window_is_offscreen (GdkWindow *window)
631 return window->window_type == GDK_WINDOW_OFFSCREEN;
635 gdk_window_get_impl_window (GdkWindow *window)
637 return window->impl_window;
641 _gdk_window_get_impl_window (GdkWindow *window)
643 return gdk_window_get_impl_window (window);
647 gdk_window_has_impl (GdkWindow *window)
649 return window->impl_window == window;
653 gdk_window_is_toplevel (GdkWindow *window)
656 window->parent == NULL ||
657 window->parent->window_type == GDK_WINDOW_ROOT;
661 _gdk_window_has_impl (GdkWindow *window)
663 return gdk_window_has_impl (window);
667 gdk_window_has_no_impl (GdkWindow *window)
669 return window->impl_window != window;
673 gdk_window_has_alpha (GdkWindow *window)
675 return !gdk_window_has_impl (window) &&
676 window->has_alpha_background;
680 remove_layered_child_area (GdkWindow *window,
681 cairo_region_t *region)
684 cairo_region_t *child_region;
688 for (l = window->children; l; l = l->next)
692 /* If region is empty already, no need to do
693 anything potentially costly */
694 if (cairo_region_is_empty (region))
697 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
700 /* Ignore offscreen children, as they don't draw in their parent and
701 * don't take part in the clipping */
702 if (gdk_window_is_offscreen (child))
705 /* Only non-impl children with alpha add to the layered region */
706 if (!gdk_window_has_alpha (child))
711 r.width = child->width;
712 r.height = child->height;
714 /* Bail early if child totally outside region */
715 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
718 child_region = cairo_region_create_rectangle (&r);
721 /* Adjust shape region to parent window coords */
722 cairo_region_translate (child->shape, child->x, child->y);
723 cairo_region_intersect (child_region, child->shape);
724 cairo_region_translate (child->shape, -child->x, -child->y);
727 cairo_region_subtract (region, child_region);
728 cairo_region_destroy (child_region);
733 remove_child_area (GdkWindow *window,
736 cairo_region_t *region,
737 cairo_region_t *layered_region)
740 cairo_region_t *child_region;
743 cairo_region_t *shape;
745 for (l = window->children; l; l = l->next)
752 /* If region is empty already, no need to do
753 anything potentially costly */
754 if (cairo_region_is_empty (region))
757 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
760 /* Ignore offscreen children, as they don't draw in their parent and
761 * don't take part in the clipping */
762 if (gdk_window_is_offscreen (child))
767 r.width = child->width;
768 r.height = child->height;
770 /* Bail early if child totally outside region */
771 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
774 child_region = cairo_region_create_rectangle (&r);
778 /* Adjust shape region to parent window coords */
779 cairo_region_translate (child->shape, child->x, child->y);
780 cairo_region_intersect (child_region, child->shape);
781 cairo_region_translate (child->shape, -child->x, -child->y);
783 else if (window->window_type == GDK_WINDOW_FOREIGN)
785 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
788 cairo_region_intersect (child_region, shape);
789 cairo_region_destroy (shape);
795 if (child->input_shape)
796 cairo_region_intersect (child_region, child->input_shape);
797 else if (window->window_type == GDK_WINDOW_FOREIGN)
799 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
802 cairo_region_intersect (child_region, shape);
803 cairo_region_destroy (shape);
808 if (gdk_window_has_alpha (child))
810 if (layered_region != NULL)
811 cairo_region_union (layered_region, child_region);
814 cairo_region_subtract (region, child_region);
815 cairo_region_destroy (child_region);
819 static GdkVisibilityState
820 effective_visibility (GdkWindow *window)
822 GdkVisibilityState native;
824 if (!gdk_window_is_viewable (window))
825 return GDK_VISIBILITY_NOT_VIEWABLE;
827 native = window->impl_window->native_visibility;
829 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
830 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
831 return GDK_VISIBILITY_FULLY_OBSCURED;
832 else if (native == GDK_VISIBILITY_UNOBSCURED)
833 return window->visibility;
834 else /* native PARTIAL, private partial or unobscured */
835 return GDK_VISIBILITY_PARTIAL;
839 gdk_window_update_visibility (GdkWindow *window)
841 GdkVisibilityState new_visibility;
844 new_visibility = effective_visibility (window);
846 if (new_visibility != window->effective_visibility)
848 window->effective_visibility = new_visibility;
850 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
851 window->event_mask & GDK_VISIBILITY_NOTIFY_MASK)
853 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
855 event->visibility.state = new_visibility;
861 gdk_window_update_visibility_recursively (GdkWindow *window,
862 GdkWindow *only_for_impl)
867 gdk_window_update_visibility (window);
868 for (l = window->children; l != NULL; l = l->next)
871 if ((only_for_impl == NULL) ||
872 (only_for_impl == child->impl_window))
873 gdk_window_update_visibility_recursively (child, only_for_impl);
878 should_apply_clip_as_shape (GdkWindow *window)
881 gdk_window_has_impl (window) &&
882 /* Not for offscreens */
883 !gdk_window_is_offscreen (window) &&
884 /* or for toplevels */
885 !gdk_window_is_toplevel (window) &&
886 /* or for foreign windows */
887 window->window_type != GDK_WINDOW_FOREIGN &&
888 /* or for the root window */
889 window->window_type != GDK_WINDOW_ROOT;
893 apply_shape (GdkWindow *window,
894 cairo_region_t *region)
896 GdkWindowImplClass *impl_class;
898 /* We trash whether we applied a shape so that
899 we can avoid unsetting it many times, which
900 could happen in e.g. apply_clip_as_shape as
901 windows get resized */
902 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
904 impl_class->shape_combine_region (window,
906 else if (window->applied_shape)
907 impl_class->shape_combine_region (window,
910 window->applied_shape = region != NULL;
914 region_rect_equal (const cairo_region_t *region,
915 const GdkRectangle *rect)
917 GdkRectangle extents;
919 if (cairo_region_num_rectangles (region) != 1)
922 cairo_region_get_extents (region, &extents);
924 return extents.x == rect->x &&
925 extents.y == rect->y &&
926 extents.width == rect->width &&
927 extents.height == rect->height;
931 apply_clip_as_shape (GdkWindow *window)
936 r.width = window->width;
937 r.height = window->height;
939 /* We only apply the clip region if would differ
940 from the actual clip region implied by the size
941 of the window. This is to avoid unneccessarily
942 adding meaningless shapes to all native subwindows */
943 if (!region_rect_equal (window->clip_region, &r))
944 apply_shape (window, window->clip_region);
946 apply_shape (window, NULL);
950 recompute_visible_regions_internal (GdkWindow *private,
951 gboolean recalculate_clip,
952 gboolean recalculate_siblings,
953 gboolean recalculate_children)
958 cairo_region_t *new_clip, *new_layered;
959 gboolean clip_region_changed;
960 gboolean abs_pos_changed;
961 int old_abs_x, old_abs_y;
963 old_abs_x = private->abs_x;
964 old_abs_y = private->abs_y;
966 /* Update absolute position */
967 if (gdk_window_has_impl (private))
969 /* Native window starts here */
975 private->abs_x = private->parent->abs_x + private->x;
976 private->abs_y = private->parent->abs_y + private->y;
980 private->abs_x != old_abs_x ||
981 private->abs_y != old_abs_y;
983 /* Update clip region based on:
986 * siblings in parents above window
988 clip_region_changed = FALSE;
989 if (recalculate_clip)
991 new_layered = cairo_region_create ();
992 if (private->viewable)
994 /* Calculate visible region (sans children) in parent window coords */
997 r.width = private->width;
998 r.height = private->height;
999 new_clip = cairo_region_create_rectangle (&r);
1001 if (!gdk_window_is_toplevel (private))
1003 cairo_region_intersect (new_clip, private->parent->clip_region);
1004 cairo_region_union (new_layered, private->parent->layered_region);
1006 /* Remove all overlapping children from parent. */
1007 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
1010 /* Convert from parent coords to window coords */
1011 cairo_region_translate (new_clip, -private->x, -private->y);
1012 cairo_region_translate (new_layered, -private->x, -private->y);
1015 cairo_region_intersect (new_clip, private->shape);
1018 new_clip = cairo_region_create ();
1020 cairo_region_intersect (new_layered, new_clip);
1022 if (private->clip_region == NULL ||
1023 !cairo_region_equal (private->clip_region, new_clip))
1024 clip_region_changed = TRUE;
1026 if (private->layered_region == NULL ||
1027 !cairo_region_equal (private->layered_region, new_layered))
1028 clip_region_changed = TRUE;
1030 if (private->clip_region)
1031 cairo_region_destroy (private->clip_region);
1032 private->clip_region = new_clip;
1034 if (private->layered_region != NULL)
1035 cairo_region_destroy (private->layered_region);
1036 private->layered_region = new_layered;
1038 if (private->clip_region_with_children)
1039 cairo_region_destroy (private->clip_region_with_children);
1040 private->clip_region_with_children = cairo_region_copy (private->clip_region);
1041 if (private->window_type != GDK_WINDOW_ROOT)
1042 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
1045 if (clip_region_changed)
1047 GdkVisibilityState visibility;
1048 gboolean fully_visible;
1050 if (cairo_region_is_empty (private->clip_region))
1051 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1056 fully_visible = cairo_region_equal (private->clip_region,
1063 r.width = private->width;
1064 r.height = private->height;
1065 fully_visible = region_rect_equal (private->clip_region, &r);
1069 visibility = GDK_VISIBILITY_UNOBSCURED;
1071 visibility = GDK_VISIBILITY_PARTIAL;
1074 if (private->visibility != visibility)
1076 private->visibility = visibility;
1077 gdk_window_update_visibility (private);
1081 /* Update all children, recursively (except for root, where children are not exact). */
1082 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1083 private->window_type != GDK_WINDOW_ROOT)
1085 for (l = private->children; l; l = l->next)
1088 /* Only recalculate clip if the the clip region changed, otherwise
1089 * there is no way the child clip region could change (its has not e.g. moved)
1090 * Except if recalculate_children is set to force child updates
1092 recompute_visible_regions_internal (child,
1093 recalculate_clip && (clip_region_changed || recalculate_children),
1098 if (clip_region_changed &&
1099 should_apply_clip_as_shape (private))
1100 apply_clip_as_shape (private);
1102 if (recalculate_siblings &&
1103 !gdk_window_is_toplevel (private))
1105 /* If we moved a child window in parent or changed the stacking order, then we
1106 * need to recompute the visible area of all the other children in the parent
1108 for (l = private->parent->children; l; l = l->next)
1112 if (child != private)
1113 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1116 /* We also need to recompute the _with_children clip for the parent */
1117 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1120 if (private->cairo_surface && gdk_window_has_impl (private))
1122 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1124 private->cairo_surface = iface->resize_cairo_surface (private,
1125 private->cairo_surface,
1129 else if (private->cairo_surface)
1130 gdk_window_drop_cairo_surface (private);
1133 /* Call this when private has changed in one or more of these ways:
1137 * stacking order of window changed
1140 * It will recalculate abs_x/y and the clip regions
1142 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1143 * for recalculate_siblings. (Mostly used internally for the recursion)
1145 * If a child window was removed (and you can't use that child for
1146 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1149 recompute_visible_regions (GdkWindow *private,
1150 gboolean recalculate_siblings,
1151 gboolean recalculate_children)
1153 recompute_visible_regions_internal (private,
1155 recalculate_siblings,
1156 recalculate_children);
1160 _gdk_window_update_size (GdkWindow *window)
1162 recompute_visible_regions (window, TRUE, FALSE);
1165 /* Find the native window that would be just above "child"
1166 * in the native stacking order if "child" was a native window
1167 * (it doesn't have to be native). If there is no such native
1168 * window inside this native parent then NULL is returned.
1169 * If child is NULL, find lowest native window in parent.
1172 find_native_sibling_above_helper (GdkWindow *parent,
1180 l = g_list_find (parent->children, child);
1181 g_assert (l != NULL); /* Better be a child of its parent... */
1182 l = l->prev; /* Start looking at the one above the child */
1185 l = g_list_last (parent->children);
1187 for (; l != NULL; l = l->prev)
1191 if (gdk_window_has_impl (w))
1194 g_assert (parent != w);
1195 w = find_native_sibling_above_helper (w, NULL);
1205 find_native_sibling_above (GdkWindow *parent,
1210 w = find_native_sibling_above_helper (parent, child);
1214 if (gdk_window_has_impl (parent))
1217 return find_native_sibling_above (parent->parent, parent);
1221 get_native_device_event_mask (GdkWindow *private,
1224 GdkEventMask event_mask;
1227 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1229 event_mask = private->event_mask;
1231 if (private->window_type == GDK_WINDOW_ROOT ||
1232 private->window_type == GDK_WINDOW_FOREIGN)
1238 /* Do whatever the app asks to, since the app
1239 * may be asking for weird things for native windows,
1240 * but don't use motion hints as that may affect non-native
1241 * child windows that don't want it. Also, we need to
1242 * set all the app-specified masks since they will be picked
1243 * up by any implicit grabs (i.e. if they were not set as
1244 * native we would not get the events we need). */
1245 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1247 /* We need thse for all native windows so we can
1248 emulate events on children: */
1251 GDK_VISIBILITY_NOTIFY_MASK |
1252 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1254 /* Additionally we select for pointer and button events
1255 * for toplevels as we need to get these to emulate
1256 * them for non-native subwindows. Even though we don't
1257 * select on them for all native windows we will get them
1258 * as the events are propagated out to the first window
1259 * that select for them.
1260 * Not selecting for button press on all windows is an
1261 * important thing, because in X only one client can do
1262 * so, and we don't want to unexpectedly prevent another
1263 * client from doing it.
1265 * We also need to do the same if the app selects for button presses
1266 * because then we will get implicit grabs for this window, and the
1267 * event mask used for that grab is based on the rest of the mask
1268 * for the window, but we might need more events than this window
1269 * lists due to some non-native child window.
1271 if (gdk_window_is_toplevel (private) ||
1272 mask & GDK_BUTTON_PRESS_MASK)
1275 GDK_POINTER_MOTION_MASK |
1276 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1284 get_native_grab_event_mask (GdkEventMask grab_mask)
1286 /* Similar to the above but for pointer events only */
1288 GDK_POINTER_MOTION_MASK |
1289 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1290 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1293 ~GDK_POINTER_MOTION_HINT_MASK);
1297 get_native_event_mask (GdkWindow *private)
1299 return get_native_device_event_mask (private, NULL);
1302 /* Puts the native window in the right order wrt the other native windows
1303 * in the hierarchy, given the position it has in the client side data.
1304 * This is useful if some operation changed the stacking order.
1305 * This calls assumes the native window is now topmost in its native parent.
1308 sync_native_window_stack_position (GdkWindow *window)
1311 GdkWindowImplClass *impl_class;
1312 GList listhead = {0};
1314 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1316 above = find_native_sibling_above (window->parent, window);
1319 listhead.data = window;
1320 impl_class->restack_under (above, &listhead);
1325 * gdk_window_new: (constructor)
1326 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1327 * the default root window for the default display.
1328 * @attributes: attributes of the new window
1329 * @attributes_mask: (type GdkWindowAttributesType): mask indicating which
1330 * fields in @attributes are valid
1332 * Creates a new #GdkWindow using the attributes from
1333 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1334 * more details. Note: to use this on displays other than the default
1335 * display, @parent must be specified.
1337 * Return value: (transfer full): the new #GdkWindow
1340 gdk_window_new (GdkWindow *parent,
1341 GdkWindowAttr *attributes,
1342 gint attributes_mask)
1346 GdkDisplay *display;
1349 GdkEventMask event_mask;
1350 GdkWindow *real_parent;
1351 GdkDeviceManager *device_manager;
1353 g_return_val_if_fail (attributes != NULL, NULL);
1357 GDK_NOTE (MULTIHEAD,
1358 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1360 screen = gdk_screen_get_default ();
1361 parent = gdk_screen_get_root_window (screen);
1364 screen = gdk_window_get_screen (parent);
1366 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1368 if (GDK_WINDOW_DESTROYED (parent))
1370 g_warning ("gdk_window_new(): parent is destroyed\n");
1374 if (attributes_mask & GDK_WA_VISUAL)
1376 g_return_val_if_fail (gdk_visual_get_screen (attributes->visual) == screen, NULL);
1379 display = gdk_screen_get_display (screen);
1381 window = _gdk_display_create_window (display);
1383 /* Windows with a foreign parent are treated as if they are children
1384 * of the root window, except for actual creation.
1386 real_parent = parent;
1387 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1388 parent = gdk_screen_get_root_window (screen);
1390 window->parent = parent;
1392 window->accept_focus = TRUE;
1393 window->focus_on_map = TRUE;
1395 if (attributes_mask & GDK_WA_X)
1400 if (attributes_mask & GDK_WA_Y)
1407 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1408 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1410 if (attributes->wclass == GDK_INPUT_ONLY)
1412 /* Backwards compatiblity - we've always ignored
1413 * attributes->window_type for input-only windows
1416 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1417 window->window_type = GDK_WINDOW_TEMP;
1419 window->window_type = GDK_WINDOW_CHILD;
1422 window->window_type = attributes->window_type;
1425 switch (window->window_type)
1427 case GDK_WINDOW_TOPLEVEL:
1428 case GDK_WINDOW_TEMP:
1429 case GDK_WINDOW_OFFSCREEN:
1430 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1431 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1432 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1433 case GDK_WINDOW_CHILD:
1437 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1441 if (attributes_mask & GDK_WA_VISUAL)
1442 window->visual = attributes->visual;
1444 window->visual = gdk_screen_get_system_visual (screen);
1446 window->event_mask = attributes->event_mask;
1448 if (attributes->wclass == GDK_INPUT_OUTPUT)
1450 window->input_only = FALSE;
1451 window->depth = window->visual->depth;
1453 /* XXX: Cache this somehow? */
1454 window->background = cairo_pattern_create_rgba (0, 0, 0, 0);
1455 window->has_alpha_background = TRUE;
1460 window->input_only = TRUE;
1464 window->parent->children = g_list_prepend (window->parent->children, window);
1467 if (window->parent->window_type == GDK_WINDOW_ROOT)
1468 native = TRUE; /* Always use native windows for toplevels */
1469 else if (!window->input_only &&
1470 (attributes_mask & GDK_WA_VISUAL &&
1471 attributes->visual != gdk_window_get_visual (window->parent)))
1472 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1474 if (gdk_window_is_offscreen (window))
1476 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1477 window->impl_window = window;
1481 event_mask = get_native_event_mask (window);
1483 /* Create the impl */
1484 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1485 window->impl_window = window;
1487 /* This will put the native window topmost in the native parent, which may
1488 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1489 if (!_gdk_window_has_impl (real_parent))
1490 sync_native_window_stack_position (window);
1494 window->impl_window = g_object_ref (window->parent->impl_window);
1495 window->impl = g_object_ref (window->impl_window->impl);
1498 recompute_visible_regions (window, TRUE, FALSE);
1500 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1501 (attributes->cursor) :
1504 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1505 g_signal_connect (device_manager, "device-removed",
1506 G_CALLBACK (device_removed_cb), window);
1512 is_parent_of (GdkWindow *parent,
1523 w = gdk_window_get_parent (w);
1530 change_impl (GdkWindow *private,
1531 GdkWindow *impl_window,
1536 GdkWindowImpl *old_impl;
1537 GdkWindow *old_impl_window;
1539 old_impl = private->impl;
1540 old_impl_window = private->impl_window;
1541 if (private != impl_window)
1542 private->impl_window = g_object_ref (impl_window);
1544 private->impl_window = private;
1545 private->impl = g_object_ref (new);
1546 if (old_impl_window != private)
1547 g_object_unref (old_impl_window);
1548 g_object_unref (old_impl);
1550 for (l = private->children; l != NULL; l = l->next)
1554 if (child->impl == old_impl)
1555 change_impl (child, impl_window, new);
1560 reparent_to_impl (GdkWindow *private)
1565 GdkWindowImplClass *impl_class;
1567 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1569 /* Enumerate in reverse order so we get the right order for the native
1570 windows (first in childrens list is topmost, and reparent places on top) */
1571 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1575 if (child->impl == private->impl)
1576 reparent_to_impl (child);
1579 show = impl_class->reparent ((GdkWindow *)child,
1580 (GdkWindow *)private,
1581 child->x, child->y);
1583 gdk_window_show_unraised ((GdkWindow *)child);
1590 * gdk_window_reparent:
1591 * @window: a #GdkWindow
1592 * @new_parent: new parent to move @window into
1593 * @x: X location inside the new parent
1594 * @y: Y location inside the new parent
1596 * Reparents @window into the given @new_parent. The window being
1597 * reparented will be unmapped as a side effect.
1601 gdk_window_reparent (GdkWindow *window,
1602 GdkWindow *new_parent,
1606 GdkWindow *old_parent;
1608 gboolean show, was_mapped, applied_clip_as_shape;
1609 gboolean do_reparent_to_impl;
1610 GdkEventMask old_native_event_mask;
1611 GdkWindowImplClass *impl_class;
1613 g_return_if_fail (GDK_IS_WINDOW (window));
1614 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1615 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1617 if (GDK_WINDOW_DESTROYED (window) ||
1618 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1621 screen = gdk_window_get_screen (window);
1623 new_parent = gdk_screen_get_root_window (screen);
1625 /* No input-output children of input-only windows */
1626 if (new_parent->input_only && !window->input_only)
1629 /* Don't create loops in hierarchy */
1630 if (is_parent_of (window, new_parent))
1633 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1634 To make sure we're ok, just wipe it. */
1635 gdk_window_drop_cairo_surface (window);
1637 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1638 old_parent = window->parent;
1640 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1643 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1644 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1645 new_parent->window_type == GDK_WINDOW_FOREIGN)
1646 gdk_window_ensure_native (window);
1648 applied_clip_as_shape = should_apply_clip_as_shape (window);
1650 old_native_event_mask = 0;
1651 do_reparent_to_impl = FALSE;
1652 if (gdk_window_has_impl (window))
1654 old_native_event_mask = get_native_event_mask (window);
1656 show = impl_class->reparent (window, new_parent, x, y);
1660 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1661 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1662 new_parent->window_type != GDK_WINDOW_FOREIGN);
1665 gdk_window_hide (window);
1667 do_reparent_to_impl = TRUE;
1668 change_impl (window,
1669 new_parent->impl_window,
1673 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1676 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1678 new_parent = gdk_screen_get_root_window (screen);
1682 old_parent->children = g_list_remove (old_parent->children, window);
1684 window->parent = new_parent;
1688 new_parent->children = g_list_prepend (new_parent->children, window);
1690 /* Switch the window type as appropriate */
1692 switch (GDK_WINDOW_TYPE (new_parent))
1694 case GDK_WINDOW_ROOT:
1695 case GDK_WINDOW_FOREIGN:
1696 if (window->toplevel_window_type != -1)
1697 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1698 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1699 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1701 case GDK_WINDOW_OFFSCREEN:
1702 case GDK_WINDOW_TOPLEVEL:
1703 case GDK_WINDOW_CHILD:
1704 case GDK_WINDOW_TEMP:
1705 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1706 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1708 /* Save the original window type so we can restore it if the
1709 * window is reparented back to be a toplevel
1711 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1712 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1716 /* We might have changed window type for a native windows, so we
1717 need to change the event mask too. */
1718 if (gdk_window_has_impl (window))
1720 GdkEventMask native_event_mask = get_native_event_mask (window);
1722 if (native_event_mask != old_native_event_mask)
1723 impl_class->set_events (window, native_event_mask);
1726 _gdk_window_update_viewable (window);
1728 if (window->background == NULL)
1730 /* parent relative background, update has_alpha_background */
1731 if (window->parent == NULL ||
1732 window->parent->window_type == GDK_WINDOW_ROOT)
1733 window->has_alpha_background = FALSE;
1735 window->has_alpha_background = window->parent->has_alpha_background;
1738 recompute_visible_regions (window, TRUE, FALSE);
1739 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1740 recompute_visible_regions (old_parent, FALSE, TRUE);
1742 _gdk_window_propagate_has_alpha_background (window);
1744 /* We used to apply the clip as the shape, but no more.
1745 Reset this to the real shape */
1746 if (gdk_window_has_impl (window) &&
1747 applied_clip_as_shape &&
1748 !should_apply_clip_as_shape (window))
1749 apply_shape (window, window->shape);
1751 if (do_reparent_to_impl)
1752 reparent_to_impl (window);
1755 /* The reparent will have put the native window topmost in the native parent,
1756 * which may be wrong wrt other native windows in the non-native hierarchy,
1758 if (!gdk_window_has_impl (new_parent))
1759 sync_native_window_stack_position (window);
1763 gdk_window_show_unraised (window);
1765 _gdk_synthesize_crossing_events_for_geometry_change (window);
1769 * gdk_window_ensure_native:
1770 * @window: a #GdkWindow
1772 * Tries to ensure that there is a window-system native window for this
1773 * GdkWindow. This may fail in some situations, returning %FALSE.
1775 * Offscreen window and children of them can never have native windows.
1777 * Some backends may not support native child windows.
1779 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1784 gdk_window_ensure_native (GdkWindow *window)
1786 GdkWindow *impl_window;
1787 GdkWindowImpl *new_impl, *old_impl;
1788 GdkDisplay *display;
1792 GdkWindowImplClass *impl_class;
1794 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1796 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1797 GDK_WINDOW_DESTROYED (window))
1800 impl_window = gdk_window_get_impl_window (window);
1802 if (gdk_window_is_offscreen (impl_window))
1803 return FALSE; /* native in offscreens not supported */
1805 if (impl_window == window)
1806 /* Already has an impl, and its not offscreen . */
1809 /* Need to create a native window */
1811 gdk_window_drop_cairo_surface (window);
1813 screen = gdk_window_get_screen (window);
1814 display = gdk_screen_get_display (screen);
1816 old_impl = window->impl;
1817 _gdk_display_create_window_impl (display,
1818 window, window->parent,
1820 get_native_event_mask (window),
1822 new_impl = window->impl;
1824 window->impl = old_impl;
1825 change_impl (window, window, new_impl);
1827 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1829 /* Native window creation will put the native window topmost in the
1830 * native parent, which may be wrong wrt the position of the previous
1831 * non-native window wrt to the other non-native children, so correct this.
1833 above = find_native_sibling_above (window->parent, window);
1836 listhead.data = window;
1837 listhead.prev = NULL;
1838 listhead.next = NULL;
1839 impl_class->restack_under ((GdkWindow *)above, &listhead);
1842 recompute_visible_regions (window, FALSE, FALSE);
1844 /* The shape may not have been set, as the clip region doesn't actually
1845 change, so do it here manually */
1846 if (should_apply_clip_as_shape (window))
1847 apply_clip_as_shape (window);
1849 reparent_to_impl (window);
1851 if (!window->input_only)
1852 impl_class->set_background (window, window->background);
1854 impl_class->input_shape_combine_region (window,
1855 window->input_shape,
1858 if (gdk_window_is_viewable (window))
1859 impl_class->show (window, FALSE);
1865 * _gdk_event_filter_unref:
1866 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1867 * @filter: A window filter
1869 * Release a reference to @filter. Note this function may
1870 * mutate the list storage, so you need to handle this
1871 * if iterating over a list of filters.
1874 _gdk_event_filter_unref (GdkWindow *window,
1875 GdkEventFilter *filter)
1881 filters = &_gdk_default_filters;
1883 filters = &window->filters;
1885 tmp_list = *filters;
1888 GdkEventFilter *iter_filter = tmp_list->data;
1892 tmp_list = tmp_list->next;
1894 if (iter_filter != filter)
1897 g_assert (iter_filter->ref_count > 0);
1899 filter->ref_count--;
1900 if (filter->ref_count != 0)
1903 *filters = g_list_remove_link (*filters, node);
1905 g_list_free_1 (node);
1910 window_remove_filters (GdkWindow *window)
1912 while (window->filters)
1913 _gdk_event_filter_unref (window, window->filters->data);
1917 update_pointer_info_foreach (GdkDisplay *display,
1919 GdkPointerWindowInfo *pointer_info,
1922 GdkWindow *window = user_data;
1924 if (pointer_info->toplevel_under_pointer == window)
1926 g_object_unref (pointer_info->toplevel_under_pointer);
1927 pointer_info->toplevel_under_pointer = NULL;
1932 window_remove_from_pointer_info (GdkWindow *window,
1933 GdkDisplay *display)
1935 _gdk_display_pointer_info_foreach (display,
1936 update_pointer_info_foreach,
1941 * _gdk_window_destroy_hierarchy:
1942 * @window: a #GdkWindow
1943 * @recursing: If TRUE, then this is being called because a parent
1945 * @recursing_native: If TRUE, then this is being called because a native parent
1946 * was destroyed. This generally means that the call to the
1947 * windowing system to destroy the window can be omitted, since
1948 * it will be destroyed as a result of the parent being destroyed.
1949 * Unless @foreign_destroy.
1950 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1951 * external agency. The window has already been destroyed and no
1952 * windowing system calls should be made. (This may never happen
1953 * for some windowing systems.)
1955 * Internal function to destroy a window. Like gdk_window_destroy(),
1956 * but does not drop the reference count created by gdk_window_new().
1959 _gdk_window_destroy_hierarchy (GdkWindow *window,
1961 gboolean recursing_native,
1962 gboolean foreign_destroy)
1964 GdkWindowImplClass *impl_class;
1965 GdkWindow *temp_window;
1967 GdkDisplay *display;
1971 g_return_if_fail (GDK_IS_WINDOW (window));
1973 if (GDK_WINDOW_DESTROYED (window))
1976 display = gdk_window_get_display (window);
1977 screen = gdk_window_get_screen (window);
1978 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1979 if (temp_window == window)
1980 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1983 switch (window->window_type)
1985 case GDK_WINDOW_ROOT:
1986 if (!screen->closed)
1988 g_error ("attempted to destroy root window");
1991 /* else fall thru */
1992 case GDK_WINDOW_TOPLEVEL:
1993 case GDK_WINDOW_CHILD:
1994 case GDK_WINDOW_TEMP:
1995 case GDK_WINDOW_FOREIGN:
1996 case GDK_WINDOW_OFFSCREEN:
1997 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1999 /* Logically, it probably makes more sense to send
2000 * a "destroy yourself" message to the foreign window
2001 * whether or not it's in our hierarchy; but for historical
2002 * reasons, we only send "destroy yourself" messages to
2003 * foreign windows in our hierarchy.
2007 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2009 if (gdk_window_has_impl (window))
2010 impl_class->destroy_foreign (window);
2013 /* Also for historical reasons, we remove any filters
2014 * on a foreign window when it or a parent is destroyed;
2015 * this likely causes problems if two separate portions
2016 * of code are maintaining filter lists on a foreign window.
2018 window_remove_filters (window);
2024 if (window->parent->children)
2025 window->parent->children = g_list_remove (window->parent->children, window);
2028 GDK_WINDOW_IS_MAPPED (window))
2030 recompute_visible_regions (window, TRUE, FALSE);
2031 gdk_window_invalidate_in_parent (window);
2035 gdk_window_free_paint_stack (window);
2037 if (window->background)
2039 cairo_pattern_destroy (window->background);
2040 window->background = NULL;
2043 if (window->window_type == GDK_WINDOW_FOREIGN)
2044 g_assert (window->children == NULL);
2047 children = tmp = window->children;
2048 window->children = NULL;
2052 temp_window = tmp->data;
2056 _gdk_window_destroy_hierarchy (temp_window,
2058 recursing_native || gdk_window_has_impl (window),
2062 g_list_free (children);
2065 _gdk_window_clear_update_area (window);
2067 gdk_window_drop_cairo_surface (window);
2069 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2071 if (gdk_window_has_impl (window))
2072 impl_class->destroy (window, recursing_native,
2076 /* hide to make sure we repaint and break grabs */
2077 gdk_window_hide (window);
2080 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2081 window->parent = NULL;
2082 window->destroyed = TRUE;
2084 window_remove_filters (window);
2086 window_remove_from_pointer_info (window, display);
2088 if (window->clip_region)
2090 cairo_region_destroy (window->clip_region);
2091 window->clip_region = NULL;
2094 if (window->clip_region_with_children)
2096 cairo_region_destroy (window->clip_region_with_children);
2097 window->clip_region_with_children = NULL;
2100 g_list_free_full (window->outstanding_moves, (GDestroyNotify) gdk_window_region_move_free);
2101 window->outstanding_moves = NULL;
2108 * _gdk_window_destroy:
2109 * @window: a #GdkWindow
2110 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2111 * external agency. The window has already been destroyed and no
2112 * windowing system calls should be made. (This may never happen
2113 * for some windowing systems.)
2115 * Internal function to destroy a window. Like gdk_window_destroy(),
2116 * but does not drop the reference count created by gdk_window_new().
2119 _gdk_window_destroy (GdkWindow *window,
2120 gboolean foreign_destroy)
2122 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2126 * gdk_window_destroy:
2127 * @window: a #GdkWindow
2129 * Destroys the window system resources associated with @window and decrements @window's
2130 * reference count. The window system resources for all children of @window are also
2131 * destroyed, but the children's reference counts are not decremented.
2133 * Note that a window will not be destroyed automatically when its reference count
2134 * reaches zero. You must call this function yourself before that happens.
2138 gdk_window_destroy (GdkWindow *window)
2140 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2141 g_object_unref (window);
2145 * gdk_window_set_user_data:
2146 * @window: a #GdkWindow
2147 * @user_data: (allow-none) (type GObject.Object): user data
2149 * For most purposes this function is deprecated in favor of
2150 * g_object_set_data(). However, for historical reasons GTK+ stores
2151 * the #GtkWidget that owns a #GdkWindow as user data on the
2152 * #GdkWindow. So, custom widget implementations should use
2153 * this function for that. If GTK+ receives an event for a #GdkWindow,
2154 * and the user data for the window is non-%NULL, GTK+ will assume the
2155 * user data is a #GtkWidget, and forward the event to that widget.
2159 gdk_window_set_user_data (GdkWindow *window,
2162 g_return_if_fail (GDK_IS_WINDOW (window));
2164 window->user_data = user_data;
2168 * gdk_window_get_user_data:
2169 * @window: a #GdkWindow
2170 * @data: (out): return location for user data
2172 * Retrieves the user data for @window, which is normally the widget
2173 * that @window belongs to. See gdk_window_set_user_data().
2177 gdk_window_get_user_data (GdkWindow *window,
2180 g_return_if_fail (GDK_IS_WINDOW (window));
2182 *data = window->user_data;
2186 * gdk_window_get_window_type:
2187 * @window: a #GdkWindow
2189 * Gets the type of the window. See #GdkWindowType.
2191 * Return value: type of window
2194 gdk_window_get_window_type (GdkWindow *window)
2196 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2198 return GDK_WINDOW_TYPE (window);
2202 * gdk_window_get_visual:
2203 * @window: a #GdkWindow
2205 * Gets the #GdkVisual describing the pixel format of @window.
2207 * Return value: (transfer none): a #GdkVisual
2212 gdk_window_get_visual (GdkWindow *window)
2214 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2216 return window->visual;
2220 * gdk_window_get_screen:
2221 * @window: a #GdkWindow
2223 * Gets the #GdkScreen associated with a #GdkWindow.
2225 * Return value: (transfer none): the #GdkScreen associated with @window
2230 gdk_window_get_screen (GdkWindow *window)
2232 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2234 return gdk_visual_get_screen (window->visual);
2238 * gdk_window_get_display:
2239 * @window: a #GdkWindow
2241 * Gets the #GdkDisplay associated with a #GdkWindow.
2243 * Return value: (transfer none): the #GdkDisplay associated with @window
2248 gdk_window_get_display (GdkWindow *window)
2250 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2252 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2255 * gdk_window_is_destroyed:
2256 * @window: a #GdkWindow
2258 * Check to see if a window is destroyed..
2260 * Return value: %TRUE if the window is destroyed
2265 gdk_window_is_destroyed (GdkWindow *window)
2267 return GDK_WINDOW_DESTROYED (window);
2271 to_embedder (GdkWindow *window,
2272 gdouble offscreen_x,
2273 gdouble offscreen_y,
2274 gdouble *embedder_x,
2275 gdouble *embedder_y)
2277 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2278 offscreen_x, offscreen_y,
2279 embedder_x, embedder_y);
2283 from_embedder (GdkWindow *window,
2286 gdouble *offscreen_x,
2287 gdouble *offscreen_y)
2289 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2290 embedder_x, embedder_y,
2291 offscreen_x, offscreen_y);
2295 * gdk_window_has_native:
2296 * @window: a #GdkWindow
2298 * Checks whether the window has a native window or not. Note that
2299 * you can use gdk_window_ensure_native() if a native window is needed.
2301 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2306 gdk_window_has_native (GdkWindow *window)
2308 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2310 return window->parent == NULL || window->parent->impl != window->impl;
2314 * gdk_window_get_position:
2315 * @window: a #GdkWindow
2316 * @x: (out) (allow-none): X coordinate of window
2317 * @y: (out) (allow-none): Y coordinate of window
2319 * Obtains the position of the window as reported in the
2320 * most-recently-processed #GdkEventConfigure. Contrast with
2321 * gdk_window_get_geometry() which queries the X server for the
2322 * current window position, regardless of which events have been
2323 * received or processed.
2325 * The position coordinates are relative to the window's parent window.
2329 gdk_window_get_position (GdkWindow *window,
2333 g_return_if_fail (GDK_IS_WINDOW (window));
2342 * gdk_window_get_parent:
2343 * @window: a #GdkWindow
2345 * Obtains the parent of @window, as known to GDK. Does not query the
2346 * X server; thus this returns the parent as passed to gdk_window_new(),
2347 * not the actual parent. This should never matter unless you're using
2348 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2349 * matter for toplevel windows, because the window manager may choose
2352 * Note that you should use gdk_window_get_effective_parent() when
2353 * writing generic code that walks up a window hierarchy, because
2354 * gdk_window_get_parent() will most likely not do what you expect if
2355 * there are offscreen windows in the hierarchy.
2357 * Return value: (transfer none): parent of @window
2360 gdk_window_get_parent (GdkWindow *window)
2362 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2364 return window->parent;
2368 * gdk_window_get_effective_parent:
2369 * @window: a #GdkWindow
2371 * Obtains the parent of @window, as known to GDK. Works like
2372 * gdk_window_get_parent() for normal windows, but returns the
2373 * window's embedder for offscreen windows.
2375 * See also: gdk_offscreen_window_get_embedder()
2377 * Return value: (transfer none): effective parent of @window
2382 gdk_window_get_effective_parent (GdkWindow *window)
2384 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2386 if (gdk_window_is_offscreen (window))
2387 return gdk_offscreen_window_get_embedder (window);
2389 return window->parent;
2393 * gdk_window_get_toplevel:
2394 * @window: a #GdkWindow
2396 * Gets the toplevel window that's an ancestor of @window.
2398 * Any window type but %GDK_WINDOW_CHILD is considered a
2399 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2400 * has a root window as parent.
2402 * Note that you should use gdk_window_get_effective_toplevel() when
2403 * you want to get to a window's toplevel as seen on screen, because
2404 * gdk_window_get_toplevel() will most likely not do what you expect
2405 * if there are offscreen windows in the hierarchy.
2407 * Return value: (transfer none): the toplevel window containing @window
2410 gdk_window_get_toplevel (GdkWindow *window)
2412 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2414 while (window->window_type == GDK_WINDOW_CHILD)
2416 if (gdk_window_is_toplevel (window))
2418 window = window->parent;
2425 * gdk_window_get_effective_toplevel:
2426 * @window: a #GdkWindow
2428 * Gets the toplevel window that's an ancestor of @window.
2430 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2431 * embedder as its parent, using gdk_window_get_effective_parent().
2433 * See also: gdk_offscreen_window_get_embedder()
2435 * Return value: (transfer none): the effective toplevel window containing @window
2440 gdk_window_get_effective_toplevel (GdkWindow *window)
2444 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2446 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2447 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2454 * gdk_window_get_children:
2455 * @window: a #GdkWindow
2457 * Gets the list of children of @window known to GDK.
2458 * This function only returns children created via GDK,
2459 * so for example it's useless when used with the root window;
2460 * it only returns windows an application created itself.
2462 * The returned list must be freed, but the elements in the
2465 * Return value: (transfer container) (element-type GdkWindow):
2466 * list of child windows inside @window
2469 gdk_window_get_children (GdkWindow *window)
2471 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2473 if (GDK_WINDOW_DESTROYED (window))
2476 return g_list_copy (window->children);
2480 * gdk_window_peek_children:
2481 * @window: a #GdkWindow
2483 * Like gdk_window_get_children(), but does not copy the list of
2484 * children, so the list does not need to be freed.
2486 * Return value: (transfer none) (element-type GdkWindow):
2487 * a reference to the list of child windows in @window
2490 gdk_window_peek_children (GdkWindow *window)
2492 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2494 if (GDK_WINDOW_DESTROYED (window))
2497 return window->children;
2501 * gdk_window_add_filter: (skip)
2502 * @window: (allow-none): a #GdkWindow
2503 * @function: filter callback
2504 * @data: data to pass to filter callback
2506 * Adds an event filter to @window, allowing you to intercept events
2507 * before they reach GDK. This is a low-level operation and makes it
2508 * easy to break GDK and/or GTK+, so you have to know what you're
2509 * doing. Pass %NULL for @window to get all events for all windows,
2510 * instead of events for a specific window.
2512 * If you are interested in X GenericEvents, bear in mind that
2513 * XGetEventData() has been already called on the event, and
2514 * XFreeEventData() must not be called within @function.
2517 gdk_window_add_filter (GdkWindow *window,
2518 GdkFilterFunc function,
2522 GdkEventFilter *filter;
2524 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2526 if (window && GDK_WINDOW_DESTROYED (window))
2529 /* Filters are for the native events on the native window, so
2530 ensure there is a native window. */
2532 gdk_window_ensure_native (window);
2535 tmp_list = window->filters;
2537 tmp_list = _gdk_default_filters;
2541 filter = (GdkEventFilter *)tmp_list->data;
2542 if ((filter->function == function) && (filter->data == data))
2544 filter->ref_count++;
2547 tmp_list = tmp_list->next;
2550 filter = g_new (GdkEventFilter, 1);
2551 filter->function = function;
2552 filter->data = data;
2553 filter->ref_count = 1;
2557 window->filters = g_list_append (window->filters, filter);
2559 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2563 * gdk_window_remove_filter: (skip)
2564 * @window: a #GdkWindow
2565 * @function: previously-added filter function
2566 * @data: user data for previously-added filter function
2568 * Remove a filter previously added with gdk_window_add_filter().
2571 gdk_window_remove_filter (GdkWindow *window,
2572 GdkFilterFunc function,
2576 GdkEventFilter *filter;
2578 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2581 tmp_list = window->filters;
2583 tmp_list = _gdk_default_filters;
2587 filter = (GdkEventFilter *)tmp_list->data;
2588 tmp_list = tmp_list->next;
2590 if ((filter->function == function) && (filter->data == data))
2592 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2594 _gdk_event_filter_unref (window, filter);
2602 * gdk_screen_get_toplevel_windows:
2603 * @screen: The #GdkScreen where the toplevels are located.
2605 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2606 * A toplevel window is a child of the root window (see
2607 * gdk_get_default_root_window()).
2609 * The returned list should be freed with g_list_free(), but
2610 * its elements need not be freed.
2612 * Return value: (transfer container) (element-type GdkWindow):
2613 * list of toplevel windows, free with g_list_free()
2618 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2620 GdkWindow * root_window;
2621 GList *new_list = NULL;
2624 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2626 root_window = gdk_screen_get_root_window (screen);
2628 tmp_list = root_window->children;
2631 GdkWindow *w = tmp_list->data;
2633 if (w->window_type != GDK_WINDOW_FOREIGN)
2634 new_list = g_list_prepend (new_list, w);
2635 tmp_list = tmp_list->next;
2642 * gdk_window_is_visible:
2643 * @window: a #GdkWindow
2645 * Checks whether the window has been mapped (with gdk_window_show() or
2646 * gdk_window_show_unraised()).
2648 * Return value: %TRUE if the window is mapped
2651 gdk_window_is_visible (GdkWindow *window)
2653 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2655 return GDK_WINDOW_IS_MAPPED (window);
2659 * gdk_window_is_viewable:
2660 * @window: a #GdkWindow
2662 * Check if the window and all ancestors of the window are
2663 * mapped. (This is not necessarily "viewable" in the X sense, since
2664 * we only check as far as we have GDK window parents, not to the root
2667 * Return value: %TRUE if the window is viewable
2670 gdk_window_is_viewable (GdkWindow *window)
2672 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2674 if (window->destroyed)
2677 return window->viewable;
2681 * gdk_window_get_state:
2682 * @window: a #GdkWindow
2684 * Gets the bitwise OR of the currently active window state flags,
2685 * from the #GdkWindowState enumeration.
2687 * Return value: window state bitfield
2690 gdk_window_get_state (GdkWindow *window)
2692 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2694 return window->state;
2697 static cairo_content_t
2698 gdk_window_get_content (GdkWindow *window)
2700 cairo_surface_t *surface;
2701 cairo_content_t content;
2703 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2705 surface = gdk_window_ref_impl_surface (window);
2706 content = cairo_surface_get_content (surface);
2707 cairo_surface_destroy (surface);
2712 /* This creates an empty "implicit" paint region for the impl window.
2713 * By itself this does nothing, but real paints to this window
2714 * or children of it can use this surface as backing to avoid allocating
2715 * multiple surfaces for subwindow rendering. When doing so they
2716 * add to the region of the implicit paint region, which will be
2717 * pushed to the window when the implicit paint region is ended.
2718 * Such paints should not copy anything to the window on paint end, but
2719 * should rely on the implicit paint end.
2720 * The implicit paint will be automatically ended if someone draws
2721 * directly to the window or a child window.
2724 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2726 GdkWindowPaint *paint;
2728 g_assert (gdk_window_has_impl (window));
2730 if (GDK_IS_PAINTABLE (window->impl))
2731 return FALSE; /* Implementation does double buffering */
2733 if (window->paint_stack != NULL ||
2734 window->implicit_paint != NULL)
2735 return FALSE; /* Don't stack implicit paints */
2737 /* Never do implicit paints for foreign windows, they don't need
2738 * double buffer combination since they have no client side children,
2739 * and creating surfaces for them is risky since they could disappear
2742 if (window->window_type == GDK_WINDOW_FOREIGN)
2745 paint = g_new (GdkWindowPaint, 1);
2746 paint->region = cairo_region_create (); /* Empty */
2747 paint->uses_implicit = FALSE;
2748 paint->flushed = NULL;
2749 paint->surface = gdk_window_create_similar_surface (window,
2750 gdk_window_get_content (window),
2751 MAX (rect->width, 1),
2752 MAX (rect->height, 1));
2753 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2755 window->implicit_paint = g_slist_prepend (window->implicit_paint, paint);
2760 static cairo_surface_t *
2761 gdk_window_ref_impl_surface (GdkWindow *window)
2763 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2767 gdk_cairo_create_for_impl (GdkWindow *window)
2769 cairo_surface_t *surface;
2772 surface = gdk_window_ref_impl_surface (window);
2773 cr = cairo_create (surface);
2775 cairo_surface_destroy (surface);
2780 /* This is called whenever something is drawing directly to the
2781 * window, bypassing the double buffering. When this happens we
2782 * need to mark any the currently drawn data in the double buffer
2783 * as invalid to avoid later drawing it back over the directly
2784 * rendered pixels. We also need to mark this region as "flushed"
2785 * so that if we later try to paint on it double-buffered we need
2786 * to read back the on-window pixels rather than relying on what
2787 * is in the current double-buffer pixmap.
2789 * Note that this doesn't correctly handle the case where the
2790 * non-double buffered drawing uses transparency and relies on
2791 * what the windows below it draws. A fix for that would require
2792 * drawing the existing double-buffered background to the window,
2793 * but that causes ugly flashes. Non-double buffered drawing is
2794 * typically only used in old code or when the drawed widget
2795 * already has a double-buffering layer, and in these cases the
2796 * pixels are opaque anyway. If you need transparency, don't
2797 * disable double buffering.
2800 gdk_window_flush_implicit_paint (GdkWindow *window)
2802 GdkWindow *impl_window;
2803 GdkWindowPaint *paint;
2804 cairo_region_t *region;
2806 impl_window = gdk_window_get_impl_window (window);
2807 if (impl_window->implicit_paint == NULL)
2810 paint = impl_window->implicit_paint->data;
2812 region = cairo_region_copy (window->clip_region_with_children);
2813 cairo_region_translate (region, window->abs_x, window->abs_y);
2815 /* Anything in the whole flushed window that was drawn is now
2816 considered unpainted, so that we don't push it back at the
2817 end of the implicit paint overwriting the directly rendered
2819 cairo_region_subtract (paint->region, region);
2821 /* Save flushed area so we can read it back if we draw over it later */
2822 if (paint->flushed == NULL)
2823 paint->flushed = region;
2826 cairo_region_union (paint->flushed, region);
2827 cairo_region_destroy (region);
2831 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2833 gdk_window_end_implicit_paint (GdkWindow *window)
2835 GdkWindowPaint *paint;
2837 g_assert (gdk_window_has_impl (window));
2839 g_assert (window->implicit_paint != NULL);
2841 paint = window->implicit_paint->data;
2843 window->implicit_paint = g_slist_delete_link (window->implicit_paint,
2844 window->implicit_paint);
2846 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2850 /* Some regions are valid, push these to window now */
2851 cr = gdk_cairo_create_for_impl (window);
2852 gdk_cairo_region (cr, paint->region);
2854 cairo_set_source_surface (cr, paint->surface, 0, 0);
2855 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2860 cairo_region_destroy (paint->region);
2862 cairo_region_destroy (paint->flushed);
2863 cairo_surface_destroy (paint->surface);
2868 * gdk_window_begin_paint_rect:
2869 * @window: a #GdkWindow
2870 * @rectangle: rectangle you intend to draw to
2872 * A convenience wrapper around gdk_window_begin_paint_region() which
2873 * creates a rectangular region for you. See
2874 * gdk_window_begin_paint_region() for details.
2878 gdk_window_begin_paint_rect (GdkWindow *window,
2879 const GdkRectangle *rectangle)
2881 cairo_region_t *region;
2883 g_return_if_fail (GDK_IS_WINDOW (window));
2885 region = cairo_region_create_rectangle (rectangle);
2886 gdk_window_begin_paint_region (window, region);
2887 cairo_region_destroy (region);
2891 * gdk_window_begin_paint_region:
2892 * @window: a #GdkWindow
2893 * @region: region you intend to draw to
2895 * Indicates that you are beginning the process of redrawing @region.
2896 * A backing store (offscreen buffer) large enough to contain @region
2897 * will be created. The backing store will be initialized with the
2898 * background color or background surface for @window. Then, all
2899 * drawing operations performed on @window will be diverted to the
2900 * backing store. When you call gdk_window_end_paint(), the backing
2901 * store will be copied to @window, making it visible onscreen. Only
2902 * the part of @window contained in @region will be modified; that is,
2903 * drawing operations are clipped to @region.
2905 * The net result of all this is to remove flicker, because the user
2906 * sees the finished product appear all at once when you call
2907 * gdk_window_end_paint(). If you draw to @window directly without
2908 * calling gdk_window_begin_paint_region(), the user may see flicker
2909 * as individual drawing operations are performed in sequence. The
2910 * clipping and background-initializing features of
2911 * gdk_window_begin_paint_region() are conveniences for the
2912 * programmer, so you can avoid doing that work yourself.
2914 * When using GTK+, the widget system automatically places calls to
2915 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2916 * emissions of the expose_event signal. That is, if you're writing an
2917 * expose event handler, you can assume that the exposed area in
2918 * #GdkEventExpose has already been cleared to the window background,
2919 * is already set as the clip region, and already has a backing store.
2920 * Therefore in most cases, application code need not call
2921 * gdk_window_begin_paint_region(). (You can disable the automatic
2922 * calls around expose events on a widget-by-widget basis by calling
2923 * gtk_widget_set_double_buffered().)
2925 * If you call this function multiple times before calling the
2926 * matching gdk_window_end_paint(), the backing stores are pushed onto
2927 * a stack. gdk_window_end_paint() copies the topmost backing store
2928 * onscreen, subtracts the topmost region from all other regions in
2929 * the stack, and pops the stack. All drawing operations affect only
2930 * the topmost backing store in the stack. One matching call to
2931 * gdk_window_end_paint() is required for each call to
2932 * gdk_window_begin_paint_region().
2936 gdk_window_begin_paint_region (GdkWindow *window,
2937 const cairo_region_t *region)
2939 #ifdef USE_BACKING_STORE
2940 GdkRectangle clip_box;
2941 GdkWindowPaint *paint, *implicit_paint;
2942 GdkWindow *impl_window;
2945 g_return_if_fail (GDK_IS_WINDOW (window));
2947 if (GDK_WINDOW_DESTROYED (window))
2950 if (GDK_IS_PAINTABLE (window->impl))
2952 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2954 if (iface->begin_paint_region)
2955 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2960 impl_window = gdk_window_get_impl_window (window);
2961 implicit_paint = impl_window->implicit_paint != NULL ? impl_window->implicit_paint->data : NULL;
2963 paint = g_new (GdkWindowPaint, 1);
2964 paint->region = cairo_region_copy (region);
2966 cairo_region_intersect (paint->region, window->clip_region_with_children);
2967 cairo_region_get_extents (paint->region, &clip_box);
2969 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2971 /* Mark the region as valid on the implicit paint */
2974 cairo_region_union (implicit_paint->region, paint->region);
2976 /* Convert back to normal coords */
2977 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2981 paint->uses_implicit = TRUE;
2982 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2983 window->abs_x + clip_box.x,
2984 window->abs_y + clip_box.y,
2985 MAX (clip_box.width, 1),
2986 MAX (clip_box.height, 1));
2990 paint->uses_implicit = FALSE;
2991 paint->surface = gdk_window_create_similar_surface (window,
2992 gdk_window_get_content (window),
2993 MAX (clip_box.width, 1),
2994 MAX (clip_box.height, 1));
2997 /* Normally alpha backgrounded client side windows are composited on the implicit paint
2998 by being drawn in back to front order. However, if implicit paints are not used, for
2999 instance if it was flushed due to a non-double-buffered paint in the middle of the
3000 expose we need to copy in the existing data here. */
3001 if (gdk_window_has_alpha (window) &&
3003 (implicit_paint && implicit_paint->flushed != NULL && !cairo_region_is_empty (implicit_paint->flushed))))
3005 cairo_t *cr = cairo_create (paint->surface);
3006 /* We can't use gdk_cairo_set_source_window here, as that might
3007 flush the implicit paint at an unfortunate time, since this
3008 would be detected as a draw during non-expose time */
3009 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (impl_window);
3010 cairo_set_source_surface (cr, source_surface,
3011 - (window->abs_x + clip_box.x),
3012 - (window->abs_y + clip_box.y));
3013 cairo_surface_destroy (source_surface);
3015 /* Only read back the flushed area if any */
3018 cairo_region_t *flushed = cairo_region_copy (implicit_paint->flushed);
3019 /* Convert from impl coords */
3020 cairo_region_translate (flushed, -window->abs_x, -window->abs_y);
3021 cairo_region_intersect (flushed, paint->region);
3022 gdk_cairo_region (cr, flushed);
3025 /* Convert to impl coords */
3026 cairo_region_translate (flushed, window->abs_x, window->abs_y);
3027 cairo_region_subtract (implicit_paint->flushed, flushed);
3028 cairo_region_destroy (flushed);
3034 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3036 for (list = window->paint_stack; list != NULL; list = list->next)
3038 GdkWindowPaint *tmp_paint = list->data;
3040 cairo_region_subtract (tmp_paint->region, paint->region);
3043 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
3045 if (!cairo_region_is_empty (paint->region))
3047 gdk_window_clear_backing_region (window,
3051 #endif /* USE_BACKING_STORE */
3055 * gdk_window_end_paint:
3056 * @window: a #GdkWindow
3058 * Indicates that the backing store created by the most recent call to
3059 * gdk_window_begin_paint_region() should be copied onscreen and
3060 * deleted, leaving the next-most-recent backing store or no backing
3061 * store at all as the active paint region. See
3062 * gdk_window_begin_paint_region() for full details. It is an error to
3063 * call this function without a matching
3064 * gdk_window_begin_paint_region() first.
3068 gdk_window_end_paint (GdkWindow *window)
3070 #ifdef USE_BACKING_STORE
3071 GdkWindow *composited;
3072 GdkWindowPaint *paint;
3073 GdkRectangle clip_box;
3074 cairo_region_t *full_clip;
3076 g_return_if_fail (GDK_IS_WINDOW (window));
3078 if (GDK_WINDOW_DESTROYED (window))
3081 if (GDK_IS_PAINTABLE (window->impl))
3083 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3085 if (iface->end_paint)
3086 iface->end_paint ((GdkPaintable*)window->impl);
3090 if (window->paint_stack == NULL)
3092 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3096 paint = window->paint_stack->data;
3098 window->paint_stack = g_slist_delete_link (window->paint_stack,
3099 window->paint_stack);
3101 cairo_region_get_extents (paint->region, &clip_box);
3103 if (!paint->uses_implicit)
3107 gdk_window_flush_outstanding_moves (window);
3109 full_clip = cairo_region_copy (window->clip_region_with_children);
3110 cairo_region_intersect (full_clip, paint->region);
3112 cr = gdk_cairo_create (window);
3113 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3114 cairo_set_source_surface (cr, paint->surface, 0, 0);
3115 gdk_cairo_region (cr, full_clip);
3119 cairo_region_destroy (full_clip);
3122 cairo_surface_destroy (paint->surface);
3123 cairo_region_destroy (paint->region);
3126 /* find a composited window in our hierarchy to signal its
3127 * parent to redraw, calculating the clip box as we go...
3129 * stop if parent becomes NULL since then we'd have nowhere
3130 * to draw (ie: 'composited' will always be non-NULL here).
3132 for (composited = window;
3134 composited = composited->parent)
3136 clip_box.x += composited->x;
3137 clip_box.y += composited->y;
3138 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3139 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3141 if (composited->composited)
3143 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3148 #endif /* USE_BACKING_STORE */
3152 gdk_window_free_paint_stack (GdkWindow *window)
3154 if (window->paint_stack)
3156 GSList *tmp_list = window->paint_stack;
3160 GdkWindowPaint *paint = tmp_list->data;
3162 if (tmp_list == window->paint_stack)
3163 cairo_surface_destroy (paint->surface);
3165 cairo_region_destroy (paint->region);
3168 tmp_list = tmp_list->next;
3171 g_slist_free (window->paint_stack);
3172 window->paint_stack = NULL;
3177 do_move_region_bits_on_impl (GdkWindow *impl_window,
3178 cairo_region_t *dest_region, /* In impl window coords */
3181 GdkWindowImplClass *impl_class;
3183 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3185 impl_class->translate (impl_window, dest_region, dx, dy);
3188 static GdkWindowRegionMove *
3189 gdk_window_region_move_new (cairo_region_t *region,
3192 GdkWindowRegionMove *move;
3194 move = g_slice_new (GdkWindowRegionMove);
3195 move->dest_region = cairo_region_copy (region);
3203 gdk_window_region_move_free (GdkWindowRegionMove *move)
3205 cairo_region_destroy (move->dest_region);
3206 g_slice_free (GdkWindowRegionMove, move);
3210 append_move_region (GdkWindow *impl_window,
3211 cairo_region_t *new_dest_region,
3214 GdkWindowRegionMove *move, *old_move;
3215 cairo_region_t *new_total_region, *old_total_region;
3216 cairo_region_t *source_overlaps_destination;
3217 cairo_region_t *non_overwritten;
3218 gboolean added_move;
3221 if (cairo_region_is_empty (new_dest_region))
3224 /* In principle this could just append the move to the list of outstanding
3225 moves that will be replayed before drawing anything when we're handling
3226 exposes. However, we'd like to do a bit better since its commonly the case
3227 that we get multiple copies where A is copied to B and then B is copied
3228 to C, and we'd like to express this as a simple copy A to C operation. */
3230 /* We approach this by taking the new move and pushing it ahead of moves
3231 starting at the end of the list and stopping when its not safe to do so.
3232 It's not safe to push past a move if either the source of the new move
3233 is in the destination of the old move, or if the destination of the new
3234 move is in the source of the new move, or if the destination of the new
3235 move overlaps the destination of the old move. We simplify this by
3236 just comparing the total regions (src + dest) */
3237 new_total_region = cairo_region_copy (new_dest_region);
3238 cairo_region_translate (new_total_region, -dx, -dy);
3239 cairo_region_union (new_total_region, new_dest_region);
3242 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3247 old_total_region = cairo_region_copy (old_move->dest_region);
3248 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3249 cairo_region_union (old_total_region, old_move->dest_region);
3251 cairo_region_intersect (old_total_region, new_total_region);
3252 /* If these regions intersect then its not safe to push the
3253 new region before the old one */
3254 if (!cairo_region_is_empty (old_total_region))
3256 /* The area where the new moves source overlaps the old ones
3258 source_overlaps_destination = cairo_region_copy (new_dest_region);
3259 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3260 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3261 cairo_region_translate (source_overlaps_destination, dx, dy);
3263 /* We can do all sort of optimizations here, but to do things safely it becomes
3264 quite complicated. However, a very common case is that you copy something first,
3265 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3266 in the same direction). We'd like to detect this case and optimize it to one
3268 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3270 /* This means we might be able to replace the old move and the new one
3271 with the new one read from the old ones source, and a second copy of
3272 the non-overwritten parts of the old move. However, such a split
3273 is only valid if the source in the old move isn't overwritten
3274 by the destination of the new one */
3276 /* the new destination of old move if split is ok: */
3277 non_overwritten = cairo_region_copy (old_move->dest_region);
3278 cairo_region_subtract (non_overwritten, new_dest_region);
3279 /* move to source region */
3280 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3282 cairo_region_intersect (non_overwritten, new_dest_region);
3283 if (cairo_region_is_empty (non_overwritten))
3286 move = gdk_window_region_move_new (new_dest_region,
3290 impl_window->outstanding_moves =
3291 g_list_insert_before (impl_window->outstanding_moves,
3293 cairo_region_subtract (old_move->dest_region, new_dest_region);
3295 cairo_region_destroy (non_overwritten);
3298 cairo_region_destroy (source_overlaps_destination);
3299 cairo_region_destroy (old_total_region);
3302 cairo_region_destroy (old_total_region);
3305 cairo_region_destroy (new_total_region);
3309 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3312 impl_window->outstanding_moves =
3313 g_list_prepend (impl_window->outstanding_moves,
3316 impl_window->outstanding_moves =
3317 g_list_insert_before (impl_window->outstanding_moves,
3322 /* Moves bits and update area by dx/dy in impl window.
3323 Takes ownership of region to avoid copy (because we may change it) */
3325 move_region_on_impl (GdkWindow *impl_window,
3326 cairo_region_t *region, /* In impl window coords */
3331 if ((dx == 0 && dy == 0) ||
3332 cairo_region_is_empty (region))
3334 cairo_region_destroy (region);
3338 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3340 /* Move any old invalid regions in the copy source area by dx/dy */
3341 if (impl_window->update_area)
3343 cairo_region_t *update_area;
3345 update_area = cairo_region_copy (region);
3347 /* Convert from target to source */
3348 cairo_region_translate (update_area, -dx, -dy);
3349 cairo_region_intersect (update_area, impl_window->update_area);
3350 /* We only copy the area, so keep the old update area invalid.
3351 It would be safe to remove it too, as code that uses
3352 move_region_on_impl generally also invalidate the source
3353 area. However, it would just use waste cycles. */
3356 cairo_region_translate (update_area, dx, dy);
3357 cairo_region_union (impl_window->update_area, update_area);
3359 /* This area of the destination is now invalid,
3360 so no need to copy to it. */
3361 cairo_region_subtract (region, update_area);
3363 cairo_region_destroy (update_area);
3366 /* If we're currently exposing this window, don't copy to this
3367 destination, as it will be overdrawn when the expose is done,
3368 instead invalidate it and repaint later. */
3369 for (l = impl_window->implicit_paint; l != NULL; l = l->next)
3371 GdkWindowPaint *implicit_paint = l->data;
3372 cairo_region_t *exposing;
3374 exposing = cairo_region_copy (implicit_paint->region);
3375 cairo_region_intersect (exposing, region);
3376 cairo_region_subtract (region, exposing);
3378 impl_window_add_update_area (impl_window, exposing);
3379 cairo_region_destroy (exposing);
3382 append_move_region (impl_window, region, dx, dy);
3384 cairo_region_destroy (region);
3387 /* Flushes all outstanding changes to the window, call this
3388 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3391 gdk_window_flush_outstanding_moves (GdkWindow *window)
3393 GdkWindow *impl_window;
3394 GList *l, *outstanding;
3395 GdkWindowRegionMove *move;
3397 impl_window = gdk_window_get_impl_window (window);
3398 outstanding = impl_window->outstanding_moves;
3399 impl_window->outstanding_moves = NULL;
3401 for (l = outstanding; l != NULL; l = l->next)
3405 do_move_region_bits_on_impl (impl_window,
3406 move->dest_region, move->dx, move->dy);
3408 gdk_window_region_move_free (move);
3411 g_list_free (outstanding);
3416 * @window: a #GdkWindow
3418 * Flush all outstanding cached operations on a window, leaving the
3419 * window in a state which reflects all that has been drawn before.
3421 * Gdk uses multiple kinds of caching to get better performance and
3422 * nicer drawing. For instance, during exposes all paints to a window
3423 * using double buffered rendering are keep on a surface until the last
3424 * window has been exposed. It also delays window moves/scrolls until
3425 * as long as possible until next update to avoid tearing when moving
3428 * Normally this should be completely invisible to applications, as
3429 * we automatically flush the windows when required, but this might
3430 * be needed if you for instance mix direct native drawing with
3431 * gdk drawing. For Gtk widgets that don't use double buffering this
3432 * will be called automatically before sending the expose event.
3437 gdk_window_flush (GdkWindow *window)
3439 gdk_window_flush_outstanding_moves (window);
3440 gdk_window_flush_implicit_paint (window);
3444 gdk_window_flush_recursive_helper (GdkWindow *window,
3445 GdkWindowImpl *impl)
3450 for (l = window->children; l != NULL; l = l->next)
3454 if (child->impl == impl)
3455 /* Same impl, ignore */
3456 gdk_window_flush_recursive_helper (child, impl);
3458 gdk_window_flush_recursive (child);
3463 gdk_window_flush_recursive (GdkWindow *window)
3465 gdk_window_flush (window);
3466 gdk_window_flush_recursive_helper (window, window->impl);
3470 * gdk_window_get_clip_region:
3471 * @window: a #GdkWindow
3473 * Computes the region of a window that potentially can be written
3474 * to by drawing primitives. This region may not take into account
3475 * other factors such as if the window is obscured by other windows,
3476 * but no area outside of this region will be affected by drawing
3479 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3480 * when you are done.
3483 gdk_window_get_clip_region (GdkWindow *window)
3485 cairo_region_t *result;
3487 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3489 result = cairo_region_copy (window->clip_region);
3491 if (window->paint_stack)
3493 cairo_region_t *paint_region = cairo_region_create ();
3494 GSList *tmp_list = window->paint_stack;
3498 GdkWindowPaint *paint = tmp_list->data;
3500 cairo_region_union (paint_region, paint->region);
3502 tmp_list = tmp_list->next;
3505 cairo_region_intersect (result, paint_region);
3506 cairo_region_destroy (paint_region);
3513 * gdk_window_get_visible_region:
3514 * @window: a #GdkWindow
3516 * Computes the region of the @window that is potentially visible.
3517 * This does not necessarily take into account if the window is
3518 * obscured by other windows, but no area outside of this region
3521 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3522 * when you are done.
3525 gdk_window_get_visible_region (GdkWindow *window)
3527 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3529 return cairo_region_copy (window->clip_region);
3533 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint)
3535 GdkWindow *bg_window;
3536 cairo_pattern_t *pattern = NULL;
3537 int x_offset = 0, y_offset = 0;
3540 cr = cairo_create (paint->surface);
3542 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3544 pattern = gdk_window_get_background_pattern (bg_window);
3548 x_offset += bg_window->x;
3549 y_offset += bg_window->y;
3554 cairo_translate (cr, -x_offset, -y_offset);
3555 cairo_set_source (cr, pattern);
3556 cairo_translate (cr, x_offset, y_offset);
3559 cairo_set_source_rgb (cr, 0, 0, 0);
3565 gdk_window_clear_backing_region (GdkWindow *window,
3566 cairo_region_t *region)
3568 GdkWindowPaint *paint = window->paint_stack->data;
3569 cairo_region_t *clip;
3572 if (GDK_WINDOW_DESTROYED (window))
3575 cr = setup_backing_rect (window, paint);
3577 clip = cairo_region_copy (paint->region);
3578 cairo_region_intersect (clip, region);
3580 gdk_cairo_region (cr, clip);
3585 cairo_region_destroy (clip);
3589 gdk_window_drop_cairo_surface (GdkWindow *window)
3591 if (window->cairo_surface)
3593 cairo_surface_finish (window->cairo_surface);
3594 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3596 window->cairo_surface = NULL;
3601 gdk_window_cairo_surface_destroy (void *data)
3603 GdkWindow *window = data;
3605 window->cairo_surface = NULL;
3608 static cairo_surface_t *
3609 gdk_window_create_cairo_surface (GdkWindow *window,
3613 cairo_surface_t *surface, *subsurface;
3615 surface = gdk_window_ref_impl_surface (window);
3616 if (gdk_window_has_impl (window))
3619 subsurface = cairo_surface_create_for_rectangle (surface,
3624 cairo_surface_destroy (surface);
3630 _gdk_window_ref_cairo_surface (GdkWindow *window)
3632 cairo_surface_t *surface;
3634 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3636 if (window->paint_stack)
3638 GdkWindowPaint *paint = window->paint_stack->data;
3640 surface = paint->surface;
3641 cairo_surface_reference (surface);
3646 /* This will be drawing directly to the window, so flush implicit paint */
3647 gdk_window_flush (window);
3649 if (!window->cairo_surface)
3651 window->cairo_surface = gdk_window_create_cairo_surface (window,
3655 if (window->cairo_surface)
3657 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3658 window, gdk_window_cairo_surface_destroy);
3662 cairo_surface_reference (window->cairo_surface);
3664 surface = window->cairo_surface;
3672 * @window: a #GdkWindow
3674 * Creates a Cairo context for drawing to @window.
3677 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3678 * produce undefined results, so avoid it at all costs.
3681 * Return value: A newly created Cairo context. Free with
3682 * cairo_destroy() when you are done drawing.
3687 gdk_cairo_create (GdkWindow *window)
3689 cairo_surface_t *surface;
3692 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3694 surface = _gdk_window_ref_cairo_surface (window);
3695 cr = cairo_create (surface);
3697 if (!window->paint_stack)
3699 gdk_cairo_region (cr, window->clip_region_with_children);
3704 GdkWindowPaint *paint = window->paint_stack->data;
3706 /* Only needs to clip to region if piggybacking
3707 on an implicit paint */
3708 if (paint->uses_implicit)
3710 gdk_cairo_region (cr, paint->region);
3715 cairo_surface_destroy (surface);
3720 /* Code for dirty-region queueing
3722 static GSList *update_windows = NULL;
3723 static guint update_idle = 0;
3724 static gboolean debug_updates = FALSE;
3726 static inline gboolean
3727 gdk_window_is_ancestor (GdkWindow *window,
3728 GdkWindow *ancestor)
3732 GdkWindow *parent = window->parent;
3734 if (parent == ancestor)
3744 gdk_window_add_update_window (GdkWindow *window)
3747 GSList *prev = NULL;
3748 gboolean has_ancestor_in_list = FALSE;
3750 for (tmp = update_windows; tmp; tmp = tmp->next)
3752 GdkWindow *parent = window->parent;
3754 /* check if tmp is an ancestor of "window"; if it is, set a
3755 * flag indicating that all following windows are either
3756 * children of "window" or from a differen hierarchy
3758 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3759 has_ancestor_in_list = TRUE;
3761 /* insert in reverse stacking order when adding around siblings,
3762 * so processing updates properly paints over lower stacked windows
3764 if (parent == GDK_WINDOW (tmp->data)->parent)
3766 gint index = g_list_index (parent->children, window);
3767 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3769 gint sibling_index = g_list_index (parent->children, tmp->data);
3770 if (index > sibling_index)
3774 /* here, tmp got advanced past all lower stacked siblings */
3775 tmp = g_slist_prepend (tmp, window);
3779 update_windows = tmp;
3783 /* if "window" has an ancestor in the list and tmp is one of
3784 * "window's" children, insert "window" before tmp
3786 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3788 tmp = g_slist_prepend (tmp, window);
3793 update_windows = tmp;
3797 /* if we're at the end of the list and had an ancestor it it,
3798 * append to the list
3800 if (! tmp->next && has_ancestor_in_list)
3802 tmp = g_slist_append (tmp, window);
3809 /* if all above checks failed ("window" is from a different
3810 * hierarchy than what is already in the list) or the list is
3813 update_windows = g_slist_prepend (update_windows, window);
3817 gdk_window_remove_update_window (GdkWindow *window)
3819 update_windows = g_slist_remove (update_windows, window);
3823 gdk_window_update_idle (gpointer data)
3825 gdk_window_process_all_updates ();
3831 gdk_window_is_toplevel_frozen (GdkWindow *window)
3833 GdkWindow *toplevel;
3835 toplevel = gdk_window_get_toplevel (window);
3837 return toplevel->update_and_descendants_freeze_count > 0;
3841 gdk_window_schedule_update (GdkWindow *window)
3844 (window->update_freeze_count ||
3845 gdk_window_is_toplevel_frozen (window)))
3850 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3851 gdk_window_update_idle,
3856 _gdk_window_process_updates_recurse (GdkWindow *window,
3857 cairo_region_t *expose_region)
3860 cairo_region_t *clipped_expose_region;
3861 GList *l, *children;
3863 if (cairo_region_is_empty (expose_region))
3866 if (gdk_window_is_offscreen (window->impl_window) &&
3867 gdk_window_has_impl (window))
3868 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3871 /* Paint the window before the children, clipped to the window region
3872 with visible child windows removed */
3873 clipped_expose_region = cairo_region_copy (expose_region);
3874 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3876 if (!cairo_region_is_empty (clipped_expose_region) &&
3879 if (window->event_mask & GDK_EXPOSURE_MASK)
3883 event.expose.type = GDK_EXPOSE;
3884 event.expose.window = g_object_ref (window);
3885 event.expose.send_event = FALSE;
3886 event.expose.count = 0;
3887 event.expose.region = clipped_expose_region;
3888 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
3890 _gdk_event_emit (&event);
3892 g_object_unref (window);
3894 else if (window->window_type != GDK_WINDOW_FOREIGN)
3896 /* No exposure mask set, so nothing will be drawn, the
3897 * app relies on the background being what it specified
3898 * for the window. So, we need to clear this manually.
3900 * For foreign windows if expose is not set that generally
3901 * means some other client paints them, so don't clear
3904 * We use begin/end_paint around the clear so that we can
3905 * piggyback on the implicit paint */
3907 gdk_window_begin_paint_region (window, clipped_expose_region);
3908 /* The actual clear happens in begin_paint_region */
3909 gdk_window_end_paint (window);
3912 cairo_region_destroy (clipped_expose_region);
3914 /* Make this reentrancy safe for expose handlers freeing windows */
3915 children = g_list_copy (window->children);
3916 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3918 /* Iterate over children, starting at bottommost */
3919 for (l = g_list_last (children); l != NULL; l = l->prev)
3923 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3926 /* Ignore offscreen children, as they don't draw in their parent and
3927 * don't take part in the clipping */
3928 if (gdk_window_is_offscreen (child))
3931 /* Client side child, expose */
3932 if (child->impl == window->impl)
3934 cairo_region_translate (expose_region, -child->x, -child->y);
3935 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
3936 cairo_region_translate (expose_region, child->x, child->y);
3940 g_list_free_full (children, g_object_unref);
3944 /* Process and remove any invalid area on the native window by creating
3945 * expose events for the window and all non-native descendants.
3946 * Also processes any outstanding moves on the window before doing
3947 * any drawing. Note that its possible to have outstanding moves without
3948 * any invalid area as we use the update idle mechanism to coalesce
3949 * multiple moves as well as multiple invalidations.
3952 gdk_window_process_updates_internal (GdkWindow *window)
3954 GdkWindowImplClass *impl_class;
3955 gboolean save_region = FALSE;
3956 GdkRectangle clip_box;
3958 /* Ensure the window lives while updating it */
3959 g_object_ref (window);
3961 /* If an update got queued during update processing, we can get a
3962 * window in the update queue that has an empty update_area.
3965 if (window->update_area)
3967 cairo_region_t *update_area = window->update_area;
3968 window->update_area = NULL;
3970 if (gdk_window_is_viewable (window))
3972 cairo_region_t *expose_region;
3973 gboolean end_implicit;
3975 /* Clip to part visible in toplevel */
3976 cairo_region_intersect (update_area, window->clip_region);
3980 /* Make sure we see the red invalid area before redrawing. */
3981 gdk_display_sync (gdk_window_get_display (window));
3985 /* At this point we will be completely redrawing all of update_area.
3986 * If we have any outstanding moves that end up moving stuff inside
3987 * this area we don't actually need to move that as that part would
3988 * be overdrawn by the expose anyway. So, in order to copy less data
3989 * we remove these areas from the outstanding moves.
3991 if (window->outstanding_moves)
3993 GdkWindowRegionMove *move;
3994 cairo_region_t *remove;
3997 remove = cairo_region_copy (update_area);
3998 /* We iterate backwards, starting from the state that would be
3999 if we had applied all the moves. */
4000 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
4005 /* Don't need this area */
4006 cairo_region_subtract (move->dest_region, remove);
4008 /* However if any of the destination we do need has a source
4009 in the updated region we do need that as a destination for
4010 the earlier moves */
4011 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4012 cairo_region_subtract (remove, move->dest_region);
4014 if (cairo_region_is_empty (move->dest_region))
4016 gdk_window_region_move_free (move);
4017 window->outstanding_moves =
4018 g_list_delete_link (window->outstanding_moves, l);
4020 else /* move back */
4021 cairo_region_translate (move->dest_region, move->dx, move->dy);
4023 cairo_region_destroy (remove);
4026 /* By now we a set of window moves that should be applied, and then
4027 * an update region that should be repainted. A trivial implementation
4028 * would just do that in order, however in order to get nicer drawing
4029 * we do some tricks:
4031 * First of all, each subwindow expose may be double buffered by
4032 * itself (depending on widget setting) via
4033 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4034 * creating a single surface the size of the invalid area on the
4035 * native window which all the individual normal paints will draw
4036 * into. This way in the normal case there will be only one surface
4037 * allocated and only once surface draw done for all the windows
4038 * in this native window.
4039 * There are a couple of reasons this may fail, for instance, some
4040 * backends (like quartz) do its own double buffering, so we disable
4041 * gdk double buffering there. Secondly, some subwindow could be
4042 * non-double buffered and draw directly to the window outside a
4043 * begin/end_paint pair. That will be lead to a gdk_window_flush
4044 * which immediately executes all outstanding moves and paints+removes
4045 * the implicit paint (further paints will allocate their own surfaces).
4047 * Secondly, in the case of implicit double buffering we expose all
4048 * the child windows into the implicit surface before we execute
4049 * the outstanding moves. This way we minimize the time between
4050 * doing the moves and rendering the new update area, thus minimizing
4051 * flashing. Of course, if any subwindow is non-double buffered we
4052 * well flush earlier than that.
4054 * Thirdly, after having done the outstanding moves we queue an
4055 * "antiexpose" on the area that will be drawn by the expose, which
4056 * means that any invalid region on the native window side before
4057 * the first expose drawing operation will be discarded, as it
4058 * has by then been overdrawn with valid data. This means we can
4059 * avoid doing the unnecessary repaint any outstanding expose events.
4062 cairo_region_get_extents (update_area, &clip_box);
4063 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4064 expose_region = cairo_region_copy (update_area);
4065 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4068 /* Rendering is not double buffered by gdk, do outstanding
4069 * moves and queue antiexposure immediately. No need to do
4071 gdk_window_flush_outstanding_moves (window);
4072 save_region = impl_class->queue_antiexpose (window, update_area);
4074 /* Render the invalid areas to the implicit paint, by sending exposes.
4075 * May flush if non-double buffered widget draw. */
4076 impl_class->process_updates_recurse (window, expose_region);
4080 /* Do moves right before exposes are rendered to the window */
4081 gdk_window_flush_outstanding_moves (window);
4083 /* By this time we know that any outstanding expose for this
4084 * area is invalid and we can avoid it, so queue an antiexpose.
4085 * we have already started drawing to the window, so it would
4086 * be to late to anti-expose now. Since this is merely an
4087 * optimization we just avoid doing it at all in that case.
4089 if (window->implicit_paint != NULL && !((GdkWindowPaint *)window->implicit_paint->data)->flushed)
4090 save_region = impl_class->queue_antiexpose (window, update_area);
4092 gdk_window_end_implicit_paint (window);
4094 cairo_region_destroy (expose_region);
4097 cairo_region_destroy (update_area);
4100 if (window->outstanding_moves)
4102 /* Flush any outstanding moves, may happen if we moved a window but got
4103 no actual invalid area */
4104 gdk_window_flush_outstanding_moves (window);
4107 g_object_unref (window);
4111 flush_all_displays (void)
4113 GSList *displays, *l;
4115 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4116 for (l = displays; l; l = l->next)
4117 gdk_display_flush (l->data);
4119 g_slist_free (displays);
4123 before_process_all_updates (void)
4125 GSList *displays, *l;
4126 GdkDisplayClass *display_class;
4128 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4129 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4130 for (l = displays; l; l = l->next)
4131 display_class->before_process_all_updates (l->data);
4133 g_slist_free (displays);
4137 after_process_all_updates (void)
4139 GSList *displays, *l;
4140 GdkDisplayClass *display_class;
4142 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4143 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4144 for (l = displays; l; l = l->next)
4145 display_class->after_process_all_updates (l->data);
4147 g_slist_free (displays);
4150 /* Currently it is not possible to override
4151 * gdk_window_process_all_updates in the same manner as
4152 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4153 * by implementing the GdkPaintable interface. If in the future a
4154 * backend would need this, the right solution would be to add a
4155 * method to GdkDisplay that can be optionally
4156 * NULL. gdk_window_process_all_updates can then walk the list of open
4157 * displays and call the mehod.
4161 * gdk_window_process_all_updates:
4163 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4164 * in the application.
4168 gdk_window_process_all_updates (void)
4170 GSList *old_update_windows = update_windows;
4171 GSList *tmp_list = update_windows;
4172 static gboolean in_process_all_updates = FALSE;
4173 static gboolean got_recursive_update = FALSE;
4175 if (in_process_all_updates)
4177 /* We can't do this now since that would recurse, so
4178 delay it until after the recursion is done. */
4179 got_recursive_update = TRUE;
4184 in_process_all_updates = TRUE;
4185 got_recursive_update = FALSE;
4188 g_source_remove (update_idle);
4190 update_windows = NULL;
4193 before_process_all_updates ();
4195 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4199 GdkWindow *window = tmp_list->data;
4201 if (!GDK_WINDOW_DESTROYED (window))
4203 if (window->update_freeze_count ||
4204 gdk_window_is_toplevel_frozen (window))
4205 gdk_window_add_update_window (window);
4207 gdk_window_process_updates_internal (window);
4210 g_object_unref (window);
4211 tmp_list = tmp_list->next;
4214 g_slist_free (old_update_windows);
4216 flush_all_displays ();
4218 after_process_all_updates ();
4220 in_process_all_updates = FALSE;
4222 /* If we ignored a recursive call, schedule a
4223 redraw now so that it eventually happens,
4224 otherwise we could miss an update if nothing
4225 else schedules an update. */
4226 if (got_recursive_update && !update_idle)
4228 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4229 gdk_window_update_idle,
4234 * gdk_window_process_updates:
4235 * @window: a #GdkWindow
4236 * @update_children: whether to also process updates for child windows
4238 * Sends one or more expose events to @window. The areas in each
4239 * expose event will cover the entire update area for the window (see
4240 * gdk_window_invalidate_region() for details). Normally GDK calls
4241 * gdk_window_process_all_updates() on your behalf, so there's no
4242 * need to call this function unless you want to force expose events
4243 * to be delivered immediately and synchronously (vs. the usual
4244 * case, where GDK delivers them in an idle handler). Occasionally
4245 * this is useful to produce nicer scrolling behavior, for example.
4249 gdk_window_process_updates (GdkWindow *window,
4250 gboolean update_children)
4252 GdkWindow *impl_window;
4254 g_return_if_fail (GDK_IS_WINDOW (window));
4256 if (GDK_WINDOW_DESTROYED (window))
4259 /* Make sure the window lives during the expose callouts */
4260 g_object_ref (window);
4262 impl_window = gdk_window_get_impl_window (window);
4263 if ((impl_window->update_area ||
4264 impl_window->outstanding_moves) &&
4265 !impl_window->update_freeze_count &&
4266 !gdk_window_is_toplevel_frozen (window) &&
4268 /* Don't recurse into process_updates_internal, we'll
4269 * do the update later when idle instead. */
4270 impl_window->implicit_paint == NULL)
4272 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4273 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4276 if (update_children)
4278 /* process updates in reverse stacking order so composition or
4279 * painting over achieves the desired effect for offscreen windows
4281 GList *node, *children;
4283 children = g_list_copy (window->children);
4284 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4286 for (node = g_list_last (children); node; node = node->prev)
4288 gdk_window_process_updates (node->data, TRUE);
4289 g_object_unref (node->data);
4292 g_list_free (children);
4295 g_object_unref (window);
4299 gdk_window_invalidate_rect_full (GdkWindow *window,
4300 const GdkRectangle *rect,
4301 gboolean invalidate_children,
4304 GdkRectangle window_rect;
4305 cairo_region_t *region;
4307 g_return_if_fail (GDK_IS_WINDOW (window));
4309 if (GDK_WINDOW_DESTROYED (window))
4312 if (window->input_only || !window->viewable)
4319 window_rect.width = window->width;
4320 window_rect.height = window->height;
4321 rect = &window_rect;
4324 region = cairo_region_create_rectangle (rect);
4325 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4326 cairo_region_destroy (region);
4330 * gdk_window_invalidate_rect:
4331 * @window: a #GdkWindow
4332 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4334 * @invalidate_children: whether to also invalidate child windows
4336 * A convenience wrapper around gdk_window_invalidate_region() which
4337 * invalidates a rectangular region. See
4338 * gdk_window_invalidate_region() for details.
4341 gdk_window_invalidate_rect (GdkWindow *window,
4342 const GdkRectangle *rect,
4343 gboolean invalidate_children)
4345 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4349 draw_ugly_color (GdkWindow *window,
4350 const cairo_region_t *region)
4354 cr = gdk_cairo_create (window);
4355 /* Draw ugly color all over the newly-invalid region */
4356 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4357 gdk_cairo_region (cr, region);
4364 impl_window_add_update_area (GdkWindow *impl_window,
4365 cairo_region_t *region)
4367 if (impl_window->update_area)
4368 cairo_region_union (impl_window->update_area, region);
4371 gdk_window_add_update_window (impl_window);
4372 impl_window->update_area = cairo_region_copy (region);
4373 gdk_window_schedule_update (impl_window);
4377 /* clear_bg controls if the region will be cleared to
4378 * the background pattern if the exposure mask is not
4379 * set for the window, whereas this might not otherwise be
4380 * done (unless necessary to emulate background settings).
4381 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4382 * need to clear the background, such as when exposing the area beneath a
4383 * hidden or moved window, but not when an app requests repaint or when the
4384 * windowing system exposes a newly visible area (because then the windowing
4385 * system has already cleared the area).
4388 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4389 const cairo_region_t *region,
4391 GdkWindowChildFunc child_func,
4394 GdkWindow *impl_window;
4395 cairo_region_t *visible_region;
4398 g_return_if_fail (GDK_IS_WINDOW (window));
4400 if (GDK_WINDOW_DESTROYED (window))
4403 if (window->input_only ||
4404 !window->viewable ||
4405 cairo_region_is_empty (region) ||
4406 window->window_type == GDK_WINDOW_ROOT)
4409 visible_region = gdk_window_get_visible_region (window);
4410 cairo_region_intersect (visible_region, region);
4412 tmp_list = window->children;
4415 GdkWindow *child = tmp_list->data;
4417 if (!child->input_only)
4419 cairo_region_t *child_region;
4420 GdkRectangle child_rect;
4422 child_rect.x = child->x;
4423 child_rect.y = child->y;
4424 child_rect.width = child->width;
4425 child_rect.height = child->height;
4426 child_region = cairo_region_create_rectangle (&child_rect);
4428 /* remove child area from the invalid area of the parent */
4429 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4430 !child->composited &&
4431 !gdk_window_is_offscreen (child))
4432 cairo_region_subtract (visible_region, child_region);
4434 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4436 cairo_region_t *tmp = cairo_region_copy (region);
4438 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4439 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4440 cairo_region_intersect (child_region, tmp);
4442 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4443 child_region, clear_bg, child_func, user_data);
4445 cairo_region_destroy (tmp);
4448 cairo_region_destroy (child_region);
4451 tmp_list = tmp_list->next;
4454 impl_window = gdk_window_get_impl_window (window);
4456 if (!cairo_region_is_empty (visible_region) ||
4457 /* Even if we're not exposing anything, make sure we process
4458 idles for windows with outstanding moves */
4459 (impl_window->outstanding_moves != NULL &&
4460 impl_window->update_area == NULL))
4463 draw_ugly_color (window, region);
4465 /* Convert to impl coords */
4466 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4468 /* Only invalidate area if app requested expose events or if
4469 we need to clear the area (by request or to emulate background
4470 clearing for non-native windows or native windows with no support
4471 for window backgrounds */
4472 if (window->event_mask & GDK_EXPOSURE_MASK ||
4473 clear_bg == CLEAR_BG_ALL ||
4474 clear_bg == CLEAR_BG_WINCLEARED)
4475 impl_window_add_update_area (impl_window, visible_region);
4478 cairo_region_destroy (visible_region);
4482 * gdk_window_invalidate_maybe_recurse:
4483 * @window: a #GdkWindow
4484 * @region: a #cairo_region_t
4485 * @child_func: (scope call) (allow-none): function to use to decide if to
4486 * recurse to a child, %NULL means never recurse.
4487 * @user_data: data passed to @child_func
4489 * Adds @region to the update area for @window. The update area is the
4490 * region that needs to be redrawn, or "dirty region." The call
4491 * gdk_window_process_updates() sends one or more expose events to the
4492 * window, which together cover the entire update area. An
4493 * application would normally redraw the contents of @window in
4494 * response to those expose events.
4496 * GDK will call gdk_window_process_all_updates() on your behalf
4497 * whenever your program returns to the main loop and becomes idle, so
4498 * normally there's no need to do that manually, you just need to
4499 * invalidate regions that you know should be redrawn.
4501 * The @child_func parameter controls whether the region of
4502 * each child window that intersects @region will also be invalidated.
4503 * Only children for which @child_func returns TRUE will have the area
4507 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4508 const cairo_region_t *region,
4509 GdkWindowChildFunc child_func,
4512 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4513 child_func, user_data);
4517 true_predicate (GdkWindow *window,
4524 gdk_window_invalidate_region_full (GdkWindow *window,
4525 const cairo_region_t *region,
4526 gboolean invalidate_children,
4529 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4530 invalidate_children ?
4531 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4536 * gdk_window_invalidate_region:
4537 * @window: a #GdkWindow
4538 * @region: a #cairo_region_t
4539 * @invalidate_children: %TRUE to also invalidate child windows
4541 * Adds @region to the update area for @window. The update area is the
4542 * region that needs to be redrawn, or "dirty region." The call
4543 * gdk_window_process_updates() sends one or more expose events to the
4544 * window, which together cover the entire update area. An
4545 * application would normally redraw the contents of @window in
4546 * response to those expose events.
4548 * GDK will call gdk_window_process_all_updates() on your behalf
4549 * whenever your program returns to the main loop and becomes idle, so
4550 * normally there's no need to do that manually, you just need to
4551 * invalidate regions that you know should be redrawn.
4553 * The @invalidate_children parameter controls whether the region of
4554 * each child window that intersects @region will also be invalidated.
4555 * If %FALSE, then the update area for child windows will remain
4556 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4557 * fine grained control over which children are invalidated.
4560 gdk_window_invalidate_region (GdkWindow *window,
4561 const cairo_region_t *region,
4562 gboolean invalidate_children)
4564 gdk_window_invalidate_maybe_recurse (window, region,
4565 invalidate_children ?
4566 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4571 * _gdk_window_invalidate_for_expose:
4572 * @window: a #GdkWindow
4573 * @region: a #cairo_region_t
4575 * Adds @region to the update area for @window. The update area is the
4576 * region that needs to be redrawn, or "dirty region." The call
4577 * gdk_window_process_updates() sends one or more expose events to the
4578 * window, which together cover the entire update area. An
4579 * application would normally redraw the contents of @window in
4580 * response to those expose events.
4582 * GDK will call gdk_window_process_all_updates() on your behalf
4583 * whenever your program returns to the main loop and becomes idle, so
4584 * normally there's no need to do that manually, you just need to
4585 * invalidate regions that you know should be redrawn.
4587 * This version of invalidation is used when you recieve expose events
4588 * from the native window system. It exposes the native window, plus
4589 * any non-native child windows (but not native child windows, as those would
4590 * have gotten their own expose events).
4593 _gdk_window_invalidate_for_expose (GdkWindow *window,
4594 cairo_region_t *region)
4596 GdkWindowRegionMove *move;
4597 cairo_region_t *move_region;
4600 /* Any invalidations comming from the windowing system will
4601 be in areas that may be moved by outstanding moves,
4602 so we need to modify the expose region correspondingly,
4603 otherwise we would expose in the wrong place, as the
4604 outstanding moves will be copied before we draw the
4606 for (l = window->outstanding_moves; l != NULL; l = l->next)
4610 /* covert to move source region */
4611 move_region = cairo_region_copy (move->dest_region);
4612 cairo_region_translate (move_region, -move->dx, -move->dy);
4614 /* Move area of region that intersects with move source
4615 by dx, dy of the move*/
4616 cairo_region_intersect (move_region, region);
4617 cairo_region_subtract (region, move_region);
4618 cairo_region_translate (move_region, move->dx, move->dy);
4619 cairo_region_union (region, move_region);
4621 cairo_region_destroy (move_region);
4624 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4625 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4631 * gdk_window_get_update_area:
4632 * @window: a #GdkWindow
4634 * Transfers ownership of the update area from @window to the caller
4635 * of the function. That is, after calling this function, @window will
4636 * no longer have an invalid/dirty region; the update area is removed
4637 * from @window and handed to you. If a window has no update area,
4638 * gdk_window_get_update_area() returns %NULL. You are responsible for
4639 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4641 * Return value: the update area for @window
4644 gdk_window_get_update_area (GdkWindow *window)
4646 GdkWindow *impl_window;
4647 cairo_region_t *tmp_region, *to_remove;
4649 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4651 impl_window = gdk_window_get_impl_window (window);
4653 if (impl_window->update_area)
4655 tmp_region = cairo_region_copy (window->clip_region_with_children);
4656 /* Convert to impl coords */
4657 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4658 cairo_region_intersect (tmp_region, impl_window->update_area);
4660 if (cairo_region_is_empty (tmp_region))
4662 cairo_region_destroy (tmp_region);
4667 /* Convert from impl coords */
4668 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4670 /* Don't remove any update area that is overlapped by non-opaque windows
4671 (children or siblings) with alpha, as these really need to be repainted
4672 independently of this window. */
4673 to_remove = cairo_region_copy (tmp_region);
4674 cairo_region_subtract (to_remove, window->parent->layered_region);
4675 remove_layered_child_area (window, to_remove);
4677 /* Remove from update_area */
4678 cairo_region_translate (to_remove, window->abs_x, window->abs_y);
4679 cairo_region_subtract (impl_window->update_area, to_remove);
4681 cairo_region_destroy (to_remove);
4683 if (cairo_region_is_empty (impl_window->update_area) &&
4684 impl_window->outstanding_moves == NULL)
4686 cairo_region_destroy (impl_window->update_area);
4687 impl_window->update_area = NULL;
4689 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4700 * _gdk_window_clear_update_area:
4701 * @window: a #GdkWindow.
4703 * Internal function to clear the update area for a window. This
4704 * is called when the window is hidden or destroyed.
4707 _gdk_window_clear_update_area (GdkWindow *window)
4709 g_return_if_fail (GDK_IS_WINDOW (window));
4711 if (window->update_area)
4713 gdk_window_remove_update_window (window);
4715 cairo_region_destroy (window->update_area);
4716 window->update_area = NULL;
4721 * gdk_window_freeze_updates:
4722 * @window: a #GdkWindow
4724 * Temporarily freezes a window such that it won't receive expose
4725 * events. The window will begin receiving expose events again when
4726 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4727 * has been called more than once, gdk_window_thaw_updates() must be called
4728 * an equal number of times to begin processing exposes.
4731 gdk_window_freeze_updates (GdkWindow *window)
4733 GdkWindow *impl_window;
4735 g_return_if_fail (GDK_IS_WINDOW (window));
4737 impl_window = gdk_window_get_impl_window (window);
4738 impl_window->update_freeze_count++;
4742 * gdk_window_thaw_updates:
4743 * @window: a #GdkWindow
4745 * Thaws a window frozen with gdk_window_freeze_updates().
4748 gdk_window_thaw_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);
4756 g_return_if_fail (impl_window->update_freeze_count > 0);
4758 if (--impl_window->update_freeze_count == 0)
4759 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4763 * gdk_window_freeze_toplevel_updates_libgtk_only:
4764 * @window: a #GdkWindow
4766 * Temporarily freezes a window and all its descendants such that it won't
4767 * receive expose events. The window will begin receiving expose events
4768 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4769 * gdk_window_freeze_toplevel_updates_libgtk_only()
4770 * has been called more than once,
4771 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4772 * an equal number of times to begin processing exposes.
4774 * This function is not part of the GDK public API and is only
4778 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4780 g_return_if_fail (GDK_IS_WINDOW (window));
4781 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4783 window->update_and_descendants_freeze_count++;
4787 * gdk_window_thaw_toplevel_updates_libgtk_only:
4788 * @window: a #GdkWindow
4790 * Thaws a window frozen with
4791 * gdk_window_freeze_toplevel_updates_libgtk_only().
4793 * This function is not part of the GDK public API and is only
4797 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4799 g_return_if_fail (GDK_IS_WINDOW (window));
4800 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4801 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4803 window->update_and_descendants_freeze_count--;
4805 gdk_window_schedule_update (window);
4809 * gdk_window_set_debug_updates:
4810 * @setting: %TRUE to turn on update debugging
4812 * With update debugging enabled, calls to
4813 * gdk_window_invalidate_region() clear the invalidated region of the
4814 * screen to a noticeable color, and GDK pauses for a short time
4815 * before sending exposes to windows during
4816 * gdk_window_process_updates(). The net effect is that you can see
4817 * the invalid region for each window and watch redraws as they
4818 * occur. This allows you to diagnose inefficiencies in your application.
4820 * In essence, because the GDK rendering model prevents all flicker,
4821 * if you are redrawing the same region 400 times you may never
4822 * notice, aside from noticing a speed problem. Enabling update
4823 * debugging causes GTK to flicker slowly and noticeably, so you can
4824 * see exactly what's being redrawn when, in what order.
4826 * The --gtk-debug=updates command line option passed to GTK+ programs
4827 * enables this debug option at application startup time. That's
4828 * usually more useful than calling gdk_window_set_debug_updates()
4829 * yourself, though you might want to use this function to enable
4830 * updates sometime after application startup time.
4834 gdk_window_set_debug_updates (gboolean setting)
4836 debug_updates = setting;
4840 * gdk_window_constrain_size:
4841 * @geometry: a #GdkGeometry structure
4842 * @flags: a mask indicating what portions of @geometry are set
4843 * @width: desired width of window
4844 * @height: desired height of the window
4845 * @new_width: (out): location to store resulting width
4846 * @new_height: (out): location to store resulting height
4848 * Constrains a desired width and height according to a
4849 * set of geometry hints (such as minimum and maximum size).
4852 gdk_window_constrain_size (GdkGeometry *geometry,
4859 /* This routine is partially borrowed from fvwm.
4861 * Copyright 1993, Robert Nation
4862 * You may use this code for any purpose, as long as the original
4863 * copyright remains in the source code and all documentation
4865 * which in turn borrows parts of the algorithm from uwm
4868 gint min_height = 0;
4869 gint base_width = 0;
4870 gint base_height = 0;
4873 gint max_width = G_MAXINT;
4874 gint max_height = G_MAXINT;
4876 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4878 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4880 base_width = geometry->base_width;
4881 base_height = geometry->base_height;
4882 min_width = geometry->min_width;
4883 min_height = geometry->min_height;
4885 else if (flags & GDK_HINT_BASE_SIZE)
4887 base_width = geometry->base_width;
4888 base_height = geometry->base_height;
4889 min_width = geometry->base_width;
4890 min_height = geometry->base_height;
4892 else if (flags & GDK_HINT_MIN_SIZE)
4894 base_width = geometry->min_width;
4895 base_height = geometry->min_height;
4896 min_width = geometry->min_width;
4897 min_height = geometry->min_height;
4900 if (flags & GDK_HINT_MAX_SIZE)
4902 max_width = geometry->max_width ;
4903 max_height = geometry->max_height;
4906 if (flags & GDK_HINT_RESIZE_INC)
4908 xinc = MAX (xinc, geometry->width_inc);
4909 yinc = MAX (yinc, geometry->height_inc);
4912 /* clamp width and height to min and max values
4914 width = CLAMP (width, min_width, max_width);
4915 height = CLAMP (height, min_height, max_height);
4917 /* shrink to base + N * inc
4919 width = base_width + FLOOR (width - base_width, xinc);
4920 height = base_height + FLOOR (height - base_height, yinc);
4922 /* constrain aspect ratio, according to:
4925 * min_aspect <= -------- <= max_aspect
4929 if (flags & GDK_HINT_ASPECT &&
4930 geometry->min_aspect > 0 &&
4931 geometry->max_aspect > 0)
4935 if (geometry->min_aspect * height > width)
4937 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4938 if (height - delta >= min_height)
4942 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4943 if (width + delta <= max_width)
4948 if (geometry->max_aspect * height < width)
4950 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4951 if (width - delta >= min_width)
4955 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4956 if (height + delta <= max_height)
4965 *new_height = height;
4969 * gdk_window_get_pointer:
4970 * @window: a #GdkWindow
4971 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4972 * return the X coordinate
4973 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4974 * return the Y coordinate
4975 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4978 * Obtains the current pointer position and modifier state.
4979 * The position is given in coordinates relative to the upper left
4980 * corner of @window.
4982 * Return value: (transfer none): the window containing the pointer (as with
4983 * gdk_window_at_pointer()), or %NULL if the window containing the
4984 * pointer isn't known to GDK
4986 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4989 gdk_window_get_pointer (GdkWindow *window,
4992 GdkModifierType *mask)
4994 GdkDisplay *display;
4996 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4998 display = gdk_window_get_display (window);
5000 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
5004 * gdk_window_get_device_position:
5005 * @window: a #GdkWindow.
5006 * @device: pointer #GdkDevice to query to.
5007 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5008 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5009 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5011 * Obtains the current device position and modifier state.
5012 * The position is given in coordinates relative to the upper left
5013 * corner of @window.
5015 * Return value: (transfer none): The window underneath @device (as with
5016 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
5021 gdk_window_get_device_position (GdkWindow *window,
5025 GdkModifierType *mask)
5028 GdkModifierType tmp_mask;
5029 gboolean normal_child;
5031 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5032 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5033 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
5035 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
5039 /* We got the coords on the impl, convert to the window */
5040 tmp_x -= window->abs_x;
5041 tmp_y -= window->abs_y;
5050 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
5053 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5058 * gdk_get_default_root_window:
5060 * Obtains the root window (parent all other windows are inside)
5061 * for the default display and screen.
5063 * Return value: (transfer none): the default root window
5066 gdk_get_default_root_window (void)
5068 return gdk_screen_get_root_window (gdk_screen_get_default ());
5072 get_all_native_children (GdkWindow *window,
5078 for (l = window->children; l != NULL; l = l->next)
5082 if (gdk_window_has_impl (child))
5083 *native = g_list_prepend (*native, child);
5085 get_all_native_children (child, native);
5091 gdk_window_raise_internal (GdkWindow *window)
5093 GdkWindow *parent = window->parent;
5095 GList *native_children;
5097 GdkWindowImplClass *impl_class;
5101 parent->children = g_list_remove (parent->children, window);
5102 parent->children = g_list_prepend (parent->children, window);
5105 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5106 /* Just do native raise for toplevels */
5107 if (gdk_window_is_toplevel (window) ||
5108 /* The restack_under codepath should work correctly even if the parent
5109 is native, but it relies on the order of ->children to be correct,
5110 and some apps like SWT reorder the x windows without gdks knowledge,
5111 so we use raise directly in order to make these behave as before
5112 when using native windows */
5113 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5115 impl_class->raise (window);
5117 else if (gdk_window_has_impl (window))
5119 above = find_native_sibling_above (parent, window);
5122 listhead.data = window;
5123 listhead.next = NULL;
5124 listhead.prev = NULL;
5125 impl_class->restack_under ((GdkWindow *)above,
5129 impl_class->raise (window);
5133 native_children = NULL;
5134 get_all_native_children (window, &native_children);
5135 if (native_children != NULL)
5137 above = find_native_sibling_above (parent, window);
5140 impl_class->restack_under (above, native_children);
5143 /* Right order, since native_children is bottom-topmost first */
5144 for (l = native_children; l != NULL; l = l->next)
5145 impl_class->raise (l->data);
5148 g_list_free (native_children);
5154 /* Returns TRUE If the native window was mapped or unmapped */
5156 set_viewable (GdkWindow *w,
5160 GdkWindowImplClass *impl_class;
5163 if (w->viewable == val)
5169 recompute_visible_regions (w, FALSE, FALSE);
5171 for (l = w->children; l != NULL; l = l->next)
5175 if (GDK_WINDOW_IS_MAPPED (child) &&
5176 child->window_type != GDK_WINDOW_FOREIGN)
5177 set_viewable (child, val);
5180 if (gdk_window_has_impl (w) &&
5181 w->window_type != GDK_WINDOW_FOREIGN &&
5182 !gdk_window_is_toplevel (w))
5184 /* For most native windows we show/hide them not when they are
5185 * mapped/unmapped, because that may not produce the correct results.
5186 * For instance, if a native window have a non-native parent which is
5187 * hidden, but its native parent is viewable then showing the window
5188 * would make it viewable to X but its not viewable wrt the non-native
5189 * hierarchy. In order to handle this we track the gdk side viewability
5190 * and only map really viewable windows.
5192 * There are two exceptions though:
5194 * For foreign windows we don't want ever change the mapped state
5195 * except when explicitly done via gdk_window_show/hide, as this may
5196 * cause problems for client owning the foreign window when its window
5197 * is suddenly mapped or unmapped.
5199 * For toplevel windows embedded in a foreign window (e.g. a plug)
5200 * we sometimes synthesize a map of a window, but the native
5201 * window is really shown by the embedder, so we don't want to
5202 * do the show ourselves. We can't really tell this case from the normal
5203 * toplevel show as such toplevels are seen by gdk as parents of the
5204 * root window, so we make an exception for all toplevels.
5207 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5209 impl_class->show ((GdkWindow *)w, FALSE);
5211 impl_class->hide ((GdkWindow *)w);
5219 /* Returns TRUE If the native window was mapped or unmapped */
5221 _gdk_window_update_viewable (GdkWindow *window)
5225 if (window->window_type == GDK_WINDOW_FOREIGN ||
5226 window->window_type == GDK_WINDOW_ROOT)
5228 else if (gdk_window_is_toplevel (window) ||
5229 window->parent->viewable)
5230 viewable = GDK_WINDOW_IS_MAPPED (window);
5234 return set_viewable (window, viewable);
5238 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5240 GdkWindowImplClass *impl_class;
5241 gboolean was_mapped, was_viewable;
5244 g_return_if_fail (GDK_IS_WINDOW (window));
5246 if (window->destroyed)
5249 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5250 was_viewable = window->viewable;
5253 /* Keep children in (reverse) stacking order */
5254 gdk_window_raise_internal (window);
5256 if (gdk_window_has_impl (window))
5259 gdk_synthesize_window_state (window,
5260 GDK_WINDOW_STATE_WITHDRAWN,
5261 GDK_WINDOW_STATE_FOCUSED);
5268 did_show = _gdk_window_update_viewable (window);
5270 /* If it was already viewable the backend show op won't be called, call it
5271 again to ensure things happen right if the mapped tracking was not right
5272 for e.g. a foreign window.
5273 Dunno if this is strictly needed but its what happened pre-csw.
5274 Also show if not done by gdk_window_update_viewable. */
5275 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5277 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5278 impl_class->show (window, !did_show ? was_mapped : TRUE);
5281 if (!was_mapped && !gdk_window_has_impl (window))
5283 if (window->event_mask & GDK_STRUCTURE_MASK)
5284 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5286 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5287 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5290 if (!was_mapped || raise)
5292 recompute_visible_regions (window, TRUE, FALSE);
5294 /* If any decendants became visible we need to send visibility notify */
5295 gdk_window_update_visibility_recursively (window, NULL);
5297 if (gdk_window_is_viewable (window))
5299 _gdk_synthesize_crossing_events_for_geometry_change (window);
5300 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5306 * gdk_window_show_unraised:
5307 * @window: a #GdkWindow
5309 * Shows a #GdkWindow onscreen, but does not modify its stacking
5310 * order. In contrast, gdk_window_show() will raise the window
5311 * to the top of the window stack.
5313 * On the X11 platform, in Xlib terms, this function calls
5314 * XMapWindow() (it also updates some internal GDK state, which means
5315 * that you can't really use XMapWindow() directly on a GDK window).
5318 gdk_window_show_unraised (GdkWindow *window)
5320 gdk_window_show_internal (window, FALSE);
5325 * @window: a #GdkWindow
5327 * Raises @window to the top of the Z-order (stacking order), so that
5328 * other windows with the same parent window appear below @window.
5329 * This is true whether or not the windows are visible.
5331 * If @window is a toplevel, the window manager may choose to deny the
5332 * request to move the window in the Z-order, gdk_window_raise() only
5333 * requests the restack, does not guarantee it.
5336 gdk_window_raise (GdkWindow *window)
5338 g_return_if_fail (GDK_IS_WINDOW (window));
5340 if (window->destroyed)
5343 /* Keep children in (reverse) stacking order */
5344 gdk_window_raise_internal (window);
5346 recompute_visible_regions (window, TRUE, FALSE);
5348 if (gdk_window_is_viewable (window) &&
5349 !window->input_only)
5350 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5354 gdk_window_lower_internal (GdkWindow *window)
5356 GdkWindow *parent = window->parent;
5357 GdkWindowImplClass *impl_class;
5359 GList *native_children;
5364 parent->children = g_list_remove (parent->children, window);
5365 parent->children = g_list_append (parent->children, window);
5368 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5369 /* Just do native lower for toplevels */
5370 if (gdk_window_is_toplevel (window) ||
5371 /* The restack_under codepath should work correctly even if the parent
5372 is native, but it relies on the order of ->children to be correct,
5373 and some apps like SWT reorder the x windows without gdks knowledge,
5374 so we use lower directly in order to make these behave as before
5375 when using native windows */
5376 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5378 impl_class->lower (window);
5380 else if (gdk_window_has_impl (window))
5382 above = find_native_sibling_above (parent, window);
5385 listhead.data = window;
5386 listhead.next = NULL;
5387 listhead.prev = NULL;
5388 impl_class->restack_under ((GdkWindow *)above, &listhead);
5391 impl_class->raise (window);
5395 native_children = NULL;
5396 get_all_native_children (window, &native_children);
5397 if (native_children != NULL)
5399 above = find_native_sibling_above (parent, window);
5402 impl_class->restack_under ((GdkWindow *)above,
5406 /* Right order, since native_children is bottom-topmost first */
5407 for (l = native_children; l != NULL; l = l->next)
5408 impl_class->raise (l->data);
5411 g_list_free (native_children);
5418 gdk_window_invalidate_in_parent (GdkWindow *private)
5420 GdkRectangle r, child;
5422 if (gdk_window_is_toplevel (private))
5425 /* get the visible rectangle of the parent */
5427 r.width = private->parent->width;
5428 r.height = private->parent->height;
5430 child.x = private->x;
5431 child.y = private->y;
5432 child.width = private->width;
5433 child.height = private->height;
5434 gdk_rectangle_intersect (&r, &child, &r);
5436 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5442 * @window: a #GdkWindow
5444 * Lowers @window to the bottom of the Z-order (stacking order), so that
5445 * other windows with the same parent window appear above @window.
5446 * This is true whether or not the other windows are visible.
5448 * If @window is a toplevel, the window manager may choose to deny the
5449 * request to move the window in the Z-order, gdk_window_lower() only
5450 * requests the restack, does not guarantee it.
5452 * Note that gdk_window_show() raises the window again, so don't call this
5453 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5456 gdk_window_lower (GdkWindow *window)
5458 g_return_if_fail (GDK_IS_WINDOW (window));
5460 if (window->destroyed)
5463 /* Keep children in (reverse) stacking order */
5464 gdk_window_lower_internal (window);
5466 recompute_visible_regions (window, TRUE, FALSE);
5468 _gdk_synthesize_crossing_events_for_geometry_change (window);
5469 gdk_window_invalidate_in_parent (window);
5473 * gdk_window_restack:
5474 * @window: a #GdkWindow
5475 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5478 * Changes the position of @window in the Z-order (stacking order), so that
5479 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5482 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5483 * lowers the window.
5485 * If @window is a toplevel, the window manager may choose to deny the
5486 * request to move the window in the Z-order, gdk_window_restack() only
5487 * requests the restack, does not guarantee it.
5492 gdk_window_restack (GdkWindow *window,
5496 GdkWindowImplClass *impl_class;
5498 GdkWindow *above_native;
5499 GList *sibling_link;
5500 GList *native_children;
5503 g_return_if_fail (GDK_IS_WINDOW (window));
5504 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5506 if (window->destroyed)
5509 if (sibling == NULL)
5512 gdk_window_raise (window);
5514 gdk_window_lower (window);
5518 if (gdk_window_is_toplevel (window))
5520 g_return_if_fail (gdk_window_is_toplevel (sibling));
5521 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5522 impl_class->restack_toplevel (window, sibling, above);
5526 parent = window->parent;
5529 sibling_link = g_list_find (parent->children, sibling);
5530 g_return_if_fail (sibling_link != NULL);
5531 if (sibling_link == NULL)
5534 parent->children = g_list_remove (parent->children, window);
5536 parent->children = g_list_insert_before (parent->children,
5540 parent->children = g_list_insert_before (parent->children,
5544 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5545 if (gdk_window_has_impl (window))
5547 above_native = find_native_sibling_above (parent, window);
5550 listhead.data = window;
5551 listhead.next = NULL;
5552 listhead.prev = NULL;
5553 impl_class->restack_under (above_native, &listhead);
5556 impl_class->raise (window);
5560 native_children = NULL;
5561 get_all_native_children (window, &native_children);
5562 if (native_children != NULL)
5564 above_native = find_native_sibling_above (parent, window);
5566 impl_class->restack_under (above_native,
5570 /* Right order, since native_children is bottom-topmost first */
5571 for (l = native_children; l != NULL; l = l->next)
5572 impl_class->raise (l->data);
5575 g_list_free (native_children);
5580 recompute_visible_regions (window, TRUE, FALSE);
5582 _gdk_synthesize_crossing_events_for_geometry_change (window);
5583 gdk_window_invalidate_in_parent (window);
5589 * @window: a #GdkWindow
5591 * Like gdk_window_show_unraised(), but also raises the window to the
5592 * top of the window stack (moves the window to the front of the
5595 * This function maps a window so it's visible onscreen. Its opposite
5596 * is gdk_window_hide().
5598 * When implementing a #GtkWidget, you should call this function on the widget's
5599 * #GdkWindow as part of the "map" method.
5602 gdk_window_show (GdkWindow *window)
5604 gdk_window_show_internal (window, TRUE);
5609 * @window: a #GdkWindow
5611 * For toplevel windows, withdraws them, so they will no longer be
5612 * known to the window manager; for all windows, unmaps them, so
5613 * they won't be displayed. Normally done automatically as
5614 * part of gtk_widget_hide().
5617 gdk_window_hide (GdkWindow *window)
5619 GdkWindowImplClass *impl_class;
5620 gboolean was_mapped, did_hide;
5622 g_return_if_fail (GDK_IS_WINDOW (window));
5624 if (window->destroyed)
5627 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5629 if (gdk_window_has_impl (window))
5632 if (GDK_WINDOW_IS_MAPPED (window))
5633 gdk_synthesize_window_state (window,
5635 GDK_WINDOW_STATE_WITHDRAWN);
5637 else if (was_mapped)
5639 GdkDisplay *display;
5640 GdkDeviceManager *device_manager;
5643 /* May need to break grabs on children */
5644 display = gdk_window_get_display (window);
5645 device_manager = gdk_display_get_device_manager (display);
5647 /* Get all devices */
5648 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5649 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5650 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5652 for (d = devices; d; d = d->next)
5654 GdkDevice *device = d->data;
5656 if (_gdk_display_end_device_grab (display,
5658 _gdk_display_get_next_serial (display),
5661 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5664 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5665 g_list_free (devices);
5668 did_hide = _gdk_window_update_viewable (window);
5670 /* Hide foreign window as those are not handled by update_viewable. */
5671 if (gdk_window_has_impl (window) && (!did_hide))
5673 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5674 impl_class->hide (window);
5677 recompute_visible_regions (window, TRUE, FALSE);
5679 /* all decendants became non-visible, we need to send visibility notify */
5680 gdk_window_update_visibility_recursively (window, NULL);
5682 if (was_mapped && !gdk_window_has_impl (window))
5684 if (window->event_mask & GDK_STRUCTURE_MASK)
5685 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5687 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5688 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5690 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5693 /* Invalidate the rect */
5695 gdk_window_invalidate_in_parent (window);
5699 * gdk_window_withdraw:
5700 * @window: a toplevel #GdkWindow
5702 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5703 * This function is not really useful as gdk_window_hide() automatically
5704 * withdraws toplevel windows before hiding them.
5707 gdk_window_withdraw (GdkWindow *window)
5709 GdkWindowImplClass *impl_class;
5710 gboolean was_mapped;
5712 g_return_if_fail (GDK_IS_WINDOW (window));
5714 if (window->destroyed)
5717 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5719 if (gdk_window_has_impl (window))
5721 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5722 impl_class->withdraw (window);
5726 if (window->event_mask & GDK_STRUCTURE_MASK)
5727 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5729 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5730 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5732 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5735 recompute_visible_regions (window, TRUE, FALSE);
5740 * gdk_window_set_events:
5741 * @window: a #GdkWindow
5742 * @event_mask: event mask for @window
5744 * The event mask for a window determines which events will be reported
5745 * for that window from all master input devices. For example, an event mask
5746 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5747 * press events. The event mask is the bitwise OR of values from the
5748 * #GdkEventMask enumeration.
5751 gdk_window_set_events (GdkWindow *window,
5752 GdkEventMask event_mask)
5754 GdkWindowImplClass *impl_class;
5755 GdkDisplay *display;
5757 g_return_if_fail (GDK_IS_WINDOW (window));
5759 if (window->destroyed)
5762 /* If motion hint is disabled, enable motion events again */
5763 display = gdk_window_get_display (window);
5764 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5765 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5767 GList *devices = window->devices_inside;
5771 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5772 devices = devices->next;
5776 window->event_mask = event_mask;
5778 if (gdk_window_has_impl (window))
5780 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5781 impl_class->set_events (window,
5782 get_native_event_mask (window));
5788 * gdk_window_get_events:
5789 * @window: a #GdkWindow
5791 * Gets the event mask for @window for all master input devices. See
5792 * gdk_window_set_events().
5794 * Return value: event mask for @window
5797 gdk_window_get_events (GdkWindow *window)
5799 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5801 if (window->destroyed)
5804 return window->event_mask;
5808 * gdk_window_set_device_events:
5809 * @window: a #GdkWindow
5810 * @device: #GdkDevice to enable events for.
5811 * @event_mask: event mask for @window
5813 * Sets the event mask for a given device (Normally a floating device, not
5814 * attached to any visible pointer) to @window. For example, an event mask
5815 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5816 * press events. The event mask is the bitwise OR of values from the
5817 * #GdkEventMask enumeration.
5822 gdk_window_set_device_events (GdkWindow *window,
5824 GdkEventMask event_mask)
5826 GdkEventMask device_mask;
5827 GdkDisplay *display;
5830 g_return_if_fail (GDK_IS_WINDOW (window));
5831 g_return_if_fail (GDK_IS_DEVICE (device));
5833 if (GDK_WINDOW_DESTROYED (window))
5836 /* If motion hint is disabled, enable motion events again */
5837 display = gdk_window_get_display (window);
5838 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5839 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5840 _gdk_display_enable_motion_hints (display, device);
5842 if (G_UNLIKELY (!window->device_events))
5843 window->device_events = g_hash_table_new (NULL, NULL);
5845 if (event_mask == 0)
5847 /* FIXME: unsetting events on a master device
5848 * would restore window->event_mask
5850 g_hash_table_remove (window->device_events, device);
5853 g_hash_table_insert (window->device_events, device,
5854 GINT_TO_POINTER (event_mask));
5856 native = gdk_window_get_toplevel (window);
5858 while (gdk_window_is_offscreen (native))
5860 native = gdk_offscreen_window_get_embedder (native);
5862 if (native == NULL ||
5863 (!_gdk_window_has_impl (native) &&
5864 !gdk_window_is_viewable (native)))
5867 native = gdk_window_get_toplevel (native);
5870 device_mask = get_native_device_event_mask (window, device);
5871 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5875 * gdk_window_get_device_events:
5876 * @window: a #GdkWindow.
5877 * @device: a #GdkDevice.
5879 * Returns the event mask for @window corresponding to an specific device.
5881 * Returns: device event mask for @window
5886 gdk_window_get_device_events (GdkWindow *window,
5891 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5892 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5894 if (GDK_WINDOW_DESTROYED (window))
5897 if (!window->device_events)
5900 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5902 /* FIXME: device could be controlled by window->event_mask */
5908 gdk_window_move_resize_toplevel (GdkWindow *window,
5915 cairo_region_t *old_region, *new_region;
5916 GdkWindowImplClass *impl_class;
5923 is_resize = (width != -1) || (height != -1);
5925 if (gdk_window_is_viewable (window) &&
5926 !window->input_only)
5929 old_region = cairo_region_copy (window->clip_region);
5932 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5933 impl_class->move_resize (window, with_move, x, y, width, height);
5935 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5937 recompute_visible_regions (window, TRUE, FALSE);
5941 new_region = cairo_region_copy (window->clip_region);
5943 /* This is the newly exposed area (due to any resize),
5944 * X will expose it, but lets do that without the roundtrip
5946 cairo_region_subtract (new_region, old_region);
5947 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
5949 cairo_region_destroy (old_region);
5950 cairo_region_destroy (new_region);
5953 _gdk_synthesize_crossing_events_for_geometry_change (window);
5958 move_native_children (GdkWindow *private)
5962 GdkWindowImplClass *impl_class;
5964 for (l = private->children; l; l = l->next)
5968 if (child->impl != private->impl)
5970 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
5971 impl_class->move_resize (child, TRUE,
5973 child->width, child->height);
5976 move_native_children (child);
5981 collect_native_child_region_helper (GdkWindow *window,
5982 GdkWindowImpl *impl,
5983 cairo_region_t **region,
5988 cairo_region_t *tmp;
5991 for (l = window->children; l != NULL; l = l->next)
5995 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
5998 if (child->impl != impl)
6000 tmp = cairo_region_copy (child->clip_region);
6001 cairo_region_translate (tmp,
6002 x_offset + child->x,
6003 y_offset + child->y);
6004 if (*region == NULL)
6008 cairo_region_union (*region, tmp);
6009 cairo_region_destroy (tmp);
6013 collect_native_child_region_helper (child, impl, region,
6014 x_offset + child->x,
6015 y_offset + child->y);
6021 static cairo_region_t *
6022 collect_native_child_region (GdkWindow *window,
6023 gboolean include_this)
6025 cairo_region_t *region;
6027 if (include_this && gdk_window_has_impl (window) && window->viewable)
6028 return cairo_region_copy (window->clip_region);
6032 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6039 gdk_window_move_resize_internal (GdkWindow *window,
6046 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
6047 cairo_region_t *old_native_child_region, *new_native_child_region;
6048 GdkWindow *impl_window;
6049 GdkWindowImplClass *impl_class;
6051 int old_x, old_y, old_abs_x, old_abs_y;
6054 g_return_if_fail (GDK_IS_WINDOW (window));
6056 if (window->destroyed)
6059 if (gdk_window_is_toplevel (window))
6061 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6065 /* Bail early if no change */
6066 if (window->width == width &&
6067 window->height == height &&
6073 /* Handle child windows */
6079 impl_window = gdk_window_get_impl_window (window);
6084 old_native_child_region = NULL;
6085 if (gdk_window_is_viewable (window) &&
6086 !window->input_only)
6090 old_region = cairo_region_copy (window->clip_region);
6091 old_layered = cairo_region_copy (window->layered_region);
6092 /* Adjust regions to parent window coords */
6093 cairo_region_translate (old_region, window->x, window->y);
6094 cairo_region_translate (old_layered, window->x, window->y);
6096 old_native_child_region = collect_native_child_region (window, TRUE);
6097 if (old_native_child_region)
6099 /* Adjust region to parent window coords */
6100 cairo_region_translate (old_native_child_region, window->x, window->y);
6102 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6103 * source or destination for a delayed GdkWindowRegionMove. So, we need
6104 * to flush those here for the parent window and all overlapped subwindows
6105 * of it. And we need to do this before setting the new clips as those will be
6108 gdk_window_flush_recursive (window->parent);
6112 /* Set the new position and size */
6118 if (!(width < 0 && height < 0))
6122 window->width = width;
6125 window->height = height;
6128 dx = window->x - old_x;
6129 dy = window->y - old_y;
6131 old_abs_x = window->abs_x;
6132 old_abs_y = window->abs_y;
6134 recompute_visible_regions (window, TRUE, FALSE);
6136 new_native_child_region = NULL;
6137 if (old_native_child_region)
6139 new_native_child_region = collect_native_child_region (window, TRUE);
6140 /* Adjust region to parent window coords */
6141 cairo_region_translate (new_native_child_region, window->x, window->y);
6144 if (gdk_window_has_impl (window))
6146 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6148 /* Do the actual move after recomputing things, as this will have set the shape to
6149 the now correct one, thus avoiding copying regions that should not be copied. */
6150 impl_class->move_resize (window, TRUE,
6151 window->x, window->y,
6152 window->width, window->height);
6154 else if (old_abs_x != window->abs_x ||
6155 old_abs_y != window->abs_y)
6156 move_native_children (window);
6160 new_region = cairo_region_copy (window->clip_region);
6161 /* Adjust region to parent window coords */
6162 cairo_region_translate (new_region, window->x, window->y);
6165 * Part of the data at the new location can be copied from the
6166 * old location, this area is the intersection of the old region
6167 * moved as the copy will move it and then intersected with
6171 * Everything in the old and new regions that is not copied must be
6172 * invalidated (including children) as this is newly exposed
6174 if (gdk_window_has_alpha (window))
6175 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6177 copy_area = cairo_region_copy (new_region);
6179 /* Don't copy from a previously layered region */
6180 cairo_region_translate (old_layered, dx, dy);
6181 cairo_region_subtract (copy_area, old_layered);
6183 /* Don't copy into a layered region */
6184 cairo_region_translate (copy_area, -window->x, -window->y);
6185 cairo_region_subtract (copy_area, window->layered_region);
6186 cairo_region_translate (copy_area, window->x, window->y);
6188 cairo_region_union (new_region, old_region);
6190 if (old_native_child_region)
6192 /* Don't copy from inside native children, as this is copied by
6193 * the native window move.
6195 cairo_region_subtract (old_region, old_native_child_region);
6197 cairo_region_translate (old_region, dx, dy);
6199 cairo_region_intersect (copy_area, old_region);
6201 if (new_native_child_region)
6203 /* Don't copy any bits that would cause a read from the moved
6204 native windows, as we can't read that data */
6205 cairo_region_translate (new_native_child_region, dx, dy);
6206 cairo_region_subtract (copy_area, new_native_child_region);
6207 cairo_region_translate (new_native_child_region, -dx, -dy);
6210 cairo_region_subtract (new_region, copy_area);
6212 /* Convert old region to impl coords */
6213 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6215 /* convert from parent coords to impl */
6216 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6218 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6220 /* Invalidate affected part in the parent window
6221 * (no higher window should be affected)
6222 * We also invalidate any children in that area, which could include
6223 * this window if it still overlaps that area.
6225 if (old_native_child_region)
6227 /* No need to expose the region that the native window move copies */
6228 cairo_region_translate (old_native_child_region, dx, dy);
6229 cairo_region_intersect (old_native_child_region, new_native_child_region);
6230 cairo_region_subtract (new_region, old_native_child_region);
6232 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6234 cairo_region_destroy (old_region);
6235 cairo_region_destroy (old_layered);
6236 cairo_region_destroy (new_region);
6239 if (old_native_child_region)
6241 cairo_region_destroy (old_native_child_region);
6242 cairo_region_destroy (new_native_child_region);
6245 _gdk_synthesize_crossing_events_for_geometry_change (window);
6252 * @window: a #GdkWindow
6253 * @x: X coordinate relative to window's parent
6254 * @y: Y coordinate relative to window's parent
6256 * Repositions a window relative to its parent window.
6257 * For toplevel windows, window managers may ignore or modify the move;
6258 * you should probably use gtk_window_move() on a #GtkWindow widget
6259 * anyway, instead of using GDK functions. For child windows,
6260 * the move will reliably succeed.
6262 * If you're also planning to resize the window, use gdk_window_move_resize()
6263 * to both move and resize simultaneously, for a nicer visual effect.
6266 gdk_window_move (GdkWindow *window,
6270 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6274 * gdk_window_resize:
6275 * @window: a #GdkWindow
6276 * @width: new width of the window
6277 * @height: new height of the window
6279 * Resizes @window; for toplevel windows, asks the window manager to resize
6280 * the window. The window manager may not allow the resize. When using GTK+,
6281 * use gtk_window_resize() instead of this low-level GDK function.
6283 * Windows may not be resized below 1x1.
6285 * If you're also planning to move the window, use gdk_window_move_resize()
6286 * to both move and resize simultaneously, for a nicer visual effect.
6289 gdk_window_resize (GdkWindow *window,
6293 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6298 * gdk_window_move_resize:
6299 * @window: a #GdkWindow
6300 * @x: new X position relative to window's parent
6301 * @y: new Y position relative to window's parent
6303 * @height: new height
6305 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6306 * except that both operations are performed at once, avoiding strange
6307 * visual effects. (i.e. the user may be able to see the window first
6308 * move, then resize, if you don't use gdk_window_move_resize().)
6311 gdk_window_move_resize (GdkWindow *window,
6317 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6322 * gdk_window_scroll:
6323 * @window: a #GdkWindow
6324 * @dx: Amount to scroll in the X direction
6325 * @dy: Amount to scroll in the Y direction
6327 * Scroll the contents of @window, both pixels and children, by the
6328 * given amount. @window itself does not move. Portions of the window
6329 * that the scroll operation brings in from offscreen areas are
6330 * invalidated. The invalidated region may be bigger than what would
6331 * strictly be necessary.
6333 * For X11, a minimum area will be invalidated if the window has no
6334 * subwindows, or if the edges of the window's parent do not extend
6335 * beyond the edges of the window. In other cases, a multi-step process
6336 * is used to scroll the window which may produce temporary visual
6337 * artifacts and unnecessary invalidations.
6340 gdk_window_scroll (GdkWindow *window,
6344 GdkWindow *impl_window;
6345 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6346 cairo_region_t *old_native_child_region, *new_native_child_region;
6349 g_return_if_fail (GDK_IS_WINDOW (window));
6351 if (dx == 0 && dy == 0)
6354 if (window->destroyed)
6357 old_layered_area = cairo_region_copy (window->layered_region);
6358 old_native_child_region = collect_native_child_region (window, FALSE);
6359 if (old_native_child_region)
6361 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6362 * source or destination for a delayed GdkWindowRegionMove. So, we need
6363 * to flush those here for the window and all overlapped subwindows
6364 * of it. And we need to do this before setting the new clips as those will be
6367 gdk_window_flush_recursive (window);
6371 /* First move all child windows, without causing invalidation */
6373 tmp_list = window->children;
6376 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6378 /* Just update the positions, the bits will move with the copy */
6382 tmp_list = tmp_list->next;
6385 recompute_visible_regions (window, FALSE, TRUE);
6387 new_native_child_region = NULL;
6388 if (old_native_child_region)
6389 new_native_child_region = collect_native_child_region (window, FALSE);
6391 move_native_children (window);
6393 /* Then copy the actual bits of the window w/ child windows */
6395 impl_window = gdk_window_get_impl_window (window);
6397 /* Calculate the area that can be gotten by copying the old area */
6398 if (gdk_window_has_alpha (window))
6399 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6401 copy_area = cairo_region_copy (window->clip_region);
6402 cairo_region_subtract (copy_area, old_layered_area);
6403 if (old_native_child_region)
6405 /* Don't copy from inside native children, as this is copied by
6406 * the native window move.
6408 cairo_region_subtract (copy_area, old_native_child_region);
6410 /* Don't copy any bits that would cause a read from the moved
6411 native windows, as we can't read that data */
6412 cairo_region_subtract (copy_area, new_native_child_region);
6414 cairo_region_translate (copy_area, dx, dy);
6415 cairo_region_intersect (copy_area, window->clip_region);
6416 cairo_region_subtract (copy_area, window->layered_region);
6418 /* And the rest need to be invalidated */
6419 noncopy_area = cairo_region_copy (window->clip_region);
6420 cairo_region_subtract (noncopy_area, copy_area);
6422 /* convert from window coords to impl */
6423 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6425 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6427 /* Invalidate not copied regions */
6428 if (old_native_child_region)
6430 /* No need to expose the region that the native window move copies */
6431 cairo_region_translate (old_native_child_region, dx, dy);
6432 cairo_region_intersect (old_native_child_region, new_native_child_region);
6433 cairo_region_subtract (noncopy_area, old_native_child_region);
6435 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6437 cairo_region_destroy (noncopy_area);
6438 cairo_region_destroy (old_layered_area);
6440 if (old_native_child_region)
6442 cairo_region_destroy (old_native_child_region);
6443 cairo_region_destroy (new_native_child_region);
6446 _gdk_synthesize_crossing_events_for_geometry_change (window);
6450 * gdk_window_move_region:
6451 * @window: a #GdkWindow
6452 * @region: The #cairo_region_t to move
6453 * @dx: Amount to move in the X direction
6454 * @dy: Amount to move in the Y direction
6456 * Move the part of @window indicated by @region by @dy pixels in the Y
6457 * direction and @dx pixels in the X direction. The portions of @region
6458 * that not covered by the new position of @region are invalidated.
6460 * Child windows are not moved.
6465 gdk_window_move_region (GdkWindow *window,
6466 const cairo_region_t *region,
6470 GdkWindow *impl_window;
6471 cairo_region_t *nocopy_area;
6472 cairo_region_t *copy_area;
6474 g_return_if_fail (GDK_IS_WINDOW (window));
6475 g_return_if_fail (region != NULL);
6477 if (dx == 0 && dy == 0)
6480 if (window->destroyed)
6483 impl_window = gdk_window_get_impl_window (window);
6485 /* compute source regions */
6486 if (gdk_window_has_alpha (window))
6487 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6489 copy_area = cairo_region_copy (region);
6490 cairo_region_intersect (copy_area, window->clip_region_with_children);
6491 cairo_region_subtract (copy_area, window->layered_region);
6492 remove_layered_child_area (window, copy_area);
6494 /* compute destination regions */
6495 cairo_region_translate (copy_area, dx, dy);
6496 cairo_region_intersect (copy_area, window->clip_region_with_children);
6497 cairo_region_subtract (copy_area, window->layered_region);
6498 remove_layered_child_area (window, copy_area);
6500 /* Invalidate parts of the region (source and dest) not covered
6502 nocopy_area = cairo_region_copy (region);
6503 cairo_region_translate (nocopy_area, dx, dy);
6504 cairo_region_union (nocopy_area, region);
6505 cairo_region_subtract (nocopy_area, copy_area);
6507 /* convert from window coords to impl */
6508 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6509 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6511 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6512 cairo_region_destroy (nocopy_area);
6516 * gdk_window_set_background:
6517 * @window: a #GdkWindow
6518 * @color: a #GdkColor
6520 * Sets the background color of @window. (However, when using GTK+,
6521 * set the background of a widget with gtk_widget_modify_bg() - if
6522 * you're an application - or gtk_style_set_background() - if you're
6523 * implementing a custom widget.)
6525 * See also gdk_window_set_background_pattern().
6527 * Deprecated: 3.4: Use gdk_window_set_background_rgba() instead.
6530 gdk_window_set_background (GdkWindow *window,
6531 const GdkColor *color)
6533 cairo_pattern_t *pattern;
6535 g_return_if_fail (GDK_IS_WINDOW (window));
6537 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6538 color->green / 65535.,
6539 color->blue / 65535.);
6541 gdk_window_set_background_pattern (window, pattern);
6543 cairo_pattern_destroy (pattern);
6547 * gdk_window_set_background_rgba:
6548 * @window: a #GdkWindow
6549 * @rgba: a #GdkRGBA color
6551 * Sets the background color of @window.
6553 * See also gdk_window_set_background_pattern().
6556 gdk_window_set_background_rgba (GdkWindow *window,
6557 const GdkRGBA *rgba)
6559 cairo_pattern_t *pattern;
6561 g_return_if_fail (GDK_IS_WINDOW (window));
6562 g_return_if_fail (rgba != NULL);
6564 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6565 rgba->blue, rgba->alpha);
6567 gdk_window_set_background_pattern (window, pattern);
6569 cairo_pattern_destroy (pattern);
6573 /* Updates has_alpha_background recursively for all child windows
6574 that have parent-relative alpha */
6576 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6581 for (l = window->children; l; l = l->next)
6585 if (child->background == NULL &&
6586 child->has_alpha_background != window->has_alpha_background)
6588 child->has_alpha_background = window->has_alpha_background;
6589 recompute_visible_regions (child, TRUE, FALSE);
6590 _gdk_window_propagate_has_alpha_background (child);
6596 * gdk_window_set_background_pattern:
6597 * @window: a #GdkWindow
6598 * @pattern: (allow-none): a pattern to use, or %NULL
6600 * Sets the background of @window.
6602 * A background of %NULL means that the window will inherit its
6603 * background form its parent window.
6605 * The windowing system will normally fill a window with its background
6606 * when the window is obscured then exposed.
6609 gdk_window_set_background_pattern (GdkWindow *window,
6610 cairo_pattern_t *pattern)
6613 cairo_pattern_type_t type;
6615 g_return_if_fail (GDK_IS_WINDOW (window));
6617 if (window->input_only)
6621 cairo_pattern_reference (pattern);
6622 if (window->background)
6623 cairo_pattern_destroy (window->background);
6624 window->background = pattern;
6628 if (pattern == NULL)
6630 /* parent-relative, copy has_alpha from parent */
6631 if (window->parent == NULL ||
6632 window->parent->window_type == GDK_WINDOW_ROOT)
6635 has_alpha = window->parent->has_alpha_background;
6639 type = cairo_pattern_get_type (pattern);
6641 if (type == CAIRO_PATTERN_TYPE_SOLID)
6644 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6648 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6649 type == CAIRO_PATTERN_TYPE_RADIAL)
6655 cairo_pattern_get_color_stop_count (pattern, &n);
6657 for (i = 0; i < n; i++)
6659 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6660 NULL, NULL, NULL, &alpha);
6668 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6670 cairo_surface_t *surface;
6671 cairo_content_t content;
6673 cairo_pattern_get_surface (pattern, &surface);
6674 content = cairo_surface_get_content (surface);
6676 (content == CAIRO_CONTENT_ALPHA) ||
6677 (content == CAIRO_CONTENT_COLOR_ALPHA);
6681 if (has_alpha != window->has_alpha_background)
6683 window->has_alpha_background = has_alpha;
6684 recompute_visible_regions (window, TRUE, FALSE);
6686 _gdk_window_propagate_has_alpha_background (window);
6689 if (gdk_window_has_impl (window))
6691 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6692 impl_class->set_background (window, pattern);
6695 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6699 * gdk_window_get_background_pattern:
6702 * Gets the pattern used to clear the background on @window. If @window
6703 * does not have its own background and reuses the parent's, %NULL is
6704 * returned and you'll have to query it yourself.
6706 * Returns: (transfer none): The pattern to use for the background or
6707 * %NULL to use the parent's background.
6712 gdk_window_get_background_pattern (GdkWindow *window)
6714 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6716 return window->background;
6720 gdk_window_set_cursor_internal (GdkWindow *window,
6724 if (GDK_WINDOW_DESTROYED (window))
6727 if (window->window_type == GDK_WINDOW_ROOT ||
6728 window->window_type == GDK_WINDOW_FOREIGN)
6729 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6732 GdkPointerWindowInfo *pointer_info;
6733 GdkDisplay *display;
6735 display = gdk_window_get_display (window);
6736 pointer_info = _gdk_display_get_pointer_info (display, device);
6738 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6739 update_cursor (display, device);
6744 * gdk_window_get_cursor:
6745 * @window: a #GdkWindow
6747 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6748 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6749 * there is no custom cursor set on the specified window, and it is
6750 * using the cursor for its parent window.
6752 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6753 * object is owned by the #GdkWindow and should not be unreferenced
6754 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6760 gdk_window_get_cursor (GdkWindow *window)
6762 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6764 return window->cursor;
6768 * gdk_window_set_cursor:
6769 * @window: a #GdkWindow
6770 * @cursor: (allow-none): a cursor
6772 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6773 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6774 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6775 * to gdk_window_set_cursor() means that @window will use the cursor of its
6776 * parent window. Most windows should use this default.
6779 gdk_window_set_cursor (GdkWindow *window,
6782 GdkDisplay *display;
6784 g_return_if_fail (GDK_IS_WINDOW (window));
6786 display = gdk_window_get_display (window);
6790 g_object_unref (window->cursor);
6791 window->cursor = NULL;
6794 if (!GDK_WINDOW_DESTROYED (window))
6796 GdkDeviceManager *device_manager;
6800 window->cursor = g_object_ref (cursor);
6802 device_manager = gdk_display_get_device_manager (display);
6803 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6805 for (d = devices; d; d = d->next)
6811 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6814 gdk_window_set_cursor_internal (window, device, window->cursor);
6817 g_list_free (devices);
6818 g_object_notify (G_OBJECT (window), "cursor");
6823 * gdk_window_get_device_cursor:
6824 * @window: a #GdkWindow.
6825 * @device: a master, pointer #GdkDevice.
6827 * Retrieves a #GdkCursor pointer for the @device currently set on the
6828 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6829 * there is no custom cursor set on the specified window, and it is
6830 * using the cursor for its parent window.
6832 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6833 * object is owned by the #GdkWindow and should not be unreferenced
6834 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6840 gdk_window_get_device_cursor (GdkWindow *window,
6843 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6844 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6845 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6846 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6848 return g_hash_table_lookup (window->device_cursor, device);
6852 * gdk_window_set_device_cursor:
6853 * @window: a #Gdkwindow
6854 * @device: a master, pointer #GdkDevice
6855 * @cursor: a #GdkCursor
6857 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6858 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6859 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6860 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6861 * @window will use the cursor of its parent window. Most windows should
6867 gdk_window_set_device_cursor (GdkWindow *window,
6871 g_return_if_fail (GDK_IS_WINDOW (window));
6872 g_return_if_fail (GDK_IS_DEVICE (device));
6873 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6874 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6877 g_hash_table_remove (window->device_cursor, device);
6879 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6881 gdk_window_set_cursor_internal (window, device, cursor);
6885 * gdk_window_get_geometry:
6886 * @window: a #GdkWindow
6887 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6888 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6889 * @width: (out) (allow-none): return location for width of window
6890 * @height: (out) (allow-none): return location for height of window
6892 * Any of the return location arguments to this function may be %NULL,
6893 * if you aren't interested in getting the value of that field.
6895 * The X and Y coordinates returned are relative to the parent window
6896 * of @window, which for toplevels usually means relative to the
6897 * window decorations (titlebar, etc.) rather than relative to the
6898 * root window (screen-size background window).
6900 * On the X11 platform, the geometry is obtained from the X server,
6901 * so reflects the latest position of @window; this may be out-of-sync
6902 * with the position of @window delivered in the most-recently-processed
6903 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6904 * position from the most recent configure event.
6907 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6908 * to call gdk_window_get_position(), gdk_window_get_width() and
6909 * gdk_window_get_height() instead, because it avoids the roundtrip to
6910 * the X server and because these functions support the full 32-bit
6911 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6912 * the 16-bit coordinates of X11.
6916 gdk_window_get_geometry (GdkWindow *window,
6923 GdkWindowImplClass *impl_class;
6927 GDK_NOTE (MULTIHEAD,
6928 g_message ("gdk_window_get_geometry(): Window needs "
6929 "to be non-NULL to be multi head safe"));
6930 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6933 g_return_if_fail (GDK_IS_WINDOW (window));
6935 if (!GDK_WINDOW_DESTROYED (window))
6937 if (gdk_window_has_impl (window))
6939 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6940 impl_class->get_geometry (window, x, y,
6942 /* This reports the position wrt to the native parent, we need to convert
6943 it to be relative to the client side parent */
6944 parent = window->parent;
6945 if (parent && !gdk_window_has_impl (parent))
6948 *x -= parent->abs_x;
6950 *y -= parent->abs_y;
6960 *width = window->width;
6962 *height = window->height;
6968 * gdk_window_get_width:
6969 * @window: a #GdkWindow
6971 * Returns the width of the given @window.
6973 * On the X11 platform the returned size is the size reported in the
6974 * most-recently-processed configure event, rather than the current
6975 * size on the X server.
6977 * Returns: The width of @window
6982 gdk_window_get_width (GdkWindow *window)
6984 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6986 return window->width;
6990 * gdk_window_get_height:
6991 * @window: a #GdkWindow
6993 * Returns the height of the given @window.
6995 * On the X11 platform the returned size is the size reported in the
6996 * most-recently-processed configure event, rather than the current
6997 * size on the X server.
6999 * Returns: The height of @window
7004 gdk_window_get_height (GdkWindow *window)
7006 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7008 return window->height;
7012 * gdk_window_get_origin:
7013 * @window: a #GdkWindow
7014 * @x: (out) (allow-none): return location for X coordinate
7015 * @y: (out) (allow-none): return location for Y coordinate
7017 * Obtains the position of a window in root window coordinates.
7018 * (Compare with gdk_window_get_position() and
7019 * gdk_window_get_geometry() which return the position of a window
7020 * relative to its parent window.)
7022 * Return value: not meaningful, ignore
7025 gdk_window_get_origin (GdkWindow *window,
7029 GdkWindowImplClass *impl_class;
7031 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7033 if (GDK_WINDOW_DESTROYED (window))
7042 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7043 impl_class->get_root_coords (window,
7052 * gdk_window_get_root_coords:
7053 * @window: a #GdkWindow
7054 * @x: X coordinate in window
7055 * @y: Y coordinate in window
7056 * @root_x: (out): return location for X coordinate
7057 * @root_y: (out): return location for Y coordinate
7059 * Obtains the position of a window position in root
7060 * window coordinates. This is similar to
7061 * gdk_window_get_origin() but allows you go pass
7062 * in any position in the window, not just the origin.
7067 gdk_window_get_root_coords (GdkWindow *window,
7073 GdkWindowImplClass *impl_class;
7075 g_return_if_fail (GDK_IS_WINDOW (window));
7077 if (GDK_WINDOW_DESTROYED (window))
7084 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7085 impl_class->get_root_coords (window,
7092 * gdk_window_coords_to_parent:
7093 * @window: a child window
7094 * @x: X coordinate in child's coordinate system
7095 * @y: Y coordinate in child's coordinate system
7096 * @parent_x: (out) (allow-none): return location for X coordinate
7097 * in parent's coordinate system, or %NULL
7098 * @parent_y: (out) (allow-none): return location for Y coordinate
7099 * in parent's coordinate system, or %NULL
7101 * Transforms window coordinates from a child window to its parent
7102 * window, where the parent window is the normal parent as returned by
7103 * gdk_window_get_parent() for normal windows, and the window's
7104 * embedder as returned by gdk_offscreen_window_get_embedder() for
7105 * offscreen windows.
7107 * For normal windows, calling this function is equivalent to adding
7108 * the return values of gdk_window_get_position() to the child coordinates.
7109 * For offscreen windows however (which can be arbitrarily transformed),
7110 * this function calls the GdkWindow::to-embedder: signal to translate
7113 * You should always use this function when writing generic code that
7114 * walks up a window hierarchy.
7116 * See also: gdk_window_coords_from_parent()
7121 gdk_window_coords_to_parent (GdkWindow *window,
7127 g_return_if_fail (GDK_IS_WINDOW (window));
7129 if (gdk_window_is_offscreen (window))
7133 to_embedder (window, x, y, &px, &py);
7144 *parent_x = x + window->x;
7147 *parent_y = y + window->y;
7152 * gdk_window_coords_from_parent:
7153 * @window: a child window
7154 * @parent_x: X coordinate in parent's coordinate system
7155 * @parent_y: Y coordinate in parent's coordinate system
7156 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7157 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7159 * Transforms window coordinates from a parent window to a child
7160 * window, where the parent window is the normal parent as returned by
7161 * gdk_window_get_parent() for normal windows, and the window's
7162 * embedder as returned by gdk_offscreen_window_get_embedder() for
7163 * offscreen windows.
7165 * For normal windows, calling this function is equivalent to subtracting
7166 * the return values of gdk_window_get_position() from the parent coordinates.
7167 * For offscreen windows however (which can be arbitrarily transformed),
7168 * this function calls the GdkWindow::from-embedder: signal to translate
7171 * You should always use this function when writing generic code that
7172 * walks down a window hierarchy.
7174 * See also: gdk_window_coords_to_parent()
7179 gdk_window_coords_from_parent (GdkWindow *window,
7185 g_return_if_fail (GDK_IS_WINDOW (window));
7187 if (gdk_window_is_offscreen (window))
7191 from_embedder (window, parent_x, parent_y, &cx, &cy);
7202 *x = parent_x - window->x;
7205 *y = parent_y - window->y;
7210 * gdk_window_shape_combine_region:
7211 * @window: a #GdkWindow
7212 * @shape_region: (allow-none): region of window to be non-transparent
7213 * @offset_x: X position of @shape_region in @window coordinates
7214 * @offset_y: Y position of @shape_region in @window coordinates
7216 * Makes pixels in @window outside @shape_region be transparent,
7217 * so that the window may be nonrectangular.
7219 * If @shape_region is %NULL, the shape will be unset, so the whole
7220 * window will be opaque again. @offset_x and @offset_y are ignored
7221 * if @shape_region is %NULL.
7223 * On the X11 platform, this uses an X server extension which is
7224 * widely available on most common platforms, but not available on
7225 * very old X servers, and occasionally the implementation will be
7226 * buggy. On servers without the shape extension, this function
7229 * This function works on both toplevel and child windows.
7232 gdk_window_shape_combine_region (GdkWindow *window,
7233 const cairo_region_t *shape_region,
7237 cairo_region_t *old_region, *new_region, *diff;
7239 g_return_if_fail (GDK_IS_WINDOW (window));
7241 if (GDK_WINDOW_DESTROYED (window))
7244 if (!window->shape && shape_region == NULL)
7247 window->shaped = (shape_region != NULL);
7250 cairo_region_destroy (window->shape);
7253 if (GDK_WINDOW_IS_MAPPED (window))
7254 old_region = cairo_region_copy (window->clip_region);
7258 window->shape = cairo_region_copy (shape_region);
7259 cairo_region_translate (window->shape, offset_x, offset_y);
7262 window->shape = NULL;
7264 recompute_visible_regions (window, TRUE, FALSE);
7266 if (gdk_window_has_impl (window) &&
7267 !should_apply_clip_as_shape (window))
7268 apply_shape (window, window->shape);
7272 new_region = cairo_region_copy (window->clip_region);
7274 /* New area in the window, needs invalidation */
7275 diff = cairo_region_copy (new_region);
7276 cairo_region_subtract (diff, old_region);
7278 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7280 cairo_region_destroy (diff);
7282 if (!gdk_window_is_toplevel (window))
7284 /* New area in the non-root parent window, needs invalidation */
7285 diff = cairo_region_copy (old_region);
7286 cairo_region_subtract (diff, new_region);
7288 /* Adjust region to parent window coords */
7289 cairo_region_translate (diff, window->x, window->y);
7291 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7293 cairo_region_destroy (diff);
7296 cairo_region_destroy (new_region);
7297 cairo_region_destroy (old_region);
7302 do_child_shapes (GdkWindow *window,
7306 cairo_region_t *region;
7310 r.width = window->width;
7311 r.height = window->height;
7313 region = cairo_region_create_rectangle (&r);
7314 remove_child_area (window, NULL, FALSE, region, NULL);
7316 if (merge && window->shape)
7317 cairo_region_subtract (region, window->shape);
7319 gdk_window_shape_combine_region (window, region, 0, 0);
7323 * gdk_window_set_child_shapes:
7324 * @window: a #GdkWindow
7326 * Sets the shape mask of @window to the union of shape masks
7327 * for all children of @window, ignoring the shape mask of @window
7328 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7329 * the shape mask of @window in the masks to be merged.
7332 gdk_window_set_child_shapes (GdkWindow *window)
7334 g_return_if_fail (GDK_IS_WINDOW (window));
7336 do_child_shapes (window, FALSE);
7340 * gdk_window_merge_child_shapes:
7341 * @window: a #GdkWindow
7343 * Merges the shape masks for any child windows into the
7344 * shape mask for @window. i.e. the union of all masks
7345 * for @window and its children will become the new mask
7346 * for @window. See gdk_window_shape_combine_region().
7348 * This function is distinct from gdk_window_set_child_shapes()
7349 * because it includes @window's shape mask in the set of shapes to
7353 gdk_window_merge_child_shapes (GdkWindow *window)
7355 g_return_if_fail (GDK_IS_WINDOW (window));
7357 do_child_shapes (window, TRUE);
7361 * gdk_window_input_shape_combine_region:
7362 * @window: a #GdkWindow
7363 * @shape_region: region of window to be non-transparent
7364 * @offset_x: X position of @shape_region in @window coordinates
7365 * @offset_y: Y position of @shape_region in @window coordinates
7367 * Like gdk_window_shape_combine_region(), but the shape applies
7368 * only to event handling. Mouse events which happen while
7369 * the pointer position corresponds to an unset bit in the
7370 * mask will be passed on the window below @window.
7372 * An input shape is typically used with RGBA windows.
7373 * The alpha channel of the window defines which pixels are
7374 * invisible and allows for nicely antialiased borders,
7375 * and the input shape controls where the window is
7378 * On the X11 platform, this requires version 1.1 of the
7381 * On the Win32 platform, this functionality is not present and the
7382 * function does nothing.
7387 gdk_window_input_shape_combine_region (GdkWindow *window,
7388 const cairo_region_t *shape_region,
7392 GdkWindowImplClass *impl_class;
7394 g_return_if_fail (GDK_IS_WINDOW (window));
7396 if (GDK_WINDOW_DESTROYED (window))
7399 if (window->input_shape)
7400 cairo_region_destroy (window->input_shape);
7404 window->input_shape = cairo_region_copy (shape_region);
7405 cairo_region_translate (window->input_shape, offset_x, offset_y);
7408 window->input_shape = NULL;
7410 if (gdk_window_has_impl (window))
7412 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7413 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7416 /* Pointer may have e.g. moved outside window due to the input mask change */
7417 _gdk_synthesize_crossing_events_for_geometry_change (window);
7421 do_child_input_shapes (GdkWindow *window,
7425 cairo_region_t *region;
7429 r.width = window->width;
7430 r.height = window->height;
7432 region = cairo_region_create_rectangle (&r);
7433 remove_child_area (window, NULL, TRUE, region, NULL);
7435 if (merge && window->shape)
7436 cairo_region_subtract (region, window->shape);
7437 if (merge && window->input_shape)
7438 cairo_region_subtract (region, window->input_shape);
7440 gdk_window_input_shape_combine_region (window, region, 0, 0);
7445 * gdk_window_set_child_input_shapes:
7446 * @window: a #GdkWindow
7448 * Sets the input shape mask of @window to the union of input shape masks
7449 * for all children of @window, ignoring the input shape mask of @window
7450 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7451 * the input shape mask of @window in the masks to be merged.
7456 gdk_window_set_child_input_shapes (GdkWindow *window)
7458 g_return_if_fail (GDK_IS_WINDOW (window));
7460 do_child_input_shapes (window, FALSE);
7464 * gdk_window_merge_child_input_shapes:
7465 * @window: a #GdkWindow
7467 * Merges the input shape masks for any child windows into the
7468 * input shape mask for @window. i.e. the union of all input masks
7469 * for @window and its children will become the new input mask
7470 * for @window. See gdk_window_input_shape_combine_region().
7472 * This function is distinct from gdk_window_set_child_input_shapes()
7473 * because it includes @window's input shape mask in the set of
7474 * shapes to be merged.
7479 gdk_window_merge_child_input_shapes (GdkWindow *window)
7481 g_return_if_fail (GDK_IS_WINDOW (window));
7483 do_child_input_shapes (window, TRUE);
7488 * gdk_window_set_static_gravities:
7489 * @window: a #GdkWindow
7490 * @use_static: %TRUE to turn on static gravity
7492 * Set the bit gravity of the given window to static, and flag it so
7493 * all children get static subwindow gravity. This is used if you are
7494 * implementing scary features that involve deep knowledge of the
7495 * windowing system. Don't worry about it unless you have to.
7497 * Return value: %TRUE if the server supports static gravity
7500 gdk_window_set_static_gravities (GdkWindow *window,
7501 gboolean use_static)
7503 GdkWindowImplClass *impl_class;
7505 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7507 if (gdk_window_has_impl (window))
7509 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7510 return impl_class->set_static_gravities (window, use_static);
7517 * gdk_window_get_composited:
7518 * @window: a #GdkWindow
7520 * Determines whether @window is composited.
7522 * See gdk_window_set_composited().
7524 * Returns: %TRUE if the window is composited.
7529 gdk_window_get_composited (GdkWindow *window)
7531 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7533 return window->composited;
7537 * gdk_window_set_composited:
7538 * @window: a #GdkWindow
7539 * @composited: %TRUE to set the window as composited
7541 * Sets a #GdkWindow as composited, or unsets it. Composited
7542 * windows do not automatically have their contents drawn to
7543 * the screen. Drawing is redirected to an offscreen buffer
7544 * and an expose event is emitted on the parent of the composited
7545 * window. It is the responsibility of the parent's expose handler
7546 * to manually merge the off-screen content onto the screen in
7547 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7550 * It only makes sense for child windows to be composited; see
7551 * gdk_window_set_opacity() if you need translucent toplevel
7554 * An additional effect of this call is that the area of this
7555 * window is no longer clipped from regions marked for
7556 * invalidation on its parent. Draws done on the parent
7557 * window are also no longer clipped by the child.
7559 * This call is only supported on some systems (currently,
7560 * only X11 with new enough Xcomposite and Xdamage extensions).
7561 * You must call gdk_display_supports_composite() to check if
7562 * setting a window as composited is supported before
7563 * attempting to do so.
7568 gdk_window_set_composited (GdkWindow *window,
7569 gboolean composited)
7571 GdkDisplay *display;
7572 GdkWindowImplClass *impl_class;
7574 g_return_if_fail (GDK_IS_WINDOW (window));
7576 composited = composited != FALSE;
7578 if (window->composited == composited)
7582 gdk_window_ensure_native (window);
7584 display = gdk_window_get_display (window);
7586 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7588 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7590 g_warning ("gdk_window_set_composited called but "
7591 "compositing is not supported");
7595 impl_class->set_composited (window, composited);
7597 recompute_visible_regions (window, TRUE, FALSE);
7599 if (GDK_WINDOW_IS_MAPPED (window))
7600 gdk_window_invalidate_in_parent (window);
7602 window->composited = composited;
7606 * gdk_window_get_modal_hint:
7607 * @window: A toplevel #GdkWindow.
7609 * Determines whether or not the window manager is hinted that @window
7610 * has modal behaviour.
7612 * Return value: whether or not the window has the modal hint set.
7617 gdk_window_get_modal_hint (GdkWindow *window)
7619 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7621 return window->modal_hint;
7625 * gdk_window_get_accept_focus:
7626 * @window: a toplevel #GdkWindow.
7628 * Determines whether or not the desktop environment shuld be hinted that
7629 * the window does not want to receive input focus.
7631 * Return value: whether or not the window should receive input focus.
7636 gdk_window_get_accept_focus (GdkWindow *window)
7638 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7640 return window->accept_focus;
7644 * gdk_window_get_focus_on_map:
7645 * @window: a toplevel #GdkWindow.
7647 * Determines whether or not the desktop environment should be hinted that the
7648 * window does not want to receive input focus when it is mapped.
7650 * Return value: whether or not the window wants to receive input focus when
7656 gdk_window_get_focus_on_map (GdkWindow *window)
7658 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7660 return window->focus_on_map;
7664 * gdk_window_is_input_only:
7665 * @window: a toplevel #GdkWindow
7667 * Determines whether or not the window is an input only window.
7669 * Return value: %TRUE if @window is input only
7674 gdk_window_is_input_only (GdkWindow *window)
7676 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7678 return window->input_only;
7682 * gdk_window_is_shaped:
7683 * @window: a toplevel #GdkWindow
7685 * Determines whether or not the window is shaped.
7687 * Return value: %TRUE if @window is shaped
7692 gdk_window_is_shaped (GdkWindow *window)
7694 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7696 return window->shaped;
7700 _gdk_window_add_damage (GdkWindow *toplevel,
7701 cairo_region_t *damaged_region)
7703 GdkDisplay *display;
7704 GdkEvent event = { 0, };
7705 event.expose.type = GDK_DAMAGE;
7706 event.expose.window = toplevel;
7707 event.expose.send_event = FALSE;
7708 event.expose.region = damaged_region;
7709 cairo_region_get_extents (event.expose.region, &event.expose.area);
7710 display = gdk_window_get_display (event.expose.window);
7711 _gdk_event_queue_append (display, gdk_event_copy (&event));
7714 /* Gets the toplevel for a window as used for events,
7715 i.e. including offscreen parents */
7717 get_event_parent (GdkWindow *window)
7719 if (gdk_window_is_offscreen (window))
7720 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7722 return window->parent;
7725 /* Gets the toplevel for a window as used for events,
7726 i.e. including offscreen parents going up to the native
7729 get_event_toplevel (GdkWindow *window)
7733 while ((parent = get_event_parent (window)) != NULL &&
7734 (parent->window_type != GDK_WINDOW_ROOT))
7741 _gdk_window_event_parent_of (GdkWindow *parent,
7752 w = get_event_parent (w);
7759 update_cursor (GdkDisplay *display,
7762 GdkWindow *cursor_window, *parent, *toplevel;
7763 GdkWindow *pointer_window;
7764 GdkWindowImplClass *impl_class;
7765 GdkPointerWindowInfo *pointer_info;
7766 GdkDeviceGrabInfo *grab;
7769 pointer_info = _gdk_display_get_pointer_info (display, device);
7770 pointer_window = pointer_info->window_under_pointer;
7772 /* We ignore the serials here and just pick the last grab
7773 we've sent, as that would shortly be used anyway. */
7774 grab = _gdk_display_get_last_device_grab (display, device);
7777 /* the pointer is not in a descendant of the grab window */
7778 !_gdk_window_event_parent_of (grab->window, pointer_window))
7780 /* use the cursor from the grab window */
7781 cursor_window = grab->window;
7785 /* otherwise use the cursor from the pointer window */
7786 cursor_window = pointer_window;
7789 /* Find the first window with the cursor actually set, as
7790 the cursor is inherited from the parent */
7791 while (cursor_window->cursor == NULL &&
7792 (parent = get_event_parent (cursor_window)) != NULL &&
7793 parent->window_type != GDK_WINDOW_ROOT)
7794 cursor_window = parent;
7796 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7799 cursor = cursor_window->cursor;
7801 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7802 * which native window has what cursor set. */
7803 toplevel = get_event_toplevel (pointer_window);
7804 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7805 impl_class->set_device_cursor (toplevel, device, cursor);
7809 point_in_window (GdkWindow *window,
7814 x >= 0 && x < window->width &&
7815 y >= 0 && y < window->height &&
7816 (window->shape == NULL ||
7817 cairo_region_contains_point (window->shape,
7819 (window->input_shape == NULL ||
7820 cairo_region_contains_point (window->input_shape,
7825 convert_native_coords_to_toplevel (GdkWindow *window,
7828 gdouble *toplevel_x,
7829 gdouble *toplevel_y)
7836 while (!gdk_window_is_toplevel (window))
7840 window = window->parent;
7850 convert_toplevel_coords_to_window (GdkWindow *window,
7858 GList *children, *l;
7864 while ((parent = get_event_parent (window)) != NULL &&
7865 (parent->window_type != GDK_WINDOW_ROOT))
7867 children = g_list_prepend (children, window);
7871 for (l = children; l != NULL; l = l->next)
7872 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7874 g_list_free (children);
7881 pick_embedded_child (GdkWindow *window,
7888 g_signal_emit (window,
7889 signals[PICK_EMBEDDED_CHILD], 0,
7896 _gdk_window_find_child_at (GdkWindow *window,
7901 double child_x, child_y;
7904 if (point_in_window (window, x, y))
7906 /* Children is ordered in reverse stack order, i.e. first is topmost */
7907 for (l = window->children; l != NULL; l = l->next)
7911 if (!GDK_WINDOW_IS_MAPPED (sub))
7914 gdk_window_coords_from_parent ((GdkWindow *)sub,
7916 &child_x, &child_y);
7917 if (point_in_window (sub, child_x, child_y))
7918 return (GdkWindow *)sub;
7921 if (window->num_offscreen_children > 0)
7923 sub = pick_embedded_child (window,
7926 return (GdkWindow *)sub;
7934 _gdk_window_find_descendant_at (GdkWindow *window,
7941 gdouble child_x, child_y;
7945 if (point_in_window (window, x, y))
7950 /* Children is ordered in reverse stack order, i.e. first is topmost */
7951 for (l = window->children; l != NULL; l = l->next)
7955 if (!GDK_WINDOW_IS_MAPPED (sub))
7958 gdk_window_coords_from_parent ((GdkWindow *)sub,
7960 &child_x, &child_y);
7961 if (point_in_window (sub, child_x, child_y))
7971 window->num_offscreen_children > 0)
7973 sub = pick_embedded_child (window,
7979 from_embedder (sub, x, y, &x, &y);
7987 /* Not in window at all */
8001 * @window: a toplevel #GdkWindow
8003 * Emits a short beep associated to @window in the appropriate
8004 * display, if supported. Otherwise, emits a short beep on
8005 * the display just as gdk_display_beep().
8010 gdk_window_beep (GdkWindow *window)
8012 GdkDisplay *display;
8013 GdkWindow *toplevel;
8015 g_return_if_fail (GDK_IS_WINDOW (window));
8017 if (GDK_WINDOW_DESTROYED (window))
8020 toplevel = get_event_toplevel (window);
8021 display = gdk_window_get_display (window);
8025 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
8029 /* If windows fail to beep, we beep the display. */
8030 gdk_display_beep (display);
8034 * gdk_window_set_support_multidevice:
8035 * @window: a #GdkWindow.
8036 * @support_multidevice: %TRUE to enable multidevice support in @window.
8038 * This function will enable multidevice features in @window.
8040 * Multidevice aware windows will need to handle properly multiple,
8041 * per device enter/leave events, device grabs and grab ownerships.
8046 gdk_window_set_support_multidevice (GdkWindow *window,
8047 gboolean support_multidevice)
8049 g_return_if_fail (GDK_IS_WINDOW (window));
8051 if (GDK_WINDOW_DESTROYED (window))
8054 if (window->support_multidevice == support_multidevice)
8057 window->support_multidevice = support_multidevice;
8059 /* FIXME: What to do if called when some pointers are inside the window ? */
8063 * gdk_window_get_support_multidevice:
8064 * @window: a #GdkWindow.
8066 * Returns %TRUE if the window is aware of the existence of multiple
8069 * Returns: %TRUE if the window handles multidevice features.
8074 gdk_window_get_support_multidevice (GdkWindow *window)
8076 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8078 if (GDK_WINDOW_DESTROYED (window))
8081 return window->support_multidevice;
8084 static const guint type_masks[] = {
8085 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8086 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8087 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8088 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8089 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8090 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8091 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8092 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8093 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8094 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8095 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8096 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8097 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8098 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8099 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8100 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8101 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8102 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8103 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8104 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8105 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8106 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8107 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8108 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8109 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8110 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8111 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8112 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8113 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8114 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8115 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8116 GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK,/* GDK_SCROLL= 31 */
8117 0, /* GDK_WINDOW_STATE = 32 */
8118 0, /* GDK_SETTING = 33 */
8119 0, /* GDK_OWNER_CHANGE = 34 */
8120 0, /* GDK_GRAB_BROKEN = 35 */
8121 0, /* GDK_DAMAGE = 36 */
8122 GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */
8123 GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */
8124 GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */
8125 GDK_TOUCH_MASK /* GDK_TOUCH_CANCEL = 40 */
8127 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8129 /* send motion events if the right buttons are down */
8131 update_evmask_for_button_motion (guint evmask,
8132 GdkModifierType mask)
8134 if (evmask & GDK_BUTTON_MOTION_MASK &&
8135 mask & (GDK_BUTTON1_MASK |
8140 evmask |= GDK_POINTER_MOTION_MASK;
8142 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8143 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8144 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8145 evmask |= GDK_POINTER_MOTION_MASK;
8151 is_button_type (GdkEventType type)
8153 return type == GDK_BUTTON_PRESS ||
8154 type == GDK_2BUTTON_PRESS ||
8155 type == GDK_3BUTTON_PRESS ||
8156 type == GDK_BUTTON_RELEASE ||
8157 type == GDK_TOUCH_BEGIN ||
8158 type == GDK_TOUCH_END ||
8163 is_motion_type (GdkEventType type)
8165 return type == GDK_MOTION_NOTIFY ||
8166 type == GDK_TOUCH_UPDATE ||
8167 type == GDK_ENTER_NOTIFY ||
8168 type == GDK_LEAVE_NOTIFY;
8172 is_touch_type (GdkEventType type)
8174 return type == GDK_TOUCH_BEGIN ||
8175 type == GDK_TOUCH_UPDATE ||
8176 type == GDK_TOUCH_END ||
8177 type == GDK_TOUCH_CANCEL;
8181 find_common_ancestor (GdkWindow *win1,
8185 GList *path1 = NULL, *path2 = NULL;
8186 GList *list1, *list2;
8189 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8191 path1 = g_list_prepend (path1, tmp);
8192 tmp = get_event_parent (tmp);
8196 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8198 path2 = g_list_prepend (path2, tmp);
8199 tmp = get_event_parent (tmp);
8205 while (list1 && list2 && (list1->data == list2->data))
8208 list1 = g_list_next (list1);
8209 list2 = g_list_next (list2);
8211 g_list_free (path1);
8212 g_list_free (path2);
8218 _gdk_make_event (GdkWindow *window,
8220 GdkEvent *event_in_queue,
8221 gboolean before_event)
8223 GdkEvent *event = gdk_event_new (type);
8225 GdkModifierType the_state;
8227 the_time = gdk_event_get_time (event_in_queue);
8228 gdk_event_get_state (event_in_queue, &the_state);
8230 event->any.window = g_object_ref (window);
8231 event->any.send_event = FALSE;
8232 if (event_in_queue && event_in_queue->any.send_event)
8233 event->any.send_event = TRUE;
8237 case GDK_MOTION_NOTIFY:
8238 event->motion.time = the_time;
8239 event->motion.axes = NULL;
8240 event->motion.state = the_state;
8243 case GDK_BUTTON_PRESS:
8244 case GDK_2BUTTON_PRESS:
8245 case GDK_3BUTTON_PRESS:
8246 case GDK_BUTTON_RELEASE:
8247 event->button.time = the_time;
8248 event->button.axes = NULL;
8249 event->button.state = the_state;
8252 case GDK_TOUCH_BEGIN:
8253 case GDK_TOUCH_UPDATE:
8255 case GDK_TOUCH_CANCEL:
8256 event->touch.time = the_time;
8257 event->touch.axes = NULL;
8258 event->touch.state = the_state;
8262 event->scroll.time = the_time;
8263 event->scroll.state = the_state;
8267 case GDK_KEY_RELEASE:
8268 event->key.time = the_time;
8269 event->key.state = the_state;
8272 case GDK_ENTER_NOTIFY:
8273 case GDK_LEAVE_NOTIFY:
8274 event->crossing.time = the_time;
8275 event->crossing.state = the_state;
8278 case GDK_PROPERTY_NOTIFY:
8279 event->property.time = the_time;
8280 event->property.state = the_state;
8283 case GDK_SELECTION_CLEAR:
8284 case GDK_SELECTION_REQUEST:
8285 case GDK_SELECTION_NOTIFY:
8286 event->selection.time = the_time;
8289 case GDK_PROXIMITY_IN:
8290 case GDK_PROXIMITY_OUT:
8291 event->proximity.time = the_time;
8294 case GDK_DRAG_ENTER:
8295 case GDK_DRAG_LEAVE:
8296 case GDK_DRAG_MOTION:
8297 case GDK_DRAG_STATUS:
8298 case GDK_DROP_START:
8299 case GDK_DROP_FINISHED:
8300 event->dnd.time = the_time;
8303 case GDK_FOCUS_CHANGE:
8307 case GDK_CLIENT_EVENT:
8308 case GDK_VISIBILITY_NOTIFY:
8319 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8321 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8324 _gdk_event_queue_append (gdk_window_get_display (window), event);
8330 send_crossing_event (GdkDisplay *display,
8331 GdkWindow *toplevel,
8334 GdkCrossingMode mode,
8335 GdkNotifyType notify_type,
8336 GdkWindow *subwindow,
8338 GdkDevice *source_device,
8341 GdkModifierType mask,
8343 GdkEvent *event_in_queue,
8347 guint32 window_event_mask, type_event_mask;
8348 GdkDeviceGrabInfo *grab;
8349 GdkTouchGrabInfo *touch_grab = NULL;
8350 GdkPointerWindowInfo *pointer_info;
8351 gboolean block_event = FALSE;
8352 GdkEventSequence *sequence;
8354 grab = _gdk_display_has_device_grab (display, device, serial);
8355 pointer_info = _gdk_display_get_pointer_info (display, device);
8357 sequence = gdk_event_get_event_sequence (event_in_queue);
8359 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
8363 if (window != touch_grab->window)
8366 window_event_mask = touch_grab->event_mask;
8368 else if (grab != NULL &&
8369 !grab->owner_events)
8371 /* !owner_event => only report events wrt grab window, ignore rest */
8372 if ((GdkWindow *)window != grab->window)
8374 window_event_mask = grab->event_mask;
8377 window_event_mask = window->event_mask;
8379 if (type == GDK_ENTER_NOTIFY &&
8380 (pointer_info->need_touch_press_enter ||
8381 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN) &&
8382 mode != GDK_CROSSING_TOUCH_BEGIN &&
8383 mode != GDK_CROSSING_TOUCH_END)
8385 pointer_info->need_touch_press_enter = TRUE;
8388 else if (type == GDK_LEAVE_NOTIFY)
8390 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8391 window->devices_inside = g_list_remove (window->devices_inside, device);
8393 if (!window->support_multidevice && window->devices_inside)
8395 /* Block leave events unless it's the last pointer */
8401 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8403 if (!window->support_multidevice && window->devices_inside)
8405 /* Only emit enter events for the first device */
8409 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8410 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8411 !g_list_find (window->devices_inside, device))
8412 window->devices_inside = g_list_prepend (window->devices_inside, device);
8418 if (window_event_mask & type_event_mask)
8420 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8421 gdk_event_set_device (event, device);
8424 gdk_event_set_source_device (event, source_device);
8426 event->crossing.time = time_;
8427 event->crossing.subwindow = subwindow;
8429 g_object_ref (subwindow);
8430 convert_toplevel_coords_to_window ((GdkWindow *)window,
8431 toplevel_x, toplevel_y,
8432 &event->crossing.x, &event->crossing.y);
8433 event->crossing.x_root = toplevel_x + toplevel->x;
8434 event->crossing.y_root = toplevel_y + toplevel->y;
8435 event->crossing.mode = mode;
8436 event->crossing.detail = notify_type;
8437 event->crossing.focus = FALSE;
8438 event->crossing.state = mask;
8443 /* The coordinates are in the toplevel window that src/dest are in.
8444 * src and dest are always (if != NULL) in the same toplevel, as
8445 * we get a leave-notify and set the window_under_pointer to null
8446 * before crossing to another toplevel.
8449 _gdk_synthesize_crossing_events (GdkDisplay *display,
8453 GdkDevice *source_device,
8454 GdkCrossingMode mode,
8457 GdkModifierType mask,
8459 GdkEvent *event_in_queue,
8461 gboolean non_linear)
8464 GdkWindow *win, *last, *next;
8468 GdkWindow *toplevel;
8469 GdkNotifyType notify_type;
8471 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8476 return; /* No crossings generated between src and dest */
8478 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8480 if (a && gdk_window_get_device_events (src, device) == 0)
8483 if (b && gdk_window_get_device_events (dest, device) == 0)
8490 c = find_common_ancestor (a, b);
8492 non_linear |= (c != a) && (c != b);
8494 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8496 toplevel = gdk_window_get_toplevel (a);
8498 /* Traverse up from a to (excluding) c sending leave events */
8500 notify_type = GDK_NOTIFY_NONLINEAR;
8502 notify_type = GDK_NOTIFY_INFERIOR;
8504 notify_type = GDK_NOTIFY_ANCESTOR;
8505 send_crossing_event (display, toplevel,
8506 a, GDK_LEAVE_NOTIFY,
8509 NULL, device, source_device,
8510 toplevel_x, toplevel_y,
8518 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8520 notify_type = GDK_NOTIFY_VIRTUAL;
8523 win = get_event_parent (a);
8524 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8526 send_crossing_event (display, toplevel,
8527 win, GDK_LEAVE_NOTIFY,
8531 device, source_device,
8532 toplevel_x, toplevel_y,
8538 win = get_event_parent (win);
8543 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8545 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8547 /* Traverse down from c to b */
8551 win = get_event_parent (b);
8552 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8554 path = g_list_prepend (path, win);
8555 win = get_event_parent (win);
8559 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8561 notify_type = GDK_NOTIFY_VIRTUAL;
8567 list = g_list_next (list);
8573 send_crossing_event (display, toplevel,
8574 win, GDK_ENTER_NOTIFY,
8578 device, source_device,
8579 toplevel_x, toplevel_y,
8589 notify_type = GDK_NOTIFY_NONLINEAR;
8591 notify_type = GDK_NOTIFY_ANCESTOR;
8593 notify_type = GDK_NOTIFY_INFERIOR;
8595 send_crossing_event (display, toplevel,
8596 b, GDK_ENTER_NOTIFY,
8600 device, source_device,
8601 toplevel_x, toplevel_y,
8608 /* Returns the window inside the event window with the pointer in it
8609 * at the specified coordinates, or NULL if its not in any child of
8610 * the toplevel. It also takes into account !owner_events grabs.
8613 get_pointer_window (GdkDisplay *display,
8614 GdkWindow *event_window,
8620 GdkWindow *pointer_window;
8621 GdkDeviceGrabInfo *grab;
8622 GdkPointerWindowInfo *pointer_info;
8624 pointer_info = _gdk_display_get_pointer_info (display, device);
8626 if (event_window == pointer_info->toplevel_under_pointer)
8628 _gdk_window_find_descendant_at (event_window,
8629 toplevel_x, toplevel_y,
8632 pointer_window = NULL;
8634 grab = _gdk_display_has_device_grab (display, device, serial);
8636 !grab->owner_events &&
8637 pointer_window != grab->window)
8638 pointer_window = NULL;
8640 return pointer_window;
8644 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8648 GdkPointerWindowInfo *device_info;
8650 device_info = _gdk_display_get_pointer_info (display, device);
8652 if (device_info->window_under_pointer)
8653 g_object_unref (device_info->window_under_pointer);
8654 device_info->window_under_pointer = window;
8658 g_object_ref (window);
8659 update_cursor (display, device);
8662 _gdk_display_enable_motion_hints (display, device);
8667 * @window: the #GdkWindow which will own the grab (the grab window).
8668 * @owner_events: if %FALSE then all pointer events are reported with respect to
8669 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8670 * events for this application are reported as normal, but pointer events outside
8671 * this application are reported with respect to @window and only if selected by
8672 * @event_mask. In either mode, unreported events are discarded.
8673 * @event_mask: specifies the event mask, which is used in accordance with
8674 * @owner_events. Note that only pointer events (i.e. button and motion events)
8676 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8677 * window during the grab. If the pointer is outside @confine_to, it will
8678 * automatically be moved to the closest edge of @confine_to and enter
8679 * and leave events will be generated as necessary.
8680 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8681 * the normal cursors are used for @window and its descendants, and the cursor
8682 * for @window is used for all other windows.
8683 * @time_: the timestamp of the event which led to this pointer grab. This usually
8684 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8685 * the time isn't known.
8687 * Grabs the pointer (usually a mouse) so that all events are passed to this
8688 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8689 * the grab window becomes unviewable.
8690 * This overrides any previous pointer grab by this client.
8692 * Pointer grabs are used for operations which need complete control over mouse
8693 * events, even if the mouse leaves the application.
8694 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8695 * the #GtkHPaned and #GtkVPaned widgets.
8697 * Note that if the event mask of an X window has selected both button press and
8698 * button release events, then a button press event will cause an automatic
8699 * pointer grab until the button is released.
8700 * X does this automatically since most applications expect to receive button
8701 * press and release events in pairs.
8702 * It is equivalent to a pointer grab on the window with @owner_events set to
8705 * If you set up anything at the time you take the grab that needs to be cleaned
8706 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8707 * are emitted when the grab ends unvoluntarily.
8709 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8711 * Deprecated: 3.0: Use gdk_device_grab() instead.
8714 gdk_pointer_grab (GdkWindow * window,
8715 gboolean owner_events,
8716 GdkEventMask event_mask,
8717 GdkWindow * confine_to,
8722 GdkDisplay *display;
8723 GdkDeviceManager *device_manager;
8725 GdkGrabStatus res = 0;
8727 GList *devices, *dev;
8729 g_return_val_if_fail (window != NULL, 0);
8730 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8731 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8733 /* We need a native window for confine to to work, ensure we have one */
8736 if (!gdk_window_ensure_native (confine_to))
8738 g_warning ("Can't confine to grabbed window, not native");
8743 /* Non-viewable client side window => fail */
8744 if (!_gdk_window_has_impl (window) &&
8745 !gdk_window_is_viewable (window))
8746 return GDK_GRAB_NOT_VIEWABLE;
8748 native = gdk_window_get_toplevel (window);
8749 while (gdk_window_is_offscreen (native))
8751 native = gdk_offscreen_window_get_embedder (native);
8753 if (native == NULL ||
8754 (!_gdk_window_has_impl (native) &&
8755 !gdk_window_is_viewable (native)))
8756 return GDK_GRAB_NOT_VIEWABLE;
8758 native = gdk_window_get_toplevel (native);
8761 display = gdk_window_get_display (window);
8763 serial = _gdk_display_get_next_serial (display);
8764 device_manager = gdk_display_get_device_manager (display);
8765 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8767 /* FIXME: Should this be generic to all backends? */
8768 /* FIXME: What happens with extended devices? */
8769 for (dev = devices; dev; dev = dev->next)
8773 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8776 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8779 get_native_grab_event_mask (event_mask),
8784 if (res == GDK_GRAB_SUCCESS)
8785 _gdk_display_add_device_grab (display,
8797 /* FIXME: handle errors when grabbing */
8799 g_list_free (devices);
8805 * gdk_keyboard_grab:
8806 * @window: the #GdkWindow which will own the grab (the grab window).
8807 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8808 * @window. If %TRUE then keyboard events for this application are
8809 * reported as normal, but keyboard events outside this application
8810 * are reported with respect to @window. Both key press and key
8811 * release events are always reported, independant of the event mask
8812 * set by the application.
8813 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8816 * Grabs the keyboard so that all events are passed to this
8817 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8818 * This overrides any previous keyboard grab by this client.
8820 * If you set up anything at the time you take the grab that needs to be cleaned
8821 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8822 * are emitted when the grab ends unvoluntarily.
8824 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8826 * Deprecated: 3.0: Use gdk_device_grab() instead.
8829 gdk_keyboard_grab (GdkWindow *window,
8830 gboolean owner_events,
8834 GdkDisplay *display;
8835 GdkDeviceManager *device_manager;
8837 GdkGrabStatus res = 0;
8839 GList *devices, *dev;
8841 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8843 /* Non-viewable client side window => fail */
8844 if (!_gdk_window_has_impl (window) &&
8845 !gdk_window_is_viewable (window))
8846 return GDK_GRAB_NOT_VIEWABLE;
8848 native = gdk_window_get_toplevel (window);
8850 while (gdk_window_is_offscreen (native))
8852 native = gdk_offscreen_window_get_embedder (native);
8854 if (native == NULL ||
8855 (!_gdk_window_has_impl (native) &&
8856 !gdk_window_is_viewable (native)))
8857 return GDK_GRAB_NOT_VIEWABLE;
8859 native = gdk_window_get_toplevel (native);
8862 display = gdk_window_get_display (window);
8863 serial = _gdk_display_get_next_serial (display);
8864 device_manager = gdk_display_get_device_manager (display);
8865 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8867 /* FIXME: Should this be generic to all backends? */
8868 /* FIXME: What happens with extended devices? */
8869 for (dev = devices; dev; dev = dev->next)
8873 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8876 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8879 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8884 if (res == GDK_GRAB_SUCCESS)
8885 _gdk_display_add_device_grab (display,
8896 /* FIXME: handle errors when grabbing */
8898 g_list_free (devices);
8904 * gdk_window_geometry_changed:
8905 * @window: an embedded offscreen #GdkWindow
8907 * This function informs GDK that the geometry of an embedded
8908 * offscreen window has changed. This is necessary for GDK to keep
8909 * track of which offscreen window the pointer is in.
8914 gdk_window_geometry_changed (GdkWindow *window)
8916 _gdk_synthesize_crossing_events_for_geometry_change (window);
8920 source_events_device_added (GdkDeviceManager *device_manager,
8925 GdkEventMask event_mask;
8926 GdkInputSource source;
8928 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
8932 source = gdk_device_get_source (device);
8934 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8935 GINT_TO_POINTER (source)));
8937 gdk_window_set_device_events (window, device, event_mask);
8941 source_events_device_changed (GdkDeviceManager *device_manager,
8946 GdkInputSource source;
8947 GdkEventMask event_mask;
8951 type = gdk_device_get_device_type (device);
8952 source = gdk_device_get_source (device);
8954 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8955 GINT_TO_POINTER (source)));
8960 if (type == GDK_DEVICE_TYPE_FLOATING)
8962 /* The device was just floated, enable its event mask */
8963 gdk_window_set_device_events (window, device, event_mask);
8965 else if (type == GDK_DEVICE_TYPE_SLAVE)
8966 gdk_window_set_device_events (window, device, 0);
8970 * gdk_window_set_source_events:
8971 * @window: a #GdkWindow
8972 * @source: a #GdkInputSource to define the source class.
8973 * @event_mask: event mask for @window
8975 * Sets the event mask for any floating device (i.e. not attached to any
8976 * visible pointer) that has the source defined as @source. This event
8977 * mask will be applied both to currently existing, newly added devices
8978 * after this call, and devices being attached/detached.
8983 gdk_window_set_source_events (GdkWindow *window,
8984 GdkInputSource source,
8985 GdkEventMask event_mask)
8987 GdkDeviceManager *device_manager;
8988 GdkDisplay *display;
8992 g_return_if_fail (GDK_IS_WINDOW (window));
8994 display = gdk_window_get_display (window);
8995 device_manager = gdk_display_get_device_manager (display);
8997 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
8999 /* Set event mask for existing devices */
9000 for (d = devices; d; d = d->next)
9002 GdkDevice *device = d->data;
9004 if (source == gdk_device_get_source (device))
9005 gdk_window_set_device_events (window, device, event_mask);
9008 g_list_free (devices);
9010 /* Update accounting */
9011 if (G_UNLIKELY (!window->source_event_masks))
9012 window->source_event_masks = g_hash_table_new (NULL, NULL);
9015 g_hash_table_insert (window->source_event_masks,
9016 GUINT_TO_POINTER (source),
9017 GUINT_TO_POINTER (event_mask));
9019 g_hash_table_remove (window->source_event_masks,
9020 GUINT_TO_POINTER (source));
9022 size = g_hash_table_size (window->source_event_masks);
9024 /* Update handler if needed */
9025 if (!window->device_added_handler_id && size > 0)
9027 window->device_added_handler_id =
9028 g_signal_connect (device_manager, "device-added",
9029 G_CALLBACK (source_events_device_added), window);
9030 window->device_changed_handler_id =
9031 g_signal_connect (device_manager, "device-changed",
9032 G_CALLBACK (source_events_device_changed), window);
9034 else if (window->device_added_handler_id && size == 0)
9035 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
9039 * gdk_window_get_source_events:
9040 * @window: a #GdkWindow
9041 * @source: a #GdkInputSource to define the source class.
9043 * Returns the event mask for @window corresponding to the device class specified
9046 * Returns: source event mask for @window
9049 gdk_window_get_source_events (GdkWindow *window,
9050 GdkInputSource source)
9052 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
9054 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
9055 GUINT_TO_POINTER (source)));
9059 do_synthesize_crossing_event (gpointer data)
9061 GdkDisplay *display;
9062 GdkWindow *changed_toplevel;
9063 GHashTableIter iter;
9064 gpointer key, value;
9067 changed_toplevel = data;
9069 changed_toplevel->synthesize_crossing_event_queued = FALSE;
9071 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9074 display = gdk_window_get_display (changed_toplevel);
9075 serial = _gdk_display_get_next_serial (display);
9076 g_hash_table_iter_init (&iter, display->pointers_info);
9078 while (g_hash_table_iter_next (&iter, &key, &value))
9080 GdkWindow *new_window_under_pointer;
9081 GdkPointerWindowInfo *pointer_info = value;
9082 GdkDevice *device = key;
9084 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9086 new_window_under_pointer =
9087 get_pointer_window (display, changed_toplevel,
9089 pointer_info->toplevel_x,
9090 pointer_info->toplevel_y,
9092 if (new_window_under_pointer != pointer_info->window_under_pointer)
9094 _gdk_synthesize_crossing_events (display,
9095 pointer_info->window_under_pointer,
9096 new_window_under_pointer,
9097 device, pointer_info->last_slave,
9098 GDK_CROSSING_NORMAL,
9099 pointer_info->toplevel_x,
9100 pointer_info->toplevel_y,
9101 pointer_info->state,
9106 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9115 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9117 GdkWindow *toplevel;
9119 toplevel = get_event_toplevel (changed_window);
9121 if (!toplevel->synthesize_crossing_event_queued)
9123 toplevel->synthesize_crossing_event_queued = TRUE;
9125 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9126 do_synthesize_crossing_event,
9127 g_object_ref (toplevel),
9132 /* Don't use for crossing events */
9134 get_event_window (GdkDisplay *display,
9136 GdkEventSequence *sequence,
9137 GdkWindow *pointer_window,
9139 GdkModifierType mask,
9141 gboolean pointer_emulated,
9144 guint evmask, emulated_mask = 0;
9145 GdkWindow *grab_window;
9146 GdkDeviceGrabInfo *grab;
9147 GdkTouchGrabInfo *touch_grab;
9149 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
9150 grab = _gdk_display_get_last_device_grab (display, device);
9152 if (is_touch_type (type) && pointer_emulated)
9156 case GDK_TOUCH_BEGIN:
9157 emulated_mask |= GDK_BUTTON_PRESS_MASK;
9159 case GDK_TOUCH_UPDATE:
9160 emulated_mask |= GDK_POINTER_MOTION_MASK;
9163 emulated_mask |= GDK_BUTTON_RELEASE_MASK;
9169 if (touch_grab != NULL &&
9170 (!grab || grab->implicit || touch_grab->serial >= grab->serial_start))
9172 evmask = touch_grab->event_mask;
9173 evmask = update_evmask_for_button_motion (evmask, mask);
9175 if (evmask & (type_masks[type] | emulated_mask))
9178 *evmask_out = evmask;
9179 return touch_grab->window;
9185 if (grab != NULL && !grab->owner_events)
9187 evmask = grab->event_mask;
9188 evmask = update_evmask_for_button_motion (evmask, mask);
9190 grab_window = grab->window;
9192 if (evmask & (type_masks[type] | emulated_mask))
9195 *evmask_out = evmask;
9202 while (pointer_window != NULL)
9204 evmask = pointer_window->event_mask;
9205 evmask = update_evmask_for_button_motion (evmask, mask);
9207 if (evmask & (type_masks[type] | emulated_mask))
9210 *evmask_out = evmask;
9211 return pointer_window;
9214 pointer_window = get_event_parent (pointer_window);
9220 evmask = grab->event_mask;
9221 evmask = update_evmask_for_button_motion (evmask, mask);
9223 if (evmask & (type_masks[type] | emulated_mask))
9226 *evmask_out = evmask;
9227 return grab->window;
9237 proxy_pointer_event (GdkDisplay *display,
9238 GdkEvent *source_event,
9241 GdkWindow *toplevel_window, *event_window;
9242 GdkWindow *pointer_window;
9243 GdkPointerWindowInfo *pointer_info;
9244 GdkDevice *device, *source_device;
9247 gdouble toplevel_x, toplevel_y;
9249 gboolean non_linear, need_synthetic_enter = FALSE;
9252 event_type = source_event->type;
9253 event_window = source_event->any.window;
9254 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9255 gdk_event_get_state (source_event, &state);
9256 time_ = gdk_event_get_time (source_event);
9257 device = gdk_event_get_device (source_event);
9258 source_device = gdk_event_get_source_device (source_event);
9259 pointer_info = _gdk_display_get_pointer_info (display, device);
9260 toplevel_window = convert_native_coords_to_toplevel (event_window,
9261 toplevel_x, toplevel_y,
9262 &toplevel_x, &toplevel_y);
9265 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9266 source_event->type == GDK_ENTER_NOTIFY) &&
9267 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9268 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9271 if (pointer_info->need_touch_press_enter &&
9272 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHSCREEN &&
9273 (source_event->type != GDK_TOUCH_UPDATE ||
9274 _gdk_event_get_pointer_emulated (source_event)))
9276 pointer_info->need_touch_press_enter = FALSE;
9277 need_synthetic_enter = TRUE;
9280 /* If we get crossing events with subwindow unexpectedly being NULL
9281 that means there is a native subwindow that gdk doesn't know about.
9282 We track these and forward them, with the correct virtual window
9284 This is important to get right, as metacity uses gdk for the frame
9285 windows, but gdk doesn't know about the client windows reparented
9287 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9288 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9289 (source_event->type == GDK_ENTER_NOTIFY &&
9290 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9291 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9292 source_event->crossing.subwindow == NULL)
9294 /* Left for an unknown (to gdk) subwindow */
9296 /* Send leave events from window under pointer to event window
9297 that will get the subwindow == NULL window */
9298 _gdk_synthesize_crossing_events (display,
9299 pointer_info->window_under_pointer,
9301 device, source_device,
9302 source_event->crossing.mode,
9303 toplevel_x, toplevel_y,
9309 /* Send subwindow == NULL event */
9310 send_crossing_event (display,
9314 source_event->crossing.mode,
9315 source_event->crossing.detail,
9317 device, source_device,
9318 toplevel_x, toplevel_y,
9323 _gdk_display_set_window_under_pointer (display, device, NULL);
9327 pointer_window = get_pointer_window (display, toplevel_window, device,
9328 toplevel_x, toplevel_y, serial);
9330 if (((source_event->type == GDK_ENTER_NOTIFY &&
9331 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9332 (source_event->type == GDK_LEAVE_NOTIFY &&
9333 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9334 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9335 source_event->crossing.subwindow == NULL)
9337 /* Entered from an unknown (to gdk) subwindow */
9339 /* Send subwindow == NULL event */
9340 send_crossing_event (display,
9344 source_event->crossing.mode,
9345 source_event->crossing.detail,
9347 device, source_device,
9348 toplevel_x, toplevel_y,
9353 /* Send enter events from event window to pointer_window */
9354 _gdk_synthesize_crossing_events (display,
9357 device, source_device,
9358 source_event->crossing.mode,
9359 toplevel_x, toplevel_y,
9362 serial, non_linear);
9363 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9367 if ((source_event->type != GDK_TOUCH_UPDATE ||
9368 _gdk_event_get_pointer_emulated (source_event)) &&
9369 pointer_info->window_under_pointer != pointer_window)
9371 /* Either a toplevel crossing notify that ended up inside a child window,
9372 or a motion notify that got into another child window */
9374 /* Different than last time, send crossing events */
9375 _gdk_synthesize_crossing_events (display,
9376 pointer_info->window_under_pointer,
9378 device, source_device,
9379 GDK_CROSSING_NORMAL,
9380 toplevel_x, toplevel_y,
9383 serial, non_linear);
9384 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9386 else if (source_event->type == GDK_MOTION_NOTIFY ||
9387 source_event->type == GDK_TOUCH_UPDATE)
9389 GdkWindow *event_win;
9392 GdkEventSequence *sequence;
9394 sequence = gdk_event_get_event_sequence (source_event);
9396 event_win = get_event_window (display,
9403 _gdk_event_get_pointer_emulated (source_event),
9406 if (event_type == GDK_TOUCH_UPDATE)
9408 if (_gdk_event_get_pointer_emulated (source_event))
9410 /* Touch events emulating pointer events are transformed back
9411 * to pointer events if:
9412 * 1 - The event window doesn't select for touch events
9413 * 2 - There's no touch grab for this sequence, which means
9414 * it was started as a pointer sequence, but a device
9415 * grab added touch events afterwards, the sequence must
9416 * not mutate in this case.
9418 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9419 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9420 event_type = GDK_MOTION_NOTIFY;
9422 else if ((evmask & GDK_TOUCH_MASK) == 0)
9426 if (is_touch_type (source_event->type) && !is_touch_type (event_type))
9427 state |= GDK_BUTTON1_MASK;
9430 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9431 gdk_window_get_device_events (event_win, device) == 0)
9434 /* The last device to interact with the window was a touch device,
9435 * which synthesized a leave notify event, so synthesize another enter
9436 * notify to tell the pointer is on the window.
9438 if (need_synthetic_enter)
9439 _gdk_synthesize_crossing_events (display,
9440 NULL, pointer_window,
9441 device, source_device,
9442 GDK_CROSSING_DEVICE_SWITCH,
9443 toplevel_x, toplevel_y,
9450 event_type == GDK_MOTION_NOTIFY &&
9451 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9453 gulong *device_serial;
9455 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9457 if (!device_serial ||
9458 (*device_serial != 0 &&
9459 serial < *device_serial))
9460 event_win = NULL; /* Ignore event */
9464 *device_serial = G_MAXULONG;
9471 event = gdk_event_new (event_type);
9472 event->any.window = g_object_ref (event_win);
9473 event->any.send_event = source_event->any.send_event;
9475 gdk_event_set_device (event, gdk_event_get_device (source_event));
9476 gdk_event_set_source_device (event, source_device);
9478 if (event_type == GDK_TOUCH_UPDATE)
9480 event->touch.time = time_;
9481 event->touch.state = state | GDK_BUTTON1_MASK;
9482 event->touch.sequence = source_event->touch.sequence;
9483 event->touch.emulating_pointer = source_event->touch.emulating_pointer;
9484 convert_toplevel_coords_to_window (event_win,
9485 toplevel_x, toplevel_y,
9486 &event->touch.x, &event->touch.y);
9487 gdk_event_get_root_coords (source_event,
9488 &event->touch.x_root,
9489 &event->touch.y_root);
9491 event->touch.axes = g_memdup (source_event->touch.axes,
9492 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9496 event->motion.time = time_;
9497 event->motion.state = state;
9498 event->motion.is_hint = is_hint;
9500 convert_toplevel_coords_to_window (event_win,
9501 toplevel_x, toplevel_y,
9502 &event->motion.x, &event->motion.y);
9503 gdk_event_get_root_coords (source_event,
9504 &event->motion.x_root,
9505 &event->motion.y_root);
9507 if (is_touch_type (source_event->type))
9508 event->motion.axes = g_memdup (source_event->touch.axes,
9509 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9511 event->motion.axes = g_memdup (source_event->motion.axes,
9512 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9515 /* Just insert the event */
9516 _gdk_event_queue_insert_after (gdk_window_get_display (event_win),
9517 source_event, event);
9520 /* unlink all move events from queue.
9521 We handle our own, including our emulated masks. */
9525 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9526 GDK_BUTTON2_MASK | \
9527 GDK_BUTTON3_MASK | \
9528 GDK_BUTTON4_MASK | \
9532 proxy_button_event (GdkEvent *source_event,
9535 GdkWindow *toplevel_window, *event_window;
9536 GdkWindow *event_win;
9537 GdkWindow *pointer_window;
9540 GdkPointerWindowInfo *pointer_info;
9541 GdkDeviceGrabInfo *pointer_grab;
9545 gdouble toplevel_x, toplevel_y;
9546 GdkDisplay *display;
9548 GdkDevice *device, *source_device;
9549 GdkEventMask evmask;
9550 GdkEventSequence *sequence;
9552 type = source_event->any.type;
9553 event_window = source_event->any.window;
9554 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9555 gdk_event_get_state (source_event, &state);
9556 time_ = gdk_event_get_time (source_event);
9557 device = gdk_event_get_device (source_event);
9558 source_device = gdk_event_get_source_device (source_event);
9559 display = gdk_window_get_display (source_event->any.window);
9560 toplevel_window = convert_native_coords_to_toplevel (event_window,
9561 toplevel_x, toplevel_y,
9562 &toplevel_x, &toplevel_y);
9564 sequence = gdk_event_get_event_sequence (source_event);
9566 pointer_info = _gdk_display_get_pointer_info (display, device);
9567 pointer_grab = _gdk_display_has_device_grab (display, device, serial);
9569 if ((type == GDK_BUTTON_PRESS ||
9570 type == GDK_TOUCH_BEGIN) &&
9571 !source_event->any.send_event &&
9573 (type == GDK_TOUCH_BEGIN && pointer_grab->implicit &&
9574 !_gdk_event_get_pointer_emulated (source_event))))
9577 _gdk_window_find_descendant_at (toplevel_window,
9578 toplevel_x, toplevel_y,
9581 /* Find the event window, that gets the grab */
9584 (parent = get_event_parent (w)) != NULL &&
9585 parent->window_type != GDK_WINDOW_ROOT)
9587 if (w->event_mask & GDK_BUTTON_PRESS_MASK &&
9588 (type == GDK_BUTTON_PRESS ||
9589 _gdk_event_get_pointer_emulated (source_event)))
9592 if (type == GDK_TOUCH_BEGIN &&
9593 w->event_mask & GDK_TOUCH_MASK)
9602 if (type == GDK_TOUCH_BEGIN &&
9603 pointer_window->event_mask & GDK_TOUCH_MASK)
9605 _gdk_display_add_touch_grab (display, device, sequence,
9606 pointer_window, event_window,
9607 gdk_window_get_events (pointer_window),
9610 else if (type == GDK_BUTTON_PRESS ||
9611 _gdk_event_get_pointer_emulated (source_event))
9613 _gdk_display_add_device_grab (display,
9619 gdk_window_get_events (pointer_window),
9623 _gdk_display_device_grab_update (display, device,
9624 source_device, serial);
9629 pointer_window = get_pointer_window (display, toplevel_window, device,
9630 toplevel_x, toplevel_y,
9633 event_win = get_event_window (display,
9639 _gdk_event_get_pointer_emulated (source_event),
9642 if (type == GDK_TOUCH_BEGIN || type == GDK_TOUCH_END)
9644 if (_gdk_event_get_pointer_emulated (source_event))
9646 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9647 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9649 if (type == GDK_TOUCH_BEGIN)
9650 type = GDK_BUTTON_PRESS;
9651 else if (type == GDK_TOUCH_END)
9652 type = GDK_BUTTON_RELEASE;
9655 else if ((evmask & GDK_TOUCH_MASK) == 0)
9659 if (source_event->type == GDK_TOUCH_END && !is_touch_type (type))
9660 state |= GDK_BUTTON1_MASK;
9662 if (event_win == NULL)
9665 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9666 gdk_window_get_device_events (event_win, device) == 0)
9669 if ((type == GDK_BUTTON_PRESS ||
9670 (type == GDK_TOUCH_BEGIN &&
9671 _gdk_event_get_pointer_emulated (source_event))) &&
9672 pointer_info->need_touch_press_enter)
9674 GdkCrossingMode mode;
9676 /* The last device to interact with the window was a touch device,
9677 * which synthesized a leave notify event, so synthesize another enter
9678 * notify to tell the pointer is on the window.
9680 if (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9681 mode = GDK_CROSSING_TOUCH_BEGIN;
9683 mode = GDK_CROSSING_DEVICE_SWITCH;
9685 pointer_info->need_touch_press_enter = FALSE;
9686 _gdk_synthesize_crossing_events (display,
9688 pointer_info->window_under_pointer,
9689 device, source_device, mode,
9690 toplevel_x, toplevel_y,
9691 state, time_, source_event,
9694 else if (type == GDK_SCROLL &&
9695 (((evmask & GDK_SMOOTH_SCROLL_MASK) == 0 &&
9696 source_event->scroll.direction == GDK_SCROLL_SMOOTH) ||
9697 ((evmask & GDK_SMOOTH_SCROLL_MASK) != 0 &&
9698 source_event->scroll.direction != GDK_SCROLL_SMOOTH &&
9699 _gdk_event_get_pointer_emulated (source_event))))
9702 event = _gdk_make_event (event_win, type, source_event, FALSE);
9706 case GDK_BUTTON_PRESS:
9707 case GDK_BUTTON_RELEASE:
9708 event->button.button = source_event->button.button;
9709 convert_toplevel_coords_to_window (event_win,
9710 toplevel_x, toplevel_y,
9711 &event->button.x, &event->button.y);
9712 gdk_event_get_root_coords (source_event,
9713 &event->button.x_root,
9714 &event->button.y_root);
9715 gdk_event_set_device (event, gdk_event_get_device (source_event));
9716 gdk_event_set_source_device (event, source_device);
9718 if (is_touch_type (source_event->type))
9720 if (type == GDK_BUTTON_RELEASE)
9721 event->button.state |= GDK_BUTTON1_MASK;
9722 event->button.button = 1;
9723 event->button.axes = g_memdup (source_event->touch.axes,
9724 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9728 event->button.button = source_event->button.button;
9729 event->button.axes = g_memdup (source_event->button.axes,
9730 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9733 if (type == GDK_BUTTON_PRESS)
9734 _gdk_event_button_generate (display, event);
9735 else if ((type == GDK_BUTTON_RELEASE ||
9736 (type == GDK_TOUCH_END &&
9737 _gdk_event_get_pointer_emulated (source_event))) &&
9738 pointer_window == pointer_info->window_under_pointer &&
9739 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9741 /* Synthesize a leave notify event
9742 * whenever a touch device is released
9744 pointer_info->need_touch_press_enter = TRUE;
9745 _gdk_synthesize_crossing_events (display,
9746 pointer_window, NULL,
9747 device, source_device,
9748 GDK_CROSSING_TOUCH_END,
9749 toplevel_x, toplevel_y,
9755 case GDK_TOUCH_BEGIN:
9757 convert_toplevel_coords_to_window (event_win,
9758 toplevel_x, toplevel_y,
9759 &event->button.x, &event->button.y);
9760 gdk_event_get_root_coords (source_event,
9761 &event->touch.x_root,
9762 &event->touch.y_root);
9763 event->touch.state = state;
9764 event->touch.device = source_event->touch.device;
9765 event->touch.axes = g_memdup (source_event->touch.axes,
9766 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9767 event->touch.sequence = source_event->touch.sequence;
9768 event->touch.emulating_pointer = source_event->touch.emulating_pointer;
9770 gdk_event_set_source_device (event, source_device);
9772 if ((type == GDK_TOUCH_END &&
9773 _gdk_event_get_pointer_emulated (source_event)) &&
9774 pointer_window == pointer_info->window_under_pointer &&
9775 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9777 /* Synthesize a leave notify event
9778 * whenever a touch device is released
9780 pointer_info->need_touch_press_enter = TRUE;
9781 _gdk_synthesize_crossing_events (display,
9782 pointer_window, NULL,
9783 device, source_device,
9784 GDK_CROSSING_TOUCH_END,
9785 toplevel_x, toplevel_y,
9792 event->scroll.direction = source_event->scroll.direction;
9793 convert_toplevel_coords_to_window (event_win,
9794 toplevel_x, toplevel_y,
9795 &event->scroll.x, &event->scroll.y);
9796 event->scroll.x_root = source_event->scroll.x_root;
9797 event->scroll.y_root = source_event->scroll.y_root;
9798 event->scroll.state = state;
9799 event->scroll.device = source_event->scroll.device;
9800 event->scroll.delta_x = source_event->scroll.delta_x;
9801 event->scroll.delta_y = source_event->scroll.delta_y;
9802 gdk_event_set_source_device (event, source_device);
9809 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9812 #ifdef DEBUG_WINDOW_PRINTING
9814 #ifdef GDK_WINDOWING_X11
9815 #include "x11/gdkx.h"
9819 gdk_window_print (GdkWindow *window,
9823 const char *window_types[] = {
9833 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9834 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9835 window->x, window->y,
9836 window->width, window->height
9839 if (gdk_window_has_impl (window))
9841 #ifdef GDK_WINDOWING_X11
9842 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9846 if (window->window_type != GDK_WINDOW_CHILD)
9847 g_print (" %s", window_types[window->window_type]);
9849 if (window->input_only)
9850 g_print (" input-only");
9853 g_print (" shaped");
9855 if (!gdk_window_is_visible ((GdkWindow *)window))
9856 g_print (" hidden");
9858 g_print (" abs[%d,%d]",
9859 window->abs_x, window->abs_y);
9861 s = print_region (window->clip_region);
9862 g_print (" clipbox[%s]", s);
9869 gdk_window_print_tree (GdkWindow *window,
9871 gboolean include_input_only)
9875 if (window->input_only && !include_input_only)
9878 gdk_window_print (window, indent);
9880 for (l = window->children; l != NULL; l = l->next)
9881 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9884 #endif /* DEBUG_WINDOW_PRINTING */
9887 _gdk_windowing_got_event (GdkDisplay *display,
9892 GdkWindow *event_window;
9894 gboolean unlink_event;
9895 GdkDeviceGrabInfo *button_release_grab;
9896 GdkPointerWindowInfo *pointer_info = NULL;
9897 GdkDevice *device, *source_device;
9898 gboolean is_toplevel;
9900 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9901 display->last_event_time = gdk_event_get_time (event);
9903 device = gdk_event_get_device (event);
9904 source_device = gdk_event_get_source_device (event);
9910 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
9912 pointer_info = _gdk_display_get_pointer_info (display, device);
9914 if (source_device != pointer_info->last_slave &&
9915 gdk_device_get_device_type (source_device) == GDK_DEVICE_TYPE_SLAVE)
9916 pointer_info->last_slave = source_device;
9917 else if (pointer_info->last_slave)
9918 source_device = pointer_info->last_slave;
9921 g_object_get (device, "input-mode", &mode, NULL);
9922 _gdk_display_device_grab_update (display, device, source_device, serial);
9924 if (mode == GDK_MODE_DISABLED ||
9925 !_gdk_display_check_grab_ownership (display, device, serial))
9927 /* Device events are blocked by another
9928 * device grab, or the device is disabled
9930 unlink_event = TRUE;
9935 event_window = event->any.window;
9939 #ifdef DEBUG_WINDOW_PRINTING
9940 if (event->type == GDK_KEY_PRESS &&
9941 (event->key.keyval == 0xa7 ||
9942 event->key.keyval == 0xbd))
9944 gdk_window_print_tree (event_window, 0, event->key.keyval == 0xbd);
9948 if (event->type == GDK_VISIBILITY_NOTIFY)
9950 event_window->native_visibility = event->visibility.state;
9951 gdk_window_update_visibility_recursively (event_window, event_window);
9955 if (!(is_button_type (event->type) ||
9956 is_motion_type (event->type)) ||
9957 event_window->window_type == GDK_WINDOW_ROOT)
9960 is_toplevel = gdk_window_is_toplevel (event_window);
9962 if ((event->type == GDK_ENTER_NOTIFY ||
9963 event->type == GDK_LEAVE_NOTIFY) &&
9964 (event->crossing.mode == GDK_CROSSING_GRAB ||
9965 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9966 (_gdk_display_has_device_grab (display, device, serial) ||
9967 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9969 /* We synthesize all crossing events due to grabs ourselves,
9970 * so we ignore the native ones caused by our native pointer_grab
9971 * calls. Otherwise we would proxy these crossing event and cause
9972 * multiple copies of crossing events for grabs.
9974 * We do want to handle grabs from other clients though, as for
9975 * instance alt-tab in metacity causes grabs like these and
9976 * we want to handle those. Thus the has_pointer_grab check.
9978 * Implicit grabs on child windows create some grabbing events
9979 * that are sent before the button press. This means we can't
9980 * detect these with the has_pointer_grab check (as the implicit
9981 * grab is only noticed when we get button press event), so we
9982 * detect these events by checking for INFERIOR enter or leave
9983 * events. These should never be a problem to filter out.
9986 /* We ended up in this window after some (perhaps other clients)
9987 * grab, so update the toplevel_under_window state
9990 event->type == GDK_ENTER_NOTIFY &&
9991 event->crossing.mode == GDK_CROSSING_UNGRAB)
9993 if (pointer_info->toplevel_under_pointer)
9994 g_object_unref (pointer_info->toplevel_under_pointer);
9995 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9998 unlink_event = TRUE;
10002 /* Track toplevel_under_pointer */
10005 if (event->type == GDK_ENTER_NOTIFY &&
10006 event->crossing.detail != GDK_NOTIFY_INFERIOR)
10008 if (pointer_info->toplevel_under_pointer)
10009 g_object_unref (pointer_info->toplevel_under_pointer);
10010 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
10012 else if (event->type == GDK_LEAVE_NOTIFY &&
10013 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
10014 pointer_info->toplevel_under_pointer == event_window)
10016 if (pointer_info->toplevel_under_pointer)
10017 g_object_unref (pointer_info->toplevel_under_pointer);
10018 pointer_info->toplevel_under_pointer = NULL;
10022 if (pointer_info &&
10023 (!is_touch_type (event->type) ||
10024 _gdk_event_get_pointer_emulated (event)))
10026 guint old_state, old_button;
10028 /* Store last pointer window and position/state */
10029 old_state = pointer_info->state;
10030 old_button = pointer_info->button;
10032 gdk_event_get_coords (event, &x, &y);
10033 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
10034 pointer_info->toplevel_x = x;
10035 pointer_info->toplevel_y = y;
10036 gdk_event_get_state (event, &pointer_info->state);
10038 if (event->type == GDK_BUTTON_PRESS ||
10039 event->type == GDK_BUTTON_RELEASE)
10040 pointer_info->button = event->button.button;
10041 else if (event->type == GDK_TOUCH_BEGIN ||
10042 event->type == GDK_TOUCH_END)
10043 pointer_info->button = 1;
10046 (pointer_info->state != old_state ||
10047 pointer_info->button != old_button))
10048 _gdk_display_enable_motion_hints (display, device);
10051 unlink_event = FALSE;
10052 if (is_motion_type (event->type))
10053 unlink_event = proxy_pointer_event (display, event, serial);
10054 else if (is_button_type (event->type))
10055 unlink_event = proxy_button_event (event, serial);
10057 if ((event->type == GDK_BUTTON_RELEASE ||
10058 event->type == GDK_TOUCH_END) &&
10059 !event->any.send_event)
10061 GdkEventSequence *sequence;
10063 sequence = gdk_event_get_event_sequence (event);
10064 if (event->type == GDK_TOUCH_END && sequence)
10066 _gdk_display_end_touch_grab (display, device, sequence);
10069 if (event->type == GDK_BUTTON_RELEASE ||
10070 _gdk_event_get_pointer_emulated (event))
10072 button_release_grab =
10073 _gdk_display_has_device_grab (display, device, serial);
10075 if (button_release_grab &&
10076 button_release_grab->implicit &&
10077 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
10079 button_release_grab->serial_end = serial;
10080 button_release_grab->implicit_ungrab = FALSE;
10081 _gdk_display_device_grab_update (display, device, source_device, serial);
10089 _gdk_event_queue_remove_link (display, event_link);
10090 g_list_free_1 (event_link);
10091 gdk_event_free (event);
10096 * gdk_window_create_similar_surface:
10097 * @window: window to make new surface similar to
10098 * @content: the content for the new surface
10099 * @width: width of the new surface
10100 * @height: height of the new surface
10102 * Create a new surface that is as compatible as possible with the
10103 * given @window. For example the new surface will have the same
10104 * fallback resolution and font options as @window. Generally, the new
10105 * surface will also use the same backend as @window, unless that is
10106 * not possible for some reason. The type of the returned surface may
10107 * be examined with cairo_surface_get_type().
10109 * Initially the surface contents are all 0 (transparent if contents
10110 * have transparency, black otherwise.)
10112 * Returns: a pointer to the newly allocated surface. The caller
10113 * owns the surface and should call cairo_surface_destroy() when done
10116 * This function always returns a valid pointer, but it will return a
10117 * pointer to a "nil" surface if @other is already in an error state
10118 * or any other error occurs.
10123 gdk_window_create_similar_surface (GdkWindow * window,
10124 cairo_content_t content,
10128 cairo_surface_t *window_surface, *surface;
10130 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
10132 window_surface = gdk_window_ref_impl_surface (window);
10134 switch (_gdk_rendering_mode)
10136 case GDK_RENDERING_MODE_RECORDING:
10138 cairo_rectangle_t rect = { 0, 0, width, height };
10139 surface = cairo_recording_surface_create (content, &rect);
10142 case GDK_RENDERING_MODE_IMAGE:
10143 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
10144 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
10147 case GDK_RENDERING_MODE_SIMILAR:
10149 surface = cairo_surface_create_similar (window_surface,
10155 cairo_surface_destroy (window_surface);
10161 * gdk_window_focus:
10162 * @window: a #GdkWindow
10163 * @timestamp: timestamp of the event triggering the window focus
10165 * Sets keyboard focus to @window. In most cases, gtk_window_present()
10166 * should be used on a #GtkWindow, rather than calling this function.
10170 gdk_window_focus (GdkWindow *window,
10173 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
10177 * gdk_window_set_type_hint:
10178 * @window: A toplevel #GdkWindow
10179 * @hint: A hint of the function this window will have
10181 * The application can use this call to provide a hint to the window
10182 * manager about the functionality of a window. The window manager
10183 * can use this information when determining the decoration and behaviour
10186 * The hint must be set before the window is mapped.
10189 gdk_window_set_type_hint (GdkWindow *window,
10190 GdkWindowTypeHint hint)
10192 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
10196 * gdk_window_get_type_hint:
10197 * @window: A toplevel #GdkWindow
10199 * This function returns the type hint set for a window.
10201 * Return value: The type hint set for @window
10206 gdk_window_get_type_hint (GdkWindow *window)
10208 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
10212 * gdk_window_set_modal_hint:
10213 * @window: A toplevel #GdkWindow
10214 * @modal: %TRUE if the window is modal, %FALSE otherwise.
10216 * The application can use this hint to tell the window manager
10217 * that a certain window has modal behaviour. The window manager
10218 * can use this information to handle modal windows in a special
10221 * You should only use this on windows for which you have
10222 * previously called gdk_window_set_transient_for()
10225 gdk_window_set_modal_hint (GdkWindow *window,
10228 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
10232 * gdk_window_set_skip_taskbar_hint:
10233 * @window: a toplevel #GdkWindow
10234 * @skips_taskbar: %TRUE to skip the taskbar
10236 * Toggles whether a window should appear in a task list or window
10237 * list. If a window's semantic type as specified with
10238 * gdk_window_set_type_hint() already fully describes the window, this
10239 * function should <emphasis>not</emphasis> be called in addition,
10240 * instead you should allow the window to be treated according to
10241 * standard policy for its semantic type.
10246 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
10247 gboolean skips_taskbar)
10249 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
10253 * gdk_window_set_skip_pager_hint:
10254 * @window: a toplevel #GdkWindow
10255 * @skips_pager: %TRUE to skip the pager
10257 * Toggles whether a window should appear in a pager (workspace
10258 * switcher, or other desktop utility program that displays a small
10259 * thumbnail representation of the windows on the desktop). If a
10260 * window's semantic type as specified with gdk_window_set_type_hint()
10261 * already fully describes the window, this function should
10262 * <emphasis>not</emphasis> be called in addition, instead you should
10263 * allow the window to be treated according to standard policy for
10264 * its semantic type.
10269 gdk_window_set_skip_pager_hint (GdkWindow *window,
10270 gboolean skips_pager)
10272 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
10276 * gdk_window_set_urgency_hint:
10277 * @window: a toplevel #GdkWindow
10278 * @urgent: %TRUE if the window is urgent
10280 * Toggles whether a window needs the user's
10281 * urgent attention.
10286 gdk_window_set_urgency_hint (GdkWindow *window,
10289 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
10293 * gdk_window_set_geometry_hints:
10294 * @window: a toplevel #GdkWindow
10295 * @geometry: geometry hints
10296 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
10298 * Sets the geometry hints for @window. Hints flagged in @geom_mask
10299 * are set, hints not flagged in @geom_mask are unset.
10300 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
10302 * This function provides hints to the windowing system about
10303 * acceptable sizes for a toplevel window. The purpose of
10304 * this is to constrain user resizing, but the windowing system
10305 * will typically (but is not required to) also constrain the
10306 * current size of the window to the provided values and
10307 * constrain programatic resizing via gdk_window_resize() or
10308 * gdk_window_move_resize().
10310 * Note that on X11, this effect has no effect on windows
10311 * of type %GDK_WINDOW_TEMP or windows where override redirect
10312 * has been turned on via gdk_window_set_override_redirect()
10313 * since these windows are not resizable by the user.
10315 * Since you can't count on the windowing system doing the
10316 * constraints for programmatic resizes, you should generally
10317 * call gdk_window_constrain_size() yourself to determine
10318 * appropriate sizes.
10322 gdk_window_set_geometry_hints (GdkWindow *window,
10323 const GdkGeometry *geometry,
10324 GdkWindowHints geom_mask)
10326 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
10330 * gdk_window_set_title:
10331 * @window: a toplevel #GdkWindow
10332 * @title: title of @window
10334 * Sets the title of a toplevel window, to be displayed in the titlebar.
10335 * If you haven't explicitly set the icon name for the window
10336 * (using gdk_window_set_icon_name()), the icon name will be set to
10337 * @title as well. @title must be in UTF-8 encoding (as with all
10338 * user-readable strings in GDK/GTK+). @title may not be %NULL.
10341 gdk_window_set_title (GdkWindow *window,
10342 const gchar *title)
10344 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
10348 * gdk_window_set_role:
10349 * @window: a toplevel #GdkWindow
10350 * @role: a string indicating its role
10352 * When using GTK+, typically you should use gtk_window_set_role() instead
10353 * of this low-level function.
10355 * The window manager and session manager use a window's role to
10356 * distinguish it from other kinds of window in the same application.
10357 * When an application is restarted after being saved in a previous
10358 * session, all windows with the same title and role are treated as
10359 * interchangeable. So if you have two windows with the same title
10360 * that should be distinguished for session management purposes, you
10361 * should set the role on those windows. It doesn't matter what string
10362 * you use for the role, as long as you have a different role for each
10363 * non-interchangeable kind of window.
10367 gdk_window_set_role (GdkWindow *window,
10370 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
10374 * gdk_window_set_startup_id:
10375 * @window: a toplevel #GdkWindow
10376 * @startup_id: a string with startup-notification identifier
10378 * When using GTK+, typically you should use gtk_window_set_startup_id()
10379 * instead of this low-level function.
10385 gdk_window_set_startup_id (GdkWindow *window,
10386 const gchar *startup_id)
10388 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
10392 * gdk_window_set_transient_for:
10393 * @window: a toplevel #GdkWindow
10394 * @parent: another toplevel #GdkWindow
10396 * Indicates to the window manager that @window is a transient dialog
10397 * associated with the application window @parent. This allows the
10398 * window manager to do things like center @window on @parent and
10399 * keep @window above @parent.
10401 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10405 gdk_window_set_transient_for (GdkWindow *window,
10408 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10412 * gdk_window_get_root_origin:
10413 * @window: a toplevel #GdkWindow
10414 * @x: (out): return location for X position of window frame
10415 * @y: (out): return location for Y position of window frame
10417 * Obtains the top-left corner of the window manager frame in root
10418 * window coordinates.
10422 gdk_window_get_root_origin (GdkWindow *window,
10426 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10430 * gdk_window_get_frame_extents:
10431 * @window: a toplevel #GdkWindow
10432 * @rect: (out): rectangle to fill with bounding box of the window frame
10434 * Obtains the bounding box of the window, including window manager
10435 * titlebar/borders if any. The frame position is given in root window
10436 * coordinates. To get the position of the window itself (rather than
10437 * the frame) in root window coordinates, use gdk_window_get_origin().
10441 gdk_window_get_frame_extents (GdkWindow *window,
10442 GdkRectangle *rect)
10444 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10448 * gdk_window_set_override_redirect:
10449 * @window: a toplevel #GdkWindow
10450 * @override_redirect: %TRUE if window should be override redirect
10452 * An override redirect window is not under the control of the window manager.
10453 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10454 * be entirely under the control of the application. The window manager
10455 * can't see the override redirect window at all.
10457 * Override redirect should only be used for short-lived temporary
10458 * windows, such as popup menus. #GtkMenu uses an override redirect
10459 * window in its implementation, for example.
10463 gdk_window_set_override_redirect (GdkWindow *window,
10464 gboolean override_redirect)
10466 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10470 * gdk_window_set_accept_focus:
10471 * @window: a toplevel #GdkWindow
10472 * @accept_focus: %TRUE if the window should receive input focus
10474 * Setting @accept_focus to %FALSE hints the desktop environment that the
10475 * window doesn't want to receive input focus.
10477 * On X, it is the responsibility of the window manager to interpret this
10478 * hint. ICCCM-compliant window manager usually respect it.
10483 gdk_window_set_accept_focus (GdkWindow *window,
10484 gboolean accept_focus)
10486 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10490 * gdk_window_set_focus_on_map:
10491 * @window: a toplevel #GdkWindow
10492 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10494 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10495 * window doesn't want to receive input focus when it is mapped.
10496 * focus_on_map should be turned off for windows that aren't triggered
10497 * interactively (such as popups from network activity).
10499 * On X, it is the responsibility of the window manager to interpret
10500 * this hint. Window managers following the freedesktop.org window
10501 * manager extension specification should respect it.
10506 gdk_window_set_focus_on_map (GdkWindow *window,
10507 gboolean focus_on_map)
10509 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10513 * gdk_window_set_icon_list:
10514 * @window: The #GdkWindow toplevel window to set the icon of.
10515 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10516 * A list of pixbufs, of different sizes.
10518 * Sets a list of icons for the window. One of these will be used
10519 * to represent the window when it has been iconified. The icon is
10520 * usually shown in an icon box or some sort of task bar. Which icon
10521 * size is shown depends on the window manager. The window manager
10522 * can scale the icon but setting several size icons can give better
10523 * image quality since the window manager may only need to scale the
10524 * icon by a small amount or not at all.
10528 gdk_window_set_icon_list (GdkWindow *window,
10531 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10535 * gdk_window_set_icon_name:
10536 * @window: a toplevel #GdkWindow
10537 * @name: (allow-none): name of window while iconified (minimized)
10539 * Windows may have a name used while minimized, distinct from the
10540 * name they display in their titlebar. Most of the time this is a bad
10541 * idea from a user interface standpoint. But you can set such a name
10542 * with this function, if you like.
10544 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10545 * will not update the icon title.
10547 * Using %NULL for @name unsets the icon title; further calls to
10548 * gdk_window_set_title() will again update the icon title as well.
10551 gdk_window_set_icon_name (GdkWindow *window,
10554 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10558 * gdk_window_iconify:
10559 * @window: a toplevel #GdkWindow
10561 * Asks to iconify (minimize) @window. The window manager may choose
10562 * to ignore the request, but normally will honor it. Using
10563 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10565 * This function only makes sense when @window is a toplevel window.
10569 gdk_window_iconify (GdkWindow *window)
10571 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10575 * gdk_window_deiconify:
10576 * @window: a toplevel #GdkWindow
10578 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10579 * choose to ignore the request to deiconify. When using GTK+,
10580 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10581 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10582 * unminimizes it, and puts it on the current desktop.
10586 gdk_window_deiconify (GdkWindow *window)
10588 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10592 * gdk_window_stick:
10593 * @window: a toplevel #GdkWindow
10595 * "Pins" a window such that it's on all workspaces and does not scroll
10596 * with viewports, for window managers that have scrollable viewports.
10597 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10599 * On the X11 platform, this function depends on window manager
10600 * support, so may have no effect with many window managers. However,
10601 * GDK will do the best it can to convince the window manager to stick
10602 * the window. For window managers that don't support this operation,
10603 * there's nothing you can do to force it to happen.
10607 gdk_window_stick (GdkWindow *window)
10609 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10613 * gdk_window_unstick:
10614 * @window: a toplevel #GdkWindow
10616 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10617 * and gtk_window_unstick().
10621 gdk_window_unstick (GdkWindow *window)
10623 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10627 * gdk_window_maximize:
10628 * @window: a toplevel #GdkWindow
10630 * Maximizes the window. If the window was already maximized, then
10631 * this function does nothing.
10633 * On X11, asks the window manager to maximize @window, if the window
10634 * manager supports this operation. Not all window managers support
10635 * this, and some deliberately ignore it or don't have a concept of
10636 * "maximized"; so you can't rely on the maximization actually
10637 * happening. But it will happen with most standard window managers,
10638 * and GDK makes a best effort to get it to happen.
10640 * On Windows, reliably maximizes the window.
10644 gdk_window_maximize (GdkWindow *window)
10646 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10650 * gdk_window_unmaximize:
10651 * @window: a toplevel #GdkWindow
10653 * Unmaximizes the window. If the window wasn't maximized, then this
10654 * function does nothing.
10656 * On X11, asks the window manager to unmaximize @window, if the
10657 * window manager supports this operation. Not all window managers
10658 * support this, and some deliberately ignore it or don't have a
10659 * concept of "maximized"; so you can't rely on the unmaximization
10660 * actually happening. But it will happen with most standard window
10661 * managers, and GDK makes a best effort to get it to happen.
10663 * On Windows, reliably unmaximizes the window.
10667 gdk_window_unmaximize (GdkWindow *window)
10669 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10673 * gdk_window_fullscreen:
10674 * @window: a toplevel #GdkWindow
10676 * Moves the window into fullscreen mode. This means the
10677 * window covers the entire screen and is above any panels
10680 * If the window was already fullscreen, then this function does nothing.
10682 * On X11, asks the window manager to put @window in a fullscreen
10683 * state, if the window manager supports this operation. Not all
10684 * window managers support this, and some deliberately ignore it or
10685 * don't have a concept of "fullscreen"; so you can't rely on the
10686 * fullscreenification actually happening. But it will happen with
10687 * most standard window managers, and GDK makes a best effort to get
10693 gdk_window_fullscreen (GdkWindow *window)
10695 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10699 * gdk_window_set_fullscreen_mode:
10700 * @window: a toplevel #GdkWindow
10701 * @mode: fullscreen mode
10703 * Specifies whether the @window should span over all monitors (in a multi-head
10704 * setup) or only the current monitor when in fullscreen mode.
10706 * The @mode argument is from the #GdkFullscreenMode enumeration.
10707 * If #GDK_FULLSCREEN_ON_ALL_MONITORS is specified, the fullscreen @window will
10708 * span over all monitors from the #GdkScreen.
10710 * On X11, searches through the list of monitors from the #GdkScreen the ones
10711 * which delimit the 4 edges of the entire #GdkScreen and will ask the window
10712 * manager to span the @window over these monitors.
10714 * If the XINERAMA extension is not available or not usable, this function
10717 * Not all window managers support this, so you can't rely on the fullscreen
10718 * window to span over the multiple monitors when #GDK_FULLSCREEN_ON_ALL_MONITORS
10724 gdk_window_set_fullscreen_mode (GdkWindow *window,
10725 GdkFullscreenMode mode)
10727 GdkWindowImplClass *impl_class;
10729 g_return_if_fail (GDK_IS_WINDOW (window));
10731 if (window->fullscreen_mode != mode)
10733 window->fullscreen_mode = mode;
10735 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
10736 if (impl_class->apply_fullscreen_mode != NULL)
10737 impl_class->apply_fullscreen_mode (window);
10742 * gdk_window_get_fullscreen_mode:
10743 * @window: a toplevel #GdkWindow
10745 * Obtains the #GdkFullscreenMode of the @window.
10747 * Returns: The #GdkFullscreenMode applied to the window when fullscreen.
10752 gdk_window_get_fullscreen_mode (GdkWindow *window)
10754 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_FULLSCREEN_ON_CURRENT_MONITOR);
10756 return window->fullscreen_mode;
10760 * gdk_window_unfullscreen:
10761 * @window: a toplevel #GdkWindow
10763 * Moves the window out of fullscreen mode. If the window was not
10764 * fullscreen, does nothing.
10766 * On X11, asks the window manager to move @window out of the fullscreen
10767 * state, if the window manager supports this operation. Not all
10768 * window managers support this, and some deliberately ignore it or
10769 * don't have a concept of "fullscreen"; so you can't rely on the
10770 * unfullscreenification actually happening. But it will happen with
10771 * most standard window managers, and GDK makes a best effort to get
10777 gdk_window_unfullscreen (GdkWindow *window)
10779 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10783 * gdk_window_set_keep_above:
10784 * @window: a toplevel #GdkWindow
10785 * @setting: whether to keep @window above other windows
10787 * Set if @window must be kept above other windows. If the
10788 * window was already above, then this function does nothing.
10790 * On X11, asks the window manager to keep @window above, if the window
10791 * manager supports this operation. Not all window managers support
10792 * this, and some deliberately ignore it or don't have a concept of
10793 * "keep above"; so you can't rely on the window being kept above.
10794 * But it will happen with most standard window managers,
10795 * and GDK makes a best effort to get it to happen.
10800 gdk_window_set_keep_above (GdkWindow *window,
10803 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10807 * gdk_window_set_keep_below:
10808 * @window: a toplevel #GdkWindow
10809 * @setting: whether to keep @window below other windows
10811 * Set if @window must be kept below other windows. If the
10812 * window was already below, then this function does nothing.
10814 * On X11, asks the window manager to keep @window below, if the window
10815 * manager supports this operation. Not all window managers support
10816 * this, and some deliberately ignore it or don't have a concept of
10817 * "keep below"; so you can't rely on the window being kept below.
10818 * But it will happen with most standard window managers,
10819 * and GDK makes a best effort to get it to happen.
10824 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10826 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10830 * gdk_window_get_group:
10831 * @window: a toplevel #GdkWindow
10833 * Returns the group leader window for @window. See gdk_window_set_group().
10835 * Return value: (transfer none): the group leader window for @window
10840 gdk_window_get_group (GdkWindow *window)
10842 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10846 * gdk_window_set_group:
10847 * @window: a toplevel #GdkWindow
10848 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10850 * Sets the group leader window for @window. By default,
10851 * GDK sets the group leader for all toplevel windows
10852 * to a global window implicitly created by GDK. With this function
10853 * you can override this default.
10855 * The group leader window allows the window manager to distinguish
10856 * all windows that belong to a single application. It may for example
10857 * allow users to minimize/unminimize all windows belonging to an
10858 * application at once. You should only set a non-default group window
10859 * if your application pretends to be multiple applications.
10862 gdk_window_set_group (GdkWindow *window,
10865 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10869 * gdk_window_set_decorations:
10870 * @window: a toplevel #GdkWindow
10871 * @decorations: decoration hint mask
10873 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10874 * This function sets the traditional Motif window manager hints that tell the
10875 * window manager which decorations you would like your window to have.
10876 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10877 * using the GDK function directly.
10879 * The @decorations argument is the logical OR of the fields in
10880 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10881 * mask, the other bits indicate which decorations should be turned off.
10882 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10883 * which decorations should be turned on.
10885 * Most window managers honor a decorations hint of 0 to disable all decorations,
10886 * but very few honor all possible combinations of bits.
10890 gdk_window_set_decorations (GdkWindow *window,
10891 GdkWMDecoration decorations)
10893 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10897 * gdk_window_get_decorations:
10898 * @window: The toplevel #GdkWindow to get the decorations from
10899 * @decorations: (out): The window decorations will be written here
10901 * Returns the decorations set on the GdkWindow with
10902 * gdk_window_set_decorations().
10904 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10907 gdk_window_get_decorations(GdkWindow *window,
10908 GdkWMDecoration *decorations)
10910 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10914 * gdk_window_set_functions:
10915 * @window: a toplevel #GdkWindow
10916 * @functions: bitmask of operations to allow on @window
10918 * Sets hints about the window management functions to make available
10919 * via buttons on the window frame.
10921 * On the X backend, this function sets the traditional Motif window
10922 * manager hint for this purpose. However, few window managers do
10923 * anything reliable or interesting with this hint. Many ignore it
10926 * The @functions argument is the logical OR of values from the
10927 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
10928 * then the other bits indicate which functions to disable; if
10929 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
10934 gdk_window_set_functions (GdkWindow *window,
10935 GdkWMFunction functions)
10937 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
10941 * gdk_window_begin_resize_drag_for_device:
10942 * @window: a toplevel #GdkWindow
10943 * @edge: the edge or corner from which the drag is started
10944 * @device: the device used for the operation
10945 * @button: the button being used to drag
10946 * @root_x: root window X coordinate of mouse click that began the drag
10947 * @root_y: root window Y coordinate of mouse click that began the drag
10948 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10950 * Begins a window resize operation (for a toplevel window).
10951 * You might use this function to implement a "window resize grip," for
10952 * example; in fact #GtkStatusbar uses it. The function works best
10953 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
10954 * fallback implementation for other window managers.
10959 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
10960 GdkWindowEdge edge,
10967 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
10971 * gdk_window_begin_resize_drag:
10972 * @window: a toplevel #GdkWindow
10973 * @edge: the edge or corner from which the drag is started
10974 * @button: the button being used to drag
10975 * @root_x: root window X coordinate of mouse click that began the drag
10976 * @root_y: root window Y coordinate of mouse click that began the drag
10977 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10979 * Begins a window resize operation (for a toplevel window).
10981 * This function assumes that the drag is controlled by the
10982 * client pointer device, use gdk_window_begin_resize_drag_for_device()
10983 * to begin a drag with a different device.
10986 gdk_window_begin_resize_drag (GdkWindow *window,
10987 GdkWindowEdge edge,
10993 GdkDeviceManager *device_manager;
10996 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10997 device = gdk_device_manager_get_client_pointer (device_manager);
10998 gdk_window_begin_resize_drag_for_device (window, edge,
10999 device, button, root_x, root_y, timestamp);
11003 * gdk_window_begin_move_drag_for_device:
11004 * @window: a toplevel #GdkWindow
11005 * @device: the device used for the operation
11006 * @button: the button being used to drag
11007 * @root_x: root window X coordinate of mouse click that began the drag
11008 * @root_y: root window Y coordinate of mouse click that began the drag
11009 * @timestamp: timestamp of mouse click that began the drag
11011 * Begins a window move operation (for a toplevel window).
11012 * You might use this function to implement a "window move grip," for
11013 * example. The function works best with window managers that support
11014 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
11015 * Window Manager Hints</ulink>, but has a fallback implementation for
11016 * other window managers.
11021 gdk_window_begin_move_drag_for_device (GdkWindow *window,
11028 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
11029 device, button, root_x, root_y, timestamp);
11033 * gdk_window_begin_move_drag:
11034 * @window: a toplevel #GdkWindow
11035 * @button: the button being used to drag
11036 * @root_x: root window X coordinate of mouse click that began the drag
11037 * @root_y: root window Y coordinate of mouse click that began the drag
11038 * @timestamp: timestamp of mouse click that began the drag
11040 * Begins a window move operation (for a toplevel window).
11042 * This function assumes that the drag is controlled by the
11043 * client pointer device, use gdk_window_begin_move_drag_for_device()
11044 * to begin a drag with a different device.
11047 gdk_window_begin_move_drag (GdkWindow *window,
11053 GdkDeviceManager *device_manager;
11056 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11057 device = gdk_device_manager_get_client_pointer (device_manager);
11058 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
11062 * gdk_window_enable_synchronized_configure:
11063 * @window: a toplevel #GdkWindow
11065 * Indicates that the application will cooperate with the window
11066 * system in synchronizing the window repaint with the window
11067 * manager during resizing operations. After an application calls
11068 * this function, it must call gdk_window_configure_finished() every
11069 * time it has finished all processing associated with a set of
11070 * Configure events. Toplevel GTK+ windows automatically use this
11073 * On X, calling this function makes @window participate in the
11074 * _NET_WM_SYNC_REQUEST window manager protocol.
11079 gdk_window_enable_synchronized_configure (GdkWindow *window)
11081 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
11085 * gdk_window_configure_finished:
11086 * @window: a toplevel #GdkWindow
11088 * Signal to the window system that the application has finished
11089 * handling Configure events it has received. Window Managers can
11090 * use this to better synchronize the frame repaint with the
11091 * application. GTK+ applications will automatically call this
11092 * function when appropriate.
11094 * This function can only be called if gdk_window_enable_synchronized_configure()
11095 * was called previously.
11100 gdk_window_configure_finished (GdkWindow *window)
11102 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
11106 * gdk_window_set_opacity:
11107 * @window: a top-level #GdkWindow
11108 * @opacity: opacity
11110 * Request the windowing system to make @window partially transparent,
11111 * with opacity 0 being fully transparent and 1 fully opaque. (Values
11112 * of the opacity parameter are clamped to the [0,1] range.)
11114 * On X11, this works only on X screens with a compositing manager
11117 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
11118 * For making non-toplevel windows translucent, see
11119 * gdk_window_set_composited().
11124 gdk_window_set_opacity (GdkWindow *window,
11127 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
11130 /* This function is called when the XWindow is really gone.
11133 gdk_window_destroy_notify (GdkWindow *window)
11135 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
11139 * gdk_window_register_dnd:
11140 * @window: a #GdkWindow.
11142 * Registers a window as a potential drop destination.
11145 gdk_window_register_dnd (GdkWindow *window)
11147 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
11151 * gdk_window_get_drag_protocol:
11152 * @window: the destination window
11153 * @target: (out) (allow-none) (transfer full): location of the window
11154 * where the drop should happen. This may be @window or a proxy window,
11155 * or %NULL if @window does not support Drag and Drop.
11157 * Finds out the DND protocol supported by a window.
11159 * Returns: the supported DND protocol.
11164 gdk_window_get_drag_protocol (GdkWindow *window,
11165 GdkWindow **target)
11167 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
11169 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
11174 * @window: the source window for this drag.
11175 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11176 * as list of #GdkAtoms
11178 * Starts a drag and creates a new drag context for it.
11179 * This function assumes that the drag is controlled by the
11180 * client pointer device, use gdk_drag_begin_for_device() to
11181 * begin a drag with a different device.
11183 * This function is called by the drag source.
11185 * Return value: (transfer full): a newly created #GdkDragContext
11188 gdk_drag_begin (GdkWindow *window,
11191 GdkDeviceManager *device_manager;
11194 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11195 device = gdk_device_manager_get_client_pointer (device_manager);
11197 return gdk_drag_begin_for_device (window, device, targets);
11201 * gdk_drag_begin_for_device:
11202 * @window: the source window for this drag
11203 * @device: the device that controls this drag
11204 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11205 * as list of #GdkAtoms
11207 * Starts a drag and creates a new drag context for it.
11209 * This function is called by the drag source.
11211 * Return value: (transfer full): a newly created #GdkDragContext
11214 gdk_drag_begin_for_device (GdkWindow *window,
11218 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
11222 * gdk_test_render_sync:
11223 * @window: a mapped #GdkWindow
11225 * Retrieves a pixel from @window to force the windowing
11226 * system to carry out any pending rendering commands.
11228 * This function is intended to be used to synchronize with rendering
11229 * pipelines, to benchmark windowing system rendering operations.
11234 gdk_test_render_sync (GdkWindow *window)
11236 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
11240 * gdk_test_simulate_key:
11241 * @window: a #GdkWindow to simulate a key event for
11242 * @x: x coordinate within @window for the key event
11243 * @y: y coordinate within @window for the key event
11244 * @keyval: A GDK keyboard value
11245 * @modifiers: Keyboard modifiers the event is setup with
11246 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
11248 * This function is intended to be used in GTK+ test programs.
11249 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
11250 * the given (@x,@y) coordinates within @window and simulate a
11251 * key press or release event.
11253 * When the mouse pointer is warped to the target location, use
11254 * of this function outside of test programs that run in their
11255 * own virtual windowing system (e.g. Xvfb) is not recommended.
11256 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
11257 * be warped and @window origin will be used as mouse pointer
11258 * location for the event.
11260 * Also, gdk_test_simulate_key() is a fairly low level function,
11261 * for most testing purposes, gtk_test_widget_send_key() is the
11262 * right function to call which will generate a key press event
11263 * followed by its accompanying key release event.
11265 * Returns: whether all actions necessary for a key event simulation
11266 * were carried out successfully
11271 gdk_test_simulate_key (GdkWindow *window,
11275 GdkModifierType modifiers,
11276 GdkEventType key_pressrelease)
11278 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11279 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
11283 * gdk_test_simulate_button:
11284 * @window: a #GdkWindow to simulate a button event for
11285 * @x: x coordinate within @window for the button event
11286 * @y: y coordinate within @window for the button event
11287 * @button: Number of the pointer button for the event, usually 1, 2 or 3
11288 * @modifiers: Keyboard modifiers the event is setup with
11289 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
11291 * This function is intended to be used in GTK+ test programs.
11292 * It will warp the mouse pointer to the given (@x,@y) coordinates
11293 * within @window and simulate a button press or release event.
11294 * Because the mouse pointer needs to be warped to the target
11295 * location, use of this function outside of test programs that
11296 * run in their own virtual windowing system (e.g. Xvfb) is not
11299 * Also, gdk_test_simulate_button() is a fairly low level function,
11300 * for most testing purposes, gtk_test_widget_click() is the right
11301 * function to call which will generate a button press event followed
11302 * by its accompanying button release event.
11304 * Returns: whether all actions necessary for a button event simulation
11305 * were carried out successfully
11310 gdk_test_simulate_button (GdkWindow *window,
11313 guint button, /*1..3*/
11314 GdkModifierType modifiers,
11315 GdkEventType button_pressrelease)
11317 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11318 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
11322 * gdk_property_get:
11323 * @window: a #GdkWindow
11324 * @property: the property to retrieve
11325 * @type: the desired property type, or %GDK_NONE, if any type of data
11326 * is acceptable. If this does not match the actual
11327 * type, then @actual_format and @actual_length will
11328 * be filled in, a warning will be printed to stderr
11329 * and no data will be returned.
11330 * @offset: the offset into the property at which to begin
11331 * retrieving data, in 4 byte units.
11332 * @length: the length of the data to retrieve in bytes. Data is
11333 * considered to be retrieved in 4 byte chunks, so @length
11334 * will be rounded up to the next highest 4 byte boundary
11335 * (so be careful not to pass a value that might overflow
11336 * when rounded up).
11337 * @pdelete: if %TRUE, delete the property after retrieving the
11339 * @actual_property_type: (out) (transfer none): location to store the
11340 * actual type of the property.
11341 * @actual_format: (out): location to store the actual return format of the
11342 * data; either 8, 16 or 32 bits.
11343 * @actual_length: location to store the length of the retrieved data, in
11344 * bytes. Data returned in the 32 bit format is stored
11345 * in a long variable, so the actual number of 32 bit
11346 * elements should be be calculated via
11347 * @actual_length / sizeof(glong) to ensure portability to
11349 * @data: (out) (array length=actual_length) (transfer full): location
11350 * to store a pointer to the data. The retrieved data should be
11351 * freed with g_free() when you are finished using it.
11353 * Retrieves a portion of the contents of a property. If the
11354 * property does not exist, then the function returns %FALSE,
11355 * and %GDK_NONE will be stored in @actual_property_type.
11359 * The XGetWindowProperty() function that gdk_property_get()
11360 * uses has a very confusing and complicated set of semantics.
11361 * Unfortunately, gdk_property_get() makes the situation
11362 * worse instead of better (the semantics should be considered
11363 * undefined), and also prints warnings to stderr in cases where it
11364 * should return a useful error to the program. You are advised to use
11365 * XGetWindowProperty() directly until a replacement function for
11366 * gdk_property_get()
11371 * Returns: %TRUE if data was successfully received and stored
11372 * in @data, otherwise %FALSE.
11375 gdk_property_get (GdkWindow *window,
11381 GdkAtom *actual_property_type,
11382 gint *actual_format_type,
11383 gint *actual_length,
11386 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11387 ->get_property (window, property, type, offset, length, pdelete,
11388 actual_property_type, actual_format_type,
11389 actual_length, data);
11393 * gdk_property_change: (skip)
11394 * @window: a #GdkWindow
11395 * @property: the property to change
11396 * @type: the new type for the property. If @mode is
11397 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11398 * must match the existing type or an error will occur.
11399 * @format: the new format for the property. If @mode is
11400 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11401 * must match the existing format or an error will occur.
11402 * @mode: a value describing how the new data is to be combined
11403 * with the current data.
11404 * @data: the data (a <literal>guchar *</literal>
11405 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
11406 * depending on @format), cast to a <literal>guchar *</literal>.
11407 * @nelements: the number of elements of size determined by the format,
11408 * contained in @data.
11410 * Changes the contents of a property on a window.
11413 gdk_property_change (GdkWindow *window,
11418 const guchar *data,
11421 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11422 ->change_property (window, property, type, format, mode, data, nelements);
11426 * gdk_property_delete:
11427 * @window: a #GdkWindow
11428 * @property: the property to delete
11430 * Deletes a property from a window.
11433 gdk_property_delete (GdkWindow *window,
11436 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);