1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include <cairo-gobject.h>
32 #include "gdkwindow.h"
34 #include "gdkrectangle.h"
35 #include "gdkinternals.h"
37 #include "gdkscreenprivate.h"
38 #include "gdkdisplayprivate.h"
39 #include "gdkdeviceprivate.h"
40 #include "gdkvisualprivate.h"
41 #include "gdkmarshalers.h"
42 #include "gdkwindowimpl.h"
46 #undef DEBUG_WINDOW_PRINTING
51 * @Short_description: Onscreen display areas in the target window system
54 * A #GdkWindow is a (usually) rectangular region on the screen.
55 * It's a low-level object, used to implement high-level objects such as
56 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
57 * window, the thing a user might think of as a "window" with a titlebar and
58 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
59 * #GtkButton has a #GdkWindow associated with it.
61 * <refsect2 id="COMPOSITED-WINDOWS">
62 * <title>Composited Windows</title>
64 * Normally, the windowing system takes care of rendering the contents of a
65 * child window onto its parent window. This mechanism can be intercepted by
66 * calling gdk_window_set_composited() on the child window. For a
67 * <firstterm>composited</firstterm> window it is the responsibility of the
68 * application to render the window contents at the right spot.
70 * <example id="composited-window-example">
71 * <title>Composited windows</title>
73 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/gdk/composited-window-example.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include>
74 * </programlisting></example>
76 * In the example <xref linkend="composited-window-example"/>, a button is
77 * placed inside of an event box inside of a window. The event box is set as
78 * composited and therefore is no longer automatically drawn to the screen.
80 * When the contents of the event box change, an expose event is generated on
81 * its parent window (which, in this case, belongs to the toplevel #GtkWindow).
82 * The expose handler for this widget is responsible for merging the changes
83 * back on the screen in the way that it wishes.
85 * In our case, we merge the contents with a 50% transparency. We also set the
86 * background colour of the window to red. The effect is that the background
87 * shows through the button.
90 * <refsect2 id="OFFSCREEN-WINDOWS">
91 * <title>Offscreen Windows</title>
93 * Offscreen windows are more general than composited windows, since they allow
94 * not only to modify the rendering of the child window onto its parent, but
95 * also to apply coordinate transformations.
97 * To integrate an offscreen window into a window hierarchy, one has to call
98 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
99 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
100 * select an offscreen child at given coordinates, and the
101 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
102 * offscreen window are used to translate coordinates between the embedder and
103 * the offscreen window.
105 * For rendering an offscreen window onto its embedder, the contents of the
106 * offscreen window are available as a surface, via
107 * gdk_offscreen_window_get_surface().
113 /* Historically a GdkWindow always matches a platform native window,
114 * be it a toplevel window or a child window. In this setup the
115 * GdkWindow (and other GdkDrawables) were platform independent classes,
116 * and the actual platform specific implementation was in a delegate
117 * object availible as "impl" in the window object.
119 * With the addition of client side windows and offscreen windows this
120 * changes a bit. The application-visible GdkWindow object behaves as
121 * it did before, but not all such windows now have a corresponding native
122 * window. Instead windows that are "client side" are emulated by the gdk
123 * code such that clipping, drawing, moving, events etc work as expected.
125 * For GdkWindows that have a native window the "impl" object is the
126 * same as before. However, for all client side windows the impl object
127 * is shared with its parent (i.e. all client windows descendants of one
128 * native window has the same impl.
130 * Additionally there is a new type of platform independent impl object,
131 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
132 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
133 * windows). Such windows work by allocating a #cairo_surface_t as the backing
134 * store for drawing operations, which is resized with the window.
136 * GdkWindows have a pointer to the "impl window" they are in, i.e.
137 * the topmost GdkWindow which have the same "impl" value. This is stored
138 * in impl_window, which is different from the window itself only for client
140 * All GdkWindows (native or not) track the position of the window in the parent
141 * (x, y), the size of the window (width, height), the position of the window
142 * with respect to the impl window (abs_x, abs_y). We also track the clip
143 * region of the window wrt parent windows and siblings, in window-relative
144 * coordinates with and without child windows included (clip_region,
145 * clip_region_with_children).
147 * All toplevel windows are native windows, but also child windows can be
148 * native (although not children of offscreens). We always listen to
149 * a basic set of events (see get_native_event_mask) for these windows
150 * so that we can emulate events for any client side children.
152 * For native windows we apply the calculated clip region as a window shape
153 * so that eg. client side siblings that overlap the native child properly
154 * draws over the native child window.
156 * In order to minimize flicker and for performance we use a couple of cacheing
157 * tricks. First of all, every time we do a window to window copy area, for instance
158 * when moving a client side window or when scrolling/moving a region in a window
159 * we store this in outstanding_moves instead of applying immediately. We then
160 * delay this move until we really need it (because something depends on being
161 * able to read it), or until we're handing a redraw from an expose/invalidation
162 * (actually we delay it past redraw, but before blitting the double buffer
163 * to the window). This gives us two advantages. First of all it minimizes the time
164 * from the window is moved to the exposes related to that move, secondly it allows
165 * us to be smart about how to do the copy. We combine multiple moves into one (when
166 * possible) and we don't actually do copies to anything that is or will be
167 * invalidated and exposed anyway.
169 * Secondly, we use something called a "implicit paint" during repaint handling.
170 * An implicit paint is similar to a regular paint for the paint stack, but it is
171 * not put on the stack. Instead, it is set on the impl window, and later when
172 * regular gdk_window_begin_paint_region() happen on a window of this impl window
173 * we reuse the surface from the implicit paint. During repaint we create and at the
174 * end flush an implicit paint, which means we can collect all the paints on
175 * multiple client side windows in the same backing store.
178 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
180 /* This adds a local value to the GdkVisibilityState enum */
181 #define GDK_VISIBILITY_NOT_VIEWABLE 3
184 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
198 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
202 struct _GdkWindowPaint
204 cairo_region_t *region;
205 cairo_surface_t *surface;
206 guint uses_implicit : 1;
212 cairo_region_t *dest_region; /* The destination region */
213 int dx, dy; /* The amount that the source was moved to reach dest_region */
214 } GdkWindowRegionMove;
218 static void gdk_window_drop_cairo_surface (GdkWindow *private);
220 static void gdk_window_free_paint_stack (GdkWindow *window);
222 static void gdk_window_finalize (GObject *object);
224 static void gdk_window_set_property (GObject *object,
228 static void gdk_window_get_property (GObject *object,
233 static void gdk_window_clear_backing_region (GdkWindow *window,
234 cairo_region_t *region);
236 static void recompute_visible_regions (GdkWindow *private,
237 gboolean recalculate_siblings,
238 gboolean recalculate_children);
239 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
240 static void gdk_window_flush_recursive (GdkWindow *window);
241 static void do_move_region_bits_on_impl (GdkWindow *window,
242 cairo_region_t *region, /* In impl window coords */
244 static void gdk_window_invalidate_in_parent (GdkWindow *private);
245 static void move_native_children (GdkWindow *private);
246 static void update_cursor (GdkDisplay *display,
248 static void impl_window_add_update_area (GdkWindow *impl_window,
249 cairo_region_t *region);
250 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
251 static void gdk_window_invalidate_region_full (GdkWindow *window,
252 const cairo_region_t *region,
253 gboolean invalidate_children,
255 static void gdk_window_invalidate_rect_full (GdkWindow *window,
256 const GdkRectangle *rect,
257 gboolean invalidate_children,
260 static guint signals[LAST_SIGNAL] = { 0 };
262 static gpointer parent_class = NULL;
264 static const cairo_user_data_key_t gdk_window_cairo_key;
267 new_region_tag (void)
269 static guint32 tag = 0;
274 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
277 _gdk_paintable_get_type (void)
279 static GType paintable_type = 0;
283 const GTypeInfo paintable_info =
285 sizeof (GdkPaintableIface), /* class_size */
286 NULL, /* base_init */
287 NULL, /* base_finalize */
290 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
291 g_intern_static_string ("GdkPaintable"),
294 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
297 return paintable_type;
301 gdk_window_init (GdkWindow *window)
303 /* 0-initialization is good for all other fields. */
305 window->window_type = GDK_WINDOW_CHILD;
307 window->state = GDK_WINDOW_STATE_WITHDRAWN;
310 window->toplevel_window_type = -1;
312 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
313 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
314 /* Default to unobscured since some backends don't send visibility events */
315 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
317 window->device_cursor = g_hash_table_new_full (NULL, NULL,
318 NULL, g_object_unref);
321 /* Stop and return on the first non-NULL parent */
323 accumulate_get_window (GSignalInvocationHint *ihint,
325 const GValue *handler_return,
328 g_value_copy (handler_return, return_accu);
329 /* Continue while returning NULL */
330 return g_value_get_object (handler_return) == NULL;
334 create_surface_accumulator (GSignalInvocationHint *ihint,
336 const GValue *handler_return,
339 g_value_copy (handler_return, return_accu);
341 /* Stop on the first non-NULL return value */
342 return g_value_get_boxed (handler_return) == NULL;
345 static GQuark quark_pointer_window = 0;
348 gdk_window_class_init (GdkWindowClass *klass)
350 GObjectClass *object_class = G_OBJECT_CLASS (klass);
352 parent_class = g_type_class_peek_parent (klass);
354 object_class->finalize = gdk_window_finalize;
355 object_class->set_property = gdk_window_set_property;
356 object_class->get_property = gdk_window_get_property;
358 klass->create_surface = _gdk_offscreen_window_create_surface;
360 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
368 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
369 * gdk_window_get_cursor() for details.
373 g_object_class_install_property (object_class,
375 g_param_spec_object ("cursor",
382 * GdkWindow::pick-embedded-child:
383 * @window: the window on which the signal is emitted
384 * @x: x coordinate in the window
385 * @y: y coordinate in the window
387 * The ::pick-embedded-child signal is emitted to find an embedded
388 * child at the given position.
390 * Returns: (transfer none): the #GdkWindow of the embedded child at
395 signals[PICK_EMBEDDED_CHILD] =
396 g_signal_new (g_intern_static_string ("pick-embedded-child"),
397 G_OBJECT_CLASS_TYPE (object_class),
399 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
400 accumulate_get_window, NULL,
401 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
408 * GdkWindow::to-embedder:
409 * @window: the offscreen window on which the signal is emitted
410 * @offscreen-x: x coordinate in the offscreen window
411 * @offscreen-y: y coordinate in the offscreen window
412 * @embedder-x: (out) (type double): return location for the x
413 * coordinate in the embedder window
414 * @embedder-y: (out) (type double): return location for the y
415 * coordinate in the embedder window
417 * The ::to-embedder signal is emitted to translate coordinates
418 * in an offscreen window to its embedder.
420 * See also #GtkWindow::from-embedder.
424 signals[TO_EMBEDDER] =
425 g_signal_new (g_intern_static_string ("to-embedder"),
426 G_OBJECT_CLASS_TYPE (object_class),
428 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
430 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
439 * GdkWindow::from-embedder:
440 * @window: the offscreen window on which the signal is emitted
441 * @embedder-x: x coordinate in the embedder window
442 * @embedder-y: y coordinate in the embedder window
443 * @offscreen-x: (out) (type double): return location for the x
444 * coordinate in the offscreen window
445 * @offscreen-y: (out) (type double): return location for the y
446 * coordinate in the offscreen window
448 * The ::from-embedder signal is emitted to translate coordinates
449 * in the embedder of an offscreen window to the offscreen window.
451 * See also #GtkWindow::to-embedder.
455 signals[FROM_EMBEDDER] =
456 g_signal_new (g_intern_static_string ("from-embedder"),
457 G_OBJECT_CLASS_TYPE (object_class),
459 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
461 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
470 * GdkWindow::create-surface:
471 * @window: the offscreen window on which the signal is emitted
472 * @width: the width of the offscreen surface to create
473 * @height: the height of the offscreen surface to create
475 * The ::create-surface signal is emitted when an offscreen window
476 * needs its surface (re)created, which happens either when the the
477 * window is first drawn to, or when the window is being
478 * resized. The first signal handler that returns a non-%NULL
479 * surface will stop any further signal emission, and its surface
482 * Note that it is not possible to access the window's previous
483 * surface from within any callback of this signal. Calling
484 * gdk_offscreen_window_get_surface() will lead to a crash.
486 * Returns: the newly created #cairo_surface_t for the offscreen window
490 signals[CREATE_SURFACE] =
491 g_signal_new (g_intern_static_string ("create-surface"),
492 G_OBJECT_CLASS_TYPE (object_class),
494 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
495 create_surface_accumulator, NULL,
496 _gdk_marshal_BOXED__INT_INT,
497 CAIRO_GOBJECT_TYPE_SURFACE,
504 device_removed_cb (GdkDeviceManager *device_manager,
508 window->devices_inside = g_list_remove (window->devices_inside, device);
509 g_hash_table_remove (window->device_cursor, device);
511 if (window->device_events)
512 g_hash_table_remove (window->device_events, device);
516 gdk_window_finalize (GObject *object)
518 GdkWindow *window = GDK_WINDOW (object);
519 GdkDeviceManager *device_manager;
521 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
522 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
524 if (!GDK_WINDOW_DESTROYED (window))
526 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
528 g_warning ("losing last reference to undestroyed window\n");
529 _gdk_window_destroy (window, FALSE);
532 /* We use TRUE here, to keep us from actually calling
533 * XDestroyWindow() on the window
535 _gdk_window_destroy (window, TRUE);
538 gdk_window_drop_cairo_surface (window);
542 g_object_unref (window->impl);
546 if (window->impl_window != window)
548 g_object_unref (window->impl_window);
549 window->impl_window = NULL;
553 cairo_region_destroy (window->shape);
555 if (window->input_shape)
556 cairo_region_destroy (window->input_shape);
559 g_object_unref (window->cursor);
561 if (window->device_cursor)
562 g_hash_table_destroy (window->device_cursor);
564 if (window->device_events)
565 g_hash_table_destroy (window->device_events);
567 if (window->source_event_masks)
568 g_hash_table_destroy (window->source_event_masks);
570 if (window->devices_inside)
571 g_list_free (window->devices_inside);
573 G_OBJECT_CLASS (parent_class)->finalize (object);
577 gdk_window_set_property (GObject *object,
582 GdkWindow *window = (GdkWindow *)object;
587 gdk_window_set_cursor (window, g_value_get_object (value));
591 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
597 gdk_window_get_property (GObject *object,
602 GdkWindow *window = (GdkWindow *) object;
607 g_value_set_object (value, gdk_window_get_cursor (window));
611 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
617 gdk_window_is_offscreen (GdkWindow *window)
619 return window->window_type == GDK_WINDOW_OFFSCREEN;
623 gdk_window_get_impl_window (GdkWindow *window)
625 return window->impl_window;
629 _gdk_window_get_impl_window (GdkWindow *window)
631 return gdk_window_get_impl_window (window);
635 gdk_window_has_impl (GdkWindow *window)
637 return window->impl_window == window;
641 gdk_window_is_toplevel (GdkWindow *window)
644 window->parent == NULL ||
645 window->parent->window_type == GDK_WINDOW_ROOT;
649 _gdk_window_has_impl (GdkWindow *window)
651 return gdk_window_has_impl (window);
655 gdk_window_has_no_impl (GdkWindow *window)
657 return window->impl_window != window;
661 remove_child_area (GdkWindow *private,
664 cairo_region_t *region)
667 cairo_region_t *child_region;
670 cairo_region_t *shape;
672 for (l = private->children; l; l = l->next)
679 /* If region is empty already, no need to do
680 anything potentially costly */
681 if (cairo_region_is_empty (region))
684 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
687 /* Ignore offscreen children, as they don't draw in their parent and
688 * don't take part in the clipping */
689 if (gdk_window_is_offscreen (child))
694 r.width = child->width;
695 r.height = child->height;
697 /* Bail early if child totally outside region */
698 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
701 child_region = cairo_region_create_rectangle (&r);
705 /* Adjust shape region to parent window coords */
706 cairo_region_translate (child->shape, child->x, child->y);
707 cairo_region_intersect (child_region, child->shape);
708 cairo_region_translate (child->shape, -child->x, -child->y);
710 else if (private->window_type == GDK_WINDOW_FOREIGN)
712 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
715 cairo_region_intersect (child_region, shape);
716 cairo_region_destroy (shape);
722 if (child->input_shape)
723 cairo_region_intersect (child_region, child->input_shape);
724 else if (private->window_type == GDK_WINDOW_FOREIGN)
726 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
729 cairo_region_intersect (child_region, shape);
730 cairo_region_destroy (shape);
735 cairo_region_subtract (region, child_region);
736 cairo_region_destroy (child_region);
741 static GdkVisibilityState
742 effective_visibility (GdkWindow *window)
744 GdkVisibilityState native;
746 if (!gdk_window_is_viewable (window))
747 return GDK_VISIBILITY_NOT_VIEWABLE;
749 native = window->impl_window->native_visibility;
751 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
752 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
753 return GDK_VISIBILITY_FULLY_OBSCURED;
754 else if (native == GDK_VISIBILITY_UNOBSCURED)
755 return window->visibility;
756 else /* native PARTIAL, private partial or unobscured */
757 return GDK_VISIBILITY_PARTIAL;
761 gdk_window_update_visibility (GdkWindow *window)
763 GdkVisibilityState new_visibility;
766 new_visibility = effective_visibility (window);
768 if (new_visibility != window->effective_visibility)
770 window->effective_visibility = new_visibility;
772 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
773 window->event_mask & GDK_VISIBILITY_NOTIFY)
775 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
777 event->visibility.state = new_visibility;
783 gdk_window_update_visibility_recursively (GdkWindow *window,
784 GdkWindow *only_for_impl)
789 gdk_window_update_visibility (window);
790 for (l = window->children; l != NULL; l = l->next)
793 if ((only_for_impl == NULL) ||
794 (only_for_impl == child->impl_window))
795 gdk_window_update_visibility_recursively (child, only_for_impl);
800 should_apply_clip_as_shape (GdkWindow *window)
803 gdk_window_has_impl (window) &&
804 /* Not for offscreens */
805 !gdk_window_is_offscreen (window) &&
806 /* or for toplevels */
807 !gdk_window_is_toplevel (window) &&
808 /* or for foreign windows */
809 window->window_type != GDK_WINDOW_FOREIGN &&
810 /* or for the root window */
811 window->window_type != GDK_WINDOW_ROOT;
815 apply_shape (GdkWindow *window,
816 cairo_region_t *region)
818 GdkWindowImplClass *impl_class;
820 /* We trash whether we applied a shape so that
821 we can avoid unsetting it many times, which
822 could happen in e.g. apply_clip_as_shape as
823 windows get resized */
824 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
826 impl_class->shape_combine_region (window,
828 else if (window->applied_shape)
829 impl_class->shape_combine_region (window,
832 window->applied_shape = region != NULL;
836 region_rect_equal (const cairo_region_t *region,
837 const GdkRectangle *rect)
839 GdkRectangle extents;
841 if (cairo_region_num_rectangles (region) != 1)
844 cairo_region_get_extents (region, &extents);
846 return extents.x == rect->x &&
847 extents.y == rect->y &&
848 extents.width == rect->width &&
849 extents.height == rect->height;
853 apply_clip_as_shape (GdkWindow *window)
858 r.width = window->width;
859 r.height = window->height;
861 /* We only apply the clip region if would differ
862 from the actual clip region implied by the size
863 of the window. This is to avoid unneccessarily
864 adding meaningless shapes to all native subwindows */
865 if (!region_rect_equal (window->clip_region, &r))
866 apply_shape (window, window->clip_region);
868 apply_shape (window, NULL);
872 recompute_visible_regions_internal (GdkWindow *private,
873 gboolean recalculate_clip,
874 gboolean recalculate_siblings,
875 gboolean recalculate_children)
880 cairo_region_t *new_clip, *old_clip_region_with_children;
881 gboolean clip_region_changed;
882 gboolean abs_pos_changed;
883 int old_abs_x, old_abs_y;
885 old_abs_x = private->abs_x;
886 old_abs_y = private->abs_y;
888 /* Update absolute position */
889 if (gdk_window_has_impl (private))
891 /* Native window starts here */
897 private->abs_x = private->parent->abs_x + private->x;
898 private->abs_y = private->parent->abs_y + private->y;
902 private->abs_x != old_abs_x ||
903 private->abs_y != old_abs_y;
905 /* Update clip region based on:
908 * siblings in parents above window
910 clip_region_changed = FALSE;
911 if (recalculate_clip)
913 if (private->viewable)
915 /* Calculate visible region (sans children) in parent window coords */
918 r.width = private->width;
919 r.height = private->height;
920 new_clip = cairo_region_create_rectangle (&r);
922 if (!gdk_window_is_toplevel (private))
924 cairo_region_intersect (new_clip, private->parent->clip_region);
926 /* Remove all overlapping children from parent. */
927 remove_child_area (private->parent, private, FALSE, new_clip);
930 /* Convert from parent coords to window coords */
931 cairo_region_translate (new_clip, -private->x, -private->y);
934 cairo_region_intersect (new_clip, private->shape);
937 new_clip = cairo_region_create ();
939 if (private->clip_region == NULL ||
940 !cairo_region_equal (private->clip_region, new_clip))
941 clip_region_changed = TRUE;
943 if (private->clip_region)
944 cairo_region_destroy (private->clip_region);
945 private->clip_region = new_clip;
947 old_clip_region_with_children = private->clip_region_with_children;
948 private->clip_region_with_children = cairo_region_copy (private->clip_region);
949 if (private->window_type != GDK_WINDOW_ROOT)
950 remove_child_area (private, NULL, FALSE, private->clip_region_with_children);
952 if (clip_region_changed ||
953 !cairo_region_equal (private->clip_region_with_children, old_clip_region_with_children))
954 private->clip_tag = new_region_tag ();
956 if (old_clip_region_with_children)
957 cairo_region_destroy (old_clip_region_with_children);
960 if (clip_region_changed)
962 GdkVisibilityState visibility;
963 gboolean fully_visible;
965 if (cairo_region_is_empty (private->clip_region))
966 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
971 fully_visible = cairo_region_equal (private->clip_region,
978 r.width = private->width;
979 r.height = private->height;
980 fully_visible = region_rect_equal (private->clip_region, &r);
984 visibility = GDK_VISIBILITY_UNOBSCURED;
986 visibility = GDK_VISIBILITY_PARTIAL;
989 if (private->visibility != visibility)
991 private->visibility = visibility;
992 gdk_window_update_visibility (private);
996 /* Update all children, recursively (except for root, where children are not exact). */
997 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
998 private->window_type != GDK_WINDOW_ROOT)
1000 for (l = private->children; l; l = l->next)
1003 /* Only recalculate clip if the the clip region changed, otherwise
1004 * there is no way the child clip region could change (its has not e.g. moved)
1005 * Except if recalculate_children is set to force child updates
1007 recompute_visible_regions_internal (child,
1008 recalculate_clip && (clip_region_changed || recalculate_children),
1013 if (clip_region_changed &&
1014 should_apply_clip_as_shape (private))
1015 apply_clip_as_shape (private);
1017 if (recalculate_siblings &&
1018 !gdk_window_is_toplevel (private))
1020 /* If we moved a child window in parent or changed the stacking order, then we
1021 * need to recompute the visible area of all the other children in the parent
1023 for (l = private->parent->children; l; l = l->next)
1027 if (child != private)
1028 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1031 /* We also need to recompute the _with_children clip for the parent */
1032 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1035 if (private->cairo_surface && gdk_window_has_impl (private))
1037 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1039 private->cairo_surface = iface->resize_cairo_surface (private,
1040 private->cairo_surface,
1044 else if (private->cairo_surface)
1045 gdk_window_drop_cairo_surface (private);
1048 /* Call this when private has changed in one or more of these ways:
1052 * stacking order of window changed
1055 * It will recalculate abs_x/y and the clip regions
1057 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1058 * for recalculate_siblings. (Mostly used internally for the recursion)
1060 * If a child window was removed (and you can't use that child for
1061 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1064 recompute_visible_regions (GdkWindow *private,
1065 gboolean recalculate_siblings,
1066 gboolean recalculate_children)
1068 recompute_visible_regions_internal (private,
1070 recalculate_siblings,
1071 recalculate_children);
1075 _gdk_window_update_size (GdkWindow *window)
1077 recompute_visible_regions (window, TRUE, FALSE);
1080 /* Find the native window that would be just above "child"
1081 * in the native stacking order if "child" was a native window
1082 * (it doesn't have to be native). If there is no such native
1083 * window inside this native parent then NULL is returned.
1084 * If child is NULL, find lowest native window in parent.
1087 find_native_sibling_above_helper (GdkWindow *parent,
1095 l = g_list_find (parent->children, child);
1096 g_assert (l != NULL); /* Better be a child of its parent... */
1097 l = l->prev; /* Start looking at the one above the child */
1100 l = g_list_last (parent->children);
1102 for (; l != NULL; l = l->prev)
1106 if (gdk_window_has_impl (w))
1109 g_assert (parent != w);
1110 w = find_native_sibling_above_helper (w, NULL);
1120 find_native_sibling_above (GdkWindow *parent,
1125 w = find_native_sibling_above_helper (parent, child);
1129 if (gdk_window_has_impl (parent))
1132 return find_native_sibling_above (parent->parent, parent);
1136 get_native_device_event_mask (GdkWindow *private,
1139 GdkEventMask event_mask;
1142 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1144 event_mask = private->event_mask;
1146 if (private->window_type == GDK_WINDOW_ROOT ||
1147 private->window_type == GDK_WINDOW_FOREIGN)
1153 /* Do whatever the app asks to, since the app
1154 * may be asking for weird things for native windows,
1155 * but don't use motion hints as that may affect non-native
1156 * child windows that don't want it. Also, we need to
1157 * set all the app-specified masks since they will be picked
1158 * up by any implicit grabs (i.e. if they were not set as
1159 * native we would not get the events we need). */
1160 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1162 /* We need thse for all native windows so we can
1163 emulate events on children: */
1166 GDK_VISIBILITY_NOTIFY_MASK |
1167 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1169 /* Additionally we select for pointer and button events
1170 * for toplevels as we need to get these to emulate
1171 * them for non-native subwindows. Even though we don't
1172 * select on them for all native windows we will get them
1173 * as the events are propagated out to the first window
1174 * that select for them.
1175 * Not selecting for button press on all windows is an
1176 * important thing, because in X only one client can do
1177 * so, and we don't want to unexpectedly prevent another
1178 * client from doing it.
1180 * We also need to do the same if the app selects for button presses
1181 * because then we will get implicit grabs for this window, and the
1182 * event mask used for that grab is based on the rest of the mask
1183 * for the window, but we might need more events than this window
1184 * lists due to some non-native child window.
1186 if (gdk_window_is_toplevel (private) ||
1187 mask & GDK_BUTTON_PRESS_MASK)
1189 GDK_POINTER_MOTION_MASK |
1190 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1198 get_native_grab_event_mask (GdkEventMask grab_mask)
1200 /* Similar to the above but for pointer events only */
1202 GDK_POINTER_MOTION_MASK |
1203 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1204 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1207 ~GDK_POINTER_MOTION_HINT_MASK);
1211 get_native_event_mask (GdkWindow *private)
1213 return get_native_device_event_mask (private, NULL);
1216 /* Puts the native window in the right order wrt the other native windows
1217 * in the hierarchy, given the position it has in the client side data.
1218 * This is useful if some operation changed the stacking order.
1219 * This calls assumes the native window is now topmost in its native parent.
1222 sync_native_window_stack_position (GdkWindow *window)
1225 GdkWindowImplClass *impl_class;
1226 GList listhead = {0};
1228 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1230 above = find_native_sibling_above (window->parent, window);
1233 listhead.data = window;
1234 impl_class->restack_under (above, &listhead);
1239 * gdk_window_new: (constructor)
1240 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1241 * the default root window for the default display.
1242 * @attributes: attributes of the new window
1243 * @attributes_mask: mask indicating which fields in @attributes are valid
1245 * Creates a new #GdkWindow using the attributes from
1246 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1247 * more details. Note: to use this on displays other than the default
1248 * display, @parent must be specified.
1250 * Return value: (transfer full): the new #GdkWindow
1253 gdk_window_new (GdkWindow *parent,
1254 GdkWindowAttr *attributes,
1255 gint attributes_mask)
1259 GdkDisplay *display;
1262 GdkEventMask event_mask;
1263 GdkWindow *real_parent;
1264 GdkDeviceManager *device_manager;
1266 g_return_val_if_fail (attributes != NULL, NULL);
1270 GDK_NOTE (MULTIHEAD,
1271 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1273 screen = gdk_screen_get_default ();
1274 parent = gdk_screen_get_root_window (screen);
1277 screen = gdk_window_get_screen (parent);
1279 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1281 if (GDK_WINDOW_DESTROYED (parent))
1283 g_warning ("gdk_window_new(): parent is destroyed\n");
1287 display = gdk_screen_get_display (screen);
1289 window = _gdk_display_create_window (display);
1291 /* Windows with a foreign parent are treated as if they are children
1292 * of the root window, except for actual creation.
1294 real_parent = parent;
1295 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1296 parent = gdk_screen_get_root_window (screen);
1298 window->parent = parent;
1300 window->accept_focus = TRUE;
1301 window->focus_on_map = TRUE;
1303 if (attributes_mask & GDK_WA_X)
1308 if (attributes_mask & GDK_WA_Y)
1315 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1316 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1318 if (attributes->wclass == GDK_INPUT_ONLY)
1320 /* Backwards compatiblity - we've always ignored
1321 * attributes->window_type for input-only windows
1324 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1325 window->window_type = GDK_WINDOW_TEMP;
1327 window->window_type = GDK_WINDOW_CHILD;
1330 window->window_type = attributes->window_type;
1333 switch (window->window_type)
1335 case GDK_WINDOW_TOPLEVEL:
1336 case GDK_WINDOW_TEMP:
1337 case GDK_WINDOW_OFFSCREEN:
1338 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1339 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1340 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1341 case GDK_WINDOW_CHILD:
1345 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1349 if (attributes_mask & GDK_WA_VISUAL)
1350 window->visual = attributes->visual;
1352 window->visual = gdk_screen_get_system_visual (screen);
1354 window->event_mask = attributes->event_mask;
1356 if (attributes->wclass == GDK_INPUT_OUTPUT)
1358 window->input_only = FALSE;
1359 window->depth = window->visual->depth;
1361 /* XXX: Cache this somehow? */
1362 window->background = cairo_pattern_create_rgb (0, 0, 0);
1367 window->input_only = TRUE;
1371 window->parent->children = g_list_prepend (window->parent->children, window);
1374 if (window->parent->window_type == GDK_WINDOW_ROOT)
1375 native = TRUE; /* Always use native windows for toplevels */
1376 else if (!window->input_only &&
1377 (attributes_mask & GDK_WA_VISUAL &&
1378 attributes->visual != gdk_window_get_visual (window->parent)))
1379 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1381 if (gdk_window_is_offscreen (window))
1383 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1384 window->impl_window = window;
1388 event_mask = get_native_event_mask (window);
1390 /* Create the impl */
1391 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1392 window->impl_window = window;
1394 /* This will put the native window topmost in the native parent, which may
1395 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1396 if (!_gdk_window_has_impl (real_parent))
1397 sync_native_window_stack_position (window);
1401 window->impl_window = g_object_ref (window->parent->impl_window);
1402 window->impl = g_object_ref (window->impl_window->impl);
1405 recompute_visible_regions (window, TRUE, FALSE);
1407 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1408 (attributes->cursor) :
1411 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1412 g_signal_connect (device_manager, "device-removed",
1413 G_CALLBACK (device_removed_cb), window);
1419 is_parent_of (GdkWindow *parent,
1430 w = gdk_window_get_parent (w);
1437 change_impl (GdkWindow *private,
1438 GdkWindow *impl_window,
1443 GdkWindowImpl *old_impl;
1444 GdkWindow *old_impl_window;
1446 old_impl = private->impl;
1447 old_impl_window = private->impl_window;
1448 if (private != impl_window)
1449 private->impl_window = g_object_ref (impl_window);
1451 private->impl_window = private;
1452 private->impl = g_object_ref (new);
1453 if (old_impl_window != private)
1454 g_object_unref (old_impl_window);
1455 g_object_unref (old_impl);
1457 for (l = private->children; l != NULL; l = l->next)
1461 if (child->impl == old_impl)
1462 change_impl (child, impl_window, new);
1467 reparent_to_impl (GdkWindow *private)
1472 GdkWindowImplClass *impl_class;
1474 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1476 /* Enumerate in reverse order so we get the right order for the native
1477 windows (first in childrens list is topmost, and reparent places on top) */
1478 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1482 if (child->impl == private->impl)
1483 reparent_to_impl (child);
1486 show = impl_class->reparent ((GdkWindow *)child,
1487 (GdkWindow *)private,
1488 child->x, child->y);
1490 gdk_window_show_unraised ((GdkWindow *)child);
1497 * gdk_window_reparent:
1498 * @window: a #GdkWindow
1499 * @new_parent: new parent to move @window into
1500 * @x: X location inside the new parent
1501 * @y: Y location inside the new parent
1503 * Reparents @window into the given @new_parent. The window being
1504 * reparented will be unmapped as a side effect.
1508 gdk_window_reparent (GdkWindow *window,
1509 GdkWindow *new_parent,
1513 GdkWindow *old_parent;
1515 gboolean show, was_mapped, applied_clip_as_shape;
1516 gboolean do_reparent_to_impl;
1517 GdkEventMask old_native_event_mask;
1518 GdkWindowImplClass *impl_class;
1520 g_return_if_fail (GDK_IS_WINDOW (window));
1521 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1522 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1524 if (GDK_WINDOW_DESTROYED (window) ||
1525 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1528 screen = gdk_window_get_screen (window);
1530 new_parent = gdk_screen_get_root_window (screen);
1532 /* No input-output children of input-only windows */
1533 if (new_parent->input_only && !window->input_only)
1536 /* Don't create loops in hierarchy */
1537 if (is_parent_of (window, new_parent))
1540 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1541 To make sure we're ok, just wipe it. */
1542 gdk_window_drop_cairo_surface (window);
1544 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1545 old_parent = window->parent;
1547 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1550 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1551 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1552 new_parent->window_type == GDK_WINDOW_FOREIGN)
1553 gdk_window_ensure_native (window);
1555 applied_clip_as_shape = should_apply_clip_as_shape (window);
1557 old_native_event_mask = 0;
1558 do_reparent_to_impl = FALSE;
1559 if (gdk_window_has_impl (window))
1561 old_native_event_mask = get_native_event_mask (window);
1563 show = impl_class->reparent (window, new_parent, x, y);
1567 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1568 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1569 new_parent->window_type != GDK_WINDOW_FOREIGN);
1572 gdk_window_hide (window);
1574 do_reparent_to_impl = TRUE;
1575 change_impl (window,
1576 new_parent->impl_window,
1580 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1583 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1585 new_parent = gdk_screen_get_root_window (screen);
1589 old_parent->children = g_list_remove (old_parent->children, window);
1591 window->parent = new_parent;
1595 new_parent->children = g_list_prepend (new_parent->children, window);
1597 /* Switch the window type as appropriate */
1599 switch (GDK_WINDOW_TYPE (new_parent))
1601 case GDK_WINDOW_ROOT:
1602 case GDK_WINDOW_FOREIGN:
1603 if (window->toplevel_window_type != -1)
1604 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1605 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1606 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1608 case GDK_WINDOW_OFFSCREEN:
1609 case GDK_WINDOW_TOPLEVEL:
1610 case GDK_WINDOW_CHILD:
1611 case GDK_WINDOW_TEMP:
1612 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1613 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1615 /* Save the original window type so we can restore it if the
1616 * window is reparented back to be a toplevel
1618 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1619 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1623 /* We might have changed window type for a native windows, so we
1624 need to change the event mask too. */
1625 if (gdk_window_has_impl (window))
1627 GdkEventMask native_event_mask = get_native_event_mask (window);
1629 if (native_event_mask != old_native_event_mask)
1630 impl_class->set_events (window, native_event_mask);
1633 _gdk_window_update_viewable (window);
1635 recompute_visible_regions (window, TRUE, FALSE);
1636 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1637 recompute_visible_regions (old_parent, FALSE, TRUE);
1639 /* We used to apply the clip as the shape, but no more.
1640 Reset this to the real shape */
1641 if (gdk_window_has_impl (window) &&
1642 applied_clip_as_shape &&
1643 !should_apply_clip_as_shape (window))
1644 apply_shape (window, window->shape);
1646 if (do_reparent_to_impl)
1647 reparent_to_impl (window);
1650 /* The reparent will have put the native window topmost in the native parent,
1651 * which may be wrong wrt other native windows in the non-native hierarchy,
1653 if (!gdk_window_has_impl (new_parent))
1654 sync_native_window_stack_position (window);
1658 gdk_window_show_unraised (window);
1660 _gdk_synthesize_crossing_events_for_geometry_change (window);
1664 * gdk_window_ensure_native:
1665 * @window: a #GdkWindow
1667 * Tries to ensure that there is a window-system native window for this
1668 * GdkWindow. This may fail in some situations, returning %FALSE.
1670 * Offscreen window and children of them can never have native windows.
1672 * Some backends may not support native child windows.
1674 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1679 gdk_window_ensure_native (GdkWindow *window)
1681 GdkWindow *impl_window;
1682 GdkWindowImpl *new_impl, *old_impl;
1683 GdkDisplay *display;
1687 GdkWindowImplClass *impl_class;
1689 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1691 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1692 GDK_WINDOW_DESTROYED (window))
1695 impl_window = gdk_window_get_impl_window (window);
1697 if (gdk_window_is_offscreen (impl_window))
1698 return FALSE; /* native in offscreens not supported */
1700 if (impl_window == window)
1701 /* Already has an impl, and its not offscreen . */
1704 /* Need to create a native window */
1706 gdk_window_drop_cairo_surface (window);
1708 screen = gdk_window_get_screen (window);
1709 display = gdk_screen_get_display (screen);
1711 old_impl = window->impl;
1712 _gdk_display_create_window_impl (display,
1713 window, window->parent,
1715 get_native_event_mask (window),
1717 new_impl = window->impl;
1719 window->impl = old_impl;
1720 change_impl (window, window, new_impl);
1722 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1724 /* Native window creation will put the native window topmost in the
1725 * native parent, which may be wrong wrt the position of the previous
1726 * non-native window wrt to the other non-native children, so correct this.
1728 above = find_native_sibling_above (window->parent, window);
1731 listhead.data = window;
1732 listhead.prev = NULL;
1733 listhead.next = NULL;
1734 impl_class->restack_under ((GdkWindow *)above, &listhead);
1737 recompute_visible_regions (window, FALSE, FALSE);
1739 /* The shape may not have been set, as the clip region doesn't actually
1740 change, so do it here manually */
1741 if (should_apply_clip_as_shape (window))
1742 apply_clip_as_shape (window);
1744 reparent_to_impl (window);
1746 if (!window->input_only)
1747 impl_class->set_background (window, window->background);
1749 impl_class->input_shape_combine_region (window,
1750 window->input_shape,
1753 if (gdk_window_is_viewable (window))
1754 impl_class->show (window, FALSE);
1760 * _gdk_event_filter_unref:
1761 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1762 * @filter: A window filter
1764 * Release a reference to @filter. Note this function may
1765 * mutate the list storage, so you need to handle this
1766 * if iterating over a list of filters.
1769 _gdk_event_filter_unref (GdkWindow *window,
1770 GdkEventFilter *filter)
1776 filters = &_gdk_default_filters;
1778 filters = &window->filters;
1780 tmp_list = *filters;
1783 GdkEventFilter *iter_filter = tmp_list->data;
1787 tmp_list = tmp_list->next;
1789 if (iter_filter != filter)
1792 g_assert (iter_filter->ref_count > 0);
1794 filter->ref_count--;
1795 if (filter->ref_count != 0)
1798 *filters = g_list_remove_link (*filters, node);
1800 g_list_free_1 (node);
1805 window_remove_filters (GdkWindow *window)
1807 while (window->filters)
1808 _gdk_event_filter_unref (window, window->filters->data);
1812 update_pointer_info_foreach (GdkDisplay *display,
1814 GdkPointerWindowInfo *pointer_info,
1817 GdkWindow *window = user_data;
1819 if (pointer_info->toplevel_under_pointer == window)
1821 g_object_unref (pointer_info->toplevel_under_pointer);
1822 pointer_info->toplevel_under_pointer = NULL;
1827 window_remove_from_pointer_info (GdkWindow *window,
1828 GdkDisplay *display)
1830 _gdk_display_pointer_info_foreach (display,
1831 update_pointer_info_foreach,
1836 * _gdk_window_destroy_hierarchy:
1837 * @window: a #GdkWindow
1838 * @recursing: If TRUE, then this is being called because a parent
1840 * @recursing_native: If TRUE, then this is being called because a native parent
1841 * was destroyed. This generally means that the call to the
1842 * windowing system to destroy the window can be omitted, since
1843 * it will be destroyed as a result of the parent being destroyed.
1844 * Unless @foreign_destroy.
1845 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1846 * external agency. The window has already been destroyed and no
1847 * windowing system calls should be made. (This may never happen
1848 * for some windowing systems.)
1850 * Internal function to destroy a window. Like gdk_window_destroy(),
1851 * but does not drop the reference count created by gdk_window_new().
1854 _gdk_window_destroy_hierarchy (GdkWindow *window,
1856 gboolean recursing_native,
1857 gboolean foreign_destroy)
1859 GdkWindowImplClass *impl_class;
1860 GdkWindow *temp_window;
1862 GdkDisplay *display;
1866 g_return_if_fail (GDK_IS_WINDOW (window));
1868 if (GDK_WINDOW_DESTROYED (window))
1871 display = gdk_window_get_display (window);
1872 screen = gdk_window_get_screen (window);
1873 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1874 if (temp_window == window)
1875 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1878 switch (window->window_type)
1880 case GDK_WINDOW_ROOT:
1881 if (!screen->closed)
1883 g_error ("attempted to destroy root window");
1886 /* else fall thru */
1887 case GDK_WINDOW_TOPLEVEL:
1888 case GDK_WINDOW_CHILD:
1889 case GDK_WINDOW_TEMP:
1890 case GDK_WINDOW_FOREIGN:
1891 case GDK_WINDOW_OFFSCREEN:
1892 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1894 /* Logically, it probably makes more sense to send
1895 * a "destroy yourself" message to the foreign window
1896 * whether or not it's in our hierarchy; but for historical
1897 * reasons, we only send "destroy yourself" messages to
1898 * foreign windows in our hierarchy.
1902 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1904 if (gdk_window_has_impl (window))
1905 impl_class->destroy_foreign (window);
1908 /* Also for historical reasons, we remove any filters
1909 * on a foreign window when it or a parent is destroyed;
1910 * this likely causes problems if two separate portions
1911 * of code are maintaining filter lists on a foreign window.
1913 window_remove_filters (window);
1919 if (window->parent->children)
1920 window->parent->children = g_list_remove (window->parent->children, window);
1923 GDK_WINDOW_IS_MAPPED (window))
1925 recompute_visible_regions (window, TRUE, FALSE);
1926 gdk_window_invalidate_in_parent (window);
1930 gdk_window_free_paint_stack (window);
1932 if (window->background)
1934 cairo_pattern_destroy (window->background);
1935 window->background = NULL;
1938 if (window->window_type == GDK_WINDOW_FOREIGN)
1939 g_assert (window->children == NULL);
1942 children = tmp = window->children;
1943 window->children = NULL;
1947 temp_window = tmp->data;
1951 _gdk_window_destroy_hierarchy (temp_window,
1953 recursing_native || gdk_window_has_impl (window),
1957 g_list_free (children);
1960 _gdk_window_clear_update_area (window);
1962 gdk_window_drop_cairo_surface (window);
1964 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1966 if (gdk_window_has_impl (window))
1967 impl_class->destroy (window, recursing_native,
1971 /* hide to make sure we repaint and break grabs */
1972 gdk_window_hide (window);
1975 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
1976 window->parent = NULL;
1977 window->destroyed = TRUE;
1979 window_remove_filters (window);
1981 window_remove_from_pointer_info (window, display);
1983 if (window->clip_region)
1985 cairo_region_destroy (window->clip_region);
1986 window->clip_region = NULL;
1989 if (window->clip_region_with_children)
1991 cairo_region_destroy (window->clip_region_with_children);
1992 window->clip_region_with_children = NULL;
1995 if (window->outstanding_moves)
1997 g_list_foreach (window->outstanding_moves, (GFunc)gdk_window_region_move_free, NULL);
1998 g_list_free (window->outstanding_moves);
1999 window->outstanding_moves = NULL;
2007 * _gdk_window_destroy:
2008 * @window: a #GdkWindow
2009 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2010 * external agency. The window has already been destroyed and no
2011 * windowing system calls should be made. (This may never happen
2012 * for some windowing systems.)
2014 * Internal function to destroy a window. Like gdk_window_destroy(),
2015 * but does not drop the reference count created by gdk_window_new().
2018 _gdk_window_destroy (GdkWindow *window,
2019 gboolean foreign_destroy)
2021 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2025 * gdk_window_destroy:
2026 * @window: a #GdkWindow
2028 * Destroys the window system resources associated with @window and decrements @window's
2029 * reference count. The window system resources for all children of @window are also
2030 * destroyed, but the children's reference counts are not decremented.
2032 * Note that a window will not be destroyed automatically when its reference count
2033 * reaches zero. You must call this function yourself before that happens.
2037 gdk_window_destroy (GdkWindow *window)
2039 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2040 g_object_unref (window);
2044 * gdk_window_set_user_data:
2045 * @window: a #GdkWindow
2046 * @user_data: (allow-none): user data
2048 * For most purposes this function is deprecated in favor of
2049 * g_object_set_data(). However, for historical reasons GTK+ stores
2050 * the #GtkWidget that owns a #GdkWindow as user data on the
2051 * #GdkWindow. So, custom widget implementations should use
2052 * this function for that. If GTK+ receives an event for a #GdkWindow,
2053 * and the user data for the window is non-%NULL, GTK+ will assume the
2054 * user data is a #GtkWidget, and forward the event to that widget.
2058 gdk_window_set_user_data (GdkWindow *window,
2061 g_return_if_fail (GDK_IS_WINDOW (window));
2063 window->user_data = user_data;
2067 * gdk_window_get_user_data:
2068 * @window: a #GdkWindow
2069 * @data: (out): return location for user data
2071 * Retrieves the user data for @window, which is normally the widget
2072 * that @window belongs to. See gdk_window_set_user_data().
2076 gdk_window_get_user_data (GdkWindow *window,
2079 g_return_if_fail (GDK_IS_WINDOW (window));
2081 *data = window->user_data;
2085 * gdk_window_get_window_type:
2086 * @window: a #GdkWindow
2088 * Gets the type of the window. See #GdkWindowType.
2090 * Return value: type of window
2093 gdk_window_get_window_type (GdkWindow *window)
2095 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2097 return GDK_WINDOW_TYPE (window);
2101 * gdk_window_get_visual:
2102 * @window: a #GdkWindow
2104 * Gets the #GdkVisual describing the pixel format of @window.
2106 * Return value: (transfer none): a #GdkVisual
2111 gdk_window_get_visual (GdkWindow *window)
2113 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2115 return window->visual;
2119 * gdk_window_get_screen:
2120 * @window: a #GdkWindow
2122 * Gets the #GdkScreen associated with a #GdkWindow.
2124 * Return value: (transfer none): the #GdkScreen associated with @window
2129 gdk_window_get_screen (GdkWindow *window)
2131 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2133 return gdk_visual_get_screen (window->visual);
2137 * gdk_window_get_display:
2138 * @window: a #GdkWindow
2140 * Gets the #GdkDisplay associated with a #GdkWindow.
2142 * Return value: (transfer none): the #GdkDisplay associated with @window
2147 gdk_window_get_display (GdkWindow *window)
2149 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2151 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2154 * gdk_window_is_destroyed:
2155 * @window: a #GdkWindow
2157 * Check to see if a window is destroyed..
2159 * Return value: %TRUE if the window is destroyed
2164 gdk_window_is_destroyed (GdkWindow *window)
2166 return GDK_WINDOW_DESTROYED (window);
2170 to_embedder (GdkWindow *window,
2171 gdouble offscreen_x,
2172 gdouble offscreen_y,
2173 gdouble *embedder_x,
2174 gdouble *embedder_y)
2176 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2177 offscreen_x, offscreen_y,
2178 embedder_x, embedder_y);
2182 from_embedder (GdkWindow *window,
2185 gdouble *offscreen_x,
2186 gdouble *offscreen_y)
2188 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2189 embedder_x, embedder_y,
2190 offscreen_x, offscreen_y);
2194 * gdk_window_has_native:
2195 * @window: a #GdkWindow
2197 * Checks whether the window has a native window or not. Note that
2198 * you can use gdk_window_ensure_native() if a native window is needed.
2200 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2205 gdk_window_has_native (GdkWindow *window)
2207 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2209 return window->parent == NULL || window->parent->impl != window->impl;
2213 * gdk_window_get_position:
2214 * @window: a #GdkWindow
2215 * @x: (out) (allow-none): X coordinate of window
2216 * @y: (out) (allow-none): Y coordinate of window
2218 * Obtains the position of the window as reported in the
2219 * most-recently-processed #GdkEventConfigure. Contrast with
2220 * gdk_window_get_geometry() which queries the X server for the
2221 * current window position, regardless of which events have been
2222 * received or processed.
2224 * The position coordinates are relative to the window's parent window.
2228 gdk_window_get_position (GdkWindow *window,
2232 g_return_if_fail (GDK_IS_WINDOW (window));
2241 * gdk_window_get_parent:
2242 * @window: a #GdkWindow
2244 * Obtains the parent of @window, as known to GDK. Does not query the
2245 * X server; thus this returns the parent as passed to gdk_window_new(),
2246 * not the actual parent. This should never matter unless you're using
2247 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2248 * matter for toplevel windows, because the window manager may choose
2251 * Note that you should use gdk_window_get_effective_parent() when
2252 * writing generic code that walks up a window hierarchy, because
2253 * gdk_window_get_parent() will most likely not do what you expect if
2254 * there are offscreen windows in the hierarchy.
2256 * Return value: (transfer none): parent of @window
2259 gdk_window_get_parent (GdkWindow *window)
2261 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2263 return window->parent;
2267 * gdk_window_get_effective_parent:
2268 * @window: a #GdkWindow
2270 * Obtains the parent of @window, as known to GDK. Works like
2271 * gdk_window_get_parent() for normal windows, but returns the
2272 * window's embedder for offscreen windows.
2274 * See also: gdk_offscreen_window_get_embedder()
2276 * Return value: (transfer none): effective parent of @window
2281 gdk_window_get_effective_parent (GdkWindow *window)
2283 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2285 if (gdk_window_is_offscreen (window))
2286 return gdk_offscreen_window_get_embedder (window);
2288 return window->parent;
2292 * gdk_window_get_toplevel:
2293 * @window: a #GdkWindow
2295 * Gets the toplevel window that's an ancestor of @window.
2297 * Any window type but %GDK_WINDOW_CHILD is considered a
2298 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2299 * has a root window as parent.
2301 * Note that you should use gdk_window_get_effective_toplevel() when
2302 * you want to get to a window's toplevel as seen on screen, because
2303 * gdk_window_get_toplevel() will most likely not do what you expect
2304 * if there are offscreen windows in the hierarchy.
2306 * Return value: (transfer none): the toplevel window containing @window
2309 gdk_window_get_toplevel (GdkWindow *window)
2311 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2313 while (window->window_type == GDK_WINDOW_CHILD)
2315 if (gdk_window_is_toplevel (window))
2317 window = window->parent;
2324 * gdk_window_get_effective_toplevel:
2325 * @window: a #GdkWindow
2327 * Gets the toplevel window that's an ancestor of @window.
2329 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2330 * embedder as its parent, using gdk_window_get_effective_parent().
2332 * See also: gdk_offscreen_window_get_embedder()
2334 * Return value: (transfer none): the effective toplevel window containing @window
2339 gdk_window_get_effective_toplevel (GdkWindow *window)
2343 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2345 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2346 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2353 * gdk_window_get_children:
2354 * @window: a #GdkWindow
2356 * Gets the list of children of @window known to GDK.
2357 * This function only returns children created via GDK,
2358 * so for example it's useless when used with the root window;
2359 * it only returns windows an application created itself.
2361 * The returned list must be freed, but the elements in the
2364 * Return value: (transfer container) (element-type GdkWindow):
2365 * list of child windows inside @window
2368 gdk_window_get_children (GdkWindow *window)
2370 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2372 if (GDK_WINDOW_DESTROYED (window))
2375 return g_list_copy (window->children);
2379 * gdk_window_peek_children:
2380 * @window: a #GdkWindow
2382 * Like gdk_window_get_children(), but does not copy the list of
2383 * children, so the list does not need to be freed.
2385 * Return value: (transfer none) (element-type GdkWindow):
2386 * a reference to the list of child windows in @window
2389 gdk_window_peek_children (GdkWindow *window)
2391 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2393 if (GDK_WINDOW_DESTROYED (window))
2396 return window->children;
2400 * gdk_window_add_filter: (skip)
2401 * @window: (allow-none): a #GdkWindow
2402 * @function: filter callback
2403 * @data: data to pass to filter callback
2405 * Adds an event filter to @window, allowing you to intercept events
2406 * before they reach GDK. This is a low-level operation and makes it
2407 * easy to break GDK and/or GTK+, so you have to know what you're
2408 * doing. Pass %NULL for @window to get all events for all windows,
2409 * instead of events for a specific window.
2411 * See gdk_display_add_client_message_filter() if you are interested
2412 * in X ClientMessage events.
2414 * If you are interested in X GenericEvents, bear in mind that
2415 * XGetEventData() has been already called on the event, and
2416 * XFreeEventData() must not be called within @function.
2419 gdk_window_add_filter (GdkWindow *window,
2420 GdkFilterFunc function,
2424 GdkEventFilter *filter;
2426 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2428 if (window && GDK_WINDOW_DESTROYED (window))
2431 /* Filters are for the native events on the native window, so
2432 ensure there is a native window. */
2434 gdk_window_ensure_native (window);
2437 tmp_list = window->filters;
2439 tmp_list = _gdk_default_filters;
2443 filter = (GdkEventFilter *)tmp_list->data;
2444 if ((filter->function == function) && (filter->data == data))
2446 filter->ref_count++;
2449 tmp_list = tmp_list->next;
2452 filter = g_new (GdkEventFilter, 1);
2453 filter->function = function;
2454 filter->data = data;
2455 filter->ref_count = 1;
2459 window->filters = g_list_append (window->filters, filter);
2461 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2465 * gdk_window_remove_filter: (skip)
2466 * @window: a #GdkWindow
2467 * @function: previously-added filter function
2468 * @data: user data for previously-added filter function
2470 * Remove a filter previously added with gdk_window_add_filter().
2473 gdk_window_remove_filter (GdkWindow *window,
2474 GdkFilterFunc function,
2478 GdkEventFilter *filter;
2480 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2483 tmp_list = window->filters;
2485 tmp_list = _gdk_default_filters;
2489 filter = (GdkEventFilter *)tmp_list->data;
2490 tmp_list = tmp_list->next;
2492 if ((filter->function == function) && (filter->data == data))
2494 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2496 _gdk_event_filter_unref (window, filter);
2504 * gdk_screen_get_toplevel_windows:
2505 * @screen: The #GdkScreen where the toplevels are located.
2507 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2508 * A toplevel window is a child of the root window (see
2509 * gdk_get_default_root_window()).
2511 * The returned list should be freed with g_list_free(), but
2512 * its elements need not be freed.
2514 * Return value: (transfer container) (element-type GdkWindow):
2515 * list of toplevel windows, free with g_list_free()
2520 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2522 GdkWindow * root_window;
2523 GList *new_list = NULL;
2526 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2528 root_window = gdk_screen_get_root_window (screen);
2530 tmp_list = root_window->children;
2533 GdkWindow *w = tmp_list->data;
2535 if (w->window_type != GDK_WINDOW_FOREIGN)
2536 new_list = g_list_prepend (new_list, w);
2537 tmp_list = tmp_list->next;
2544 * gdk_window_is_visible:
2545 * @window: a #GdkWindow
2547 * Checks whether the window has been mapped (with gdk_window_show() or
2548 * gdk_window_show_unraised()).
2550 * Return value: %TRUE if the window is mapped
2553 gdk_window_is_visible (GdkWindow *window)
2555 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2557 return GDK_WINDOW_IS_MAPPED (window);
2561 * gdk_window_is_viewable:
2562 * @window: a #GdkWindow
2564 * Check if the window and all ancestors of the window are
2565 * mapped. (This is not necessarily "viewable" in the X sense, since
2566 * we only check as far as we have GDK window parents, not to the root
2569 * Return value: %TRUE if the window is viewable
2572 gdk_window_is_viewable (GdkWindow *window)
2574 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2576 if (window->destroyed)
2579 return window->viewable;
2583 * gdk_window_get_state:
2584 * @window: a #GdkWindow
2586 * Gets the bitwise OR of the currently active window state flags,
2587 * from the #GdkWindowState enumeration.
2589 * Return value: window state bitfield
2592 gdk_window_get_state (GdkWindow *window)
2594 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2596 return window->state;
2599 static cairo_content_t
2600 gdk_window_get_content (GdkWindow *window)
2602 cairo_surface_t *surface;
2603 cairo_content_t content;
2605 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2607 surface = _gdk_window_ref_cairo_surface (window);
2608 content = cairo_surface_get_content (surface);
2609 cairo_surface_destroy (surface);
2614 /* This creates an empty "implicit" paint region for the impl window.
2615 * By itself this does nothing, but real paints to this window
2616 * or children of it can use this surface as backing to avoid allocating
2617 * multiple surfaces for subwindow rendering. When doing so they
2618 * add to the region of the implicit paint region, which will be
2619 * pushed to the window when the implicit paint region is ended.
2620 * Such paints should not copy anything to the window on paint end, but
2621 * should rely on the implicit paint end.
2622 * The implicit paint will be automatically ended if someone draws
2623 * directly to the window or a child window.
2626 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2628 GdkWindowPaint *paint;
2630 g_assert (gdk_window_has_impl (window));
2632 if (GDK_IS_PAINTABLE (window->impl))
2633 return FALSE; /* Implementation does double buffering */
2635 if (window->paint_stack != NULL ||
2636 window->implicit_paint != NULL)
2637 return FALSE; /* Don't stack implicit paints */
2639 /* Never do implicit paints for foreign windows, they don't need
2640 * double buffer combination since they have no client side children,
2641 * and creating surfaces for them is risky since they could disappear
2644 if (window->window_type == GDK_WINDOW_FOREIGN)
2647 paint = g_new (GdkWindowPaint, 1);
2648 paint->region = cairo_region_create (); /* Empty */
2649 paint->uses_implicit = FALSE;
2650 paint->flushed = FALSE;
2651 paint->surface = gdk_window_create_similar_surface (window,
2652 gdk_window_get_content (window),
2653 MAX (rect->width, 1),
2654 MAX (rect->height, 1));
2655 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2657 window->implicit_paint = paint;
2662 static cairo_surface_t *
2663 gdk_window_ref_impl_surface (GdkWindow *window)
2665 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2669 gdk_cairo_create_for_impl (GdkWindow *window)
2671 cairo_surface_t *surface;
2674 surface = gdk_window_ref_impl_surface (window);
2675 cr = cairo_create (surface);
2677 cairo_surface_destroy (surface);
2682 /* Ensure that all content related to this (sub)window is pushed to the
2683 native region. If there is an active paint then that area is not
2684 pushed, in order to not show partially finished double buffers. */
2686 gdk_window_flush_implicit_paint (GdkWindow *window)
2688 GdkWindow *impl_window;
2689 GdkWindowPaint *paint;
2690 cairo_region_t *region;
2693 impl_window = gdk_window_get_impl_window (window);
2694 if (impl_window->implicit_paint == NULL)
2697 paint = impl_window->implicit_paint;
2698 paint->flushed = TRUE;
2699 region = cairo_region_copy (window->clip_region_with_children);
2701 /* Don't flush active double buffers, as that may show partially done
2703 for (list = window->paint_stack; list != NULL; list = list->next)
2705 GdkWindowPaint *tmp_paint = list->data;
2707 cairo_region_subtract (region, tmp_paint->region);
2710 cairo_region_translate (region, -window->abs_x, -window->abs_y);
2711 cairo_region_intersect (region, paint->region);
2713 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2717 /* Remove flushed region from the implicit paint */
2718 cairo_region_subtract (paint->region, region);
2720 /* Some regions are valid, push these to window now */
2721 cr = gdk_cairo_create_for_impl (window);
2722 gdk_cairo_region (cr, region);
2724 cairo_set_source_surface (cr, paint->surface, 0, 0);
2725 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2730 cairo_region_destroy (region);
2733 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2735 gdk_window_end_implicit_paint (GdkWindow *window)
2737 GdkWindowPaint *paint;
2739 g_assert (gdk_window_has_impl (window));
2741 g_assert (window->implicit_paint != NULL);
2743 paint = window->implicit_paint;
2745 window->implicit_paint = NULL;
2747 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2751 /* Some regions are valid, push these to window now */
2752 cr = gdk_cairo_create_for_impl (window);
2753 gdk_cairo_region (cr, paint->region);
2755 cairo_set_source_surface (cr, paint->surface, 0, 0);
2756 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2761 cairo_region_destroy (paint->region);
2763 cairo_surface_destroy (paint->surface);
2768 * gdk_window_begin_paint_rect:
2769 * @window: a #GdkWindow
2770 * @rectangle: rectangle you intend to draw to
2772 * A convenience wrapper around gdk_window_begin_paint_region() which
2773 * creates a rectangular region for you. See
2774 * gdk_window_begin_paint_region() for details.
2778 gdk_window_begin_paint_rect (GdkWindow *window,
2779 const GdkRectangle *rectangle)
2781 cairo_region_t *region;
2783 g_return_if_fail (GDK_IS_WINDOW (window));
2785 region = cairo_region_create_rectangle (rectangle);
2786 gdk_window_begin_paint_region (window, region);
2787 cairo_region_destroy (region);
2791 * gdk_window_begin_paint_region:
2792 * @window: a #GdkWindow
2793 * @region: region you intend to draw to
2795 * Indicates that you are beginning the process of redrawing @region.
2796 * A backing store (offscreen buffer) large enough to contain @region
2797 * will be created. The backing store will be initialized with the
2798 * background color or background surface for @window. Then, all
2799 * drawing operations performed on @window will be diverted to the
2800 * backing store. When you call gdk_window_end_paint(), the backing
2801 * store will be copied to @window, making it visible onscreen. Only
2802 * the part of @window contained in @region will be modified; that is,
2803 * drawing operations are clipped to @region.
2805 * The net result of all this is to remove flicker, because the user
2806 * sees the finished product appear all at once when you call
2807 * gdk_window_end_paint(). If you draw to @window directly without
2808 * calling gdk_window_begin_paint_region(), the user may see flicker
2809 * as individual drawing operations are performed in sequence. The
2810 * clipping and background-initializing features of
2811 * gdk_window_begin_paint_region() are conveniences for the
2812 * programmer, so you can avoid doing that work yourself.
2814 * When using GTK+, the widget system automatically places calls to
2815 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2816 * emissions of the expose_event signal. That is, if you're writing an
2817 * expose event handler, you can assume that the exposed area in
2818 * #GdkEventExpose has already been cleared to the window background,
2819 * is already set as the clip region, and already has a backing store.
2820 * Therefore in most cases, application code need not call
2821 * gdk_window_begin_paint_region(). (You can disable the automatic
2822 * calls around expose events on a widget-by-widget basis by calling
2823 * gtk_widget_set_double_buffered().)
2825 * If you call this function multiple times before calling the
2826 * matching gdk_window_end_paint(), the backing stores are pushed onto
2827 * a stack. gdk_window_end_paint() copies the topmost backing store
2828 * onscreen, subtracts the topmost region from all other regions in
2829 * the stack, and pops the stack. All drawing operations affect only
2830 * the topmost backing store in the stack. One matching call to
2831 * gdk_window_end_paint() is required for each call to
2832 * gdk_window_begin_paint_region().
2836 gdk_window_begin_paint_region (GdkWindow *window,
2837 const cairo_region_t *region)
2839 #ifdef USE_BACKING_STORE
2840 GdkRectangle clip_box;
2841 GdkWindowPaint *paint, *implicit_paint;
2842 GdkWindow *impl_window;
2845 g_return_if_fail (GDK_IS_WINDOW (window));
2847 if (GDK_WINDOW_DESTROYED (window))
2850 if (GDK_IS_PAINTABLE (window->impl))
2852 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2854 if (iface->begin_paint_region)
2855 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2860 impl_window = gdk_window_get_impl_window (window);
2861 implicit_paint = impl_window->implicit_paint;
2863 paint = g_new (GdkWindowPaint, 1);
2864 paint->region = cairo_region_copy (region);
2865 paint->region_tag = new_region_tag ();
2867 cairo_region_intersect (paint->region, window->clip_region_with_children);
2868 cairo_region_get_extents (paint->region, &clip_box);
2870 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2872 /* Mark the region as valid on the implicit paint */
2875 cairo_region_union (implicit_paint->region, paint->region);
2877 /* Convert back to normal coords */
2878 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2882 paint->uses_implicit = TRUE;
2883 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2884 window->abs_x + clip_box.x,
2885 window->abs_y + clip_box.y,
2886 MAX (clip_box.width, 1),
2887 MAX (clip_box.height, 1));
2891 paint->uses_implicit = FALSE;
2892 paint->surface = gdk_window_create_similar_surface (window,
2893 gdk_window_get_content (window),
2894 MAX (clip_box.width, 1),
2895 MAX (clip_box.height, 1));
2897 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
2899 for (list = window->paint_stack; list != NULL; list = list->next)
2901 GdkWindowPaint *tmp_paint = list->data;
2903 cairo_region_subtract (tmp_paint->region, paint->region);
2906 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
2908 if (!cairo_region_is_empty (paint->region))
2910 gdk_window_clear_backing_region (window,
2914 #endif /* USE_BACKING_STORE */
2918 * gdk_window_end_paint:
2919 * @window: a #GdkWindow
2921 * Indicates that the backing store created by the most recent call to
2922 * gdk_window_begin_paint_region() should be copied onscreen and
2923 * deleted, leaving the next-most-recent backing store or no backing
2924 * store at all as the active paint region. See
2925 * gdk_window_begin_paint_region() for full details. It is an error to
2926 * call this function without a matching
2927 * gdk_window_begin_paint_region() first.
2931 gdk_window_end_paint (GdkWindow *window)
2933 #ifdef USE_BACKING_STORE
2934 GdkWindow *composited;
2935 GdkWindowPaint *paint;
2936 GdkRectangle clip_box;
2937 cairo_region_t *full_clip;
2939 g_return_if_fail (GDK_IS_WINDOW (window));
2941 if (GDK_WINDOW_DESTROYED (window))
2944 if (GDK_IS_PAINTABLE (window->impl))
2946 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2948 if (iface->end_paint)
2949 iface->end_paint ((GdkPaintable*)window->impl);
2953 if (window->paint_stack == NULL)
2955 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
2959 paint = window->paint_stack->data;
2961 window->paint_stack = g_slist_delete_link (window->paint_stack,
2962 window->paint_stack);
2964 cairo_region_get_extents (paint->region, &clip_box);
2966 if (!paint->uses_implicit)
2970 gdk_window_flush_outstanding_moves (window);
2972 full_clip = cairo_region_copy (window->clip_region_with_children);
2973 cairo_region_intersect (full_clip, paint->region);
2975 cr = gdk_cairo_create (window);
2976 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2977 cairo_set_source_surface (cr, paint->surface, 0, 0);
2978 gdk_cairo_region (cr, full_clip);
2982 cairo_region_destroy (full_clip);
2985 cairo_surface_destroy (paint->surface);
2986 cairo_region_destroy (paint->region);
2989 /* find a composited window in our hierarchy to signal its
2990 * parent to redraw, calculating the clip box as we go...
2992 * stop if parent becomes NULL since then we'd have nowhere
2993 * to draw (ie: 'composited' will always be non-NULL here).
2995 for (composited = window;
2997 composited = composited->parent)
2999 clip_box.x += composited->x;
3000 clip_box.y += composited->y;
3001 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3002 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3004 if (composited->composited)
3006 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3011 #endif /* USE_BACKING_STORE */
3015 gdk_window_free_paint_stack (GdkWindow *window)
3017 if (window->paint_stack)
3019 GSList *tmp_list = window->paint_stack;
3023 GdkWindowPaint *paint = tmp_list->data;
3025 if (tmp_list == window->paint_stack)
3026 cairo_surface_destroy (paint->surface);
3028 cairo_region_destroy (paint->region);
3031 tmp_list = tmp_list->next;
3034 g_slist_free (window->paint_stack);
3035 window->paint_stack = NULL;
3040 do_move_region_bits_on_impl (GdkWindow *impl_window,
3041 cairo_region_t *dest_region, /* In impl window coords */
3044 GdkWindowImplClass *impl_class;
3046 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3048 impl_class->translate (impl_window, dest_region, dx, dy);
3051 static GdkWindowRegionMove *
3052 gdk_window_region_move_new (cairo_region_t *region,
3055 GdkWindowRegionMove *move;
3057 move = g_slice_new (GdkWindowRegionMove);
3058 move->dest_region = cairo_region_copy (region);
3066 gdk_window_region_move_free (GdkWindowRegionMove *move)
3068 cairo_region_destroy (move->dest_region);
3069 g_slice_free (GdkWindowRegionMove, move);
3073 append_move_region (GdkWindow *impl_window,
3074 cairo_region_t *new_dest_region,
3077 GdkWindowRegionMove *move, *old_move;
3078 cairo_region_t *new_total_region, *old_total_region;
3079 cairo_region_t *source_overlaps_destination;
3080 cairo_region_t *non_overwritten;
3081 gboolean added_move;
3084 if (cairo_region_is_empty (new_dest_region))
3087 /* In principle this could just append the move to the list of outstanding
3088 moves that will be replayed before drawing anything when we're handling
3089 exposes. However, we'd like to do a bit better since its commonly the case
3090 that we get multiple copies where A is copied to B and then B is copied
3091 to C, and we'd like to express this as a simple copy A to C operation. */
3093 /* We approach this by taking the new move and pushing it ahead of moves
3094 starting at the end of the list and stopping when its not safe to do so.
3095 It's not safe to push past a move if either the source of the new move
3096 is in the destination of the old move, or if the destination of the new
3097 move is in the source of the new move, or if the destination of the new
3098 move overlaps the destination of the old move. We simplify this by
3099 just comparing the total regions (src + dest) */
3100 new_total_region = cairo_region_copy (new_dest_region);
3101 cairo_region_translate (new_total_region, -dx, -dy);
3102 cairo_region_union (new_total_region, new_dest_region);
3105 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3110 old_total_region = cairo_region_copy (old_move->dest_region);
3111 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3112 cairo_region_union (old_total_region, old_move->dest_region);
3114 cairo_region_intersect (old_total_region, new_total_region);
3115 /* If these regions intersect then its not safe to push the
3116 new region before the old one */
3117 if (!cairo_region_is_empty (old_total_region))
3119 /* The area where the new moves source overlaps the old ones
3121 source_overlaps_destination = cairo_region_copy (new_dest_region);
3122 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3123 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3124 cairo_region_translate (source_overlaps_destination, dx, dy);
3126 /* We can do all sort of optimizations here, but to do things safely it becomes
3127 quite complicated. However, a very common case is that you copy something first,
3128 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3129 in the same direction). We'd like to detect this case and optimize it to one
3131 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3133 /* This means we might be able to replace the old move and the new one
3134 with the new one read from the old ones source, and a second copy of
3135 the non-overwritten parts of the old move. However, such a split
3136 is only valid if the source in the old move isn't overwritten
3137 by the destination of the new one */
3139 /* the new destination of old move if split is ok: */
3140 non_overwritten = cairo_region_copy (old_move->dest_region);
3141 cairo_region_subtract (non_overwritten, new_dest_region);
3142 /* move to source region */
3143 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3145 cairo_region_intersect (non_overwritten, new_dest_region);
3146 if (cairo_region_is_empty (non_overwritten))
3149 move = gdk_window_region_move_new (new_dest_region,
3153 impl_window->outstanding_moves =
3154 g_list_insert_before (impl_window->outstanding_moves,
3156 cairo_region_subtract (old_move->dest_region, new_dest_region);
3158 cairo_region_destroy (non_overwritten);
3161 cairo_region_destroy (source_overlaps_destination);
3162 cairo_region_destroy (old_total_region);
3165 cairo_region_destroy (old_total_region);
3168 cairo_region_destroy (new_total_region);
3172 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3175 impl_window->outstanding_moves =
3176 g_list_prepend (impl_window->outstanding_moves,
3179 impl_window->outstanding_moves =
3180 g_list_insert_before (impl_window->outstanding_moves,
3185 /* Moves bits and update area by dx/dy in impl window.
3186 Takes ownership of region to avoid copy (because we may change it) */
3188 move_region_on_impl (GdkWindow *impl_window,
3189 cairo_region_t *region, /* In impl window coords */
3192 if ((dx == 0 && dy == 0) ||
3193 cairo_region_is_empty (region))
3195 cairo_region_destroy (region);
3199 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3201 /* Move any old invalid regions in the copy source area by dx/dy */
3202 if (impl_window->update_area)
3204 cairo_region_t *update_area;
3206 update_area = cairo_region_copy (region);
3208 /* Convert from target to source */
3209 cairo_region_translate (update_area, -dx, -dy);
3210 cairo_region_intersect (update_area, impl_window->update_area);
3211 /* We only copy the area, so keep the old update area invalid.
3212 It would be safe to remove it too, as code that uses
3213 move_region_on_impl generally also invalidate the source
3214 area. However, it would just use waste cycles. */
3217 cairo_region_translate (update_area, dx, dy);
3218 cairo_region_union (impl_window->update_area, update_area);
3220 /* This area of the destination is now invalid,
3221 so no need to copy to it. */
3222 cairo_region_subtract (region, update_area);
3224 cairo_region_destroy (update_area);
3227 /* If we're currently exposing this window, don't copy to this
3228 destination, as it will be overdrawn when the expose is done,
3229 instead invalidate it and repaint later. */
3230 if (impl_window->implicit_paint)
3232 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3233 cairo_region_t *exposing;
3235 exposing = cairo_region_copy (implicit_paint->region);
3236 cairo_region_intersect (exposing, region);
3237 cairo_region_subtract (region, exposing);
3239 impl_window_add_update_area (impl_window, exposing);
3240 cairo_region_destroy (exposing);
3243 append_move_region (impl_window, region, dx, dy);
3245 cairo_region_destroy (region);
3248 /* Flushes all outstanding changes to the window, call this
3249 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3252 gdk_window_flush_outstanding_moves (GdkWindow *window)
3254 GdkWindow *impl_window;
3255 GList *l, *outstanding;
3256 GdkWindowRegionMove *move;
3258 impl_window = gdk_window_get_impl_window (window);
3259 outstanding = impl_window->outstanding_moves;
3260 impl_window->outstanding_moves = NULL;
3262 for (l = outstanding; l != NULL; l = l->next)
3266 do_move_region_bits_on_impl (impl_window,
3267 move->dest_region, move->dx, move->dy);
3269 gdk_window_region_move_free (move);
3272 g_list_free (outstanding);
3277 * @window: a #GdkWindow
3279 * Flush all outstanding cached operations on a window, leaving the
3280 * window in a state which reflects all that has been drawn before.
3282 * Gdk uses multiple kinds of caching to get better performance and
3283 * nicer drawing. For instance, during exposes all paints to a window
3284 * using double buffered rendering are keep on a surface until the last
3285 * window has been exposed. It also delays window moves/scrolls until
3286 * as long as possible until next update to avoid tearing when moving
3289 * Normally this should be completely invisible to applications, as
3290 * we automatically flush the windows when required, but this might
3291 * be needed if you for instance mix direct native drawing with
3292 * gdk drawing. For Gtk widgets that don't use double buffering this
3293 * will be called automatically before sending the expose event.
3298 gdk_window_flush (GdkWindow *window)
3300 gdk_window_flush_outstanding_moves (window);
3301 gdk_window_flush_implicit_paint (window);
3304 /* If we're about to move/resize or otherwise change the
3305 * hierarchy of a client side window in an impl and we're
3306 * called from an expose event handler then we need to
3307 * flush any already painted parts of the implicit paint
3308 * that are not part of the current paint, as these may
3309 * be used when scrolling or may overdraw the changes
3310 * caused by the hierarchy change.
3313 gdk_window_flush_if_exposing (GdkWindow *window)
3315 GdkWindow *impl_window;
3317 impl_window = gdk_window_get_impl_window (window);
3319 /* If we're in an implicit paint (i.e. in an expose handler, flush
3320 all the already finished exposes to get things to an uptodate state. */
3321 if (impl_window->implicit_paint)
3322 gdk_window_flush (window);
3327 gdk_window_flush_recursive_helper (GdkWindow *window,
3328 GdkWindowImpl *impl)
3333 for (l = window->children; l != NULL; l = l->next)
3337 if (child->impl == impl)
3338 /* Same impl, ignore */
3339 gdk_window_flush_recursive_helper (child, impl);
3341 gdk_window_flush_recursive (child);
3346 gdk_window_flush_recursive (GdkWindow *window)
3348 gdk_window_flush (window);
3349 gdk_window_flush_recursive_helper (window, window->impl);
3353 * gdk_window_get_clip_region:
3354 * @window: a #GdkWindow
3356 * Computes the region of a window that potentially can be written
3357 * to by drawing primitives. This region may not take into account
3358 * other factors such as if the window is obscured by other windows,
3359 * but no area outside of this region will be affected by drawing
3362 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3363 * when you are done.
3366 gdk_window_get_clip_region (GdkWindow *window)
3368 cairo_region_t *result;
3370 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3372 result = cairo_region_copy (window->clip_region);
3374 if (window->paint_stack)
3376 cairo_region_t *paint_region = cairo_region_create ();
3377 GSList *tmp_list = window->paint_stack;
3381 GdkWindowPaint *paint = tmp_list->data;
3383 cairo_region_union (paint_region, paint->region);
3385 tmp_list = tmp_list->next;
3388 cairo_region_intersect (result, paint_region);
3389 cairo_region_destroy (paint_region);
3396 * gdk_window_get_visible_region:
3397 * @window: a #GdkWindow
3399 * Computes the region of the @window that is potentially visible.
3400 * This does not necessarily take into account if the window is
3401 * obscured by other windows, but no area outside of this region
3404 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3405 * when you are done.
3408 gdk_window_get_visible_region (GdkWindow *window)
3410 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3412 return cairo_region_copy (window->clip_region);
3416 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint, int x_offset_cairo, int y_offset_cairo)
3418 GdkWindow *bg_window;
3419 cairo_pattern_t *pattern = NULL;
3420 int x_offset = 0, y_offset = 0;
3423 cr = cairo_create (paint->surface);
3425 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3427 pattern = gdk_window_get_background_pattern (bg_window);
3431 x_offset += bg_window->x;
3432 y_offset += bg_window->y;
3437 cairo_translate (cr, -x_offset, -y_offset);
3438 cairo_set_source (cr, pattern);
3439 cairo_translate (cr, x_offset, y_offset);
3442 cairo_set_source_rgb (cr, 0, 0, 0);
3448 gdk_window_clear_backing_region (GdkWindow *window,
3449 cairo_region_t *region)
3451 GdkWindowPaint *paint = window->paint_stack->data;
3452 cairo_region_t *clip;
3453 GdkRectangle clipbox;
3456 if (GDK_WINDOW_DESTROYED (window))
3459 cr = setup_backing_rect (window, paint, 0, 0);
3461 clip = cairo_region_copy (paint->region);
3462 cairo_region_intersect (clip, region);
3463 cairo_region_get_extents (clip, &clipbox);
3465 gdk_cairo_region (cr, clip);
3470 cairo_region_destroy (clip);
3474 gdk_window_clear_backing_region_direct (GdkWindow *window,
3475 cairo_region_t *region)
3477 GdkWindowPaint paint;
3478 cairo_region_t *clip;
3479 GdkRectangle clipbox;
3482 if (GDK_WINDOW_DESTROYED (window))
3485 paint.surface = _gdk_window_ref_cairo_surface (window);
3487 cr = setup_backing_rect (window, &paint, 0, 0);
3489 clip = cairo_region_copy (window->clip_region_with_children);
3490 cairo_region_intersect (clip, region);
3491 cairo_region_get_extents (clip, &clipbox);
3493 gdk_cairo_region (cr, clip);
3498 cairo_region_destroy (clip);
3499 cairo_surface_destroy (paint.surface);
3504 gdk_window_clear_region_internal (GdkWindow *window,
3505 cairo_region_t *region)
3507 if (window->paint_stack)
3508 gdk_window_clear_backing_region (window, region);
3510 gdk_window_clear_backing_region_direct (window, region);
3514 gdk_window_drop_cairo_surface (GdkWindow *window)
3516 if (window->cairo_surface)
3518 cairo_surface_finish (window->cairo_surface);
3519 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3521 window->cairo_surface = NULL;
3526 gdk_window_cairo_surface_destroy (void *data)
3528 GdkWindow *window = data;
3530 window->cairo_surface = NULL;
3533 static cairo_surface_t *
3534 gdk_window_create_cairo_surface (GdkWindow *window,
3538 cairo_surface_t *surface, *subsurface;
3540 surface = gdk_window_ref_impl_surface (window);
3541 if (gdk_window_has_impl (window))
3544 subsurface = cairo_surface_create_for_rectangle (surface,
3549 cairo_surface_destroy (surface);
3555 _gdk_window_ref_cairo_surface (GdkWindow *window)
3557 cairo_surface_t *surface;
3559 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3561 if (window->paint_stack)
3563 GdkWindowPaint *paint = window->paint_stack->data;
3565 surface = paint->surface;
3566 cairo_surface_reference (surface);
3571 /* This will be drawing directly to the window, so flush implicit paint */
3572 gdk_window_flush (window);
3574 if (!window->cairo_surface)
3576 window->cairo_surface = gdk_window_create_cairo_surface (window,
3580 if (window->cairo_surface)
3582 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3583 window, gdk_window_cairo_surface_destroy);
3587 cairo_surface_reference (window->cairo_surface);
3589 surface = window->cairo_surface;
3597 * @window: a #GdkWindow
3599 * Creates a Cairo context for drawing to @window.
3602 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3603 * produce undefined results, so avoid it at all costs.
3606 * Return value: A newly created Cairo context. Free with
3607 * cairo_destroy() when you are done drawing.
3612 gdk_cairo_create (GdkWindow *window)
3614 cairo_surface_t *surface;
3617 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3619 surface = _gdk_window_ref_cairo_surface (window);
3620 cr = cairo_create (surface);
3622 if (!window->paint_stack)
3624 gdk_cairo_region (cr, window->clip_region_with_children);
3629 GdkWindowPaint *paint = window->paint_stack->data;
3631 /* Only needs to clip to region if piggybacking
3632 on an implicit paint */
3633 if (paint->uses_implicit)
3635 gdk_cairo_region (cr, paint->region);
3640 cairo_surface_destroy (surface);
3645 /* Code for dirty-region queueing
3647 static GSList *update_windows = NULL;
3648 static guint update_idle = 0;
3649 static gboolean debug_updates = FALSE;
3651 static inline gboolean
3652 gdk_window_is_ancestor (GdkWindow *window,
3653 GdkWindow *ancestor)
3657 GdkWindow *parent = window->parent;
3659 if (parent == ancestor)
3669 gdk_window_add_update_window (GdkWindow *window)
3672 GSList *prev = NULL;
3673 gboolean has_ancestor_in_list = FALSE;
3675 for (tmp = update_windows; tmp; tmp = tmp->next)
3677 GdkWindow *parent = window->parent;
3679 /* check if tmp is an ancestor of "window"; if it is, set a
3680 * flag indicating that all following windows are either
3681 * children of "window" or from a differen hierarchy
3683 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3684 has_ancestor_in_list = TRUE;
3686 /* insert in reverse stacking order when adding around siblings,
3687 * so processing updates properly paints over lower stacked windows
3689 if (parent == GDK_WINDOW (tmp->data)->parent)
3691 gint index = g_list_index (parent->children, window);
3692 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3694 gint sibling_index = g_list_index (parent->children, tmp->data);
3695 if (index > sibling_index)
3699 /* here, tmp got advanced past all lower stacked siblings */
3700 tmp = g_slist_prepend (tmp, window);
3704 update_windows = tmp;
3708 /* if "window" has an ancestor in the list and tmp is one of
3709 * "window's" children, insert "window" before tmp
3711 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3713 tmp = g_slist_prepend (tmp, window);
3718 update_windows = tmp;
3722 /* if we're at the end of the list and had an ancestor it it,
3723 * append to the list
3725 if (! tmp->next && has_ancestor_in_list)
3727 tmp = g_slist_append (tmp, window);
3734 /* if all above checks failed ("window" is from a different
3735 * hierarchy than what is already in the list) or the list is
3738 update_windows = g_slist_prepend (update_windows, window);
3742 gdk_window_remove_update_window (GdkWindow *window)
3744 update_windows = g_slist_remove (update_windows, window);
3748 gdk_window_update_idle (gpointer data)
3750 gdk_window_process_all_updates ();
3756 gdk_window_is_toplevel_frozen (GdkWindow *window)
3758 GdkWindow *toplevel;
3760 toplevel = gdk_window_get_toplevel (window);
3762 return toplevel->update_and_descendants_freeze_count > 0;
3766 gdk_window_schedule_update (GdkWindow *window)
3769 (window->update_freeze_count ||
3770 gdk_window_is_toplevel_frozen (window)))
3775 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3776 gdk_window_update_idle,
3781 _gdk_window_process_updates_recurse (GdkWindow *window,
3782 cairo_region_t *expose_region)
3785 cairo_region_t *child_region;
3787 GList *l, *children;
3789 if (cairo_region_is_empty (expose_region))
3792 if (gdk_window_is_offscreen (window->impl_window) &&
3793 window == window->impl_window)
3794 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3796 /* Make this reentrancy safe for expose handlers freeing windows */
3797 children = g_list_copy (window->children);
3798 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3800 /* Iterate over children, starting at topmost */
3801 for (l = children; l != NULL; l = l->next)
3805 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3808 /* Ignore offscreen children, as they don't draw in their parent and
3809 * don't take part in the clipping */
3810 if (gdk_window_is_offscreen (child))
3815 r.width = child->width;
3816 r.height = child->height;
3818 child_region = cairo_region_create_rectangle (&r);
3821 /* Adjust shape region to parent window coords */
3822 cairo_region_translate (child->shape, child->x, child->y);
3823 cairo_region_intersect (child_region, child->shape);
3824 cairo_region_translate (child->shape, -child->x, -child->y);
3827 if (child->impl == window->impl)
3829 /* Client side child, expose */
3830 cairo_region_intersect (child_region, expose_region);
3831 cairo_region_subtract (expose_region, child_region);
3832 cairo_region_translate (child_region, -child->x, -child->y);
3833 _gdk_window_process_updates_recurse ((GdkWindow *)child, child_region);
3837 /* Native child, just remove area from expose region */
3838 cairo_region_subtract (expose_region, child_region);
3840 cairo_region_destroy (child_region);
3843 g_list_foreach (children, (GFunc)g_object_unref, NULL);
3844 g_list_free (children);
3846 if (!cairo_region_is_empty (expose_region) &&
3849 if (window->event_mask & GDK_EXPOSURE_MASK)
3853 event.expose.type = GDK_EXPOSE;
3854 event.expose.window = g_object_ref (window);
3855 event.expose.send_event = FALSE;
3856 event.expose.count = 0;
3857 event.expose.region = expose_region;
3858 cairo_region_get_extents (expose_region, &event.expose.area);
3860 _gdk_event_emit (&event);
3862 g_object_unref (window);
3864 else if (window->window_type != GDK_WINDOW_FOREIGN)
3866 /* No exposure mask set, so nothing will be drawn, the
3867 * app relies on the background being what it specified
3868 * for the window. So, we need to clear this manually.
3870 * For foreign windows if expose is not set that generally
3871 * means some other client paints them, so don't clear
3874 * We use begin/end_paint around the clear so that we can
3875 * piggyback on the implicit paint */
3877 gdk_window_begin_paint_region (window, expose_region);
3878 gdk_window_clear_region_internal (window, expose_region);
3879 gdk_window_end_paint (window);
3884 /* Process and remove any invalid area on the native window by creating
3885 * expose events for the window and all non-native descendants.
3886 * Also processes any outstanding moves on the window before doing
3887 * any drawing. Note that its possible to have outstanding moves without
3888 * any invalid area as we use the update idle mechanism to coalesce
3889 * multiple moves as well as multiple invalidations.
3892 gdk_window_process_updates_internal (GdkWindow *window)
3894 GdkWindowImplClass *impl_class;
3895 gboolean save_region = FALSE;
3896 GdkRectangle clip_box;
3898 /* Ensure the window lives while updating it */
3899 g_object_ref (window);
3901 /* If an update got queued during update processing, we can get a
3902 * window in the update queue that has an empty update_area.
3905 if (window->update_area)
3907 cairo_region_t *update_area = window->update_area;
3908 window->update_area = NULL;
3910 if (gdk_window_is_viewable (window))
3912 cairo_region_t *expose_region;
3913 gboolean end_implicit;
3915 /* Clip to part visible in toplevel */
3916 cairo_region_intersect (update_area, window->clip_region);
3920 /* Make sure we see the red invalid area before redrawing. */
3921 gdk_display_sync (gdk_window_get_display (window));
3925 /* At this point we will be completely redrawing all of update_area.
3926 * If we have any outstanding moves that end up moving stuff inside
3927 * this area we don't actually need to move that as that part would
3928 * be overdrawn by the expose anyway. So, in order to copy less data
3929 * we remove these areas from the outstanding moves.
3931 if (window->outstanding_moves)
3933 GdkWindowRegionMove *move;
3934 cairo_region_t *remove;
3937 remove = cairo_region_copy (update_area);
3938 /* We iterate backwards, starting from the state that would be
3939 if we had applied all the moves. */
3940 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
3945 /* Don't need this area */
3946 cairo_region_subtract (move->dest_region, remove);
3948 /* However if any of the destination we do need has a source
3949 in the updated region we do need that as a destination for
3950 the earlier moves */
3951 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
3952 cairo_region_subtract (remove, move->dest_region);
3954 if (cairo_region_is_empty (move->dest_region))
3956 gdk_window_region_move_free (move);
3957 window->outstanding_moves =
3958 g_list_delete_link (window->outstanding_moves, l);
3960 else /* move back */
3961 cairo_region_translate (move->dest_region, move->dx, move->dy);
3963 cairo_region_destroy (remove);
3966 /* By now we a set of window moves that should be applied, and then
3967 * an update region that should be repainted. A trivial implementation
3968 * would just do that in order, however in order to get nicer drawing
3969 * we do some tricks:
3971 * First of all, each subwindow expose may be double buffered by
3972 * itself (depending on widget setting) via
3973 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
3974 * creating a single surface the size of the invalid area on the
3975 * native window which all the individual normal paints will draw
3976 * into. This way in the normal case there will be only one surface
3977 * allocated and only once surface draw done for all the windows
3978 * in this native window.
3979 * There are a couple of reasons this may fail, for instance, some
3980 * backends (like quartz) do its own double buffering, so we disable
3981 * gdk double buffering there. Secondly, some subwindow could be
3982 * non-double buffered and draw directly to the window outside a
3983 * begin/end_paint pair. That will be lead to a gdk_window_flush
3984 * which immediately executes all outstanding moves and paints+removes
3985 * the implicit paint (further paints will allocate their own surfaces).
3987 * Secondly, in the case of implicit double buffering we expose all
3988 * the child windows into the implicit surface before we execute
3989 * the outstanding moves. This way we minimize the time between
3990 * doing the moves and rendering the new update area, thus minimizing
3991 * flashing. Of course, if any subwindow is non-double buffered we
3992 * well flush earlier than that.
3994 * Thirdly, after having done the outstanding moves we queue an
3995 * "antiexpose" on the area that will be drawn by the expose, which
3996 * means that any invalid region on the native window side before
3997 * the first expose drawing operation will be discarded, as it
3998 * has by then been overdrawn with valid data. This means we can
3999 * avoid doing the unnecessary repaint any outstanding expose events.
4002 cairo_region_get_extents (update_area, &clip_box);
4003 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4004 expose_region = cairo_region_copy (update_area);
4005 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4008 /* Rendering is not double buffered by gdk, do outstanding
4009 * moves and queue antiexposure immediately. No need to do
4011 gdk_window_flush_outstanding_moves (window);
4012 save_region = impl_class->queue_antiexpose (window, update_area);
4014 /* Render the invalid areas to the implicit paint, by sending exposes.
4015 * May flush if non-double buffered widget draw. */
4016 impl_class->process_updates_recurse (window, expose_region);
4020 /* Do moves right before exposes are rendered to the window */
4021 gdk_window_flush_outstanding_moves (window);
4023 /* By this time we know that any outstanding expose for this
4024 * area is invalid and we can avoid it, so queue an antiexpose.
4025 * we have already started drawing to the window, so it would
4026 * be to late to anti-expose now. Since this is merely an
4027 * optimization we just avoid doing it at all in that case.
4029 if (window->implicit_paint != NULL && !window->implicit_paint->flushed)
4030 save_region = impl_class->queue_antiexpose (window, update_area);
4032 gdk_window_end_implicit_paint (window);
4034 cairo_region_destroy (expose_region);
4037 cairo_region_destroy (update_area);
4040 if (window->outstanding_moves)
4042 /* Flush any outstanding moves, may happen if we moved a window but got
4043 no actual invalid area */
4044 gdk_window_flush_outstanding_moves (window);
4047 g_object_unref (window);
4051 flush_all_displays (void)
4053 GSList *displays, *l;
4055 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4056 for (l = displays; l; l = l->next)
4057 gdk_display_flush (l->data);
4059 g_slist_free (displays);
4063 before_process_all_updates (void)
4065 GSList *displays, *l;
4066 GdkDisplayClass *display_class;
4068 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4069 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4070 for (l = displays; l; l = l->next)
4071 display_class->before_process_all_updates (l->data);
4073 g_slist_free (displays);
4077 after_process_all_updates (void)
4079 GSList *displays, *l;
4080 GdkDisplayClass *display_class;
4082 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4083 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4084 for (l = displays; l; l = l->next)
4085 display_class->after_process_all_updates (l->data);
4087 g_slist_free (displays);
4090 /* Currently it is not possible to override
4091 * gdk_window_process_all_updates in the same manner as
4092 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4093 * by implementing the GdkPaintable interface. If in the future a
4094 * backend would need this, the right solution would be to add a
4095 * method to GdkDisplay that can be optionally
4096 * NULL. gdk_window_process_all_updates can then walk the list of open
4097 * displays and call the mehod.
4101 * gdk_window_process_all_updates:
4103 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4104 * in the application.
4108 gdk_window_process_all_updates (void)
4110 GSList *old_update_windows = update_windows;
4111 GSList *tmp_list = update_windows;
4112 static gboolean in_process_all_updates = FALSE;
4113 static gboolean got_recursive_update = FALSE;
4115 if (in_process_all_updates)
4117 /* We can't do this now since that would recurse, so
4118 delay it until after the recursion is done. */
4119 got_recursive_update = TRUE;
4124 in_process_all_updates = TRUE;
4125 got_recursive_update = FALSE;
4128 g_source_remove (update_idle);
4130 update_windows = NULL;
4133 before_process_all_updates ();
4135 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4139 GdkWindow *window = tmp_list->data;
4141 if (!GDK_WINDOW_DESTROYED (window))
4143 if (window->update_freeze_count ||
4144 gdk_window_is_toplevel_frozen (window))
4145 gdk_window_add_update_window (window);
4147 gdk_window_process_updates_internal (window);
4150 g_object_unref (window);
4151 tmp_list = tmp_list->next;
4154 g_slist_free (old_update_windows);
4156 flush_all_displays ();
4158 after_process_all_updates ();
4160 in_process_all_updates = FALSE;
4162 /* If we ignored a recursive call, schedule a
4163 redraw now so that it eventually happens,
4164 otherwise we could miss an update if nothing
4165 else schedules an update. */
4166 if (got_recursive_update && !update_idle)
4168 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4169 gdk_window_update_idle,
4174 * gdk_window_process_updates:
4175 * @window: a #GdkWindow
4176 * @update_children: whether to also process updates for child windows
4178 * Sends one or more expose events to @window. The areas in each
4179 * expose event will cover the entire update area for the window (see
4180 * gdk_window_invalidate_region() for details). Normally GDK calls
4181 * gdk_window_process_all_updates() on your behalf, so there's no
4182 * need to call this function unless you want to force expose events
4183 * to be delivered immediately and synchronously (vs. the usual
4184 * case, where GDK delivers them in an idle handler). Occasionally
4185 * this is useful to produce nicer scrolling behavior, for example.
4189 gdk_window_process_updates (GdkWindow *window,
4190 gboolean update_children)
4192 GdkWindow *impl_window;
4194 g_return_if_fail (GDK_IS_WINDOW (window));
4196 if (GDK_WINDOW_DESTROYED (window))
4199 /* Make sure the window lives during the expose callouts */
4200 g_object_ref (window);
4202 impl_window = gdk_window_get_impl_window (window);
4203 if ((impl_window->update_area ||
4204 impl_window->outstanding_moves) &&
4205 !impl_window->update_freeze_count &&
4206 !gdk_window_is_toplevel_frozen (window) &&
4208 /* Don't recurse into process_updates_internal, we'll
4209 * do the update later when idle instead. */
4210 impl_window->implicit_paint == NULL)
4212 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4213 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4216 if (update_children)
4218 /* process updates in reverse stacking order so composition or
4219 * painting over achieves the desired effect for offscreen windows
4221 GList *node, *children;
4223 children = g_list_copy (window->children);
4224 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4226 for (node = g_list_last (children); node; node = node->prev)
4228 gdk_window_process_updates (node->data, TRUE);
4229 g_object_unref (node->data);
4232 g_list_free (children);
4235 g_object_unref (window);
4239 gdk_window_invalidate_rect_full (GdkWindow *window,
4240 const GdkRectangle *rect,
4241 gboolean invalidate_children,
4244 GdkRectangle window_rect;
4245 cairo_region_t *region;
4247 g_return_if_fail (GDK_IS_WINDOW (window));
4249 if (GDK_WINDOW_DESTROYED (window))
4252 if (window->input_only || !window->viewable)
4259 window_rect.width = window->width;
4260 window_rect.height = window->height;
4261 rect = &window_rect;
4264 region = cairo_region_create_rectangle (rect);
4265 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4266 cairo_region_destroy (region);
4270 * gdk_window_invalidate_rect:
4271 * @window: a #GdkWindow
4272 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4274 * @invalidate_children: whether to also invalidate child windows
4276 * A convenience wrapper around gdk_window_invalidate_region() which
4277 * invalidates a rectangular region. See
4278 * gdk_window_invalidate_region() for details.
4281 gdk_window_invalidate_rect (GdkWindow *window,
4282 const GdkRectangle *rect,
4283 gboolean invalidate_children)
4285 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4289 draw_ugly_color (GdkWindow *window,
4290 const cairo_region_t *region)
4294 cr = gdk_cairo_create (window);
4295 /* Draw ugly color all over the newly-invalid region */
4296 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4297 gdk_cairo_region (cr, region);
4304 impl_window_add_update_area (GdkWindow *impl_window,
4305 cairo_region_t *region)
4307 if (impl_window->update_area)
4308 cairo_region_union (impl_window->update_area, region);
4311 gdk_window_add_update_window (impl_window);
4312 impl_window->update_area = cairo_region_copy (region);
4313 gdk_window_schedule_update (impl_window);
4317 /* clear_bg controls if the region will be cleared to
4318 * the background pattern if the exposure mask is not
4319 * set for the window, whereas this might not otherwise be
4320 * done (unless necessary to emulate background settings).
4321 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4322 * need to clear the background, such as when exposing the area beneath a
4323 * hidden or moved window, but not when an app requests repaint or when the
4324 * windowing system exposes a newly visible area (because then the windowing
4325 * system has already cleared the area).
4328 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4329 const cairo_region_t *region,
4331 GdkWindowChildFunc child_func,
4334 GdkWindow *impl_window;
4335 cairo_region_t *visible_region;
4338 g_return_if_fail (GDK_IS_WINDOW (window));
4340 if (GDK_WINDOW_DESTROYED (window))
4343 if (window->input_only ||
4344 !window->viewable ||
4345 cairo_region_is_empty (region) ||
4346 window->window_type == GDK_WINDOW_ROOT)
4349 visible_region = gdk_window_get_visible_region (window);
4350 cairo_region_intersect (visible_region, region);
4352 tmp_list = window->children;
4355 GdkWindow *child = tmp_list->data;
4357 if (!child->input_only)
4359 cairo_region_t *child_region;
4360 GdkRectangle child_rect;
4362 child_rect.x = child->x;
4363 child_rect.y = child->y;
4364 child_rect.width = child->width;
4365 child_rect.height = child->height;
4366 child_region = cairo_region_create_rectangle (&child_rect);
4368 /* remove child area from the invalid area of the parent */
4369 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4370 !child->composited &&
4371 !gdk_window_is_offscreen (child))
4372 cairo_region_subtract (visible_region, child_region);
4374 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4376 cairo_region_t *tmp = cairo_region_copy (region);
4378 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4379 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4380 cairo_region_intersect (child_region, tmp);
4382 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4383 child_region, clear_bg, child_func, user_data);
4385 cairo_region_destroy (tmp);
4388 cairo_region_destroy (child_region);
4391 tmp_list = tmp_list->next;
4394 impl_window = gdk_window_get_impl_window (window);
4396 if (!cairo_region_is_empty (visible_region) ||
4397 /* Even if we're not exposing anything, make sure we process
4398 idles for windows with outstanding moves */
4399 (impl_window->outstanding_moves != NULL &&
4400 impl_window->update_area == NULL))
4403 draw_ugly_color (window, region);
4405 /* Convert to impl coords */
4406 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4408 /* Only invalidate area if app requested expose events or if
4409 we need to clear the area (by request or to emulate background
4410 clearing for non-native windows or native windows with no support
4411 for window backgrounds */
4412 if (window->event_mask & GDK_EXPOSURE_MASK ||
4413 clear_bg == CLEAR_BG_ALL ||
4414 clear_bg == CLEAR_BG_WINCLEARED)
4415 impl_window_add_update_area (impl_window, visible_region);
4418 cairo_region_destroy (visible_region);
4422 * gdk_window_invalidate_maybe_recurse:
4423 * @window: a #GdkWindow
4424 * @region: a #cairo_region_t
4425 * @child_func: (scope call) (allow-none): function to use to decide if to
4426 * recurse to a child, %NULL means never recurse.
4427 * @user_data: data passed to @child_func
4429 * Adds @region to the update area for @window. The update area is the
4430 * region that needs to be redrawn, or "dirty region." The call
4431 * gdk_window_process_updates() sends one or more expose events to the
4432 * window, which together cover the entire update area. An
4433 * application would normally redraw the contents of @window in
4434 * response to those expose events.
4436 * GDK will call gdk_window_process_all_updates() on your behalf
4437 * whenever your program returns to the main loop and becomes idle, so
4438 * normally there's no need to do that manually, you just need to
4439 * invalidate regions that you know should be redrawn.
4441 * The @child_func parameter controls whether the region of
4442 * each child window that intersects @region will also be invalidated.
4443 * Only children for which @child_func returns TRUE will have the area
4447 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4448 const cairo_region_t *region,
4449 GdkWindowChildFunc child_func,
4452 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4453 child_func, user_data);
4457 true_predicate (GdkWindow *window,
4464 gdk_window_invalidate_region_full (GdkWindow *window,
4465 const cairo_region_t *region,
4466 gboolean invalidate_children,
4469 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4470 invalidate_children ?
4471 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4476 * gdk_window_invalidate_region:
4477 * @window: a #GdkWindow
4478 * @region: a #cairo_region_t
4479 * @invalidate_children: %TRUE to also invalidate child windows
4481 * Adds @region to the update area for @window. The update area is the
4482 * region that needs to be redrawn, or "dirty region." The call
4483 * gdk_window_process_updates() sends one or more expose events to the
4484 * window, which together cover the entire update area. An
4485 * application would normally redraw the contents of @window in
4486 * response to those expose events.
4488 * GDK will call gdk_window_process_all_updates() on your behalf
4489 * whenever your program returns to the main loop and becomes idle, so
4490 * normally there's no need to do that manually, you just need to
4491 * invalidate regions that you know should be redrawn.
4493 * The @invalidate_children parameter controls whether the region of
4494 * each child window that intersects @region will also be invalidated.
4495 * If %FALSE, then the update area for child windows will remain
4496 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4497 * fine grained control over which children are invalidated.
4500 gdk_window_invalidate_region (GdkWindow *window,
4501 const cairo_region_t *region,
4502 gboolean invalidate_children)
4504 gdk_window_invalidate_maybe_recurse (window, region,
4505 invalidate_children ?
4506 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4511 * _gdk_window_invalidate_for_expose:
4512 * @window: a #GdkWindow
4513 * @region: a #cairo_region_t
4515 * Adds @region to the update area for @window. The update area is the
4516 * region that needs to be redrawn, or "dirty region." The call
4517 * gdk_window_process_updates() sends one or more expose events to the
4518 * window, which together cover the entire update area. An
4519 * application would normally redraw the contents of @window in
4520 * response to those expose events.
4522 * GDK will call gdk_window_process_all_updates() on your behalf
4523 * whenever your program returns to the main loop and becomes idle, so
4524 * normally there's no need to do that manually, you just need to
4525 * invalidate regions that you know should be redrawn.
4527 * This version of invalidation is used when you recieve expose events
4528 * from the native window system. It exposes the native window, plus
4529 * any non-native child windows (but not native child windows, as those would
4530 * have gotten their own expose events).
4533 _gdk_window_invalidate_for_expose (GdkWindow *window,
4534 cairo_region_t *region)
4536 GdkWindowRegionMove *move;
4537 cairo_region_t *move_region;
4540 /* Any invalidations comming from the windowing system will
4541 be in areas that may be moved by outstanding moves,
4542 so we need to modify the expose region correspondingly,
4543 otherwise we would expose in the wrong place, as the
4544 outstanding moves will be copied before we draw the
4546 for (l = window->outstanding_moves; l != NULL; l = l->next)
4550 /* covert to move source region */
4551 move_region = cairo_region_copy (move->dest_region);
4552 cairo_region_translate (move_region, -move->dx, -move->dy);
4554 /* Move area of region that intersects with move source
4555 by dx, dy of the move*/
4556 cairo_region_intersect (move_region, region);
4557 cairo_region_subtract (region, move_region);
4558 cairo_region_translate (move_region, move->dx, move->dy);
4559 cairo_region_union (region, move_region);
4561 cairo_region_destroy (move_region);
4564 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4565 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4571 * gdk_window_get_update_area:
4572 * @window: a #GdkWindow
4574 * Transfers ownership of the update area from @window to the caller
4575 * of the function. That is, after calling this function, @window will
4576 * no longer have an invalid/dirty region; the update area is removed
4577 * from @window and handed to you. If a window has no update area,
4578 * gdk_window_get_update_area() returns %NULL. You are responsible for
4579 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4581 * Return value: the update area for @window
4584 gdk_window_get_update_area (GdkWindow *window)
4586 GdkWindow *impl_window;
4587 cairo_region_t *tmp_region;
4589 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4591 impl_window = gdk_window_get_impl_window (window);
4593 if (impl_window->update_area)
4595 tmp_region = cairo_region_copy (window->clip_region_with_children);
4596 /* Convert to impl coords */
4597 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4598 cairo_region_intersect (tmp_region, impl_window->update_area);
4600 if (cairo_region_is_empty (tmp_region))
4602 cairo_region_destroy (tmp_region);
4607 cairo_region_subtract (impl_window->update_area, tmp_region);
4609 if (cairo_region_is_empty (impl_window->update_area) &&
4610 impl_window->outstanding_moves == NULL)
4612 cairo_region_destroy (impl_window->update_area);
4613 impl_window->update_area = NULL;
4615 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4618 /* Convert from impl coords */
4619 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4629 * _gdk_window_clear_update_area:
4630 * @window: a #GdkWindow.
4632 * Internal function to clear the update area for a window. This
4633 * is called when the window is hidden or destroyed.
4636 _gdk_window_clear_update_area (GdkWindow *window)
4638 g_return_if_fail (GDK_IS_WINDOW (window));
4640 if (window->update_area)
4642 gdk_window_remove_update_window (window);
4644 cairo_region_destroy (window->update_area);
4645 window->update_area = NULL;
4650 * gdk_window_freeze_updates:
4651 * @window: a #GdkWindow
4653 * Temporarily freezes a window such that it won't receive expose
4654 * events. The window will begin receiving expose events again when
4655 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4656 * has been called more than once, gdk_window_thaw_updates() must be called
4657 * an equal number of times to begin processing exposes.
4660 gdk_window_freeze_updates (GdkWindow *window)
4662 GdkWindow *impl_window;
4664 g_return_if_fail (GDK_IS_WINDOW (window));
4666 impl_window = gdk_window_get_impl_window (window);
4667 impl_window->update_freeze_count++;
4671 * gdk_window_thaw_updates:
4672 * @window: a #GdkWindow
4674 * Thaws a window frozen with gdk_window_freeze_updates().
4677 gdk_window_thaw_updates (GdkWindow *window)
4679 GdkWindow *impl_window;
4681 g_return_if_fail (GDK_IS_WINDOW (window));
4683 impl_window = gdk_window_get_impl_window (window);
4685 g_return_if_fail (impl_window->update_freeze_count > 0);
4687 if (--impl_window->update_freeze_count == 0)
4688 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4692 * gdk_window_freeze_toplevel_updates_libgtk_only:
4693 * @window: a #GdkWindow
4695 * Temporarily freezes a window and all its descendants such that it won't
4696 * receive expose events. The window will begin receiving expose events
4697 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4698 * gdk_window_freeze_toplevel_updates_libgtk_only()
4699 * has been called more than once,
4700 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4701 * an equal number of times to begin processing exposes.
4703 * This function is not part of the GDK public API and is only
4707 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4709 g_return_if_fail (GDK_IS_WINDOW (window));
4710 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4712 window->update_and_descendants_freeze_count++;
4716 * gdk_window_thaw_toplevel_updates_libgtk_only:
4717 * @window: a #GdkWindow
4719 * Thaws a window frozen with
4720 * gdk_window_freeze_toplevel_updates_libgtk_only().
4722 * This function is not part of the GDK public API and is only
4726 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4728 g_return_if_fail (GDK_IS_WINDOW (window));
4729 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4730 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4732 window->update_and_descendants_freeze_count--;
4734 gdk_window_schedule_update (window);
4738 * gdk_window_set_debug_updates:
4739 * @setting: %TRUE to turn on update debugging
4741 * With update debugging enabled, calls to
4742 * gdk_window_invalidate_region() clear the invalidated region of the
4743 * screen to a noticeable color, and GDK pauses for a short time
4744 * before sending exposes to windows during
4745 * gdk_window_process_updates(). The net effect is that you can see
4746 * the invalid region for each window and watch redraws as they
4747 * occur. This allows you to diagnose inefficiencies in your application.
4749 * In essence, because the GDK rendering model prevents all flicker,
4750 * if you are redrawing the same region 400 times you may never
4751 * notice, aside from noticing a speed problem. Enabling update
4752 * debugging causes GTK to flicker slowly and noticeably, so you can
4753 * see exactly what's being redrawn when, in what order.
4755 * The --gtk-debug=updates command line option passed to GTK+ programs
4756 * enables this debug option at application startup time. That's
4757 * usually more useful than calling gdk_window_set_debug_updates()
4758 * yourself, though you might want to use this function to enable
4759 * updates sometime after application startup time.
4763 gdk_window_set_debug_updates (gboolean setting)
4765 debug_updates = setting;
4769 * gdk_window_constrain_size:
4770 * @geometry: a #GdkGeometry structure
4771 * @flags: a mask indicating what portions of @geometry are set
4772 * @width: desired width of window
4773 * @height: desired height of the window
4774 * @new_width: (out): location to store resulting width
4775 * @new_height: (out): location to store resulting height
4777 * Constrains a desired width and height according to a
4778 * set of geometry hints (such as minimum and maximum size).
4781 gdk_window_constrain_size (GdkGeometry *geometry,
4788 /* This routine is partially borrowed from fvwm.
4790 * Copyright 1993, Robert Nation
4791 * You may use this code for any purpose, as long as the original
4792 * copyright remains in the source code and all documentation
4794 * which in turn borrows parts of the algorithm from uwm
4797 gint min_height = 0;
4798 gint base_width = 0;
4799 gint base_height = 0;
4802 gint max_width = G_MAXINT;
4803 gint max_height = G_MAXINT;
4805 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4807 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4809 base_width = geometry->base_width;
4810 base_height = geometry->base_height;
4811 min_width = geometry->min_width;
4812 min_height = geometry->min_height;
4814 else if (flags & GDK_HINT_BASE_SIZE)
4816 base_width = geometry->base_width;
4817 base_height = geometry->base_height;
4818 min_width = geometry->base_width;
4819 min_height = geometry->base_height;
4821 else if (flags & GDK_HINT_MIN_SIZE)
4823 base_width = geometry->min_width;
4824 base_height = geometry->min_height;
4825 min_width = geometry->min_width;
4826 min_height = geometry->min_height;
4829 if (flags & GDK_HINT_MAX_SIZE)
4831 max_width = geometry->max_width ;
4832 max_height = geometry->max_height;
4835 if (flags & GDK_HINT_RESIZE_INC)
4837 xinc = MAX (xinc, geometry->width_inc);
4838 yinc = MAX (yinc, geometry->height_inc);
4841 /* clamp width and height to min and max values
4843 width = CLAMP (width, min_width, max_width);
4844 height = CLAMP (height, min_height, max_height);
4846 /* shrink to base + N * inc
4848 width = base_width + FLOOR (width - base_width, xinc);
4849 height = base_height + FLOOR (height - base_height, yinc);
4851 /* constrain aspect ratio, according to:
4854 * min_aspect <= -------- <= max_aspect
4858 if (flags & GDK_HINT_ASPECT &&
4859 geometry->min_aspect > 0 &&
4860 geometry->max_aspect > 0)
4864 if (geometry->min_aspect * height > width)
4866 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4867 if (height - delta >= min_height)
4871 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4872 if (width + delta <= max_width)
4877 if (geometry->max_aspect * height < width)
4879 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4880 if (width - delta >= min_width)
4884 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4885 if (height + delta <= max_height)
4894 *new_height = height;
4898 * gdk_window_get_pointer:
4899 * @window: a #GdkWindow
4900 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4901 * return the X coordinate
4902 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4903 * return the Y coordinate
4904 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4907 * Obtains the current pointer position and modifier state.
4908 * The position is given in coordinates relative to the upper left
4909 * corner of @window.
4911 * Return value: (transfer none): the window containing the pointer (as with
4912 * gdk_window_at_pointer()), or %NULL if the window containing the
4913 * pointer isn't known to GDK
4915 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4918 gdk_window_get_pointer (GdkWindow *window,
4921 GdkModifierType *mask)
4923 GdkDisplay *display;
4925 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4927 display = gdk_window_get_display (window);
4929 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
4933 * gdk_window_get_device_position:
4934 * @window: a #GdkWindow.
4935 * @device: pointer #GdkDevice to query to.
4936 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
4937 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
4938 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
4940 * Obtains the current device position and modifier state.
4941 * The position is given in coordinates relative to the upper left
4942 * corner of @window.
4944 * Return value: (transfer none): The window underneath @device (as with
4945 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
4950 gdk_window_get_device_position (GdkWindow *window,
4954 GdkModifierType *mask)
4957 GdkModifierType tmp_mask;
4958 gboolean normal_child;
4960 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4961 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
4962 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
4964 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
4968 /* We got the coords on the impl, convert to the window */
4969 tmp_x -= window->abs_x;
4970 tmp_y -= window->abs_y;
4979 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
4982 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
4987 * gdk_window_at_pointer:
4988 * @win_x: (out) (allow-none): return location for origin of the window under the pointer
4989 * @win_y: (out) (allow-none): return location for origin of the window under the pointer
4991 * Obtains the window underneath the mouse pointer, returning the
4992 * location of that window in @win_x, @win_y. Returns %NULL if the
4993 * window under the mouse pointer is not known to GDK (if the window
4994 * belongs to another application and a #GdkWindow hasn't been created
4995 * for it with gdk_window_foreign_new())
4997 * NOTE: For multihead-aware widgets or applications use
4998 * gdk_display_get_window_at_pointer() instead.
5000 * Return value: (transfer none): window under the mouse pointer
5002 * Deprecated: 3.0: Use gdk_device_get_window_at_position() instead.
5005 gdk_window_at_pointer (gint *win_x,
5008 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
5012 * gdk_get_default_root_window:
5014 * Obtains the root window (parent all other windows are inside)
5015 * for the default display and screen.
5017 * Return value: (transfer none): the default root window
5020 gdk_get_default_root_window (void)
5022 return gdk_screen_get_root_window (gdk_screen_get_default ());
5026 get_all_native_children (GdkWindow *window,
5032 for (l = window->children; l != NULL; l = l->next)
5036 if (gdk_window_has_impl (child))
5037 *native = g_list_prepend (*native, child);
5039 get_all_native_children (child, native);
5045 gdk_window_raise_internal (GdkWindow *window)
5047 GdkWindow *parent = window->parent;
5049 GList *native_children;
5051 GdkWindowImplClass *impl_class;
5055 parent->children = g_list_remove (parent->children, window);
5056 parent->children = g_list_prepend (parent->children, window);
5059 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5060 /* Just do native raise for toplevels */
5061 if (gdk_window_is_toplevel (window) ||
5062 /* The restack_under codepath should work correctly even if the parent
5063 is native, but it relies on the order of ->children to be correct,
5064 and some apps like SWT reorder the x windows without gdks knowledge,
5065 so we use raise directly in order to make these behave as before
5066 when using native windows */
5067 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5069 impl_class->raise (window);
5071 else if (gdk_window_has_impl (window))
5073 above = find_native_sibling_above (parent, window);
5076 listhead.data = window;
5077 listhead.next = NULL;
5078 listhead.prev = NULL;
5079 impl_class->restack_under ((GdkWindow *)above,
5083 impl_class->raise (window);
5087 native_children = NULL;
5088 get_all_native_children (window, &native_children);
5089 if (native_children != NULL)
5091 above = find_native_sibling_above (parent, window);
5094 impl_class->restack_under (above, native_children);
5097 /* Right order, since native_children is bottom-topmost first */
5098 for (l = native_children; l != NULL; l = l->next)
5099 impl_class->raise (l->data);
5102 g_list_free (native_children);
5108 /* Returns TRUE If the native window was mapped or unmapped */
5110 set_viewable (GdkWindow *w,
5114 GdkWindowImplClass *impl_class;
5117 if (w->viewable == val)
5123 recompute_visible_regions (w, FALSE, FALSE);
5125 for (l = w->children; l != NULL; l = l->next)
5129 if (GDK_WINDOW_IS_MAPPED (child) &&
5130 child->window_type != GDK_WINDOW_FOREIGN)
5131 set_viewable (child, val);
5134 if (gdk_window_has_impl (w) &&
5135 w->window_type != GDK_WINDOW_FOREIGN &&
5136 !gdk_window_is_toplevel (w))
5138 /* For most native windows we show/hide them not when they are
5139 * mapped/unmapped, because that may not produce the correct results.
5140 * For instance, if a native window have a non-native parent which is
5141 * hidden, but its native parent is viewable then showing the window
5142 * would make it viewable to X but its not viewable wrt the non-native
5143 * hierarchy. In order to handle this we track the gdk side viewability
5144 * and only map really viewable windows.
5146 * There are two exceptions though:
5148 * For foreign windows we don't want ever change the mapped state
5149 * except when explicitly done via gdk_window_show/hide, as this may
5150 * cause problems for client owning the foreign window when its window
5151 * is suddenly mapped or unmapped.
5153 * For toplevel windows embedded in a foreign window (e.g. a plug)
5154 * we sometimes synthesize a map of a window, but the native
5155 * window is really shown by the embedder, so we don't want to
5156 * do the show ourselves. We can't really tell this case from the normal
5157 * toplevel show as such toplevels are seen by gdk as parents of the
5158 * root window, so we make an exception for all toplevels.
5161 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5163 impl_class->show ((GdkWindow *)w, FALSE);
5165 impl_class->hide ((GdkWindow *)w);
5173 /* Returns TRUE If the native window was mapped or unmapped */
5175 _gdk_window_update_viewable (GdkWindow *window)
5179 if (window->window_type == GDK_WINDOW_FOREIGN ||
5180 window->window_type == GDK_WINDOW_ROOT)
5182 else if (gdk_window_is_toplevel (window) ||
5183 window->parent->viewable)
5184 viewable = GDK_WINDOW_IS_MAPPED (window);
5188 return set_viewable (window, viewable);
5192 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5194 GdkWindowImplClass *impl_class;
5195 gboolean was_mapped, was_viewable;
5198 g_return_if_fail (GDK_IS_WINDOW (window));
5200 if (window->destroyed)
5203 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5204 was_viewable = window->viewable;
5207 /* Keep children in (reverse) stacking order */
5208 gdk_window_raise_internal (window);
5210 if (gdk_window_has_impl (window))
5213 gdk_synthesize_window_state (window,
5214 GDK_WINDOW_STATE_WITHDRAWN,
5222 did_show = _gdk_window_update_viewable (window);
5224 /* If it was already viewable the backend show op won't be called, call it
5225 again to ensure things happen right if the mapped tracking was not right
5226 for e.g. a foreign window.
5227 Dunno if this is strictly needed but its what happened pre-csw.
5228 Also show if not done by gdk_window_update_viewable. */
5229 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5231 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5232 impl_class->show (window, !did_show ? was_mapped : TRUE);
5235 if (!was_mapped && !gdk_window_has_impl (window))
5237 if (window->event_mask & GDK_STRUCTURE_MASK)
5238 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5240 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5241 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5244 if (!was_mapped || raise)
5246 recompute_visible_regions (window, TRUE, FALSE);
5248 /* If any decendants became visible we need to send visibility notify */
5249 gdk_window_update_visibility_recursively (window, NULL);
5251 if (gdk_window_is_viewable (window))
5253 _gdk_synthesize_crossing_events_for_geometry_change (window);
5254 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5260 * gdk_window_show_unraised:
5261 * @window: a #GdkWindow
5263 * Shows a #GdkWindow onscreen, but does not modify its stacking
5264 * order. In contrast, gdk_window_show() will raise the window
5265 * to the top of the window stack.
5267 * On the X11 platform, in Xlib terms, this function calls
5268 * XMapWindow() (it also updates some internal GDK state, which means
5269 * that you can't really use XMapWindow() directly on a GDK window).
5272 gdk_window_show_unraised (GdkWindow *window)
5274 gdk_window_show_internal (window, FALSE);
5279 * @window: a #GdkWindow
5281 * Raises @window to the top of the Z-order (stacking order), so that
5282 * other windows with the same parent window appear below @window.
5283 * This is true whether or not the windows are visible.
5285 * If @window is a toplevel, the window manager may choose to deny the
5286 * request to move the window in the Z-order, gdk_window_raise() only
5287 * requests the restack, does not guarantee it.
5290 gdk_window_raise (GdkWindow *window)
5292 cairo_region_t *old_region, *new_region;
5294 g_return_if_fail (GDK_IS_WINDOW (window));
5296 if (window->destroyed)
5299 gdk_window_flush_if_exposing (window);
5302 if (gdk_window_is_viewable (window) &&
5303 !window->input_only)
5304 old_region = cairo_region_copy (window->clip_region);
5306 /* Keep children in (reverse) stacking order */
5307 gdk_window_raise_internal (window);
5309 recompute_visible_regions (window, TRUE, FALSE);
5313 new_region = cairo_region_copy (window->clip_region);
5315 cairo_region_subtract (new_region, old_region);
5316 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_ALL);
5318 cairo_region_destroy (old_region);
5319 cairo_region_destroy (new_region);
5324 gdk_window_lower_internal (GdkWindow *window)
5326 GdkWindow *parent = window->parent;
5327 GdkWindowImplClass *impl_class;
5329 GList *native_children;
5334 parent->children = g_list_remove (parent->children, window);
5335 parent->children = g_list_append (parent->children, window);
5338 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5339 /* Just do native lower for toplevels */
5340 if (gdk_window_is_toplevel (window) ||
5341 /* The restack_under codepath should work correctly even if the parent
5342 is native, but it relies on the order of ->children to be correct,
5343 and some apps like SWT reorder the x windows without gdks knowledge,
5344 so we use lower directly in order to make these behave as before
5345 when using native windows */
5346 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5348 impl_class->lower (window);
5350 else if (gdk_window_has_impl (window))
5352 above = find_native_sibling_above (parent, window);
5355 listhead.data = window;
5356 listhead.next = NULL;
5357 listhead.prev = NULL;
5358 impl_class->restack_under ((GdkWindow *)above, &listhead);
5361 impl_class->raise (window);
5365 native_children = NULL;
5366 get_all_native_children (window, &native_children);
5367 if (native_children != NULL)
5369 above = find_native_sibling_above (parent, window);
5372 impl_class->restack_under ((GdkWindow *)above,
5376 /* Right order, since native_children is bottom-topmost first */
5377 for (l = native_children; l != NULL; l = l->next)
5378 impl_class->raise (l->data);
5381 g_list_free (native_children);
5388 gdk_window_invalidate_in_parent (GdkWindow *private)
5390 GdkRectangle r, child;
5392 if (gdk_window_is_toplevel (private))
5395 /* get the visible rectangle of the parent */
5397 r.width = private->parent->width;
5398 r.height = private->parent->height;
5400 child.x = private->x;
5401 child.y = private->y;
5402 child.width = private->width;
5403 child.height = private->height;
5404 gdk_rectangle_intersect (&r, &child, &r);
5406 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5412 * @window: a #GdkWindow
5414 * Lowers @window to the bottom of the Z-order (stacking order), so that
5415 * other windows with the same parent window appear above @window.
5416 * This is true whether or not the other windows are visible.
5418 * If @window is a toplevel, the window manager may choose to deny the
5419 * request to move the window in the Z-order, gdk_window_lower() only
5420 * requests the restack, does not guarantee it.
5422 * Note that gdk_window_show() raises the window again, so don't call this
5423 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5426 gdk_window_lower (GdkWindow *window)
5428 g_return_if_fail (GDK_IS_WINDOW (window));
5430 if (window->destroyed)
5433 gdk_window_flush_if_exposing (window);
5435 /* Keep children in (reverse) stacking order */
5436 gdk_window_lower_internal (window);
5438 recompute_visible_regions (window, TRUE, FALSE);
5440 _gdk_synthesize_crossing_events_for_geometry_change (window);
5441 gdk_window_invalidate_in_parent (window);
5445 * gdk_window_restack:
5446 * @window: a #GdkWindow
5447 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5450 * Changes the position of @window in the Z-order (stacking order), so that
5451 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5454 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5455 * lowers the window.
5457 * If @window is a toplevel, the window manager may choose to deny the
5458 * request to move the window in the Z-order, gdk_window_restack() only
5459 * requests the restack, does not guarantee it.
5464 gdk_window_restack (GdkWindow *window,
5468 GdkWindowImplClass *impl_class;
5470 GdkWindow *above_native;
5471 GList *sibling_link;
5472 GList *native_children;
5475 g_return_if_fail (GDK_IS_WINDOW (window));
5476 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5478 if (window->destroyed)
5481 if (sibling == NULL)
5484 gdk_window_raise (window);
5486 gdk_window_lower (window);
5490 gdk_window_flush_if_exposing (window);
5492 if (gdk_window_is_toplevel (window))
5494 g_return_if_fail (gdk_window_is_toplevel (sibling));
5495 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5496 impl_class->restack_toplevel (window, sibling, above);
5500 parent = window->parent;
5503 sibling_link = g_list_find (parent->children, sibling);
5504 g_return_if_fail (sibling_link != NULL);
5505 if (sibling_link == NULL)
5508 parent->children = g_list_remove (parent->children, window);
5510 parent->children = g_list_insert_before (parent->children,
5514 parent->children = g_list_insert_before (parent->children,
5518 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5519 if (gdk_window_has_impl (window))
5521 above_native = find_native_sibling_above (parent, window);
5524 listhead.data = window;
5525 listhead.next = NULL;
5526 listhead.prev = NULL;
5527 impl_class->restack_under (above_native, &listhead);
5530 impl_class->raise (window);
5534 native_children = NULL;
5535 get_all_native_children (window, &native_children);
5536 if (native_children != NULL)
5538 above_native = find_native_sibling_above (parent, window);
5540 impl_class->restack_under (above_native,
5544 /* Right order, since native_children is bottom-topmost first */
5545 for (l = native_children; l != NULL; l = l->next)
5546 impl_class->raise (l->data);
5549 g_list_free (native_children);
5554 recompute_visible_regions (window, TRUE, FALSE);
5556 _gdk_synthesize_crossing_events_for_geometry_change (window);
5557 gdk_window_invalidate_in_parent (window);
5563 * @window: a #GdkWindow
5565 * Like gdk_window_show_unraised(), but also raises the window to the
5566 * top of the window stack (moves the window to the front of the
5569 * This function maps a window so it's visible onscreen. Its opposite
5570 * is gdk_window_hide().
5572 * When implementing a #GtkWidget, you should call this function on the widget's
5573 * #GdkWindow as part of the "map" method.
5576 gdk_window_show (GdkWindow *window)
5578 gdk_window_show_internal (window, TRUE);
5583 * @window: a #GdkWindow
5585 * For toplevel windows, withdraws them, so they will no longer be
5586 * known to the window manager; for all windows, unmaps them, so
5587 * they won't be displayed. Normally done automatically as
5588 * part of gtk_widget_hide().
5591 gdk_window_hide (GdkWindow *window)
5593 GdkWindowImplClass *impl_class;
5594 gboolean was_mapped, did_hide;
5596 g_return_if_fail (GDK_IS_WINDOW (window));
5598 if (window->destroyed)
5601 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5603 if (gdk_window_has_impl (window))
5606 if (GDK_WINDOW_IS_MAPPED (window))
5607 gdk_synthesize_window_state (window,
5609 GDK_WINDOW_STATE_WITHDRAWN);
5611 else if (was_mapped)
5613 GdkDisplay *display;
5614 GdkDeviceManager *device_manager;
5617 /* May need to break grabs on children */
5618 display = gdk_window_get_display (window);
5619 device_manager = gdk_display_get_device_manager (display);
5621 /* Get all devices */
5622 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5623 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5624 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5626 for (d = devices; d; d = d->next)
5628 GdkDevice *device = d->data;
5630 if (_gdk_display_end_device_grab (display,
5632 _gdk_display_get_next_serial (display),
5635 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5638 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5639 g_list_free (devices);
5642 did_hide = _gdk_window_update_viewable (window);
5644 /* Hide foreign window as those are not handled by update_viewable. */
5645 if (gdk_window_has_impl (window) && (!did_hide))
5647 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5648 impl_class->hide (window);
5651 recompute_visible_regions (window, TRUE, FALSE);
5653 /* all decendants became non-visible, we need to send visibility notify */
5654 gdk_window_update_visibility_recursively (window, NULL);
5656 if (was_mapped && !gdk_window_has_impl (window))
5658 if (window->event_mask & GDK_STRUCTURE_MASK)
5659 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5661 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5662 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5664 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5667 /* Invalidate the rect */
5669 gdk_window_invalidate_in_parent (window);
5673 * gdk_window_withdraw:
5674 * @window: a toplevel #GdkWindow
5676 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5677 * This function is not really useful as gdk_window_hide() automatically
5678 * withdraws toplevel windows before hiding them.
5681 gdk_window_withdraw (GdkWindow *window)
5683 GdkWindowImplClass *impl_class;
5684 gboolean was_mapped;
5686 g_return_if_fail (GDK_IS_WINDOW (window));
5688 if (window->destroyed)
5691 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5693 if (gdk_window_has_impl (window))
5695 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5696 impl_class->withdraw (window);
5700 if (window->event_mask & GDK_STRUCTURE_MASK)
5701 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5703 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5704 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5706 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5709 recompute_visible_regions (window, TRUE, FALSE);
5714 * gdk_window_set_events:
5715 * @window: a #GdkWindow
5716 * @event_mask: event mask for @window
5718 * The event mask for a window determines which events will be reported
5719 * for that window from all master input devices. For example, an event mask
5720 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5721 * press events. The event mask is the bitwise OR of values from the
5722 * #GdkEventMask enumeration.
5725 gdk_window_set_events (GdkWindow *window,
5726 GdkEventMask event_mask)
5728 GdkWindowImplClass *impl_class;
5729 GdkDisplay *display;
5731 g_return_if_fail (GDK_IS_WINDOW (window));
5733 if (window->destroyed)
5736 /* If motion hint is disabled, enable motion events again */
5737 display = gdk_window_get_display (window);
5738 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5739 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5741 GList *devices = window->devices_inside;
5745 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5746 devices = devices->next;
5750 window->event_mask = event_mask;
5752 if (gdk_window_has_impl (window))
5754 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5755 impl_class->set_events (window,
5756 get_native_event_mask (window));
5762 * gdk_window_get_events:
5763 * @window: a #GdkWindow
5765 * Gets the event mask for @window for all master input devices. See
5766 * gdk_window_set_events().
5768 * Return value: event mask for @window
5771 gdk_window_get_events (GdkWindow *window)
5773 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5775 if (window->destroyed)
5778 return window->event_mask;
5782 * gdk_window_set_device_events:
5783 * @window: a #GdkWindow
5784 * @device: #GdkDevice to enable events for.
5785 * @event_mask: event mask for @window
5787 * Sets the event mask for a given device (Normally a floating device, not
5788 * attached to any visible pointer) to @window. For example, an event mask
5789 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5790 * press events. The event mask is the bitwise OR of values from the
5791 * #GdkEventMask enumeration.
5796 gdk_window_set_device_events (GdkWindow *window,
5798 GdkEventMask event_mask)
5800 GdkEventMask device_mask;
5801 GdkDisplay *display;
5804 g_return_if_fail (GDK_IS_WINDOW (window));
5805 g_return_if_fail (GDK_IS_DEVICE (device));
5807 if (GDK_WINDOW_DESTROYED (window))
5810 /* If motion hint is disabled, enable motion events again */
5811 display = gdk_window_get_display (window);
5812 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5813 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5814 _gdk_display_enable_motion_hints (display, device);
5816 if (G_UNLIKELY (!window->device_events))
5817 window->device_events = g_hash_table_new (NULL, NULL);
5819 if (event_mask == 0)
5821 /* FIXME: unsetting events on a master device
5822 * would restore window->event_mask
5824 g_hash_table_remove (window->device_events, device);
5827 g_hash_table_insert (window->device_events, device,
5828 GINT_TO_POINTER (event_mask));
5830 native = gdk_window_get_toplevel (window);
5832 while (gdk_window_is_offscreen (native))
5834 native = gdk_offscreen_window_get_embedder (native);
5836 if (native == NULL ||
5837 (!_gdk_window_has_impl (native) &&
5838 !gdk_window_is_viewable (native)))
5841 native = gdk_window_get_toplevel (native);
5844 device_mask = get_native_device_event_mask (window, device);
5845 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5849 * gdk_window_get_device_events:
5850 * @window: a #GdkWindow.
5851 * @device: a #GdkDevice.
5853 * Returns the event mask for @window corresponding to an specific device.
5855 * Returns: device event mask for @window
5860 gdk_window_get_device_events (GdkWindow *window,
5865 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5866 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5868 if (GDK_WINDOW_DESTROYED (window))
5871 if (!window->device_events)
5874 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5876 /* FIXME: device could be controlled by window->event_mask */
5882 gdk_window_move_resize_toplevel (GdkWindow *window,
5889 cairo_region_t *old_region, *new_region;
5890 GdkWindowImplClass *impl_class;
5897 is_resize = (width != -1) || (height != -1);
5899 if (gdk_window_is_viewable (window) &&
5900 !window->input_only)
5903 old_region = cairo_region_copy (window->clip_region);
5906 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5907 impl_class->move_resize (window, with_move, x, y, width, height);
5909 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5911 recompute_visible_regions (window, TRUE, FALSE);
5915 new_region = cairo_region_copy (window->clip_region);
5917 /* This is the newly exposed area (due to any resize),
5918 * X will expose it, but lets do that without the roundtrip
5920 cairo_region_subtract (new_region, old_region);
5921 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
5923 cairo_region_destroy (old_region);
5924 cairo_region_destroy (new_region);
5927 _gdk_synthesize_crossing_events_for_geometry_change (window);
5932 move_native_children (GdkWindow *private)
5936 GdkWindowImplClass *impl_class;
5938 for (l = private->children; l; l = l->next)
5942 if (child->impl != private->impl)
5944 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
5945 impl_class->move_resize (child, TRUE,
5947 child->width, child->height);
5950 move_native_children (child);
5955 collect_native_child_region_helper (GdkWindow *window,
5956 GdkWindowImpl *impl,
5957 cairo_region_t **region,
5962 cairo_region_t *tmp;
5965 for (l = window->children; l != NULL; l = l->next)
5969 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
5972 if (child->impl != impl)
5974 tmp = cairo_region_copy (child->clip_region);
5975 cairo_region_translate (tmp,
5976 x_offset + child->x,
5977 y_offset + child->y);
5978 if (*region == NULL)
5982 cairo_region_union (*region, tmp);
5983 cairo_region_destroy (tmp);
5987 collect_native_child_region_helper (child, impl, region,
5988 x_offset + child->x,
5989 y_offset + child->y);
5995 static cairo_region_t *
5996 collect_native_child_region (GdkWindow *window,
5997 gboolean include_this)
5999 cairo_region_t *region;
6001 if (include_this && gdk_window_has_impl (window) && window->viewable)
6002 return cairo_region_copy (window->clip_region);
6006 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6013 gdk_window_move_resize_internal (GdkWindow *window,
6020 cairo_region_t *old_region, *new_region, *copy_area;
6021 cairo_region_t *old_native_child_region, *new_native_child_region;
6022 GdkWindow *impl_window;
6023 GdkWindowImplClass *impl_class;
6025 int old_x, old_y, old_abs_x, old_abs_y;
6028 g_return_if_fail (GDK_IS_WINDOW (window));
6030 if (window->destroyed)
6033 if (gdk_window_is_toplevel (window))
6035 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6039 /* Bail early if no change */
6040 if (window->width == width &&
6041 window->height == height &&
6047 gdk_window_flush_if_exposing (window);
6049 /* Handle child windows */
6054 impl_window = gdk_window_get_impl_window (window);
6059 old_native_child_region = NULL;
6060 if (gdk_window_is_viewable (window) &&
6061 !window->input_only)
6065 old_region = cairo_region_copy (window->clip_region);
6066 /* Adjust region to parent window coords */
6067 cairo_region_translate (old_region, window->x, window->y);
6069 old_native_child_region = collect_native_child_region (window, TRUE);
6070 if (old_native_child_region)
6072 /* Adjust region to parent window coords */
6073 cairo_region_translate (old_native_child_region, window->x, window->y);
6075 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6076 * source or destination for a delayed GdkWindowRegionMove. So, we need
6077 * to flush those here for the parent window and all overlapped subwindows
6078 * of it. And we need to do this before setting the new clips as those will be
6081 gdk_window_flush_recursive (window->parent);
6085 /* Set the new position and size */
6091 if (!(width < 0 && height < 0))
6095 window->width = width;
6098 window->height = height;
6101 dx = window->x - old_x;
6102 dy = window->y - old_y;
6104 old_abs_x = window->abs_x;
6105 old_abs_y = window->abs_y;
6107 recompute_visible_regions (window, TRUE, FALSE);
6109 new_native_child_region = NULL;
6110 if (old_native_child_region)
6112 new_native_child_region = collect_native_child_region (window, TRUE);
6113 /* Adjust region to parent window coords */
6114 cairo_region_translate (new_native_child_region, window->x, window->y);
6117 if (gdk_window_has_impl (window))
6119 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6121 /* Do the actual move after recomputing things, as this will have set the shape to
6122 the now correct one, thus avoiding copying regions that should not be copied. */
6123 impl_class->move_resize (window, TRUE,
6124 window->x, window->y,
6125 window->width, window->height);
6127 else if (old_abs_x != window->abs_x ||
6128 old_abs_y != window->abs_y)
6129 move_native_children (window);
6133 new_region = cairo_region_copy (window->clip_region);
6134 /* Adjust region to parent window coords */
6135 cairo_region_translate (new_region, window->x, window->y);
6138 * Part of the data at the new location can be copied from the
6139 * old location, this area is the intersection of the old region
6140 * moved as the copy will move it and then intersected with
6144 * Everything in the old and new regions that is not copied must be
6145 * invalidated (including children) as this is newly exposed
6147 copy_area = cairo_region_copy (new_region);
6149 cairo_region_union (new_region, old_region);
6151 if (old_native_child_region)
6153 /* Don't copy from inside native children, as this is copied by
6154 * the native window move.
6156 cairo_region_subtract (old_region, old_native_child_region);
6158 cairo_region_translate (old_region, dx, dy);
6160 cairo_region_intersect (copy_area, old_region);
6162 if (new_native_child_region)
6164 /* Don't copy any bits that would cause a read from the moved
6165 native windows, as we can't read that data */
6166 cairo_region_translate (new_native_child_region, dx, dy);
6167 cairo_region_subtract (copy_area, new_native_child_region);
6168 cairo_region_translate (new_native_child_region, -dx, -dy);
6171 cairo_region_subtract (new_region, copy_area);
6173 /* Convert old region to impl coords */
6174 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6176 /* convert from parent coords to impl */
6177 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6179 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6181 /* Invalidate affected part in the parent window
6182 * (no higher window should be affected)
6183 * We also invalidate any children in that area, which could include
6184 * this window if it still overlaps that area.
6186 if (old_native_child_region)
6188 /* No need to expose the region that the native window move copies */
6189 cairo_region_translate (old_native_child_region, dx, dy);
6190 cairo_region_intersect (old_native_child_region, new_native_child_region);
6191 cairo_region_subtract (new_region, old_native_child_region);
6193 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6195 cairo_region_destroy (old_region);
6196 cairo_region_destroy (new_region);
6199 if (old_native_child_region)
6201 cairo_region_destroy (old_native_child_region);
6202 cairo_region_destroy (new_native_child_region);
6205 _gdk_synthesize_crossing_events_for_geometry_change (window);
6212 * @window: a #GdkWindow
6213 * @x: X coordinate relative to window's parent
6214 * @y: Y coordinate relative to window's parent
6216 * Repositions a window relative to its parent window.
6217 * For toplevel windows, window managers may ignore or modify the move;
6218 * you should probably use gtk_window_move() on a #GtkWindow widget
6219 * anyway, instead of using GDK functions. For child windows,
6220 * the move will reliably succeed.
6222 * If you're also planning to resize the window, use gdk_window_move_resize()
6223 * to both move and resize simultaneously, for a nicer visual effect.
6226 gdk_window_move (GdkWindow *window,
6230 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6234 * gdk_window_resize:
6235 * @window: a #GdkWindow
6236 * @width: new width of the window
6237 * @height: new height of the window
6239 * Resizes @window; for toplevel windows, asks the window manager to resize
6240 * the window. The window manager may not allow the resize. When using GTK+,
6241 * use gtk_window_resize() instead of this low-level GDK function.
6243 * Windows may not be resized below 1x1.
6245 * If you're also planning to move the window, use gdk_window_move_resize()
6246 * to both move and resize simultaneously, for a nicer visual effect.
6249 gdk_window_resize (GdkWindow *window,
6253 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6258 * gdk_window_move_resize:
6259 * @window: a #GdkWindow
6260 * @x: new X position relative to window's parent
6261 * @y: new Y position relative to window's parent
6263 * @height: new height
6265 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6266 * except that both operations are performed at once, avoiding strange
6267 * visual effects. (i.e. the user may be able to see the window first
6268 * move, then resize, if you don't use gdk_window_move_resize().)
6271 gdk_window_move_resize (GdkWindow *window,
6277 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6282 * gdk_window_scroll:
6283 * @window: a #GdkWindow
6284 * @dx: Amount to scroll in the X direction
6285 * @dy: Amount to scroll in the Y direction
6287 * Scroll the contents of @window, both pixels and children, by the
6288 * given amount. @window itself does not move. Portions of the window
6289 * that the scroll operation brings in from offscreen areas are
6290 * invalidated. The invalidated region may be bigger than what would
6291 * strictly be necessary.
6293 * For X11, a minimum area will be invalidated if the window has no
6294 * subwindows, or if the edges of the window's parent do not extend
6295 * beyond the edges of the window. In other cases, a multi-step process
6296 * is used to scroll the window which may produce temporary visual
6297 * artifacts and unnecessary invalidations.
6300 gdk_window_scroll (GdkWindow *window,
6304 GdkWindow *impl_window;
6305 cairo_region_t *copy_area, *noncopy_area;
6306 cairo_region_t *old_native_child_region, *new_native_child_region;
6309 g_return_if_fail (GDK_IS_WINDOW (window));
6311 if (dx == 0 && dy == 0)
6314 if (window->destroyed)
6317 gdk_window_flush_if_exposing (window);
6319 old_native_child_region = collect_native_child_region (window, FALSE);
6320 if (old_native_child_region)
6322 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6323 * source or destination for a delayed GdkWindowRegionMove. So, we need
6324 * to flush those here for the window and all overlapped subwindows
6325 * of it. And we need to do this before setting the new clips as those will be
6328 gdk_window_flush_recursive (window);
6332 /* First move all child windows, without causing invalidation */
6334 tmp_list = window->children;
6337 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6339 /* Just update the positions, the bits will move with the copy */
6343 tmp_list = tmp_list->next;
6346 recompute_visible_regions (window, FALSE, TRUE);
6348 new_native_child_region = NULL;
6349 if (old_native_child_region)
6350 new_native_child_region = collect_native_child_region (window, FALSE);
6352 move_native_children (window);
6354 /* Then copy the actual bits of the window w/ child windows */
6356 impl_window = gdk_window_get_impl_window (window);
6358 /* Calculate the area that can be gotten by copying the old area */
6359 copy_area = cairo_region_copy (window->clip_region);
6360 if (old_native_child_region)
6362 /* Don't copy from inside native children, as this is copied by
6363 * the native window move.
6365 cairo_region_subtract (copy_area, old_native_child_region);
6367 /* Don't copy any bits that would cause a read from the moved
6368 native windows, as we can't read that data */
6369 cairo_region_subtract (copy_area, new_native_child_region);
6371 cairo_region_translate (copy_area, dx, dy);
6372 cairo_region_intersect (copy_area, window->clip_region);
6374 /* And the rest need to be invalidated */
6375 noncopy_area = cairo_region_copy (window->clip_region);
6376 cairo_region_subtract (noncopy_area, copy_area);
6378 /* convert from window coords to impl */
6379 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6381 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6383 /* Invalidate not copied regions */
6384 if (old_native_child_region)
6386 /* No need to expose the region that the native window move copies */
6387 cairo_region_translate (old_native_child_region, dx, dy);
6388 cairo_region_intersect (old_native_child_region, new_native_child_region);
6389 cairo_region_subtract (noncopy_area, old_native_child_region);
6391 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6393 cairo_region_destroy (noncopy_area);
6395 if (old_native_child_region)
6397 cairo_region_destroy (old_native_child_region);
6398 cairo_region_destroy (new_native_child_region);
6401 _gdk_synthesize_crossing_events_for_geometry_change (window);
6405 * gdk_window_move_region:
6406 * @window: a #GdkWindow
6407 * @region: The #cairo_region_t to move
6408 * @dx: Amount to move in the X direction
6409 * @dy: Amount to move in the Y direction
6411 * Move the part of @window indicated by @region by @dy pixels in the Y
6412 * direction and @dx pixels in the X direction. The portions of @region
6413 * that not covered by the new position of @region are invalidated.
6415 * Child windows are not moved.
6420 gdk_window_move_region (GdkWindow *window,
6421 const cairo_region_t *region,
6425 GdkWindow *impl_window;
6426 cairo_region_t *nocopy_area;
6427 cairo_region_t *copy_area;
6429 g_return_if_fail (GDK_IS_WINDOW (window));
6430 g_return_if_fail (region != NULL);
6432 if (dx == 0 && dy == 0)
6435 if (window->destroyed)
6438 impl_window = gdk_window_get_impl_window (window);
6440 /* compute source regions */
6441 copy_area = cairo_region_copy (region);
6442 cairo_region_intersect (copy_area, window->clip_region_with_children);
6444 /* compute destination regions */
6445 cairo_region_translate (copy_area, dx, dy);
6446 cairo_region_intersect (copy_area, window->clip_region_with_children);
6448 /* Invalidate parts of the region (source and dest) not covered
6450 nocopy_area = cairo_region_copy (region);
6451 cairo_region_translate (nocopy_area, dx, dy);
6452 cairo_region_union (nocopy_area, region);
6453 cairo_region_subtract (nocopy_area, copy_area);
6455 /* convert from window coords to impl */
6456 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6457 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6459 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6460 cairo_region_destroy (nocopy_area);
6464 * gdk_window_set_background:
6465 * @window: a #GdkWindow
6466 * @color: a #GdkColor
6468 * Sets the background color of @window. (However, when using GTK+,
6469 * set the background of a widget with gtk_widget_modify_bg() - if
6470 * you're an application - or gtk_style_set_background() - if you're
6471 * implementing a custom widget.)
6473 * See also gdk_window_set_background_pattern().
6476 gdk_window_set_background (GdkWindow *window,
6477 const GdkColor *color)
6479 cairo_pattern_t *pattern;
6481 g_return_if_fail (GDK_IS_WINDOW (window));
6483 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6484 color->green / 65535.,
6485 color->blue / 65535.);
6487 gdk_window_set_background_pattern (window, pattern);
6489 cairo_pattern_destroy (pattern);
6493 * gdk_window_set_background_rgba:
6494 * @window: a #GdkWindow
6495 * @rgba: a #GdkRGBA color
6497 * Sets the background color of @window.
6499 * See also gdk_window_set_background_pattern().
6502 gdk_window_set_background_rgba (GdkWindow *window,
6505 cairo_pattern_t *pattern;
6507 g_return_if_fail (GDK_IS_WINDOW (window));
6508 g_return_if_fail (rgba != NULL);
6510 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6511 rgba->blue, rgba->alpha);
6513 gdk_window_set_background_pattern (window, pattern);
6515 cairo_pattern_destroy (pattern);
6519 * gdk_window_set_background_pattern:
6520 * @window: a #GdkWindow
6521 * @pattern: (allow-none): a pattern to use, or %NULL
6523 * Sets the background of @window.
6525 * A background of %NULL means that the window will inherit its
6526 * background form its parent window.
6528 * The windowing system will normally fill a window with its background
6529 * when the window is obscured then exposed.
6532 gdk_window_set_background_pattern (GdkWindow *window,
6533 cairo_pattern_t *pattern)
6535 g_return_if_fail (GDK_IS_WINDOW (window));
6537 if (window->input_only)
6541 cairo_pattern_reference (pattern);
6542 if (window->background)
6543 cairo_pattern_destroy (window->background);
6544 window->background = pattern;
6546 if (gdk_window_has_impl (window))
6548 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6549 impl_class->set_background (window, pattern);
6554 * gdk_window_get_background_pattern:
6557 * Gets the pattern used to clear the background on @window. If @window
6558 * does not have its own background and reuses the parent's, %NULL is
6559 * returned and you'll have to query it yourself.
6561 * Returns: (transfer none): The pattern to use for the background or
6562 * %NULL to use the parent's background.
6567 gdk_window_get_background_pattern (GdkWindow *window)
6569 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6571 return window->background;
6575 gdk_window_set_cursor_internal (GdkWindow *window,
6579 if (GDK_WINDOW_DESTROYED (window))
6582 if (window->window_type == GDK_WINDOW_ROOT ||
6583 window->window_type == GDK_WINDOW_FOREIGN)
6584 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6587 GdkPointerWindowInfo *pointer_info;
6588 GdkDisplay *display;
6590 display = gdk_window_get_display (window);
6591 pointer_info = _gdk_display_get_pointer_info (display, device);
6593 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6594 update_cursor (display, device);
6599 * gdk_window_get_cursor:
6600 * @window: a #GdkWindow
6602 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6603 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6604 * there is no custom cursor set on the specified window, and it is
6605 * using the cursor for its parent window.
6607 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6608 * object is owned by the #GdkWindow and should not be unreferenced
6609 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6615 gdk_window_get_cursor (GdkWindow *window)
6617 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6619 return window->cursor;
6623 * gdk_window_set_cursor:
6624 * @window: a #GdkWindow
6625 * @cursor: (allow-none): a cursor
6627 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6628 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6629 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6630 * to gdk_window_set_cursor() means that @window will use the cursor of its
6631 * parent window. Most windows should use this default.
6634 gdk_window_set_cursor (GdkWindow *window,
6637 GdkDisplay *display;
6639 g_return_if_fail (GDK_IS_WINDOW (window));
6641 display = gdk_window_get_display (window);
6645 g_object_unref (window->cursor);
6646 window->cursor = NULL;
6649 if (!GDK_WINDOW_DESTROYED (window))
6651 GdkDeviceManager *device_manager;
6655 window->cursor = g_object_ref (cursor);
6657 device_manager = gdk_display_get_device_manager (display);
6658 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6660 for (d = devices; d; d = d->next)
6666 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6669 gdk_window_set_cursor_internal (window, device, window->cursor);
6672 g_list_free (devices);
6673 g_object_notify (G_OBJECT (window), "cursor");
6678 * gdk_window_get_device_cursor:
6679 * @window: a #GdkWindow.
6680 * @device: a master, pointer #GdkDevice.
6682 * Retrieves a #GdkCursor pointer for the @device currently set on the
6683 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6684 * there is no custom cursor set on the specified window, and it is
6685 * using the cursor for its parent window.
6687 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6688 * object is owned by the #GdkWindow and should not be unreferenced
6689 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6695 gdk_window_get_device_cursor (GdkWindow *window,
6698 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6699 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6700 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6701 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6703 return g_hash_table_lookup (window->device_cursor, device);
6707 * gdk_window_set_device_cursor:
6708 * @window: a #Gdkwindow
6709 * @device: a master, pointer #GdkDevice
6710 * @cursor: a #GdkCursor
6712 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6713 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6714 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6715 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6716 * @window will use the cursor of its parent window. Most windows should
6722 gdk_window_set_device_cursor (GdkWindow *window,
6726 g_return_if_fail (GDK_IS_WINDOW (window));
6727 g_return_if_fail (GDK_IS_DEVICE (device));
6728 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6729 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6732 g_hash_table_remove (window->device_cursor, device);
6734 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6736 gdk_window_set_cursor_internal (window, device, cursor);
6740 * gdk_window_get_geometry:
6741 * @window: a #GdkWindow
6742 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6743 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6744 * @width: (out) (allow-none): return location for width of window
6745 * @height: (out) (allow-none): return location for height of window
6747 * Any of the return location arguments to this function may be %NULL,
6748 * if you aren't interested in getting the value of that field.
6750 * The X and Y coordinates returned are relative to the parent window
6751 * of @window, which for toplevels usually means relative to the
6752 * window decorations (titlebar, etc.) rather than relative to the
6753 * root window (screen-size background window).
6755 * On the X11 platform, the geometry is obtained from the X server,
6756 * so reflects the latest position of @window; this may be out-of-sync
6757 * with the position of @window delivered in the most-recently-processed
6758 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6759 * position from the most recent configure event.
6762 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6763 * to call gdk_window_get_position(), gdk_window_get_width() and
6764 * gdk_window_get_height() instead, because it avoids the roundtrip to
6765 * the X server and because these functions support the full 32-bit
6766 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6767 * the 16-bit coordinates of X11.
6771 gdk_window_get_geometry (GdkWindow *window,
6778 GdkWindowImplClass *impl_class;
6782 GDK_NOTE (MULTIHEAD,
6783 g_message ("gdk_window_get_geometry(): Window needs "
6784 "to be non-NULL to be multi head safe"));
6785 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6788 g_return_if_fail (GDK_IS_WINDOW (window));
6790 if (!GDK_WINDOW_DESTROYED (window))
6792 if (gdk_window_has_impl (window))
6794 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6795 impl_class->get_geometry (window, x, y,
6797 /* This reports the position wrt to the native parent, we need to convert
6798 it to be relative to the client side parent */
6799 parent = window->parent;
6800 if (parent && !gdk_window_has_impl (parent))
6803 *x -= parent->abs_x;
6805 *y -= parent->abs_y;
6815 *width = window->width;
6817 *height = window->height;
6823 * gdk_window_get_width:
6824 * @window: a #GdkWindow
6826 * Returns the width of the given @window.
6828 * On the X11 platform the returned size is the size reported in the
6829 * most-recently-processed configure event, rather than the current
6830 * size on the X server.
6832 * Returns: The width of @window
6837 gdk_window_get_width (GdkWindow *window)
6839 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6841 return window->width;
6845 * gdk_window_get_height:
6846 * @window: a #GdkWindow
6848 * Returns the height of the given @window.
6850 * On the X11 platform the returned size is the size reported in the
6851 * most-recently-processed configure event, rather than the current
6852 * size on the X server.
6854 * Returns: The height of @window
6859 gdk_window_get_height (GdkWindow *window)
6861 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6863 return window->height;
6867 * gdk_window_get_origin:
6868 * @window: a #GdkWindow
6869 * @x: (out) (allow-none): return location for X coordinate
6870 * @y: (out) (allow-none): return location for Y coordinate
6872 * Obtains the position of a window in root window coordinates.
6873 * (Compare with gdk_window_get_position() and
6874 * gdk_window_get_geometry() which return the position of a window
6875 * relative to its parent window.)
6877 * Return value: not meaningful, ignore
6880 gdk_window_get_origin (GdkWindow *window,
6884 GdkWindowImplClass *impl_class;
6886 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6888 if (GDK_WINDOW_DESTROYED (window))
6897 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6898 impl_class->get_root_coords (window,
6907 * gdk_window_get_root_coords:
6908 * @window: a #GdkWindow
6909 * @x: X coordinate in window
6910 * @y: Y coordinate in window
6911 * @root_x: (out): return location for X coordinate
6912 * @root_y: (out): return location for Y coordinate
6914 * Obtains the position of a window position in root
6915 * window coordinates. This is similar to
6916 * gdk_window_get_origin() but allows you go pass
6917 * in any position in the window, not just the origin.
6922 gdk_window_get_root_coords (GdkWindow *window,
6928 GdkWindowImplClass *impl_class;
6930 g_return_if_fail (GDK_IS_WINDOW (window));
6932 if (GDK_WINDOW_DESTROYED (window))
6941 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6942 impl_class->get_root_coords (window,
6949 * gdk_window_coords_to_parent:
6950 * @window: a child window
6951 * @x: X coordinate in child's coordinate system
6952 * @y: Y coordinate in child's coordinate system
6953 * @parent_x: (out) (allow-none): return location for X coordinate
6954 * in parent's coordinate system, or %NULL
6955 * @parent_y: (out) (allow-none): return location for Y coordinate
6956 * in parent's coordinate system, or %NULL
6958 * Transforms window coordinates from a child window to its parent
6959 * window, where the parent window is the normal parent as returned by
6960 * gdk_window_get_parent() for normal windows, and the window's
6961 * embedder as returned by gdk_offscreen_window_get_embedder() for
6962 * offscreen windows.
6964 * For normal windows, calling this function is equivalent to adding
6965 * the return values of gdk_window_get_position() to the child coordinates.
6966 * For offscreen windows however (which can be arbitrarily transformed),
6967 * this function calls the GdkWindow::to-embedder: signal to translate
6970 * You should always use this function when writing generic code that
6971 * walks up a window hierarchy.
6973 * See also: gdk_window_coords_from_parent()
6978 gdk_window_coords_to_parent (GdkWindow *window,
6984 g_return_if_fail (GDK_IS_WINDOW (window));
6986 if (gdk_window_is_offscreen (window))
6990 to_embedder (window, x, y, &px, &py);
7001 *parent_x = x + window->x;
7004 *parent_y = y + window->y;
7009 * gdk_window_coords_from_parent:
7010 * @window: a child window
7011 * @parent_x: X coordinate in parent's coordinate system
7012 * @parent_y: Y coordinate in parent's coordinate system
7013 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7014 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7016 * Transforms window coordinates from a parent window to a child
7017 * window, where the parent window is the normal parent as returned by
7018 * gdk_window_get_parent() for normal windows, and the window's
7019 * embedder as returned by gdk_offscreen_window_get_embedder() for
7020 * offscreen windows.
7022 * For normal windows, calling this function is equivalent to subtracting
7023 * the return values of gdk_window_get_position() from the parent coordinates.
7024 * For offscreen windows however (which can be arbitrarily transformed),
7025 * this function calls the GdkWindow::from-embedder: signal to translate
7028 * You should always use this function when writing generic code that
7029 * walks down a window hierarchy.
7031 * See also: gdk_window_coords_to_parent()
7036 gdk_window_coords_from_parent (GdkWindow *window,
7042 g_return_if_fail (GDK_IS_WINDOW (window));
7044 if (gdk_window_is_offscreen (window))
7048 from_embedder (window, parent_x, parent_y, &cx, &cy);
7059 *x = parent_x - window->x;
7062 *y = parent_y - window->y;
7067 * gdk_window_shape_combine_region:
7068 * @window: a #GdkWindow
7069 * @shape_region: (allow-none): region of window to be non-transparent
7070 * @offset_x: X position of @shape_region in @window coordinates
7071 * @offset_y: Y position of @shape_region in @window coordinates
7073 * Makes pixels in @window outside @shape_region be transparent,
7074 * so that the window may be nonrectangular.
7076 * If @shape_region is %NULL, the shape will be unset, so the whole
7077 * window will be opaque again. @offset_x and @offset_y are ignored
7078 * if @shape_region is %NULL.
7080 * On the X11 platform, this uses an X server extension which is
7081 * widely available on most common platforms, but not available on
7082 * very old X servers, and occasionally the implementation will be
7083 * buggy. On servers without the shape extension, this function
7086 * This function works on both toplevel and child windows.
7089 gdk_window_shape_combine_region (GdkWindow *window,
7090 const cairo_region_t *shape_region,
7094 cairo_region_t *old_region, *new_region, *diff;
7096 g_return_if_fail (GDK_IS_WINDOW (window));
7098 if (GDK_WINDOW_DESTROYED (window))
7101 if (!window->shape && shape_region == NULL)
7104 window->shaped = (shape_region != NULL);
7107 cairo_region_destroy (window->shape);
7110 if (GDK_WINDOW_IS_MAPPED (window))
7111 old_region = cairo_region_copy (window->clip_region);
7115 window->shape = cairo_region_copy (shape_region);
7116 cairo_region_translate (window->shape, offset_x, offset_y);
7119 window->shape = NULL;
7121 recompute_visible_regions (window, TRUE, FALSE);
7123 if (gdk_window_has_impl (window) &&
7124 !should_apply_clip_as_shape (window))
7125 apply_shape (window, window->shape);
7129 new_region = cairo_region_copy (window->clip_region);
7131 /* New area in the window, needs invalidation */
7132 diff = cairo_region_copy (new_region);
7133 cairo_region_subtract (diff, old_region);
7135 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7137 cairo_region_destroy (diff);
7139 if (!gdk_window_is_toplevel (window))
7141 /* New area in the non-root parent window, needs invalidation */
7142 diff = cairo_region_copy (old_region);
7143 cairo_region_subtract (diff, new_region);
7145 /* Adjust region to parent window coords */
7146 cairo_region_translate (diff, window->x, window->y);
7148 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7150 cairo_region_destroy (diff);
7153 cairo_region_destroy (new_region);
7154 cairo_region_destroy (old_region);
7159 do_child_shapes (GdkWindow *window,
7163 cairo_region_t *region;
7167 r.width = window->width;
7168 r.height = window->height;
7170 region = cairo_region_create_rectangle (&r);
7171 remove_child_area (window, NULL, FALSE, region);
7173 if (merge && window->shape)
7174 cairo_region_subtract (region, window->shape);
7176 gdk_window_shape_combine_region (window, region, 0, 0);
7180 * gdk_window_set_child_shapes:
7181 * @window: a #GdkWindow
7183 * Sets the shape mask of @window to the union of shape masks
7184 * for all children of @window, ignoring the shape mask of @window
7185 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7186 * the shape mask of @window in the masks to be merged.
7189 gdk_window_set_child_shapes (GdkWindow *window)
7191 g_return_if_fail (GDK_IS_WINDOW (window));
7193 do_child_shapes (window, FALSE);
7197 * gdk_window_merge_child_shapes:
7198 * @window: a #GdkWindow
7200 * Merges the shape masks for any child windows into the
7201 * shape mask for @window. i.e. the union of all masks
7202 * for @window and its children will become the new mask
7203 * for @window. See gdk_window_shape_combine_region().
7205 * This function is distinct from gdk_window_set_child_shapes()
7206 * because it includes @window's shape mask in the set of shapes to
7210 gdk_window_merge_child_shapes (GdkWindow *window)
7212 g_return_if_fail (GDK_IS_WINDOW (window));
7214 do_child_shapes (window, TRUE);
7218 * gdk_window_input_shape_combine_region:
7219 * @window: a #GdkWindow
7220 * @shape_region: region of window to be non-transparent
7221 * @offset_x: X position of @shape_region in @window coordinates
7222 * @offset_y: Y position of @shape_region in @window coordinates
7224 * Like gdk_window_shape_combine_region(), but the shape applies
7225 * only to event handling. Mouse events which happen while
7226 * the pointer position corresponds to an unset bit in the
7227 * mask will be passed on the window below @window.
7229 * An input shape is typically used with RGBA windows.
7230 * The alpha channel of the window defines which pixels are
7231 * invisible and allows for nicely antialiased borders,
7232 * and the input shape controls where the window is
7235 * On the X11 platform, this requires version 1.1 of the
7238 * On the Win32 platform, this functionality is not present and the
7239 * function does nothing.
7244 gdk_window_input_shape_combine_region (GdkWindow *window,
7245 const cairo_region_t *shape_region,
7249 GdkWindowImplClass *impl_class;
7251 g_return_if_fail (GDK_IS_WINDOW (window));
7253 if (GDK_WINDOW_DESTROYED (window))
7256 if (window->input_shape)
7257 cairo_region_destroy (window->input_shape);
7261 window->input_shape = cairo_region_copy (shape_region);
7262 cairo_region_translate (window->input_shape, offset_x, offset_y);
7265 window->input_shape = NULL;
7267 if (gdk_window_has_impl (window))
7269 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7270 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7273 /* Pointer may have e.g. moved outside window due to the input mask change */
7274 _gdk_synthesize_crossing_events_for_geometry_change (window);
7278 do_child_input_shapes (GdkWindow *window,
7282 cairo_region_t *region;
7286 r.width = window->width;
7287 r.height = window->height;
7289 region = cairo_region_create_rectangle (&r);
7290 remove_child_area (window, NULL, TRUE, region);
7292 if (merge && window->shape)
7293 cairo_region_subtract (region, window->shape);
7294 if (merge && window->input_shape)
7295 cairo_region_subtract (region, window->input_shape);
7297 gdk_window_input_shape_combine_region (window, region, 0, 0);
7302 * gdk_window_set_child_input_shapes:
7303 * @window: a #GdkWindow
7305 * Sets the input shape mask of @window to the union of input shape masks
7306 * for all children of @window, ignoring the input shape mask of @window
7307 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7308 * the input shape mask of @window in the masks to be merged.
7313 gdk_window_set_child_input_shapes (GdkWindow *window)
7315 g_return_if_fail (GDK_IS_WINDOW (window));
7317 do_child_input_shapes (window, FALSE);
7321 * gdk_window_merge_child_input_shapes:
7322 * @window: a #GdkWindow
7324 * Merges the input shape masks for any child windows into the
7325 * input shape mask for @window. i.e. the union of all input masks
7326 * for @window and its children will become the new input mask
7327 * for @window. See gdk_window_input_shape_combine_region().
7329 * This function is distinct from gdk_window_set_child_input_shapes()
7330 * because it includes @window's input shape mask in the set of
7331 * shapes to be merged.
7336 gdk_window_merge_child_input_shapes (GdkWindow *window)
7338 g_return_if_fail (GDK_IS_WINDOW (window));
7340 do_child_input_shapes (window, TRUE);
7345 * gdk_window_set_static_gravities:
7346 * @window: a #GdkWindow
7347 * @use_static: %TRUE to turn on static gravity
7349 * Set the bit gravity of the given window to static, and flag it so
7350 * all children get static subwindow gravity. This is used if you are
7351 * implementing scary features that involve deep knowledge of the
7352 * windowing system. Don't worry about it unless you have to.
7354 * Return value: %TRUE if the server supports static gravity
7357 gdk_window_set_static_gravities (GdkWindow *window,
7358 gboolean use_static)
7360 GdkWindowImplClass *impl_class;
7362 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7364 if (gdk_window_has_impl (window))
7366 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7367 return impl_class->set_static_gravities (window, use_static);
7374 * gdk_window_get_composited:
7375 * @window: a #GdkWindow
7377 * Determines whether @window is composited.
7379 * See gdk_window_set_composited().
7381 * Returns: %TRUE if the window is composited.
7386 gdk_window_get_composited (GdkWindow *window)
7388 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7390 return window->composited;
7394 * gdk_window_set_composited:
7395 * @window: a #GdkWindow
7396 * @composited: %TRUE to set the window as composited
7398 * Sets a #GdkWindow as composited, or unsets it. Composited
7399 * windows do not automatically have their contents drawn to
7400 * the screen. Drawing is redirected to an offscreen buffer
7401 * and an expose event is emitted on the parent of the composited
7402 * window. It is the responsibility of the parent's expose handler
7403 * to manually merge the off-screen content onto the screen in
7404 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7407 * It only makes sense for child windows to be composited; see
7408 * gdk_window_set_opacity() if you need translucent toplevel
7411 * An additional effect of this call is that the area of this
7412 * window is no longer clipped from regions marked for
7413 * invalidation on its parent. Draws done on the parent
7414 * window are also no longer clipped by the child.
7416 * This call is only supported on some systems (currently,
7417 * only X11 with new enough Xcomposite and Xdamage extensions).
7418 * You must call gdk_display_supports_composite() to check if
7419 * setting a window as composited is supported before
7420 * attempting to do so.
7425 gdk_window_set_composited (GdkWindow *window,
7426 gboolean composited)
7428 GdkDisplay *display;
7429 GdkWindowImplClass *impl_class;
7431 g_return_if_fail (GDK_IS_WINDOW (window));
7433 composited = composited != FALSE;
7435 if (window->composited == composited)
7439 gdk_window_ensure_native (window);
7441 display = gdk_window_get_display (window);
7443 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7445 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7447 g_warning ("gdk_window_set_composited called but "
7448 "compositing is not supported");
7452 impl_class->set_composited (window, composited);
7454 recompute_visible_regions (window, TRUE, FALSE);
7456 if (GDK_WINDOW_IS_MAPPED (window))
7457 gdk_window_invalidate_in_parent (window);
7459 window->composited = composited;
7463 * gdk_window_get_modal_hint:
7464 * @window: A toplevel #GdkWindow.
7466 * Determines whether or not the window manager is hinted that @window
7467 * has modal behaviour.
7469 * Return value: whether or not the window has the modal hint set.
7474 gdk_window_get_modal_hint (GdkWindow *window)
7476 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7478 return window->modal_hint;
7482 * gdk_window_get_accept_focus:
7483 * @window: a toplevel #GdkWindow.
7485 * Determines whether or not the desktop environment shuld be hinted that
7486 * the window does not want to receive input focus.
7488 * Return value: whether or not the window should receive input focus.
7493 gdk_window_get_accept_focus (GdkWindow *window)
7495 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7497 return window->accept_focus;
7501 * gdk_window_get_focus_on_map:
7502 * @window: a toplevel #GdkWindow.
7504 * Determines whether or not the desktop environment should be hinted that the
7505 * window does not want to receive input focus when it is mapped.
7507 * Return value: whether or not the window wants to receive input focus when
7513 gdk_window_get_focus_on_map (GdkWindow *window)
7515 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7517 return window->focus_on_map;
7521 * gdk_window_is_input_only:
7522 * @window: a toplevel #GdkWindow
7524 * Determines whether or not the window is an input only window.
7526 * Return value: %TRUE if @window is input only
7531 gdk_window_is_input_only (GdkWindow *window)
7533 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7535 return window->input_only;
7539 * gdk_window_is_shaped:
7540 * @window: a toplevel #GdkWindow
7542 * Determines whether or not the window is shaped.
7544 * Return value: %TRUE if @window is shaped
7549 gdk_window_is_shaped (GdkWindow *window)
7551 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7553 return window->shaped;
7557 window_get_size_rectangle (GdkWindow *window,
7560 rect->x = rect->y = 0;
7561 rect->width = window->width;
7562 rect->height = window->height;
7565 /* Calculates the real clipping region for a window, in window coordinates,
7566 * taking into account other windows, gc clip region and gc clip mask.
7569 _gdk_window_calculate_full_clip_region (GdkWindow *window,
7570 GdkWindow *base_window,
7571 gboolean do_children,
7572 gint *base_x_offset,
7573 gint *base_y_offset)
7575 GdkRectangle visible_rect;
7576 cairo_region_t *real_clip_region;
7577 gint x_offset, y_offset;
7578 GdkWindow *parentwin, *lastwin;
7585 if (!window->viewable || window->input_only)
7586 return cairo_region_create ();
7588 window_get_size_rectangle (window, &visible_rect);
7590 /* real_clip_region is in window coordinates */
7591 real_clip_region = cairo_region_create_rectangle (&visible_rect);
7593 x_offset = y_offset = 0;
7597 parentwin = lastwin;
7599 parentwin = lastwin->parent;
7601 /* Remove the areas of all overlapping windows above parentwin in the hiearachy */
7602 for (; parentwin != NULL &&
7603 (parentwin == window || lastwin != base_window);
7604 lastwin = parentwin, parentwin = lastwin->parent)
7607 GdkRectangle real_clip_rect;
7609 if (parentwin != window)
7611 x_offset += lastwin->x;
7612 y_offset += lastwin->y;
7615 /* children is ordered in reverse stack order */
7616 for (cur = parentwin->children;
7617 cur && cur->data != lastwin;
7620 GdkWindow *child = cur->data;
7622 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
7625 /* Ignore offscreen children, as they don't draw in their parent and
7626 * don't take part in the clipping */
7627 if (gdk_window_is_offscreen (child))
7630 window_get_size_rectangle (child, &visible_rect);
7632 /* Convert rect to "window" coords */
7633 visible_rect.x += child->x - x_offset;
7634 visible_rect.y += child->y - y_offset;
7636 /* This shortcut is really necessary for performance when there are a lot of windows */
7637 cairo_region_get_extents (real_clip_region, &real_clip_rect);
7638 if (visible_rect.x >= real_clip_rect.x + real_clip_rect.width ||
7639 visible_rect.x + visible_rect.width <= real_clip_rect.x ||
7640 visible_rect.y >= real_clip_rect.y + real_clip_rect.height ||
7641 visible_rect.y + visible_rect.height <= real_clip_rect.y)
7644 cairo_region_subtract_rectangle (real_clip_region, &visible_rect);
7647 /* Clip to the parent */
7648 window_get_size_rectangle ((GdkWindow *)parentwin, &visible_rect);
7649 /* Convert rect to "window" coords */
7650 visible_rect.x += - x_offset;
7651 visible_rect.y += - y_offset;
7653 cairo_region_intersect_rectangle (real_clip_region, &visible_rect);
7657 *base_x_offset = x_offset;
7659 *base_y_offset = y_offset;
7661 return real_clip_region;
7665 _gdk_window_add_damage (GdkWindow *toplevel,
7666 cairo_region_t *damaged_region)
7668 GdkDisplay *display;
7669 GdkEvent event = { 0, };
7670 event.expose.type = GDK_DAMAGE;
7671 event.expose.window = toplevel;
7672 event.expose.send_event = FALSE;
7673 event.expose.region = damaged_region;
7674 cairo_region_get_extents (event.expose.region, &event.expose.area);
7675 display = gdk_window_get_display (event.expose.window);
7676 _gdk_event_queue_append (display, gdk_event_copy (&event));
7679 /* Gets the toplevel for a window as used for events,
7680 i.e. including offscreen parents */
7682 get_event_parent (GdkWindow *window)
7684 if (gdk_window_is_offscreen (window))
7685 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7687 return window->parent;
7690 /* Gets the toplevel for a window as used for events,
7691 i.e. including offscreen parents going up to the native
7694 get_event_toplevel (GdkWindow *window)
7698 while ((parent = get_event_parent (window)) != NULL &&
7699 (parent->window_type != GDK_WINDOW_ROOT))
7706 _gdk_window_event_parent_of (GdkWindow *parent,
7717 w = get_event_parent (w);
7724 update_cursor (GdkDisplay *display,
7727 GdkWindow *cursor_window, *parent, *toplevel;
7728 GdkWindow *pointer_window;
7729 GdkWindowImplClass *impl_class;
7730 GdkPointerWindowInfo *pointer_info;
7731 GdkDeviceGrabInfo *grab;
7734 pointer_info = _gdk_display_get_pointer_info (display, device);
7735 pointer_window = pointer_info->window_under_pointer;
7737 /* We ignore the serials here and just pick the last grab
7738 we've sent, as that would shortly be used anyway. */
7739 grab = _gdk_display_get_last_device_grab (display, device);
7742 /* the pointer is not in a descendant of the grab window */
7743 !_gdk_window_event_parent_of (grab->window, pointer_window))
7745 /* use the cursor from the grab window */
7746 cursor_window = grab->window;
7750 /* otherwise use the cursor from the pointer window */
7751 cursor_window = pointer_window;
7754 /* Find the first window with the cursor actually set, as
7755 the cursor is inherited from the parent */
7756 while (cursor_window->cursor == NULL &&
7757 (parent = get_event_parent (cursor_window)) != NULL &&
7758 parent->window_type != GDK_WINDOW_ROOT)
7759 cursor_window = parent;
7761 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7764 cursor = cursor_window->cursor;
7766 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7767 * which native window has what cursor set. */
7768 toplevel = get_event_toplevel (pointer_window);
7769 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7770 impl_class->set_device_cursor (toplevel, device, cursor);
7774 point_in_window (GdkWindow *window,
7779 x >= 0 && x < window->width &&
7780 y >= 0 && y < window->height &&
7781 (window->shape == NULL ||
7782 cairo_region_contains_point (window->shape,
7784 (window->input_shape == NULL ||
7785 cairo_region_contains_point (window->input_shape,
7790 convert_native_coords_to_toplevel (GdkWindow *window,
7793 gdouble *toplevel_x,
7794 gdouble *toplevel_y)
7801 while (!gdk_window_is_toplevel (window))
7805 window = window->parent;
7815 convert_toplevel_coords_to_window (GdkWindow *window,
7823 GList *children, *l;
7829 while ((parent = get_event_parent (window)) != NULL &&
7830 (parent->window_type != GDK_WINDOW_ROOT))
7832 children = g_list_prepend (children, window);
7836 for (l = children; l != NULL; l = l->next)
7837 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7839 g_list_free (children);
7846 pick_embedded_child (GdkWindow *window,
7853 g_signal_emit (window,
7854 signals[PICK_EMBEDDED_CHILD], 0,
7861 _gdk_window_find_child_at (GdkWindow *window,
7866 double child_x, child_y;
7869 if (point_in_window (window, x, y))
7871 /* Children is ordered in reverse stack order, i.e. first is topmost */
7872 for (l = window->children; l != NULL; l = l->next)
7876 if (!GDK_WINDOW_IS_MAPPED (sub))
7879 gdk_window_coords_from_parent ((GdkWindow *)sub,
7881 &child_x, &child_y);
7882 if (point_in_window (sub, child_x, child_y))
7883 return (GdkWindow *)sub;
7886 if (window->num_offscreen_children > 0)
7888 sub = pick_embedded_child (window,
7891 return (GdkWindow *)sub;
7899 _gdk_window_find_descendant_at (GdkWindow *window,
7906 gdouble child_x, child_y;
7910 if (point_in_window (window, x, y))
7915 /* Children is ordered in reverse stack order, i.e. first is topmost */
7916 for (l = window->children; l != NULL; l = l->next)
7920 if (!GDK_WINDOW_IS_MAPPED (sub))
7923 gdk_window_coords_from_parent ((GdkWindow *)sub,
7925 &child_x, &child_y);
7926 if (point_in_window (sub, child_x, child_y))
7936 window->num_offscreen_children > 0)
7938 sub = pick_embedded_child (window,
7944 from_embedder (sub, x, y, &x, &y);
7952 /* Not in window at all */
7966 * @window: a toplevel #GdkWindow
7968 * Emits a short beep associated to @window in the appropriate
7969 * display, if supported. Otherwise, emits a short beep on
7970 * the display just as gdk_display_beep().
7975 gdk_window_beep (GdkWindow *window)
7977 GdkDisplay *display;
7978 GdkWindow *toplevel;
7980 g_return_if_fail (GDK_IS_WINDOW (window));
7982 if (GDK_WINDOW_DESTROYED (window))
7985 toplevel = get_event_toplevel (window);
7986 display = gdk_window_get_display (window);
7990 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
7994 /* If windows fail to beep, we beep the display. */
7995 gdk_display_beep (display);
7999 * gdk_window_set_support_multidevice:
8000 * @window: a #GdkWindow.
8001 * @support_multidevice: %TRUE to enable multidevice support in @window.
8003 * This function will enable multidevice features in @window.
8005 * Multidevice aware windows will need to handle properly multiple,
8006 * per device enter/leave events, device grabs and grab ownerships.
8011 gdk_window_set_support_multidevice (GdkWindow *window,
8012 gboolean support_multidevice)
8014 g_return_if_fail (GDK_IS_WINDOW (window));
8016 if (GDK_WINDOW_DESTROYED (window))
8019 if (window->support_multidevice == support_multidevice)
8022 window->support_multidevice = support_multidevice;
8024 /* FIXME: What to do if called when some pointers are inside the window ? */
8028 * gdk_window_get_support_multidevice:
8029 * @window: a #GdkWindow.
8031 * Returns %TRUE if the window is aware of the existence of multiple
8034 * Returns: %TRUE if the window handles multidevice features.
8039 gdk_window_get_support_multidevice (GdkWindow *window)
8041 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8043 if (GDK_WINDOW_DESTROYED (window))
8046 return window->support_multidevice;
8049 static const guint type_masks[] = {
8050 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8051 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8052 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8053 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8054 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8055 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8056 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8057 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8058 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8059 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8060 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8061 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8062 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8063 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8064 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8065 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8066 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8067 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8068 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8069 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8070 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8071 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8072 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8073 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8074 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8075 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8076 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8077 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8078 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8079 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8080 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8081 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8082 0, /* GDK_WINDOW_STATE = 32 */
8083 0, /* GDK_SETTING = 33 */
8084 0, /* GDK_OWNER_CHANGE = 34 */
8085 0, /* GDK_GRAB_BROKEN = 35 */
8086 0, /* GDK_DAMAGE = 36 */
8088 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8090 /* send motion events if the right buttons are down */
8092 update_evmask_for_button_motion (guint evmask,
8093 GdkModifierType mask)
8095 if (evmask & GDK_BUTTON_MOTION_MASK &&
8096 mask & (GDK_BUTTON1_MASK |
8101 evmask |= GDK_POINTER_MOTION_MASK;
8103 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8104 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8105 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8106 evmask |= GDK_POINTER_MOTION_MASK;
8112 is_button_type (GdkEventType type)
8114 return type == GDK_BUTTON_PRESS ||
8115 type == GDK_2BUTTON_PRESS ||
8116 type == GDK_3BUTTON_PRESS ||
8117 type == GDK_BUTTON_RELEASE ||
8122 is_motion_type (GdkEventType type)
8124 return type == GDK_MOTION_NOTIFY ||
8125 type == GDK_ENTER_NOTIFY ||
8126 type == GDK_LEAVE_NOTIFY;
8130 find_common_ancestor (GdkWindow *win1,
8134 GList *path1 = NULL, *path2 = NULL;
8135 GList *list1, *list2;
8138 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8140 path1 = g_list_prepend (path1, tmp);
8141 tmp = get_event_parent (tmp);
8145 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8147 path2 = g_list_prepend (path2, tmp);
8148 tmp = get_event_parent (tmp);
8154 while (list1 && list2 && (list1->data == list2->data))
8157 list1 = g_list_next (list1);
8158 list2 = g_list_next (list2);
8160 g_list_free (path1);
8161 g_list_free (path2);
8167 _gdk_make_event (GdkWindow *window,
8169 GdkEvent *event_in_queue,
8170 gboolean before_event)
8172 GdkEvent *event = gdk_event_new (type);
8174 GdkModifierType the_state;
8176 the_time = gdk_event_get_time (event_in_queue);
8177 gdk_event_get_state (event_in_queue, &the_state);
8179 event->any.window = g_object_ref (window);
8180 event->any.send_event = FALSE;
8181 if (event_in_queue && event_in_queue->any.send_event)
8182 event->any.send_event = TRUE;
8186 case GDK_MOTION_NOTIFY:
8187 event->motion.time = the_time;
8188 event->motion.axes = NULL;
8189 event->motion.state = the_state;
8192 case GDK_BUTTON_PRESS:
8193 case GDK_2BUTTON_PRESS:
8194 case GDK_3BUTTON_PRESS:
8195 case GDK_BUTTON_RELEASE:
8196 event->button.time = the_time;
8197 event->button.axes = NULL;
8198 event->button.state = the_state;
8202 event->scroll.time = the_time;
8203 event->scroll.state = the_state;
8207 case GDK_KEY_RELEASE:
8208 event->key.time = the_time;
8209 event->key.state = the_state;
8212 case GDK_ENTER_NOTIFY:
8213 case GDK_LEAVE_NOTIFY:
8214 event->crossing.time = the_time;
8215 event->crossing.state = the_state;
8218 case GDK_PROPERTY_NOTIFY:
8219 event->property.time = the_time;
8220 event->property.state = the_state;
8223 case GDK_SELECTION_CLEAR:
8224 case GDK_SELECTION_REQUEST:
8225 case GDK_SELECTION_NOTIFY:
8226 event->selection.time = the_time;
8229 case GDK_PROXIMITY_IN:
8230 case GDK_PROXIMITY_OUT:
8231 event->proximity.time = the_time;
8234 case GDK_DRAG_ENTER:
8235 case GDK_DRAG_LEAVE:
8236 case GDK_DRAG_MOTION:
8237 case GDK_DRAG_STATUS:
8238 case GDK_DROP_START:
8239 case GDK_DROP_FINISHED:
8240 event->dnd.time = the_time;
8243 case GDK_FOCUS_CHANGE:
8247 case GDK_CLIENT_EVENT:
8248 case GDK_VISIBILITY_NOTIFY:
8259 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8261 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8264 _gdk_event_queue_append (gdk_window_get_display (window), event);
8270 send_crossing_event (GdkDisplay *display,
8271 GdkWindow *toplevel,
8274 GdkCrossingMode mode,
8275 GdkNotifyType notify_type,
8276 GdkWindow *subwindow,
8278 GdkDevice *source_device,
8281 GdkModifierType mask,
8283 GdkEvent *event_in_queue,
8287 guint32 window_event_mask, type_event_mask;
8288 GdkDeviceGrabInfo *grab;
8289 gboolean block_event = FALSE;
8291 grab = _gdk_display_has_device_grab (display, device, serial);
8294 !grab->owner_events)
8296 /* !owner_event => only report events wrt grab window, ignore rest */
8297 if ((GdkWindow *)window != grab->window)
8299 window_event_mask = grab->event_mask;
8302 window_event_mask = window->event_mask;
8304 if (type == GDK_LEAVE_NOTIFY)
8306 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8307 window->devices_inside = g_list_remove (window->devices_inside, device);
8309 if (!window->support_multidevice && window->devices_inside)
8311 /* Block leave events unless it's the last pointer */
8317 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8319 if (!window->support_multidevice && window->devices_inside)
8321 /* Only emit enter events for the first device */
8325 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8326 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8327 !g_list_find (window->devices_inside, device))
8328 window->devices_inside = g_list_prepend (window->devices_inside, device);
8334 if (window_event_mask & type_event_mask)
8336 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8337 gdk_event_set_device (event, device);
8340 gdk_event_set_source_device (event, source_device);
8342 event->crossing.time = time_;
8343 event->crossing.subwindow = subwindow;
8345 g_object_ref (subwindow);
8346 convert_toplevel_coords_to_window ((GdkWindow *)window,
8347 toplevel_x, toplevel_y,
8348 &event->crossing.x, &event->crossing.y);
8349 event->crossing.x_root = toplevel_x + toplevel->x;
8350 event->crossing.y_root = toplevel_y + toplevel->y;
8351 event->crossing.mode = mode;
8352 event->crossing.detail = notify_type;
8353 event->crossing.focus = FALSE;
8354 event->crossing.state = mask;
8359 /* The coordinates are in the toplevel window that src/dest are in.
8360 * src and dest are always (if != NULL) in the same toplevel, as
8361 * we get a leave-notify and set the window_under_pointer to null
8362 * before crossing to another toplevel.
8365 _gdk_synthesize_crossing_events (GdkDisplay *display,
8369 GdkDevice *source_device,
8370 GdkCrossingMode mode,
8373 GdkModifierType mask,
8375 GdkEvent *event_in_queue,
8377 gboolean non_linear)
8380 GdkWindow *win, *last, *next;
8384 GdkWindow *toplevel;
8385 GdkNotifyType notify_type;
8387 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8392 return; /* No crossings generated between src and dest */
8394 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8396 if (a && gdk_window_get_device_events (src, device) == 0)
8399 if (b && gdk_window_get_device_events (dest, device) == 0)
8406 c = find_common_ancestor (a, b);
8408 non_linear |= (c != a) && (c != b);
8410 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8412 toplevel = gdk_window_get_toplevel (a);
8414 /* Traverse up from a to (excluding) c sending leave events */
8416 notify_type = GDK_NOTIFY_NONLINEAR;
8418 notify_type = GDK_NOTIFY_INFERIOR;
8420 notify_type = GDK_NOTIFY_ANCESTOR;
8421 send_crossing_event (display, toplevel,
8422 a, GDK_LEAVE_NOTIFY,
8425 NULL, device, source_device,
8426 toplevel_x, toplevel_y,
8434 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8436 notify_type = GDK_NOTIFY_VIRTUAL;
8439 win = get_event_parent (a);
8440 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8442 send_crossing_event (display, toplevel,
8443 win, GDK_LEAVE_NOTIFY,
8447 device, source_device,
8448 toplevel_x, toplevel_y,
8454 win = get_event_parent (win);
8459 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8461 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8463 /* Traverse down from c to b */
8467 win = get_event_parent (b);
8468 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8470 path = g_list_prepend (path, win);
8471 win = get_event_parent (win);
8475 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8477 notify_type = GDK_NOTIFY_VIRTUAL;
8483 list = g_list_next (list);
8489 send_crossing_event (display, toplevel,
8490 win, GDK_ENTER_NOTIFY,
8494 device, source_device,
8495 toplevel_x, toplevel_y,
8505 notify_type = GDK_NOTIFY_NONLINEAR;
8507 notify_type = GDK_NOTIFY_ANCESTOR;
8509 notify_type = GDK_NOTIFY_INFERIOR;
8511 send_crossing_event (display, toplevel,
8512 b, GDK_ENTER_NOTIFY,
8516 device, source_device,
8517 toplevel_x, toplevel_y,
8524 /* Returns the window inside the event window with the pointer in it
8525 * at the specified coordinates, or NULL if its not in any child of
8526 * the toplevel. It also takes into account !owner_events grabs.
8529 get_pointer_window (GdkDisplay *display,
8530 GdkWindow *event_window,
8536 GdkWindow *pointer_window;
8537 GdkDeviceGrabInfo *grab;
8538 GdkPointerWindowInfo *pointer_info;
8540 pointer_info = _gdk_display_get_pointer_info (display, device);
8542 if (event_window == pointer_info->toplevel_under_pointer)
8544 _gdk_window_find_descendant_at (event_window,
8545 toplevel_x, toplevel_y,
8548 pointer_window = NULL;
8550 grab = _gdk_display_has_device_grab (display, device, serial);
8552 !grab->owner_events &&
8553 pointer_window != grab->window)
8554 pointer_window = NULL;
8556 return pointer_window;
8560 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8564 GdkPointerWindowInfo *device_info;
8566 device_info = _gdk_display_get_pointer_info (display, device);
8568 if (device_info->window_under_pointer)
8569 g_object_unref (device_info->window_under_pointer);
8570 device_info->window_under_pointer = window;
8574 g_object_ref (window);
8575 update_cursor (display, device);
8578 _gdk_display_enable_motion_hints (display, device);
8583 * @window: the #GdkWindow which will own the grab (the grab window).
8584 * @owner_events: if %FALSE then all pointer events are reported with respect to
8585 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8586 * events for this application are reported as normal, but pointer events outside
8587 * this application are reported with respect to @window and only if selected by
8588 * @event_mask. In either mode, unreported events are discarded.
8589 * @event_mask: specifies the event mask, which is used in accordance with
8590 * @owner_events. Note that only pointer events (i.e. button and motion events)
8592 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8593 * window during the grab. If the pointer is outside @confine_to, it will
8594 * automatically be moved to the closest edge of @confine_to and enter
8595 * and leave events will be generated as necessary.
8596 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8597 * the normal cursors are used for @window and its descendants, and the cursor
8598 * for @window is used for all other windows.
8599 * @time_: the timestamp of the event which led to this pointer grab. This usually
8600 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8601 * the time isn't known.
8603 * Grabs the pointer (usually a mouse) so that all events are passed to this
8604 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8605 * the grab window becomes unviewable.
8606 * This overrides any previous pointer grab by this client.
8608 * Pointer grabs are used for operations which need complete control over mouse
8609 * events, even if the mouse leaves the application.
8610 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8611 * the #GtkHPaned and #GtkVPaned widgets.
8613 * Note that if the event mask of an X window has selected both button press and
8614 * button release events, then a button press event will cause an automatic
8615 * pointer grab until the button is released.
8616 * X does this automatically since most applications expect to receive button
8617 * press and release events in pairs.
8618 * It is equivalent to a pointer grab on the window with @owner_events set to
8621 * If you set up anything at the time you take the grab that needs to be cleaned
8622 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8623 * are emitted when the grab ends unvoluntarily.
8625 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8627 * Deprecated: 3.0: Use gdk_device_grab() instead.
8630 gdk_pointer_grab (GdkWindow * window,
8631 gboolean owner_events,
8632 GdkEventMask event_mask,
8633 GdkWindow * confine_to,
8638 GdkDisplay *display;
8639 GdkDeviceManager *device_manager;
8641 GdkGrabStatus res = 0;
8643 GList *devices, *dev;
8645 g_return_val_if_fail (window != NULL, 0);
8646 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8647 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8649 /* We need a native window for confine to to work, ensure we have one */
8652 if (!gdk_window_ensure_native (confine_to))
8654 g_warning ("Can't confine to grabbed window, not native");
8659 /* Non-viewable client side window => fail */
8660 if (!_gdk_window_has_impl (window) &&
8661 !gdk_window_is_viewable (window))
8662 return GDK_GRAB_NOT_VIEWABLE;
8664 native = gdk_window_get_toplevel (window);
8665 while (gdk_window_is_offscreen (native))
8667 native = gdk_offscreen_window_get_embedder (native);
8669 if (native == NULL ||
8670 (!_gdk_window_has_impl (native) &&
8671 !gdk_window_is_viewable (native)))
8672 return GDK_GRAB_NOT_VIEWABLE;
8674 native = gdk_window_get_toplevel (native);
8677 display = gdk_window_get_display (window);
8679 serial = _gdk_display_get_next_serial (display);
8680 device_manager = gdk_display_get_device_manager (display);
8681 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8683 /* FIXME: Should this be generic to all backends? */
8684 /* FIXME: What happens with extended devices? */
8685 for (dev = devices; dev; dev = dev->next)
8689 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8692 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8695 get_native_grab_event_mask (event_mask),
8700 if (res == GDK_GRAB_SUCCESS)
8701 _gdk_display_add_device_grab (display,
8713 /* FIXME: handle errors when grabbing */
8715 g_list_free (devices);
8721 * gdk_keyboard_grab:
8722 * @window: the #GdkWindow which will own the grab (the grab window).
8723 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8724 * @window. If %TRUE then keyboard events for this application are
8725 * reported as normal, but keyboard events outside this application
8726 * are reported with respect to @window. Both key press and key
8727 * release events are always reported, independant of the event mask
8728 * set by the application.
8729 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8732 * Grabs the keyboard so that all events are passed to this
8733 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8734 * This overrides any previous keyboard grab by this client.
8736 * If you set up anything at the time you take the grab that needs to be cleaned
8737 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8738 * are emitted when the grab ends unvoluntarily.
8740 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8742 * Deprecated: 3.0: Use gdk_device_grab() instead.
8745 gdk_keyboard_grab (GdkWindow *window,
8746 gboolean owner_events,
8750 GdkDisplay *display;
8751 GdkDeviceManager *device_manager;
8753 GdkGrabStatus res = 0;
8755 GList *devices, *dev;
8757 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8759 /* Non-viewable client side window => fail */
8760 if (!_gdk_window_has_impl (window) &&
8761 !gdk_window_is_viewable (window))
8762 return GDK_GRAB_NOT_VIEWABLE;
8764 native = gdk_window_get_toplevel (window);
8766 while (gdk_window_is_offscreen (native))
8768 native = gdk_offscreen_window_get_embedder (native);
8770 if (native == NULL ||
8771 (!_gdk_window_has_impl (native) &&
8772 !gdk_window_is_viewable (native)))
8773 return GDK_GRAB_NOT_VIEWABLE;
8775 native = gdk_window_get_toplevel (native);
8778 display = gdk_window_get_display (window);
8779 serial = _gdk_display_get_next_serial (display);
8780 device_manager = gdk_display_get_device_manager (display);
8781 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8783 /* FIXME: Should this be generic to all backends? */
8784 /* FIXME: What happens with extended devices? */
8785 for (dev = devices; dev; dev = dev->next)
8789 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8792 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8795 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8800 if (res == GDK_GRAB_SUCCESS)
8801 _gdk_display_add_device_grab (display,
8812 /* FIXME: handle errors when grabbing */
8814 g_list_free (devices);
8820 * gdk_window_geometry_changed:
8821 * @window: an embedded offscreen #GdkWindow
8823 * This function informs GDK that the geometry of an embedded
8824 * offscreen window has changed. This is necessary for GDK to keep
8825 * track of which offscreen window the pointer is in.
8830 gdk_window_geometry_changed (GdkWindow *window)
8832 _gdk_synthesize_crossing_events_for_geometry_change (window);
8836 source_events_device_added (GdkDeviceManager *device_manager,
8841 GdkEventMask event_mask;
8842 GdkInputSource source;
8844 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
8848 source = gdk_device_get_source (device);
8850 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8851 GINT_TO_POINTER (source)));
8853 gdk_window_set_device_events (window, device, event_mask);
8857 source_events_device_changed (GdkDeviceManager *device_manager,
8862 GdkInputSource source;
8863 GdkEventMask event_mask;
8867 type = gdk_device_get_device_type (device);
8868 source = gdk_device_get_source (device);
8870 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8871 GINT_TO_POINTER (source)));
8876 if (type == GDK_DEVICE_TYPE_FLOATING)
8878 /* The device was just floated, enable its event mask */
8879 gdk_window_set_device_events (window, device, event_mask);
8881 else if (type == GDK_DEVICE_TYPE_SLAVE)
8882 gdk_window_set_device_events (window, device, 0);
8886 * gdk_window_set_source_events:
8887 * @window: a #GdkWindow
8888 * @source: a #GdkInputSource to define the source class.
8889 * @event_mask: event mask for @window
8891 * Sets the event mask for any floating device (i.e. not attached to any
8892 * visible pointer) that has the source defined as @source. This event
8893 * mask will be applied both to currently existing, newly added devices
8894 * after this call, and devices being attached/detached.
8899 gdk_window_set_source_events (GdkWindow *window,
8900 GdkInputSource source,
8901 GdkEventMask event_mask)
8903 GdkDeviceManager *device_manager;
8904 GdkDisplay *display;
8908 g_return_if_fail (GDK_IS_WINDOW (window));
8910 display = gdk_window_get_display (window);
8911 device_manager = gdk_display_get_device_manager (display);
8913 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
8915 /* Set event mask for existing devices */
8916 for (d = devices; d; d = d->next)
8918 GdkDevice *device = d->data;
8920 if (source == gdk_device_get_source (device))
8921 gdk_window_set_device_events (window, device, event_mask);
8924 g_list_free (devices);
8926 /* Update accounting */
8927 if (G_UNLIKELY (!window->source_event_masks))
8928 window->source_event_masks = g_hash_table_new (NULL, NULL);
8931 g_hash_table_insert (window->source_event_masks,
8932 GUINT_TO_POINTER (source),
8933 GUINT_TO_POINTER (event_mask));
8935 g_hash_table_remove (window->source_event_masks,
8936 GUINT_TO_POINTER (source));
8938 size = g_hash_table_size (window->source_event_masks);
8940 /* Update handler if needed */
8941 if (!window->device_added_handler_id && size > 0)
8943 window->device_added_handler_id =
8944 g_signal_connect (device_manager, "device-added",
8945 G_CALLBACK (source_events_device_added), window);
8946 window->device_changed_handler_id =
8947 g_signal_connect (device_manager, "device-changed",
8948 G_CALLBACK (source_events_device_changed), window);
8950 else if (window->device_added_handler_id && size == 0)
8951 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
8955 * gdk_window_get_source_events:
8956 * @window: a #GdkWindow
8957 * @source: a #GdkInputSource to define the source class.
8959 * Returns the event mask for @window corresponding to the device class specified
8962 * Returns: source event mask for @window
8965 gdk_window_get_source_events (GdkWindow *window,
8966 GdkInputSource source)
8968 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8970 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
8971 GUINT_TO_POINTER (source)));
8975 do_synthesize_crossing_event (gpointer data)
8977 GdkDisplay *display;
8978 GdkWindow *changed_toplevel;
8979 GHashTableIter iter;
8980 gpointer key, value;
8983 changed_toplevel = data;
8985 changed_toplevel->synthesize_crossing_event_queued = FALSE;
8987 if (GDK_WINDOW_DESTROYED (changed_toplevel))
8990 display = gdk_window_get_display (changed_toplevel);
8991 serial = _gdk_display_get_next_serial (display);
8992 g_hash_table_iter_init (&iter, display->pointers_info);
8994 while (g_hash_table_iter_next (&iter, &key, &value))
8996 GdkWindow *new_window_under_pointer;
8997 GdkPointerWindowInfo *pointer_info = value;
8998 GdkDevice *device = key;
9000 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9002 new_window_under_pointer =
9003 get_pointer_window (display, changed_toplevel,
9005 pointer_info->toplevel_x,
9006 pointer_info->toplevel_y,
9008 if (new_window_under_pointer != pointer_info->window_under_pointer)
9010 _gdk_synthesize_crossing_events (display,
9011 pointer_info->window_under_pointer,
9012 new_window_under_pointer,
9014 GDK_CROSSING_NORMAL,
9015 pointer_info->toplevel_x,
9016 pointer_info->toplevel_y,
9017 pointer_info->state,
9022 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9031 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9033 GdkWindow *toplevel;
9035 toplevel = get_event_toplevel (changed_window);
9037 if (!toplevel->synthesize_crossing_event_queued)
9039 toplevel->synthesize_crossing_event_queued = TRUE;
9041 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9042 do_synthesize_crossing_event,
9043 g_object_ref (toplevel),
9048 /* Don't use for crossing events */
9050 get_event_window (GdkDisplay *display,
9052 GdkWindow *pointer_window,
9054 GdkModifierType mask,
9059 GdkWindow *grab_window;
9060 GdkDeviceGrabInfo *grab;
9062 grab = _gdk_display_has_device_grab (display, device, serial);
9064 if (grab != NULL && !grab->owner_events)
9066 evmask = grab->event_mask;
9067 evmask = update_evmask_for_button_motion (evmask, mask);
9069 grab_window = grab->window;
9071 if (evmask & type_masks[type])
9074 *evmask_out = evmask;
9081 while (pointer_window != NULL)
9083 evmask = pointer_window->event_mask;
9084 evmask = update_evmask_for_button_motion (evmask, mask);
9086 if (evmask & type_masks[type])
9089 *evmask_out = evmask;
9090 return pointer_window;
9093 pointer_window = get_event_parent (pointer_window);
9099 evmask = grab->event_mask;
9100 evmask = update_evmask_for_button_motion (evmask, mask);
9102 if (evmask & type_masks[type])
9105 *evmask_out = evmask;
9106 return grab->window;
9116 proxy_pointer_event (GdkDisplay *display,
9117 GdkEvent *source_event,
9120 GdkWindow *toplevel_window, *event_window;
9121 GdkWindow *pointer_window;
9122 GdkPointerWindowInfo *pointer_info;
9123 GdkDevice *device, *source_device;
9126 gdouble toplevel_x, toplevel_y;
9128 gboolean non_linear;
9130 event_window = source_event->any.window;
9131 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9132 gdk_event_get_state (source_event, &state);
9133 time_ = gdk_event_get_time (source_event);
9134 device = gdk_event_get_device (source_event);
9135 source_device = gdk_event_get_source_device (source_event);
9136 pointer_info = _gdk_display_get_pointer_info (display, device);
9137 toplevel_window = convert_native_coords_to_toplevel (event_window,
9138 toplevel_x, toplevel_y,
9139 &toplevel_x, &toplevel_y);
9142 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9143 source_event->type == GDK_ENTER_NOTIFY) &&
9144 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9145 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9148 /* If we get crossing events with subwindow unexpectedly being NULL
9149 that means there is a native subwindow that gdk doesn't know about.
9150 We track these and forward them, with the correct virtual window
9152 This is important to get right, as metacity uses gdk for the frame
9153 windows, but gdk doesn't know about the client windows reparented
9155 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9156 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9157 (source_event->type == GDK_ENTER_NOTIFY &&
9158 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9159 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9160 source_event->crossing.subwindow == NULL)
9162 /* Left for an unknown (to gdk) subwindow */
9164 /* Send leave events from window under pointer to event window
9165 that will get the subwindow == NULL window */
9166 _gdk_synthesize_crossing_events (display,
9167 pointer_info->window_under_pointer,
9169 device, source_device,
9170 source_event->crossing.mode,
9171 toplevel_x, toplevel_y,
9177 /* Send subwindow == NULL event */
9178 send_crossing_event (display,
9182 source_event->crossing.mode,
9183 source_event->crossing.detail,
9185 device, source_device,
9186 toplevel_x, toplevel_y,
9191 _gdk_display_set_window_under_pointer (display, device, NULL);
9195 pointer_window = get_pointer_window (display, toplevel_window, device,
9196 toplevel_x, toplevel_y, serial);
9198 if (((source_event->type == GDK_ENTER_NOTIFY &&
9199 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9200 (source_event->type == GDK_LEAVE_NOTIFY &&
9201 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9202 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9203 source_event->crossing.subwindow == NULL)
9205 /* Entered from an unknown (to gdk) subwindow */
9207 /* Send subwindow == NULL event */
9208 send_crossing_event (display,
9212 source_event->crossing.mode,
9213 source_event->crossing.detail,
9215 device, source_device,
9216 toplevel_x, toplevel_y,
9221 /* Send enter events from event window to pointer_window */
9222 _gdk_synthesize_crossing_events (display,
9225 device, source_device,
9226 source_event->crossing.mode,
9227 toplevel_x, toplevel_y,
9230 serial, non_linear);
9231 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9235 if (pointer_info->window_under_pointer != pointer_window)
9237 /* Either a toplevel crossing notify that ended up inside a child window,
9238 or a motion notify that got into another child window */
9240 /* Different than last time, send crossing events */
9241 _gdk_synthesize_crossing_events (display,
9242 pointer_info->window_under_pointer,
9244 device, source_device,
9245 GDK_CROSSING_NORMAL,
9246 toplevel_x, toplevel_y,
9249 serial, non_linear);
9250 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9252 else if (source_event->type == GDK_MOTION_NOTIFY)
9254 GdkWindow *event_win;
9258 event_win = get_event_window (display,
9267 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9268 gdk_window_get_device_events (event_win, device) == 0)
9274 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9276 gulong *device_serial;
9278 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9280 if (!device_serial ||
9281 (*device_serial != 0 &&
9282 serial < *device_serial))
9283 event_win = NULL; /* Ignore event */
9287 *device_serial = G_MAXULONG;
9291 if (event_win && !display->ignore_core_events)
9293 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9294 event->motion.time = time_;
9295 convert_toplevel_coords_to_window (event_win,
9296 toplevel_x, toplevel_y,
9297 &event->motion.x, &event->motion.y);
9298 event->motion.x_root = source_event->motion.x_root;
9299 event->motion.y_root = source_event->motion.y_root;
9300 event->motion.state = state;
9301 event->motion.is_hint = is_hint;
9302 event->motion.device = source_event->motion.device;
9303 event->motion.axes = g_memdup (source_event->motion.axes,
9304 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9305 gdk_event_set_source_device (event, source_device);
9309 /* unlink all move events from queue.
9310 We handle our own, including our emulated masks. */
9314 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9315 GDK_BUTTON2_MASK | \
9316 GDK_BUTTON3_MASK | \
9317 GDK_BUTTON4_MASK | \
9321 proxy_button_event (GdkEvent *source_event,
9324 GdkWindow *toplevel_window, *event_window;
9325 GdkWindow *event_win;
9326 GdkWindow *pointer_window;
9332 gdouble toplevel_x, toplevel_y;
9333 GdkDisplay *display;
9335 GdkDevice *device, *source_device;
9337 type = source_event->any.type;
9338 event_window = source_event->any.window;
9339 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9340 gdk_event_get_state (source_event, &state);
9341 time_ = gdk_event_get_time (source_event);
9342 device = gdk_event_get_device (source_event);
9343 source_device = gdk_event_get_source_device (source_event);
9344 display = gdk_window_get_display (source_event->any.window);
9345 toplevel_window = convert_native_coords_to_toplevel (event_window,
9346 toplevel_x, toplevel_y,
9347 &toplevel_x, &toplevel_y);
9349 if (type == GDK_BUTTON_PRESS &&
9350 !source_event->any.send_event &&
9351 _gdk_display_has_device_grab (display, device, serial) == NULL)
9354 _gdk_window_find_descendant_at (toplevel_window,
9355 toplevel_x, toplevel_y,
9358 /* Find the event window, that gets the grab */
9361 (parent = get_event_parent (w)) != NULL &&
9362 parent->window_type != GDK_WINDOW_ROOT)
9364 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9368 pointer_window = (GdkWindow *)w;
9370 _gdk_display_add_device_grab (display,
9376 gdk_window_get_events (pointer_window),
9380 _gdk_display_device_grab_update (display, device, source_device, serial);
9383 pointer_window = get_pointer_window (display, toplevel_window, device,
9384 toplevel_x, toplevel_y,
9387 event_win = get_event_window (display,
9393 if (event_win == NULL || display->ignore_core_events)
9396 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9397 gdk_window_get_device_events (event_win, device) == 0)
9400 event = _gdk_make_event (event_win, type, source_event, FALSE);
9404 case GDK_BUTTON_PRESS:
9405 case GDK_BUTTON_RELEASE:
9406 event->button.button = source_event->button.button;
9407 convert_toplevel_coords_to_window (event_win,
9408 toplevel_x, toplevel_y,
9409 &event->button.x, &event->button.y);
9410 event->button.x_root = source_event->button.x_root;
9411 event->button.y_root = source_event->button.y_root;
9412 event->button.state = state;
9413 event->button.device = source_event->button.device;
9414 event->button.axes = g_memdup (source_event->button.axes,
9415 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9417 gdk_event_set_source_device (event, source_device);
9419 if (type == GDK_BUTTON_PRESS)
9420 _gdk_event_button_generate (display, event);
9424 event->scroll.direction = source_event->scroll.direction;
9425 convert_toplevel_coords_to_window (event_win,
9426 toplevel_x, toplevel_y,
9427 &event->scroll.x, &event->scroll.y);
9428 event->scroll.x_root = source_event->scroll.x_root;
9429 event->scroll.y_root = source_event->scroll.y_root;
9430 event->scroll.state = state;
9431 event->scroll.device = source_event->scroll.device;
9432 gdk_event_set_source_device (event, source_device);
9439 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9442 #ifdef DEBUG_WINDOW_PRINTING
9444 gdk_window_print (GdkWindow *window,
9448 const char *window_types[] = {
9458 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9459 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9460 window->x, window->y,
9461 window->width, window->height
9464 if (gdk_window_has_impl (window))
9466 #ifdef GDK_WINDOWING_X11
9467 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9471 if (window->window_type != GDK_WINDOW_CHILD)
9472 g_print (" %s", window_types[window->window_type]);
9474 if (window->input_only)
9475 g_print (" input-only");
9478 g_print (" shaped");
9480 if (!gdk_window_is_visible ((GdkWindow *)window))
9481 g_print (" hidden");
9483 g_print (" abs[%d,%d]",
9484 window->abs_x, window->abs_y);
9486 cairo_region_get_extents (window->clip_region, &r);
9487 if (cairo_region_is_empty (window->clip_region))
9488 g_print (" clipbox[empty]");
9490 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9497 gdk_window_print_tree (GdkWindow *window,
9499 gboolean include_input_only)
9503 if (window->input_only && !include_input_only)
9506 gdk_window_print (window, indent);
9508 for (l = window->children; l != NULL; l = l->next)
9509 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9512 #endif /* DEBUG_WINDOW_PRINTING */
9515 _gdk_windowing_got_event (GdkDisplay *display,
9520 GdkWindow *event_window;
9522 gboolean unlink_event;
9523 guint old_state, old_button;
9524 GdkDeviceGrabInfo *button_release_grab;
9525 GdkPointerWindowInfo *pointer_info;
9526 GdkDevice *device, *source_device;
9527 gboolean is_toplevel;
9529 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9530 display->last_event_time = gdk_event_get_time (event);
9532 device = gdk_event_get_device (event);
9533 source_device = gdk_event_get_source_device (event);
9539 g_object_get (device, "input-mode", &mode, NULL);
9540 _gdk_display_device_grab_update (display, device, source_device, serial);
9542 if (mode == GDK_MODE_DISABLED ||
9543 !_gdk_display_check_grab_ownership (display, device, serial))
9545 /* Device events are blocked by another
9546 * device grab, or the device is disabled
9548 unlink_event = TRUE;
9553 event_window = event->any.window;
9557 pointer_info = _gdk_display_get_pointer_info (display, device);
9559 #ifdef DEBUG_WINDOW_PRINTING
9560 if (event->type == GDK_KEY_PRESS &&
9561 (event->key.keyval == 0xa7 ||
9562 event->key.keyval == 0xbd))
9564 gdk_window_print_tree (event_window, 0,
9565 event->key.keyval == 0xbd);
9569 if (event->type == GDK_VISIBILITY_NOTIFY)
9571 event_window->native_visibility = event->visibility.state;
9572 gdk_window_update_visibility_recursively (event_window,
9577 if (!(is_button_type (event->type) ||
9578 is_motion_type (event->type)) ||
9579 event_window->window_type == GDK_WINDOW_ROOT)
9582 is_toplevel = gdk_window_is_toplevel (event_window);
9584 if ((event->type == GDK_ENTER_NOTIFY ||
9585 event->type == GDK_LEAVE_NOTIFY) &&
9586 (event->crossing.mode == GDK_CROSSING_GRAB ||
9587 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9588 (_gdk_display_has_device_grab (display, device, serial) ||
9589 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9591 /* We synthesize all crossing events due to grabs ourselves,
9592 * so we ignore the native ones caused by our native pointer_grab
9593 * calls. Otherwise we would proxy these crossing event and cause
9594 * multiple copies of crossing events for grabs.
9596 * We do want to handle grabs from other clients though, as for
9597 * instance alt-tab in metacity causes grabs like these and
9598 * we want to handle those. Thus the has_pointer_grab check.
9600 * Implicit grabs on child windows create some grabbing events
9601 * that are sent before the button press. This means we can't
9602 * detect these with the has_pointer_grab check (as the implicit
9603 * grab is only noticed when we get button press event), so we
9604 * detect these events by checking for INFERIOR enter or leave
9605 * events. These should never be a problem to filter out.
9608 /* We ended up in this window after some (perhaps other clients)
9609 grab, so update the toplevel_under_window state */
9611 event->type == GDK_ENTER_NOTIFY &&
9612 event->crossing.mode == GDK_CROSSING_UNGRAB)
9614 if (pointer_info->toplevel_under_pointer)
9615 g_object_unref (pointer_info->toplevel_under_pointer);
9616 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9619 unlink_event = TRUE;
9623 /* Track toplevel_under_pointer */
9626 if (event->type == GDK_ENTER_NOTIFY &&
9627 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9629 if (pointer_info->toplevel_under_pointer)
9630 g_object_unref (pointer_info->toplevel_under_pointer);
9631 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9633 else if (event->type == GDK_LEAVE_NOTIFY &&
9634 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9635 pointer_info->toplevel_under_pointer == event_window)
9637 if (pointer_info->toplevel_under_pointer)
9638 g_object_unref (pointer_info->toplevel_under_pointer);
9639 pointer_info->toplevel_under_pointer = NULL;
9643 /* Store last pointer window and position/state */
9644 old_state = pointer_info->state;
9645 old_button = pointer_info->button;
9647 gdk_event_get_coords (event, &x, &y);
9648 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9649 pointer_info->toplevel_x = x;
9650 pointer_info->toplevel_y = y;
9651 gdk_event_get_state (event, &pointer_info->state);
9652 if (event->type == GDK_BUTTON_PRESS ||
9653 event->type == GDK_BUTTON_RELEASE)
9654 pointer_info->button = event->button.button;
9657 (pointer_info->state != old_state ||
9658 pointer_info->button != old_button))
9659 _gdk_display_enable_motion_hints (display, device);
9661 unlink_event = FALSE;
9662 if (is_motion_type (event->type))
9663 unlink_event = proxy_pointer_event (display,
9666 else if (is_button_type (event->type))
9667 unlink_event = proxy_button_event (event,
9670 if (event->type == GDK_BUTTON_RELEASE &&
9671 !event->any.send_event)
9673 button_release_grab =
9674 _gdk_display_has_device_grab (display, device, serial);
9675 if (button_release_grab &&
9676 button_release_grab->implicit &&
9677 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9679 button_release_grab->serial_end = serial;
9680 button_release_grab->implicit_ungrab = FALSE;
9681 _gdk_display_device_grab_update (display, device, source_device, serial);
9688 _gdk_event_queue_remove_link (display, event_link);
9689 g_list_free_1 (event_link);
9690 gdk_event_free (event);
9695 * gdk_window_create_similar_surface:
9696 * @window: window to make new surface similar to
9697 * @content: the content for the new surface
9698 * @width: width of the new surface
9699 * @height: height of the new surface
9701 * Create a new surface that is as compatible as possible with the
9702 * given @window. For example the new surface will have the same
9703 * fallback resolution and font options as @window. Generally, the new
9704 * surface will also use the same backend as @window, unless that is
9705 * not possible for some reason. The type of the returned surface may
9706 * be examined with cairo_surface_get_type().
9708 * Initially the surface contents are all 0 (transparent if contents
9709 * have transparency, black otherwise.)
9711 * Returns: a pointer to the newly allocated surface. The caller
9712 * owns the surface and should call cairo_surface_destroy() when done
9715 * This function always returns a valid pointer, but it will return a
9716 * pointer to a "nil" surface if @other is already in an error state
9717 * or any other error occurs.
9722 gdk_window_create_similar_surface (GdkWindow * window,
9723 cairo_content_t content,
9727 cairo_surface_t *window_surface, *surface;
9729 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9731 window_surface = _gdk_window_ref_cairo_surface (window);
9733 switch (_gdk_rendering_mode)
9735 case GDK_RENDERING_MODE_RECORDING:
9737 cairo_rectangle_t rect = { 0, 0, width, height };
9738 surface = cairo_recording_surface_create (content, &rect);
9741 case GDK_RENDERING_MODE_IMAGE:
9742 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
9743 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
9746 case GDK_RENDERING_MODE_SIMILAR:
9748 surface = cairo_surface_create_similar (window_surface,
9754 cairo_surface_destroy (window_surface);
9761 * @window: a #GdkWindow
9762 * @timestamp: timestamp of the event triggering the window focus
9764 * Sets keyboard focus to @window. In most cases, gtk_window_present()
9765 * should be used on a #GtkWindow, rather than calling this function.
9769 gdk_window_focus (GdkWindow *window,
9772 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
9776 * gdk_window_set_type_hint:
9777 * @window: A toplevel #GdkWindow
9778 * @hint: A hint of the function this window will have
9780 * The application can use this call to provide a hint to the window
9781 * manager about the functionality of a window. The window manager
9782 * can use this information when determining the decoration and behaviour
9785 * The hint must be set before the window is mapped.
9788 gdk_window_set_type_hint (GdkWindow *window,
9789 GdkWindowTypeHint hint)
9791 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
9795 * gdk_window_get_type_hint:
9796 * @window: A toplevel #GdkWindow
9798 * This function returns the type hint set for a window.
9800 * Return value: The type hint set for @window
9805 gdk_window_get_type_hint (GdkWindow *window)
9807 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
9811 * gdk_window_set_modal_hint:
9812 * @window: A toplevel #GdkWindow
9813 * @modal: %TRUE if the window is modal, %FALSE otherwise.
9815 * The application can use this hint to tell the window manager
9816 * that a certain window has modal behaviour. The window manager
9817 * can use this information to handle modal windows in a special
9820 * You should only use this on windows for which you have
9821 * previously called gdk_window_set_transient_for()
9824 gdk_window_set_modal_hint (GdkWindow *window,
9827 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
9831 * gdk_window_set_skip_taskbar_hint:
9832 * @window: a toplevel #GdkWindow
9833 * @skips_taskbar: %TRUE to skip the taskbar
9835 * Toggles whether a window should appear in a task list or window
9836 * list. If a window's semantic type as specified with
9837 * gdk_window_set_type_hint() already fully describes the window, this
9838 * function should <emphasis>not</emphasis> be called in addition,
9839 * instead you should allow the window to be treated according to
9840 * standard policy for its semantic type.
9845 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
9846 gboolean skips_taskbar)
9848 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
9852 * gdk_window_set_skip_pager_hint:
9853 * @window: a toplevel #GdkWindow
9854 * @skips_pager: %TRUE to skip the pager
9856 * Toggles whether a window should appear in a pager (workspace
9857 * switcher, or other desktop utility program that displays a small
9858 * thumbnail representation of the windows on the desktop). If a
9859 * window's semantic type as specified with gdk_window_set_type_hint()
9860 * already fully describes the window, this function should
9861 * <emphasis>not</emphasis> be called in addition, instead you should
9862 * allow the window to be treated according to standard policy for
9863 * its semantic type.
9868 gdk_window_set_skip_pager_hint (GdkWindow *window,
9869 gboolean skips_pager)
9871 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
9875 * gdk_window_set_urgency_hint:
9876 * @window: a toplevel #GdkWindow
9877 * @urgent: %TRUE if the window is urgent
9879 * Toggles whether a window needs the user's
9885 gdk_window_set_urgency_hint (GdkWindow *window,
9888 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
9892 * gdk_window_set_geometry_hints:
9893 * @window: a toplevel #GdkWindow
9894 * @geometry: geometry hints
9895 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
9897 * Sets the geometry hints for @window. Hints flagged in @geom_mask
9898 * are set, hints not flagged in @geom_mask are unset.
9899 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
9901 * This function provides hints to the windowing system about
9902 * acceptable sizes for a toplevel window. The purpose of
9903 * this is to constrain user resizing, but the windowing system
9904 * will typically (but is not required to) also constrain the
9905 * current size of the window to the provided values and
9906 * constrain programatic resizing via gdk_window_resize() or
9907 * gdk_window_move_resize().
9909 * Note that on X11, this effect has no effect on windows
9910 * of type %GDK_WINDOW_TEMP or windows where override redirect
9911 * has been turned on via gdk_window_set_override_redirect()
9912 * since these windows are not resizable by the user.
9914 * Since you can't count on the windowing system doing the
9915 * constraints for programmatic resizes, you should generally
9916 * call gdk_window_constrain_size() yourself to determine
9917 * appropriate sizes.
9921 gdk_window_set_geometry_hints (GdkWindow *window,
9922 const GdkGeometry *geometry,
9923 GdkWindowHints geom_mask)
9925 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
9929 * gdk_window_set_title:
9930 * @window: a toplevel #GdkWindow
9931 * @title: title of @window
9933 * Sets the title of a toplevel window, to be displayed in the titlebar.
9934 * If you haven't explicitly set the icon name for the window
9935 * (using gdk_window_set_icon_name()), the icon name will be set to
9936 * @title as well. @title must be in UTF-8 encoding (as with all
9937 * user-readable strings in GDK/GTK+). @title may not be %NULL.
9940 gdk_window_set_title (GdkWindow *window,
9943 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
9947 * gdk_window_set_role:
9948 * @window: a toplevel #GdkWindow
9949 * @role: a string indicating its role
9951 * When using GTK+, typically you should use gtk_window_set_role() instead
9952 * of this low-level function.
9954 * The window manager and session manager use a window's role to
9955 * distinguish it from other kinds of window in the same application.
9956 * When an application is restarted after being saved in a previous
9957 * session, all windows with the same title and role are treated as
9958 * interchangeable. So if you have two windows with the same title
9959 * that should be distinguished for session management purposes, you
9960 * should set the role on those windows. It doesn't matter what string
9961 * you use for the role, as long as you have a different role for each
9962 * non-interchangeable kind of window.
9966 gdk_window_set_role (GdkWindow *window,
9969 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
9973 * gdk_window_set_startup_id:
9974 * @window: a toplevel #GdkWindow
9975 * @startup_id: a string with startup-notification identifier
9977 * When using GTK+, typically you should use gtk_window_set_startup_id()
9978 * instead of this low-level function.
9984 gdk_window_set_startup_id (GdkWindow *window,
9985 const gchar *startup_id)
9987 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
9991 * gdk_window_set_transient_for:
9992 * @window: a toplevel #GdkWindow
9993 * @parent: another toplevel #GdkWindow
9995 * Indicates to the window manager that @window is a transient dialog
9996 * associated with the application window @parent. This allows the
9997 * window manager to do things like center @window on @parent and
9998 * keep @window above @parent.
10000 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10004 gdk_window_set_transient_for (GdkWindow *window,
10007 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10011 * gdk_window_get_root_origin:
10012 * @window: a toplevel #GdkWindow
10013 * @x: (out): return location for X position of window frame
10014 * @y: (out): return location for Y position of window frame
10016 * Obtains the top-left corner of the window manager frame in root
10017 * window coordinates.
10021 gdk_window_get_root_origin (GdkWindow *window,
10025 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10029 * gdk_window_get_frame_extents:
10030 * @window: a toplevel #GdkWindow
10031 * @rect: rectangle to fill with bounding box of the window frame
10033 * Obtains the bounding box of the window, including window manager
10034 * titlebar/borders if any. The frame position is given in root window
10035 * coordinates. To get the position of the window itself (rather than
10036 * the frame) in root window coordinates, use gdk_window_get_origin().
10040 gdk_window_get_frame_extents (GdkWindow *window,
10041 GdkRectangle *rect)
10043 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10047 * gdk_window_set_override_redirect:
10048 * @window: a toplevel #GdkWindow
10049 * @override_redirect: %TRUE if window should be override redirect
10051 * An override redirect window is not under the control of the window manager.
10052 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10053 * be entirely under the control of the application. The window manager
10054 * can't see the override redirect window at all.
10056 * Override redirect should only be used for short-lived temporary
10057 * windows, such as popup menus. #GtkMenu uses an override redirect
10058 * window in its implementation, for example.
10062 gdk_window_set_override_redirect (GdkWindow *window,
10063 gboolean override_redirect)
10065 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10069 * gdk_window_set_accept_focus:
10070 * @window: a toplevel #GdkWindow
10071 * @accept_focus: %TRUE if the window should receive input focus
10073 * Setting @accept_focus to %FALSE hints the desktop environment that the
10074 * window doesn't want to receive input focus.
10076 * On X, it is the responsibility of the window manager to interpret this
10077 * hint. ICCCM-compliant window manager usually respect it.
10082 gdk_window_set_accept_focus (GdkWindow *window,
10083 gboolean accept_focus)
10085 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10089 * gdk_window_set_focus_on_map:
10090 * @window: a toplevel #GdkWindow
10091 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10093 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10094 * window doesn't want to receive input focus when it is mapped.
10095 * focus_on_map should be turned off for windows that aren't triggered
10096 * interactively (such as popups from network activity).
10098 * On X, it is the responsibility of the window manager to interpret
10099 * this hint. Window managers following the freedesktop.org window
10100 * manager extension specification should respect it.
10105 gdk_window_set_focus_on_map (GdkWindow *window,
10106 gboolean focus_on_map)
10108 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10112 * gdk_window_set_icon_list:
10113 * @window: The #GdkWindow toplevel window to set the icon of.
10114 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10115 * A list of pixbufs, of different sizes.
10117 * Sets a list of icons for the window. One of these will be used
10118 * to represent the window when it has been iconified. The icon is
10119 * usually shown in an icon box or some sort of task bar. Which icon
10120 * size is shown depends on the window manager. The window manager
10121 * can scale the icon but setting several size icons can give better
10122 * image quality since the window manager may only need to scale the
10123 * icon by a small amount or not at all.
10127 gdk_window_set_icon_list (GdkWindow *window,
10130 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10134 * gdk_window_set_icon_name:
10135 * @window: a toplevel #GdkWindow
10136 * @name: (allow-none): name of window while iconified (minimized)
10138 * Windows may have a name used while minimized, distinct from the
10139 * name they display in their titlebar. Most of the time this is a bad
10140 * idea from a user interface standpoint. But you can set such a name
10141 * with this function, if you like.
10143 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10144 * will not update the icon title.
10146 * Using %NULL for @name unsets the icon title; further calls to
10147 * gdk_window_set_title() will again update the icon title as well.
10150 gdk_window_set_icon_name (GdkWindow *window,
10153 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10157 * gdk_window_iconify:
10158 * @window: a toplevel #GdkWindow
10160 * Asks to iconify (minimize) @window. The window manager may choose
10161 * to ignore the request, but normally will honor it. Using
10162 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10164 * This function only makes sense when @window is a toplevel window.
10168 gdk_window_iconify (GdkWindow *window)
10170 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10174 * gdk_window_deiconify:
10175 * @window: a toplevel #GdkWindow
10177 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10178 * choose to ignore the request to deiconify. When using GTK+,
10179 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10180 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10181 * unminimizes it, and puts it on the current desktop.
10185 gdk_window_deiconify (GdkWindow *window)
10187 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10191 * gdk_window_stick:
10192 * @window: a toplevel #GdkWindow
10194 * "Pins" a window such that it's on all workspaces and does not scroll
10195 * with viewports, for window managers that have scrollable viewports.
10196 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10198 * On the X11 platform, this function depends on window manager
10199 * support, so may have no effect with many window managers. However,
10200 * GDK will do the best it can to convince the window manager to stick
10201 * the window. For window managers that don't support this operation,
10202 * there's nothing you can do to force it to happen.
10206 gdk_window_stick (GdkWindow *window)
10208 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10212 * gdk_window_unstick:
10213 * @window: a toplevel #GdkWindow
10215 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10216 * and gtk_window_unstick().
10220 gdk_window_unstick (GdkWindow *window)
10222 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10226 * gdk_window_maximize:
10227 * @window: a toplevel #GdkWindow
10229 * Maximizes the window. If the window was already maximized, then
10230 * this function does nothing.
10232 * On X11, asks the window manager to maximize @window, if the window
10233 * manager supports this operation. Not all window managers support
10234 * this, and some deliberately ignore it or don't have a concept of
10235 * "maximized"; so you can't rely on the maximization actually
10236 * happening. But it will happen with most standard window managers,
10237 * and GDK makes a best effort to get it to happen.
10239 * On Windows, reliably maximizes the window.
10243 gdk_window_maximize (GdkWindow *window)
10245 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10249 * gdk_window_unmaximize:
10250 * @window: a toplevel #GdkWindow
10252 * Unmaximizes the window. If the window wasn't maximized, then this
10253 * function does nothing.
10255 * On X11, asks the window manager to unmaximize @window, if the
10256 * window manager supports this operation. Not all window managers
10257 * support this, and some deliberately ignore it or don't have a
10258 * concept of "maximized"; so you can't rely on the unmaximization
10259 * actually happening. But it will happen with most standard window
10260 * managers, and GDK makes a best effort to get it to happen.
10262 * On Windows, reliably unmaximizes the window.
10266 gdk_window_unmaximize (GdkWindow *window)
10268 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10272 * gdk_window_fullscreen:
10273 * @window: a toplevel #GdkWindow
10275 * Moves the window into fullscreen mode. This means the
10276 * window covers the entire screen and is above any panels
10279 * If the window was already fullscreen, then this function does nothing.
10281 * On X11, asks the window manager to put @window in a fullscreen
10282 * state, if the window manager supports this operation. Not all
10283 * window managers support this, and some deliberately ignore it or
10284 * don't have a concept of "fullscreen"; so you can't rely on the
10285 * fullscreenification actually happening. But it will happen with
10286 * most standard window managers, and GDK makes a best effort to get
10292 gdk_window_fullscreen (GdkWindow *window)
10294 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10298 * gdk_window_unfullscreen:
10299 * @window: a toplevel #GdkWindow
10301 * Moves the window out of fullscreen mode. If the window was not
10302 * fullscreen, does nothing.
10304 * On X11, asks the window manager to move @window out of the fullscreen
10305 * state, if the window manager supports this operation. Not all
10306 * window managers support this, and some deliberately ignore it or
10307 * don't have a concept of "fullscreen"; so you can't rely on the
10308 * unfullscreenification actually happening. But it will happen with
10309 * most standard window managers, and GDK makes a best effort to get
10315 gdk_window_unfullscreen (GdkWindow *window)
10317 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10321 * gdk_window_set_keep_above:
10322 * @window: a toplevel #GdkWindow
10323 * @setting: whether to keep @window above other windows
10325 * Set if @window must be kept above other windows. If the
10326 * window was already above, then this function does nothing.
10328 * On X11, asks the window manager to keep @window above, if the window
10329 * manager supports this operation. Not all window managers support
10330 * this, and some deliberately ignore it or don't have a concept of
10331 * "keep above"; so you can't rely on the window being kept above.
10332 * But it will happen with most standard window managers,
10333 * and GDK makes a best effort to get it to happen.
10338 gdk_window_set_keep_above (GdkWindow *window,
10341 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10345 * gdk_window_set_keep_below:
10346 * @window: a toplevel #GdkWindow
10347 * @setting: whether to keep @window below other windows
10349 * Set if @window must be kept below other windows. If the
10350 * window was already below, then this function does nothing.
10352 * On X11, asks the window manager to keep @window below, if the window
10353 * manager supports this operation. Not all window managers support
10354 * this, and some deliberately ignore it or don't have a concept of
10355 * "keep below"; so you can't rely on the window being kept below.
10356 * But it will happen with most standard window managers,
10357 * and GDK makes a best effort to get it to happen.
10362 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10364 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10368 * gdk_window_get_group:
10369 * @window: a toplevel #GdkWindow
10371 * Returns the group leader window for @window. See gdk_window_set_group().
10373 * Return value: (transfer none): the group leader window for @window
10378 gdk_window_get_group (GdkWindow *window)
10380 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10384 * gdk_window_set_group:
10385 * @window: a toplevel #GdkWindow
10386 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10388 * Sets the group leader window for @window. By default,
10389 * GDK sets the group leader for all toplevel windows
10390 * to a global window implicitly created by GDK. With this function
10391 * you can override this default.
10393 * The group leader window allows the window manager to distinguish
10394 * all windows that belong to a single application. It may for example
10395 * allow users to minimize/unminimize all windows belonging to an
10396 * application at once. You should only set a non-default group window
10397 * if your application pretends to be multiple applications.
10400 gdk_window_set_group (GdkWindow *window,
10403 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10407 * gdk_window_set_decorations:
10408 * @window: a toplevel #GdkWindow
10409 * @decorations: decoration hint mask
10411 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10412 * This function sets the traditional Motif window manager hints that tell the
10413 * window manager which decorations you would like your window to have.
10414 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10415 * using the GDK function directly.
10417 * The @decorations argument is the logical OR of the fields in
10418 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10419 * mask, the other bits indicate which decorations should be turned off.
10420 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10421 * which decorations should be turned on.
10423 * Most window managers honor a decorations hint of 0 to disable all decorations,
10424 * but very few honor all possible combinations of bits.
10428 gdk_window_set_decorations (GdkWindow *window,
10429 GdkWMDecoration decorations)
10431 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10435 * gdk_window_get_decorations:
10436 * @window: The toplevel #GdkWindow to get the decorations from
10437 * @decorations: (out): The window decorations will be written here
10439 * Returns the decorations set on the GdkWindow with
10440 * gdk_window_set_decorations().
10442 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10445 gdk_window_get_decorations(GdkWindow *window,
10446 GdkWMDecoration *decorations)
10448 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10452 * gdk_window_set_functions:
10453 * @window: a toplevel #GdkWindow
10454 * @functions: bitmask of operations to allow on @window
10456 * Sets hints about the window management functions to make available
10457 * via buttons on the window frame.
10459 * On the X backend, this function sets the traditional Motif window
10460 * manager hint for this purpose. However, few window managers do
10461 * anything reliable or interesting with this hint. Many ignore it
10464 * The @functions argument is the logical OR of values from the
10465 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
10466 * then the other bits indicate which functions to disable; if
10467 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
10472 gdk_window_set_functions (GdkWindow *window,
10473 GdkWMFunction functions)
10475 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
10479 * gdk_window_begin_resize_drag:
10480 * @window: a toplevel #GdkWindow
10481 * @edge: the edge or corner from which the drag is started
10482 * @button: the button being used to drag
10483 * @root_x: root window X coordinate of mouse click that began the drag
10484 * @root_y: root window Y coordinate of mouse click that began the drag
10485 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10487 * Begins a window resize operation (for a toplevel window).
10488 * You might use this function to implement a "window resize grip," for
10489 * example; in fact #GtkStatusbar uses it. The function works best
10490 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
10491 * fallback implementation for other window managers.
10495 gdk_window_begin_resize_drag (GdkWindow *window,
10496 GdkWindowEdge edge,
10502 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, button, root_x, root_y, timestamp);
10506 * gdk_window_begin_move_drag:
10507 * @window: a toplevel #GdkWindow
10508 * @button: the button being used to drag
10509 * @root_x: root window X coordinate of mouse click that began the drag
10510 * @root_y: root window Y coordinate of mouse click that began the drag
10511 * @timestamp: timestamp of mouse click that began the drag
10513 * Begins a window move operation (for a toplevel window). You might
10514 * use this function to implement a "window move grip," for
10515 * example. The function works best with window managers that support
10516 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
10517 * Window Manager Hints</ulink>, but has a fallback implementation for
10518 * other window managers.
10522 gdk_window_begin_move_drag (GdkWindow *window,
10528 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window, button, root_x, root_y, timestamp);
10532 * gdk_window_enable_synchronized_configure:
10533 * @window: a toplevel #GdkWindow
10535 * Indicates that the application will cooperate with the window
10536 * system in synchronizing the window repaint with the window
10537 * manager during resizing operations. After an application calls
10538 * this function, it must call gdk_window_configure_finished() every
10539 * time it has finished all processing associated with a set of
10540 * Configure events. Toplevel GTK+ windows automatically use this
10543 * On X, calling this function makes @window participate in the
10544 * _NET_WM_SYNC_REQUEST window manager protocol.
10549 gdk_window_enable_synchronized_configure (GdkWindow *window)
10551 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
10555 * gdk_window_configure_finished:
10556 * @window: a toplevel #GdkWindow
10558 * Signal to the window system that the application has finished
10559 * handling Configure events it has received. Window Managers can
10560 * use this to better synchronize the frame repaint with the
10561 * application. GTK+ applications will automatically call this
10562 * function when appropriate.
10564 * This function can only be called if gdk_window_enable_synchronized_configure()
10565 * was called previously.
10570 gdk_window_configure_finished (GdkWindow *window)
10572 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
10576 * gdk_window_set_opacity:
10577 * @window: a top-level #GdkWindow
10578 * @opacity: opacity
10580 * Request the windowing system to make @window partially transparent,
10581 * with opacity 0 being fully transparent and 1 fully opaque. (Values
10582 * of the opacity parameter are clamped to the [0,1] range.)
10584 * On X11, this works only on X screens with a compositing manager
10587 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
10588 * For making non-toplevel windows translucent, see
10589 * gdk_window_set_composited().
10594 gdk_window_set_opacity (GdkWindow *window,
10597 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
10600 /* This function is called when the XWindow is really gone.
10603 gdk_window_destroy_notify (GdkWindow *window)
10605 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
10609 * gdk_window_register_dnd:
10610 * @window: a #GdkWindow.
10612 * Registers a window as a potential drop destination.
10615 gdk_window_register_dnd (GdkWindow *window)
10617 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
10621 * gdk_window_get_drag_protocol:
10622 * @window: the destination window
10623 * @target: (out) (allow-none) (transfer full): location of the window
10624 * where the drop should happen. This may be @window or a proxy window,
10625 * or %NULL if @window does not support Drag and Drop.
10627 * Finds out the DND protocol supported by a window.
10629 * Returns: the supported DND protocol.
10634 gdk_window_get_drag_protocol (GdkWindow *window,
10635 GdkWindow **target)
10637 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
10639 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
10644 * @window: the source window for this drag.
10645 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10646 * as list of #GdkAtoms
10648 * Starts a drag and creates a new drag context for it.
10649 * This function assumes that the drag is controlled by the
10650 * client pointer device, use gdk_drag_begin_for_device() to
10651 * begin a drag with a different device.
10653 * This function is called by the drag source.
10655 * Return value: (transfer full): a newly created #GdkDragContext
10658 gdk_drag_begin (GdkWindow *window,
10661 GdkDeviceManager *device_manager;
10664 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10665 device = gdk_device_manager_get_client_pointer (device_manager);
10667 return gdk_drag_begin_for_device (window, device, targets);
10671 * gdk_drag_begin_for_device:
10672 * @window: the source window for this drag
10673 * @device: the device that controls this drag
10674 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10675 * as list of #GdkAtoms
10677 * Starts a drag and creates a new drag context for it.
10679 * This function is called by the drag source.
10681 * Return value: (transfer full): a newly created #GdkDragContext
10684 gdk_drag_begin_for_device (GdkWindow *window,
10688 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
10692 * gdk_test_render_sync:
10693 * @window: a mapped #GdkWindow
10695 * Retrieves a pixel from @window to force the windowing
10696 * system to carry out any pending rendering commands.
10698 * This function is intended to be used to synchronize with rendering
10699 * pipelines, to benchmark windowing system rendering operations.
10704 gdk_test_render_sync (GdkWindow *window)
10706 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
10710 * gdk_test_simulate_key:
10711 * @window: a #GdkWindow to simulate a key event for
10712 * @x: x coordinate within @window for the key event
10713 * @y: y coordinate within @window for the key event
10714 * @keyval: A GDK keyboard value
10715 * @modifiers: Keyboard modifiers the event is setup with
10716 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
10718 * This function is intended to be used in GTK+ test programs.
10719 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
10720 * the given (@x,@y) coordinates within @window and simulate a
10721 * key press or release event.
10723 * When the mouse pointer is warped to the target location, use
10724 * of this function outside of test programs that run in their
10725 * own virtual windowing system (e.g. Xvfb) is not recommended.
10726 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
10727 * be warped and @window origin will be used as mouse pointer
10728 * location for the event.
10730 * Also, gdk_test_simulate_key() is a fairly low level function,
10731 * for most testing purposes, gtk_test_widget_send_key() is the
10732 * right function to call which will generate a key press event
10733 * followed by its accompanying key release event.
10735 * Returns: whether all actions necessary for a key event simulation
10736 * were carried out successfully
10741 gdk_test_simulate_key (GdkWindow *window,
10745 GdkModifierType modifiers,
10746 GdkEventType key_pressrelease)
10748 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10749 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
10753 * gdk_test_simulate_button:
10754 * @window: a #GdkWindow to simulate a button event for
10755 * @x: x coordinate within @window for the button event
10756 * @y: y coordinate within @window for the button event
10757 * @button: Number of the pointer button for the event, usually 1, 2 or 3
10758 * @modifiers: Keyboard modifiers the event is setup with
10759 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
10761 * This function is intended to be used in GTK+ test programs.
10762 * It will warp the mouse pointer to the given (@x,@y) coordinates
10763 * within @window and simulate a button press or release event.
10764 * Because the mouse pointer needs to be warped to the target
10765 * location, use of this function outside of test programs that
10766 * run in their own virtual windowing system (e.g. Xvfb) is not
10769 * Also, gdk_test_simulate_button() is a fairly low level function,
10770 * for most testing purposes, gtk_test_widget_click() is the right
10771 * function to call which will generate a button press event followed
10772 * by its accompanying button release event.
10774 * Returns: whether all actions necessary for a button event simulation
10775 * were carried out successfully
10780 gdk_test_simulate_button (GdkWindow *window,
10783 guint button, /*1..3*/
10784 GdkModifierType modifiers,
10785 GdkEventType button_pressrelease)
10787 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10788 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
10792 * gdk_property_get:
10793 * @window: a #GdkWindow
10794 * @property: the property to retrieve
10795 * @type: the desired property type, or %GDK_NONE, if any type of data
10796 * is acceptable. If this does not match the actual
10797 * type, then @actual_format and @actual_length will
10798 * be filled in, a warning will be printed to stderr
10799 * and no data will be returned.
10800 * @offset: the offset into the property at which to begin
10801 * retrieving data, in 4 byte units.
10802 * @length: the length of the data to retrieve in bytes. Data is
10803 * considered to be retrieved in 4 byte chunks, so @length
10804 * will be rounded up to the next highest 4 byte boundary
10805 * (so be careful not to pass a value that might overflow
10806 * when rounded up).
10807 * @pdelete: if %TRUE, delete the property after retrieving the
10809 * @actual_property_type: (out) (transfer none): location to store the
10810 * actual type of the property.
10811 * @actual_format: (out): location to store the actual return format of the
10812 * data; either 8, 16 or 32 bits.
10813 * @actual_length: location to store the length of the retrieved data, in
10814 * bytes. Data returned in the 32 bit format is stored
10815 * in a long variable, so the actual number of 32 bit
10816 * elements should be be calculated via
10817 * @actual_length / sizeof(glong) to ensure portability to
10819 * @data: (out) (array length=actual_length) (transfer full): location
10820 * to store a pointer to the data. The retrieved data should be
10821 * freed with g_free() when you are finished using it.
10823 * Retrieves a portion of the contents of a property. If the
10824 * property does not exist, then the function returns %FALSE,
10825 * and %GDK_NONE will be stored in @actual_property_type.
10829 * The XGetWindowProperty() function that gdk_property_get()
10830 * uses has a very confusing and complicated set of semantics.
10831 * uses has a very confusing and complicated set of semantics.
10832 * Unfortunately, gdk_property_get() makes the situation
10833 * worse instead of better (the semantics should be considered
10834 * undefined), and also prints warnings to stderr in cases where it
10835 * should return a useful error to the program. You are advised to use
10836 * XGetWindowProperty() directly until a replacement function for
10837 * gdk_property_get()
10842 * Returns: %TRUE if data was successfully received and stored
10843 * in @data, otherwise %FALSE.
10846 gdk_property_get (GdkWindow *window,
10852 GdkAtom *actual_property_type,
10853 gint *actual_format_type,
10854 gint *actual_length,
10857 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10858 ->get_property (window, property, type, offset, length, pdelete,
10859 actual_property_type, actual_format_type,
10860 actual_length, data);
10864 * gdk_property_change: (skip)
10865 * @window: a #GdkWindow
10866 * @property: the property to change
10867 * @type: the new type for the property. If @mode is
10868 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
10869 * must match the existing type or an error will occur.
10870 * @format: the new format for the property. If @mode is
10871 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
10872 * must match the existing format or an error will occur.
10873 * @mode: a value describing how the new data is to be combined
10874 * with the current data.
10875 * @data: the data (a <literal>guchar *</literal>
10876 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
10877 * depending on @format), cast to a <literal>guchar *</literal>.
10878 * @nelements: the number of elements of size determined by the format,
10879 * contained in @data.
10881 * Changes the contents of a property on a window.
10884 gdk_property_change (GdkWindow *window,
10889 const guchar *data,
10892 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10893 ->change_property (window, property, type, format, mode, data, nelements);
10897 * gdk_property_delete:
10898 * @window: a #GdkWindow
10899 * @property: the property to delete
10901 * Deletes a property from a window.
10904 gdk_property_delete (GdkWindow *window,
10907 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);