1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include <cairo-gobject.h>
32 #include "gdkwindow.h"
34 #ifdef GDK_WINDOWING_X11
35 #include "x11/gdkx.h" /* For workaround */
38 #include "gdkrectangle.h"
39 #include "gdkinternals.h"
41 #include "gdkscreen.h"
42 #include "gdkdeviceprivate.h"
43 #include "gdkdrawable.h"
44 #include "gdkmarshalers.h"
45 #include "gdkscreen.h"
46 #include "gdkwindowimpl.h"
50 #undef DEBUG_WINDOW_PRINTING
55 * @Short_description: Onscreen display areas in the target window system
58 * A #GdkWindow is a rectangular region on the screen. It's a low-level object,
59 * used to implement high-level objects such as #GtkWidget and #GtkWindow on the
60 * GTK+ level. A #GtkWindow is a toplevel window, the thing a user might think
61 * of as a "window" with a titlebar and so on; a #GtkWindow may contain many
62 * #GdkWindow<!-- -->s. For example, each #GtkButton has a #GdkWindow associated
65 * <refsect2 id="COMPOSITED-WINDOWS">
66 * <title>Composited Windows</title>
68 * Normally, the windowing system takes care of rendering the contents of a
69 * child window onto its parent window. This mechanism can be intercepted by
70 * calling gdk_window_set_composited() on the child window. For a
71 * <firstterm>composited</firstterm> window it is the responsibility of the
72 * application to render the window contents at the right spot.
74 * <example id="composited-window-example">
75 * <title>Composited windows</title>
77 * <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>
78 * </programlisting></example>
80 * In the example <xref linkend="composited-window-example"/>, a button is
81 * placed inside of an event box inside of a window. The event box is set as
82 * composited and therefore is no longer automatically drawn to the screen.
84 * When the contents of the event box change, an expose event is generated on
85 * it's parent window (which, in this case, belongs to the toplevel #GtkWindow).
86 * The expose handler for this widget is responsible for merging the changes
87 * back on the screen in the way that it wishes.
89 * In our case, we merge the contents with a 50% transparency. We also set the
90 * background colour of the window to red. The effect is that the background
91 * shows through the button.
94 * <refsect2 id="OFFSCREEN-WINDOWS">
95 * <title>Offscreen Windows</title>
97 * Offscreen windows are more general than composited windows, since they allow
98 * not only to modify the rendering of the child window onto its parent, but
99 * also to apply coordinate transformations.
101 * To integrate an offscreen window into a window hierarchy, one has to call
102 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
103 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
104 * select an offscreen child at given coordinates, and the
105 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
106 * offscreen window are used to translate coordinates between the embedder and
107 * the offscreen window.
109 * For rendering an offscreen window onto its embedder, the contents of the
110 * offscreen window are available as a surface, via
111 * gdk_offscreen_window_get_surface().
117 /* Historically a GdkWindow always matches a platform native window,
118 * be it a toplevel window or a child window. In this setup the
119 * GdkWindow (and other GdkDrawables) were platform independent classes,
120 * and the actual platform specific implementation was in a delegate
121 * object availible as "impl" in the window object.
123 * With the addition of client side windows and offscreen windows this
124 * changes a bit. The application-visible GdkWindow object behaves as
125 * it did before, but not all such windows now have a corresponding native
126 * window. Instead windows that are "client side" are emulated by the gdk
127 * code such that clipping, drawing, moving, events etc work as expected.
129 * For GdkWindows that have a native window the "impl" object is the
130 * same as before. However, for all client side windows the impl object
131 * is shared with its parent (i.e. all client windows descendants of one
132 * native window has the same impl.
134 * Additionally there is a new type of platform independent impl object,
135 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
136 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
137 * windows). Such windows work by allocating a #cairo_surface_t as the backing
138 * store for drawing operations, which is resized with the window.
140 * GdkWindows have a pointer to the "impl window" they are in, i.e.
141 * the topmost GdkWindow which have the same "impl" value. This is stored
142 * in impl_window, which is different from the window itself only for client
144 * All GdkWindows (native or not) track the position of the window in the parent
145 * (x, y), the size of the window (width, height), the position of the window
146 * with respect to the impl window (abs_x, abs_y). We also track the clip
147 * region of the window wrt parent windows and siblings, in window-relative
148 * coordinates with and without child windows included (clip_region,
149 * clip_region_with_children).
151 * All toplevel windows are native windows, but also child windows can be
152 * native (although not children of offscreens). We always listen to
153 * a basic set of events (see get_native_event_mask) for these windows
154 * so that we can emulate events for any client side children.
156 * For native windows we apply the calculated clip region as a window shape
157 * so that eg. client side siblings that overlap the native child properly
158 * draws over the native child window.
160 * In order to minimize flicker and for performance we use a couple of cacheing
161 * tricks. First of all, every time we do a window to window copy area, for instance
162 * when moving a client side window or when scrolling/moving a region in a window
163 * we store this in outstanding_moves instead of applying immediately. We then
164 * delay this move until we really need it (because something depends on being
165 * able to read it), or until we're handing a redraw from an expose/invalidation
166 * (actually we delay it past redraw, but before blitting the double buffer
167 * to the window). This gives us two advantages. First of all it minimizes the time
168 * from the window is moved to the exposes related to that move, secondly it allows
169 * us to be smart about how to do the copy. We combine multiple moves into one (when
170 * possible) and we don't actually do copies to anything that is or will be
171 * invalidated and exposed anyway.
173 * Secondly, we use something called a "implicit paint" during repaint handling.
174 * An implicit paint is similar to a regular paint for the paint stack, but it is
175 * not put on the stack. Instead, it is set on the impl window, and later when
176 * regular gdk_window_begin_paint_region() happen on a window of this impl window
177 * we reuse the surface from the implicit paint. During repaint we create and at the
178 * end flush an implicit paint, which means we can collect all the paints on
179 * multiple client side windows in the same backing store.
182 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
184 /* This adds a local value to the GdkVisibilityState enum */
185 #define GDK_VISIBILITY_NOT_VIEWABLE 3
188 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
202 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
206 struct _GdkWindowPaint
208 cairo_region_t *region;
209 cairo_surface_t *surface;
210 guint uses_implicit : 1;
216 cairo_region_t *dest_region; /* The destination region */
217 int dx, dy; /* The amount that the source was moved to reach dest_region */
218 } GdkWindowRegionMove;
222 static cairo_surface_t *gdk_window_ref_cairo_surface (GdkDrawable *drawable);
223 static cairo_surface_t *gdk_window_create_cairo_surface (GdkDrawable *drawable,
226 static void gdk_window_drop_cairo_surface (GdkWindowObject *private);
227 static void gdk_window_set_cairo_clip (GdkDrawable *drawable,
230 static cairo_region_t* gdk_window_get_clip_region (GdkDrawable *drawable);
231 static cairo_region_t* gdk_window_get_visible_region (GdkDrawable *drawable);
233 static void gdk_window_free_paint_stack (GdkWindow *window);
235 static void gdk_window_init (GdkWindowObject *window);
236 static void gdk_window_class_init (GdkWindowObjectClass *klass);
237 static void gdk_window_finalize (GObject *object);
239 static void gdk_window_set_property (GObject *object,
243 static void gdk_window_get_property (GObject *object,
248 static void gdk_window_clear_backing_region (GdkWindow *window,
249 cairo_region_t *region);
251 static void recompute_visible_regions (GdkWindowObject *private,
252 gboolean recalculate_siblings,
253 gboolean recalculate_children);
254 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
255 static void gdk_window_flush_recursive (GdkWindowObject *window);
256 static void do_move_region_bits_on_impl (GdkWindowObject *private,
257 cairo_region_t *region, /* In impl window coords */
259 static void gdk_window_invalidate_in_parent (GdkWindowObject *private);
260 static void move_native_children (GdkWindowObject *private);
261 static void update_cursor (GdkDisplay *display,
263 static void impl_window_add_update_area (GdkWindowObject *impl_window,
264 cairo_region_t *region);
265 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
266 static void gdk_window_invalidate_region_full (GdkWindow *window,
267 const cairo_region_t *region,
268 gboolean invalidate_children,
270 static void gdk_window_invalidate_rect_full (GdkWindow *window,
271 const GdkRectangle *rect,
272 gboolean invalidate_children,
275 static guint signals[LAST_SIGNAL] = { 0 };
277 static gpointer parent_class = NULL;
279 static const cairo_user_data_key_t gdk_window_cairo_key;
282 new_region_tag (void)
284 static guint32 tag = 0;
290 gdk_window_object_get_type (void)
292 static GType object_type = 0;
295 object_type = g_type_register_static_simple (GDK_TYPE_DRAWABLE,
297 sizeof (GdkWindowObjectClass),
298 (GClassInitFunc) gdk_window_class_init,
299 sizeof (GdkWindowObject),
300 (GInstanceInitFunc) gdk_window_init,
307 _gdk_paintable_get_type (void)
309 static GType paintable_type = 0;
313 const GTypeInfo paintable_info =
315 sizeof (GdkPaintableIface), /* class_size */
316 NULL, /* base_init */
317 NULL, /* base_finalize */
320 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
321 g_intern_static_string ("GdkPaintable"),
324 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
327 return paintable_type;
331 gdk_window_init (GdkWindowObject *window)
333 /* 0-initialization is good for all other fields. */
335 window->window_type = GDK_WINDOW_CHILD;
337 window->state = GDK_WINDOW_STATE_WITHDRAWN;
340 window->toplevel_window_type = -1;
342 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
343 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
344 /* Default to unobscured since some backends don't send visibility events */
345 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
348 /* Stop and return on the first non-NULL parent */
350 accumulate_get_window (GSignalInvocationHint *ihint,
352 const GValue *handler_return,
355 g_value_copy (handler_return, return_accu);
356 /* Continue while returning NULL */
357 return g_value_get_object (handler_return) == NULL;
361 create_surface_accumulator (GSignalInvocationHint *ihint,
363 const GValue *handler_return,
366 g_value_copy (handler_return, return_accu);
368 /* Stop on the first non-NULL return value */
369 return g_value_get_boxed (handler_return) == NULL;
372 static GQuark quark_pointer_window = 0;
375 gdk_window_class_init (GdkWindowObjectClass *klass)
377 GObjectClass *object_class = G_OBJECT_CLASS (klass);
378 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
380 parent_class = g_type_class_peek_parent (klass);
382 object_class->finalize = gdk_window_finalize;
383 object_class->set_property = gdk_window_set_property;
384 object_class->get_property = gdk_window_get_property;
386 drawable_class->ref_cairo_surface = gdk_window_ref_cairo_surface;
387 drawable_class->create_cairo_surface = gdk_window_create_cairo_surface;
388 drawable_class->set_cairo_clip = gdk_window_set_cairo_clip;
389 drawable_class->get_clip_region = gdk_window_get_clip_region;
390 drawable_class->get_visible_region = gdk_window_get_visible_region;
392 klass->create_surface = _gdk_offscreen_window_create_surface;
394 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
402 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
403 * gdk_window_get_cursor() for details.
407 g_object_class_install_property (object_class,
409 g_param_spec_boxed ("cursor",
416 * GdkWindow::pick-embedded-child:
417 * @window: the window on which the signal is emitted
418 * @x: x coordinate in the window
419 * @y: y coordinate in the window
421 * The ::pick-embedded-child signal is emitted to find an embedded
422 * child at the given position.
424 * Returns: the #GdkWindow of the embedded child at @x, @y, or %NULL
428 signals[PICK_EMBEDDED_CHILD] =
429 g_signal_new (g_intern_static_string ("pick-embedded-child"),
430 G_OBJECT_CLASS_TYPE (object_class),
432 G_STRUCT_OFFSET (GdkWindowObjectClass, pick_embedded_child),
433 accumulate_get_window, NULL,
434 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
441 * GdkWindow::to-embedder:
442 * @window: the offscreen window on which the signal is emitted
443 * @offscreen-x: x coordinate in the offscreen window
444 * @offscreen-y: y coordinate in the offscreen window
445 * @embedder-x: return location for the x coordinate in the embedder window
446 * @embedder-y: return location for the y coordinate in the embedder window
448 * The ::to-embedder signal is emitted to translate coordinates
449 * in an offscreen window to its embedder.
451 * See also #GtkWindow::from-embedder.
455 signals[TO_EMBEDDER] =
456 g_signal_new (g_intern_static_string ("to-embedder"),
457 G_OBJECT_CLASS_TYPE (object_class),
459 G_STRUCT_OFFSET (GdkWindowObjectClass, to_embedder),
461 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
470 * GdkWindow::from-embedder:
471 * @window: the offscreen window on which the signal is emitted
472 * @embedder-x: x coordinate in the embedder window
473 * @embedder-y: y coordinate in the embedder window
474 * @offscreen-x: return location for the x coordinate in the offscreen window
475 * @offscreen-y: return location for the y coordinate in the offscreen window
477 * The ::from-embedder signal is emitted to translate coordinates
478 * in the embedder of an offscreen window to the offscreen window.
480 * See also #GtkWindow::to-embedder.
484 signals[FROM_EMBEDDER] =
485 g_signal_new (g_intern_static_string ("from-embedder"),
486 G_OBJECT_CLASS_TYPE (object_class),
488 G_STRUCT_OFFSET (GdkWindowObjectClass, from_embedder),
490 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
499 * GdkWindow::create-surface:
500 * @window: the offscreen window on which the signal is emitted
501 * @width: the width of the offscreen surface to create
502 * @height: the height of the offscreen surface to create
504 * The ::create-surface signal is emitted when an offscreen window
505 * needs its surface (re)created, which happens either when the the
506 * window is first drawn to, or when the window is being
507 * resized. The first signal handler that returns a non-%NULL
508 * surface will stop any further signal emission, and its surface
511 * Note that it is not possible to access the window's previous
512 * surface from within any callback of this signal. Calling
513 * gdk_offscreen_window_get_surface() will lead to a crash.
515 * Returns: the newly created #cairo_surface_t for the offscreen window
519 signals[CREATE_SURFACE] =
520 g_signal_new (g_intern_static_string ("create-surface"),
521 G_OBJECT_CLASS_TYPE (object_class),
523 G_STRUCT_OFFSET (GdkWindowObjectClass, create_surface),
524 create_surface_accumulator, NULL,
525 _gdk_marshal_BOXED__INT_INT,
526 CAIRO_GOBJECT_TYPE_SURFACE,
533 device_removed_cb (GdkDeviceManager *device_manager,
537 GdkWindowObject *private;
539 private = (GdkWindowObject *) window;
541 private->devices_inside = g_list_remove (private->devices_inside, device);
542 g_hash_table_remove (private->device_cursor, device);
544 if (private->device_events)
545 g_hash_table_remove (private->device_events, device);
549 gdk_window_finalize (GObject *object)
551 GdkWindow *window = GDK_WINDOW (object);
552 GdkWindowObject *obj = (GdkWindowObject *) object;
553 GdkDeviceManager *device_manager;
555 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
556 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
558 if (!GDK_WINDOW_DESTROYED (window))
560 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
562 g_warning ("losing last reference to undestroyed window\n");
563 _gdk_window_destroy (window, FALSE);
566 /* We use TRUE here, to keep us from actually calling
567 * XDestroyWindow() on the window
569 _gdk_window_destroy (window, TRUE);
572 gdk_window_drop_cairo_surface (obj);
576 g_object_unref (obj->impl);
580 if (obj->impl_window != obj)
582 g_object_unref (obj->impl_window);
583 obj->impl_window = NULL;
587 cairo_region_destroy (obj->shape);
589 if (obj->input_shape)
590 cairo_region_destroy (obj->input_shape);
593 gdk_cursor_unref (obj->cursor);
595 if (obj->device_cursor)
596 g_hash_table_destroy (obj->device_cursor);
598 if (obj->device_events)
599 g_hash_table_destroy (obj->device_events);
601 if (obj->devices_inside)
602 g_list_free (obj->devices_inside);
604 G_OBJECT_CLASS (parent_class)->finalize (object);
608 gdk_window_set_property (GObject *object,
613 GdkWindow *window = (GdkWindow *)object;
618 gdk_window_set_cursor (window, g_value_get_boxed (value));
622 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
628 gdk_window_get_property (GObject *object,
633 GdkWindow *window = (GdkWindow *) object;
638 g_value_set_boxed (value, gdk_window_get_cursor (window));
642 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
648 gdk_window_is_offscreen (GdkWindowObject *window)
650 return window->window_type == GDK_WINDOW_OFFSCREEN;
653 static GdkWindowObject *
654 gdk_window_get_impl_window (GdkWindowObject *window)
656 return window->impl_window;
660 _gdk_window_get_impl_window (GdkWindow *window)
662 return (GdkWindow *)gdk_window_get_impl_window ((GdkWindowObject *)window);
666 gdk_window_has_impl (GdkWindowObject *window)
668 return window->impl_window == window;
672 gdk_window_is_toplevel (GdkWindowObject *window)
675 window->parent == NULL ||
676 window->parent->window_type == GDK_WINDOW_ROOT;
680 _gdk_window_has_impl (GdkWindow *window)
682 return gdk_window_has_impl ((GdkWindowObject *)window);
686 gdk_window_has_no_impl (GdkWindowObject *window)
688 return window->impl_window != window;
692 remove_child_area (GdkWindowObject *private,
693 GdkWindowObject *until,
695 cairo_region_t *region)
697 GdkWindowObject *child;
698 cairo_region_t *child_region;
701 cairo_region_t *shape;
703 for (l = private->children; l; l = l->next)
710 /* If region is empty already, no need to do
711 anything potentially costly */
712 if (cairo_region_is_empty (region))
715 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
718 /* Ignore offscreen children, as they don't draw in their parent and
719 * don't take part in the clipping */
720 if (gdk_window_is_offscreen (child))
725 r.width = child->width;
726 r.height = child->height;
728 /* Bail early if child totally outside region */
729 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
732 child_region = cairo_region_create_rectangle (&r);
736 /* Adjust shape region to parent window coords */
737 cairo_region_translate (child->shape, child->x, child->y);
738 cairo_region_intersect (child_region, child->shape);
739 cairo_region_translate (child->shape, -child->x, -child->y);
741 else if (private->window_type == GDK_WINDOW_FOREIGN)
743 shape = _gdk_windowing_window_get_shape ((GdkWindow *)child);
746 cairo_region_intersect (child_region, shape);
747 cairo_region_destroy (shape);
753 if (child->input_shape)
754 cairo_region_intersect (child_region, child->input_shape);
755 else if (private->window_type == GDK_WINDOW_FOREIGN)
757 shape = _gdk_windowing_window_get_input_shape ((GdkWindow *)child);
760 cairo_region_intersect (child_region, shape);
761 cairo_region_destroy (shape);
766 cairo_region_subtract (region, child_region);
767 cairo_region_destroy (child_region);
772 static GdkVisibilityState
773 effective_visibility (GdkWindowObject *private)
775 GdkVisibilityState native;
777 if (!gdk_window_is_viewable ((GdkWindow *)private))
778 return GDK_VISIBILITY_NOT_VIEWABLE;
780 native = private->impl_window->native_visibility;
782 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
783 private->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
784 return GDK_VISIBILITY_FULLY_OBSCURED;
785 else if (native == GDK_VISIBILITY_UNOBSCURED)
786 return private->visibility;
787 else /* native PARTIAL, private partial or unobscured */
788 return GDK_VISIBILITY_PARTIAL;
792 gdk_window_update_visibility (GdkWindowObject *private)
794 GdkVisibilityState new_visibility;
797 new_visibility = effective_visibility (private);
799 if (new_visibility != private->effective_visibility)
801 private->effective_visibility = new_visibility;
803 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
804 private->event_mask & GDK_VISIBILITY_NOTIFY)
806 event = _gdk_make_event ((GdkWindow *)private, GDK_VISIBILITY_NOTIFY,
808 event->visibility.state = new_visibility;
814 gdk_window_update_visibility_recursively (GdkWindowObject *private,
815 GdkWindowObject *only_for_impl)
817 GdkWindowObject *child;
820 gdk_window_update_visibility (private);
821 for (l = private->children; l != NULL; l = l->next)
824 if ((only_for_impl == NULL) ||
825 (only_for_impl == child->impl_window))
826 gdk_window_update_visibility_recursively (child, only_for_impl);
831 should_apply_clip_as_shape (GdkWindowObject *private)
834 gdk_window_has_impl (private) &&
835 /* Not for offscreens */
836 !gdk_window_is_offscreen (private) &&
837 /* or for toplevels */
838 !gdk_window_is_toplevel (private) &&
839 /* or for foreign windows */
840 private->window_type != GDK_WINDOW_FOREIGN &&
841 /* or for the root window */
842 private->window_type != GDK_WINDOW_ROOT;
846 apply_shape (GdkWindowObject *private,
847 cairo_region_t *region)
849 GdkWindowImplIface *impl_iface;
851 /* We trash whether we applied a shape so that
852 we can avoid unsetting it many times, which
853 could happen in e.g. apply_clip_as_shape as
854 windows get resized */
855 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
857 impl_iface->shape_combine_region ((GdkWindow *)private,
859 else if (private->applied_shape)
860 impl_iface->shape_combine_region ((GdkWindow *)private,
863 private->applied_shape = region != NULL;
867 region_rect_equal (const cairo_region_t *region,
868 const GdkRectangle *rect)
870 GdkRectangle extents;
872 if (cairo_region_num_rectangles (region) != 1)
875 cairo_region_get_extents (region, &extents);
877 return extents.x == rect->x &&
878 extents.y == rect->y &&
879 extents.width == rect->width &&
880 extents.height == rect->height;
884 apply_clip_as_shape (GdkWindowObject *private)
889 r.width = private->width;
890 r.height = private->height;
892 /* We only apply the clip region if would differ
893 from the actual clip region implied by the size
894 of the window. This is to avoid unneccessarily
895 adding meaningless shapes to all native subwindows */
896 if (!region_rect_equal (private->clip_region, &r))
897 apply_shape (private, private->clip_region);
899 apply_shape (private, NULL);
903 recompute_visible_regions_internal (GdkWindowObject *private,
904 gboolean recalculate_clip,
905 gboolean recalculate_siblings,
906 gboolean recalculate_children)
910 GdkWindowObject *child;
911 cairo_region_t *new_clip, *old_clip_region_with_children;
912 gboolean clip_region_changed;
913 gboolean abs_pos_changed;
914 int old_abs_x, old_abs_y;
916 old_abs_x = private->abs_x;
917 old_abs_y = private->abs_y;
919 /* Update absolute position */
920 if (gdk_window_has_impl (private))
922 /* Native window starts here */
928 private->abs_x = private->parent->abs_x + private->x;
929 private->abs_y = private->parent->abs_y + private->y;
933 private->abs_x != old_abs_x ||
934 private->abs_y != old_abs_y;
936 /* Update clip region based on:
939 * siblings in parents above window
941 clip_region_changed = FALSE;
942 if (recalculate_clip)
944 if (private->viewable)
946 /* Calculate visible region (sans children) in parent window coords */
949 r.width = private->width;
950 r.height = private->height;
951 new_clip = cairo_region_create_rectangle (&r);
953 if (!gdk_window_is_toplevel (private))
955 cairo_region_intersect (new_clip, private->parent->clip_region);
957 /* Remove all overlapping children from parent.
958 * Unless we're all native, because then we don't need to take
959 * siblings into account since X does that clipping for us.
960 * This makes things like SWT that modify the raw X stacking
961 * order without GDKs knowledge work.
963 if (!_gdk_native_windows)
964 remove_child_area (private->parent, private, FALSE, new_clip);
967 /* Convert from parent coords to window coords */
968 cairo_region_translate (new_clip, -private->x, -private->y);
971 cairo_region_intersect (new_clip, private->shape);
974 new_clip = cairo_region_create ();
976 if (private->clip_region == NULL ||
977 !cairo_region_equal (private->clip_region, new_clip))
978 clip_region_changed = TRUE;
980 if (private->clip_region)
981 cairo_region_destroy (private->clip_region);
982 private->clip_region = new_clip;
984 old_clip_region_with_children = private->clip_region_with_children;
985 private->clip_region_with_children = cairo_region_copy (private->clip_region);
986 if (private->window_type != GDK_WINDOW_ROOT)
987 remove_child_area (private, NULL, FALSE, private->clip_region_with_children);
989 if (clip_region_changed ||
990 !cairo_region_equal (private->clip_region_with_children, old_clip_region_with_children))
991 private->clip_tag = new_region_tag ();
993 if (old_clip_region_with_children)
994 cairo_region_destroy (old_clip_region_with_children);
997 if (clip_region_changed)
999 GdkVisibilityState visibility;
1000 gboolean fully_visible;
1002 if (cairo_region_is_empty (private->clip_region))
1003 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1008 fully_visible = cairo_region_equal (private->clip_region,
1015 r.width = private->width;
1016 r.height = private->height;
1017 fully_visible = region_rect_equal (private->clip_region, &r);
1021 visibility = GDK_VISIBILITY_UNOBSCURED;
1023 visibility = GDK_VISIBILITY_PARTIAL;
1026 if (private->visibility != visibility)
1028 private->visibility = visibility;
1029 gdk_window_update_visibility (private);
1033 /* Update all children, recursively (except for root, where children are not exact). */
1034 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1035 private->window_type != GDK_WINDOW_ROOT)
1037 for (l = private->children; l; l = l->next)
1040 /* Only recalculate clip if the the clip region changed, otherwise
1041 * there is no way the child clip region could change (its has not e.g. moved)
1042 * Except if recalculate_children is set to force child updates
1044 recompute_visible_regions_internal (child,
1045 recalculate_clip && (clip_region_changed || recalculate_children),
1050 if (clip_region_changed &&
1051 should_apply_clip_as_shape (private))
1052 apply_clip_as_shape (private);
1054 if (recalculate_siblings &&
1055 !gdk_window_is_toplevel (private))
1057 /* If we moved a child window in parent or changed the stacking order, then we
1058 * need to recompute the visible area of all the other children in the parent
1060 for (l = private->parent->children; l; l = l->next)
1064 if (child != private)
1065 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1068 /* We also need to recompute the _with_children clip for the parent */
1069 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1072 if (private->cairo_surface && gdk_window_has_impl (private))
1074 GdkWindowImplIface *iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
1076 private->cairo_surface = iface->resize_cairo_surface (private->impl,
1077 private->cairo_surface,
1081 else if (private->cairo_surface)
1082 gdk_window_drop_cairo_surface (private);
1085 /* Call this when private has changed in one or more of these ways:
1089 * stacking order of window changed
1092 * It will recalculate abs_x/y and the clip regions
1094 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1095 * for recalculate_siblings. (Mostly used internally for the recursion)
1097 * If a child window was removed (and you can't use that child for
1098 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1101 recompute_visible_regions (GdkWindowObject *private,
1102 gboolean recalculate_siblings,
1103 gboolean recalculate_children)
1105 recompute_visible_regions_internal (private,
1107 recalculate_siblings,
1108 recalculate_children);
1112 _gdk_window_update_size (GdkWindow *window)
1114 recompute_visible_regions ((GdkWindowObject *)window, TRUE, FALSE);
1117 /* Find the native window that would be just above "child"
1118 * in the native stacking order if "child" was a native window
1119 * (it doesn't have to be native). If there is no such native
1120 * window inside this native parent then NULL is returned.
1121 * If child is NULL, find lowest native window in parent.
1123 static GdkWindowObject *
1124 find_native_sibling_above_helper (GdkWindowObject *parent,
1125 GdkWindowObject *child)
1132 l = g_list_find (parent->children, child);
1133 g_assert (l != NULL); /* Better be a child of its parent... */
1134 l = l->prev; /* Start looking at the one above the child */
1137 l = g_list_last (parent->children);
1139 for (; l != NULL; l = l->prev)
1143 if (gdk_window_has_impl (w))
1146 g_assert (parent != w);
1147 w = find_native_sibling_above_helper (w, NULL);
1156 static GdkWindowObject *
1157 find_native_sibling_above (GdkWindowObject *parent,
1158 GdkWindowObject *child)
1162 w = find_native_sibling_above_helper (parent, child);
1166 if (gdk_window_has_impl (parent))
1169 return find_native_sibling_above (parent->parent, parent);
1173 get_native_device_event_mask (GdkWindowObject *private,
1176 GdkEventMask event_mask;
1179 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1181 event_mask = private->event_mask;
1183 if (_gdk_native_windows ||
1184 private->window_type == GDK_WINDOW_ROOT ||
1185 private->window_type == GDK_WINDOW_FOREIGN)
1191 /* Do whatever the app asks to, since the app
1192 * may be asking for weird things for native windows,
1193 * but don't use motion hints as that may affect non-native
1194 * child windows that don't want it. Also, we need to
1195 * set all the app-specified masks since they will be picked
1196 * up by any implicit grabs (i.e. if they were not set as
1197 * native we would not get the events we need). */
1198 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1200 /* We need thse for all native windows so we can
1201 emulate events on children: */
1204 GDK_VISIBILITY_NOTIFY_MASK |
1205 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1207 /* Additionally we select for pointer and button events
1208 * for toplevels as we need to get these to emulate
1209 * them for non-native subwindows. Even though we don't
1210 * select on them for all native windows we will get them
1211 * as the events are propagated out to the first window
1212 * that select for them.
1213 * Not selecting for button press on all windows is an
1214 * important thing, because in X only one client can do
1215 * so, and we don't want to unexpectedly prevent another
1216 * client from doing it.
1218 * We also need to do the same if the app selects for button presses
1219 * because then we will get implicit grabs for this window, and the
1220 * event mask used for that grab is based on the rest of the mask
1221 * for the window, but we might need more events than this window
1222 * lists due to some non-native child window.
1224 if (gdk_window_is_toplevel (private) ||
1225 mask & GDK_BUTTON_PRESS_MASK)
1227 GDK_POINTER_MOTION_MASK |
1228 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1236 get_native_grab_event_mask (GdkEventMask grab_mask)
1238 /* Similar to the above but for pointer events only */
1240 GDK_POINTER_MOTION_MASK |
1241 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1242 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1245 ~GDK_POINTER_MOTION_HINT_MASK);
1249 get_native_event_mask (GdkWindowObject *private)
1251 return get_native_device_event_mask (private, NULL);
1254 /* Puts the native window in the right order wrt the other native windows
1255 * in the hierarchy, given the position it has in the client side data.
1256 * This is useful if some operation changed the stacking order.
1257 * This calls assumes the native window is now topmost in its native parent.
1260 sync_native_window_stack_position (GdkWindow *window)
1262 GdkWindowObject *above;
1263 GdkWindowObject *private;
1264 GdkWindowImplIface *impl_iface;
1265 GList listhead = {0};
1267 private = (GdkWindowObject *) window;
1268 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
1270 above = find_native_sibling_above (private->parent, private);
1273 listhead.data = window;
1274 impl_iface->restack_under ((GdkWindow *)above,
1281 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1282 * the default root window for the default display.
1283 * @attributes: attributes of the new window
1284 * @attributes_mask: mask indicating which fields in @attributes are valid
1286 * Creates a new #GdkWindow using the attributes from
1287 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1288 * more details. Note: to use this on displays other than the default
1289 * display, @parent must be specified.
1291 * Return value: (transfer none): the new #GdkWindow
1294 gdk_window_new (GdkWindow *parent,
1295 GdkWindowAttr *attributes,
1296 gint attributes_mask)
1299 GdkWindowObject *private;
1303 GdkEventMask event_mask;
1304 GdkWindow *real_parent;
1305 GdkDeviceManager *device_manager;
1307 g_return_val_if_fail (attributes != NULL, NULL);
1311 GDK_NOTE (MULTIHEAD,
1312 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1314 screen = gdk_screen_get_default ();
1315 parent = gdk_screen_get_root_window (screen);
1318 screen = gdk_window_get_screen (parent);
1320 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1322 if (GDK_WINDOW_DESTROYED (parent))
1324 g_warning ("gdk_window_new(): parent is destroyed\n");
1328 if (attributes->window_type == GDK_WINDOW_OFFSCREEN &&
1329 _gdk_native_windows)
1331 g_warning ("Offscreen windows not supported with native-windows gdk");
1335 window = g_object_new (GDK_TYPE_WINDOW, NULL);
1336 private = (GdkWindowObject *) window;
1338 /* Windows with a foreign parent are treated as if they are children
1339 * of the root window, except for actual creation.
1341 real_parent = parent;
1342 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1343 parent = gdk_screen_get_root_window (screen);
1345 private->parent = (GdkWindowObject *)parent;
1347 private->accept_focus = TRUE;
1348 private->focus_on_map = TRUE;
1350 if (attributes_mask & GDK_WA_X)
1355 if (attributes_mask & GDK_WA_Y)
1362 private->width = (attributes->width > 1) ? (attributes->width) : (1);
1363 private->height = (attributes->height > 1) ? (attributes->height) : (1);
1365 #ifdef GDK_WINDOWING_X11
1366 /* Work around a bug where Xorg refuses to map toplevel InputOnly windows
1367 * from an untrusted client: http://bugs.freedesktop.org/show_bug.cgi?id=6988
1369 if (attributes->wclass == GDK_INPUT_ONLY &&
1370 private->parent->window_type == GDK_WINDOW_ROOT &&
1371 !G_LIKELY (GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (parent))->trusted_client))
1373 g_warning ("Coercing GDK_INPUT_ONLY toplevel window to GDK_INPUT_OUTPUT to work around bug in Xorg server");
1374 attributes->wclass = GDK_INPUT_OUTPUT;
1378 if (attributes->wclass == GDK_INPUT_ONLY)
1380 /* Backwards compatiblity - we've always ignored
1381 * attributes->window_type for input-only windows
1384 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1385 private->window_type = GDK_WINDOW_TEMP;
1387 private->window_type = GDK_WINDOW_CHILD;
1390 private->window_type = attributes->window_type;
1393 switch (private->window_type)
1395 case GDK_WINDOW_TOPLEVEL:
1396 case GDK_WINDOW_TEMP:
1397 case GDK_WINDOW_OFFSCREEN:
1398 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1399 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1400 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1401 case GDK_WINDOW_CHILD:
1405 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
1409 if (attributes_mask & GDK_WA_VISUAL)
1410 private->visual = attributes->visual;
1412 private->visual = gdk_screen_get_system_visual (screen);
1414 private->event_mask = attributes->event_mask;
1416 if (attributes->wclass == GDK_INPUT_OUTPUT)
1418 private->input_only = FALSE;
1419 private->depth = private->visual->depth;
1421 /* XXX: Cache this somehow? */
1422 private->background = cairo_pattern_create_rgb (0, 0, 0);
1427 private->input_only = TRUE;
1430 if (private->parent)
1431 private->parent->children = g_list_prepend (private->parent->children, window);
1433 private->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
1434 (GDestroyNotify) gdk_cursor_unref);
1436 native = _gdk_native_windows; /* Default */
1437 if (private->parent->window_type == GDK_WINDOW_ROOT)
1438 native = TRUE; /* Always use native windows for toplevels */
1439 else if (!private->input_only &&
1440 (attributes_mask & GDK_WA_VISUAL &&
1441 attributes->visual != gdk_window_get_visual (GDK_WINDOW (private->parent))))
1442 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1444 if (gdk_window_is_offscreen (private))
1446 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1447 private->impl_window = private;
1451 event_mask = get_native_event_mask (private);
1453 /* Create the impl */
1454 _gdk_window_impl_new (window, real_parent, screen, event_mask, attributes, attributes_mask);
1455 private->impl_window = private;
1457 /* This will put the native window topmost in the native parent, which may
1458 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1459 if (!_gdk_window_has_impl (real_parent))
1460 sync_native_window_stack_position (window);
1464 private->impl_window = g_object_ref (private->parent->impl_window);
1465 private->impl = g_object_ref (private->impl_window->impl);
1468 recompute_visible_regions (private, TRUE, FALSE);
1470 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1471 (attributes->cursor) :
1474 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1475 g_signal_connect (device_manager, "device-removed",
1476 G_CALLBACK (device_removed_cb), window);
1482 is_parent_of (GdkWindow *parent,
1493 w = gdk_window_get_parent (w);
1500 change_impl (GdkWindowObject *private,
1501 GdkWindowObject *impl_window,
1505 GdkWindowObject *child;
1506 GdkDrawable *old_impl;
1507 GdkWindowObject *old_impl_window;
1509 old_impl = private->impl;
1510 old_impl_window = private->impl_window;
1511 if (private != impl_window)
1512 private->impl_window = g_object_ref (impl_window);
1514 private->impl_window = private;
1515 private->impl = g_object_ref (new);
1516 if (old_impl_window != private)
1517 g_object_unref (old_impl_window);
1518 g_object_unref (old_impl);
1520 for (l = private->children; l != NULL; l = l->next)
1524 if (child->impl == old_impl)
1525 change_impl (child, impl_window, new);
1530 reparent_to_impl (GdkWindowObject *private)
1533 GdkWindowObject *child;
1535 GdkWindowImplIface *impl_iface;
1537 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
1539 /* Enumerate in reverse order so we get the right order for the native
1540 windows (first in childrens list is topmost, and reparent places on top) */
1541 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1545 if (child->impl == private->impl)
1546 reparent_to_impl (child);
1549 show = impl_iface->reparent ((GdkWindow *)child,
1550 (GdkWindow *)private,
1551 child->x, child->y);
1553 gdk_window_show_unraised ((GdkWindow *)child);
1560 * gdk_window_reparent:
1561 * @window: a #GdkWindow
1562 * @new_parent: new parent to move @window into
1563 * @x: X location inside the new parent
1564 * @y: Y location inside the new parent
1566 * Reparents @window into the given @new_parent. The window being
1567 * reparented will be unmapped as a side effect.
1571 gdk_window_reparent (GdkWindow *window,
1572 GdkWindow *new_parent,
1576 GdkWindowObject *private;
1577 GdkWindowObject *new_parent_private;
1578 GdkWindowObject *old_parent;
1580 gboolean show, was_mapped, applied_clip_as_shape;
1581 gboolean do_reparent_to_impl;
1582 GdkEventMask old_native_event_mask;
1583 GdkWindowImplIface *impl_iface;
1585 g_return_if_fail (GDK_IS_WINDOW (window));
1586 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1587 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1589 if (GDK_WINDOW_DESTROYED (window) ||
1590 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1593 screen = gdk_window_get_screen (window);
1595 new_parent = gdk_screen_get_root_window (screen);
1597 private = (GdkWindowObject *) window;
1598 new_parent_private = (GdkWindowObject *)new_parent;
1600 /* No input-output children of input-only windows */
1601 if (new_parent_private->input_only && !private->input_only)
1604 /* Don't create loops in hierarchy */
1605 if (is_parent_of (window, new_parent))
1608 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1609 To make sure we're ok, just wipe it. */
1610 gdk_window_drop_cairo_surface (private);
1612 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
1613 old_parent = private->parent;
1615 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1618 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1619 if (new_parent_private->window_type == GDK_WINDOW_ROOT ||
1620 new_parent_private->window_type == GDK_WINDOW_FOREIGN)
1621 gdk_window_ensure_native (window);
1623 applied_clip_as_shape = should_apply_clip_as_shape (private);
1625 old_native_event_mask = 0;
1626 do_reparent_to_impl = FALSE;
1627 if (gdk_window_has_impl (private))
1629 old_native_event_mask = get_native_event_mask (private);
1631 show = impl_iface->reparent (window, new_parent, x, y);
1635 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1636 g_assert (new_parent_private->window_type != GDK_WINDOW_ROOT &&
1637 new_parent_private->window_type != GDK_WINDOW_FOREIGN);
1640 gdk_window_hide (window);
1642 do_reparent_to_impl = TRUE;
1643 change_impl (private,
1644 new_parent_private->impl_window,
1645 new_parent_private->impl);
1648 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1651 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1653 new_parent = gdk_screen_get_root_window (screen);
1654 new_parent_private = (GdkWindowObject *)new_parent;
1658 old_parent->children = g_list_remove (old_parent->children, window);
1660 private->parent = new_parent_private;
1664 new_parent_private->children = g_list_prepend (new_parent_private->children, window);
1666 /* Switch the window type as appropriate */
1668 switch (GDK_WINDOW_TYPE (new_parent))
1670 case GDK_WINDOW_ROOT:
1671 case GDK_WINDOW_FOREIGN:
1672 if (private->toplevel_window_type != -1)
1673 GDK_WINDOW_TYPE (window) = private->toplevel_window_type;
1674 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1675 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1677 case GDK_WINDOW_OFFSCREEN:
1678 case GDK_WINDOW_TOPLEVEL:
1679 case GDK_WINDOW_CHILD:
1680 case GDK_WINDOW_TEMP:
1681 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1682 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1684 /* Save the original window type so we can restore it if the
1685 * window is reparented back to be a toplevel
1687 private->toplevel_window_type = GDK_WINDOW_TYPE (window);
1688 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1692 /* We might have changed window type for a native windows, so we
1693 need to change the event mask too. */
1694 if (gdk_window_has_impl (private))
1696 GdkEventMask native_event_mask = get_native_event_mask (private);
1698 if (native_event_mask != old_native_event_mask)
1699 impl_iface->set_events (window, native_event_mask);
1702 _gdk_window_update_viewable (window);
1704 recompute_visible_regions (private, TRUE, FALSE);
1705 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1706 recompute_visible_regions (old_parent, FALSE, TRUE);
1708 /* We used to apply the clip as the shape, but no more.
1709 Reset this to the real shape */
1710 if (gdk_window_has_impl (private) &&
1711 applied_clip_as_shape &&
1712 !should_apply_clip_as_shape (private))
1713 apply_shape (private, private->shape);
1715 if (do_reparent_to_impl)
1716 reparent_to_impl (private);
1719 /* The reparent will have put the native window topmost in the native parent,
1720 * which may be wrong wrt other native windows in the non-native hierarchy,
1722 if (!gdk_window_has_impl (new_parent_private))
1723 sync_native_window_stack_position (window);
1727 gdk_window_show_unraised (window);
1729 _gdk_synthesize_crossing_events_for_geometry_change (window);
1733 temporary_disable_extension_events (GdkWindowObject *window)
1735 GdkWindowObject *child;
1739 if (window->extension_events != 0)
1741 g_object_set_data (G_OBJECT (window),
1742 "gdk-window-extension-events",
1743 GINT_TO_POINTER (window->extension_events));
1744 gdk_input_set_extension_events ((GdkWindow *)window, 0,
1745 GDK_EXTENSION_EVENTS_NONE);
1750 for (l = window->children; l != NULL; l = l->next)
1754 if (window->impl_window == child->impl_window)
1755 res |= temporary_disable_extension_events (child);
1762 reenable_extension_events (GdkWindowObject *window)
1764 GdkWindowObject *child;
1768 mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window),
1769 "gdk-window-extension-events"));
1773 /* We don't have the mode here, so we pass in cursor.
1774 This works with the current code since mode is not
1775 stored except as part of the mask, and cursor doesn't
1777 gdk_input_set_extension_events ((GdkWindow *)window, mask,
1778 GDK_EXTENSION_EVENTS_CURSOR);
1779 g_object_set_data (G_OBJECT (window),
1780 "gdk-window-extension-events",
1784 for (l = window->children; l != NULL; l = l->next)
1788 if (window->impl_window == child->impl_window)
1789 reenable_extension_events (window);
1794 * gdk_window_ensure_native:
1795 * @window: a #GdkWindow
1797 * Tries to ensure that there is a window-system native window for this
1798 * GdkWindow. This may fail in some situations, returning %FALSE.
1800 * Offscreen window and children of them can never have native windows.
1802 * Some backends may not support native child windows.
1804 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1809 gdk_window_ensure_native (GdkWindow *window)
1811 GdkWindowObject *private;
1812 GdkWindowObject *impl_window;
1813 GdkDrawable *new_impl, *old_impl;
1815 GdkWindowObject *above;
1817 GdkWindowImplIface *impl_iface;
1818 gboolean disabled_extension_events;
1820 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1822 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1823 GDK_WINDOW_DESTROYED (window))
1826 private = (GdkWindowObject *) window;
1828 impl_window = gdk_window_get_impl_window (private);
1830 if (gdk_window_is_offscreen (impl_window))
1831 return FALSE; /* native in offscreens not supported */
1833 if (impl_window == private)
1834 /* Already has an impl, and its not offscreen . */
1837 /* Need to create a native window */
1839 /* First we disable any extension events on the window or its
1840 descendants to handle the native input window moving */
1841 disabled_extension_events = FALSE;
1842 if (impl_window->input_window)
1843 disabled_extension_events = temporary_disable_extension_events (private);
1845 gdk_window_drop_cairo_surface (private);
1847 screen = gdk_window_get_screen (window);
1849 old_impl = private->impl;
1850 _gdk_window_impl_new (window, (GdkWindow *)private->parent,
1852 get_native_event_mask (private),
1854 new_impl = private->impl;
1856 private->impl = old_impl;
1857 change_impl (private, private, new_impl);
1859 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
1861 /* Native window creation will put the native window topmost in the
1862 * native parent, which may be wrong wrt the position of the previous
1863 * non-native window wrt to the other non-native children, so correct this.
1865 above = find_native_sibling_above (private->parent, private);
1868 listhead.data = window;
1869 listhead.prev = NULL;
1870 listhead.next = NULL;
1871 impl_iface->restack_under ((GdkWindow *)above, &listhead);
1874 recompute_visible_regions (private, FALSE, FALSE);
1876 /* The shape may not have been set, as the clip region doesn't actually
1877 change, so do it here manually */
1878 if (should_apply_clip_as_shape (private))
1879 apply_clip_as_shape (private);
1881 reparent_to_impl (private);
1883 if (!private->input_only)
1885 impl_iface->set_background (window, private->background);
1888 impl_iface->input_shape_combine_region (window,
1889 private->input_shape,
1892 if (gdk_window_is_viewable (window))
1893 impl_iface->show (window, FALSE);
1895 if (disabled_extension_events)
1896 reenable_extension_events (private);
1902 window_remove_filters (GdkWindow *window)
1904 GdkWindowObject *obj = (GdkWindowObject*) window;
1910 for (tmp_list = obj->filters; tmp_list; tmp_list = tmp_list->next)
1911 g_free (tmp_list->data);
1913 g_list_free (obj->filters);
1914 obj->filters = NULL;
1919 update_pointer_info_foreach (GdkDisplay *display,
1921 GdkPointerWindowInfo *pointer_info,
1924 GdkWindow *window = user_data;
1926 if (pointer_info->toplevel_under_pointer == window)
1928 g_object_unref (pointer_info->toplevel_under_pointer);
1929 pointer_info->toplevel_under_pointer = NULL;
1934 window_remove_from_pointer_info (GdkWindow *window,
1935 GdkDisplay *display)
1937 _gdk_display_pointer_info_foreach (display,
1938 update_pointer_info_foreach,
1943 * _gdk_window_destroy_hierarchy:
1944 * @window: a #GdkWindow
1945 * @recursing: If TRUE, then this is being called because a parent
1947 * @recursing_native: If TRUE, then this is being called because a native parent
1948 * was destroyed. This generally means that the call to the
1949 * windowing system to destroy the window can be omitted, since
1950 * it will be destroyed as a result of the parent being destroyed.
1951 * Unless @foreign_destroy.
1952 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1953 * external agency. The window has already been destroyed and no
1954 * windowing system calls should be made. (This may never happen
1955 * for some windowing systems.)
1957 * Internal function to destroy a window. Like gdk_window_destroy(),
1958 * but does not drop the reference count created by gdk_window_new().
1961 _gdk_window_destroy_hierarchy (GdkWindow *window,
1963 gboolean recursing_native,
1964 gboolean foreign_destroy)
1966 GdkWindowObject *private;
1967 GdkWindowObject *temp_private;
1968 GdkWindowImplIface *impl_iface;
1969 GdkWindow *temp_window;
1971 GdkDisplay *display;
1975 g_return_if_fail (GDK_IS_WINDOW (window));
1977 private = (GdkWindowObject*) window;
1979 if (GDK_WINDOW_DESTROYED (window))
1982 display = gdk_window_get_display (window);
1983 screen = gdk_window_get_screen (window);
1984 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1985 if (temp_window == window)
1986 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1989 switch (private->window_type)
1991 case GDK_WINDOW_ROOT:
1992 if (!screen->closed)
1994 g_error ("attempted to destroy root window");
1997 /* else fall thru */
1998 case GDK_WINDOW_TOPLEVEL:
1999 case GDK_WINDOW_CHILD:
2000 case GDK_WINDOW_TEMP:
2001 case GDK_WINDOW_FOREIGN:
2002 case GDK_WINDOW_OFFSCREEN:
2003 if (private->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
2005 /* Logically, it probably makes more sense to send
2006 * a "destroy yourself" message to the foreign window
2007 * whether or not it's in our hierarchy; but for historical
2008 * reasons, we only send "destroy yourself" messages to
2009 * foreign windows in our hierarchy.
2011 if (private->parent)
2012 _gdk_windowing_window_destroy_foreign (window);
2014 /* Also for historical reasons, we remove any filters
2015 * on a foreign window when it or a parent is destroyed;
2016 * this likely causes problems if two separate portions
2017 * of code are maintaining filter lists on a foreign window.
2019 window_remove_filters (window);
2023 if (private->parent)
2025 GdkWindowObject *parent_private = (GdkWindowObject *)private->parent;
2027 if (parent_private->children)
2028 parent_private->children = g_list_remove (parent_private->children, window);
2031 GDK_WINDOW_IS_MAPPED (window))
2033 recompute_visible_regions (private, TRUE, FALSE);
2034 gdk_window_invalidate_in_parent (private);
2038 gdk_window_free_paint_stack (window);
2040 if (private->background)
2042 cairo_pattern_destroy (private->background);
2043 private->background = NULL;
2046 if (private->window_type == GDK_WINDOW_FOREIGN)
2047 g_assert (private->children == NULL);
2050 children = tmp = private->children;
2051 private->children = NULL;
2055 temp_window = tmp->data;
2058 temp_private = (GdkWindowObject*) temp_window;
2060 _gdk_window_destroy_hierarchy (temp_window,
2062 recursing_native || gdk_window_has_impl (private),
2066 g_list_free (children);
2069 _gdk_window_clear_update_area (window);
2071 gdk_window_drop_cairo_surface (private);
2073 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
2075 if (gdk_window_has_impl (private))
2076 impl_iface->destroy (window, recursing_native,
2080 /* hide to make sure we repaint and break grabs */
2081 gdk_window_hide (window);
2084 private->state |= GDK_WINDOW_STATE_WITHDRAWN;
2085 private->parent = NULL;
2086 private->destroyed = TRUE;
2088 window_remove_filters (window);
2090 window_remove_from_pointer_info (window, display);
2092 if (private->clip_region)
2094 cairo_region_destroy (private->clip_region);
2095 private->clip_region = NULL;
2098 if (private->clip_region_with_children)
2100 cairo_region_destroy (private->clip_region_with_children);
2101 private->clip_region_with_children = NULL;
2104 if (private->outstanding_moves)
2106 g_list_foreach (private->outstanding_moves, (GFunc)gdk_window_region_move_free, NULL);
2107 g_list_free (private->outstanding_moves);
2108 private->outstanding_moves = NULL;
2116 * _gdk_window_destroy:
2117 * @window: a #GdkWindow
2118 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2119 * external agency. The window has already been destroyed and no
2120 * windowing system calls should be made. (This may never happen
2121 * for some windowing systems.)
2123 * Internal function to destroy a window. Like gdk_window_destroy(),
2124 * but does not drop the reference count created by gdk_window_new().
2127 _gdk_window_destroy (GdkWindow *window,
2128 gboolean foreign_destroy)
2130 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2134 * gdk_window_destroy:
2135 * @window: a #GdkWindow
2137 * Destroys the window system resources associated with @window and decrements @window's
2138 * reference count. The window system resources for all children of @window are also
2139 * destroyed, but the children's reference counts are not decremented.
2141 * Note that a window will not be destroyed automatically when its reference count
2142 * reaches zero. You must call this function yourself before that happens.
2146 gdk_window_destroy (GdkWindow *window)
2148 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2149 g_object_unref (window);
2153 * gdk_window_set_user_data:
2154 * @window: a #GdkWindow
2155 * @user_data: user data
2157 * For most purposes this function is deprecated in favor of
2158 * g_object_set_data(). However, for historical reasons GTK+ stores
2159 * the #GtkWidget that owns a #GdkWindow as user data on the
2160 * #GdkWindow. So, custom widget implementations should use
2161 * this function for that. If GTK+ receives an event for a #GdkWindow,
2162 * and the user data for the window is non-%NULL, GTK+ will assume the
2163 * user data is a #GtkWidget, and forward the event to that widget.
2167 gdk_window_set_user_data (GdkWindow *window,
2170 g_return_if_fail (GDK_IS_WINDOW (window));
2172 ((GdkWindowObject*)window)->user_data = user_data;
2176 * gdk_window_get_user_data:
2177 * @window: a #GdkWindow
2178 * @data: return location for user data
2180 * Retrieves the user data for @window, which is normally the widget
2181 * that @window belongs to. See gdk_window_set_user_data().
2185 gdk_window_get_user_data (GdkWindow *window,
2188 g_return_if_fail (GDK_IS_WINDOW (window));
2190 *data = ((GdkWindowObject*)window)->user_data;
2194 * gdk_window_get_window_type:
2195 * @window: a #GdkWindow
2197 * Gets the type of the window. See #GdkWindowType.
2199 * Return value: type of window
2202 gdk_window_get_window_type (GdkWindow *window)
2204 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2206 return GDK_WINDOW_TYPE (window);
2210 * gdk_window_get_visual:
2211 * @window: a #GdkWindow
2213 * Gets the #GdkVisual describing the pixel format of @window.
2215 * Return value: a #GdkVisual
2220 gdk_window_get_visual (GdkWindow *window)
2222 GdkWindowObject *private;
2224 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2226 private = (GdkWindowObject *) window;
2228 return private->visual;
2232 * gdk_window_get_screen:
2233 * @window: a #GdkWindow
2235 * Gets the #GdkScreen associated with a #GdkWindow.
2237 * Return value: the #GdkScreen associated with @window
2242 gdk_window_get_screen (GdkWindow *window)
2244 GdkWindowObject *private;
2246 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2248 private = (GdkWindowObject *) window;
2250 return gdk_visual_get_screen (private->visual);
2254 * gdk_window_get_display:
2255 * @window: a #GdkWindow
2257 * Gets the #GdkDisplay associated with a #GdkWindow.
2259 * Return value: the #GdkDisplay associated with @window
2264 gdk_window_get_display (GdkWindow *window)
2266 GdkWindowObject *private;
2268 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2270 private = (GdkWindowObject *) window;
2272 return gdk_screen_get_display (gdk_visual_get_screen (private->visual));
2275 * gdk_window_is_destroyed:
2276 * @window: a #GdkWindow
2278 * Check to see if a window is destroyed..
2280 * Return value: %TRUE if the window is destroyed
2285 gdk_window_is_destroyed (GdkWindow *window)
2287 return GDK_WINDOW_DESTROYED (window);
2291 to_embedder (GdkWindowObject *window,
2292 gdouble offscreen_x,
2293 gdouble offscreen_y,
2294 gdouble *embedder_x,
2295 gdouble *embedder_y)
2297 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2298 offscreen_x, offscreen_y,
2299 embedder_x, embedder_y);
2303 from_embedder (GdkWindowObject *window,
2306 gdouble *offscreen_x,
2307 gdouble *offscreen_y)
2309 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2310 embedder_x, embedder_y,
2311 offscreen_x, offscreen_y);
2315 * gdk_window_has_native:
2316 * @window: a #GdkWindow
2318 * Checks whether the window has a native window or not. Note that
2319 * you can use gdk_window_ensure_native() if a native window is needed.
2321 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2326 gdk_window_has_native (GdkWindow *window)
2330 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2332 w = GDK_WINDOW_OBJECT (window);
2334 return w->parent == NULL || w->parent->impl != w->impl;
2338 * gdk_window_get_position:
2339 * @window: a #GdkWindow
2340 * @x: X coordinate of window
2341 * @y: Y coordinate of window
2343 * Obtains the position of the window as reported in the
2344 * most-recently-processed #GdkEventConfigure. Contrast with
2345 * gdk_window_get_geometry() which queries the X server for the
2346 * current window position, regardless of which events have been
2347 * received or processed.
2349 * The position coordinates are relative to the window's parent window.
2353 gdk_window_get_position (GdkWindow *window,
2357 GdkWindowObject *obj;
2359 g_return_if_fail (GDK_IS_WINDOW (window));
2361 obj = (GdkWindowObject*) window;
2370 * gdk_window_get_parent:
2371 * @window: a #GdkWindow
2373 * Obtains the parent of @window, as known to GDK. Does not query the
2374 * X server; thus this returns the parent as passed to gdk_window_new(),
2375 * not the actual parent. This should never matter unless you're using
2376 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2377 * matter for toplevel windows, because the window manager may choose
2380 * Note that you should use gdk_window_get_effective_parent() when
2381 * writing generic code that walks up a window hierarchy, because
2382 * gdk_window_get_parent() will most likely not do what you expect if
2383 * there are offscreen windows in the hierarchy.
2385 * Return value: (transfer none): parent of @window
2388 gdk_window_get_parent (GdkWindow *window)
2390 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2392 return (GdkWindow*) ((GdkWindowObject*) window)->parent;
2396 * gdk_window_get_effective_parent:
2397 * @window: a #GdkWindow
2399 * Obtains the parent of @window, as known to GDK. Works like
2400 * gdk_window_get_parent() for normal windows, but returns the
2401 * window's embedder for offscreen windows.
2403 * See also: gdk_offscreen_window_get_embedder()
2405 * Return value: (transfer none): effective parent of @window
2410 gdk_window_get_effective_parent (GdkWindow *window)
2412 GdkWindowObject *obj;
2414 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2416 obj = (GdkWindowObject *)window;
2418 if (gdk_window_is_offscreen (obj))
2419 return gdk_offscreen_window_get_embedder (window);
2421 return (GdkWindow *) obj->parent;
2425 * gdk_window_get_toplevel:
2426 * @window: a #GdkWindow
2428 * Gets the toplevel window that's an ancestor of @window.
2430 * Any window type but %GDK_WINDOW_CHILD is considered a
2431 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2432 * has a root window as parent.
2434 * Note that you should use gdk_window_get_effective_toplevel() when
2435 * you want to get to a window's toplevel as seen on screen, because
2436 * gdk_window_get_toplevel() will most likely not do what you expect
2437 * if there are offscreen windows in the hierarchy.
2439 * Return value: (transfer none): the toplevel window containing @window
2442 gdk_window_get_toplevel (GdkWindow *window)
2444 GdkWindowObject *obj;
2446 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2448 obj = (GdkWindowObject *)window;
2450 while (obj->window_type == GDK_WINDOW_CHILD)
2452 if (gdk_window_is_toplevel (obj))
2457 return GDK_WINDOW (obj);
2461 * gdk_window_get_effective_toplevel:
2462 * @window: a #GdkWindow
2464 * Gets the toplevel window that's an ancestor of @window.
2466 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2467 * embedder as its parent, using gdk_window_get_effective_parent().
2469 * See also: gdk_offscreen_window_get_embedder()
2471 * Return value: (transfer none): the effective toplevel window containing @window
2476 gdk_window_get_effective_toplevel (GdkWindow *window)
2480 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2482 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2483 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2490 * gdk_window_get_children:
2491 * @window: a #GdkWindow
2493 * Gets the list of children of @window known to GDK.
2494 * This function only returns children created via GDK,
2495 * so for example it's useless when used with the root window;
2496 * it only returns windows an application created itself.
2498 * The returned list must be freed, but the elements in the
2501 * Return value: (transfer container) (element-type GdkWindow):
2502 * list of child windows inside @window
2505 gdk_window_get_children (GdkWindow *window)
2507 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2509 if (GDK_WINDOW_DESTROYED (window))
2512 return g_list_copy (GDK_WINDOW_OBJECT (window)->children);
2516 * gdk_window_peek_children:
2517 * @window: a #GdkWindow
2519 * Like gdk_window_get_children(), but does not copy the list of
2520 * children, so the list does not need to be freed.
2522 * Return value: (transfer none) (element-type GdkWindow):
2523 * a reference to the list of child windows in @window
2526 gdk_window_peek_children (GdkWindow *window)
2528 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2530 if (GDK_WINDOW_DESTROYED (window))
2533 return GDK_WINDOW_OBJECT (window)->children;
2537 * gdk_window_add_filter:
2538 * @window: a #GdkWindow
2539 * @function: filter callback
2540 * @data: data to pass to filter callback
2542 * Adds an event filter to @window, allowing you to intercept events
2543 * before they reach GDK. This is a low-level operation and makes it
2544 * easy to break GDK and/or GTK+, so you have to know what you're
2545 * doing. Pass %NULL for @window to get all events for all windows,
2546 * instead of events for a specific window.
2548 * See gdk_display_add_client_message_filter() if you are interested
2549 * in X ClientMessage events.
2552 gdk_window_add_filter (GdkWindow *window,
2553 GdkFilterFunc function,
2556 GdkWindowObject *private;
2558 GdkEventFilter *filter;
2560 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2562 private = (GdkWindowObject*) window;
2563 if (private && GDK_WINDOW_DESTROYED (window))
2566 /* Filters are for the native events on the native window, so
2567 ensure there is a native window. */
2569 gdk_window_ensure_native (window);
2572 tmp_list = private->filters;
2574 tmp_list = _gdk_default_filters;
2578 filter = (GdkEventFilter *)tmp_list->data;
2579 if ((filter->function == function) && (filter->data == data))
2581 tmp_list = tmp_list->next;
2584 filter = g_new (GdkEventFilter, 1);
2585 filter->function = function;
2586 filter->data = data;
2589 private->filters = g_list_append (private->filters, filter);
2591 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2595 * gdk_window_remove_filter:
2596 * @window: a #GdkWindow
2597 * @function: previously-added filter function
2598 * @data: user data for previously-added filter function
2600 * Remove a filter previously added with gdk_window_add_filter().
2604 gdk_window_remove_filter (GdkWindow *window,
2605 GdkFilterFunc function,
2608 GdkWindowObject *private;
2609 GList *tmp_list, *node;
2610 GdkEventFilter *filter;
2612 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2614 private = (GdkWindowObject*) window;
2617 tmp_list = private->filters;
2619 tmp_list = _gdk_default_filters;
2623 filter = (GdkEventFilter *)tmp_list->data;
2625 tmp_list = tmp_list->next;
2627 if ((filter->function == function) && (filter->data == data))
2630 private->filters = g_list_remove_link (private->filters, node);
2632 _gdk_default_filters = g_list_remove_link (_gdk_default_filters, node);
2633 g_list_free_1 (node);
2642 * gdk_screen_get_toplevel_windows:
2643 * @screen: The #GdkScreen where the toplevels are located.
2645 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2646 * A toplevel window is a child of the root window (see
2647 * gdk_get_default_root_window()).
2649 * The returned list should be freed with g_list_free(), but
2650 * its elements need not be freed.
2652 * Return value: (transfer container) (element-type GdkWindow):
2653 * list of toplevel windows, free with g_list_free()
2658 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2660 GdkWindow * root_window;
2661 GList *new_list = NULL;
2664 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2666 root_window = gdk_screen_get_root_window (screen);
2668 tmp_list = ((GdkWindowObject *)root_window)->children;
2671 GdkWindowObject *w = tmp_list->data;
2673 if (w->window_type != GDK_WINDOW_FOREIGN)
2674 new_list = g_list_prepend (new_list, w);
2675 tmp_list = tmp_list->next;
2682 * gdk_window_is_visible:
2683 * @window: a #GdkWindow
2685 * Checks whether the window has been mapped (with gdk_window_show() or
2686 * gdk_window_show_unraised()).
2688 * Return value: %TRUE if the window is mapped
2691 gdk_window_is_visible (GdkWindow *window)
2693 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2695 return GDK_WINDOW_IS_MAPPED (window);
2699 * gdk_window_is_viewable:
2700 * @window: a #GdkWindow
2702 * Check if the window and all ancestors of the window are
2703 * mapped. (This is not necessarily "viewable" in the X sense, since
2704 * we only check as far as we have GDK window parents, not to the root
2707 * Return value: %TRUE if the window is viewable
2710 gdk_window_is_viewable (GdkWindow *window)
2712 GdkWindowObject *private = (GdkWindowObject *)window;
2714 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2716 if (private->destroyed)
2719 return private->viewable;
2723 * gdk_window_get_state:
2724 * @window: a #GdkWindow
2726 * Gets the bitwise OR of the currently active window state flags,
2727 * from the #GdkWindowState enumeration.
2729 * Return value: window state bitfield
2732 gdk_window_get_state (GdkWindow *window)
2734 GdkWindowObject *private = (GdkWindowObject *)window;
2736 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2738 return private->state;
2741 static cairo_content_t
2742 gdk_window_get_content (GdkWindow *window)
2744 cairo_surface_t *surface;
2745 cairo_content_t content;
2747 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2749 surface = _gdk_drawable_ref_cairo_surface (window);
2750 content = cairo_surface_get_content (surface);
2751 cairo_surface_destroy (surface);
2756 /* This creates an empty "implicit" paint region for the impl window.
2757 * By itself this does nothing, but real paints to this window
2758 * or children of it can use this surface as backing to avoid allocating
2759 * multiple surfaces for subwindow rendering. When doing so they
2760 * add to the region of the implicit paint region, which will be
2761 * pushed to the window when the implicit paint region is ended.
2762 * Such paints should not copy anything to the window on paint end, but
2763 * should rely on the implicit paint end.
2764 * The implicit paint will be automatically ended if someone draws
2765 * directly to the window or a child window.
2768 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2770 GdkWindowObject *private = (GdkWindowObject *)window;
2771 GdkWindowPaint *paint;
2773 g_assert (gdk_window_has_impl (private));
2775 if (_gdk_native_windows)
2776 return FALSE; /* No need for implicit paints since we can't merge draws anyway */
2778 if (GDK_IS_PAINTABLE (private->impl))
2779 return FALSE; /* Implementation does double buffering */
2781 if (private->paint_stack != NULL ||
2782 private->implicit_paint != NULL)
2783 return FALSE; /* Don't stack implicit paints */
2785 if (private->outstanding_surfaces != 0)
2786 return FALSE; /* May conflict with direct drawing to cairo surface */
2788 /* Never do implicit paints for foreign windows, they don't need
2789 * double buffer combination since they have no client side children,
2790 * and creating surfaces for them is risky since they could disappear
2793 if (private->window_type == GDK_WINDOW_FOREIGN)
2796 paint = g_new (GdkWindowPaint, 1);
2797 paint->region = cairo_region_create (); /* Empty */
2798 paint->uses_implicit = FALSE;
2799 paint->flushed = FALSE;
2800 paint->surface = gdk_window_create_similar_surface (window,
2801 gdk_window_get_content (window),
2802 MAX (rect->width, 1),
2803 MAX (rect->height, 1));
2804 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2806 private->implicit_paint = paint;
2811 /* Ensure that all content related to this (sub)window is pushed to the
2812 native region. If there is an active paint then that area is not
2813 pushed, in order to not show partially finished double buffers. */
2815 gdk_window_flush_implicit_paint (GdkWindow *window)
2817 GdkWindowObject *private = (GdkWindowObject *)window;
2818 GdkWindowObject *impl_window;
2819 GdkWindowPaint *paint;
2820 cairo_region_t *region;
2823 impl_window = gdk_window_get_impl_window (private);
2824 if (impl_window->implicit_paint == NULL)
2827 paint = impl_window->implicit_paint;
2828 paint->flushed = TRUE;
2829 region = cairo_region_copy (private->clip_region_with_children);
2831 /* Don't flush active double buffers, as that may show partially done
2833 for (list = private->paint_stack; list != NULL; list = list->next)
2835 GdkWindowPaint *tmp_paint = list->data;
2837 cairo_region_subtract (region, tmp_paint->region);
2840 cairo_region_translate (region, -private->abs_x, -private->abs_y);
2841 cairo_region_intersect (region, paint->region);
2843 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2847 /* Remove flushed region from the implicit paint */
2848 cairo_region_subtract (paint->region, region);
2850 /* Some regions are valid, push these to window now */
2851 cr = gdk_cairo_create (private->impl);
2852 gdk_cairo_region (cr, region);
2854 cairo_set_source_surface (cr, paint->surface, 0, 0);
2855 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2860 cairo_region_destroy (region);
2863 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2865 gdk_window_end_implicit_paint (GdkWindow *window)
2867 GdkWindowObject *private = (GdkWindowObject *)window;
2868 GdkWindowPaint *paint;
2870 g_assert (gdk_window_has_impl (private));
2872 g_assert (private->implicit_paint != NULL);
2874 paint = private->implicit_paint;
2876 private->implicit_paint = NULL;
2878 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2882 /* Some regions are valid, push these to window now */
2883 cr = gdk_cairo_create (private->impl);
2884 gdk_cairo_region (cr, paint->region);
2886 cairo_set_source_surface (cr, paint->surface, 0, 0);
2887 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2892 cairo_region_destroy (paint->region);
2894 cairo_surface_destroy (paint->surface);
2899 * gdk_window_begin_paint_rect:
2900 * @window: a #GdkWindow
2901 * @rectangle: rectangle you intend to draw to
2903 * A convenience wrapper around gdk_window_begin_paint_region() which
2904 * creates a rectangular region for you. See
2905 * gdk_window_begin_paint_region() for details.
2909 gdk_window_begin_paint_rect (GdkWindow *window,
2910 const GdkRectangle *rectangle)
2912 cairo_region_t *region;
2914 g_return_if_fail (GDK_IS_WINDOW (window));
2916 region = cairo_region_create_rectangle (rectangle);
2917 gdk_window_begin_paint_region (window, region);
2918 cairo_region_destroy (region);
2922 * gdk_window_begin_paint_region:
2923 * @window: a #GdkWindow
2924 * @region: region you intend to draw to
2926 * Indicates that you are beginning the process of redrawing @region.
2927 * A backing store (offscreen buffer) large enough to contain @region
2928 * will be created. The backing store will be initialized with the
2929 * background color or background surface for @window. Then, all
2930 * drawing operations performed on @window will be diverted to the
2931 * backing store. When you call gdk_window_end_paint(), the backing
2932 * store will be copied to @window, making it visible onscreen. Only
2933 * the part of @window contained in @region will be modified; that is,
2934 * drawing operations are clipped to @region.
2936 * The net result of all this is to remove flicker, because the user
2937 * sees the finished product appear all at once when you call
2938 * gdk_window_end_paint(). If you draw to @window directly without
2939 * calling gdk_window_begin_paint_region(), the user may see flicker
2940 * as individual drawing operations are performed in sequence. The
2941 * clipping and background-initializing features of
2942 * gdk_window_begin_paint_region() are conveniences for the
2943 * programmer, so you can avoid doing that work yourself.
2945 * When using GTK+, the widget system automatically places calls to
2946 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2947 * emissions of the expose_event signal. That is, if you're writing an
2948 * expose event handler, you can assume that the exposed area in
2949 * #GdkEventExpose has already been cleared to the window background,
2950 * is already set as the clip region, and already has a backing store.
2951 * Therefore in most cases, application code need not call
2952 * gdk_window_begin_paint_region(). (You can disable the automatic
2953 * calls around expose events on a widget-by-widget basis by calling
2954 * gtk_widget_set_double_buffered().)
2956 * If you call this function multiple times before calling the
2957 * matching gdk_window_end_paint(), the backing stores are pushed onto
2958 * a stack. gdk_window_end_paint() copies the topmost backing store
2959 * onscreen, subtracts the topmost region from all other regions in
2960 * the stack, and pops the stack. All drawing operations affect only
2961 * the topmost backing store in the stack. One matching call to
2962 * gdk_window_end_paint() is required for each call to
2963 * gdk_window_begin_paint_region().
2967 gdk_window_begin_paint_region (GdkWindow *window,
2968 const cairo_region_t *region)
2970 #ifdef USE_BACKING_STORE
2971 GdkWindowObject *private = (GdkWindowObject *)window;
2972 GdkRectangle clip_box;
2973 GdkWindowPaint *paint, *implicit_paint;
2974 GdkWindowObject *impl_window;
2977 g_return_if_fail (GDK_IS_WINDOW (window));
2979 if (GDK_WINDOW_DESTROYED (window))
2982 if (GDK_IS_PAINTABLE (private->impl))
2984 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (private->impl);
2986 if (iface->begin_paint_region)
2987 iface->begin_paint_region ((GdkPaintable*)private->impl, window, region);
2992 impl_window = gdk_window_get_impl_window (private);
2993 implicit_paint = impl_window->implicit_paint;
2995 paint = g_new (GdkWindowPaint, 1);
2996 paint->region = cairo_region_copy (region);
2997 paint->region_tag = new_region_tag ();
2999 cairo_region_intersect (paint->region, private->clip_region_with_children);
3000 cairo_region_get_extents (paint->region, &clip_box);
3002 cairo_region_translate (paint->region, private->abs_x, private->abs_y);
3004 /* Mark the region as valid on the implicit paint */
3007 cairo_region_union (implicit_paint->region, paint->region);
3009 /* Convert back to normal coords */
3010 cairo_region_translate (paint->region, -private->abs_x, -private->abs_y);
3014 paint->uses_implicit = TRUE;
3015 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
3016 private->abs_x + clip_box.x,
3017 private->abs_y + clip_box.y,
3018 MAX (clip_box.width, 1),
3019 MAX (clip_box.height, 1));
3023 paint->uses_implicit = FALSE;
3024 paint->surface = gdk_window_create_similar_surface (window,
3025 gdk_window_get_content (window),
3026 MAX (clip_box.width, 1),
3027 MAX (clip_box.height, 1));
3029 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3031 for (list = private->paint_stack; list != NULL; list = list->next)
3033 GdkWindowPaint *tmp_paint = list->data;
3035 cairo_region_subtract (tmp_paint->region, paint->region);
3038 private->paint_stack = g_slist_prepend (private->paint_stack, paint);
3040 if (!cairo_region_is_empty (paint->region))
3042 gdk_window_clear_backing_region (window,
3046 #endif /* USE_BACKING_STORE */
3050 * gdk_window_end_paint:
3051 * @window: a #GdkWindow
3053 * Indicates that the backing store created by the most recent call to
3054 * gdk_window_begin_paint_region() should be copied onscreen and
3055 * deleted, leaving the next-most-recent backing store or no backing
3056 * store at all as the active paint region. See
3057 * gdk_window_begin_paint_region() for full details. It is an error to
3058 * call this function without a matching
3059 * gdk_window_begin_paint_region() first.
3063 gdk_window_end_paint (GdkWindow *window)
3065 #ifdef USE_BACKING_STORE
3066 GdkWindowObject *private = (GdkWindowObject *)window;
3067 GdkWindowObject *composited;
3068 GdkWindowPaint *paint;
3069 GdkRectangle clip_box;
3070 cairo_region_t *full_clip;
3072 g_return_if_fail (GDK_IS_WINDOW (window));
3074 if (GDK_WINDOW_DESTROYED (window))
3077 if (GDK_IS_PAINTABLE (private->impl))
3079 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (private->impl);
3081 if (iface->end_paint)
3082 iface->end_paint ((GdkPaintable*)private->impl);
3086 if (private->paint_stack == NULL)
3088 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3092 paint = private->paint_stack->data;
3094 private->paint_stack = g_slist_delete_link (private->paint_stack,
3095 private->paint_stack);
3097 cairo_region_get_extents (paint->region, &clip_box);
3099 if (!paint->uses_implicit)
3103 gdk_window_flush_outstanding_moves (window);
3105 full_clip = cairo_region_copy (private->clip_region_with_children);
3106 cairo_region_intersect (full_clip, paint->region);
3108 cr = gdk_cairo_create (window);
3109 cairo_set_source_surface (cr, paint->surface, 0, 0);
3110 gdk_cairo_region (cr, full_clip);
3114 cairo_region_destroy (full_clip);
3117 cairo_surface_destroy (paint->surface);
3118 cairo_region_destroy (paint->region);
3121 /* find a composited window in our hierarchy to signal its
3122 * parent to redraw, calculating the clip box as we go...
3124 * stop if parent becomes NULL since then we'd have nowhere
3125 * to draw (ie: 'composited' will always be non-NULL here).
3127 for (composited = private;
3129 composited = composited->parent)
3131 clip_box.x += composited->x;
3132 clip_box.y += composited->y;
3133 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3134 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3136 if (composited->composited)
3138 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3143 #endif /* USE_BACKING_STORE */
3147 gdk_window_free_paint_stack (GdkWindow *window)
3149 GdkWindowObject *private = (GdkWindowObject *)window;
3151 if (private->paint_stack)
3153 GSList *tmp_list = private->paint_stack;
3157 GdkWindowPaint *paint = tmp_list->data;
3159 if (tmp_list == private->paint_stack)
3160 cairo_surface_destroy (paint->surface);
3162 cairo_region_destroy (paint->region);
3165 tmp_list = tmp_list->next;
3168 g_slist_free (private->paint_stack);
3169 private->paint_stack = NULL;
3174 do_move_region_bits_on_impl (GdkWindowObject *impl_window,
3175 cairo_region_t *dest_region, /* In impl window coords */
3178 GdkWindowImplIface *impl_iface;
3180 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (impl_window->impl);
3182 impl_iface->translate ((GdkWindow *) impl_window, dest_region, dx, dy);
3185 static GdkWindowRegionMove *
3186 gdk_window_region_move_new (cairo_region_t *region,
3189 GdkWindowRegionMove *move;
3191 move = g_slice_new (GdkWindowRegionMove);
3192 move->dest_region = cairo_region_copy (region);
3200 gdk_window_region_move_free (GdkWindowRegionMove *move)
3202 cairo_region_destroy (move->dest_region);
3203 g_slice_free (GdkWindowRegionMove, move);
3207 append_move_region (GdkWindowObject *impl_window,
3208 cairo_region_t *new_dest_region,
3211 GdkWindowRegionMove *move, *old_move;
3212 cairo_region_t *new_total_region, *old_total_region;
3213 cairo_region_t *source_overlaps_destination;
3214 cairo_region_t *non_overwritten;
3215 gboolean added_move;
3218 if (cairo_region_is_empty (new_dest_region))
3221 /* In principle this could just append the move to the list of outstanding
3222 moves that will be replayed before drawing anything when we're handling
3223 exposes. However, we'd like to do a bit better since its commonly the case
3224 that we get multiple copies where A is copied to B and then B is copied
3225 to C, and we'd like to express this as a simple copy A to C operation. */
3227 /* We approach this by taking the new move and pushing it ahead of moves
3228 starting at the end of the list and stopping when its not safe to do so.
3229 It's not safe to push past a move if either the source of the new move
3230 is in the destination of the old move, or if the destination of the new
3231 move is in the source of the new move, or if the destination of the new
3232 move overlaps the destination of the old move. We simplify this by
3233 just comparing the total regions (src + dest) */
3234 new_total_region = cairo_region_copy (new_dest_region);
3235 cairo_region_translate (new_total_region, -dx, -dy);
3236 cairo_region_union (new_total_region, new_dest_region);
3239 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3244 old_total_region = cairo_region_copy (old_move->dest_region);
3245 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3246 cairo_region_union (old_total_region, old_move->dest_region);
3248 cairo_region_intersect (old_total_region, new_total_region);
3249 /* If these regions intersect then its not safe to push the
3250 new region before the old one */
3251 if (!cairo_region_is_empty (old_total_region))
3253 /* The area where the new moves source overlaps the old ones
3255 source_overlaps_destination = cairo_region_copy (new_dest_region);
3256 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3257 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3258 cairo_region_translate (source_overlaps_destination, dx, dy);
3260 /* We can do all sort of optimizations here, but to do things safely it becomes
3261 quite complicated. However, a very common case is that you copy something first,
3262 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3263 in the same direction). We'd like to detect this case and optimize it to one
3265 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3267 /* This means we might be able to replace the old move and the new one
3268 with the new one read from the old ones source, and a second copy of
3269 the non-overwritten parts of the old move. However, such a split
3270 is only valid if the source in the old move isn't overwritten
3271 by the destination of the new one */
3273 /* the new destination of old move if split is ok: */
3274 non_overwritten = cairo_region_copy (old_move->dest_region);
3275 cairo_region_subtract (non_overwritten, new_dest_region);
3276 /* move to source region */
3277 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3279 cairo_region_intersect (non_overwritten, new_dest_region);
3280 if (cairo_region_is_empty (non_overwritten))
3283 move = gdk_window_region_move_new (new_dest_region,
3287 impl_window->outstanding_moves =
3288 g_list_insert_before (impl_window->outstanding_moves,
3290 cairo_region_subtract (old_move->dest_region, new_dest_region);
3292 cairo_region_destroy (non_overwritten);
3295 cairo_region_destroy (source_overlaps_destination);
3296 cairo_region_destroy (old_total_region);
3299 cairo_region_destroy (old_total_region);
3302 cairo_region_destroy (new_total_region);
3306 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3309 impl_window->outstanding_moves =
3310 g_list_prepend (impl_window->outstanding_moves,
3313 impl_window->outstanding_moves =
3314 g_list_insert_before (impl_window->outstanding_moves,
3319 /* Moves bits and update area by dx/dy in impl window.
3320 Takes ownership of region to avoid copy (because we may change it) */
3322 move_region_on_impl (GdkWindowObject *impl_window,
3323 cairo_region_t *region, /* In impl window coords */
3326 if ((dx == 0 && dy == 0) ||
3327 cairo_region_is_empty (region))
3329 cairo_region_destroy (region);
3333 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3335 /* Move any old invalid regions in the copy source area by dx/dy */
3336 if (impl_window->update_area)
3338 cairo_region_t *update_area;
3340 update_area = cairo_region_copy (region);
3342 /* Convert from target to source */
3343 cairo_region_translate (update_area, -dx, -dy);
3344 cairo_region_intersect (update_area, impl_window->update_area);
3345 /* We only copy the area, so keep the old update area invalid.
3346 It would be safe to remove it too, as code that uses
3347 move_region_on_impl generally also invalidate the source
3348 area. However, it would just use waste cycles. */
3351 cairo_region_translate (update_area, dx, dy);
3352 cairo_region_union (impl_window->update_area, update_area);
3354 /* This area of the destination is now invalid,
3355 so no need to copy to it. */
3356 cairo_region_subtract (region, update_area);
3358 cairo_region_destroy (update_area);
3361 /* If we're currently exposing this window, don't copy to this
3362 destination, as it will be overdrawn when the expose is done,
3363 instead invalidate it and repaint later. */
3364 if (impl_window->implicit_paint)
3366 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3367 cairo_region_t *exposing;
3369 exposing = cairo_region_copy (implicit_paint->region);
3370 cairo_region_intersect (exposing, region);
3371 cairo_region_subtract (region, exposing);
3373 impl_window_add_update_area (impl_window, exposing);
3374 cairo_region_destroy (exposing);
3377 if (impl_window->outstanding_surfaces == 0) /* Enable flicker free handling of moves. */
3378 append_move_region (impl_window, region, dx, dy);
3380 do_move_region_bits_on_impl (impl_window,
3383 cairo_region_destroy (region);
3386 /* Flushes all outstanding changes to the window, call this
3387 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3390 gdk_window_flush_outstanding_moves (GdkWindow *window)
3392 GdkWindowObject *private;
3393 GdkWindowObject *impl_window;
3394 GList *l, *outstanding;
3395 GdkWindowRegionMove *move;
3397 private = (GdkWindowObject *) window;
3399 impl_window = gdk_window_get_impl_window (private);
3400 outstanding = impl_window->outstanding_moves;
3401 impl_window->outstanding_moves = NULL;
3403 for (l = outstanding; l != NULL; l = l->next)
3407 do_move_region_bits_on_impl (impl_window,
3408 move->dest_region, move->dx, move->dy);
3410 gdk_window_region_move_free (move);
3413 g_list_free (outstanding);
3418 * @window: a #GdkWindow
3420 * Flush all outstanding cached operations on a window, leaving the
3421 * window in a state which reflects all that has been drawn before.
3423 * Gdk uses multiple kinds of caching to get better performance and
3424 * nicer drawing. For instance, during exposes all paints to a window
3425 * using double buffered rendering are keep on a surface until the last
3426 * window has been exposed. It also delays window moves/scrolls until
3427 * as long as possible until next update to avoid tearing when moving
3430 * Normally this should be completely invisible to applications, as
3431 * we automatically flush the windows when required, but this might
3432 * be needed if you for instance mix direct native drawing with
3433 * gdk drawing. For Gtk widgets that don't use double buffering this
3434 * will be called automatically before sending the expose event.
3439 gdk_window_flush (GdkWindow *window)
3441 gdk_window_flush_outstanding_moves (window);
3442 gdk_window_flush_implicit_paint (window);
3445 /* If we're about to move/resize or otherwise change the
3446 * hierarchy of a client side window in an impl and we're
3447 * called from an expose event handler then we need to
3448 * flush any already painted parts of the implicit paint
3449 * that are not part of the current paint, as these may
3450 * be used when scrolling or may overdraw the changes
3451 * caused by the hierarchy change.
3454 gdk_window_flush_if_exposing (GdkWindow *window)
3456 GdkWindowObject *private;
3457 GdkWindowObject *impl_window;
3459 private = (GdkWindowObject *) window;
3460 impl_window = gdk_window_get_impl_window (private);
3462 /* If we're in an implicit paint (i.e. in an expose handler, flush
3463 all the already finished exposes to get things to an uptodate state. */
3464 if (impl_window->implicit_paint)
3465 gdk_window_flush (window);
3470 gdk_window_flush_recursive_helper (GdkWindowObject *window,
3473 GdkWindowObject *child;
3476 for (l = window->children; l != NULL; l = l->next)
3480 if (child->impl == impl)
3481 /* Same impl, ignore */
3482 gdk_window_flush_recursive_helper (child, impl);
3484 gdk_window_flush_recursive (child);
3489 gdk_window_flush_recursive (GdkWindowObject *window)
3491 gdk_window_flush ((GdkWindow *)window);
3492 gdk_window_flush_recursive_helper (window, window->impl);
3495 static cairo_region_t*
3496 gdk_window_get_clip_region (GdkDrawable *drawable)
3498 GdkWindowObject *private = (GdkWindowObject *)drawable;
3499 cairo_region_t *result;
3501 result = cairo_region_copy (private->clip_region);
3503 if (private->paint_stack)
3505 cairo_region_t *paint_region = cairo_region_create ();
3506 GSList *tmp_list = private->paint_stack;
3510 GdkWindowPaint *paint = tmp_list->data;
3512 cairo_region_union (paint_region, paint->region);
3514 tmp_list = tmp_list->next;
3517 cairo_region_intersect (result, paint_region);
3518 cairo_region_destroy (paint_region);
3524 static cairo_region_t*
3525 gdk_window_get_visible_region (GdkDrawable *drawable)
3527 GdkWindowObject *private = (GdkWindowObject*) drawable;
3529 return cairo_region_copy (private->clip_region);
3533 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint, int x_offset_cairo, int y_offset_cairo)
3535 GdkWindowObject *private = (GdkWindowObject *) window;
3536 GdkWindowObject *bg_private;
3537 cairo_pattern_t *pattern = NULL;
3538 int x_offset = 0, y_offset = 0;
3541 cr = cairo_create (paint->surface);
3543 for (bg_private = private; bg_private; bg_private = bg_private->parent)
3545 pattern = gdk_window_get_background_pattern ((GdkWindow *) bg_private);
3549 x_offset += bg_private->x;
3550 y_offset += bg_private->y;
3555 cairo_translate (cr, -x_offset, -y_offset);
3556 cairo_set_source (cr, pattern);
3557 cairo_translate (cr, x_offset, y_offset);
3560 cairo_set_source_rgb (cr, 0, 0, 0);
3566 gdk_window_clear_backing_region (GdkWindow *window,
3567 cairo_region_t *region)
3569 GdkWindowObject *private = (GdkWindowObject *)window;
3570 GdkWindowPaint *paint = private->paint_stack->data;
3571 cairo_region_t *clip;
3572 GdkRectangle clipbox;
3575 if (GDK_WINDOW_DESTROYED (window))
3578 cr = setup_backing_rect (window, paint, 0, 0);
3580 clip = cairo_region_copy (paint->region);
3581 cairo_region_intersect (clip, region);
3582 cairo_region_get_extents (clip, &clipbox);
3584 gdk_cairo_region (cr, clip);
3589 cairo_region_destroy (clip);
3593 gdk_window_clear_backing_region_direct (GdkWindow *window,
3594 cairo_region_t *region)
3596 GdkWindowObject *private = (GdkWindowObject *)window;
3597 GdkWindowPaint paint;
3598 cairo_region_t *clip;
3599 GdkRectangle clipbox;
3602 if (GDK_WINDOW_DESTROYED (window))
3605 paint.surface = _gdk_drawable_ref_cairo_surface (window);
3607 cr = setup_backing_rect (window, &paint, 0, 0);
3609 clip = cairo_region_copy (private->clip_region_with_children);
3610 cairo_region_intersect (clip, region);
3611 cairo_region_get_extents (clip, &clipbox);
3613 gdk_cairo_region (cr, clip);
3618 cairo_region_destroy (clip);
3619 cairo_surface_destroy (paint.surface);
3624 gdk_window_clear_region_internal (GdkWindow *window,
3625 cairo_region_t *region)
3627 GdkWindowObject *private = (GdkWindowObject *)window;
3629 if (private->paint_stack)
3630 gdk_window_clear_backing_region (window, region);
3632 gdk_window_clear_backing_region_direct (window, region);
3636 gdk_window_drop_cairo_surface (GdkWindowObject *private)
3638 if (private->cairo_surface)
3640 cairo_surface_finish (private->cairo_surface);
3641 cairo_surface_set_user_data (private->cairo_surface, &gdk_window_cairo_key,
3643 private->cairo_surface = NULL;
3648 gdk_window_cairo_surface_destroy (void *data)
3650 GdkWindowObject *private = (GdkWindowObject*) data;
3652 private->cairo_surface = NULL;
3653 private->impl_window->outstanding_surfaces--;
3656 static cairo_surface_t *
3657 gdk_window_create_cairo_surface (GdkDrawable *drawable,
3661 GdkWindowObject *private = GDK_WINDOW_OBJECT(drawable);
3662 cairo_surface_t *surface, *subsurface;
3664 surface =_gdk_drawable_ref_cairo_surface (private->impl);
3665 if (gdk_window_has_impl (private))
3668 subsurface = cairo_surface_create_for_rectangle (surface,
3673 cairo_surface_destroy (surface);
3678 static cairo_surface_t *
3679 gdk_window_ref_cairo_surface (GdkDrawable *drawable)
3681 GdkWindowObject *private = (GdkWindowObject*) drawable;
3682 cairo_surface_t *surface;
3684 if (private->paint_stack)
3686 GdkWindowPaint *paint = private->paint_stack->data;
3688 surface = paint->surface;
3689 cairo_surface_reference (surface);
3694 /* This will be drawing directly to the window, so flush implicit paint */
3695 gdk_window_flush ((GdkWindow *)drawable);
3697 if (!private->cairo_surface)
3699 private->cairo_surface = _gdk_drawable_create_cairo_surface (drawable,
3703 if (private->cairo_surface)
3705 private->impl_window->outstanding_surfaces++;
3707 cairo_surface_set_user_data (private->cairo_surface, &gdk_window_cairo_key,
3708 drawable, gdk_window_cairo_surface_destroy);
3712 cairo_surface_reference (private->cairo_surface);
3714 surface = private->cairo_surface;
3721 gdk_window_set_cairo_clip (GdkDrawable *drawable,
3724 GdkWindowObject *private = (GdkWindowObject*) drawable;
3726 if (!private->paint_stack)
3728 cairo_reset_clip (cr);
3731 cairo_identity_matrix (cr);
3733 cairo_new_path (cr);
3734 gdk_cairo_region (cr, private->clip_region_with_children);
3741 GdkWindowPaint *paint = private->paint_stack->data;
3743 /* Only needs to clip to region if piggybacking
3744 on an implicit paint */
3745 cairo_reset_clip (cr);
3746 if (paint->uses_implicit)
3749 cairo_identity_matrix (cr);
3751 cairo_new_path (cr);
3752 gdk_cairo_region (cr, paint->region);
3760 /* Code for dirty-region queueing
3762 static GSList *update_windows = NULL;
3763 static guint update_idle = 0;
3764 static gboolean debug_updates = FALSE;
3766 static inline gboolean
3767 gdk_window_is_ancestor (GdkWindow *window,
3768 GdkWindow *ancestor)
3772 GdkWindow *parent = (GdkWindow*) ((GdkWindowObject*) window)->parent;
3774 if (parent == ancestor)
3784 gdk_window_add_update_window (GdkWindow *window)
3787 GSList *prev = NULL;
3788 gboolean has_ancestor_in_list = FALSE;
3790 for (tmp = update_windows; tmp; tmp = tmp->next)
3792 GdkWindowObject *parent = GDK_WINDOW_OBJECT (window)->parent;
3794 /* check if tmp is an ancestor of "window"; if it is, set a
3795 * flag indicating that all following windows are either
3796 * children of "window" or from a differen hierarchy
3798 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3799 has_ancestor_in_list = TRUE;
3801 /* insert in reverse stacking order when adding around siblings,
3802 * so processing updates properly paints over lower stacked windows
3804 if (parent == GDK_WINDOW_OBJECT (tmp->data)->parent)
3806 gint index = g_list_index (parent->children, window);
3807 for (; tmp && parent == GDK_WINDOW_OBJECT (tmp->data)->parent; tmp = tmp->next)
3809 gint sibling_index = g_list_index (parent->children, tmp->data);
3810 if (index > sibling_index)
3814 /* here, tmp got advanced past all lower stacked siblings */
3815 tmp = g_slist_prepend (tmp, window);
3819 update_windows = tmp;
3823 /* if "window" has an ancestor in the list and tmp is one of
3824 * "window's" children, insert "window" before tmp
3826 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3828 tmp = g_slist_prepend (tmp, window);
3833 update_windows = tmp;
3837 /* if we're at the end of the list and had an ancestor it it,
3838 * append to the list
3840 if (! tmp->next && has_ancestor_in_list)
3842 tmp = g_slist_append (tmp, window);
3849 /* if all above checks failed ("window" is from a different
3850 * hierarchy than what is already in the list) or the list is
3853 update_windows = g_slist_prepend (update_windows, window);
3857 gdk_window_remove_update_window (GdkWindow *window)
3859 update_windows = g_slist_remove (update_windows, window);
3863 gdk_window_update_idle (gpointer data)
3865 gdk_window_process_all_updates ();
3871 gdk_window_is_toplevel_frozen (GdkWindow *window)
3873 GdkWindowObject *toplevel;
3875 toplevel = (GdkWindowObject *)gdk_window_get_toplevel (window);
3877 return toplevel->update_and_descendants_freeze_count > 0;
3881 gdk_window_schedule_update (GdkWindow *window)
3884 (GDK_WINDOW_OBJECT (window)->update_freeze_count ||
3885 gdk_window_is_toplevel_frozen (window)))
3890 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3891 gdk_window_update_idle,
3896 _gdk_window_process_updates_recurse (GdkWindow *window,
3897 cairo_region_t *expose_region)
3899 GdkWindowObject *private = (GdkWindowObject *)window;
3900 GdkWindowObject *child;
3901 cairo_region_t *child_region;
3903 GList *l, *children;
3905 if (cairo_region_is_empty (expose_region))
3908 if (gdk_window_is_offscreen (private->impl_window) &&
3909 private == private->impl_window)
3910 _gdk_window_add_damage ((GdkWindow *) private->impl_window, expose_region);
3912 /* Make this reentrancy safe for expose handlers freeing windows */
3913 children = g_list_copy (private->children);
3914 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3916 /* Iterate over children, starting at topmost */
3917 for (l = children; l != NULL; l = l->next)
3921 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3924 /* Ignore offscreen children, as they don't draw in their parent and
3925 * don't take part in the clipping */
3926 if (gdk_window_is_offscreen (child))
3931 r.width = child->width;
3932 r.height = child->height;
3934 child_region = cairo_region_create_rectangle (&r);
3937 /* Adjust shape region to parent window coords */
3938 cairo_region_translate (child->shape, child->x, child->y);
3939 cairo_region_intersect (child_region, child->shape);
3940 cairo_region_translate (child->shape, -child->x, -child->y);
3943 if (child->impl == private->impl)
3945 /* Client side child, expose */
3946 cairo_region_intersect (child_region, expose_region);
3947 cairo_region_subtract (expose_region, child_region);
3948 cairo_region_translate (child_region, -child->x, -child->y);
3949 _gdk_window_process_updates_recurse ((GdkWindow *)child, child_region);
3953 /* Native child, just remove area from expose region */
3954 cairo_region_subtract (expose_region, child_region);
3956 cairo_region_destroy (child_region);
3959 g_list_foreach (children, (GFunc)g_object_unref, NULL);
3960 g_list_free (children);
3962 if (!cairo_region_is_empty (expose_region) &&
3963 !private->destroyed)
3965 if (private->event_mask & GDK_EXPOSURE_MASK)
3969 event.expose.type = GDK_EXPOSE;
3970 event.expose.window = g_object_ref (window);
3971 event.expose.send_event = FALSE;
3972 event.expose.count = 0;
3973 event.expose.region = expose_region;
3974 cairo_region_get_extents (expose_region, &event.expose.area);
3976 (*_gdk_event_func) (&event, _gdk_event_data);
3978 g_object_unref (window);
3980 else if (private->window_type != GDK_WINDOW_FOREIGN)
3982 /* No exposure mask set, so nothing will be drawn, the
3983 * app relies on the background being what it specified
3984 * for the window. So, we need to clear this manually.
3986 * For foreign windows if expose is not set that generally
3987 * means some other client paints them, so don't clear
3990 * We use begin/end_paint around the clear so that we can
3991 * piggyback on the implicit paint */
3993 gdk_window_begin_paint_region (window, expose_region);
3994 gdk_window_clear_region_internal (window, expose_region);
3995 gdk_window_end_paint (window);
4000 /* Process and remove any invalid area on the native window by creating
4001 * expose events for the window and all non-native descendants.
4002 * Also processes any outstanding moves on the window before doing
4003 * any drawing. Note that its possible to have outstanding moves without
4004 * any invalid area as we use the update idle mechanism to coalesce
4005 * multiple moves as well as multiple invalidations.
4008 gdk_window_process_updates_internal (GdkWindow *window)
4010 GdkWindowObject *private = (GdkWindowObject *)window;
4011 GdkWindowImplIface *impl_iface;
4012 gboolean save_region = FALSE;
4013 GdkRectangle clip_box;
4015 /* Ensure the window lives while updating it */
4016 g_object_ref (window);
4018 /* If an update got queued during update processing, we can get a
4019 * window in the update queue that has an empty update_area.
4022 if (private->update_area)
4024 cairo_region_t *update_area = private->update_area;
4025 private->update_area = NULL;
4027 if (_gdk_event_func && gdk_window_is_viewable (window))
4029 cairo_region_t *expose_region;
4030 gboolean end_implicit;
4032 /* Clip to part visible in toplevel */
4033 cairo_region_intersect (update_area, private->clip_region);
4037 /* Make sure we see the red invalid area before redrawing. */
4038 gdk_display_sync (gdk_window_get_display (window));
4042 /* At this point we will be completely redrawing all of update_area.
4043 * If we have any outstanding moves that end up moving stuff inside
4044 * this area we don't actually need to move that as that part would
4045 * be overdrawn by the expose anyway. So, in order to copy less data
4046 * we remove these areas from the outstanding moves.
4048 if (private->outstanding_moves)
4050 GdkWindowRegionMove *move;
4051 cairo_region_t *remove;
4054 remove = cairo_region_copy (update_area);
4055 /* We iterate backwards, starting from the state that would be
4056 if we had applied all the moves. */
4057 for (l = g_list_last (private->outstanding_moves); l != NULL; l = prev)
4062 /* Don't need this area */
4063 cairo_region_subtract (move->dest_region, remove);
4065 /* However if any of the destination we do need has a source
4066 in the updated region we do need that as a destination for
4067 the earlier moves */
4068 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4069 cairo_region_subtract (remove, move->dest_region);
4071 if (cairo_region_is_empty (move->dest_region))
4073 gdk_window_region_move_free (move);
4074 private->outstanding_moves =
4075 g_list_delete_link (private->outstanding_moves, l);
4077 else /* move back */
4078 cairo_region_translate (move->dest_region, move->dx, move->dy);
4080 cairo_region_destroy (remove);
4083 /* By now we a set of window moves that should be applied, and then
4084 * an update region that should be repainted. A trivial implementation
4085 * would just do that in order, however in order to get nicer drawing
4086 * we do some tricks:
4088 * First of all, each subwindow expose may be double buffered by
4089 * itself (depending on widget setting) via
4090 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4091 * creating a single surface the size of the invalid area on the
4092 * native window which all the individual normal paints will draw
4093 * into. This way in the normal case there will be only one surface
4094 * allocated and only once surface draw done for all the windows
4095 * in this native window.
4096 * There are a couple of reasons this may fail, for instance, some
4097 * backends (like quartz) do its own double buffering, so we disable
4098 * gdk double buffering there. Secondly, some subwindow could be
4099 * non-double buffered and draw directly to the window outside a
4100 * begin/end_paint pair. That will be lead to a gdk_window_flush
4101 * which immediately executes all outstanding moves and paints+removes
4102 * the implicit paint (further paints will allocate their own surfaces).
4104 * Secondly, in the case of implicit double buffering we expose all
4105 * the child windows into the implicit surface before we execute
4106 * the outstanding moves. This way we minimize the time between
4107 * doing the moves and rendering the new update area, thus minimizing
4108 * flashing. Of course, if any subwindow is non-double buffered we
4109 * well flush earlier than that.
4111 * Thirdly, after having done the outstanding moves we queue an
4112 * "antiexpose" on the area that will be drawn by the expose, which
4113 * means that any invalid region on the native window side before
4114 * the first expose drawing operation will be discarded, as it
4115 * has by then been overdrawn with valid data. This means we can
4116 * avoid doing the unnecessary repaint any outstanding expose events.
4119 cairo_region_get_extents (update_area, &clip_box);
4120 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4121 expose_region = cairo_region_copy (update_area);
4124 /* Rendering is not double buffered by gdk, do outstanding
4125 * moves and queue antiexposure immediately. No need to do
4127 gdk_window_flush_outstanding_moves (window);
4128 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
4129 save_region = impl_iface->queue_antiexpose (window, update_area);
4132 /* Render the invalid areas to the implicit paint, by sending exposes.
4133 * May flush if non-double buffered widget draw. */
4134 _gdk_windowing_window_process_updates_recurse (window, expose_region);
4138 /* Do moves right before exposes are rendered to the window */
4139 gdk_window_flush_outstanding_moves (window);
4141 /* By this time we know that any outstanding expose for this
4142 * area is invalid and we can avoid it, so queue an antiexpose.
4143 * However, it may be that due to an non-double buffered expose
4144 * we have already started drawing to the window, so it would
4145 * be to late to anti-expose now. Since this is merely an
4146 * optimization we just avoid doing it at all in that case.
4148 if (private->implicit_paint != NULL &&
4149 !private->implicit_paint->flushed)
4151 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
4152 save_region = impl_iface->queue_antiexpose (window, update_area);
4155 gdk_window_end_implicit_paint (window);
4157 cairo_region_destroy (expose_region);
4160 cairo_region_destroy (update_area);
4163 if (private->outstanding_moves)
4165 /* Flush any outstanding moves, may happen if we moved a window but got
4166 no actual invalid area */
4167 gdk_window_flush_outstanding_moves (window);
4170 g_object_unref (window);
4174 flush_all_displays (void)
4176 GSList *displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4179 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
4180 gdk_display_flush (tmp_list->data);
4182 g_slist_free (displays);
4185 /* Currently it is not possible to override
4186 * gdk_window_process_all_updates in the same manner as
4187 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4188 * by implementing the GdkPaintable interface. If in the future a
4189 * backend would need this, the right solution would be to add a
4190 * method to GdkDisplay that can be optionally
4191 * NULL. gdk_window_process_all_updates can then walk the list of open
4192 * displays and call the mehod.
4196 * gdk_window_process_all_updates:
4198 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4199 * in the application.
4203 gdk_window_process_all_updates (void)
4205 GSList *old_update_windows = update_windows;
4206 GSList *tmp_list = update_windows;
4207 static gboolean in_process_all_updates = FALSE;
4208 static gboolean got_recursive_update = FALSE;
4210 if (in_process_all_updates)
4212 /* We can't do this now since that would recurse, so
4213 delay it until after the recursion is done. */
4214 got_recursive_update = TRUE;
4219 in_process_all_updates = TRUE;
4220 got_recursive_update = FALSE;
4223 g_source_remove (update_idle);
4225 update_windows = NULL;
4228 _gdk_windowing_before_process_all_updates ();
4230 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4234 GdkWindowObject *private = (GdkWindowObject *)tmp_list->data;
4236 if (!GDK_WINDOW_DESTROYED (tmp_list->data))
4238 if (private->update_freeze_count ||
4239 gdk_window_is_toplevel_frozen (tmp_list->data))
4240 gdk_window_add_update_window ((GdkWindow *) private);
4242 gdk_window_process_updates_internal (tmp_list->data);
4245 g_object_unref (tmp_list->data);
4246 tmp_list = tmp_list->next;
4249 g_slist_free (old_update_windows);
4251 flush_all_displays ();
4253 _gdk_windowing_after_process_all_updates ();
4255 in_process_all_updates = FALSE;
4257 /* If we ignored a recursive call, schedule a
4258 redraw now so that it eventually happens,
4259 otherwise we could miss an update if nothing
4260 else schedules an update. */
4261 if (got_recursive_update && !update_idle)
4263 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4264 gdk_window_update_idle,
4269 * gdk_window_process_updates:
4270 * @window: a #GdkWindow
4271 * @update_children: whether to also process updates for child windows
4273 * Sends one or more expose events to @window. The areas in each
4274 * expose event will cover the entire update area for the window (see
4275 * gdk_window_invalidate_region() for details). Normally GDK calls
4276 * gdk_window_process_all_updates() on your behalf, so there's no
4277 * need to call this function unless you want to force expose events
4278 * to be delivered immediately and synchronously (vs. the usual
4279 * case, where GDK delivers them in an idle handler). Occasionally
4280 * this is useful to produce nicer scrolling behavior, for example.
4284 gdk_window_process_updates (GdkWindow *window,
4285 gboolean update_children)
4287 GdkWindowObject *private = (GdkWindowObject *)window;
4288 GdkWindowObject *impl_window;
4290 g_return_if_fail (GDK_IS_WINDOW (window));
4292 if (GDK_WINDOW_DESTROYED (window))
4295 /* Make sure the window lives during the expose callouts */
4296 g_object_ref (window);
4298 impl_window = gdk_window_get_impl_window (private);
4299 if ((impl_window->update_area ||
4300 impl_window->outstanding_moves) &&
4301 !impl_window->update_freeze_count &&
4302 !gdk_window_is_toplevel_frozen (window) &&
4304 /* Don't recurse into process_updates_internal, we'll
4305 * do the update later when idle instead. */
4306 impl_window->implicit_paint == NULL)
4308 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4309 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4312 if (update_children)
4314 /* process updates in reverse stacking order so composition or
4315 * painting over achieves the desired effect for offscreen windows
4317 GList *node, *children;
4319 children = g_list_copy (private->children);
4320 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4322 for (node = g_list_last (children); node; node = node->prev)
4324 gdk_window_process_updates (node->data, TRUE);
4325 g_object_unref (node->data);
4328 g_list_free (children);
4331 g_object_unref (window);
4335 gdk_window_invalidate_rect_full (GdkWindow *window,
4336 const GdkRectangle *rect,
4337 gboolean invalidate_children,
4340 GdkRectangle window_rect;
4341 cairo_region_t *region;
4342 GdkWindowObject *private = (GdkWindowObject *)window;
4344 g_return_if_fail (GDK_IS_WINDOW (window));
4346 if (GDK_WINDOW_DESTROYED (window))
4349 if (private->input_only || !private->viewable)
4356 window_rect.width = private->width;
4357 window_rect.height = private->height;
4358 rect = &window_rect;
4361 region = cairo_region_create_rectangle (rect);
4362 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4363 cairo_region_destroy (region);
4367 * gdk_window_invalidate_rect:
4368 * @window: a #GdkWindow
4369 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4371 * @invalidate_children: whether to also invalidate child windows
4373 * A convenience wrapper around gdk_window_invalidate_region() which
4374 * invalidates a rectangular region. See
4375 * gdk_window_invalidate_region() for details.
4378 gdk_window_invalidate_rect (GdkWindow *window,
4379 const GdkRectangle *rect,
4380 gboolean invalidate_children)
4382 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4386 draw_ugly_color (GdkWindow *window,
4387 const cairo_region_t *region)
4391 cr = gdk_cairo_create (window);
4392 /* Draw ugly color all over the newly-invalid region */
4393 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4394 gdk_cairo_region (cr, region);
4401 impl_window_add_update_area (GdkWindowObject *impl_window,
4402 cairo_region_t *region)
4404 if (impl_window->update_area)
4405 cairo_region_union (impl_window->update_area, region);
4408 gdk_window_add_update_window ((GdkWindow *)impl_window);
4409 impl_window->update_area = cairo_region_copy (region);
4410 gdk_window_schedule_update ((GdkWindow *)impl_window);
4414 /* clear_bg controls if the region will be cleared to
4415 * the background pattern if the exposure mask is not
4416 * set for the window, whereas this might not otherwise be
4417 * done (unless necessary to emulate background settings).
4418 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4419 * need to clear the background, such as when exposing the area beneath a
4420 * hidden or moved window, but not when an app requests repaint or when the
4421 * windowing system exposes a newly visible area (because then the windowing
4422 * system has already cleared the area).
4425 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4426 const cairo_region_t *region,
4428 GdkWindowChildFunc child_func,
4431 GdkWindowObject *private = (GdkWindowObject *)window;
4432 GdkWindowObject *impl_window;
4433 cairo_region_t *visible_region;
4436 g_return_if_fail (GDK_IS_WINDOW (window));
4438 if (GDK_WINDOW_DESTROYED (window))
4441 if (private->input_only ||
4442 !private->viewable ||
4443 cairo_region_is_empty (region) ||
4444 private->window_type == GDK_WINDOW_ROOT)
4447 visible_region = gdk_drawable_get_visible_region (window);
4448 cairo_region_intersect (visible_region, region);
4450 tmp_list = private->children;
4453 GdkWindowObject *child = tmp_list->data;
4455 if (!child->input_only)
4457 cairo_region_t *child_region;
4458 GdkRectangle child_rect;
4460 child_rect.x = child->x;
4461 child_rect.y = child->y;
4462 child_rect.width = child->width;
4463 child_rect.height = child->height;
4464 child_region = cairo_region_create_rectangle (&child_rect);
4466 /* remove child area from the invalid area of the parent */
4467 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4468 !child->composited &&
4469 !gdk_window_is_offscreen (child))
4470 cairo_region_subtract (visible_region, child_region);
4472 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4474 cairo_region_t *tmp = cairo_region_copy (region);
4476 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4477 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4478 cairo_region_intersect (child_region, tmp);
4480 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4481 child_region, clear_bg, child_func, user_data);
4483 cairo_region_destroy (tmp);
4486 cairo_region_destroy (child_region);
4489 tmp_list = tmp_list->next;
4492 impl_window = gdk_window_get_impl_window (private);
4494 if (!cairo_region_is_empty (visible_region) ||
4495 /* Even if we're not exposing anything, make sure we process
4496 idles for windows with outstanding moves */
4497 (impl_window->outstanding_moves != NULL &&
4498 impl_window->update_area == NULL))
4501 draw_ugly_color (window, region);
4503 /* Convert to impl coords */
4504 cairo_region_translate (visible_region, private->abs_x, private->abs_y);
4506 /* Only invalidate area if app requested expose events or if
4507 we need to clear the area (by request or to emulate background
4508 clearing for non-native windows or native windows with no support
4509 for window backgrounds */
4510 if (private->event_mask & GDK_EXPOSURE_MASK ||
4511 clear_bg == CLEAR_BG_ALL ||
4512 clear_bg == CLEAR_BG_WINCLEARED)
4513 impl_window_add_update_area (impl_window, visible_region);
4516 cairo_region_destroy (visible_region);
4520 * gdk_window_invalidate_maybe_recurse:
4521 * @window: a #GdkWindow
4522 * @region: a #cairo_region_t
4523 * @child_func: function to use to decide if to recurse to a child,
4524 * %NULL means never recurse.
4525 * @user_data: data passed to @child_func
4527 * Adds @region to the update area for @window. The update area is the
4528 * region that needs to be redrawn, or "dirty region." The call
4529 * gdk_window_process_updates() sends one or more expose events to the
4530 * window, which together cover the entire update area. An
4531 * application would normally redraw the contents of @window in
4532 * response to those expose events.
4534 * GDK will call gdk_window_process_all_updates() on your behalf
4535 * whenever your program returns to the main loop and becomes idle, so
4536 * normally there's no need to do that manually, you just need to
4537 * invalidate regions that you know should be redrawn.
4539 * The @child_func parameter controls whether the region of
4540 * each child window that intersects @region will also be invalidated.
4541 * Only children for which @child_func returns TRUE will have the area
4545 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4546 const cairo_region_t *region,
4547 GdkWindowChildFunc child_func,
4550 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4551 child_func, user_data);
4555 true_predicate (GdkWindow *window,
4562 gdk_window_invalidate_region_full (GdkWindow *window,
4563 const cairo_region_t *region,
4564 gboolean invalidate_children,
4567 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4568 invalidate_children ?
4569 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4574 * gdk_window_invalidate_region:
4575 * @window: a #GdkWindow
4576 * @region: a #cairo_region_t
4577 * @invalidate_children: %TRUE to also invalidate child windows
4579 * Adds @region to the update area for @window. The update area is the
4580 * region that needs to be redrawn, or "dirty region." The call
4581 * gdk_window_process_updates() sends one or more expose events to the
4582 * window, which together cover the entire update area. An
4583 * application would normally redraw the contents of @window in
4584 * response to those expose events.
4586 * GDK will call gdk_window_process_all_updates() on your behalf
4587 * whenever your program returns to the main loop and becomes idle, so
4588 * normally there's no need to do that manually, you just need to
4589 * invalidate regions that you know should be redrawn.
4591 * The @invalidate_children parameter controls whether the region of
4592 * each child window that intersects @region will also be invalidated.
4593 * If %FALSE, then the update area for child windows will remain
4594 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4595 * fine grained control over which children are invalidated.
4598 gdk_window_invalidate_region (GdkWindow *window,
4599 const cairo_region_t *region,
4600 gboolean invalidate_children)
4602 gdk_window_invalidate_maybe_recurse (window, region,
4603 invalidate_children ?
4604 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4609 * _gdk_window_invalidate_for_expose:
4610 * @window: a #GdkWindow
4611 * @region: a #cairo_region_t
4613 * Adds @region to the update area for @window. The update area is the
4614 * region that needs to be redrawn, or "dirty region." The call
4615 * gdk_window_process_updates() sends one or more expose events to the
4616 * window, which together cover the entire update area. An
4617 * application would normally redraw the contents of @window in
4618 * response to those expose events.
4620 * GDK will call gdk_window_process_all_updates() on your behalf
4621 * whenever your program returns to the main loop and becomes idle, so
4622 * normally there's no need to do that manually, you just need to
4623 * invalidate regions that you know should be redrawn.
4625 * This version of invalidation is used when you recieve expose events
4626 * from the native window system. It exposes the native window, plus
4627 * any non-native child windows (but not native child windows, as those would
4628 * have gotten their own expose events).
4631 _gdk_window_invalidate_for_expose (GdkWindow *window,
4632 cairo_region_t *region)
4634 GdkWindowObject *private = (GdkWindowObject *) window;
4635 GdkWindowRegionMove *move;
4636 cairo_region_t *move_region;
4639 /* Any invalidations comming from the windowing system will
4640 be in areas that may be moved by outstanding moves,
4641 so we need to modify the expose region correspondingly,
4642 otherwise we would expose in the wrong place, as the
4643 outstanding moves will be copied before we draw the
4645 for (l = private->outstanding_moves; l != NULL; l = l->next)
4649 /* covert to move source region */
4650 move_region = cairo_region_copy (move->dest_region);
4651 cairo_region_translate (move_region, -move->dx, -move->dy);
4653 /* Move area of region that intersects with move source
4654 by dx, dy of the move*/
4655 cairo_region_intersect (move_region, region);
4656 cairo_region_subtract (region, move_region);
4657 cairo_region_translate (move_region, move->dx, move->dy);
4658 cairo_region_union (region, move_region);
4660 cairo_region_destroy (move_region);
4663 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4664 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4670 * gdk_window_get_update_area:
4671 * @window: a #GdkWindow
4673 * Transfers ownership of the update area from @window to the caller
4674 * of the function. That is, after calling this function, @window will
4675 * no longer have an invalid/dirty region; the update area is removed
4676 * from @window and handed to you. If a window has no update area,
4677 * gdk_window_get_update_area() returns %NULL. You are responsible for
4678 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4680 * Return value: the update area for @window
4683 gdk_window_get_update_area (GdkWindow *window)
4685 GdkWindowObject *private = (GdkWindowObject *)window;
4686 GdkWindowObject *impl_window;
4687 cairo_region_t *tmp_region;
4689 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4691 impl_window = gdk_window_get_impl_window (private);
4693 if (impl_window->update_area)
4695 tmp_region = cairo_region_copy (private->clip_region_with_children);
4696 /* Convert to impl coords */
4697 cairo_region_translate (tmp_region, private->abs_x, private->abs_y);
4698 cairo_region_intersect (tmp_region, impl_window->update_area);
4700 if (cairo_region_is_empty (tmp_region))
4702 cairo_region_destroy (tmp_region);
4707 cairo_region_subtract (impl_window->update_area, tmp_region);
4709 if (cairo_region_is_empty (impl_window->update_area) &&
4710 impl_window->outstanding_moves == NULL)
4712 cairo_region_destroy (impl_window->update_area);
4713 impl_window->update_area = NULL;
4715 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4718 /* Convert from impl coords */
4719 cairo_region_translate (tmp_region, -private->abs_x, -private->abs_y);
4729 * _gdk_window_clear_update_area:
4730 * @window: a #GdkWindow.
4732 * Internal function to clear the update area for a window. This
4733 * is called when the window is hidden or destroyed.
4736 _gdk_window_clear_update_area (GdkWindow *window)
4738 GdkWindowObject *private = (GdkWindowObject *)window;
4740 g_return_if_fail (GDK_IS_WINDOW (window));
4742 if (private->update_area)
4744 gdk_window_remove_update_window (window);
4746 cairo_region_destroy (private->update_area);
4747 private->update_area = NULL;
4752 * gdk_window_freeze_updates:
4753 * @window: a #GdkWindow
4755 * Temporarily freezes a window such that it won't receive expose
4756 * events. The window will begin receiving expose events again when
4757 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4758 * has been called more than once, gdk_window_thaw_updates() must be called
4759 * an equal number of times to begin processing exposes.
4762 gdk_window_freeze_updates (GdkWindow *window)
4764 GdkWindowObject *private = (GdkWindowObject *)window;
4765 GdkWindowObject *impl_window;
4767 g_return_if_fail (GDK_IS_WINDOW (window));
4769 impl_window = gdk_window_get_impl_window (private);
4770 impl_window->update_freeze_count++;
4774 * gdk_window_thaw_updates:
4775 * @window: a #GdkWindow
4777 * Thaws a window frozen with gdk_window_freeze_updates().
4780 gdk_window_thaw_updates (GdkWindow *window)
4782 GdkWindowObject *private = (GdkWindowObject *)window;
4783 GdkWindowObject *impl_window;
4785 g_return_if_fail (GDK_IS_WINDOW (window));
4787 impl_window = gdk_window_get_impl_window (private);
4789 g_return_if_fail (impl_window->update_freeze_count > 0);
4791 if (--impl_window->update_freeze_count == 0)
4792 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4796 * gdk_window_freeze_toplevel_updates_libgtk_only:
4797 * @window: a #GdkWindow
4799 * Temporarily freezes a window and all its descendants such that it won't
4800 * receive expose events. The window will begin receiving expose events
4801 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4802 * gdk_window_freeze_toplevel_updates_libgtk_only()
4803 * has been called more than once,
4804 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4805 * an equal number of times to begin processing exposes.
4807 * This function is not part of the GDK public API and is only
4811 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4813 GdkWindowObject *private = (GdkWindowObject *)window;
4815 g_return_if_fail (GDK_IS_WINDOW (window));
4816 g_return_if_fail (private->window_type != GDK_WINDOW_CHILD);
4818 private->update_and_descendants_freeze_count++;
4822 * gdk_window_thaw_toplevel_updates_libgtk_only:
4823 * @window: a #GdkWindow
4825 * Thaws a window frozen with
4826 * gdk_window_freeze_toplevel_updates_libgtk_only().
4828 * This function is not part of the GDK public API and is only
4832 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4834 GdkWindowObject *private = (GdkWindowObject *)window;
4836 g_return_if_fail (GDK_IS_WINDOW (window));
4837 g_return_if_fail (private->window_type != GDK_WINDOW_CHILD);
4838 g_return_if_fail (private->update_and_descendants_freeze_count > 0);
4840 private->update_and_descendants_freeze_count--;
4842 gdk_window_schedule_update (window);
4846 * gdk_window_set_debug_updates:
4847 * @setting: %TRUE to turn on update debugging
4849 * With update debugging enabled, calls to
4850 * gdk_window_invalidate_region() clear the invalidated region of the
4851 * screen to a noticeable color, and GDK pauses for a short time
4852 * before sending exposes to windows during
4853 * gdk_window_process_updates(). The net effect is that you can see
4854 * the invalid region for each window and watch redraws as they
4855 * occur. This allows you to diagnose inefficiencies in your application.
4857 * In essence, because the GDK rendering model prevents all flicker,
4858 * if you are redrawing the same region 400 times you may never
4859 * notice, aside from noticing a speed problem. Enabling update
4860 * debugging causes GTK to flicker slowly and noticeably, so you can
4861 * see exactly what's being redrawn when, in what order.
4863 * The --gtk-debug=updates command line option passed to GTK+ programs
4864 * enables this debug option at application startup time. That's
4865 * usually more useful than calling gdk_window_set_debug_updates()
4866 * yourself, though you might want to use this function to enable
4867 * updates sometime after application startup time.
4871 gdk_window_set_debug_updates (gboolean setting)
4873 debug_updates = setting;
4877 * gdk_window_constrain_size:
4878 * @geometry: a #GdkGeometry structure
4879 * @flags: a mask indicating what portions of @geometry are set
4880 * @width: desired width of window
4881 * @height: desired height of the window
4882 * @new_width: location to store resulting width
4883 * @new_height: location to store resulting height
4885 * Constrains a desired width and height according to a
4886 * set of geometry hints (such as minimum and maximum size).
4889 gdk_window_constrain_size (GdkGeometry *geometry,
4896 /* This routine is partially borrowed from fvwm.
4898 * Copyright 1993, Robert Nation
4899 * You may use this code for any purpose, as long as the original
4900 * copyright remains in the source code and all documentation
4902 * which in turn borrows parts of the algorithm from uwm
4905 gint min_height = 0;
4906 gint base_width = 0;
4907 gint base_height = 0;
4910 gint max_width = G_MAXINT;
4911 gint max_height = G_MAXINT;
4913 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4915 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4917 base_width = geometry->base_width;
4918 base_height = geometry->base_height;
4919 min_width = geometry->min_width;
4920 min_height = geometry->min_height;
4922 else if (flags & GDK_HINT_BASE_SIZE)
4924 base_width = geometry->base_width;
4925 base_height = geometry->base_height;
4926 min_width = geometry->base_width;
4927 min_height = geometry->base_height;
4929 else if (flags & GDK_HINT_MIN_SIZE)
4931 base_width = geometry->min_width;
4932 base_height = geometry->min_height;
4933 min_width = geometry->min_width;
4934 min_height = geometry->min_height;
4937 if (flags & GDK_HINT_MAX_SIZE)
4939 max_width = geometry->max_width ;
4940 max_height = geometry->max_height;
4943 if (flags & GDK_HINT_RESIZE_INC)
4945 xinc = MAX (xinc, geometry->width_inc);
4946 yinc = MAX (yinc, geometry->height_inc);
4949 /* clamp width and height to min and max values
4951 width = CLAMP (width, min_width, max_width);
4952 height = CLAMP (height, min_height, max_height);
4954 /* shrink to base + N * inc
4956 width = base_width + FLOOR (width - base_width, xinc);
4957 height = base_height + FLOOR (height - base_height, yinc);
4959 /* constrain aspect ratio, according to:
4962 * min_aspect <= -------- <= max_aspect
4966 if (flags & GDK_HINT_ASPECT &&
4967 geometry->min_aspect > 0 &&
4968 geometry->max_aspect > 0)
4972 if (geometry->min_aspect * height > width)
4974 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4975 if (height - delta >= min_height)
4979 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4980 if (width + delta <= max_width)
4985 if (geometry->max_aspect * height < width)
4987 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4988 if (width - delta >= min_width)
4992 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4993 if (height + delta <= max_height)
5002 *new_height = height;
5006 * gdk_window_get_pointer:
5007 * @window: a #GdkWindow
5008 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
5009 * return the X coordinate
5010 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
5011 * return the Y coordinate
5012 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
5015 * Obtains the current pointer position and modifier state.
5016 * The position is given in coordinates relative to the upper left
5017 * corner of @window.
5019 * Return value: (transfer none): the window containing the pointer (as with
5020 * gdk_window_at_pointer()), or %NULL if the window containing the
5021 * pointer isn't known to GDK
5023 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
5026 gdk_window_get_pointer (GdkWindow *window,
5029 GdkModifierType *mask)
5031 GdkDisplay *display;
5033 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5035 display = gdk_window_get_display (window);
5037 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
5041 * gdk_window_get_device_position:
5042 * @window: a #GdkWindow.
5043 * @device: #GdkDevice to query to.
5044 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5045 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5046 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5048 * Obtains the current device position and modifier state.
5049 * The position is given in coordinates relative to the upper left
5050 * corner of @window.
5052 * Return value: (transfer none): The window underneath @device (as with
5053 * gdk_display_get_window_at_device_position()), or %NULL if the
5054 * window is not known to GDK.
5059 gdk_window_get_device_position (GdkWindow *window,
5063 GdkModifierType *mask)
5065 GdkDisplay *display;
5067 GdkModifierType tmp_mask;
5070 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5071 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5076 display = gdk_window_get_display (window);
5077 child = display->device_hooks->window_get_device_position (display, device, window,
5078 &tmp_x, &tmp_y, &tmp_mask);
5087 _gdk_display_enable_motion_hints (display, device);
5093 * gdk_window_at_pointer:
5094 * @win_x: (out) (allow-none): return location for origin of the window under the pointer
5095 * @win_y: (out) (allow-none): return location for origin of the window under the pointer
5097 * Obtains the window underneath the mouse pointer, returning the
5098 * location of that window in @win_x, @win_y. Returns %NULL if the
5099 * window under the mouse pointer is not known to GDK (if the window
5100 * belongs to another application and a #GdkWindow hasn't been created
5101 * for it with gdk_window_foreign_new())
5103 * NOTE: For multihead-aware widgets or applications use
5104 * gdk_display_get_window_at_pointer() instead.
5106 * Return value: (transfer none): window under the mouse pointer
5108 * Deprecated: 3.0: Use gdk_display_get_window_at_device_position() instead.
5111 gdk_window_at_pointer (gint *win_x,
5114 return gdk_display_get_window_at_pointer (gdk_display_get_default (), win_x, win_y);
5118 * gdk_get_default_root_window:
5120 * Obtains the root window (parent all other windows are inside)
5121 * for the default display and screen.
5123 * Return value: the default root window
5126 gdk_get_default_root_window (void)
5128 return gdk_screen_get_root_window (gdk_screen_get_default ());
5132 * gdk_window_foreign_new:
5133 * @anid: a native window handle.
5135 * Wraps a native window for the default display in a #GdkWindow.
5136 * This may fail if the window has been destroyed.
5138 * For example in the X backend, a native window handle is an Xlib
5141 * Return value: the newly-created #GdkWindow wrapper for the
5142 * native window or %NULL if the window has been destroyed.
5145 gdk_window_foreign_new (GdkNativeWindow anid)
5147 return gdk_window_foreign_new_for_display (gdk_display_get_default (), anid);
5151 get_all_native_children (GdkWindowObject *private,
5154 GdkWindowObject *child;
5157 for (l = private->children; l != NULL; l = l->next)
5161 if (gdk_window_has_impl (child))
5162 *native = g_list_prepend (*native, child);
5164 get_all_native_children (child, native);
5170 gdk_window_raise_internal (GdkWindow *window)
5172 GdkWindowObject *private = (GdkWindowObject *)window;
5173 GdkWindowObject *parent = private->parent;
5174 GdkWindowObject *above;
5175 GList *native_children;
5177 GdkWindowImplIface *impl_iface;
5181 parent->children = g_list_remove (parent->children, window);
5182 parent->children = g_list_prepend (parent->children, window);
5185 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5186 /* Just do native raise for toplevels */
5187 if (gdk_window_is_toplevel (private) ||
5188 /* The restack_under codepath should work correctly even if the parent
5189 is native, but it relies on the order of ->children to be correct,
5190 and some apps like SWT reorder the x windows without gdks knowledge,
5191 so we use raise directly in order to make these behave as before
5192 when using native windows */
5193 (gdk_window_has_impl (private) && gdk_window_has_impl (parent)))
5195 impl_iface->raise (window);
5197 else if (gdk_window_has_impl (private))
5199 above = find_native_sibling_above (parent, private);
5202 listhead.data = window;
5203 listhead.next = NULL;
5204 listhead.prev = NULL;
5205 impl_iface->restack_under ((GdkWindow *)above,
5209 impl_iface->raise (window);
5213 native_children = NULL;
5214 get_all_native_children (private, &native_children);
5215 if (native_children != NULL)
5217 above = find_native_sibling_above (parent, private);
5220 impl_iface->restack_under ((GdkWindow *)above,
5224 /* Right order, since native_children is bottom-topmost first */
5225 for (l = native_children; l != NULL; l = l->next)
5226 impl_iface->raise (l->data);
5229 g_list_free (native_children);
5235 /* Returns TRUE If the native window was mapped or unmapped */
5237 set_viewable (GdkWindowObject *w,
5240 GdkWindowObject *child;
5241 GdkWindowImplIface *impl_iface;
5244 if (w->viewable == val)
5250 recompute_visible_regions (w, FALSE, FALSE);
5252 for (l = w->children; l != NULL; l = l->next)
5256 if (GDK_WINDOW_IS_MAPPED (child) &&
5257 child->window_type != GDK_WINDOW_FOREIGN)
5258 set_viewable (child, val);
5261 if (!_gdk_native_windows &&
5262 gdk_window_has_impl (w) &&
5263 w->window_type != GDK_WINDOW_FOREIGN &&
5264 !gdk_window_is_toplevel (w))
5266 /* For most native windows we show/hide them not when they are
5267 * mapped/unmapped, because that may not produce the correct results.
5268 * For instance, if a native window have a non-native parent which is
5269 * hidden, but its native parent is viewable then showing the window
5270 * would make it viewable to X but its not viewable wrt the non-native
5271 * hierarchy. In order to handle this we track the gdk side viewability
5272 * and only map really viewable windows.
5274 * There are two exceptions though:
5276 * For foreign windows we don't want ever change the mapped state
5277 * except when explicitly done via gdk_window_show/hide, as this may
5278 * cause problems for client owning the foreign window when its window
5279 * is suddenly mapped or unmapped.
5281 * For toplevel windows embedded in a foreign window (e.g. a plug)
5282 * we sometimes synthesize a map of a window, but the native
5283 * window is really shown by the embedder, so we don't want to
5284 * do the show ourselves. We can't really tell this case from the normal
5285 * toplevel show as such toplevels are seen by gdk as parents of the
5286 * root window, so we make an exception for all toplevels.
5288 * Also, when in GDK_NATIVE_WINDOW mode we never need to play games
5289 * like this, so we just always show/hide directly.
5292 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (w->impl);
5294 impl_iface->show ((GdkWindow *)w, FALSE);
5296 impl_iface->hide ((GdkWindow *)w);
5304 /* Returns TRUE If the native window was mapped or unmapped */
5306 _gdk_window_update_viewable (GdkWindow *window)
5308 GdkWindowObject *priv = (GdkWindowObject *)window;
5311 if (priv->window_type == GDK_WINDOW_FOREIGN ||
5312 priv->window_type == GDK_WINDOW_ROOT)
5314 else if (gdk_window_is_toplevel (priv) ||
5315 priv->parent->viewable)
5316 viewable = GDK_WINDOW_IS_MAPPED (priv);
5320 return set_viewable (priv, viewable);
5324 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5326 GdkWindowObject *private;
5327 GdkWindowImplIface *impl_iface;
5328 gboolean was_mapped, was_viewable;
5331 g_return_if_fail (GDK_IS_WINDOW (window));
5333 private = (GdkWindowObject *) window;
5334 if (private->destroyed)
5337 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5338 was_viewable = private->viewable;
5341 /* Keep children in (reverse) stacking order */
5342 gdk_window_raise_internal (window);
5344 if (gdk_window_has_impl (private))
5347 gdk_synthesize_window_state (window,
5348 GDK_WINDOW_STATE_WITHDRAWN,
5356 did_show = _gdk_window_update_viewable (window);
5358 /* If it was already viewable the backend show op won't be called, call it
5359 again to ensure things happen right if the mapped tracking was not right
5360 for e.g. a foreign window.
5361 Dunno if this is strictly needed but its what happened pre-csw.
5362 Also show if not done by gdk_window_update_viewable. */
5363 if (gdk_window_has_impl (private) && (was_viewable || !did_show))
5365 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5366 impl_iface->show ((GdkWindow *)private,
5367 !did_show ? was_mapped : TRUE);
5370 if (!was_mapped && !gdk_window_has_impl (private))
5372 if (private->event_mask & GDK_STRUCTURE_MASK)
5373 _gdk_make_event (GDK_WINDOW (private), GDK_MAP, NULL, FALSE);
5375 if (private->parent && private->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5376 _gdk_make_event (GDK_WINDOW (private), GDK_MAP, NULL, FALSE);
5379 if (!was_mapped || raise)
5381 recompute_visible_regions (private, TRUE, FALSE);
5383 /* If any decendants became visible we need to send visibility notify */
5384 gdk_window_update_visibility_recursively (private, NULL);
5386 if (gdk_window_is_viewable (window))
5388 _gdk_synthesize_crossing_events_for_geometry_change (window);
5389 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5395 * gdk_window_show_unraised:
5396 * @window: a #GdkWindow
5398 * Shows a #GdkWindow onscreen, but does not modify its stacking
5399 * order. In contrast, gdk_window_show() will raise the window
5400 * to the top of the window stack.
5402 * On the X11 platform, in Xlib terms, this function calls
5403 * XMapWindow() (it also updates some internal GDK state, which means
5404 * that you can't really use XMapWindow() directly on a GDK window).
5407 gdk_window_show_unraised (GdkWindow *window)
5409 gdk_window_show_internal (window, FALSE);
5414 * @window: a #GdkWindow
5416 * Raises @window to the top of the Z-order (stacking order), so that
5417 * other windows with the same parent window appear below @window.
5418 * This is true whether or not the windows are visible.
5420 * If @window is a toplevel, the window manager may choose to deny the
5421 * request to move the window in the Z-order, gdk_window_raise() only
5422 * requests the restack, does not guarantee it.
5425 gdk_window_raise (GdkWindow *window)
5427 GdkWindowObject *private;
5428 cairo_region_t *old_region, *new_region;
5430 g_return_if_fail (GDK_IS_WINDOW (window));
5432 private = (GdkWindowObject *) window;
5433 if (private->destroyed)
5436 gdk_window_flush_if_exposing (window);
5439 if (gdk_window_is_viewable (window) &&
5440 !private->input_only)
5441 old_region = cairo_region_copy (private->clip_region);
5443 /* Keep children in (reverse) stacking order */
5444 gdk_window_raise_internal (window);
5446 recompute_visible_regions (private, TRUE, FALSE);
5450 new_region = cairo_region_copy (private->clip_region);
5452 cairo_region_subtract (new_region, old_region);
5453 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_ALL);
5455 cairo_region_destroy (old_region);
5456 cairo_region_destroy (new_region);
5461 gdk_window_lower_internal (GdkWindow *window)
5463 GdkWindowObject *private = (GdkWindowObject *)window;
5464 GdkWindowObject *parent = private->parent;
5465 GdkWindowImplIface *impl_iface;
5466 GdkWindowObject *above;
5467 GList *native_children;
5472 parent->children = g_list_remove (parent->children, window);
5473 parent->children = g_list_append (parent->children, window);
5476 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5477 /* Just do native lower for toplevels */
5478 if (gdk_window_is_toplevel (private) ||
5479 /* The restack_under codepath should work correctly even if the parent
5480 is native, but it relies on the order of ->children to be correct,
5481 and some apps like SWT reorder the x windows without gdks knowledge,
5482 so we use lower directly in order to make these behave as before
5483 when using native windows */
5484 (gdk_window_has_impl (private) && gdk_window_has_impl (parent)))
5486 impl_iface->lower (window);
5488 else if (gdk_window_has_impl (private))
5490 above = find_native_sibling_above (parent, private);
5493 listhead.data = window;
5494 listhead.next = NULL;
5495 listhead.prev = NULL;
5496 impl_iface->restack_under ((GdkWindow *)above, &listhead);
5499 impl_iface->raise (window);
5503 native_children = NULL;
5504 get_all_native_children (private, &native_children);
5505 if (native_children != NULL)
5507 above = find_native_sibling_above (parent, private);
5510 impl_iface->restack_under ((GdkWindow *)above,
5514 /* Right order, since native_children is bottom-topmost first */
5515 for (l = native_children; l != NULL; l = l->next)
5516 impl_iface->raise (l->data);
5519 g_list_free (native_children);
5526 gdk_window_invalidate_in_parent (GdkWindowObject *private)
5528 GdkRectangle r, child;
5530 if (gdk_window_is_toplevel (private))
5533 /* get the visible rectangle of the parent */
5535 r.width = private->parent->width;
5536 r.height = private->parent->height;
5538 child.x = private->x;
5539 child.y = private->y;
5540 child.width = private->width;
5541 child.height = private->height;
5542 gdk_rectangle_intersect (&r, &child, &r);
5544 gdk_window_invalidate_rect_full (GDK_WINDOW (private->parent), &r, TRUE, CLEAR_BG_ALL);
5550 * @window: a #GdkWindow
5552 * Lowers @window to the bottom of the Z-order (stacking order), so that
5553 * other windows with the same parent window appear above @window.
5554 * This is true whether or not the other windows are visible.
5556 * If @window is a toplevel, the window manager may choose to deny the
5557 * request to move the window in the Z-order, gdk_window_lower() only
5558 * requests the restack, does not guarantee it.
5560 * Note that gdk_window_show() raises the window again, so don't call this
5561 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5564 gdk_window_lower (GdkWindow *window)
5566 GdkWindowObject *private;
5568 g_return_if_fail (GDK_IS_WINDOW (window));
5570 private = (GdkWindowObject *) window;
5571 if (private->destroyed)
5574 gdk_window_flush_if_exposing (window);
5576 /* Keep children in (reverse) stacking order */
5577 gdk_window_lower_internal (window);
5579 recompute_visible_regions (private, TRUE, FALSE);
5581 _gdk_synthesize_crossing_events_for_geometry_change (window);
5582 gdk_window_invalidate_in_parent (private);
5586 * gdk_window_restack:
5587 * @window: a #GdkWindow
5588 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5591 * Changes the position of @window in the Z-order (stacking order), so that
5592 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5595 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5596 * lowers the window.
5598 * If @window is a toplevel, the window manager may choose to deny the
5599 * request to move the window in the Z-order, gdk_window_restack() only
5600 * requests the restack, does not guarantee it.
5605 gdk_window_restack (GdkWindow *window,
5609 GdkWindowObject *private;
5610 GdkWindowImplIface *impl_iface;
5611 GdkWindowObject *parent;
5612 GdkWindowObject *above_native;
5613 GList *sibling_link;
5614 GList *native_children;
5617 g_return_if_fail (GDK_IS_WINDOW (window));
5618 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5620 private = (GdkWindowObject *) window;
5621 if (private->destroyed)
5624 if (sibling == NULL)
5627 gdk_window_raise (window);
5629 gdk_window_lower (window);
5633 gdk_window_flush_if_exposing (window);
5635 if (gdk_window_is_toplevel (private))
5637 g_return_if_fail (gdk_window_is_toplevel (GDK_WINDOW_OBJECT (sibling)));
5638 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5639 impl_iface->restack_toplevel (window, sibling, above);
5643 parent = private->parent;
5646 sibling_link = g_list_find (parent->children, sibling);
5647 g_return_if_fail (sibling_link != NULL);
5648 if (sibling_link == NULL)
5651 parent->children = g_list_remove (parent->children, window);
5653 parent->children = g_list_insert_before (parent->children,
5657 parent->children = g_list_insert_before (parent->children,
5661 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5662 if (gdk_window_has_impl (private))
5664 above_native = find_native_sibling_above (parent, private);
5667 listhead.data = window;
5668 listhead.next = NULL;
5669 listhead.prev = NULL;
5670 impl_iface->restack_under ((GdkWindow *)above_native, &listhead);
5673 impl_iface->raise (window);
5677 native_children = NULL;
5678 get_all_native_children (private, &native_children);
5679 if (native_children != NULL)
5681 above_native = find_native_sibling_above (parent, private);
5683 impl_iface->restack_under ((GdkWindow *)above_native,
5687 /* Right order, since native_children is bottom-topmost first */
5688 for (l = native_children; l != NULL; l = l->next)
5689 impl_iface->raise (l->data);
5692 g_list_free (native_children);
5697 recompute_visible_regions (private, TRUE, FALSE);
5699 _gdk_synthesize_crossing_events_for_geometry_change (window);
5700 gdk_window_invalidate_in_parent (private);
5706 * @window: a #GdkWindow
5708 * Like gdk_window_show_unraised(), but also raises the window to the
5709 * top of the window stack (moves the window to the front of the
5712 * This function maps a window so it's visible onscreen. Its opposite
5713 * is gdk_window_hide().
5715 * When implementing a #GtkWidget, you should call this function on the widget's
5716 * #GdkWindow as part of the "map" method.
5719 gdk_window_show (GdkWindow *window)
5721 gdk_window_show_internal (window, TRUE);
5726 * @window: a #GdkWindow
5728 * For toplevel windows, withdraws them, so they will no longer be
5729 * known to the window manager; for all windows, unmaps them, so
5730 * they won't be displayed. Normally done automatically as
5731 * part of gtk_widget_hide().
5734 gdk_window_hide (GdkWindow *window)
5736 GdkWindowObject *private;
5737 GdkWindowImplIface *impl_iface;
5738 gboolean was_mapped, did_hide;
5740 g_return_if_fail (GDK_IS_WINDOW (window));
5742 private = (GdkWindowObject *) window;
5743 if (private->destroyed)
5746 was_mapped = GDK_WINDOW_IS_MAPPED (private);
5748 if (gdk_window_has_impl (private))
5751 if (GDK_WINDOW_IS_MAPPED (window))
5752 gdk_synthesize_window_state (window,
5754 GDK_WINDOW_STATE_WITHDRAWN);
5756 else if (was_mapped)
5758 GdkDisplay *display;
5759 GdkDeviceManager *device_manager;
5762 /* May need to break grabs on children */
5763 display = gdk_window_get_display (window);
5764 device_manager = gdk_display_get_device_manager (display);
5766 /* Get all devices */
5767 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5768 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5769 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5771 for (d = devices; d; d = d->next)
5773 GdkDevice *device = d->data;
5775 if (_gdk_display_end_device_grab (display, device,
5776 _gdk_windowing_window_get_next_serial (display),
5779 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5782 private->state = GDK_WINDOW_STATE_WITHDRAWN;
5783 g_list_free (devices);
5786 did_hide = _gdk_window_update_viewable (window);
5788 /* Hide foreign window as those are not handled by update_viewable. */
5789 if (gdk_window_has_impl (private) && (!did_hide))
5791 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5792 impl_iface->hide (window);
5795 recompute_visible_regions (private, TRUE, FALSE);
5797 /* all decendants became non-visible, we need to send visibility notify */
5798 gdk_window_update_visibility_recursively (private, NULL);
5800 if (was_mapped && !gdk_window_has_impl (private))
5802 if (private->event_mask & GDK_STRUCTURE_MASK)
5803 _gdk_make_event (GDK_WINDOW (private), GDK_UNMAP, NULL, FALSE);
5805 if (private->parent && private->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5806 _gdk_make_event (GDK_WINDOW (private), GDK_UNMAP, NULL, FALSE);
5808 _gdk_synthesize_crossing_events_for_geometry_change (GDK_WINDOW (private->parent));
5811 /* Invalidate the rect */
5813 gdk_window_invalidate_in_parent (private);
5817 * gdk_window_withdraw:
5818 * @window: a toplevel #GdkWindow
5820 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5821 * This function is not really useful as gdk_window_hide() automatically
5822 * withdraws toplevel windows before hiding them.
5825 gdk_window_withdraw (GdkWindow *window)
5827 GdkWindowObject *private;
5828 GdkWindowImplIface *impl_iface;
5829 gboolean was_mapped;
5831 g_return_if_fail (GDK_IS_WINDOW (window));
5833 private = (GdkWindowObject *) window;
5834 if (private->destroyed)
5837 was_mapped = GDK_WINDOW_IS_MAPPED (private);
5839 if (gdk_window_has_impl (private))
5841 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5842 impl_iface->withdraw (window);
5846 if (private->event_mask & GDK_STRUCTURE_MASK)
5847 _gdk_make_event (GDK_WINDOW (private), GDK_UNMAP, NULL, FALSE);
5849 if (private->parent && private->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5850 _gdk_make_event (GDK_WINDOW (private), GDK_UNMAP, NULL, FALSE);
5852 _gdk_synthesize_crossing_events_for_geometry_change (GDK_WINDOW (private->parent));
5855 recompute_visible_regions (private, TRUE, FALSE);
5860 * gdk_window_set_events:
5861 * @window: a #GdkWindow
5862 * @event_mask: event mask for @window
5864 * The event mask for a window determines which events will be reported
5865 * for that window from all master input devices. For example, an event mask
5866 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5867 * press events. The event mask is the bitwise OR of values from the
5868 * #GdkEventMask enumeration.
5871 gdk_window_set_events (GdkWindow *window,
5872 GdkEventMask event_mask)
5874 GdkWindowObject *private;
5875 GdkWindowImplIface *impl_iface;
5876 GdkDisplay *display;
5878 g_return_if_fail (GDK_IS_WINDOW (window));
5880 private = (GdkWindowObject *) window;
5881 if (private->destroyed)
5884 /* If motion hint is disabled, enable motion events again */
5885 display = gdk_window_get_display (window);
5886 if ((private->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5887 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5889 GList *devices = private->devices_inside;
5893 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5894 devices = devices->next;
5898 private->event_mask = event_mask;
5900 if (gdk_window_has_impl (private))
5902 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
5903 impl_iface->set_events (window,
5904 get_native_event_mask (private));
5910 * gdk_window_get_events:
5911 * @window: a #GdkWindow
5913 * Gets the event mask for @window for all master input devices. See
5914 * gdk_window_set_events().
5916 * Return value: event mask for @window
5919 gdk_window_get_events (GdkWindow *window)
5921 GdkWindowObject *private;
5923 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5925 private = (GdkWindowObject *) window;
5926 if (private->destroyed)
5929 return private->event_mask;
5933 * gdk_window_set_device_events:
5934 * @window: a #GdkWindow
5935 * @device: #GdkDevice to enable events for.
5936 * @event_mask: event mask for @window
5938 * Sets the event mask for a given device (Normally a floating device, not
5939 * attached to any visible pointer) to @window. For example, an event mask
5940 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5941 * press events. The event mask is the bitwise OR of values from the
5942 * #GdkEventMask enumeration.
5947 gdk_window_set_device_events (GdkWindow *window,
5949 GdkEventMask event_mask)
5951 GdkEventMask device_mask;
5952 GdkWindowObject *private;
5953 GdkDisplay *display;
5956 g_return_if_fail (GDK_IS_WINDOW (window));
5957 g_return_if_fail (GDK_IS_DEVICE (device));
5959 if (GDK_WINDOW_DESTROYED (window))
5962 private = (GdkWindowObject *) window;
5964 /* If motion hint is disabled, enable motion events again */
5965 display = gdk_window_get_display (window);
5966 if ((private->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5967 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5968 _gdk_display_enable_motion_hints (display, device);
5970 if (G_UNLIKELY (!private->device_events))
5971 private->device_events = g_hash_table_new (NULL, NULL);
5973 if (event_mask == 0)
5975 /* FIXME: unsetting events on a master device
5976 * would restore private->event_mask
5978 g_hash_table_remove (private->device_events, device);
5981 g_hash_table_insert (private->device_events, device,
5982 GINT_TO_POINTER (event_mask));
5984 if (_gdk_native_windows)
5987 native = gdk_window_get_toplevel (window);
5989 while (gdk_window_is_offscreen ((GdkWindowObject *)native))
5991 native = gdk_offscreen_window_get_embedder (native);
5993 if (native == NULL ||
5994 (!_gdk_window_has_impl (native) &&
5995 !gdk_window_is_viewable (native)))
5998 native = gdk_window_get_toplevel (native);
6001 device_mask = get_native_device_event_mask (private, device);
6002 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
6006 * gdk_window_get_device_events:
6007 * @window: a #GdkWindow.
6008 * @device: a #GdkDevice.
6010 * Returns the event mask for @window corresponding to an specific device.
6012 * Returns: device event mask for @window
6017 gdk_window_get_device_events (GdkWindow *window,
6020 GdkWindowObject *private;
6023 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6024 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
6026 if (GDK_WINDOW_DESTROYED (window))
6029 private = (GdkWindowObject *) window;
6031 if (!private->device_events)
6034 mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
6036 /* FIXME: device could be controlled by private->event_mask */
6042 gdk_window_move_resize_toplevel (GdkWindow *window,
6049 GdkWindowObject *private;
6050 cairo_region_t *old_region, *new_region;
6051 GdkWindowImplIface *impl_iface;
6053 int old_x, old_y, old_abs_x, old_abs_y;
6057 private = (GdkWindowObject *) window;
6065 is_resize = (width != -1) || (height != -1);
6067 if (gdk_window_is_viewable (window) &&
6068 !private->input_only)
6071 old_region = cairo_region_copy (private->clip_region);
6074 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
6075 impl_iface->move_resize (window, with_move, x, y, width, height);
6077 dx = private->x - old_x;
6078 dy = private->y - old_y;
6080 old_abs_x = private->abs_x;
6081 old_abs_y = private->abs_y;
6083 /* Avoid recomputing for pure toplevel moves, for performance reasons */
6085 recompute_visible_regions (private, TRUE, FALSE);
6089 new_region = cairo_region_copy (private->clip_region);
6091 /* This is the newly exposed area (due to any resize),
6092 * X will expose it, but lets do that without the
6095 cairo_region_subtract (new_region, old_region);
6096 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
6098 cairo_region_destroy (old_region);
6099 cairo_region_destroy (new_region);
6102 _gdk_synthesize_crossing_events_for_geometry_change (window);
6107 move_native_children (GdkWindowObject *private)
6110 GdkWindowObject *child;
6111 GdkWindowImplIface *impl_iface;
6113 for (l = private->children; l; l = l->next)
6117 if (child->impl != private->impl)
6119 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (child->impl);
6120 impl_iface->move_resize ((GdkWindow *)child, TRUE,
6122 child->width, child->height);
6125 move_native_children (child);
6130 collect_native_child_region_helper (GdkWindowObject *window,
6132 cairo_region_t **region,
6136 GdkWindowObject *child;
6137 cairo_region_t *tmp;
6140 for (l = window->children; l != NULL; l = l->next)
6144 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
6147 if (child->impl != impl)
6149 tmp = cairo_region_copy (child->clip_region);
6150 cairo_region_translate (tmp,
6151 x_offset + child->x,
6152 y_offset + child->y);
6153 if (*region == NULL)
6157 cairo_region_union (*region, tmp);
6158 cairo_region_destroy (tmp);
6162 collect_native_child_region_helper (child, impl, region,
6163 x_offset + child->x,
6164 y_offset + child->y);
6170 static cairo_region_t *
6171 collect_native_child_region (GdkWindowObject *window,
6172 gboolean include_this)
6174 cairo_region_t *region;
6176 if (include_this && gdk_window_has_impl (window) && window->viewable)
6177 return cairo_region_copy (window->clip_region);
6181 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6188 gdk_window_move_resize_internal (GdkWindow *window,
6195 GdkWindowObject *private;
6196 cairo_region_t *old_region, *new_region, *copy_area;
6197 cairo_region_t *old_native_child_region, *new_native_child_region;
6198 GdkWindowObject *impl_window;
6199 GdkWindowImplIface *impl_iface;
6201 int old_x, old_y, old_abs_x, old_abs_y;
6204 g_return_if_fail (GDK_IS_WINDOW (window));
6206 private = (GdkWindowObject *) window;
6207 if (private->destroyed)
6210 if (gdk_window_is_toplevel (private))
6212 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6216 /* Bail early if no change */
6217 if (private->width == width &&
6218 private->height == height &&
6224 gdk_window_flush_if_exposing (window);
6226 /* Handle child windows */
6231 impl_window = gdk_window_get_impl_window (private);
6236 old_native_child_region = NULL;
6237 if (gdk_window_is_viewable (window) &&
6238 !private->input_only)
6242 old_region = cairo_region_copy (private->clip_region);
6243 /* Adjust region to parent window coords */
6244 cairo_region_translate (old_region, private->x, private->y);
6246 old_native_child_region = collect_native_child_region (private, TRUE);
6247 if (old_native_child_region)
6249 /* Adjust region to parent window coords */
6250 cairo_region_translate (old_native_child_region, private->x, private->y);
6252 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6253 * source or destination for a delayed GdkWindowRegionMove. So, we need
6254 * to flush those here for the parent window and all overlapped subwindows
6255 * of it. And we need to do this before setting the new clips as those will be
6258 gdk_window_flush_recursive (private->parent);
6262 /* Set the new position and size */
6268 if (!(width < 0 && height < 0))
6272 private->width = width;
6275 private->height = height;
6278 dx = private->x - old_x;
6279 dy = private->y - old_y;
6281 old_abs_x = private->abs_x;
6282 old_abs_y = private->abs_y;
6284 recompute_visible_regions (private, TRUE, FALSE);
6286 new_native_child_region = NULL;
6287 if (old_native_child_region)
6289 new_native_child_region = collect_native_child_region (private, TRUE);
6290 /* Adjust region to parent window coords */
6291 cairo_region_translate (new_native_child_region, private->x, private->y);
6294 if (gdk_window_has_impl (private))
6296 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
6298 /* Do the actual move after recomputing things, as this will have set the shape to
6299 the now correct one, thus avoiding copying regions that should not be copied. */
6300 impl_iface->move_resize (window, TRUE,
6301 private->x, private->y,
6302 private->width, private->height);
6304 else if (old_abs_x != private->abs_x ||
6305 old_abs_y != private->abs_y)
6306 move_native_children (private);
6310 new_region = cairo_region_copy (private->clip_region);
6311 /* Adjust region to parent window coords */
6312 cairo_region_translate (new_region, private->x, private->y);
6315 * Part of the data at the new location can be copied from the
6316 * old location, this area is the intersection of the old region
6317 * moved as the copy will move it and then intersected with
6321 * Everything in the old and new regions that is not copied must be
6322 * invalidated (including children) as this is newly exposed
6324 copy_area = cairo_region_copy (new_region);
6326 cairo_region_union (new_region, old_region);
6328 if (old_native_child_region)
6330 /* Don't copy from inside native children, as this is copied by
6331 * the native window move.
6333 cairo_region_subtract (old_region, old_native_child_region);
6335 cairo_region_translate (old_region, dx, dy);
6337 cairo_region_intersect (copy_area, old_region);
6339 if (new_native_child_region)
6341 /* Don't copy any bits that would cause a read from the moved
6342 native windows, as we can't read that data */
6343 cairo_region_translate (new_native_child_region, dx, dy);
6344 cairo_region_subtract (copy_area, new_native_child_region);
6345 cairo_region_translate (new_native_child_region, -dx, -dy);
6348 cairo_region_subtract (new_region, copy_area);
6350 /* Convert old region to impl coords */
6351 cairo_region_translate (old_region, -dx + private->abs_x - private->x, -dy + private->abs_y - private->y);
6353 /* convert from parent coords to impl */
6354 cairo_region_translate (copy_area, private->abs_x - private->x, private->abs_y - private->y);
6356 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6358 /* Invalidate affected part in the parent window
6359 * (no higher window should be affected)
6360 * We also invalidate any children in that area, which could include
6361 * this window if it still overlaps that area.
6363 if (old_native_child_region)
6365 /* No need to expose the region that the native window move copies */
6366 cairo_region_translate (old_native_child_region, dx, dy);
6367 cairo_region_intersect (old_native_child_region, new_native_child_region);
6368 cairo_region_subtract (new_region, old_native_child_region);
6370 gdk_window_invalidate_region_full (GDK_WINDOW (private->parent), new_region, TRUE, CLEAR_BG_ALL);
6372 cairo_region_destroy (old_region);
6373 cairo_region_destroy (new_region);
6376 if (old_native_child_region)
6378 cairo_region_destroy (old_native_child_region);
6379 cairo_region_destroy (new_native_child_region);
6382 _gdk_synthesize_crossing_events_for_geometry_change (window);
6389 * @window: a #GdkWindow
6390 * @x: X coordinate relative to window's parent
6391 * @y: Y coordinate relative to window's parent
6393 * Repositions a window relative to its parent window.
6394 * For toplevel windows, window managers may ignore or modify the move;
6395 * you should probably use gtk_window_move() on a #GtkWindow widget
6396 * anyway, instead of using GDK functions. For child windows,
6397 * the move will reliably succeed.
6399 * If you're also planning to resize the window, use gdk_window_move_resize()
6400 * to both move and resize simultaneously, for a nicer visual effect.
6403 gdk_window_move (GdkWindow *window,
6407 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6411 * gdk_window_resize:
6412 * @window: a #GdkWindow
6413 * @width: new width of the window
6414 * @height: new height of the window
6416 * Resizes @window; for toplevel windows, asks the window manager to resize
6417 * the window. The window manager may not allow the resize. When using GTK+,
6418 * use gtk_window_resize() instead of this low-level GDK function.
6420 * Windows may not be resized below 1x1.
6422 * If you're also planning to move the window, use gdk_window_move_resize()
6423 * to both move and resize simultaneously, for a nicer visual effect.
6426 gdk_window_resize (GdkWindow *window,
6430 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6435 * gdk_window_move_resize:
6436 * @window: a #GdkWindow
6437 * @x: new X position relative to window's parent
6438 * @y: new Y position relative to window's parent
6440 * @height: new height
6442 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6443 * except that both operations are performed at once, avoiding strange
6444 * visual effects. (i.e. the user may be able to see the window first
6445 * move, then resize, if you don't use gdk_window_move_resize().)
6448 gdk_window_move_resize (GdkWindow *window,
6454 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6459 * gdk_window_scroll:
6460 * @window: a #GdkWindow
6461 * @dx: Amount to scroll in the X direction
6462 * @dy: Amount to scroll in the Y direction
6464 * Scroll the contents of @window, both pixels and children, by the
6465 * given amount. @window itself does not move. Portions of the window
6466 * that the scroll operation brings in from offscreen areas are
6467 * invalidated. The invalidated region may be bigger than what would
6468 * strictly be necessary.
6470 * For X11, a minimum area will be invalidated if the window has no
6471 * subwindows, or if the edges of the window's parent do not extend
6472 * beyond the edges of the window. In other cases, a multi-step process
6473 * is used to scroll the window which may produce temporary visual
6474 * artifacts and unnecessary invalidations.
6477 gdk_window_scroll (GdkWindow *window,
6481 GdkWindowObject *private = (GdkWindowObject *) window;
6482 GdkWindowObject *impl_window;
6483 cairo_region_t *copy_area, *noncopy_area;
6484 cairo_region_t *old_native_child_region, *new_native_child_region;
6487 g_return_if_fail (GDK_IS_WINDOW (window));
6489 if (dx == 0 && dy == 0)
6492 if (private->destroyed)
6495 gdk_window_flush_if_exposing (window);
6497 old_native_child_region = collect_native_child_region (private, FALSE);
6498 if (old_native_child_region)
6500 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6501 * source or destination for a delayed GdkWindowRegionMove. So, we need
6502 * to flush those here for the window and all overlapped subwindows
6503 * of it. And we need to do this before setting the new clips as those will be
6506 gdk_window_flush_recursive (private);
6510 /* First move all child windows, without causing invalidation */
6512 tmp_list = private->children;
6515 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6516 GdkWindowObject *child_obj = GDK_WINDOW_OBJECT (child);
6518 /* Just update the positions, the bits will move with the copy */
6522 tmp_list = tmp_list->next;
6525 recompute_visible_regions (private, FALSE, TRUE);
6527 new_native_child_region = NULL;
6528 if (old_native_child_region)
6529 new_native_child_region = collect_native_child_region (private, FALSE);
6531 move_native_children (private);
6533 /* Then copy the actual bits of the window w/ child windows */
6535 impl_window = gdk_window_get_impl_window (private);
6537 /* Calculate the area that can be gotten by copying the old area */
6538 copy_area = cairo_region_copy (private->clip_region);
6539 if (old_native_child_region)
6541 /* Don't copy from inside native children, as this is copied by
6542 * the native window move.
6544 cairo_region_subtract (copy_area, old_native_child_region);
6546 /* Don't copy any bits that would cause a read from the moved
6547 native windows, as we can't read that data */
6548 cairo_region_subtract (copy_area, new_native_child_region);
6550 cairo_region_translate (copy_area, dx, dy);
6551 cairo_region_intersect (copy_area, private->clip_region);
6553 /* And the rest need to be invalidated */
6554 noncopy_area = cairo_region_copy (private->clip_region);
6555 cairo_region_subtract (noncopy_area, copy_area);
6557 /* convert from window coords to impl */
6558 cairo_region_translate (copy_area, private->abs_x, private->abs_y);
6560 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6562 /* Invalidate not copied regions */
6563 if (old_native_child_region)
6565 /* No need to expose the region that the native window move copies */
6566 cairo_region_translate (old_native_child_region, dx, dy);
6567 cairo_region_intersect (old_native_child_region, new_native_child_region);
6568 cairo_region_subtract (noncopy_area, old_native_child_region);
6570 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6572 cairo_region_destroy (noncopy_area);
6574 if (old_native_child_region)
6576 cairo_region_destroy (old_native_child_region);
6577 cairo_region_destroy (new_native_child_region);
6580 _gdk_synthesize_crossing_events_for_geometry_change (window);
6584 * gdk_window_move_region:
6585 * @window: a #GdkWindow
6586 * @region: The #cairo_region_t to move
6587 * @dx: Amount to move in the X direction
6588 * @dy: Amount to move in the Y direction
6590 * Move the part of @window indicated by @region by @dy pixels in the Y
6591 * direction and @dx pixels in the X direction. The portions of @region
6592 * that not covered by the new position of @region are invalidated.
6594 * Child windows are not moved.
6599 gdk_window_move_region (GdkWindow *window,
6600 const cairo_region_t *region,
6604 GdkWindowObject *private = (GdkWindowObject *) window;
6605 GdkWindowObject *impl_window;
6606 cairo_region_t *nocopy_area;
6607 cairo_region_t *copy_area;
6609 g_return_if_fail (GDK_IS_WINDOW (window));
6610 g_return_if_fail (region != NULL);
6612 if (dx == 0 && dy == 0)
6615 if (private->destroyed)
6618 impl_window = gdk_window_get_impl_window (private);
6620 /* compute source regions */
6621 copy_area = cairo_region_copy (region);
6622 cairo_region_intersect (copy_area, private->clip_region_with_children);
6624 /* compute destination regions */
6625 cairo_region_translate (copy_area, dx, dy);
6626 cairo_region_intersect (copy_area, private->clip_region_with_children);
6628 /* Invalidate parts of the region (source and dest) not covered
6630 nocopy_area = cairo_region_copy (region);
6631 cairo_region_translate (nocopy_area, dx, dy);
6632 cairo_region_union (nocopy_area, region);
6633 cairo_region_subtract (nocopy_area, copy_area);
6635 /* convert from window coords to impl */
6636 cairo_region_translate (copy_area, private->abs_x, private->abs_y);
6637 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6639 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6640 cairo_region_destroy (nocopy_area);
6644 * gdk_window_set_background:
6645 * @window: a #GdkWindow
6646 * @color: a #GdkColor
6648 * Sets the background color of @window. (However, when using GTK+,
6649 * set the background of a widget with gtk_widget_modify_bg() - if
6650 * you're an application - or gtk_style_set_background() - if you're
6651 * implementing a custom widget.)
6653 * See also gdk_window_set_background_pattern().
6656 gdk_window_set_background (GdkWindow *window,
6657 const GdkColor *color)
6659 cairo_pattern_t *pattern;
6661 g_return_if_fail (GDK_IS_WINDOW (window));
6663 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6664 color->green / 65535.,
6665 color->blue / 65535.);
6667 gdk_window_set_background_pattern (window, pattern);
6669 cairo_pattern_destroy (pattern);
6673 * gdk_window_set_background_pattern:
6674 * @window: a #GdkWindow
6675 * @pattern: (allow-none): a pattern to use, or %NULL
6677 * Sets the background of @window.
6679 * A background of %NULL means that the window will inherit its
6680 * background form its parent window.
6682 * The windowing system will normally fill a window with its background
6683 * when the window is obscured then exposed.
6686 gdk_window_set_background_pattern (GdkWindow *window,
6687 cairo_pattern_t *pattern)
6689 GdkWindowObject *private;
6691 g_return_if_fail (GDK_IS_WINDOW (window));
6693 private = (GdkWindowObject *) window;
6696 cairo_pattern_reference (pattern);
6697 if (private->background)
6698 cairo_pattern_destroy (private->background);
6699 private->background = pattern;
6701 if (gdk_window_has_impl (private) &&
6702 !private->input_only)
6704 GdkWindowImplIface *impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
6705 impl_iface->set_background (window, pattern);
6710 * gdk_window_get_background_pattern:
6713 * Gets the pattern used to clear the background on @window. If @window
6714 * does not have its own background and reuses the parent's, %NULL is
6715 * returned and you'll have to query it yourself.
6717 * Returns: The pattern to use for the background or %NULL to use the
6718 * parent's background.
6723 gdk_window_get_background_pattern (GdkWindow *window)
6725 GdkWindowObject *private = (GdkWindowObject *) window;
6727 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6729 return private->background;
6733 update_cursor_foreach (GdkDisplay *display,
6735 GdkPointerWindowInfo *pointer_info,
6738 GdkWindow *window = user_data;
6739 GdkWindowObject *private = (GdkWindowObject *) window;
6741 if (_gdk_native_windows ||
6742 private->window_type == GDK_WINDOW_ROOT ||
6743 private->window_type == GDK_WINDOW_FOREIGN)
6744 GDK_WINDOW_IMPL_GET_IFACE (private->impl)->set_device_cursor (window, device, private->cursor);
6745 else if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6746 update_cursor (display, device);
6750 * gdk_window_get_cursor:
6751 * @window: a #GdkWindow
6753 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6754 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6755 * there is no custom cursor set on the specified window, and it is
6756 * using the cursor for its parent window.
6758 * Return value: a #GdkCursor, or %NULL. The returned object is owned
6759 * by the #GdkWindow and should not be unreferenced directly. Use
6760 * gdk_window_set_cursor() to unset the cursor of the window
6765 gdk_window_get_cursor (GdkWindow *window)
6767 GdkWindowObject *private;
6769 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6771 private = (GdkWindowObject *) window;
6773 return private->cursor;
6777 * gdk_window_set_cursor:
6778 * @window: a #GdkWindow
6779 * @cursor: (allow-none): a cursor
6781 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6782 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6783 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6784 * to gdk_window_set_cursor() means that @window will use the cursor of its
6785 * parent window. Most windows should use this default.
6788 gdk_window_set_cursor (GdkWindow *window,
6791 GdkWindowObject *private;
6792 GdkDisplay *display;
6794 g_return_if_fail (GDK_IS_WINDOW (window));
6796 private = (GdkWindowObject *) window;
6797 display = gdk_window_get_display (window);
6799 if (private->cursor)
6801 gdk_cursor_unref (private->cursor);
6802 private->cursor = NULL;
6805 if (!GDK_WINDOW_DESTROYED (window))
6808 private->cursor = gdk_cursor_ref (cursor);
6810 _gdk_display_pointer_info_foreach (display,
6811 update_cursor_foreach,
6814 g_object_notify (G_OBJECT (window), "cursor");
6819 * gdk_window_get_device_cursor:
6820 * @window: a #GdkWindow.
6821 * @device: a #GdkDevice.
6823 * Retrieves a #GdkCursor pointer for the @device currently set on the
6824 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6825 * there is no custom cursor set on the specified window, and it is
6826 * using the cursor for its parent window.
6828 * Returns: a #GdkCursor, or %NULL. The returned object is owned
6829 * by the #GdkWindow and should not be unreferenced directly. Use
6830 * gdk_window_set_cursor() to unset the cursor of the window
6835 gdk_window_get_device_cursor (GdkWindow *window,
6838 GdkWindowObject *private;
6840 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6841 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6843 private = (GdkWindowObject *) window;
6845 return g_hash_table_lookup (private->device_cursor, device);
6849 * gdk_window_set_device_cursor:
6850 * @window: a #Gdkwindow
6851 * @device: a #GdkDevice
6852 * @cursor: a #GdkCursor
6854 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6855 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6856 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6857 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6858 * @window will use the cursor of its parent window. Most windows should
6864 gdk_window_set_device_cursor (GdkWindow *window,
6868 GdkWindowObject *private;
6869 GdkDisplay *display;
6871 g_return_if_fail (GDK_IS_WINDOW (window));
6872 g_return_if_fail (GDK_IS_DEVICE (device));
6874 private = (GdkWindowObject *) window;
6875 display = gdk_window_get_display (window);
6878 g_hash_table_remove (private->device_cursor, device);
6880 g_hash_table_replace (private->device_cursor, device, gdk_cursor_ref (cursor));
6882 if (!GDK_WINDOW_DESTROYED (window))
6884 GdkPointerWindowInfo *pointer_info;
6886 pointer_info = _gdk_display_get_pointer_info (display, device);
6888 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6889 update_cursor (display, device);
6894 * gdk_window_get_geometry:
6895 * @window: a #GdkWindow
6896 * @x: return location for X coordinate of window (relative to its parent)
6897 * @y: return location for Y coordinate of window (relative to its parent)
6898 * @width: return location for width of window
6899 * @height: return location for height of window
6900 * @depth: return location for bit depth of window
6902 * Any of the return location arguments to this function may be %NULL,
6903 * if you aren't interested in getting the value of that field.
6905 * The X and Y coordinates returned are relative to the parent window
6906 * of @window, which for toplevels usually means relative to the
6907 * window decorations (titlebar, etc.) rather than relative to the
6908 * root window (screen-size background window).
6910 * On the X11 platform, the geometry is obtained from the X server,
6911 * so reflects the latest position of @window; this may be out-of-sync
6912 * with the position of @window delivered in the most-recently-processed
6913 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6914 * position from the most recent configure event.
6917 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6918 * to call gdk_window_get_position(), gdk_window_get_width() and
6919 * gdk_window_get_height() instead, because it avoids the roundtrip to
6920 * the X server and because these functions support the full 32-bit
6921 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6922 * the 16-bit coordinates of X11.
6926 gdk_window_get_geometry (GdkWindow *window,
6933 GdkWindowObject *private, *parent;
6934 GdkWindowImplIface *impl_iface;
6938 GDK_NOTE (MULTIHEAD,
6939 g_message ("gdk_window_get_geometry(): Window needs "
6940 "to be non-NULL to be multi head safe"));
6941 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6944 g_return_if_fail (GDK_IS_WINDOW (window));
6946 private = (GdkWindowObject *) window;
6948 if (!GDK_WINDOW_DESTROYED (window))
6950 if (gdk_window_has_impl (private))
6952 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
6953 impl_iface->get_geometry (window, x, y,
6956 /* This reports the position wrt to the native parent, we need to convert
6957 it to be relative to the client side parent */
6958 parent = private->parent;
6959 if (parent && !gdk_window_has_impl (parent))
6962 *x -= parent->abs_x;
6964 *y -= parent->abs_y;
6974 *width = private->width;
6976 *height = private->height;
6978 *depth = private->depth;
6984 * gdk_window_get_width:
6985 * @window: a #GdkWindow
6987 * Returns the width of the given @window.
6989 * On the X11 platform the returned size is the size reported in the
6990 * most-recently-processed configure event, rather than the current
6991 * size on the X server.
6993 * Returns: The width of @window
6998 gdk_window_get_width (GdkWindow *window)
7000 GdkWindowObject *private;
7002 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7004 private = (GdkWindowObject *) window;
7006 return private->width;
7010 * gdk_window_get_height:
7011 * @window: a #GdkWindow
7013 * Returns the height of the given @window.
7015 * On the X11 platform the returned size is the size reported in the
7016 * most-recently-processed configure event, rather than the current
7017 * size on the X server.
7019 * Returns: The height of @window
7024 gdk_window_get_height (GdkWindow *window)
7026 GdkWindowObject *private;
7028 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7030 private = (GdkWindowObject *) window;
7032 return private->height;
7036 * gdk_window_get_origin:
7037 * @window: a #GdkWindow
7038 * @x: return location for X coordinate
7039 * @y: return location for Y coordinate
7041 * Obtains the position of a window in root window coordinates.
7042 * (Compare with gdk_window_get_position() and
7043 * gdk_window_get_geometry() which return the position of a window
7044 * relative to its parent window.)
7046 * Return value: not meaningful, ignore
7049 gdk_window_get_origin (GdkWindow *window,
7053 GdkWindowObject *private;
7054 GdkWindowImplIface *impl_iface;
7056 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7058 if (GDK_WINDOW_DESTROYED (window))
7067 private = (GdkWindowObject *) window;
7069 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
7070 impl_iface->get_root_coords (window,
7079 * gdk_window_get_root_coords:
7080 * @window: a #GdkWindow
7081 * @x: X coordinate in window
7082 * @y: Y coordinate in window
7083 * @root_x: return location for X coordinate
7084 * @root_y: return location for Y coordinate
7086 * Obtains the position of a window position in root
7087 * window coordinates. This is similar to
7088 * gdk_window_get_origin() but allows you go pass
7089 * in any position in the window, not just the origin.
7094 gdk_window_get_root_coords (GdkWindow *window,
7100 GdkWindowObject *private;
7101 GdkWindowImplIface *impl_iface;
7103 g_return_if_fail (GDK_IS_WINDOW (window));
7105 private = (GdkWindowObject *) window;
7107 if (GDK_WINDOW_DESTROYED (window))
7116 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
7117 impl_iface->get_root_coords (window,
7124 * gdk_window_coords_to_parent:
7125 * @window: a child window
7126 * @x: X coordinate in child's coordinate system
7127 * @y: Y coordinate in child's coordinate system
7128 * @parent_x: (out) (allow-none): return location for X coordinate
7129 * in parent's coordinate system, or %NULL
7130 * @parent_y: (out) (allow-none): return location for Y coordinate
7131 * in parent's coordinate system, or %NULL
7133 * Transforms window coordinates from a child window to its parent
7134 * window, where the parent window is the normal parent as returned by
7135 * gdk_window_get_parent() for normal windows, and the window's
7136 * embedder as returned by gdk_offscreen_window_get_embedder() for
7137 * offscreen windows.
7139 * For normal windows, calling this function is equivalent to adding
7140 * the return values of gdk_window_get_position() to the child coordinates.
7141 * For offscreen windows however (which can be arbitrarily transformed),
7142 * this function calls the GdkWindow::to-embedder: signal to translate
7145 * You should always use this function when writing generic code that
7146 * walks up a window hierarchy.
7148 * See also: gdk_window_coords_from_parent()
7153 gdk_window_coords_to_parent (GdkWindow *window,
7159 GdkWindowObject *obj;
7161 g_return_if_fail (GDK_IS_WINDOW (window));
7163 obj = (GdkWindowObject *) window;
7165 if (gdk_window_is_offscreen (obj))
7169 to_embedder (obj, x, y, &px, &py);
7180 *parent_x = x + obj->x;
7183 *parent_y = y + obj->y;
7188 * gdk_window_coords_from_parent:
7189 * @window: a child window
7190 * @parent_x: X coordinate in parent's coordinate system
7191 * @parent_y: Y coordinate in parent's coordinate system
7192 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7193 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7195 * Transforms window coordinates from a parent window to a child
7196 * window, where the parent window is the normal parent as returned by
7197 * gdk_window_get_parent() for normal windows, and the window's
7198 * embedder as returned by gdk_offscreen_window_get_embedder() for
7199 * offscreen windows.
7201 * For normal windows, calling this function is equivalent to subtracting
7202 * the return values of gdk_window_get_position() from the parent coordinates.
7203 * For offscreen windows however (which can be arbitrarily transformed),
7204 * this function calls the GdkWindow::from-embedder: signal to translate
7207 * You should always use this function when writing generic code that
7208 * walks down a window hierarchy.
7210 * See also: gdk_window_coords_to_parent()
7215 gdk_window_coords_from_parent (GdkWindow *window,
7221 GdkWindowObject *obj;
7223 g_return_if_fail (GDK_IS_WINDOW (window));
7225 obj = (GdkWindowObject *) window;
7227 if (gdk_window_is_offscreen (obj))
7231 from_embedder (obj, parent_x, parent_y, &cx, &cy);
7242 *x = parent_x - obj->x;
7245 *y = parent_y - obj->y;
7250 * gdk_window_shape_combine_region:
7251 * @window: a #GdkWindow
7252 * @shape_region: region of window to be non-transparent
7253 * @offset_x: X position of @shape_region in @window coordinates
7254 * @offset_y: Y position of @shape_region in @window coordinates
7256 * Makes pixels in @window outside @shape_region be transparent,
7257 * so that the window may be nonrectangular.
7259 * If @shape_region is %NULL, the shape will be unset, so the whole
7260 * window will be opaque again. @offset_x and @offset_y are ignored
7261 * if @shape_region is %NULL.
7263 * On the X11 platform, this uses an X server extension which is
7264 * widely available on most common platforms, but not available on
7265 * very old X servers, and occasionally the implementation will be
7266 * buggy. On servers without the shape extension, this function
7269 * This function works on both toplevel and child windows.
7272 gdk_window_shape_combine_region (GdkWindow *window,
7273 const cairo_region_t *shape_region,
7277 GdkWindowObject *private;
7278 cairo_region_t *old_region, *new_region, *diff;
7280 g_return_if_fail (GDK_IS_WINDOW (window));
7282 private = (GdkWindowObject *) window;
7284 if (GDK_WINDOW_DESTROYED (window))
7287 private->shaped = (shape_region != NULL);
7290 cairo_region_destroy (private->shape);
7293 if (GDK_WINDOW_IS_MAPPED (window))
7294 old_region = cairo_region_copy (private->clip_region);
7298 private->shape = cairo_region_copy (shape_region);
7299 cairo_region_translate (private->shape, offset_x, offset_y);
7302 private->shape = NULL;
7304 recompute_visible_regions (private, TRUE, FALSE);
7306 if (gdk_window_has_impl (private) &&
7307 !should_apply_clip_as_shape (private))
7308 apply_shape (private, private->shape);
7312 new_region = cairo_region_copy (private->clip_region);
7314 /* New area in the window, needs invalidation */
7315 diff = cairo_region_copy (new_region);
7316 cairo_region_subtract (diff, old_region);
7318 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7320 cairo_region_destroy (diff);
7322 if (!gdk_window_is_toplevel (private))
7324 /* New area in the non-root parent window, needs invalidation */
7325 diff = cairo_region_copy (old_region);
7326 cairo_region_subtract (diff, new_region);
7328 /* Adjust region to parent window coords */
7329 cairo_region_translate (diff, private->x, private->y);
7331 gdk_window_invalidate_region_full (GDK_WINDOW (private->parent), diff, TRUE, CLEAR_BG_ALL);
7333 cairo_region_destroy (diff);
7336 cairo_region_destroy (new_region);
7337 cairo_region_destroy (old_region);
7342 do_child_shapes (GdkWindow *window,
7345 GdkWindowObject *private;
7347 cairo_region_t *region;
7349 private = (GdkWindowObject *) window;
7353 r.width = private->width;
7354 r.height = private->height;
7356 region = cairo_region_create_rectangle (&r);
7357 remove_child_area (private, NULL, FALSE, region);
7359 if (merge && private->shape)
7360 cairo_region_subtract (region, private->shape);
7362 gdk_window_shape_combine_region (window, region, 0, 0);
7366 * gdk_window_set_child_shapes:
7367 * @window: a #GdkWindow
7369 * Sets the shape mask of @window to the union of shape masks
7370 * for all children of @window, ignoring the shape mask of @window
7371 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7372 * the shape mask of @window in the masks to be merged.
7375 gdk_window_set_child_shapes (GdkWindow *window)
7377 g_return_if_fail (GDK_IS_WINDOW (window));
7379 do_child_shapes (window, FALSE);
7383 * gdk_window_merge_child_shapes:
7384 * @window: a #GdkWindow
7386 * Merges the shape masks for any child windows into the
7387 * shape mask for @window. i.e. the union of all masks
7388 * for @window and its children will become the new mask
7389 * for @window. See gdk_window_shape_combine_region().
7391 * This function is distinct from gdk_window_set_child_shapes()
7392 * because it includes @window's shape mask in the set of shapes to
7396 gdk_window_merge_child_shapes (GdkWindow *window)
7398 g_return_if_fail (GDK_IS_WINDOW (window));
7400 do_child_shapes (window, TRUE);
7404 * gdk_window_input_shape_combine_region:
7405 * @window: a #GdkWindow
7406 * @shape_region: region of window to be non-transparent
7407 * @offset_x: X position of @shape_region in @window coordinates
7408 * @offset_y: Y position of @shape_region in @window coordinates
7410 * Like gdk_window_shape_combine_region(), but the shape applies
7411 * only to event handling. Mouse events which happen while
7412 * the pointer position corresponds to an unset bit in the
7413 * mask will be passed on the window below @window.
7415 * An input shape is typically used with RGBA windows.
7416 * The alpha channel of the window defines which pixels are
7417 * invisible and allows for nicely antialiased borders,
7418 * and the input shape controls where the window is
7421 * On the X11 platform, this requires version 1.1 of the
7424 * On the Win32 platform, this functionality is not present and the
7425 * function does nothing.
7430 gdk_window_input_shape_combine_region (GdkWindow *window,
7431 const cairo_region_t *shape_region,
7435 GdkWindowObject *private;
7436 GdkWindowImplIface *impl_iface;
7438 g_return_if_fail (GDK_IS_WINDOW (window));
7440 private = (GdkWindowObject *) window;
7442 if (GDK_WINDOW_DESTROYED (window))
7445 if (private->input_shape)
7446 cairo_region_destroy (private->input_shape);
7450 private->input_shape = cairo_region_copy (shape_region);
7451 cairo_region_translate (private->input_shape, offset_x, offset_y);
7454 private->input_shape = NULL;
7456 if (gdk_window_has_impl (private))
7458 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
7459 impl_iface->input_shape_combine_region (window, private->input_shape, 0, 0);
7462 /* Pointer may have e.g. moved outside window due to the input mask change */
7463 _gdk_synthesize_crossing_events_for_geometry_change (window);
7467 do_child_input_shapes (GdkWindow *window,
7470 GdkWindowObject *private;
7472 cairo_region_t *region;
7474 private = (GdkWindowObject *) window;
7478 r.width = private->width;
7479 r.height = private->height;
7481 region = cairo_region_create_rectangle (&r);
7482 remove_child_area (private, NULL, TRUE, region);
7484 if (merge && private->shape)
7485 cairo_region_subtract (region, private->shape);
7486 if (merge && private->input_shape)
7487 cairo_region_subtract (region, private->input_shape);
7489 gdk_window_input_shape_combine_region (window, region, 0, 0);
7494 * gdk_window_set_child_input_shapes:
7495 * @window: a #GdkWindow
7497 * Sets the input shape mask of @window to the union of input shape masks
7498 * for all children of @window, ignoring the input shape mask of @window
7499 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7500 * the input shape mask of @window in the masks to be merged.
7505 gdk_window_set_child_input_shapes (GdkWindow *window)
7507 g_return_if_fail (GDK_IS_WINDOW (window));
7509 do_child_input_shapes (window, FALSE);
7513 * gdk_window_merge_child_input_shapes:
7514 * @window: a #GdkWindow
7516 * Merges the input shape masks for any child windows into the
7517 * input shape mask for @window. i.e. the union of all input masks
7518 * for @window and its children will become the new input mask
7519 * for @window. See gdk_window_input_shape_combine_region().
7521 * This function is distinct from gdk_window_set_child_input_shapes()
7522 * because it includes @window's input shape mask in the set of
7523 * shapes to be merged.
7528 gdk_window_merge_child_input_shapes (GdkWindow *window)
7530 g_return_if_fail (GDK_IS_WINDOW (window));
7532 do_child_input_shapes (window, TRUE);
7537 * gdk_window_set_static_gravities:
7538 * @window: a #GdkWindow
7539 * @use_static: %TRUE to turn on static gravity
7541 * Set the bit gravity of the given window to static, and flag it so
7542 * all children get static subwindow gravity. This is used if you are
7543 * implementing scary features that involve deep knowledge of the
7544 * windowing system. Don't worry about it unless you have to.
7546 * Return value: %TRUE if the server supports static gravity
7549 gdk_window_set_static_gravities (GdkWindow *window,
7550 gboolean use_static)
7552 GdkWindowObject *private;
7553 GdkWindowImplIface *impl_iface;
7555 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7557 private = (GdkWindowObject *) window;
7559 if (gdk_window_has_impl (private))
7561 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl);
7562 return impl_iface->set_static_gravities (window, use_static);
7569 * gdk_window_get_composited:
7570 * @window: a #GdkWindow
7572 * Determines whether @window is composited.
7574 * See gdk_window_set_composited().
7576 * Returns: %TRUE if the window is composited.
7581 gdk_window_get_composited (GdkWindow *window)
7583 GdkWindowObject *private;
7585 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7587 private = (GdkWindowObject *)window;
7589 return private->composited;
7593 * gdk_window_set_composited:
7594 * @window: a #GdkWindow
7595 * @composited: %TRUE to set the window as composited
7597 * Sets a #GdkWindow as composited, or unsets it. Composited
7598 * windows do not automatically have their contents drawn to
7599 * the screen. Drawing is redirected to an offscreen buffer
7600 * and an expose event is emitted on the parent of the composited
7601 * window. It is the responsibility of the parent's expose handler
7602 * to manually merge the off-screen content onto the screen in
7603 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7606 * It only makes sense for child windows to be composited; see
7607 * gdk_window_set_opacity() if you need translucent toplevel
7610 * An additional effect of this call is that the area of this
7611 * window is no longer clipped from regions marked for
7612 * invalidation on its parent. Draws done on the parent
7613 * window are also no longer clipped by the child.
7615 * This call is only supported on some systems (currently,
7616 * only X11 with new enough Xcomposite and Xdamage extensions).
7617 * You must call gdk_display_supports_composite() to check if
7618 * setting a window as composited is supported before
7619 * attempting to do so.
7624 gdk_window_set_composited (GdkWindow *window,
7625 gboolean composited)
7627 GdkWindowObject *private = (GdkWindowObject *)window;
7628 GdkDisplay *display;
7630 g_return_if_fail (GDK_IS_WINDOW (window));
7632 composited = composited != FALSE;
7634 if (private->composited == composited)
7638 gdk_window_ensure_native (window);
7640 display = gdk_window_get_display (window);
7642 if (!gdk_display_supports_composite (display) && composited)
7644 g_warning ("gdk_window_set_composited called but "
7645 "compositing is not supported");
7649 _gdk_windowing_window_set_composited (window, composited);
7651 recompute_visible_regions (private, TRUE, FALSE);
7653 if (GDK_WINDOW_IS_MAPPED (window))
7654 gdk_window_invalidate_in_parent (private);
7656 private->composited = composited;
7660 * gdk_window_get_modal_hint:
7661 * @window: A toplevel #GdkWindow.
7663 * Determines whether or not the window manager is hinted that @window
7664 * has modal behaviour.
7666 * Return value: whether or not the window has the modal hint set.
7671 gdk_window_get_modal_hint (GdkWindow *window)
7673 GdkWindowObject *private;
7675 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7677 private = (GdkWindowObject*) window;
7679 return private->modal_hint;
7683 * gdk_window_get_accept_focus:
7684 * @window: a toplevel #GdkWindow.
7686 * Determines whether or not the desktop environment shuld be hinted that
7687 * the window does not want to receive input focus.
7689 * Return value: whether or not the window should receive input focus.
7694 gdk_window_get_accept_focus (GdkWindow *window)
7696 GdkWindowObject *private;
7698 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7700 private = (GdkWindowObject *)window;
7702 return private->accept_focus;
7706 * gdk_window_get_focus_on_map:
7707 * @window: a toplevel #GdkWindow.
7709 * Determines whether or not the desktop environment should be hinted that the
7710 * window does not want to receive input focus when it is mapped.
7712 * Return value: whether or not the window wants to receive input focus when
7718 gdk_window_get_focus_on_map (GdkWindow *window)
7720 GdkWindowObject *private;
7722 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7724 private = (GdkWindowObject *)window;
7726 return private->focus_on_map;
7730 * gdk_window_is_input_only:
7731 * @window: a toplevel #GdkWindow
7733 * Determines whether or not the window is an input only window.
7735 * Return value: %TRUE if @window is input only
7740 gdk_window_is_input_only (GdkWindow *window)
7742 GdkWindowObject *private;
7744 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7746 private = (GdkWindowObject *)window;
7748 return private->input_only;
7752 * gdk_window_is_shaped:
7753 * @window: a toplevel #GdkWindow
7755 * Determines whether or not the window is shaped.
7757 * Return value: %TRUE if @window is shaped
7762 gdk_window_is_shaped (GdkWindow *window)
7764 GdkWindowObject *private;
7766 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7768 private = (GdkWindowObject *)window;
7770 return private->shaped;
7774 window_get_size_rectangle (GdkWindow *window,
7777 GdkWindowObject *private = (GdkWindowObject *) window;
7779 rect->x = rect->y = 0;
7780 rect->width = private->width;
7781 rect->height = private->height;
7784 /* Calculates the real clipping region for a window, in window coordinates,
7785 * taking into account other windows, gc clip region and gc clip mask.
7788 _gdk_window_calculate_full_clip_region (GdkWindow *window,
7789 GdkWindow *base_window,
7790 gboolean do_children,
7791 gint *base_x_offset,
7792 gint *base_y_offset)
7794 GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
7795 GdkRectangle visible_rect;
7796 cairo_region_t *real_clip_region;
7797 gint x_offset, y_offset;
7798 GdkWindowObject *parentwin, *lastwin;
7805 if (!private->viewable || private->input_only)
7806 return cairo_region_create ();
7808 window_get_size_rectangle (window, &visible_rect);
7810 /* real_clip_region is in window coordinates */
7811 real_clip_region = cairo_region_create_rectangle (&visible_rect);
7813 x_offset = y_offset = 0;
7817 parentwin = lastwin;
7819 parentwin = lastwin->parent;
7821 /* Remove the areas of all overlapping windows above parentwin in the hiearachy */
7822 for (; parentwin != NULL &&
7823 (parentwin == private || lastwin != (GdkWindowObject*) base_window);
7824 lastwin = parentwin, parentwin = lastwin->parent)
7827 GdkRectangle real_clip_rect;
7829 if (parentwin != private)
7831 x_offset += GDK_WINDOW_OBJECT (lastwin)->x;
7832 y_offset += GDK_WINDOW_OBJECT (lastwin)->y;
7835 /* children is ordered in reverse stack order */
7836 for (cur = parentwin->children;
7837 cur && cur->data != lastwin;
7840 GdkWindow *child = cur->data;
7841 GdkWindowObject *child_private = (GdkWindowObject *)child;
7843 if (!GDK_WINDOW_IS_MAPPED (child) || child_private->input_only)
7846 /* Ignore offscreen children, as they don't draw in their parent and
7847 * don't take part in the clipping */
7848 if (gdk_window_is_offscreen (child_private))
7851 window_get_size_rectangle (child, &visible_rect);
7853 /* Convert rect to "window" coords */
7854 visible_rect.x += child_private->x - x_offset;
7855 visible_rect.y += child_private->y - y_offset;
7857 /* This shortcut is really necessary for performance when there are a lot of windows */
7858 cairo_region_get_extents (real_clip_region, &real_clip_rect);
7859 if (visible_rect.x >= real_clip_rect.x + real_clip_rect.width ||
7860 visible_rect.x + visible_rect.width <= real_clip_rect.x ||
7861 visible_rect.y >= real_clip_rect.y + real_clip_rect.height ||
7862 visible_rect.y + visible_rect.height <= real_clip_rect.y)
7865 cairo_region_subtract_rectangle (real_clip_region, &visible_rect);
7868 /* Clip to the parent */
7869 window_get_size_rectangle ((GdkWindow *)parentwin, &visible_rect);
7870 /* Convert rect to "window" coords */
7871 visible_rect.x += - x_offset;
7872 visible_rect.y += - y_offset;
7874 cairo_region_intersect_rectangle (real_clip_region, &visible_rect);
7878 *base_x_offset = x_offset;
7880 *base_y_offset = y_offset;
7882 return real_clip_region;
7886 _gdk_window_add_damage (GdkWindow *toplevel,
7887 cairo_region_t *damaged_region)
7889 GdkDisplay *display;
7890 GdkEvent event = { 0, };
7891 event.expose.type = GDK_DAMAGE;
7892 event.expose.window = toplevel;
7893 event.expose.send_event = FALSE;
7894 event.expose.region = damaged_region;
7895 cairo_region_get_extents (event.expose.region, &event.expose.area);
7896 display = gdk_window_get_display (event.expose.window);
7897 _gdk_event_queue_append (display, gdk_event_copy (&event));
7900 /* Gets the toplevel for a window as used for events,
7901 i.e. including offscreen parents */
7902 static GdkWindowObject *
7903 get_event_parent (GdkWindowObject *window)
7905 if (gdk_window_is_offscreen (window))
7906 return (GdkWindowObject *)gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7908 return window->parent;
7911 /* Gets the toplevel for a window as used for events,
7912 i.e. including offscreen parents going up to the native
7915 get_event_toplevel (GdkWindow *w)
7917 GdkWindowObject *private = GDK_WINDOW_OBJECT (w);
7918 GdkWindowObject *parent;
7920 while ((parent = get_event_parent (private)) != NULL &&
7921 (parent->window_type != GDK_WINDOW_ROOT))
7924 return GDK_WINDOW (private);
7928 _gdk_window_event_parent_of (GdkWindow *parent,
7939 w = (GdkWindow *)get_event_parent ((GdkWindowObject *)w);
7946 update_cursor (GdkDisplay *display,
7949 GdkWindowObject *cursor_window, *parent, *toplevel;
7950 GdkWindow *pointer_window;
7951 GdkWindowImplIface *impl_iface;
7952 GdkPointerWindowInfo *pointer_info;
7953 GdkDeviceGrabInfo *grab;
7956 pointer_info = _gdk_display_get_pointer_info (display, device);
7957 pointer_window = pointer_info->window_under_pointer;
7959 /* We ignore the serials here and just pick the last grab
7960 we've sent, as that would shortly be used anyway. */
7961 grab = _gdk_display_get_last_device_grab (display, device);
7964 /* the pointer is not in a descendant of the grab window */
7965 !_gdk_window_event_parent_of (grab->window, pointer_window))
7967 /* use the cursor from the grab window */
7968 cursor_window = (GdkWindowObject *) grab->window;
7972 /* otherwise use the cursor from the pointer window */
7973 cursor_window = (GdkWindowObject *) pointer_window;
7976 /* Find the first window with the cursor actually set, as
7977 the cursor is inherited from the parent */
7978 while (cursor_window->cursor == NULL &&
7979 (parent = get_event_parent (cursor_window)) != NULL &&
7980 parent->window_type != GDK_WINDOW_ROOT)
7981 cursor_window = parent;
7983 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7986 cursor = cursor_window->cursor;
7988 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7989 * which native window has what cursor set. */
7990 toplevel = (GdkWindowObject *) get_event_toplevel (pointer_window);
7991 impl_iface = GDK_WINDOW_IMPL_GET_IFACE (toplevel->impl);
7992 impl_iface->set_device_cursor ((GdkWindow *) toplevel, device, cursor);
7996 point_in_window (GdkWindowObject *window,
8001 x >= 0 && x < window->width &&
8002 y >= 0 && y < window->height &&
8003 (window->shape == NULL ||
8004 cairo_region_contains_point (window->shape,
8006 (window->input_shape == NULL ||
8007 cairo_region_contains_point (window->input_shape,
8012 convert_native_coords_to_toplevel (GdkWindow *window,
8015 gdouble *toplevel_x,
8016 gdouble *toplevel_y)
8018 GdkWindowObject *private = (GdkWindowObject *)window;
8024 while (!gdk_window_is_toplevel (private))
8028 private = private->parent;
8034 return (GdkWindow *)private;
8038 convert_toplevel_coords_to_window (GdkWindow *window,
8044 GdkWindowObject *private;
8045 GdkWindowObject *parent;
8047 GList *children, *l;
8049 private = GDK_WINDOW_OBJECT (window);
8055 while ((parent = get_event_parent (private)) != NULL &&
8056 (parent->window_type != GDK_WINDOW_ROOT))
8058 children = g_list_prepend (children, private);
8062 for (l = children; l != NULL; l = l->next)
8063 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
8065 g_list_free (children);
8071 static GdkWindowObject *
8072 pick_embedded_child (GdkWindowObject *window,
8076 GdkWindowObject *res;
8079 g_signal_emit (window,
8080 signals[PICK_EMBEDDED_CHILD], 0,
8087 _gdk_window_find_child_at (GdkWindow *window,
8091 GdkWindowObject *private, *sub;
8092 double child_x, child_y;
8095 private = (GdkWindowObject *)window;
8097 if (point_in_window (private, x, y))
8099 /* Children is ordered in reverse stack order, i.e. first is topmost */
8100 for (l = private->children; l != NULL; l = l->next)
8104 if (!GDK_WINDOW_IS_MAPPED (sub))
8107 gdk_window_coords_from_parent ((GdkWindow *)sub,
8109 &child_x, &child_y);
8110 if (point_in_window (sub, child_x, child_y))
8111 return (GdkWindow *)sub;
8114 if (private->num_offscreen_children > 0)
8116 sub = pick_embedded_child (private,
8119 return (GdkWindow *)sub;
8127 _gdk_window_find_descendant_at (GdkWindow *toplevel,
8133 GdkWindowObject *private, *sub;
8134 gdouble child_x, child_y;
8138 private = (GdkWindowObject *)toplevel;
8140 if (point_in_window (private, x, y))
8145 /* Children is ordered in reverse stack order, i.e. first is topmost */
8146 for (l = private->children; l != NULL; l = l->next)
8150 if (!GDK_WINDOW_IS_MAPPED (sub))
8153 gdk_window_coords_from_parent ((GdkWindow *)sub,
8155 &child_x, &child_y);
8156 if (point_in_window (sub, child_x, child_y))
8166 private->num_offscreen_children > 0)
8168 sub = pick_embedded_child (private,
8174 from_embedder (sub, x, y, &x, &y);
8182 /* Not in window at all */
8191 return (GdkWindow *)private;
8196 * @window: a toplevel #GdkWindow
8198 * Emits a short beep associated to @window in the appropriate
8199 * display, if supported. Otherwise, emits a short beep on
8200 * the display just as gdk_display_beep().
8205 gdk_window_beep (GdkWindow *window)
8207 GdkDisplay *display;
8208 GdkWindow *toplevel;
8210 g_return_if_fail (GDK_IS_WINDOW (window));
8212 if (GDK_WINDOW_DESTROYED (window))
8215 toplevel = get_event_toplevel (window);
8216 display = gdk_window_get_display (window);
8218 if (toplevel && !gdk_window_is_offscreen ((GdkWindowObject *)toplevel))
8219 _gdk_windowing_window_beep (toplevel);
8221 gdk_display_beep (display);
8225 * gdk_window_set_support_multidevice:
8226 * @window: a #GdkWindow.
8227 * @support_multidevice: %TRUE to enable multidevice support in @window.
8229 * This function will enable multidevice features in @window.
8231 * Multidevice aware windows will need to handle properly multiple,
8232 * per device enter/leave events, device grabs and grab ownerships.
8237 gdk_window_set_support_multidevice (GdkWindow *window,
8238 gboolean support_multidevice)
8240 GdkWindowObject *private = (GdkWindowObject *) window;
8242 g_return_if_fail (GDK_IS_WINDOW (window));
8244 if (GDK_WINDOW_DESTROYED (window))
8247 if (private->support_multidevice == support_multidevice)
8250 private->support_multidevice = support_multidevice;
8252 /* FIXME: What to do if called when some pointers are inside the window ? */
8256 * gdk_window_get_support_multidevice:
8257 * @window: a #GdkWindow.
8259 * Returns %TRUE if the window is aware of the existence of multiple
8262 * Returns: %TRUE if the window handles multidevice features.
8267 gdk_window_get_support_multidevice (GdkWindow *window)
8269 GdkWindowObject *private = (GdkWindowObject *) window;
8271 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8273 if (GDK_WINDOW_DESTROYED (window))
8276 return private->support_multidevice;
8279 static const guint type_masks[] = {
8280 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8281 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8282 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8283 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8284 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8285 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8286 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8287 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8288 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8289 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8290 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8291 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8292 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8293 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8294 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8295 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8296 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8297 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8298 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8299 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8300 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8301 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8302 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8303 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8304 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8305 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8306 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8307 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8308 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8309 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8310 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8311 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8312 0, /* GDK_WINDOW_STATE = 32 */
8313 0, /* GDK_SETTING = 33 */
8314 0, /* GDK_OWNER_CHANGE = 34 */
8315 0, /* GDK_GRAB_BROKEN = 35 */
8316 0, /* GDK_DAMAGE = 36 */
8318 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8320 /* send motion events if the right buttons are down */
8322 update_evmask_for_button_motion (guint evmask,
8323 GdkModifierType mask)
8325 if (evmask & GDK_BUTTON_MOTION_MASK &&
8326 mask & (GDK_BUTTON1_MASK |
8331 evmask |= GDK_POINTER_MOTION_MASK;
8333 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8334 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8335 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8336 evmask |= GDK_POINTER_MOTION_MASK;
8342 is_button_type (GdkEventType type)
8344 return type == GDK_BUTTON_PRESS ||
8345 type == GDK_2BUTTON_PRESS ||
8346 type == GDK_3BUTTON_PRESS ||
8347 type == GDK_BUTTON_RELEASE ||
8352 is_motion_type (GdkEventType type)
8354 return type == GDK_MOTION_NOTIFY ||
8355 type == GDK_ENTER_NOTIFY ||
8356 type == GDK_LEAVE_NOTIFY;
8359 static GdkWindowObject *
8360 find_common_ancestor (GdkWindowObject *win1,
8361 GdkWindowObject *win2)
8363 GdkWindowObject *tmp;
8364 GList *path1 = NULL, *path2 = NULL;
8365 GList *list1, *list2;
8368 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8370 path1 = g_list_prepend (path1, tmp);
8371 tmp = get_event_parent (tmp);
8375 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8377 path2 = g_list_prepend (path2, tmp);
8378 tmp = get_event_parent (tmp);
8384 while (list1 && list2 && (list1->data == list2->data))
8386 tmp = (GdkWindowObject *)list1->data;
8387 list1 = g_list_next (list1);
8388 list2 = g_list_next (list2);
8390 g_list_free (path1);
8391 g_list_free (path2);
8397 _gdk_make_event (GdkWindow *window,
8399 GdkEvent *event_in_queue,
8400 gboolean before_event)
8402 GdkEvent *event = gdk_event_new (type);
8404 GdkModifierType the_state;
8406 the_time = gdk_event_get_time (event_in_queue);
8407 gdk_event_get_state (event_in_queue, &the_state);
8409 event->any.window = g_object_ref (window);
8410 event->any.send_event = FALSE;
8411 if (event_in_queue && event_in_queue->any.send_event)
8412 event->any.send_event = TRUE;
8416 case GDK_MOTION_NOTIFY:
8417 event->motion.time = the_time;
8418 event->motion.axes = NULL;
8419 event->motion.state = the_state;
8422 case GDK_BUTTON_PRESS:
8423 case GDK_2BUTTON_PRESS:
8424 case GDK_3BUTTON_PRESS:
8425 case GDK_BUTTON_RELEASE:
8426 event->button.time = the_time;
8427 event->button.axes = NULL;
8428 event->button.state = the_state;
8432 event->scroll.time = the_time;
8433 event->scroll.state = the_state;
8437 case GDK_KEY_RELEASE:
8438 event->key.time = the_time;
8439 event->key.state = the_state;
8442 case GDK_ENTER_NOTIFY:
8443 case GDK_LEAVE_NOTIFY:
8444 event->crossing.time = the_time;
8445 event->crossing.state = the_state;
8448 case GDK_PROPERTY_NOTIFY:
8449 event->property.time = the_time;
8450 event->property.state = the_state;
8453 case GDK_SELECTION_CLEAR:
8454 case GDK_SELECTION_REQUEST:
8455 case GDK_SELECTION_NOTIFY:
8456 event->selection.time = the_time;
8459 case GDK_PROXIMITY_IN:
8460 case GDK_PROXIMITY_OUT:
8461 event->proximity.time = the_time;
8464 case GDK_DRAG_ENTER:
8465 case GDK_DRAG_LEAVE:
8466 case GDK_DRAG_MOTION:
8467 case GDK_DRAG_STATUS:
8468 case GDK_DROP_START:
8469 case GDK_DROP_FINISHED:
8470 event->dnd.time = the_time;
8473 case GDK_FOCUS_CHANGE:
8477 case GDK_CLIENT_EVENT:
8478 case GDK_VISIBILITY_NOTIFY:
8490 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8492 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8495 _gdk_event_queue_append (gdk_window_get_display (window), event);
8501 send_crossing_event (GdkDisplay *display,
8502 GdkWindowObject *toplevel,
8503 GdkWindowObject *window,
8505 GdkCrossingMode mode,
8506 GdkNotifyType notify_type,
8507 GdkWindow *subwindow,
8511 GdkModifierType mask,
8513 GdkEvent *event_in_queue,
8517 guint32 window_event_mask, type_event_mask;
8518 GdkDeviceGrabInfo *grab;
8519 gboolean block_event = FALSE;
8521 grab = _gdk_display_has_device_grab (display, device, serial);
8524 !grab->owner_events)
8526 /* !owner_event => only report events wrt grab window, ignore rest */
8527 if ((GdkWindow *)window != grab->window)
8529 window_event_mask = grab->event_mask;
8532 window_event_mask = window->event_mask;
8534 if (type == GDK_LEAVE_NOTIFY)
8536 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8537 window->devices_inside = g_list_remove (window->devices_inside, device);
8539 if (!window->support_multidevice && window->devices_inside)
8541 /* Block leave events unless it's the last pointer */
8547 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8549 if (!window->support_multidevice && window->devices_inside)
8551 /* Only emit enter events for the first device */
8555 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8556 device->mode != GDK_MODE_DISABLED &&
8557 !g_list_find (window->devices_inside, device))
8558 window->devices_inside = g_list_prepend (window->devices_inside, device);
8564 if (window_event_mask & type_event_mask)
8566 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8567 gdk_event_set_device (event, device);
8568 event->crossing.time = time_;
8569 event->crossing.subwindow = subwindow;
8571 g_object_ref (subwindow);
8572 convert_toplevel_coords_to_window ((GdkWindow *)window,
8573 toplevel_x, toplevel_y,
8574 &event->crossing.x, &event->crossing.y);
8575 event->crossing.x_root = toplevel_x + toplevel->x;
8576 event->crossing.y_root = toplevel_y + toplevel->y;
8577 event->crossing.mode = mode;
8578 event->crossing.detail = notify_type;
8579 event->crossing.focus = FALSE;
8580 event->crossing.state = mask;
8585 /* The coordinates are in the toplevel window that src/dest are in.
8586 * src and dest are always (if != NULL) in the same toplevel, as
8587 * we get a leave-notify and set the window_under_pointer to null
8588 * before crossing to another toplevel.
8591 _gdk_synthesize_crossing_events (GdkDisplay *display,
8595 GdkCrossingMode mode,
8598 GdkModifierType mask,
8600 GdkEvent *event_in_queue,
8602 gboolean non_linear)
8605 GdkWindowObject *win, *last, *next;
8609 GdkWindowObject *toplevel;
8610 GdkNotifyType notify_type;
8612 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8614 a = (GdkWindowObject *)src;
8615 b = (GdkWindowObject *)dest;
8617 return; /* No crossings generated between src and dest */
8619 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8621 if (a && gdk_window_get_device_events (src, device) == 0)
8624 if (b && gdk_window_get_device_events (dest, device) == 0)
8631 c = find_common_ancestor (a, b);
8633 non_linear |= (c != a) && (c != b);
8635 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8637 toplevel = (GdkWindowObject *)gdk_window_get_toplevel ((GdkWindow *)a);
8639 /* Traverse up from a to (excluding) c sending leave events */
8641 notify_type = GDK_NOTIFY_NONLINEAR;
8643 notify_type = GDK_NOTIFY_INFERIOR;
8645 notify_type = GDK_NOTIFY_ANCESTOR;
8646 send_crossing_event (display, toplevel,
8647 a, GDK_LEAVE_NOTIFY,
8651 toplevel_x, toplevel_y,
8659 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8661 notify_type = GDK_NOTIFY_VIRTUAL;
8664 win = get_event_parent (a);
8665 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8667 send_crossing_event (display, toplevel,
8668 win, GDK_LEAVE_NOTIFY,
8673 toplevel_x, toplevel_y,
8679 win = get_event_parent (win);
8684 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8686 toplevel = (GdkWindowObject *)gdk_window_get_toplevel ((GdkWindow *)b);
8688 /* Traverse down from c to b */
8692 win = get_event_parent (b);
8693 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8695 path = g_list_prepend (path, win);
8696 win = get_event_parent (win);
8700 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8702 notify_type = GDK_NOTIFY_VIRTUAL;
8707 win = (GdkWindowObject *)list->data;
8708 list = g_list_next (list);
8710 next = (GdkWindowObject *)list->data;
8714 send_crossing_event (display, toplevel,
8715 win, GDK_ENTER_NOTIFY,
8720 toplevel_x, toplevel_y,
8730 notify_type = GDK_NOTIFY_NONLINEAR;
8732 notify_type = GDK_NOTIFY_ANCESTOR;
8734 notify_type = GDK_NOTIFY_INFERIOR;
8736 send_crossing_event (display, toplevel,
8737 b, GDK_ENTER_NOTIFY,
8742 toplevel_x, toplevel_y,
8749 /* Returns the window inside the event window with the pointer in it
8750 * at the specified coordinates, or NULL if its not in any child of
8751 * the toplevel. It also takes into account !owner_events grabs.
8754 get_pointer_window (GdkDisplay *display,
8755 GdkWindow *event_window,
8761 GdkWindow *pointer_window;
8762 GdkDeviceGrabInfo *grab;
8763 GdkPointerWindowInfo *pointer_info;
8765 pointer_info = _gdk_display_get_pointer_info (display, device);
8767 if (event_window == pointer_info->toplevel_under_pointer)
8769 _gdk_window_find_descendant_at (event_window,
8770 toplevel_x, toplevel_y,
8773 pointer_window = NULL;
8775 grab = _gdk_display_has_device_grab (display, device, serial);
8777 !grab->owner_events &&
8778 pointer_window != grab->window)
8779 pointer_window = NULL;
8781 return pointer_window;
8785 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8789 GdkPointerWindowInfo *device_info;
8791 /* We don't track this if all native, and it can cause issues
8792 with the update_cursor call below */
8793 if (_gdk_native_windows)
8796 device_info = _gdk_display_get_pointer_info (display, device);
8798 if (device_info->window_under_pointer)
8799 g_object_unref (device_info->window_under_pointer);
8800 device_info->window_under_pointer = window;
8804 g_object_ref (window);
8805 update_cursor (display, device);
8808 _gdk_display_enable_motion_hints (display, device);
8813 * @window: the #GdkWindow which will own the grab (the grab window).
8814 * @owner_events: if %FALSE then all pointer events are reported with respect to
8815 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8816 * events for this application are reported as normal, but pointer events outside
8817 * this application are reported with respect to @window and only if selected by
8818 * @event_mask. In either mode, unreported events are discarded.
8819 * @event_mask: specifies the event mask, which is used in accordance with
8820 * @owner_events. Note that only pointer events (i.e. button and motion events)
8822 * @confine_to: If non-%NULL, the pointer will be confined to this
8823 * window during the grab. If the pointer is outside @confine_to, it will
8824 * automatically be moved to the closest edge of @confine_to and enter
8825 * and leave events will be generated as necessary.
8826 * @cursor: the cursor to display while the grab is active. If this is %NULL then
8827 * the normal cursors are used for @window and its descendants, and the cursor
8828 * for @window is used for all other windows.
8829 * @time_: the timestamp of the event which led to this pointer grab. This usually
8830 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8831 * the time isn't known.
8833 * Grabs the pointer (usually a mouse) so that all events are passed to this
8834 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8835 * the grab window becomes unviewable.
8836 * This overrides any previous pointer grab by this client.
8838 * Pointer grabs are used for operations which need complete control over mouse
8839 * events, even if the mouse leaves the application.
8840 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8841 * the #GtkHPaned and #GtkVPaned widgets, and for resizing columns in #GtkCList
8844 * Note that if the event mask of an X window has selected both button press and
8845 * button release events, then a button press event will cause an automatic
8846 * pointer grab until the button is released.
8847 * X does this automatically since most applications expect to receive button
8848 * press and release events in pairs.
8849 * It is equivalent to a pointer grab on the window with @owner_events set to
8852 * If you set up anything at the time you take the grab that needs to be cleaned
8853 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8854 * are emitted when the grab ends unvoluntarily.
8856 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8858 * Deprecated: 3.0: Use gdk_device_grab() instead.
8861 gdk_pointer_grab (GdkWindow * window,
8862 gboolean owner_events,
8863 GdkEventMask event_mask,
8864 GdkWindow * confine_to,
8869 GdkDisplay *display;
8870 GdkDeviceManager *device_manager;
8872 GdkGrabStatus res = 0;
8874 GList *devices, *dev;
8876 g_return_val_if_fail (window != NULL, 0);
8877 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8878 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8880 /* We need a native window for confine to to work, ensure we have one */
8883 if (!gdk_window_ensure_native (confine_to))
8885 g_warning ("Can't confine to grabbed window, not native");
8890 /* Non-viewable client side window => fail */
8891 if (!_gdk_window_has_impl (window) &&
8892 !gdk_window_is_viewable (window))
8893 return GDK_GRAB_NOT_VIEWABLE;
8895 if (_gdk_native_windows)
8898 native = gdk_window_get_toplevel (window);
8899 while (gdk_window_is_offscreen ((GdkWindowObject *)native))
8901 native = gdk_offscreen_window_get_embedder (native);
8903 if (native == NULL ||
8904 (!_gdk_window_has_impl (native) &&
8905 !gdk_window_is_viewable (native)))
8906 return GDK_GRAB_NOT_VIEWABLE;
8908 native = gdk_window_get_toplevel (native);
8911 display = gdk_window_get_display (window);
8913 serial = _gdk_windowing_window_get_next_serial (display);
8914 device_manager = gdk_display_get_device_manager (display);
8915 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8917 /* FIXME: Should this be generic to all backends? */
8918 /* FIXME: What happens with extended devices? */
8919 for (dev = devices; dev; dev = dev->next)
8923 if (device->source != GDK_SOURCE_MOUSE)
8926 res = _gdk_windowing_device_grab (device,
8930 get_native_grab_event_mask (event_mask),
8935 if (res == GDK_GRAB_SUCCESS)
8936 _gdk_display_add_device_grab (display,
8948 /* FIXME: handle errors when grabbing */
8950 g_list_free (devices);
8956 * gdk_keyboard_grab:
8957 * @window: the #GdkWindow which will own the grab (the grab window).
8958 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8959 * @window. If %TRUE then keyboard events for this application are
8960 * reported as normal, but keyboard events outside this application
8961 * are reported with respect to @window. Both key press and key
8962 * release events are always reported, independant of the event mask
8963 * set by the application.
8964 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8967 * Grabs the keyboard so that all events are passed to this
8968 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8969 * This overrides any previous keyboard grab by this client.
8971 * If you set up anything at the time you take the grab that needs to be cleaned
8972 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8973 * are emitted when the grab ends unvoluntarily.
8975 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8977 * Deprecated: 3.0: Use gdk_device_grab() instead.
8980 gdk_keyboard_grab (GdkWindow *window,
8981 gboolean owner_events,
8985 GdkDisplay *display;
8986 GdkDeviceManager *device_manager;
8988 GdkGrabStatus res = 0;
8990 GList *devices, *dev;
8992 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8994 /* Non-viewable client side window => fail */
8995 if (!_gdk_window_has_impl (window) &&
8996 !gdk_window_is_viewable (window))
8997 return GDK_GRAB_NOT_VIEWABLE;
8999 if (_gdk_native_windows)
9002 native = gdk_window_get_toplevel (window);
9004 while (gdk_window_is_offscreen ((GdkWindowObject *)native))
9006 native = gdk_offscreen_window_get_embedder (native);
9008 if (native == NULL ||
9009 (!_gdk_window_has_impl (native) &&
9010 !gdk_window_is_viewable (native)))
9011 return GDK_GRAB_NOT_VIEWABLE;
9013 native = gdk_window_get_toplevel (native);
9016 display = gdk_window_get_display (window);
9018 serial = _gdk_windowing_window_get_next_serial (display);
9019 device_manager = gdk_display_get_device_manager (display);
9020 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
9022 /* FIXME: Should this be generic to all backends? */
9023 /* FIXME: What happens with extended devices? */
9024 for (dev = devices; dev; dev = dev->next)
9028 if (device->source != GDK_SOURCE_KEYBOARD)
9031 res = _gdk_windowing_device_grab (device,
9035 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
9040 if (res == GDK_GRAB_SUCCESS)
9041 _gdk_display_add_device_grab (display,
9052 /* FIXME: handle errors when grabbing */
9054 g_list_free (devices);
9060 * gdk_window_geometry_changed:
9061 * @window: an embedded offscreen #GdkWindow
9063 * This function informs GDK that the geometry of an embedded
9064 * offscreen window has changed. This is necessary for GDK to keep
9065 * track of which offscreen window the pointer is in.
9070 gdk_window_geometry_changed (GdkWindow *window)
9072 _gdk_synthesize_crossing_events_for_geometry_change (window);
9076 do_synthesize_crossing_event (gpointer data)
9078 GdkDisplay *display;
9079 GdkWindow *changed_toplevel;
9080 GdkWindowObject *changed_toplevel_priv;
9081 GHashTableIter iter;
9082 gpointer key, value;
9085 changed_toplevel = data;
9086 changed_toplevel_priv = (GdkWindowObject *)changed_toplevel;
9088 changed_toplevel_priv->synthesize_crossing_event_queued = FALSE;
9090 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9093 display = gdk_window_get_display (changed_toplevel);
9094 serial = _gdk_windowing_window_get_next_serial (display);
9095 g_hash_table_iter_init (&iter, display->pointers_info);
9097 while (g_hash_table_iter_next (&iter, &key, &value))
9099 GdkWindow *new_window_under_pointer;
9100 GdkPointerWindowInfo *pointer_info = value;
9101 GdkDevice *device = key;
9103 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9105 new_window_under_pointer =
9106 get_pointer_window (display, changed_toplevel,
9108 pointer_info->toplevel_x,
9109 pointer_info->toplevel_y,
9111 if (new_window_under_pointer != pointer_info->window_under_pointer)
9113 _gdk_synthesize_crossing_events (display,
9114 pointer_info->window_under_pointer,
9115 new_window_under_pointer,
9117 GDK_CROSSING_NORMAL,
9118 pointer_info->toplevel_x,
9119 pointer_info->toplevel_y,
9120 pointer_info->state,
9125 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9134 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9136 GdkDisplay *display;
9137 GdkWindow *toplevel;
9138 GdkWindowObject *toplevel_priv;
9140 if (_gdk_native_windows)
9141 return; /* We use the native crossing events if all native */
9143 display = gdk_window_get_display (changed_window);
9145 toplevel = get_event_toplevel (changed_window);
9146 toplevel_priv = (GdkWindowObject *) toplevel;
9148 if (!toplevel_priv->synthesize_crossing_event_queued)
9150 toplevel_priv->synthesize_crossing_event_queued = TRUE;
9152 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9153 do_synthesize_crossing_event,
9154 g_object_ref (toplevel),
9159 /* Don't use for crossing events */
9161 get_event_window (GdkDisplay *display,
9163 GdkWindow *pointer_window,
9165 GdkModifierType mask,
9170 GdkWindow *grab_window;
9172 GdkDeviceGrabInfo *grab;
9174 grab = _gdk_display_has_device_grab (display, device, serial);
9176 if (grab != NULL && !grab->owner_events)
9178 evmask = grab->event_mask;
9179 evmask = update_evmask_for_button_motion (evmask, mask);
9181 grab_window = grab->window;
9183 if (evmask & type_masks[type])
9186 *evmask_out = evmask;
9193 w = (GdkWindowObject *)pointer_window;
9196 evmask = w->event_mask;
9197 evmask = update_evmask_for_button_motion (evmask, mask);
9199 if (evmask & type_masks[type])
9202 *evmask_out = evmask;
9203 return (GdkWindow *)w;
9206 w = get_event_parent (w);
9212 evmask = grab->event_mask;
9213 evmask = update_evmask_for_button_motion (evmask, mask);
9215 if (evmask & type_masks[type])
9218 *evmask_out = evmask;
9219 return grab->window;
9229 proxy_pointer_event (GdkDisplay *display,
9230 GdkEvent *source_event,
9233 GdkWindow *toplevel_window, *event_window;
9234 GdkWindow *pointer_window;
9235 GdkPointerWindowInfo *pointer_info;
9239 gdouble toplevel_x, toplevel_y;
9241 gboolean non_linear;
9243 event_window = source_event->any.window;
9244 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9245 gdk_event_get_state (source_event, &state);
9246 time_ = gdk_event_get_time (source_event);
9247 device = gdk_event_get_device (source_event);
9248 pointer_info = _gdk_display_get_pointer_info (display, device);
9249 toplevel_window = convert_native_coords_to_toplevel (event_window,
9250 toplevel_x, toplevel_y,
9251 &toplevel_x, &toplevel_y);
9254 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9255 source_event->type == GDK_ENTER_NOTIFY) &&
9256 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9257 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9260 /* If we get crossing events with subwindow unexpectedly being NULL
9261 that means there is a native subwindow that gdk doesn't know about.
9262 We track these and forward them, with the correct virtual window
9264 This is important to get right, as metacity uses gdk for the frame
9265 windows, but gdk doesn't know about the client windows reparented
9267 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9268 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9269 (source_event->type == GDK_ENTER_NOTIFY &&
9270 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9271 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9272 source_event->crossing.subwindow == NULL)
9274 /* Left for an unknown (to gdk) subwindow */
9276 /* Send leave events from window under pointer to event window
9277 that will get the subwindow == NULL window */
9278 _gdk_synthesize_crossing_events (display,
9279 pointer_info->window_under_pointer,
9282 source_event->crossing.mode,
9283 toplevel_x, toplevel_y,
9289 /* Send subwindow == NULL event */
9290 send_crossing_event (display,
9291 (GdkWindowObject *)toplevel_window,
9292 (GdkWindowObject *)event_window,
9294 source_event->crossing.mode,
9295 source_event->crossing.detail,
9298 toplevel_x, toplevel_y,
9303 _gdk_display_set_window_under_pointer (display, device, NULL);
9307 pointer_window = get_pointer_window (display, toplevel_window, device,
9308 toplevel_x, toplevel_y, serial);
9310 if (((source_event->type == GDK_ENTER_NOTIFY &&
9311 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9312 (source_event->type == GDK_LEAVE_NOTIFY &&
9313 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9314 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9315 source_event->crossing.subwindow == NULL)
9317 /* Entered from an unknown (to gdk) subwindow */
9319 /* Send subwindow == NULL event */
9320 send_crossing_event (display,
9321 (GdkWindowObject *)toplevel_window,
9322 (GdkWindowObject *)event_window,
9324 source_event->crossing.mode,
9325 source_event->crossing.detail,
9328 toplevel_x, toplevel_y,
9333 /* Send enter events from event window to pointer_window */
9334 _gdk_synthesize_crossing_events (display,
9338 source_event->crossing.mode,
9339 toplevel_x, toplevel_y,
9342 serial, non_linear);
9343 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9347 if (pointer_info->window_under_pointer != pointer_window)
9349 /* Either a toplevel crossing notify that ended up inside a child window,
9350 or a motion notify that got into another child window */
9352 /* Different than last time, send crossing events */
9353 _gdk_synthesize_crossing_events (display,
9354 pointer_info->window_under_pointer,
9357 GDK_CROSSING_NORMAL,
9358 toplevel_x, toplevel_y,
9361 serial, non_linear);
9362 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9364 else if (source_event->type == GDK_MOTION_NOTIFY)
9366 GdkWindow *event_win;
9370 event_win = get_event_window (display,
9379 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9380 gdk_window_get_device_events (event_win, device) == 0)
9386 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9388 gulong *device_serial;
9390 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9392 if (!device_serial ||
9393 (*device_serial != 0 &&
9394 serial < *device_serial))
9395 event_win = NULL; /* Ignore event */
9399 *device_serial = G_MAXULONG;
9403 if (event_win && !display->ignore_core_events)
9405 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9406 event->motion.time = time_;
9407 convert_toplevel_coords_to_window (event_win,
9408 toplevel_x, toplevel_y,
9409 &event->motion.x, &event->motion.y);
9410 event->motion.x_root = source_event->motion.x_root;
9411 event->motion.y_root = source_event->motion.y_root;
9412 event->motion.state = state;
9413 event->motion.is_hint = is_hint;
9414 event->motion.device = source_event->motion.device;
9415 event->motion.axes = g_memdup (source_event->motion.axes,
9416 sizeof (gdouble) * source_event->motion.device->num_axes);
9420 /* unlink all move events from queue.
9421 We handle our own, including our emulated masks. */
9425 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9426 GDK_BUTTON2_MASK | \
9427 GDK_BUTTON3_MASK | \
9428 GDK_BUTTON4_MASK | \
9432 proxy_button_event (GdkEvent *source_event,
9435 GdkWindow *toplevel_window, *event_window;
9436 GdkWindow *event_win;
9437 GdkWindow *pointer_window;
9438 GdkWindowObject *parent;
9443 gdouble toplevel_x, toplevel_y;
9444 GdkDisplay *display;
9448 type = source_event->any.type;
9449 event_window = source_event->any.window;
9450 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9451 gdk_event_get_state (source_event, &state);
9452 time_ = gdk_event_get_time (source_event);
9453 device = gdk_event_get_device (source_event);
9454 display = gdk_window_get_display (source_event->any.window);
9455 toplevel_window = convert_native_coords_to_toplevel (event_window,
9456 toplevel_x, toplevel_y,
9457 &toplevel_x, &toplevel_y);
9459 if (type == GDK_BUTTON_PRESS &&
9460 !source_event->any.send_event &&
9461 _gdk_display_has_device_grab (display, device, serial) == NULL)
9464 _gdk_window_find_descendant_at (toplevel_window,
9465 toplevel_x, toplevel_y,
9468 /* Find the event window, that gets the grab */
9469 w = (GdkWindowObject *)pointer_window;
9471 (parent = get_event_parent (w)) != NULL &&
9472 parent->window_type != GDK_WINDOW_ROOT)
9474 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9478 pointer_window = (GdkWindow *)w;
9480 _gdk_display_add_device_grab (display,
9486 gdk_window_get_events (pointer_window),
9490 _gdk_display_device_grab_update (display, device, serial);
9493 pointer_window = get_pointer_window (display, toplevel_window, device,
9494 toplevel_x, toplevel_y,
9497 event_win = get_event_window (display,
9503 if (event_win == NULL || display->ignore_core_events)
9506 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9507 gdk_window_get_device_events (event_win, device) == 0)
9510 event = _gdk_make_event (event_win, type, source_event, FALSE);
9514 case GDK_BUTTON_PRESS:
9515 case GDK_BUTTON_RELEASE:
9516 event->button.button = source_event->button.button;
9517 convert_toplevel_coords_to_window (event_win,
9518 toplevel_x, toplevel_y,
9519 &event->button.x, &event->button.y);
9520 event->button.x_root = source_event->button.x_root;
9521 event->button.y_root = source_event->button.y_root;
9522 event->button.state = state;
9523 event->button.device = source_event->button.device;
9524 event->button.axes = g_memdup (source_event->button.axes,
9525 sizeof (gdouble) * source_event->button.device->num_axes);
9527 if (type == GDK_BUTTON_PRESS)
9528 _gdk_event_button_generate (display, event);
9532 event->scroll.direction = source_event->scroll.direction;
9533 convert_toplevel_coords_to_window (event_win,
9534 toplevel_x, toplevel_y,
9535 &event->scroll.x, &event->scroll.y);
9536 event->scroll.x_root = source_event->scroll.x_root;
9537 event->scroll.y_root = source_event->scroll.y_root;
9538 event->scroll.state = state;
9539 event->scroll.device = source_event->scroll.device;
9546 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9549 #ifdef DEBUG_WINDOW_PRINTING
9551 gdk_window_print (GdkWindowObject *window,
9555 const char *window_types[] = {
9565 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9566 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9567 window->x, window->y,
9568 window->width, window->height
9571 if (gdk_window_has_impl (window))
9573 #ifdef GDK_WINDOWING_X11
9574 g_print (" impl(0x%lx)", gdk_x11_drawable_get_xid (GDK_DRAWABLE (window)));
9578 if (window->window_type != GDK_WINDOW_CHILD)
9579 g_print (" %s", window_types[window->window_type]);
9581 if (window->input_only)
9582 g_print (" input-only");
9585 g_print (" shaped");
9587 if (!gdk_window_is_visible ((GdkWindow *)window))
9588 g_print (" hidden");
9590 g_print (" abs[%d,%d]",
9591 window->abs_x, window->abs_y);
9593 cairo_region_get_extents (window->clip_region, &r);
9594 if (cairo_region_is_empty (window->clip_region))
9595 g_print (" clipbox[empty]");
9597 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9604 gdk_window_print_tree (GdkWindow *window,
9606 gboolean include_input_only)
9608 GdkWindowObject *private;
9611 private = (GdkWindowObject *)window;
9613 if (private->input_only && !include_input_only)
9616 gdk_window_print (private, indent);
9618 for (l = private->children; l != NULL; l = l->next)
9619 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9622 #endif /* DEBUG_WINDOW_PRINTING */
9625 _gdk_windowing_got_event (GdkDisplay *display,
9630 GdkWindow *event_window;
9631 GdkWindowObject *event_private;
9633 gboolean unlink_event;
9634 guint old_state, old_button;
9635 GdkDeviceGrabInfo *button_release_grab;
9636 GdkPointerWindowInfo *pointer_info;
9638 gboolean is_toplevel;
9640 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9641 display->last_event_time = gdk_event_get_time (event);
9643 device = gdk_event_get_device (event);
9649 g_object_get (device, "input-mode", &mode, NULL);
9650 _gdk_display_device_grab_update (display, device, serial);
9652 if (mode == GDK_MODE_DISABLED ||
9653 !_gdk_display_check_grab_ownership (display, device, serial))
9655 /* Device events are blocked by another
9656 * device grab, or the device is disabled
9658 unlink_event = TRUE;
9663 event_window = event->any.window;
9667 pointer_info = _gdk_display_get_pointer_info (display, device);
9668 event_private = GDK_WINDOW_OBJECT (event_window);
9670 #ifdef DEBUG_WINDOW_PRINTING
9671 if (event->type == GDK_KEY_PRESS &&
9672 (event->key.keyval == 0xa7 ||
9673 event->key.keyval == 0xbd))
9675 gdk_window_print_tree (event_window, 0,
9676 event->key.keyval == 0xbd);
9680 if (_gdk_native_windows)
9682 if (event->type == GDK_BUTTON_PRESS &&
9683 !event->any.send_event &&
9684 _gdk_display_has_device_grab (display, device, serial) == NULL)
9686 _gdk_display_add_device_grab (display,
9692 gdk_window_get_events (event_window),
9694 gdk_event_get_time (event),
9696 _gdk_display_device_grab_update (display, device, serial);
9698 if (event->type == GDK_BUTTON_RELEASE &&
9699 !event->any.send_event)
9701 button_release_grab =
9702 _gdk_display_has_device_grab (display, device, serial);
9703 if (button_release_grab &&
9704 button_release_grab->implicit &&
9705 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9707 button_release_grab->serial_end = serial;
9708 button_release_grab->implicit_ungrab = FALSE;
9709 _gdk_display_device_grab_update (display, device, serial);
9713 if (event->type == GDK_BUTTON_PRESS)
9714 _gdk_event_button_generate (display, event);
9719 if (event->type == GDK_VISIBILITY_NOTIFY)
9721 event_private->native_visibility = event->visibility.state;
9722 gdk_window_update_visibility_recursively (event_private,
9727 if (!(is_button_type (event->type) ||
9728 is_motion_type (event->type)) ||
9729 event_private->window_type == GDK_WINDOW_ROOT)
9732 is_toplevel = gdk_window_is_toplevel (event_private);
9734 if ((event->type == GDK_ENTER_NOTIFY ||
9735 event->type == GDK_LEAVE_NOTIFY) &&
9736 (event->crossing.mode == GDK_CROSSING_GRAB ||
9737 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9738 (_gdk_display_has_device_grab (display, device, serial) ||
9739 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9741 /* We synthesize all crossing events due to grabs ourselves,
9742 * so we ignore the native ones caused by our native pointer_grab
9743 * calls. Otherwise we would proxy these crossing event and cause
9744 * multiple copies of crossing events for grabs.
9746 * We do want to handle grabs from other clients though, as for
9747 * instance alt-tab in metacity causes grabs like these and
9748 * we want to handle those. Thus the has_pointer_grab check.
9750 * Implicit grabs on child windows create some grabbing events
9751 * that are sent before the button press. This means we can't
9752 * detect these with the has_pointer_grab check (as the implicit
9753 * grab is only noticed when we get button press event), so we
9754 * detect these events by checking for INFERIOR enter or leave
9755 * events. These should never be a problem to filter out.
9758 /* We ended up in this window after some (perhaps other clients)
9759 grab, so update the toplevel_under_window state */
9761 event->type == GDK_ENTER_NOTIFY &&
9762 event->crossing.mode == GDK_CROSSING_UNGRAB)
9764 if (pointer_info->toplevel_under_pointer)
9765 g_object_unref (pointer_info->toplevel_under_pointer);
9766 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9769 unlink_event = TRUE;
9773 /* Track toplevel_under_pointer */
9776 if (event->type == GDK_ENTER_NOTIFY &&
9777 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9779 if (pointer_info->toplevel_under_pointer)
9780 g_object_unref (pointer_info->toplevel_under_pointer);
9781 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9783 else if (event->type == GDK_LEAVE_NOTIFY &&
9784 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9785 pointer_info->toplevel_under_pointer == event_window)
9787 if (pointer_info->toplevel_under_pointer)
9788 g_object_unref (pointer_info->toplevel_under_pointer);
9789 pointer_info->toplevel_under_pointer = NULL;
9793 /* Store last pointer window and position/state */
9794 old_state = pointer_info->state;
9795 old_button = pointer_info->button;
9797 gdk_event_get_coords (event, &x, &y);
9798 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9799 pointer_info->toplevel_x = x;
9800 pointer_info->toplevel_y = y;
9801 gdk_event_get_state (event, &pointer_info->state);
9802 if (event->type == GDK_BUTTON_PRESS ||
9803 event->type == GDK_BUTTON_RELEASE)
9804 pointer_info->button = event->button.button;
9807 (pointer_info->state != old_state ||
9808 pointer_info->button != old_button))
9809 _gdk_display_enable_motion_hints (display, device);
9811 unlink_event = FALSE;
9812 if (is_motion_type (event->type))
9813 unlink_event = proxy_pointer_event (display,
9816 else if (is_button_type (event->type))
9817 unlink_event = proxy_button_event (event,
9820 if (event->type == GDK_BUTTON_RELEASE &&
9821 !event->any.send_event)
9823 button_release_grab =
9824 _gdk_display_has_device_grab (display, device, serial);
9825 if (button_release_grab &&
9826 button_release_grab->implicit &&
9827 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9829 button_release_grab->serial_end = serial;
9830 button_release_grab->implicit_ungrab = FALSE;
9831 _gdk_display_device_grab_update (display, device, serial);
9838 _gdk_event_queue_remove_link (display, event_link);
9839 g_list_free_1 (event_link);
9840 gdk_event_free (event);
9846 get_extension_event_window (GdkDisplay *display,
9847 GdkWindow *pointer_window,
9852 GdkWindow *grab_window;
9854 GdkDeviceGrabInfo *grab;
9856 /* FIXME: which device? */
9857 grab = _gdk_display_has_device_grab (display, display->core_pointer, serial);
9859 if (grab != NULL && !grab->owner_events)
9861 evmask = grab->event_mask;
9863 grab_window = grab->window;
9865 if (evmask & type_masks[type])
9871 w = (GdkWindowObject *)pointer_window;
9874 evmask = w->extension_events;
9876 if (evmask & type_masks[type])
9877 return (GdkWindow *)w;
9879 w = get_event_parent (w);
9885 evmask = grab->event_mask;
9887 if (evmask & type_masks[type])
9888 return grab->window;
9898 _gdk_window_get_input_window_for_event (GdkWindow *native_window,
9899 GdkEventType event_type,
9903 GdkDisplay *display;
9904 GdkWindow *toplevel_window;
9905 GdkWindow *pointer_window;
9906 GdkWindow *event_win;
9907 gdouble toplevel_x, toplevel_y;
9912 display = gdk_window_get_display (native_window);
9913 toplevel_window = convert_native_coords_to_toplevel (native_window,
9914 toplevel_x, toplevel_y,
9915 &toplevel_x, &toplevel_y);
9916 /* FIXME: which device? */
9917 pointer_window = get_pointer_window (display, toplevel_window, NULL,
9918 toplevel_x, toplevel_y, serial);
9919 event_win = get_extension_event_window (display,
9928 * gdk_window_create_similar_surface:
9929 * @window: window to make new surface similar to
9930 * @content: the content for the new surface
9931 * @width: width of the new surface
9932 * @height: height of the new surface
9934 * Create a new surface that is as compatible as possible with the
9935 * given @window. For example the new surface will have the same
9936 * fallback resolution and font options as @window. Generally, the new
9937 * surface will also use the same backend as @window, unless that is
9938 * not possible for some reason. The type of the returned surface may
9939 * be examined with cairo_surface_get_type().
9941 * Initially the surface contents are all 0 (transparent if contents
9942 * have transparency, black otherwise.)
9944 * Returns: a pointer to the newly allocated surface. The caller
9945 * owns the surface and should call cairo_surface_destroy() when done
9948 * This function always returns a valid pointer, but it will return a
9949 * pointer to a "nil" surface if @other is already in an error state
9950 * or any other error occurs.
9955 gdk_window_create_similar_surface (GdkWindow * window,
9956 cairo_content_t content,
9960 cairo_surface_t *window_surface, *surface;
9962 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9964 window_surface = _gdk_drawable_ref_cairo_surface (window);
9966 surface = cairo_surface_create_similar (window_surface,
9970 cairo_surface_destroy (window_surface);