1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <cairo-gobject.h>
30 #include "gdkwindow.h"
32 #include "gdkrectangle.h"
33 #include "gdkinternals.h"
35 #include "gdkscreenprivate.h"
36 #include "gdkdisplayprivate.h"
37 #include "gdkdeviceprivate.h"
38 #include "gdkvisualprivate.h"
39 #include "gdkmarshalers.h"
40 #include "gdkwindowimpl.h"
44 #undef DEBUG_WINDOW_PRINTING
49 * @Short_description: Onscreen display areas in the target window system
52 * A #GdkWindow is a (usually) rectangular region on the screen.
53 * It's a low-level object, used to implement high-level objects such as
54 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
55 * window, the thing a user might think of as a "window" with a titlebar and
56 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
57 * #GtkButton has a #GdkWindow associated with it.
59 * <refsect2 id="COMPOSITED-WINDOWS">
60 * <title>Composited Windows</title>
62 * Normally, the windowing system takes care of rendering the contents of a
63 * child window onto its parent window. This mechanism can be intercepted by
64 * calling gdk_window_set_composited() on the child window. For a
65 * <firstterm>composited</firstterm> window it is the responsibility of the
66 * application to render the window contents at the right spot.
68 * <example id="composited-window-example">
69 * <title>Composited windows</title>
71 * <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>
72 * </programlisting></example>
74 * In the example <xref linkend="composited-window-example"/>, a button is
75 * placed inside of an event box inside of a window. The event box is set as
76 * composited and therefore is no longer automatically drawn to the screen.
78 * When the contents of the event box change, an expose event is generated on
79 * its parent window (which, in this case, belongs to the toplevel #GtkWindow).
80 * The expose handler for this widget is responsible for merging the changes
81 * back on the screen in the way that it wishes.
83 * In our case, we merge the contents with a 50% transparency. We also set the
84 * background colour of the window to red. The effect is that the background
85 * shows through the button.
88 * <refsect2 id="OFFSCREEN-WINDOWS">
89 * <title>Offscreen Windows</title>
91 * Offscreen windows are more general than composited windows, since they allow
92 * not only to modify the rendering of the child window onto its parent, but
93 * also to apply coordinate transformations.
95 * To integrate an offscreen window into a window hierarchy, one has to call
96 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
97 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
98 * select an offscreen child at given coordinates, and the
99 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
100 * offscreen window are used to translate coordinates between the embedder and
101 * the offscreen window.
103 * For rendering an offscreen window onto its embedder, the contents of the
104 * offscreen window are available as a surface, via
105 * gdk_offscreen_window_get_surface().
111 /* Historically a GdkWindow always matches a platform native window,
112 * be it a toplevel window or a child window. In this setup the
113 * GdkWindow (and other GdkDrawables) were platform independent classes,
114 * and the actual platform specific implementation was in a delegate
115 * object availible as "impl" in the window object.
117 * With the addition of client side windows and offscreen windows this
118 * changes a bit. The application-visible GdkWindow object behaves as
119 * it did before, but not all such windows now have a corresponding native
120 * window. Instead windows that are "client side" are emulated by the gdk
121 * code such that clipping, drawing, moving, events etc work as expected.
123 * For GdkWindows that have a native window the "impl" object is the
124 * same as before. However, for all client side windows the impl object
125 * is shared with its parent (i.e. all client windows descendants of one
126 * native window has the same impl.
128 * Additionally there is a new type of platform independent impl object,
129 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
130 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
131 * windows). Such windows work by allocating a #cairo_surface_t as the backing
132 * store for drawing operations, which is resized with the window.
134 * GdkWindows have a pointer to the "impl window" they are in, i.e.
135 * the topmost GdkWindow which have the same "impl" value. This is stored
136 * in impl_window, which is different from the window itself only for client
138 * All GdkWindows (native or not) track the position of the window in the parent
139 * (x, y), the size of the window (width, height), the position of the window
140 * with respect to the impl window (abs_x, abs_y). We also track the clip
141 * region of the window wrt parent windows and siblings, in window-relative
142 * coordinates with and without child windows included (clip_region,
143 * clip_region_with_children).
145 * All toplevel windows are native windows, but also child windows can be
146 * native (although not children of offscreens). We always listen to
147 * a basic set of events (see get_native_event_mask) for these windows
148 * so that we can emulate events for any client side children.
150 * For native windows we apply the calculated clip region as a window shape
151 * so that eg. client side siblings that overlap the native child properly
152 * draws over the native child window.
154 * In order to minimize flicker and for performance we use a couple of cacheing
155 * tricks. First of all, every time we do a window to window copy area, for instance
156 * when moving a client side window or when scrolling/moving a region in a window
157 * we store this in outstanding_moves instead of applying immediately. We then
158 * delay this move until we really need it (because something depends on being
159 * able to read it), or until we're handing a redraw from an expose/invalidation
160 * (actually we delay it past redraw, but before blitting the double buffer
161 * to the window). This gives us two advantages. First of all it minimizes the time
162 * from the window is moved to the exposes related to that move, secondly it allows
163 * us to be smart about how to do the copy. We combine multiple moves into one (when
164 * possible) and we don't actually do copies to anything that is or will be
165 * invalidated and exposed anyway.
167 * Secondly, we use something called a "implicit paint" during repaint handling.
168 * An implicit paint is similar to a regular paint for the paint stack, but it is
169 * not put on the stack. Instead, it is set on the impl window, and later when
170 * regular gdk_window_begin_paint_region() happen on a window of this impl window
171 * we reuse the surface from the implicit paint. During repaint we create and at the
172 * end flush an implicit paint, which means we can collect all the paints on
173 * multiple client side windows in the same backing store.
176 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
178 /* This adds a local value to the GdkVisibilityState enum */
179 #define GDK_VISIBILITY_NOT_VIEWABLE 3
182 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
196 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
200 struct _GdkWindowPaint
202 cairo_region_t *region;
203 cairo_surface_t *surface;
204 cairo_region_t *flushed;
205 guint uses_implicit : 1;
209 cairo_region_t *dest_region; /* The destination region */
210 int dx, dy; /* The amount that the source was moved to reach dest_region */
211 } GdkWindowRegionMove;
215 static void gdk_window_drop_cairo_surface (GdkWindow *private);
217 static void gdk_window_free_paint_stack (GdkWindow *window);
219 static void gdk_window_finalize (GObject *object);
221 static void gdk_window_set_property (GObject *object,
225 static void gdk_window_get_property (GObject *object,
230 static void gdk_window_clear_backing_region (GdkWindow *window,
231 cairo_region_t *region);
233 static void recompute_visible_regions (GdkWindow *private,
234 gboolean recalculate_siblings,
235 gboolean recalculate_children);
236 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
237 static void gdk_window_flush_recursive (GdkWindow *window);
238 static void do_move_region_bits_on_impl (GdkWindow *window,
239 cairo_region_t *region, /* In impl window coords */
241 static void gdk_window_invalidate_in_parent (GdkWindow *private);
242 static void move_native_children (GdkWindow *private);
243 static void update_cursor (GdkDisplay *display,
245 static void impl_window_add_update_area (GdkWindow *impl_window,
246 cairo_region_t *region);
247 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
248 static void gdk_window_invalidate_region_full (GdkWindow *window,
249 const cairo_region_t *region,
250 gboolean invalidate_children,
252 static void gdk_window_invalidate_rect_full (GdkWindow *window,
253 const GdkRectangle *rect,
254 gboolean invalidate_children,
256 static void _gdk_window_propagate_has_alpha_background (GdkWindow *window);
258 static guint signals[LAST_SIGNAL] = { 0 };
260 static gpointer parent_class = NULL;
262 static const cairo_user_data_key_t gdk_window_cairo_key;
264 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
267 _gdk_paintable_get_type (void)
269 static GType paintable_type = 0;
273 const GTypeInfo paintable_info =
275 sizeof (GdkPaintableIface), /* class_size */
276 NULL, /* base_init */
277 NULL, /* base_finalize */
280 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
281 g_intern_static_string ("GdkPaintable"),
284 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
287 return paintable_type;
291 gdk_window_init (GdkWindow *window)
293 /* 0-initialization is good for all other fields. */
295 window->window_type = GDK_WINDOW_CHILD;
297 window->state = GDK_WINDOW_STATE_WITHDRAWN;
300 window->toplevel_window_type = -1;
302 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
303 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
304 /* Default to unobscured since some backends don't send visibility events */
305 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
307 window->device_cursor = g_hash_table_new_full (NULL, NULL,
308 NULL, g_object_unref);
311 /* Stop and return on the first non-NULL parent */
313 accumulate_get_window (GSignalInvocationHint *ihint,
315 const GValue *handler_return,
318 g_value_copy (handler_return, return_accu);
319 /* Continue while returning NULL */
320 return g_value_get_object (handler_return) == NULL;
324 create_surface_accumulator (GSignalInvocationHint *ihint,
326 const GValue *handler_return,
329 g_value_copy (handler_return, return_accu);
331 /* Stop on the first non-NULL return value */
332 return g_value_get_boxed (handler_return) == NULL;
335 static GQuark quark_pointer_window = 0;
338 gdk_window_class_init (GdkWindowClass *klass)
340 GObjectClass *object_class = G_OBJECT_CLASS (klass);
342 parent_class = g_type_class_peek_parent (klass);
344 object_class->finalize = gdk_window_finalize;
345 object_class->set_property = gdk_window_set_property;
346 object_class->get_property = gdk_window_get_property;
348 klass->create_surface = _gdk_offscreen_window_create_surface;
350 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
358 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
359 * gdk_window_get_cursor() for details.
363 g_object_class_install_property (object_class,
365 g_param_spec_object ("cursor",
372 * GdkWindow::pick-embedded-child:
373 * @window: the window on which the signal is emitted
374 * @x: x coordinate in the window
375 * @y: y coordinate in the window
377 * The ::pick-embedded-child signal is emitted to find an embedded
378 * child at the given position.
380 * Returns: (transfer none): the #GdkWindow of the embedded child at
385 signals[PICK_EMBEDDED_CHILD] =
386 g_signal_new (g_intern_static_string ("pick-embedded-child"),
387 G_OBJECT_CLASS_TYPE (object_class),
389 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
390 accumulate_get_window, NULL,
391 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
398 * GdkWindow::to-embedder:
399 * @window: the offscreen window on which the signal is emitted
400 * @offscreen-x: x coordinate in the offscreen window
401 * @offscreen-y: y coordinate in the offscreen window
402 * @embedder-x: (out) (type double): return location for the x
403 * coordinate in the embedder window
404 * @embedder-y: (out) (type double): return location for the y
405 * coordinate in the embedder window
407 * The ::to-embedder signal is emitted to translate coordinates
408 * in an offscreen window to its embedder.
410 * See also #GtkWindow::from-embedder.
414 signals[TO_EMBEDDER] =
415 g_signal_new (g_intern_static_string ("to-embedder"),
416 G_OBJECT_CLASS_TYPE (object_class),
418 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
420 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
429 * GdkWindow::from-embedder:
430 * @window: the offscreen window on which the signal is emitted
431 * @embedder-x: x coordinate in the embedder window
432 * @embedder-y: y coordinate in the embedder window
433 * @offscreen-x: (out) (type double): return location for the x
434 * coordinate in the offscreen window
435 * @offscreen-y: (out) (type double): return location for the y
436 * coordinate in the offscreen window
438 * The ::from-embedder signal is emitted to translate coordinates
439 * in the embedder of an offscreen window to the offscreen window.
441 * See also #GtkWindow::to-embedder.
445 signals[FROM_EMBEDDER] =
446 g_signal_new (g_intern_static_string ("from-embedder"),
447 G_OBJECT_CLASS_TYPE (object_class),
449 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
451 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
460 * GdkWindow::create-surface:
461 * @window: the offscreen window on which the signal is emitted
462 * @width: the width of the offscreen surface to create
463 * @height: the height of the offscreen surface to create
465 * The ::create-surface signal is emitted when an offscreen window
466 * needs its surface (re)created, which happens either when the the
467 * window is first drawn to, or when the window is being
468 * resized. The first signal handler that returns a non-%NULL
469 * surface will stop any further signal emission, and its surface
472 * Note that it is not possible to access the window's previous
473 * surface from within any callback of this signal. Calling
474 * gdk_offscreen_window_get_surface() will lead to a crash.
476 * Returns: the newly created #cairo_surface_t for the offscreen window
480 signals[CREATE_SURFACE] =
481 g_signal_new (g_intern_static_string ("create-surface"),
482 G_OBJECT_CLASS_TYPE (object_class),
484 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
485 create_surface_accumulator, NULL,
486 _gdk_marshal_BOXED__INT_INT,
487 CAIRO_GOBJECT_TYPE_SURFACE,
494 device_removed_cb (GdkDeviceManager *device_manager,
498 window->devices_inside = g_list_remove (window->devices_inside, device);
499 g_hash_table_remove (window->device_cursor, device);
501 if (window->device_events)
502 g_hash_table_remove (window->device_events, device);
506 gdk_window_finalize (GObject *object)
508 GdkWindow *window = GDK_WINDOW (object);
509 GdkDeviceManager *device_manager;
511 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
512 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
514 if (!GDK_WINDOW_DESTROYED (window))
516 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
518 g_warning ("losing last reference to undestroyed window\n");
519 _gdk_window_destroy (window, FALSE);
522 /* We use TRUE here, to keep us from actually calling
523 * XDestroyWindow() on the window
525 _gdk_window_destroy (window, TRUE);
528 gdk_window_drop_cairo_surface (window);
532 g_object_unref (window->impl);
536 if (window->impl_window != window)
538 g_object_unref (window->impl_window);
539 window->impl_window = NULL;
543 cairo_region_destroy (window->shape);
545 if (window->input_shape)
546 cairo_region_destroy (window->input_shape);
549 g_object_unref (window->cursor);
551 if (window->device_cursor)
552 g_hash_table_destroy (window->device_cursor);
554 if (window->device_events)
555 g_hash_table_destroy (window->device_events);
557 if (window->source_event_masks)
558 g_hash_table_destroy (window->source_event_masks);
560 if (window->devices_inside)
561 g_list_free (window->devices_inside);
563 if (window->layered_region)
564 cairo_region_destroy (window->layered_region);
566 G_OBJECT_CLASS (parent_class)->finalize (object);
570 gdk_window_set_property (GObject *object,
575 GdkWindow *window = (GdkWindow *)object;
580 gdk_window_set_cursor (window, g_value_get_object (value));
584 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
590 gdk_window_get_property (GObject *object,
595 GdkWindow *window = (GdkWindow *) object;
600 g_value_set_object (value, gdk_window_get_cursor (window));
604 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
610 gdk_window_is_offscreen (GdkWindow *window)
612 return window->window_type == GDK_WINDOW_OFFSCREEN;
616 gdk_window_get_impl_window (GdkWindow *window)
618 return window->impl_window;
622 _gdk_window_get_impl_window (GdkWindow *window)
624 return gdk_window_get_impl_window (window);
628 gdk_window_has_impl (GdkWindow *window)
630 return window->impl_window == window;
634 gdk_window_is_toplevel (GdkWindow *window)
637 window->parent == NULL ||
638 window->parent->window_type == GDK_WINDOW_ROOT;
642 _gdk_window_has_impl (GdkWindow *window)
644 return gdk_window_has_impl (window);
648 gdk_window_has_no_impl (GdkWindow *window)
650 return window->impl_window != window;
654 remove_layered_child_area (GdkWindow *window,
655 cairo_region_t *region)
658 cairo_region_t *child_region;
662 for (l = window->children; l; l = l->next)
666 /* If region is empty already, no need to do
667 anything potentially costly */
668 if (cairo_region_is_empty (region))
671 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
674 /* Ignore offscreen children, as they don't draw in their parent and
675 * don't take part in the clipping */
676 if (gdk_window_is_offscreen (child))
679 /* Only non-impl children with alpha add to the layered region */
680 if (!child->has_alpha_background && gdk_window_has_impl (child))
685 r.width = child->width;
686 r.height = child->height;
688 /* Bail early if child totally outside region */
689 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
692 child_region = cairo_region_create_rectangle (&r);
695 /* Adjust shape region to parent window coords */
696 cairo_region_translate (child->shape, child->x, child->y);
697 cairo_region_intersect (child_region, child->shape);
698 cairo_region_translate (child->shape, -child->x, -child->y);
701 cairo_region_subtract (region, child_region);
702 cairo_region_destroy (child_region);
707 remove_child_area (GdkWindow *window,
710 cairo_region_t *region,
711 cairo_region_t *layered_region)
714 cairo_region_t *child_region;
717 cairo_region_t *shape;
719 for (l = window->children; l; l = l->next)
726 /* If region is empty already, no need to do
727 anything potentially costly */
728 if (cairo_region_is_empty (region))
731 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
734 /* Ignore offscreen children, as they don't draw in their parent and
735 * don't take part in the clipping */
736 if (gdk_window_is_offscreen (child))
741 r.width = child->width;
742 r.height = child->height;
744 /* Bail early if child totally outside region */
745 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
748 child_region = cairo_region_create_rectangle (&r);
752 /* Adjust shape region to parent window coords */
753 cairo_region_translate (child->shape, child->x, child->y);
754 cairo_region_intersect (child_region, child->shape);
755 cairo_region_translate (child->shape, -child->x, -child->y);
757 else if (window->window_type == GDK_WINDOW_FOREIGN)
759 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
762 cairo_region_intersect (child_region, shape);
763 cairo_region_destroy (shape);
769 if (child->input_shape)
770 cairo_region_intersect (child_region, child->input_shape);
771 else if (window->window_type == GDK_WINDOW_FOREIGN)
773 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
776 cairo_region_intersect (child_region, shape);
777 cairo_region_destroy (shape);
782 if (child->has_alpha_background)
784 if (layered_region != NULL)
785 cairo_region_union (layered_region, child_region);
788 cairo_region_subtract (region, child_region);
789 cairo_region_destroy (child_region);
793 static GdkVisibilityState
794 effective_visibility (GdkWindow *window)
796 GdkVisibilityState native;
798 if (!gdk_window_is_viewable (window))
799 return GDK_VISIBILITY_NOT_VIEWABLE;
801 native = window->impl_window->native_visibility;
803 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
804 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
805 return GDK_VISIBILITY_FULLY_OBSCURED;
806 else if (native == GDK_VISIBILITY_UNOBSCURED)
807 return window->visibility;
808 else /* native PARTIAL, private partial or unobscured */
809 return GDK_VISIBILITY_PARTIAL;
813 gdk_window_update_visibility (GdkWindow *window)
815 GdkVisibilityState new_visibility;
818 new_visibility = effective_visibility (window);
820 if (new_visibility != window->effective_visibility)
822 window->effective_visibility = new_visibility;
824 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
825 window->event_mask & GDK_VISIBILITY_NOTIFY_MASK)
827 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
829 event->visibility.state = new_visibility;
835 gdk_window_update_visibility_recursively (GdkWindow *window,
836 GdkWindow *only_for_impl)
841 gdk_window_update_visibility (window);
842 for (l = window->children; l != NULL; l = l->next)
845 if ((only_for_impl == NULL) ||
846 (only_for_impl == child->impl_window))
847 gdk_window_update_visibility_recursively (child, only_for_impl);
852 should_apply_clip_as_shape (GdkWindow *window)
855 gdk_window_has_impl (window) &&
856 /* Not for offscreens */
857 !gdk_window_is_offscreen (window) &&
858 /* or for toplevels */
859 !gdk_window_is_toplevel (window) &&
860 /* or for foreign windows */
861 window->window_type != GDK_WINDOW_FOREIGN &&
862 /* or for the root window */
863 window->window_type != GDK_WINDOW_ROOT;
867 apply_shape (GdkWindow *window,
868 cairo_region_t *region)
870 GdkWindowImplClass *impl_class;
872 /* We trash whether we applied a shape so that
873 we can avoid unsetting it many times, which
874 could happen in e.g. apply_clip_as_shape as
875 windows get resized */
876 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
878 impl_class->shape_combine_region (window,
880 else if (window->applied_shape)
881 impl_class->shape_combine_region (window,
884 window->applied_shape = region != NULL;
888 region_rect_equal (const cairo_region_t *region,
889 const GdkRectangle *rect)
891 GdkRectangle extents;
893 if (cairo_region_num_rectangles (region) != 1)
896 cairo_region_get_extents (region, &extents);
898 return extents.x == rect->x &&
899 extents.y == rect->y &&
900 extents.width == rect->width &&
901 extents.height == rect->height;
905 apply_clip_as_shape (GdkWindow *window)
910 r.width = window->width;
911 r.height = window->height;
913 /* We only apply the clip region if would differ
914 from the actual clip region implied by the size
915 of the window. This is to avoid unneccessarily
916 adding meaningless shapes to all native subwindows */
917 if (!region_rect_equal (window->clip_region, &r))
918 apply_shape (window, window->clip_region);
920 apply_shape (window, NULL);
924 recompute_visible_regions_internal (GdkWindow *private,
925 gboolean recalculate_clip,
926 gboolean recalculate_siblings,
927 gboolean recalculate_children)
932 cairo_region_t *new_clip, *new_layered;
933 gboolean clip_region_changed;
934 gboolean abs_pos_changed;
935 int old_abs_x, old_abs_y;
937 old_abs_x = private->abs_x;
938 old_abs_y = private->abs_y;
940 /* Update absolute position */
941 if (gdk_window_has_impl (private))
943 /* Native window starts here */
949 private->abs_x = private->parent->abs_x + private->x;
950 private->abs_y = private->parent->abs_y + private->y;
954 private->abs_x != old_abs_x ||
955 private->abs_y != old_abs_y;
957 /* Update clip region based on:
960 * siblings in parents above window
962 clip_region_changed = FALSE;
963 if (recalculate_clip)
965 new_layered = cairo_region_create ();
966 if (private->viewable)
968 /* Calculate visible region (sans children) in parent window coords */
971 r.width = private->width;
972 r.height = private->height;
973 new_clip = cairo_region_create_rectangle (&r);
975 if (!gdk_window_is_toplevel (private))
977 cairo_region_intersect (new_clip, private->parent->clip_region);
978 cairo_region_union (new_layered, private->parent->layered_region);
980 /* Remove all overlapping children from parent. */
981 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
984 /* Convert from parent coords to window coords */
985 cairo_region_translate (new_clip, -private->x, -private->y);
986 cairo_region_translate (new_layered, -private->x, -private->y);
989 cairo_region_intersect (new_clip, private->shape);
992 new_clip = cairo_region_create ();
994 cairo_region_intersect (new_layered, new_clip);
996 if (private->clip_region == NULL ||
997 !cairo_region_equal (private->clip_region, new_clip))
998 clip_region_changed = TRUE;
1000 if (private->layered_region == NULL ||
1001 !cairo_region_equal (private->layered_region, new_layered))
1002 clip_region_changed = TRUE;
1004 if (private->clip_region)
1005 cairo_region_destroy (private->clip_region);
1006 private->clip_region = new_clip;
1008 if (private->layered_region != NULL)
1009 cairo_region_destroy (private->layered_region);
1010 private->layered_region = new_layered;
1012 if (private->clip_region_with_children)
1013 cairo_region_destroy (private->clip_region_with_children);
1014 private->clip_region_with_children = cairo_region_copy (private->clip_region);
1015 if (private->window_type != GDK_WINDOW_ROOT)
1016 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
1019 if (clip_region_changed)
1021 GdkVisibilityState visibility;
1022 gboolean fully_visible;
1024 if (cairo_region_is_empty (private->clip_region))
1025 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1030 fully_visible = cairo_region_equal (private->clip_region,
1037 r.width = private->width;
1038 r.height = private->height;
1039 fully_visible = region_rect_equal (private->clip_region, &r);
1043 visibility = GDK_VISIBILITY_UNOBSCURED;
1045 visibility = GDK_VISIBILITY_PARTIAL;
1048 if (private->visibility != visibility)
1050 private->visibility = visibility;
1051 gdk_window_update_visibility (private);
1055 /* Update all children, recursively (except for root, where children are not exact). */
1056 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1057 private->window_type != GDK_WINDOW_ROOT)
1059 for (l = private->children; l; l = l->next)
1062 /* Only recalculate clip if the the clip region changed, otherwise
1063 * there is no way the child clip region could change (its has not e.g. moved)
1064 * Except if recalculate_children is set to force child updates
1066 recompute_visible_regions_internal (child,
1067 recalculate_clip && (clip_region_changed || recalculate_children),
1072 if (clip_region_changed &&
1073 should_apply_clip_as_shape (private))
1074 apply_clip_as_shape (private);
1076 if (recalculate_siblings &&
1077 !gdk_window_is_toplevel (private))
1079 /* If we moved a child window in parent or changed the stacking order, then we
1080 * need to recompute the visible area of all the other children in the parent
1082 for (l = private->parent->children; l; l = l->next)
1086 if (child != private)
1087 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1090 /* We also need to recompute the _with_children clip for the parent */
1091 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1094 if (private->cairo_surface && gdk_window_has_impl (private))
1096 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1098 private->cairo_surface = iface->resize_cairo_surface (private,
1099 private->cairo_surface,
1103 else if (private->cairo_surface)
1104 gdk_window_drop_cairo_surface (private);
1107 /* Call this when private has changed in one or more of these ways:
1111 * stacking order of window changed
1114 * It will recalculate abs_x/y and the clip regions
1116 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1117 * for recalculate_siblings. (Mostly used internally for the recursion)
1119 * If a child window was removed (and you can't use that child for
1120 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1123 recompute_visible_regions (GdkWindow *private,
1124 gboolean recalculate_siblings,
1125 gboolean recalculate_children)
1127 recompute_visible_regions_internal (private,
1129 recalculate_siblings,
1130 recalculate_children);
1134 _gdk_window_update_size (GdkWindow *window)
1136 recompute_visible_regions (window, TRUE, FALSE);
1139 /* Find the native window that would be just above "child"
1140 * in the native stacking order if "child" was a native window
1141 * (it doesn't have to be native). If there is no such native
1142 * window inside this native parent then NULL is returned.
1143 * If child is NULL, find lowest native window in parent.
1146 find_native_sibling_above_helper (GdkWindow *parent,
1154 l = g_list_find (parent->children, child);
1155 g_assert (l != NULL); /* Better be a child of its parent... */
1156 l = l->prev; /* Start looking at the one above the child */
1159 l = g_list_last (parent->children);
1161 for (; l != NULL; l = l->prev)
1165 if (gdk_window_has_impl (w))
1168 g_assert (parent != w);
1169 w = find_native_sibling_above_helper (w, NULL);
1179 find_native_sibling_above (GdkWindow *parent,
1184 w = find_native_sibling_above_helper (parent, child);
1188 if (gdk_window_has_impl (parent))
1191 return find_native_sibling_above (parent->parent, parent);
1195 get_native_device_event_mask (GdkWindow *private,
1198 GdkEventMask event_mask;
1201 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1203 event_mask = private->event_mask;
1205 if (private->window_type == GDK_WINDOW_ROOT ||
1206 private->window_type == GDK_WINDOW_FOREIGN)
1212 /* Do whatever the app asks to, since the app
1213 * may be asking for weird things for native windows,
1214 * but don't use motion hints as that may affect non-native
1215 * child windows that don't want it. Also, we need to
1216 * set all the app-specified masks since they will be picked
1217 * up by any implicit grabs (i.e. if they were not set as
1218 * native we would not get the events we need). */
1219 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1221 /* We need thse for all native windows so we can
1222 emulate events on children: */
1225 GDK_VISIBILITY_NOTIFY_MASK |
1226 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1228 /* Additionally we select for pointer and button events
1229 * for toplevels as we need to get these to emulate
1230 * them for non-native subwindows. Even though we don't
1231 * select on them for all native windows we will get them
1232 * as the events are propagated out to the first window
1233 * that select for them.
1234 * Not selecting for button press on all windows is an
1235 * important thing, because in X only one client can do
1236 * so, and we don't want to unexpectedly prevent another
1237 * client from doing it.
1239 * We also need to do the same if the app selects for button presses
1240 * because then we will get implicit grabs for this window, and the
1241 * event mask used for that grab is based on the rest of the mask
1242 * for the window, but we might need more events than this window
1243 * lists due to some non-native child window.
1245 if (gdk_window_is_toplevel (private) ||
1246 mask & GDK_BUTTON_PRESS_MASK)
1249 GDK_POINTER_MOTION_MASK |
1250 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1258 get_native_grab_event_mask (GdkEventMask grab_mask)
1260 /* Similar to the above but for pointer events only */
1262 GDK_POINTER_MOTION_MASK |
1263 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1264 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1267 ~GDK_POINTER_MOTION_HINT_MASK);
1271 get_native_event_mask (GdkWindow *private)
1273 return get_native_device_event_mask (private, NULL);
1276 /* Puts the native window in the right order wrt the other native windows
1277 * in the hierarchy, given the position it has in the client side data.
1278 * This is useful if some operation changed the stacking order.
1279 * This calls assumes the native window is now topmost in its native parent.
1282 sync_native_window_stack_position (GdkWindow *window)
1285 GdkWindowImplClass *impl_class;
1286 GList listhead = {0};
1288 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1290 above = find_native_sibling_above (window->parent, window);
1293 listhead.data = window;
1294 impl_class->restack_under (above, &listhead);
1299 * gdk_window_new: (constructor)
1300 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1301 * the default root window for the default display.
1302 * @attributes: attributes of the new window
1303 * @attributes_mask: mask indicating which fields in @attributes are valid
1305 * Creates a new #GdkWindow using the attributes from
1306 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1307 * more details. Note: to use this on displays other than the default
1308 * display, @parent must be specified.
1310 * Return value: (transfer full): the new #GdkWindow
1313 gdk_window_new (GdkWindow *parent,
1314 GdkWindowAttr *attributes,
1315 gint attributes_mask)
1319 GdkDisplay *display;
1322 GdkEventMask event_mask;
1323 GdkWindow *real_parent;
1324 GdkDeviceManager *device_manager;
1326 g_return_val_if_fail (attributes != NULL, NULL);
1330 GDK_NOTE (MULTIHEAD,
1331 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1333 screen = gdk_screen_get_default ();
1334 parent = gdk_screen_get_root_window (screen);
1337 screen = gdk_window_get_screen (parent);
1339 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1341 if (GDK_WINDOW_DESTROYED (parent))
1343 g_warning ("gdk_window_new(): parent is destroyed\n");
1347 display = gdk_screen_get_display (screen);
1349 window = _gdk_display_create_window (display);
1351 /* Windows with a foreign parent are treated as if they are children
1352 * of the root window, except for actual creation.
1354 real_parent = parent;
1355 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1356 parent = gdk_screen_get_root_window (screen);
1358 window->parent = parent;
1360 window->accept_focus = TRUE;
1361 window->focus_on_map = TRUE;
1363 if (attributes_mask & GDK_WA_X)
1368 if (attributes_mask & GDK_WA_Y)
1375 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1376 window->height = (attributes->height > 1) ? (attributes->height) : (1);
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 window->window_type = GDK_WINDOW_TEMP;
1387 window->window_type = GDK_WINDOW_CHILD;
1390 window->window_type = attributes->window_type;
1393 switch (window->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", window->window_type);
1409 if (attributes_mask & GDK_WA_VISUAL)
1410 window->visual = attributes->visual;
1412 window->visual = gdk_screen_get_system_visual (screen);
1414 window->event_mask = attributes->event_mask;
1416 if (attributes->wclass == GDK_INPUT_OUTPUT)
1418 window->input_only = FALSE;
1419 window->depth = window->visual->depth;
1421 /* XXX: Cache this somehow? */
1422 window->background = cairo_pattern_create_rgba (0, 0, 0, 0);
1423 window->has_alpha_background = TRUE;
1428 window->input_only = TRUE;
1432 window->parent->children = g_list_prepend (window->parent->children, window);
1435 if (window->parent->window_type == GDK_WINDOW_ROOT)
1436 native = TRUE; /* Always use native windows for toplevels */
1437 else if (!window->input_only &&
1438 (attributes_mask & GDK_WA_VISUAL &&
1439 attributes->visual != gdk_window_get_visual (window->parent)))
1440 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1442 if (gdk_window_is_offscreen (window))
1444 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1445 window->impl_window = window;
1449 event_mask = get_native_event_mask (window);
1451 /* Create the impl */
1452 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1453 window->impl_window = window;
1455 /* This will put the native window topmost in the native parent, which may
1456 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1457 if (!_gdk_window_has_impl (real_parent))
1458 sync_native_window_stack_position (window);
1462 window->impl_window = g_object_ref (window->parent->impl_window);
1463 window->impl = g_object_ref (window->impl_window->impl);
1466 recompute_visible_regions (window, TRUE, FALSE);
1468 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1469 (attributes->cursor) :
1472 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1473 g_signal_connect (device_manager, "device-removed",
1474 G_CALLBACK (device_removed_cb), window);
1480 is_parent_of (GdkWindow *parent,
1491 w = gdk_window_get_parent (w);
1498 change_impl (GdkWindow *private,
1499 GdkWindow *impl_window,
1504 GdkWindowImpl *old_impl;
1505 GdkWindow *old_impl_window;
1507 old_impl = private->impl;
1508 old_impl_window = private->impl_window;
1509 if (private != impl_window)
1510 private->impl_window = g_object_ref (impl_window);
1512 private->impl_window = private;
1513 private->impl = g_object_ref (new);
1514 if (old_impl_window != private)
1515 g_object_unref (old_impl_window);
1516 g_object_unref (old_impl);
1518 for (l = private->children; l != NULL; l = l->next)
1522 if (child->impl == old_impl)
1523 change_impl (child, impl_window, new);
1528 reparent_to_impl (GdkWindow *private)
1533 GdkWindowImplClass *impl_class;
1535 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1537 /* Enumerate in reverse order so we get the right order for the native
1538 windows (first in childrens list is topmost, and reparent places on top) */
1539 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1543 if (child->impl == private->impl)
1544 reparent_to_impl (child);
1547 show = impl_class->reparent ((GdkWindow *)child,
1548 (GdkWindow *)private,
1549 child->x, child->y);
1551 gdk_window_show_unraised ((GdkWindow *)child);
1558 * gdk_window_reparent:
1559 * @window: a #GdkWindow
1560 * @new_parent: new parent to move @window into
1561 * @x: X location inside the new parent
1562 * @y: Y location inside the new parent
1564 * Reparents @window into the given @new_parent. The window being
1565 * reparented will be unmapped as a side effect.
1569 gdk_window_reparent (GdkWindow *window,
1570 GdkWindow *new_parent,
1574 GdkWindow *old_parent;
1576 gboolean show, was_mapped, applied_clip_as_shape;
1577 gboolean do_reparent_to_impl;
1578 GdkEventMask old_native_event_mask;
1579 GdkWindowImplClass *impl_class;
1581 g_return_if_fail (GDK_IS_WINDOW (window));
1582 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1583 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1585 if (GDK_WINDOW_DESTROYED (window) ||
1586 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1589 screen = gdk_window_get_screen (window);
1591 new_parent = gdk_screen_get_root_window (screen);
1593 /* No input-output children of input-only windows */
1594 if (new_parent->input_only && !window->input_only)
1597 /* Don't create loops in hierarchy */
1598 if (is_parent_of (window, new_parent))
1601 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1602 To make sure we're ok, just wipe it. */
1603 gdk_window_drop_cairo_surface (window);
1605 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1606 old_parent = window->parent;
1608 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1611 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1612 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1613 new_parent->window_type == GDK_WINDOW_FOREIGN)
1614 gdk_window_ensure_native (window);
1616 applied_clip_as_shape = should_apply_clip_as_shape (window);
1618 old_native_event_mask = 0;
1619 do_reparent_to_impl = FALSE;
1620 if (gdk_window_has_impl (window))
1622 old_native_event_mask = get_native_event_mask (window);
1624 show = impl_class->reparent (window, new_parent, x, y);
1628 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1629 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1630 new_parent->window_type != GDK_WINDOW_FOREIGN);
1633 gdk_window_hide (window);
1635 do_reparent_to_impl = TRUE;
1636 change_impl (window,
1637 new_parent->impl_window,
1641 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1644 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1646 new_parent = gdk_screen_get_root_window (screen);
1650 old_parent->children = g_list_remove (old_parent->children, window);
1652 window->parent = new_parent;
1656 new_parent->children = g_list_prepend (new_parent->children, window);
1658 /* Switch the window type as appropriate */
1660 switch (GDK_WINDOW_TYPE (new_parent))
1662 case GDK_WINDOW_ROOT:
1663 case GDK_WINDOW_FOREIGN:
1664 if (window->toplevel_window_type != -1)
1665 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1666 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1667 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1669 case GDK_WINDOW_OFFSCREEN:
1670 case GDK_WINDOW_TOPLEVEL:
1671 case GDK_WINDOW_CHILD:
1672 case GDK_WINDOW_TEMP:
1673 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1674 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1676 /* Save the original window type so we can restore it if the
1677 * window is reparented back to be a toplevel
1679 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1680 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1684 /* We might have changed window type for a native windows, so we
1685 need to change the event mask too. */
1686 if (gdk_window_has_impl (window))
1688 GdkEventMask native_event_mask = get_native_event_mask (window);
1690 if (native_event_mask != old_native_event_mask)
1691 impl_class->set_events (window, native_event_mask);
1694 _gdk_window_update_viewable (window);
1696 if (window->background == NULL)
1698 /* parent relative background, update has_alpha_background */
1699 if (window->parent == NULL ||
1700 window->parent->window_type == GDK_WINDOW_ROOT)
1701 window->has_alpha_background = FALSE;
1703 window->has_alpha_background = window->parent->has_alpha_background;
1706 recompute_visible_regions (window, TRUE, FALSE);
1707 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1708 recompute_visible_regions (old_parent, FALSE, TRUE);
1710 _gdk_window_propagate_has_alpha_background (window);
1712 /* We used to apply the clip as the shape, but no more.
1713 Reset this to the real shape */
1714 if (gdk_window_has_impl (window) &&
1715 applied_clip_as_shape &&
1716 !should_apply_clip_as_shape (window))
1717 apply_shape (window, window->shape);
1719 if (do_reparent_to_impl)
1720 reparent_to_impl (window);
1723 /* The reparent will have put the native window topmost in the native parent,
1724 * which may be wrong wrt other native windows in the non-native hierarchy,
1726 if (!gdk_window_has_impl (new_parent))
1727 sync_native_window_stack_position (window);
1731 gdk_window_show_unraised (window);
1733 _gdk_synthesize_crossing_events_for_geometry_change (window);
1737 * gdk_window_ensure_native:
1738 * @window: a #GdkWindow
1740 * Tries to ensure that there is a window-system native window for this
1741 * GdkWindow. This may fail in some situations, returning %FALSE.
1743 * Offscreen window and children of them can never have native windows.
1745 * Some backends may not support native child windows.
1747 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1752 gdk_window_ensure_native (GdkWindow *window)
1754 GdkWindow *impl_window;
1755 GdkWindowImpl *new_impl, *old_impl;
1756 GdkDisplay *display;
1760 GdkWindowImplClass *impl_class;
1762 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1764 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1765 GDK_WINDOW_DESTROYED (window))
1768 impl_window = gdk_window_get_impl_window (window);
1770 if (gdk_window_is_offscreen (impl_window))
1771 return FALSE; /* native in offscreens not supported */
1773 if (impl_window == window)
1774 /* Already has an impl, and its not offscreen . */
1777 /* Need to create a native window */
1779 gdk_window_drop_cairo_surface (window);
1781 screen = gdk_window_get_screen (window);
1782 display = gdk_screen_get_display (screen);
1784 old_impl = window->impl;
1785 _gdk_display_create_window_impl (display,
1786 window, window->parent,
1788 get_native_event_mask (window),
1790 new_impl = window->impl;
1792 window->impl = old_impl;
1793 change_impl (window, window, new_impl);
1795 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1797 /* Native window creation will put the native window topmost in the
1798 * native parent, which may be wrong wrt the position of the previous
1799 * non-native window wrt to the other non-native children, so correct this.
1801 above = find_native_sibling_above (window->parent, window);
1804 listhead.data = window;
1805 listhead.prev = NULL;
1806 listhead.next = NULL;
1807 impl_class->restack_under ((GdkWindow *)above, &listhead);
1810 recompute_visible_regions (window, FALSE, FALSE);
1812 /* The shape may not have been set, as the clip region doesn't actually
1813 change, so do it here manually */
1814 if (should_apply_clip_as_shape (window))
1815 apply_clip_as_shape (window);
1817 reparent_to_impl (window);
1819 if (!window->input_only)
1820 impl_class->set_background (window, window->background);
1822 impl_class->input_shape_combine_region (window,
1823 window->input_shape,
1826 if (gdk_window_is_viewable (window))
1827 impl_class->show (window, FALSE);
1833 * _gdk_event_filter_unref:
1834 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1835 * @filter: A window filter
1837 * Release a reference to @filter. Note this function may
1838 * mutate the list storage, so you need to handle this
1839 * if iterating over a list of filters.
1842 _gdk_event_filter_unref (GdkWindow *window,
1843 GdkEventFilter *filter)
1849 filters = &_gdk_default_filters;
1851 filters = &window->filters;
1853 tmp_list = *filters;
1856 GdkEventFilter *iter_filter = tmp_list->data;
1860 tmp_list = tmp_list->next;
1862 if (iter_filter != filter)
1865 g_assert (iter_filter->ref_count > 0);
1867 filter->ref_count--;
1868 if (filter->ref_count != 0)
1871 *filters = g_list_remove_link (*filters, node);
1873 g_list_free_1 (node);
1878 window_remove_filters (GdkWindow *window)
1880 while (window->filters)
1881 _gdk_event_filter_unref (window, window->filters->data);
1885 update_pointer_info_foreach (GdkDisplay *display,
1887 GdkPointerWindowInfo *pointer_info,
1890 GdkWindow *window = user_data;
1892 if (pointer_info->toplevel_under_pointer == window)
1894 g_object_unref (pointer_info->toplevel_under_pointer);
1895 pointer_info->toplevel_under_pointer = NULL;
1900 window_remove_from_pointer_info (GdkWindow *window,
1901 GdkDisplay *display)
1903 _gdk_display_pointer_info_foreach (display,
1904 update_pointer_info_foreach,
1909 * _gdk_window_destroy_hierarchy:
1910 * @window: a #GdkWindow
1911 * @recursing: If TRUE, then this is being called because a parent
1913 * @recursing_native: If TRUE, then this is being called because a native parent
1914 * was destroyed. This generally means that the call to the
1915 * windowing system to destroy the window can be omitted, since
1916 * it will be destroyed as a result of the parent being destroyed.
1917 * Unless @foreign_destroy.
1918 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1919 * external agency. The window has already been destroyed and no
1920 * windowing system calls should be made. (This may never happen
1921 * for some windowing systems.)
1923 * Internal function to destroy a window. Like gdk_window_destroy(),
1924 * but does not drop the reference count created by gdk_window_new().
1927 _gdk_window_destroy_hierarchy (GdkWindow *window,
1929 gboolean recursing_native,
1930 gboolean foreign_destroy)
1932 GdkWindowImplClass *impl_class;
1933 GdkWindow *temp_window;
1935 GdkDisplay *display;
1939 g_return_if_fail (GDK_IS_WINDOW (window));
1941 if (GDK_WINDOW_DESTROYED (window))
1944 display = gdk_window_get_display (window);
1945 screen = gdk_window_get_screen (window);
1946 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1947 if (temp_window == window)
1948 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1951 switch (window->window_type)
1953 case GDK_WINDOW_ROOT:
1954 if (!screen->closed)
1956 g_error ("attempted to destroy root window");
1959 /* else fall thru */
1960 case GDK_WINDOW_TOPLEVEL:
1961 case GDK_WINDOW_CHILD:
1962 case GDK_WINDOW_TEMP:
1963 case GDK_WINDOW_FOREIGN:
1964 case GDK_WINDOW_OFFSCREEN:
1965 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1967 /* Logically, it probably makes more sense to send
1968 * a "destroy yourself" message to the foreign window
1969 * whether or not it's in our hierarchy; but for historical
1970 * reasons, we only send "destroy yourself" messages to
1971 * foreign windows in our hierarchy.
1975 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1977 if (gdk_window_has_impl (window))
1978 impl_class->destroy_foreign (window);
1981 /* Also for historical reasons, we remove any filters
1982 * on a foreign window when it or a parent is destroyed;
1983 * this likely causes problems if two separate portions
1984 * of code are maintaining filter lists on a foreign window.
1986 window_remove_filters (window);
1992 if (window->parent->children)
1993 window->parent->children = g_list_remove (window->parent->children, window);
1996 GDK_WINDOW_IS_MAPPED (window))
1998 recompute_visible_regions (window, TRUE, FALSE);
1999 gdk_window_invalidate_in_parent (window);
2003 gdk_window_free_paint_stack (window);
2005 if (window->background)
2007 cairo_pattern_destroy (window->background);
2008 window->background = NULL;
2011 if (window->window_type == GDK_WINDOW_FOREIGN)
2012 g_assert (window->children == NULL);
2015 children = tmp = window->children;
2016 window->children = NULL;
2020 temp_window = tmp->data;
2024 _gdk_window_destroy_hierarchy (temp_window,
2026 recursing_native || gdk_window_has_impl (window),
2030 g_list_free (children);
2033 _gdk_window_clear_update_area (window);
2035 gdk_window_drop_cairo_surface (window);
2037 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2039 if (gdk_window_has_impl (window))
2040 impl_class->destroy (window, recursing_native,
2044 /* hide to make sure we repaint and break grabs */
2045 gdk_window_hide (window);
2048 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2049 window->parent = NULL;
2050 window->destroyed = TRUE;
2052 window_remove_filters (window);
2054 window_remove_from_pointer_info (window, display);
2056 if (window->clip_region)
2058 cairo_region_destroy (window->clip_region);
2059 window->clip_region = NULL;
2062 if (window->clip_region_with_children)
2064 cairo_region_destroy (window->clip_region_with_children);
2065 window->clip_region_with_children = NULL;
2068 g_list_free_full (window->outstanding_moves, (GDestroyNotify) gdk_window_region_move_free);
2069 window->outstanding_moves = NULL;
2076 * _gdk_window_destroy:
2077 * @window: a #GdkWindow
2078 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2079 * external agency. The window has already been destroyed and no
2080 * windowing system calls should be made. (This may never happen
2081 * for some windowing systems.)
2083 * Internal function to destroy a window. Like gdk_window_destroy(),
2084 * but does not drop the reference count created by gdk_window_new().
2087 _gdk_window_destroy (GdkWindow *window,
2088 gboolean foreign_destroy)
2090 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2094 * gdk_window_destroy:
2095 * @window: a #GdkWindow
2097 * Destroys the window system resources associated with @window and decrements @window's
2098 * reference count. The window system resources for all children of @window are also
2099 * destroyed, but the children's reference counts are not decremented.
2101 * Note that a window will not be destroyed automatically when its reference count
2102 * reaches zero. You must call this function yourself before that happens.
2106 gdk_window_destroy (GdkWindow *window)
2108 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2109 g_object_unref (window);
2113 * gdk_window_set_user_data:
2114 * @window: a #GdkWindow
2115 * @user_data: (allow-none) (type GObject.Object): user data
2117 * For most purposes this function is deprecated in favor of
2118 * g_object_set_data(). However, for historical reasons GTK+ stores
2119 * the #GtkWidget that owns a #GdkWindow as user data on the
2120 * #GdkWindow. So, custom widget implementations should use
2121 * this function for that. If GTK+ receives an event for a #GdkWindow,
2122 * and the user data for the window is non-%NULL, GTK+ will assume the
2123 * user data is a #GtkWidget, and forward the event to that widget.
2127 gdk_window_set_user_data (GdkWindow *window,
2130 g_return_if_fail (GDK_IS_WINDOW (window));
2132 window->user_data = user_data;
2136 * gdk_window_get_user_data:
2137 * @window: a #GdkWindow
2138 * @data: (out): return location for user data
2140 * Retrieves the user data for @window, which is normally the widget
2141 * that @window belongs to. See gdk_window_set_user_data().
2145 gdk_window_get_user_data (GdkWindow *window,
2148 g_return_if_fail (GDK_IS_WINDOW (window));
2150 *data = window->user_data;
2154 * gdk_window_get_window_type:
2155 * @window: a #GdkWindow
2157 * Gets the type of the window. See #GdkWindowType.
2159 * Return value: type of window
2162 gdk_window_get_window_type (GdkWindow *window)
2164 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2166 return GDK_WINDOW_TYPE (window);
2170 * gdk_window_get_visual:
2171 * @window: a #GdkWindow
2173 * Gets the #GdkVisual describing the pixel format of @window.
2175 * Return value: (transfer none): a #GdkVisual
2180 gdk_window_get_visual (GdkWindow *window)
2182 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2184 return window->visual;
2188 * gdk_window_get_screen:
2189 * @window: a #GdkWindow
2191 * Gets the #GdkScreen associated with a #GdkWindow.
2193 * Return value: (transfer none): the #GdkScreen associated with @window
2198 gdk_window_get_screen (GdkWindow *window)
2200 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2202 return gdk_visual_get_screen (window->visual);
2206 * gdk_window_get_display:
2207 * @window: a #GdkWindow
2209 * Gets the #GdkDisplay associated with a #GdkWindow.
2211 * Return value: (transfer none): the #GdkDisplay associated with @window
2216 gdk_window_get_display (GdkWindow *window)
2218 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2220 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2223 * gdk_window_is_destroyed:
2224 * @window: a #GdkWindow
2226 * Check to see if a window is destroyed..
2228 * Return value: %TRUE if the window is destroyed
2233 gdk_window_is_destroyed (GdkWindow *window)
2235 return GDK_WINDOW_DESTROYED (window);
2239 to_embedder (GdkWindow *window,
2240 gdouble offscreen_x,
2241 gdouble offscreen_y,
2242 gdouble *embedder_x,
2243 gdouble *embedder_y)
2245 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2246 offscreen_x, offscreen_y,
2247 embedder_x, embedder_y);
2251 from_embedder (GdkWindow *window,
2254 gdouble *offscreen_x,
2255 gdouble *offscreen_y)
2257 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2258 embedder_x, embedder_y,
2259 offscreen_x, offscreen_y);
2263 * gdk_window_has_native:
2264 * @window: a #GdkWindow
2266 * Checks whether the window has a native window or not. Note that
2267 * you can use gdk_window_ensure_native() if a native window is needed.
2269 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2274 gdk_window_has_native (GdkWindow *window)
2276 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2278 return window->parent == NULL || window->parent->impl != window->impl;
2282 * gdk_window_get_position:
2283 * @window: a #GdkWindow
2284 * @x: (out) (allow-none): X coordinate of window
2285 * @y: (out) (allow-none): Y coordinate of window
2287 * Obtains the position of the window as reported in the
2288 * most-recently-processed #GdkEventConfigure. Contrast with
2289 * gdk_window_get_geometry() which queries the X server for the
2290 * current window position, regardless of which events have been
2291 * received or processed.
2293 * The position coordinates are relative to the window's parent window.
2297 gdk_window_get_position (GdkWindow *window,
2301 g_return_if_fail (GDK_IS_WINDOW (window));
2310 * gdk_window_get_parent:
2311 * @window: a #GdkWindow
2313 * Obtains the parent of @window, as known to GDK. Does not query the
2314 * X server; thus this returns the parent as passed to gdk_window_new(),
2315 * not the actual parent. This should never matter unless you're using
2316 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2317 * matter for toplevel windows, because the window manager may choose
2320 * Note that you should use gdk_window_get_effective_parent() when
2321 * writing generic code that walks up a window hierarchy, because
2322 * gdk_window_get_parent() will most likely not do what you expect if
2323 * there are offscreen windows in the hierarchy.
2325 * Return value: (transfer none): parent of @window
2328 gdk_window_get_parent (GdkWindow *window)
2330 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2332 return window->parent;
2336 * gdk_window_get_effective_parent:
2337 * @window: a #GdkWindow
2339 * Obtains the parent of @window, as known to GDK. Works like
2340 * gdk_window_get_parent() for normal windows, but returns the
2341 * window's embedder for offscreen windows.
2343 * See also: gdk_offscreen_window_get_embedder()
2345 * Return value: (transfer none): effective parent of @window
2350 gdk_window_get_effective_parent (GdkWindow *window)
2352 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2354 if (gdk_window_is_offscreen (window))
2355 return gdk_offscreen_window_get_embedder (window);
2357 return window->parent;
2361 * gdk_window_get_toplevel:
2362 * @window: a #GdkWindow
2364 * Gets the toplevel window that's an ancestor of @window.
2366 * Any window type but %GDK_WINDOW_CHILD is considered a
2367 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2368 * has a root window as parent.
2370 * Note that you should use gdk_window_get_effective_toplevel() when
2371 * you want to get to a window's toplevel as seen on screen, because
2372 * gdk_window_get_toplevel() will most likely not do what you expect
2373 * if there are offscreen windows in the hierarchy.
2375 * Return value: (transfer none): the toplevel window containing @window
2378 gdk_window_get_toplevel (GdkWindow *window)
2380 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2382 while (window->window_type == GDK_WINDOW_CHILD)
2384 if (gdk_window_is_toplevel (window))
2386 window = window->parent;
2393 * gdk_window_get_effective_toplevel:
2394 * @window: a #GdkWindow
2396 * Gets the toplevel window that's an ancestor of @window.
2398 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2399 * embedder as its parent, using gdk_window_get_effective_parent().
2401 * See also: gdk_offscreen_window_get_embedder()
2403 * Return value: (transfer none): the effective toplevel window containing @window
2408 gdk_window_get_effective_toplevel (GdkWindow *window)
2412 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2414 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2415 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2422 * gdk_window_get_children:
2423 * @window: a #GdkWindow
2425 * Gets the list of children of @window known to GDK.
2426 * This function only returns children created via GDK,
2427 * so for example it's useless when used with the root window;
2428 * it only returns windows an application created itself.
2430 * The returned list must be freed, but the elements in the
2433 * Return value: (transfer container) (element-type GdkWindow):
2434 * list of child windows inside @window
2437 gdk_window_get_children (GdkWindow *window)
2439 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2441 if (GDK_WINDOW_DESTROYED (window))
2444 return g_list_copy (window->children);
2448 * gdk_window_peek_children:
2449 * @window: a #GdkWindow
2451 * Like gdk_window_get_children(), but does not copy the list of
2452 * children, so the list does not need to be freed.
2454 * Return value: (transfer none) (element-type GdkWindow):
2455 * a reference to the list of child windows in @window
2458 gdk_window_peek_children (GdkWindow *window)
2460 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2462 if (GDK_WINDOW_DESTROYED (window))
2465 return window->children;
2469 * gdk_window_add_filter: (skip)
2470 * @window: (allow-none): a #GdkWindow
2471 * @function: filter callback
2472 * @data: data to pass to filter callback
2474 * Adds an event filter to @window, allowing you to intercept events
2475 * before they reach GDK. This is a low-level operation and makes it
2476 * easy to break GDK and/or GTK+, so you have to know what you're
2477 * doing. Pass %NULL for @window to get all events for all windows,
2478 * instead of events for a specific window.
2480 * If you are interested in X GenericEvents, bear in mind that
2481 * XGetEventData() has been already called on the event, and
2482 * XFreeEventData() must not be called within @function.
2485 gdk_window_add_filter (GdkWindow *window,
2486 GdkFilterFunc function,
2490 GdkEventFilter *filter;
2492 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2494 if (window && GDK_WINDOW_DESTROYED (window))
2497 /* Filters are for the native events on the native window, so
2498 ensure there is a native window. */
2500 gdk_window_ensure_native (window);
2503 tmp_list = window->filters;
2505 tmp_list = _gdk_default_filters;
2509 filter = (GdkEventFilter *)tmp_list->data;
2510 if ((filter->function == function) && (filter->data == data))
2512 filter->ref_count++;
2515 tmp_list = tmp_list->next;
2518 filter = g_new (GdkEventFilter, 1);
2519 filter->function = function;
2520 filter->data = data;
2521 filter->ref_count = 1;
2525 window->filters = g_list_append (window->filters, filter);
2527 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2531 * gdk_window_remove_filter: (skip)
2532 * @window: a #GdkWindow
2533 * @function: previously-added filter function
2534 * @data: user data for previously-added filter function
2536 * Remove a filter previously added with gdk_window_add_filter().
2539 gdk_window_remove_filter (GdkWindow *window,
2540 GdkFilterFunc function,
2544 GdkEventFilter *filter;
2546 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2549 tmp_list = window->filters;
2551 tmp_list = _gdk_default_filters;
2555 filter = (GdkEventFilter *)tmp_list->data;
2556 tmp_list = tmp_list->next;
2558 if ((filter->function == function) && (filter->data == data))
2560 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2562 _gdk_event_filter_unref (window, filter);
2570 * gdk_screen_get_toplevel_windows:
2571 * @screen: The #GdkScreen where the toplevels are located.
2573 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2574 * A toplevel window is a child of the root window (see
2575 * gdk_get_default_root_window()).
2577 * The returned list should be freed with g_list_free(), but
2578 * its elements need not be freed.
2580 * Return value: (transfer container) (element-type GdkWindow):
2581 * list of toplevel windows, free with g_list_free()
2586 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2588 GdkWindow * root_window;
2589 GList *new_list = NULL;
2592 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2594 root_window = gdk_screen_get_root_window (screen);
2596 tmp_list = root_window->children;
2599 GdkWindow *w = tmp_list->data;
2601 if (w->window_type != GDK_WINDOW_FOREIGN)
2602 new_list = g_list_prepend (new_list, w);
2603 tmp_list = tmp_list->next;
2610 * gdk_window_is_visible:
2611 * @window: a #GdkWindow
2613 * Checks whether the window has been mapped (with gdk_window_show() or
2614 * gdk_window_show_unraised()).
2616 * Return value: %TRUE if the window is mapped
2619 gdk_window_is_visible (GdkWindow *window)
2621 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2623 return GDK_WINDOW_IS_MAPPED (window);
2627 * gdk_window_is_viewable:
2628 * @window: a #GdkWindow
2630 * Check if the window and all ancestors of the window are
2631 * mapped. (This is not necessarily "viewable" in the X sense, since
2632 * we only check as far as we have GDK window parents, not to the root
2635 * Return value: %TRUE if the window is viewable
2638 gdk_window_is_viewable (GdkWindow *window)
2640 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2642 if (window->destroyed)
2645 return window->viewable;
2649 * gdk_window_get_state:
2650 * @window: a #GdkWindow
2652 * Gets the bitwise OR of the currently active window state flags,
2653 * from the #GdkWindowState enumeration.
2655 * Return value: window state bitfield
2658 gdk_window_get_state (GdkWindow *window)
2660 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2662 return window->state;
2665 static cairo_content_t
2666 gdk_window_get_content (GdkWindow *window)
2668 cairo_surface_t *surface;
2669 cairo_content_t content;
2671 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2673 surface = _gdk_window_ref_cairo_surface (window);
2674 content = cairo_surface_get_content (surface);
2675 cairo_surface_destroy (surface);
2680 /* This creates an empty "implicit" paint region for the impl window.
2681 * By itself this does nothing, but real paints to this window
2682 * or children of it can use this surface as backing to avoid allocating
2683 * multiple surfaces for subwindow rendering. When doing so they
2684 * add to the region of the implicit paint region, which will be
2685 * pushed to the window when the implicit paint region is ended.
2686 * Such paints should not copy anything to the window on paint end, but
2687 * should rely on the implicit paint end.
2688 * The implicit paint will be automatically ended if someone draws
2689 * directly to the window or a child window.
2692 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2694 GdkWindowPaint *paint;
2696 g_assert (gdk_window_has_impl (window));
2698 if (GDK_IS_PAINTABLE (window->impl))
2699 return FALSE; /* Implementation does double buffering */
2701 if (window->paint_stack != NULL ||
2702 window->implicit_paint != NULL)
2703 return FALSE; /* Don't stack implicit paints */
2705 /* Never do implicit paints for foreign windows, they don't need
2706 * double buffer combination since they have no client side children,
2707 * and creating surfaces for them is risky since they could disappear
2710 if (window->window_type == GDK_WINDOW_FOREIGN)
2713 paint = g_new (GdkWindowPaint, 1);
2714 paint->region = cairo_region_create (); /* Empty */
2715 paint->uses_implicit = FALSE;
2716 paint->flushed = NULL;
2717 paint->surface = gdk_window_create_similar_surface (window,
2718 gdk_window_get_content (window),
2719 MAX (rect->width, 1),
2720 MAX (rect->height, 1));
2721 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2723 window->implicit_paint = paint;
2728 static cairo_surface_t *
2729 gdk_window_ref_impl_surface (GdkWindow *window)
2731 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2735 gdk_cairo_create_for_impl (GdkWindow *window)
2737 cairo_surface_t *surface;
2740 surface = gdk_window_ref_impl_surface (window);
2741 cr = cairo_create (surface);
2743 cairo_surface_destroy (surface);
2748 /* Ensure that all content related to this (sub)window is pushed to the
2749 native region. If there is an active paint then that area is not
2750 pushed, in order to not show partially finished double buffers. */
2752 gdk_window_flush_implicit_paint (GdkWindow *window)
2754 GdkWindow *impl_window;
2755 GdkWindowPaint *paint;
2756 cairo_region_t *region;
2759 impl_window = gdk_window_get_impl_window (window);
2760 if (impl_window->implicit_paint == NULL)
2763 paint = impl_window->implicit_paint;
2764 region = cairo_region_copy (window->clip_region_with_children);
2766 cairo_region_translate (region, window->abs_x, window->abs_y);
2768 if (paint->flushed == NULL)
2769 paint->flushed = cairo_region_copy (region);
2771 cairo_region_union (paint->flushed, region);
2773 cairo_region_intersect (region, paint->region);
2775 /* Don't flush active double buffers, as that may show partially done
2777 for (list = window->paint_stack; list != NULL; list = list->next)
2779 GdkWindowPaint *tmp_paint = list->data;
2781 cairo_region_subtract (region, tmp_paint->region);
2784 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2788 /* Remove flushed region from the implicit paint */
2789 cairo_region_subtract (paint->region, region);
2791 /* Some regions are valid, push these to window now */
2792 cr = gdk_cairo_create_for_impl (window);
2793 gdk_cairo_region (cr, region);
2795 cairo_set_source_surface (cr, paint->surface, 0, 0);
2796 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2801 cairo_region_destroy (region);
2804 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2806 gdk_window_end_implicit_paint (GdkWindow *window)
2808 GdkWindowPaint *paint;
2810 g_assert (gdk_window_has_impl (window));
2812 g_assert (window->implicit_paint != NULL);
2814 paint = window->implicit_paint;
2816 window->implicit_paint = NULL;
2818 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2822 /* Some regions are valid, push these to window now */
2823 cr = gdk_cairo_create_for_impl (window);
2824 gdk_cairo_region (cr, paint->region);
2826 cairo_set_source_surface (cr, paint->surface, 0, 0);
2827 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2832 cairo_region_destroy (paint->region);
2834 cairo_region_destroy (paint->flushed);
2835 cairo_surface_destroy (paint->surface);
2840 * gdk_window_begin_paint_rect:
2841 * @window: a #GdkWindow
2842 * @rectangle: rectangle you intend to draw to
2844 * A convenience wrapper around gdk_window_begin_paint_region() which
2845 * creates a rectangular region for you. See
2846 * gdk_window_begin_paint_region() for details.
2850 gdk_window_begin_paint_rect (GdkWindow *window,
2851 const GdkRectangle *rectangle)
2853 cairo_region_t *region;
2855 g_return_if_fail (GDK_IS_WINDOW (window));
2857 region = cairo_region_create_rectangle (rectangle);
2858 gdk_window_begin_paint_region (window, region);
2859 cairo_region_destroy (region);
2863 * gdk_window_begin_paint_region:
2864 * @window: a #GdkWindow
2865 * @region: region you intend to draw to
2867 * Indicates that you are beginning the process of redrawing @region.
2868 * A backing store (offscreen buffer) large enough to contain @region
2869 * will be created. The backing store will be initialized with the
2870 * background color or background surface for @window. Then, all
2871 * drawing operations performed on @window will be diverted to the
2872 * backing store. When you call gdk_window_end_paint(), the backing
2873 * store will be copied to @window, making it visible onscreen. Only
2874 * the part of @window contained in @region will be modified; that is,
2875 * drawing operations are clipped to @region.
2877 * The net result of all this is to remove flicker, because the user
2878 * sees the finished product appear all at once when you call
2879 * gdk_window_end_paint(). If you draw to @window directly without
2880 * calling gdk_window_begin_paint_region(), the user may see flicker
2881 * as individual drawing operations are performed in sequence. The
2882 * clipping and background-initializing features of
2883 * gdk_window_begin_paint_region() are conveniences for the
2884 * programmer, so you can avoid doing that work yourself.
2886 * When using GTK+, the widget system automatically places calls to
2887 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2888 * emissions of the expose_event signal. That is, if you're writing an
2889 * expose event handler, you can assume that the exposed area in
2890 * #GdkEventExpose has already been cleared to the window background,
2891 * is already set as the clip region, and already has a backing store.
2892 * Therefore in most cases, application code need not call
2893 * gdk_window_begin_paint_region(). (You can disable the automatic
2894 * calls around expose events on a widget-by-widget basis by calling
2895 * gtk_widget_set_double_buffered().)
2897 * If you call this function multiple times before calling the
2898 * matching gdk_window_end_paint(), the backing stores are pushed onto
2899 * a stack. gdk_window_end_paint() copies the topmost backing store
2900 * onscreen, subtracts the topmost region from all other regions in
2901 * the stack, and pops the stack. All drawing operations affect only
2902 * the topmost backing store in the stack. One matching call to
2903 * gdk_window_end_paint() is required for each call to
2904 * gdk_window_begin_paint_region().
2908 gdk_window_begin_paint_region (GdkWindow *window,
2909 const cairo_region_t *region)
2911 #ifdef USE_BACKING_STORE
2912 GdkRectangle clip_box;
2913 GdkWindowPaint *paint, *implicit_paint;
2914 GdkWindow *impl_window;
2917 g_return_if_fail (GDK_IS_WINDOW (window));
2919 if (GDK_WINDOW_DESTROYED (window))
2922 if (GDK_IS_PAINTABLE (window->impl))
2924 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2926 if (iface->begin_paint_region)
2927 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2932 impl_window = gdk_window_get_impl_window (window);
2933 implicit_paint = impl_window->implicit_paint;
2935 paint = g_new (GdkWindowPaint, 1);
2936 paint->region = cairo_region_copy (region);
2938 cairo_region_intersect (paint->region, window->clip_region_with_children);
2939 cairo_region_get_extents (paint->region, &clip_box);
2941 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2943 /* Mark the region as valid on the implicit paint */
2946 cairo_region_union (implicit_paint->region, paint->region);
2948 /* Convert back to normal coords */
2949 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2953 paint->uses_implicit = TRUE;
2954 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2955 window->abs_x + clip_box.x,
2956 window->abs_y + clip_box.y,
2957 MAX (clip_box.width, 1),
2958 MAX (clip_box.height, 1));
2962 paint->uses_implicit = FALSE;
2963 paint->surface = gdk_window_create_similar_surface (window,
2964 gdk_window_get_content (window),
2965 MAX (clip_box.width, 1),
2966 MAX (clip_box.height, 1));
2969 /* Normally alpha backgrounded client side windows are composited on the implicit paint
2970 by being drawn in back to front order. However, if implicit paints are not used, for
2971 instance if it was flushed due to a non-double-buffered paint in the middle of the
2972 expose we need to copy in the existing data here. */
2973 if (!gdk_window_has_impl (window) &&
2974 window->has_alpha_background &&
2976 (implicit_paint && implicit_paint->flushed != NULL && !cairo_region_is_empty (implicit_paint->flushed))))
2978 cairo_t *cr = cairo_create (paint->surface);
2979 /* We can't use gdk_cairo_set_source_window here, as that might
2980 flush the implicit paint at an unfortunate time, since this
2981 would be detected as a draw during non-expose time */
2982 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (impl_window);
2983 cairo_set_source_surface (cr, source_surface,
2984 - (window->abs_x + clip_box.x),
2985 - (window->abs_y + clip_box.y));
2986 cairo_surface_destroy (source_surface);
2988 /* Only read back the flushed area if any */
2991 cairo_region_t *flushed = cairo_region_copy (implicit_paint->flushed);
2992 /* Convert from impl coords */
2993 cairo_region_translate (flushed, -window->abs_x, -window->abs_y);
2994 cairo_region_intersect (flushed, paint->region);
2995 gdk_cairo_region (cr, flushed);
2998 /* Convert to impl coords */
2999 cairo_region_translate (flushed, window->abs_x, window->abs_y);
3000 cairo_region_subtract (implicit_paint->flushed, flushed);
3001 cairo_region_destroy (flushed);
3007 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3009 for (list = window->paint_stack; list != NULL; list = list->next)
3011 GdkWindowPaint *tmp_paint = list->data;
3013 cairo_region_subtract (tmp_paint->region, paint->region);
3016 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
3018 if (!cairo_region_is_empty (paint->region))
3020 gdk_window_clear_backing_region (window,
3024 #endif /* USE_BACKING_STORE */
3028 * gdk_window_end_paint:
3029 * @window: a #GdkWindow
3031 * Indicates that the backing store created by the most recent call to
3032 * gdk_window_begin_paint_region() should be copied onscreen and
3033 * deleted, leaving the next-most-recent backing store or no backing
3034 * store at all as the active paint region. See
3035 * gdk_window_begin_paint_region() for full details. It is an error to
3036 * call this function without a matching
3037 * gdk_window_begin_paint_region() first.
3041 gdk_window_end_paint (GdkWindow *window)
3043 #ifdef USE_BACKING_STORE
3044 GdkWindow *composited;
3045 GdkWindowPaint *paint;
3046 GdkRectangle clip_box;
3047 cairo_region_t *full_clip;
3049 g_return_if_fail (GDK_IS_WINDOW (window));
3051 if (GDK_WINDOW_DESTROYED (window))
3054 if (GDK_IS_PAINTABLE (window->impl))
3056 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3058 if (iface->end_paint)
3059 iface->end_paint ((GdkPaintable*)window->impl);
3063 if (window->paint_stack == NULL)
3065 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3069 paint = window->paint_stack->data;
3071 window->paint_stack = g_slist_delete_link (window->paint_stack,
3072 window->paint_stack);
3074 cairo_region_get_extents (paint->region, &clip_box);
3076 if (!paint->uses_implicit)
3080 gdk_window_flush_outstanding_moves (window);
3082 full_clip = cairo_region_copy (window->clip_region_with_children);
3083 cairo_region_intersect (full_clip, paint->region);
3085 cr = gdk_cairo_create (window);
3086 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3087 cairo_set_source_surface (cr, paint->surface, 0, 0);
3088 gdk_cairo_region (cr, full_clip);
3092 cairo_region_destroy (full_clip);
3095 cairo_surface_destroy (paint->surface);
3096 cairo_region_destroy (paint->region);
3099 /* find a composited window in our hierarchy to signal its
3100 * parent to redraw, calculating the clip box as we go...
3102 * stop if parent becomes NULL since then we'd have nowhere
3103 * to draw (ie: 'composited' will always be non-NULL here).
3105 for (composited = window;
3107 composited = composited->parent)
3109 clip_box.x += composited->x;
3110 clip_box.y += composited->y;
3111 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3112 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3114 if (composited->composited)
3116 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3121 #endif /* USE_BACKING_STORE */
3125 gdk_window_free_paint_stack (GdkWindow *window)
3127 if (window->paint_stack)
3129 GSList *tmp_list = window->paint_stack;
3133 GdkWindowPaint *paint = tmp_list->data;
3135 if (tmp_list == window->paint_stack)
3136 cairo_surface_destroy (paint->surface);
3138 cairo_region_destroy (paint->region);
3141 tmp_list = tmp_list->next;
3144 g_slist_free (window->paint_stack);
3145 window->paint_stack = NULL;
3150 do_move_region_bits_on_impl (GdkWindow *impl_window,
3151 cairo_region_t *dest_region, /* In impl window coords */
3154 GdkWindowImplClass *impl_class;
3156 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3158 impl_class->translate (impl_window, dest_region, dx, dy);
3161 static GdkWindowRegionMove *
3162 gdk_window_region_move_new (cairo_region_t *region,
3165 GdkWindowRegionMove *move;
3167 move = g_slice_new (GdkWindowRegionMove);
3168 move->dest_region = cairo_region_copy (region);
3176 gdk_window_region_move_free (GdkWindowRegionMove *move)
3178 cairo_region_destroy (move->dest_region);
3179 g_slice_free (GdkWindowRegionMove, move);
3183 append_move_region (GdkWindow *impl_window,
3184 cairo_region_t *new_dest_region,
3187 GdkWindowRegionMove *move, *old_move;
3188 cairo_region_t *new_total_region, *old_total_region;
3189 cairo_region_t *source_overlaps_destination;
3190 cairo_region_t *non_overwritten;
3191 gboolean added_move;
3194 if (cairo_region_is_empty (new_dest_region))
3197 /* In principle this could just append the move to the list of outstanding
3198 moves that will be replayed before drawing anything when we're handling
3199 exposes. However, we'd like to do a bit better since its commonly the case
3200 that we get multiple copies where A is copied to B and then B is copied
3201 to C, and we'd like to express this as a simple copy A to C operation. */
3203 /* We approach this by taking the new move and pushing it ahead of moves
3204 starting at the end of the list and stopping when its not safe to do so.
3205 It's not safe to push past a move if either the source of the new move
3206 is in the destination of the old move, or if the destination of the new
3207 move is in the source of the new move, or if the destination of the new
3208 move overlaps the destination of the old move. We simplify this by
3209 just comparing the total regions (src + dest) */
3210 new_total_region = cairo_region_copy (new_dest_region);
3211 cairo_region_translate (new_total_region, -dx, -dy);
3212 cairo_region_union (new_total_region, new_dest_region);
3215 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3220 old_total_region = cairo_region_copy (old_move->dest_region);
3221 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3222 cairo_region_union (old_total_region, old_move->dest_region);
3224 cairo_region_intersect (old_total_region, new_total_region);
3225 /* If these regions intersect then its not safe to push the
3226 new region before the old one */
3227 if (!cairo_region_is_empty (old_total_region))
3229 /* The area where the new moves source overlaps the old ones
3231 source_overlaps_destination = cairo_region_copy (new_dest_region);
3232 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3233 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3234 cairo_region_translate (source_overlaps_destination, dx, dy);
3236 /* We can do all sort of optimizations here, but to do things safely it becomes
3237 quite complicated. However, a very common case is that you copy something first,
3238 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3239 in the same direction). We'd like to detect this case and optimize it to one
3241 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3243 /* This means we might be able to replace the old move and the new one
3244 with the new one read from the old ones source, and a second copy of
3245 the non-overwritten parts of the old move. However, such a split
3246 is only valid if the source in the old move isn't overwritten
3247 by the destination of the new one */
3249 /* the new destination of old move if split is ok: */
3250 non_overwritten = cairo_region_copy (old_move->dest_region);
3251 cairo_region_subtract (non_overwritten, new_dest_region);
3252 /* move to source region */
3253 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3255 cairo_region_intersect (non_overwritten, new_dest_region);
3256 if (cairo_region_is_empty (non_overwritten))
3259 move = gdk_window_region_move_new (new_dest_region,
3263 impl_window->outstanding_moves =
3264 g_list_insert_before (impl_window->outstanding_moves,
3266 cairo_region_subtract (old_move->dest_region, new_dest_region);
3268 cairo_region_destroy (non_overwritten);
3271 cairo_region_destroy (source_overlaps_destination);
3272 cairo_region_destroy (old_total_region);
3275 cairo_region_destroy (old_total_region);
3278 cairo_region_destroy (new_total_region);
3282 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3285 impl_window->outstanding_moves =
3286 g_list_prepend (impl_window->outstanding_moves,
3289 impl_window->outstanding_moves =
3290 g_list_insert_before (impl_window->outstanding_moves,
3295 /* Moves bits and update area by dx/dy in impl window.
3296 Takes ownership of region to avoid copy (because we may change it) */
3298 move_region_on_impl (GdkWindow *impl_window,
3299 cairo_region_t *region, /* In impl window coords */
3302 if ((dx == 0 && dy == 0) ||
3303 cairo_region_is_empty (region))
3305 cairo_region_destroy (region);
3309 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3311 /* Move any old invalid regions in the copy source area by dx/dy */
3312 if (impl_window->update_area)
3314 cairo_region_t *update_area;
3316 update_area = cairo_region_copy (region);
3318 /* Convert from target to source */
3319 cairo_region_translate (update_area, -dx, -dy);
3320 cairo_region_intersect (update_area, impl_window->update_area);
3321 /* We only copy the area, so keep the old update area invalid.
3322 It would be safe to remove it too, as code that uses
3323 move_region_on_impl generally also invalidate the source
3324 area. However, it would just use waste cycles. */
3327 cairo_region_translate (update_area, dx, dy);
3328 cairo_region_union (impl_window->update_area, update_area);
3330 /* This area of the destination is now invalid,
3331 so no need to copy to it. */
3332 cairo_region_subtract (region, update_area);
3334 cairo_region_destroy (update_area);
3337 /* If we're currently exposing this window, don't copy to this
3338 destination, as it will be overdrawn when the expose is done,
3339 instead invalidate it and repaint later. */
3340 if (impl_window->implicit_paint)
3342 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3343 cairo_region_t *exposing;
3345 exposing = cairo_region_copy (implicit_paint->region);
3346 cairo_region_intersect (exposing, region);
3347 cairo_region_subtract (region, exposing);
3349 impl_window_add_update_area (impl_window, exposing);
3350 cairo_region_destroy (exposing);
3353 append_move_region (impl_window, region, dx, dy);
3355 cairo_region_destroy (region);
3358 /* Flushes all outstanding changes to the window, call this
3359 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3362 gdk_window_flush_outstanding_moves (GdkWindow *window)
3364 GdkWindow *impl_window;
3365 GList *l, *outstanding;
3366 GdkWindowRegionMove *move;
3368 impl_window = gdk_window_get_impl_window (window);
3369 outstanding = impl_window->outstanding_moves;
3370 impl_window->outstanding_moves = NULL;
3372 for (l = outstanding; l != NULL; l = l->next)
3376 do_move_region_bits_on_impl (impl_window,
3377 move->dest_region, move->dx, move->dy);
3379 gdk_window_region_move_free (move);
3382 g_list_free (outstanding);
3387 * @window: a #GdkWindow
3389 * Flush all outstanding cached operations on a window, leaving the
3390 * window in a state which reflects all that has been drawn before.
3392 * Gdk uses multiple kinds of caching to get better performance and
3393 * nicer drawing. For instance, during exposes all paints to a window
3394 * using double buffered rendering are keep on a surface until the last
3395 * window has been exposed. It also delays window moves/scrolls until
3396 * as long as possible until next update to avoid tearing when moving
3399 * Normally this should be completely invisible to applications, as
3400 * we automatically flush the windows when required, but this might
3401 * be needed if you for instance mix direct native drawing with
3402 * gdk drawing. For Gtk widgets that don't use double buffering this
3403 * will be called automatically before sending the expose event.
3408 gdk_window_flush (GdkWindow *window)
3410 gdk_window_flush_outstanding_moves (window);
3411 gdk_window_flush_implicit_paint (window);
3414 /* If we're about to move/resize or otherwise change the
3415 * hierarchy of a client side window in an impl and we're
3416 * called from an expose event handler then we need to
3417 * flush any already painted parts of the implicit paint
3418 * that are not part of the current paint, as these may
3419 * be used when scrolling or may overdraw the changes
3420 * caused by the hierarchy change.
3423 gdk_window_flush_if_exposing (GdkWindow *window)
3425 GdkWindow *impl_window;
3427 impl_window = gdk_window_get_impl_window (window);
3429 /* If we're in an implicit paint (i.e. in an expose handler, flush
3430 all the already finished exposes to get things to an uptodate state. */
3431 if (impl_window->implicit_paint)
3432 gdk_window_flush (window);
3437 gdk_window_flush_recursive_helper (GdkWindow *window,
3438 GdkWindowImpl *impl)
3443 for (l = window->children; l != NULL; l = l->next)
3447 if (child->impl == impl)
3448 /* Same impl, ignore */
3449 gdk_window_flush_recursive_helper (child, impl);
3451 gdk_window_flush_recursive (child);
3456 gdk_window_flush_recursive (GdkWindow *window)
3458 gdk_window_flush (window);
3459 gdk_window_flush_recursive_helper (window, window->impl);
3463 * gdk_window_get_clip_region:
3464 * @window: a #GdkWindow
3466 * Computes the region of a window that potentially can be written
3467 * to by drawing primitives. This region may not take into account
3468 * other factors such as if the window is obscured by other windows,
3469 * but no area outside of this region will be affected by drawing
3472 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3473 * when you are done.
3476 gdk_window_get_clip_region (GdkWindow *window)
3478 cairo_region_t *result;
3480 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3482 result = cairo_region_copy (window->clip_region);
3484 if (window->paint_stack)
3486 cairo_region_t *paint_region = cairo_region_create ();
3487 GSList *tmp_list = window->paint_stack;
3491 GdkWindowPaint *paint = tmp_list->data;
3493 cairo_region_union (paint_region, paint->region);
3495 tmp_list = tmp_list->next;
3498 cairo_region_intersect (result, paint_region);
3499 cairo_region_destroy (paint_region);
3506 * gdk_window_get_visible_region:
3507 * @window: a #GdkWindow
3509 * Computes the region of the @window that is potentially visible.
3510 * This does not necessarily take into account if the window is
3511 * obscured by other windows, but no area outside of this region
3514 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3515 * when you are done.
3518 gdk_window_get_visible_region (GdkWindow *window)
3520 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3522 return cairo_region_copy (window->clip_region);
3526 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint)
3528 GdkWindow *bg_window;
3529 cairo_pattern_t *pattern = NULL;
3530 int x_offset = 0, y_offset = 0;
3533 cr = cairo_create (paint->surface);
3535 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3537 pattern = gdk_window_get_background_pattern (bg_window);
3541 x_offset += bg_window->x;
3542 y_offset += bg_window->y;
3547 cairo_translate (cr, -x_offset, -y_offset);
3548 cairo_set_source (cr, pattern);
3549 cairo_translate (cr, x_offset, y_offset);
3552 cairo_set_source_rgb (cr, 0, 0, 0);
3558 gdk_window_clear_backing_region (GdkWindow *window,
3559 cairo_region_t *region)
3561 GdkWindowPaint *paint = window->paint_stack->data;
3562 cairo_region_t *clip;
3565 if (GDK_WINDOW_DESTROYED (window))
3568 cr = setup_backing_rect (window, paint);
3570 clip = cairo_region_copy (paint->region);
3571 cairo_region_intersect (clip, region);
3573 gdk_cairo_region (cr, clip);
3578 cairo_region_destroy (clip);
3582 gdk_window_drop_cairo_surface (GdkWindow *window)
3584 if (window->cairo_surface)
3586 cairo_surface_finish (window->cairo_surface);
3587 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3589 window->cairo_surface = NULL;
3594 gdk_window_cairo_surface_destroy (void *data)
3596 GdkWindow *window = data;
3598 window->cairo_surface = NULL;
3601 static cairo_surface_t *
3602 gdk_window_create_cairo_surface (GdkWindow *window,
3606 cairo_surface_t *surface, *subsurface;
3608 surface = gdk_window_ref_impl_surface (window);
3609 if (gdk_window_has_impl (window))
3612 subsurface = cairo_surface_create_for_rectangle (surface,
3617 cairo_surface_destroy (surface);
3623 _gdk_window_ref_cairo_surface (GdkWindow *window)
3625 cairo_surface_t *surface;
3627 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3629 if (window->paint_stack)
3631 GdkWindowPaint *paint = window->paint_stack->data;
3633 surface = paint->surface;
3634 cairo_surface_reference (surface);
3639 /* This will be drawing directly to the window, so flush implicit paint */
3640 gdk_window_flush (window);
3642 if (!window->cairo_surface)
3644 window->cairo_surface = gdk_window_create_cairo_surface (window,
3648 if (window->cairo_surface)
3650 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3651 window, gdk_window_cairo_surface_destroy);
3655 cairo_surface_reference (window->cairo_surface);
3657 surface = window->cairo_surface;
3665 * @window: a #GdkWindow
3667 * Creates a Cairo context for drawing to @window.
3670 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3671 * produce undefined results, so avoid it at all costs.
3674 * Return value: A newly created Cairo context. Free with
3675 * cairo_destroy() when you are done drawing.
3680 gdk_cairo_create (GdkWindow *window)
3682 cairo_surface_t *surface;
3685 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3687 surface = _gdk_window_ref_cairo_surface (window);
3688 cr = cairo_create (surface);
3690 if (!window->paint_stack)
3692 gdk_cairo_region (cr, window->clip_region_with_children);
3697 GdkWindowPaint *paint = window->paint_stack->data;
3699 /* Only needs to clip to region if piggybacking
3700 on an implicit paint */
3701 if (paint->uses_implicit)
3703 gdk_cairo_region (cr, paint->region);
3708 cairo_surface_destroy (surface);
3713 /* Code for dirty-region queueing
3715 static GSList *update_windows = NULL;
3716 static guint update_idle = 0;
3717 static gboolean debug_updates = FALSE;
3719 static inline gboolean
3720 gdk_window_is_ancestor (GdkWindow *window,
3721 GdkWindow *ancestor)
3725 GdkWindow *parent = window->parent;
3727 if (parent == ancestor)
3737 gdk_window_add_update_window (GdkWindow *window)
3740 GSList *prev = NULL;
3741 gboolean has_ancestor_in_list = FALSE;
3743 for (tmp = update_windows; tmp; tmp = tmp->next)
3745 GdkWindow *parent = window->parent;
3747 /* check if tmp is an ancestor of "window"; if it is, set a
3748 * flag indicating that all following windows are either
3749 * children of "window" or from a differen hierarchy
3751 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3752 has_ancestor_in_list = TRUE;
3754 /* insert in reverse stacking order when adding around siblings,
3755 * so processing updates properly paints over lower stacked windows
3757 if (parent == GDK_WINDOW (tmp->data)->parent)
3759 gint index = g_list_index (parent->children, window);
3760 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3762 gint sibling_index = g_list_index (parent->children, tmp->data);
3763 if (index > sibling_index)
3767 /* here, tmp got advanced past all lower stacked siblings */
3768 tmp = g_slist_prepend (tmp, window);
3772 update_windows = tmp;
3776 /* if "window" has an ancestor in the list and tmp is one of
3777 * "window's" children, insert "window" before tmp
3779 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3781 tmp = g_slist_prepend (tmp, window);
3786 update_windows = tmp;
3790 /* if we're at the end of the list and had an ancestor it it,
3791 * append to the list
3793 if (! tmp->next && has_ancestor_in_list)
3795 tmp = g_slist_append (tmp, window);
3802 /* if all above checks failed ("window" is from a different
3803 * hierarchy than what is already in the list) or the list is
3806 update_windows = g_slist_prepend (update_windows, window);
3810 gdk_window_remove_update_window (GdkWindow *window)
3812 update_windows = g_slist_remove (update_windows, window);
3816 gdk_window_update_idle (gpointer data)
3818 gdk_window_process_all_updates ();
3824 gdk_window_is_toplevel_frozen (GdkWindow *window)
3826 GdkWindow *toplevel;
3828 toplevel = gdk_window_get_toplevel (window);
3830 return toplevel->update_and_descendants_freeze_count > 0;
3834 gdk_window_schedule_update (GdkWindow *window)
3837 (window->update_freeze_count ||
3838 gdk_window_is_toplevel_frozen (window)))
3843 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3844 gdk_window_update_idle,
3849 _gdk_window_process_updates_recurse (GdkWindow *window,
3850 cairo_region_t *expose_region)
3853 cairo_region_t *clipped_expose_region;
3854 GList *l, *children;
3856 if (cairo_region_is_empty (expose_region))
3859 if (gdk_window_is_offscreen (window->impl_window) &&
3860 gdk_window_has_impl (window))
3861 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3864 /* Paint the window before the children, clipped to the window region
3865 with visible child windows removed */
3866 clipped_expose_region = cairo_region_copy (expose_region);
3867 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3869 if (!cairo_region_is_empty (clipped_expose_region) &&
3872 if (window->event_mask & GDK_EXPOSURE_MASK)
3876 event.expose.type = GDK_EXPOSE;
3877 event.expose.window = g_object_ref (window);
3878 event.expose.send_event = FALSE;
3879 event.expose.count = 0;
3880 event.expose.region = clipped_expose_region;
3881 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
3883 _gdk_event_emit (&event);
3885 g_object_unref (window);
3887 else if (window->window_type != GDK_WINDOW_FOREIGN)
3889 /* No exposure mask set, so nothing will be drawn, the
3890 * app relies on the background being what it specified
3891 * for the window. So, we need to clear this manually.
3893 * For foreign windows if expose is not set that generally
3894 * means some other client paints them, so don't clear
3897 * We use begin/end_paint around the clear so that we can
3898 * piggyback on the implicit paint */
3900 gdk_window_begin_paint_region (window, clipped_expose_region);
3901 /* The actual clear happens in begin_paint_region */
3902 gdk_window_end_paint (window);
3905 cairo_region_destroy (clipped_expose_region);
3907 /* Make this reentrancy safe for expose handlers freeing windows */
3908 children = g_list_copy (window->children);
3909 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3911 /* Iterate over children, starting at bottommost */
3912 for (l = g_list_last (children); l != NULL; l = l->prev)
3916 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3919 /* Ignore offscreen children, as they don't draw in their parent and
3920 * don't take part in the clipping */
3921 if (gdk_window_is_offscreen (child))
3924 /* Client side child, expose */
3925 if (child->impl == window->impl)
3927 cairo_region_translate (expose_region, -child->x, -child->y);
3928 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
3929 cairo_region_translate (expose_region, child->x, child->y);
3933 g_list_free_full (children, g_object_unref);
3937 /* Process and remove any invalid area on the native window by creating
3938 * expose events for the window and all non-native descendants.
3939 * Also processes any outstanding moves on the window before doing
3940 * any drawing. Note that its possible to have outstanding moves without
3941 * any invalid area as we use the update idle mechanism to coalesce
3942 * multiple moves as well as multiple invalidations.
3945 gdk_window_process_updates_internal (GdkWindow *window)
3947 GdkWindowImplClass *impl_class;
3948 gboolean save_region = FALSE;
3949 GdkRectangle clip_box;
3951 /* Ensure the window lives while updating it */
3952 g_object_ref (window);
3954 /* If an update got queued during update processing, we can get a
3955 * window in the update queue that has an empty update_area.
3958 if (window->update_area)
3960 cairo_region_t *update_area = window->update_area;
3961 window->update_area = NULL;
3963 if (gdk_window_is_viewable (window))
3965 cairo_region_t *expose_region;
3966 gboolean end_implicit;
3968 /* Clip to part visible in toplevel */
3969 cairo_region_intersect (update_area, window->clip_region);
3973 /* Make sure we see the red invalid area before redrawing. */
3974 gdk_display_sync (gdk_window_get_display (window));
3978 /* At this point we will be completely redrawing all of update_area.
3979 * If we have any outstanding moves that end up moving stuff inside
3980 * this area we don't actually need to move that as that part would
3981 * be overdrawn by the expose anyway. So, in order to copy less data
3982 * we remove these areas from the outstanding moves.
3984 if (window->outstanding_moves)
3986 GdkWindowRegionMove *move;
3987 cairo_region_t *remove;
3990 remove = cairo_region_copy (update_area);
3991 /* We iterate backwards, starting from the state that would be
3992 if we had applied all the moves. */
3993 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
3998 /* Don't need this area */
3999 cairo_region_subtract (move->dest_region, remove);
4001 /* However if any of the destination we do need has a source
4002 in the updated region we do need that as a destination for
4003 the earlier moves */
4004 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4005 cairo_region_subtract (remove, move->dest_region);
4007 if (cairo_region_is_empty (move->dest_region))
4009 gdk_window_region_move_free (move);
4010 window->outstanding_moves =
4011 g_list_delete_link (window->outstanding_moves, l);
4013 else /* move back */
4014 cairo_region_translate (move->dest_region, move->dx, move->dy);
4016 cairo_region_destroy (remove);
4019 /* By now we a set of window moves that should be applied, and then
4020 * an update region that should be repainted. A trivial implementation
4021 * would just do that in order, however in order to get nicer drawing
4022 * we do some tricks:
4024 * First of all, each subwindow expose may be double buffered by
4025 * itself (depending on widget setting) via
4026 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4027 * creating a single surface the size of the invalid area on the
4028 * native window which all the individual normal paints will draw
4029 * into. This way in the normal case there will be only one surface
4030 * allocated and only once surface draw done for all the windows
4031 * in this native window.
4032 * There are a couple of reasons this may fail, for instance, some
4033 * backends (like quartz) do its own double buffering, so we disable
4034 * gdk double buffering there. Secondly, some subwindow could be
4035 * non-double buffered and draw directly to the window outside a
4036 * begin/end_paint pair. That will be lead to a gdk_window_flush
4037 * which immediately executes all outstanding moves and paints+removes
4038 * the implicit paint (further paints will allocate their own surfaces).
4040 * Secondly, in the case of implicit double buffering we expose all
4041 * the child windows into the implicit surface before we execute
4042 * the outstanding moves. This way we minimize the time between
4043 * doing the moves and rendering the new update area, thus minimizing
4044 * flashing. Of course, if any subwindow is non-double buffered we
4045 * well flush earlier than that.
4047 * Thirdly, after having done the outstanding moves we queue an
4048 * "antiexpose" on the area that will be drawn by the expose, which
4049 * means that any invalid region on the native window side before
4050 * the first expose drawing operation will be discarded, as it
4051 * has by then been overdrawn with valid data. This means we can
4052 * avoid doing the unnecessary repaint any outstanding expose events.
4055 cairo_region_get_extents (update_area, &clip_box);
4056 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4057 expose_region = cairo_region_copy (update_area);
4058 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4061 /* Rendering is not double buffered by gdk, do outstanding
4062 * moves and queue antiexposure immediately. No need to do
4064 gdk_window_flush_outstanding_moves (window);
4065 save_region = impl_class->queue_antiexpose (window, update_area);
4067 /* Render the invalid areas to the implicit paint, by sending exposes.
4068 * May flush if non-double buffered widget draw. */
4069 impl_class->process_updates_recurse (window, expose_region);
4073 /* Do moves right before exposes are rendered to the window */
4074 gdk_window_flush_outstanding_moves (window);
4076 /* By this time we know that any outstanding expose for this
4077 * area is invalid and we can avoid it, so queue an antiexpose.
4078 * we have already started drawing to the window, so it would
4079 * be to late to anti-expose now. Since this is merely an
4080 * optimization we just avoid doing it at all in that case.
4082 if (window->implicit_paint != NULL && !window->implicit_paint->flushed)
4083 save_region = impl_class->queue_antiexpose (window, update_area);
4085 gdk_window_end_implicit_paint (window);
4087 cairo_region_destroy (expose_region);
4090 cairo_region_destroy (update_area);
4093 if (window->outstanding_moves)
4095 /* Flush any outstanding moves, may happen if we moved a window but got
4096 no actual invalid area */
4097 gdk_window_flush_outstanding_moves (window);
4100 g_object_unref (window);
4104 flush_all_displays (void)
4106 GSList *displays, *l;
4108 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4109 for (l = displays; l; l = l->next)
4110 gdk_display_flush (l->data);
4112 g_slist_free (displays);
4116 before_process_all_updates (void)
4118 GSList *displays, *l;
4119 GdkDisplayClass *display_class;
4121 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4122 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4123 for (l = displays; l; l = l->next)
4124 display_class->before_process_all_updates (l->data);
4126 g_slist_free (displays);
4130 after_process_all_updates (void)
4132 GSList *displays, *l;
4133 GdkDisplayClass *display_class;
4135 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4136 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4137 for (l = displays; l; l = l->next)
4138 display_class->after_process_all_updates (l->data);
4140 g_slist_free (displays);
4143 /* Currently it is not possible to override
4144 * gdk_window_process_all_updates in the same manner as
4145 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4146 * by implementing the GdkPaintable interface. If in the future a
4147 * backend would need this, the right solution would be to add a
4148 * method to GdkDisplay that can be optionally
4149 * NULL. gdk_window_process_all_updates can then walk the list of open
4150 * displays and call the mehod.
4154 * gdk_window_process_all_updates:
4156 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4157 * in the application.
4161 gdk_window_process_all_updates (void)
4163 GSList *old_update_windows = update_windows;
4164 GSList *tmp_list = update_windows;
4165 static gboolean in_process_all_updates = FALSE;
4166 static gboolean got_recursive_update = FALSE;
4168 if (in_process_all_updates)
4170 /* We can't do this now since that would recurse, so
4171 delay it until after the recursion is done. */
4172 got_recursive_update = TRUE;
4177 in_process_all_updates = TRUE;
4178 got_recursive_update = FALSE;
4181 g_source_remove (update_idle);
4183 update_windows = NULL;
4186 before_process_all_updates ();
4188 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4192 GdkWindow *window = tmp_list->data;
4194 if (!GDK_WINDOW_DESTROYED (window))
4196 if (window->update_freeze_count ||
4197 gdk_window_is_toplevel_frozen (window))
4198 gdk_window_add_update_window (window);
4200 gdk_window_process_updates_internal (window);
4203 g_object_unref (window);
4204 tmp_list = tmp_list->next;
4207 g_slist_free (old_update_windows);
4209 flush_all_displays ();
4211 after_process_all_updates ();
4213 in_process_all_updates = FALSE;
4215 /* If we ignored a recursive call, schedule a
4216 redraw now so that it eventually happens,
4217 otherwise we could miss an update if nothing
4218 else schedules an update. */
4219 if (got_recursive_update && !update_idle)
4221 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4222 gdk_window_update_idle,
4227 * gdk_window_process_updates:
4228 * @window: a #GdkWindow
4229 * @update_children: whether to also process updates for child windows
4231 * Sends one or more expose events to @window. The areas in each
4232 * expose event will cover the entire update area for the window (see
4233 * gdk_window_invalidate_region() for details). Normally GDK calls
4234 * gdk_window_process_all_updates() on your behalf, so there's no
4235 * need to call this function unless you want to force expose events
4236 * to be delivered immediately and synchronously (vs. the usual
4237 * case, where GDK delivers them in an idle handler). Occasionally
4238 * this is useful to produce nicer scrolling behavior, for example.
4242 gdk_window_process_updates (GdkWindow *window,
4243 gboolean update_children)
4245 GdkWindow *impl_window;
4247 g_return_if_fail (GDK_IS_WINDOW (window));
4249 if (GDK_WINDOW_DESTROYED (window))
4252 /* Make sure the window lives during the expose callouts */
4253 g_object_ref (window);
4255 impl_window = gdk_window_get_impl_window (window);
4256 if ((impl_window->update_area ||
4257 impl_window->outstanding_moves) &&
4258 !impl_window->update_freeze_count &&
4259 !gdk_window_is_toplevel_frozen (window) &&
4261 /* Don't recurse into process_updates_internal, we'll
4262 * do the update later when idle instead. */
4263 impl_window->implicit_paint == NULL)
4265 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4266 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4269 if (update_children)
4271 /* process updates in reverse stacking order so composition or
4272 * painting over achieves the desired effect for offscreen windows
4274 GList *node, *children;
4276 children = g_list_copy (window->children);
4277 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4279 for (node = g_list_last (children); node; node = node->prev)
4281 gdk_window_process_updates (node->data, TRUE);
4282 g_object_unref (node->data);
4285 g_list_free (children);
4288 g_object_unref (window);
4292 gdk_window_invalidate_rect_full (GdkWindow *window,
4293 const GdkRectangle *rect,
4294 gboolean invalidate_children,
4297 GdkRectangle window_rect;
4298 cairo_region_t *region;
4300 g_return_if_fail (GDK_IS_WINDOW (window));
4302 if (GDK_WINDOW_DESTROYED (window))
4305 if (window->input_only || !window->viewable)
4312 window_rect.width = window->width;
4313 window_rect.height = window->height;
4314 rect = &window_rect;
4317 region = cairo_region_create_rectangle (rect);
4318 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4319 cairo_region_destroy (region);
4323 * gdk_window_invalidate_rect:
4324 * @window: a #GdkWindow
4325 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4327 * @invalidate_children: whether to also invalidate child windows
4329 * A convenience wrapper around gdk_window_invalidate_region() which
4330 * invalidates a rectangular region. See
4331 * gdk_window_invalidate_region() for details.
4334 gdk_window_invalidate_rect (GdkWindow *window,
4335 const GdkRectangle *rect,
4336 gboolean invalidate_children)
4338 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4342 draw_ugly_color (GdkWindow *window,
4343 const cairo_region_t *region)
4347 cr = gdk_cairo_create (window);
4348 /* Draw ugly color all over the newly-invalid region */
4349 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4350 gdk_cairo_region (cr, region);
4357 impl_window_add_update_area (GdkWindow *impl_window,
4358 cairo_region_t *region)
4360 if (impl_window->update_area)
4361 cairo_region_union (impl_window->update_area, region);
4364 gdk_window_add_update_window (impl_window);
4365 impl_window->update_area = cairo_region_copy (region);
4366 gdk_window_schedule_update (impl_window);
4370 /* clear_bg controls if the region will be cleared to
4371 * the background pattern if the exposure mask is not
4372 * set for the window, whereas this might not otherwise be
4373 * done (unless necessary to emulate background settings).
4374 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4375 * need to clear the background, such as when exposing the area beneath a
4376 * hidden or moved window, but not when an app requests repaint or when the
4377 * windowing system exposes a newly visible area (because then the windowing
4378 * system has already cleared the area).
4381 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4382 const cairo_region_t *region,
4384 GdkWindowChildFunc child_func,
4387 GdkWindow *impl_window;
4388 cairo_region_t *visible_region;
4391 g_return_if_fail (GDK_IS_WINDOW (window));
4393 if (GDK_WINDOW_DESTROYED (window))
4396 if (window->input_only ||
4397 !window->viewable ||
4398 cairo_region_is_empty (region) ||
4399 window->window_type == GDK_WINDOW_ROOT)
4402 visible_region = gdk_window_get_visible_region (window);
4403 cairo_region_intersect (visible_region, region);
4405 tmp_list = window->children;
4408 GdkWindow *child = tmp_list->data;
4410 if (!child->input_only)
4412 cairo_region_t *child_region;
4413 GdkRectangle child_rect;
4415 child_rect.x = child->x;
4416 child_rect.y = child->y;
4417 child_rect.width = child->width;
4418 child_rect.height = child->height;
4419 child_region = cairo_region_create_rectangle (&child_rect);
4421 /* remove child area from the invalid area of the parent */
4422 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4423 !child->composited &&
4424 !gdk_window_is_offscreen (child))
4425 cairo_region_subtract (visible_region, child_region);
4427 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4429 cairo_region_t *tmp = cairo_region_copy (region);
4431 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4432 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4433 cairo_region_intersect (child_region, tmp);
4435 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4436 child_region, clear_bg, child_func, user_data);
4438 cairo_region_destroy (tmp);
4441 cairo_region_destroy (child_region);
4444 tmp_list = tmp_list->next;
4447 impl_window = gdk_window_get_impl_window (window);
4449 if (!cairo_region_is_empty (visible_region) ||
4450 /* Even if we're not exposing anything, make sure we process
4451 idles for windows with outstanding moves */
4452 (impl_window->outstanding_moves != NULL &&
4453 impl_window->update_area == NULL))
4456 draw_ugly_color (window, region);
4458 /* Convert to impl coords */
4459 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4461 /* Only invalidate area if app requested expose events or if
4462 we need to clear the area (by request or to emulate background
4463 clearing for non-native windows or native windows with no support
4464 for window backgrounds */
4465 if (window->event_mask & GDK_EXPOSURE_MASK ||
4466 clear_bg == CLEAR_BG_ALL ||
4467 clear_bg == CLEAR_BG_WINCLEARED)
4468 impl_window_add_update_area (impl_window, visible_region);
4471 cairo_region_destroy (visible_region);
4475 * gdk_window_invalidate_maybe_recurse:
4476 * @window: a #GdkWindow
4477 * @region: a #cairo_region_t
4478 * @child_func: (scope call) (allow-none): function to use to decide if to
4479 * recurse to a child, %NULL means never recurse.
4480 * @user_data: data passed to @child_func
4482 * Adds @region to the update area for @window. The update area is the
4483 * region that needs to be redrawn, or "dirty region." The call
4484 * gdk_window_process_updates() sends one or more expose events to the
4485 * window, which together cover the entire update area. An
4486 * application would normally redraw the contents of @window in
4487 * response to those expose events.
4489 * GDK will call gdk_window_process_all_updates() on your behalf
4490 * whenever your program returns to the main loop and becomes idle, so
4491 * normally there's no need to do that manually, you just need to
4492 * invalidate regions that you know should be redrawn.
4494 * The @child_func parameter controls whether the region of
4495 * each child window that intersects @region will also be invalidated.
4496 * Only children for which @child_func returns TRUE will have the area
4500 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4501 const cairo_region_t *region,
4502 GdkWindowChildFunc child_func,
4505 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4506 child_func, user_data);
4510 true_predicate (GdkWindow *window,
4517 gdk_window_invalidate_region_full (GdkWindow *window,
4518 const cairo_region_t *region,
4519 gboolean invalidate_children,
4522 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4523 invalidate_children ?
4524 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4529 * gdk_window_invalidate_region:
4530 * @window: a #GdkWindow
4531 * @region: a #cairo_region_t
4532 * @invalidate_children: %TRUE to also invalidate child windows
4534 * Adds @region to the update area for @window. The update area is the
4535 * region that needs to be redrawn, or "dirty region." The call
4536 * gdk_window_process_updates() sends one or more expose events to the
4537 * window, which together cover the entire update area. An
4538 * application would normally redraw the contents of @window in
4539 * response to those expose events.
4541 * GDK will call gdk_window_process_all_updates() on your behalf
4542 * whenever your program returns to the main loop and becomes idle, so
4543 * normally there's no need to do that manually, you just need to
4544 * invalidate regions that you know should be redrawn.
4546 * The @invalidate_children parameter controls whether the region of
4547 * each child window that intersects @region will also be invalidated.
4548 * If %FALSE, then the update area for child windows will remain
4549 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4550 * fine grained control over which children are invalidated.
4553 gdk_window_invalidate_region (GdkWindow *window,
4554 const cairo_region_t *region,
4555 gboolean invalidate_children)
4557 gdk_window_invalidate_maybe_recurse (window, region,
4558 invalidate_children ?
4559 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4564 * _gdk_window_invalidate_for_expose:
4565 * @window: a #GdkWindow
4566 * @region: a #cairo_region_t
4568 * Adds @region to the update area for @window. The update area is the
4569 * region that needs to be redrawn, or "dirty region." The call
4570 * gdk_window_process_updates() sends one or more expose events to the
4571 * window, which together cover the entire update area. An
4572 * application would normally redraw the contents of @window in
4573 * response to those expose events.
4575 * GDK will call gdk_window_process_all_updates() on your behalf
4576 * whenever your program returns to the main loop and becomes idle, so
4577 * normally there's no need to do that manually, you just need to
4578 * invalidate regions that you know should be redrawn.
4580 * This version of invalidation is used when you recieve expose events
4581 * from the native window system. It exposes the native window, plus
4582 * any non-native child windows (but not native child windows, as those would
4583 * have gotten their own expose events).
4586 _gdk_window_invalidate_for_expose (GdkWindow *window,
4587 cairo_region_t *region)
4589 GdkWindowRegionMove *move;
4590 cairo_region_t *move_region;
4593 /* Any invalidations comming from the windowing system will
4594 be in areas that may be moved by outstanding moves,
4595 so we need to modify the expose region correspondingly,
4596 otherwise we would expose in the wrong place, as the
4597 outstanding moves will be copied before we draw the
4599 for (l = window->outstanding_moves; l != NULL; l = l->next)
4603 /* covert to move source region */
4604 move_region = cairo_region_copy (move->dest_region);
4605 cairo_region_translate (move_region, -move->dx, -move->dy);
4607 /* Move area of region that intersects with move source
4608 by dx, dy of the move*/
4609 cairo_region_intersect (move_region, region);
4610 cairo_region_subtract (region, move_region);
4611 cairo_region_translate (move_region, move->dx, move->dy);
4612 cairo_region_union (region, move_region);
4614 cairo_region_destroy (move_region);
4617 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4618 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4624 * gdk_window_get_update_area:
4625 * @window: a #GdkWindow
4627 * Transfers ownership of the update area from @window to the caller
4628 * of the function. That is, after calling this function, @window will
4629 * no longer have an invalid/dirty region; the update area is removed
4630 * from @window and handed to you. If a window has no update area,
4631 * gdk_window_get_update_area() returns %NULL. You are responsible for
4632 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4634 * Return value: the update area for @window
4637 gdk_window_get_update_area (GdkWindow *window)
4639 GdkWindow *impl_window;
4640 cairo_region_t *tmp_region, *to_remove;
4642 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4644 impl_window = gdk_window_get_impl_window (window);
4646 if (impl_window->update_area)
4648 tmp_region = cairo_region_copy (window->clip_region_with_children);
4649 /* Convert to impl coords */
4650 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4651 cairo_region_intersect (tmp_region, impl_window->update_area);
4653 if (cairo_region_is_empty (tmp_region))
4655 cairo_region_destroy (tmp_region);
4660 /* Convert from impl coords */
4661 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4663 /* Don't remove any update area that is overlapped by non-opaque windows
4664 (children or siblings) with alpha, as these really need to be repainted
4665 independently of this window. */
4666 to_remove = cairo_region_copy (tmp_region);
4667 cairo_region_subtract (to_remove, window->parent->layered_region);
4668 remove_layered_child_area (window, to_remove);
4670 /* Remove from update_area */
4671 cairo_region_translate (to_remove, window->abs_x, window->abs_y);
4672 cairo_region_subtract (impl_window->update_area, to_remove);
4674 cairo_region_destroy (to_remove);
4676 if (cairo_region_is_empty (impl_window->update_area) &&
4677 impl_window->outstanding_moves == NULL)
4679 cairo_region_destroy (impl_window->update_area);
4680 impl_window->update_area = NULL;
4682 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4693 * _gdk_window_clear_update_area:
4694 * @window: a #GdkWindow.
4696 * Internal function to clear the update area for a window. This
4697 * is called when the window is hidden or destroyed.
4700 _gdk_window_clear_update_area (GdkWindow *window)
4702 g_return_if_fail (GDK_IS_WINDOW (window));
4704 if (window->update_area)
4706 gdk_window_remove_update_window (window);
4708 cairo_region_destroy (window->update_area);
4709 window->update_area = NULL;
4714 * gdk_window_freeze_updates:
4715 * @window: a #GdkWindow
4717 * Temporarily freezes a window such that it won't receive expose
4718 * events. The window will begin receiving expose events again when
4719 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4720 * has been called more than once, gdk_window_thaw_updates() must be called
4721 * an equal number of times to begin processing exposes.
4724 gdk_window_freeze_updates (GdkWindow *window)
4726 GdkWindow *impl_window;
4728 g_return_if_fail (GDK_IS_WINDOW (window));
4730 impl_window = gdk_window_get_impl_window (window);
4731 impl_window->update_freeze_count++;
4735 * gdk_window_thaw_updates:
4736 * @window: a #GdkWindow
4738 * Thaws a window frozen with gdk_window_freeze_updates().
4741 gdk_window_thaw_updates (GdkWindow *window)
4743 GdkWindow *impl_window;
4745 g_return_if_fail (GDK_IS_WINDOW (window));
4747 impl_window = gdk_window_get_impl_window (window);
4749 g_return_if_fail (impl_window->update_freeze_count > 0);
4751 if (--impl_window->update_freeze_count == 0)
4752 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4756 * gdk_window_freeze_toplevel_updates_libgtk_only:
4757 * @window: a #GdkWindow
4759 * Temporarily freezes a window and all its descendants such that it won't
4760 * receive expose events. The window will begin receiving expose events
4761 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4762 * gdk_window_freeze_toplevel_updates_libgtk_only()
4763 * has been called more than once,
4764 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4765 * an equal number of times to begin processing exposes.
4767 * This function is not part of the GDK public API and is only
4771 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4773 g_return_if_fail (GDK_IS_WINDOW (window));
4774 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4776 window->update_and_descendants_freeze_count++;
4780 * gdk_window_thaw_toplevel_updates_libgtk_only:
4781 * @window: a #GdkWindow
4783 * Thaws a window frozen with
4784 * gdk_window_freeze_toplevel_updates_libgtk_only().
4786 * This function is not part of the GDK public API and is only
4790 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4792 g_return_if_fail (GDK_IS_WINDOW (window));
4793 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4794 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4796 window->update_and_descendants_freeze_count--;
4798 gdk_window_schedule_update (window);
4802 * gdk_window_set_debug_updates:
4803 * @setting: %TRUE to turn on update debugging
4805 * With update debugging enabled, calls to
4806 * gdk_window_invalidate_region() clear the invalidated region of the
4807 * screen to a noticeable color, and GDK pauses for a short time
4808 * before sending exposes to windows during
4809 * gdk_window_process_updates(). The net effect is that you can see
4810 * the invalid region for each window and watch redraws as they
4811 * occur. This allows you to diagnose inefficiencies in your application.
4813 * In essence, because the GDK rendering model prevents all flicker,
4814 * if you are redrawing the same region 400 times you may never
4815 * notice, aside from noticing a speed problem. Enabling update
4816 * debugging causes GTK to flicker slowly and noticeably, so you can
4817 * see exactly what's being redrawn when, in what order.
4819 * The --gtk-debug=updates command line option passed to GTK+ programs
4820 * enables this debug option at application startup time. That's
4821 * usually more useful than calling gdk_window_set_debug_updates()
4822 * yourself, though you might want to use this function to enable
4823 * updates sometime after application startup time.
4827 gdk_window_set_debug_updates (gboolean setting)
4829 debug_updates = setting;
4833 * gdk_window_constrain_size:
4834 * @geometry: a #GdkGeometry structure
4835 * @flags: a mask indicating what portions of @geometry are set
4836 * @width: desired width of window
4837 * @height: desired height of the window
4838 * @new_width: (out): location to store resulting width
4839 * @new_height: (out): location to store resulting height
4841 * Constrains a desired width and height according to a
4842 * set of geometry hints (such as minimum and maximum size).
4845 gdk_window_constrain_size (GdkGeometry *geometry,
4852 /* This routine is partially borrowed from fvwm.
4854 * Copyright 1993, Robert Nation
4855 * You may use this code for any purpose, as long as the original
4856 * copyright remains in the source code and all documentation
4858 * which in turn borrows parts of the algorithm from uwm
4861 gint min_height = 0;
4862 gint base_width = 0;
4863 gint base_height = 0;
4866 gint max_width = G_MAXINT;
4867 gint max_height = G_MAXINT;
4869 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4871 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4873 base_width = geometry->base_width;
4874 base_height = geometry->base_height;
4875 min_width = geometry->min_width;
4876 min_height = geometry->min_height;
4878 else if (flags & GDK_HINT_BASE_SIZE)
4880 base_width = geometry->base_width;
4881 base_height = geometry->base_height;
4882 min_width = geometry->base_width;
4883 min_height = geometry->base_height;
4885 else if (flags & GDK_HINT_MIN_SIZE)
4887 base_width = geometry->min_width;
4888 base_height = geometry->min_height;
4889 min_width = geometry->min_width;
4890 min_height = geometry->min_height;
4893 if (flags & GDK_HINT_MAX_SIZE)
4895 max_width = geometry->max_width ;
4896 max_height = geometry->max_height;
4899 if (flags & GDK_HINT_RESIZE_INC)
4901 xinc = MAX (xinc, geometry->width_inc);
4902 yinc = MAX (yinc, geometry->height_inc);
4905 /* clamp width and height to min and max values
4907 width = CLAMP (width, min_width, max_width);
4908 height = CLAMP (height, min_height, max_height);
4910 /* shrink to base + N * inc
4912 width = base_width + FLOOR (width - base_width, xinc);
4913 height = base_height + FLOOR (height - base_height, yinc);
4915 /* constrain aspect ratio, according to:
4918 * min_aspect <= -------- <= max_aspect
4922 if (flags & GDK_HINT_ASPECT &&
4923 geometry->min_aspect > 0 &&
4924 geometry->max_aspect > 0)
4928 if (geometry->min_aspect * height > width)
4930 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4931 if (height - delta >= min_height)
4935 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4936 if (width + delta <= max_width)
4941 if (geometry->max_aspect * height < width)
4943 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4944 if (width - delta >= min_width)
4948 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4949 if (height + delta <= max_height)
4958 *new_height = height;
4962 * gdk_window_get_pointer:
4963 * @window: a #GdkWindow
4964 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4965 * return the X coordinate
4966 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4967 * return the Y coordinate
4968 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4971 * Obtains the current pointer position and modifier state.
4972 * The position is given in coordinates relative to the upper left
4973 * corner of @window.
4975 * Return value: (transfer none): the window containing the pointer (as with
4976 * gdk_window_at_pointer()), or %NULL if the window containing the
4977 * pointer isn't known to GDK
4979 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4982 gdk_window_get_pointer (GdkWindow *window,
4985 GdkModifierType *mask)
4987 GdkDisplay *display;
4989 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4991 display = gdk_window_get_display (window);
4993 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
4997 * gdk_window_get_device_position:
4998 * @window: a #GdkWindow.
4999 * @device: pointer #GdkDevice to query to.
5000 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5001 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5002 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5004 * Obtains the current device position and modifier state.
5005 * The position is given in coordinates relative to the upper left
5006 * corner of @window.
5008 * Return value: (transfer none): The window underneath @device (as with
5009 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
5014 gdk_window_get_device_position (GdkWindow *window,
5018 GdkModifierType *mask)
5021 GdkModifierType tmp_mask;
5022 gboolean normal_child;
5024 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5025 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5026 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
5028 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
5032 /* We got the coords on the impl, convert to the window */
5033 tmp_x -= window->abs_x;
5034 tmp_y -= window->abs_y;
5043 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
5046 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5051 * gdk_get_default_root_window:
5053 * Obtains the root window (parent all other windows are inside)
5054 * for the default display and screen.
5056 * Return value: (transfer none): the default root window
5059 gdk_get_default_root_window (void)
5061 return gdk_screen_get_root_window (gdk_screen_get_default ());
5065 get_all_native_children (GdkWindow *window,
5071 for (l = window->children; l != NULL; l = l->next)
5075 if (gdk_window_has_impl (child))
5076 *native = g_list_prepend (*native, child);
5078 get_all_native_children (child, native);
5084 gdk_window_raise_internal (GdkWindow *window)
5086 GdkWindow *parent = window->parent;
5088 GList *native_children;
5090 GdkWindowImplClass *impl_class;
5094 parent->children = g_list_remove (parent->children, window);
5095 parent->children = g_list_prepend (parent->children, window);
5098 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5099 /* Just do native raise for toplevels */
5100 if (gdk_window_is_toplevel (window) ||
5101 /* The restack_under codepath should work correctly even if the parent
5102 is native, but it relies on the order of ->children to be correct,
5103 and some apps like SWT reorder the x windows without gdks knowledge,
5104 so we use raise directly in order to make these behave as before
5105 when using native windows */
5106 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5108 impl_class->raise (window);
5110 else if (gdk_window_has_impl (window))
5112 above = find_native_sibling_above (parent, window);
5115 listhead.data = window;
5116 listhead.next = NULL;
5117 listhead.prev = NULL;
5118 impl_class->restack_under ((GdkWindow *)above,
5122 impl_class->raise (window);
5126 native_children = NULL;
5127 get_all_native_children (window, &native_children);
5128 if (native_children != NULL)
5130 above = find_native_sibling_above (parent, window);
5133 impl_class->restack_under (above, native_children);
5136 /* Right order, since native_children is bottom-topmost first */
5137 for (l = native_children; l != NULL; l = l->next)
5138 impl_class->raise (l->data);
5141 g_list_free (native_children);
5147 /* Returns TRUE If the native window was mapped or unmapped */
5149 set_viewable (GdkWindow *w,
5153 GdkWindowImplClass *impl_class;
5156 if (w->viewable == val)
5162 recompute_visible_regions (w, FALSE, FALSE);
5164 for (l = w->children; l != NULL; l = l->next)
5168 if (GDK_WINDOW_IS_MAPPED (child) &&
5169 child->window_type != GDK_WINDOW_FOREIGN)
5170 set_viewable (child, val);
5173 if (gdk_window_has_impl (w) &&
5174 w->window_type != GDK_WINDOW_FOREIGN &&
5175 !gdk_window_is_toplevel (w))
5177 /* For most native windows we show/hide them not when they are
5178 * mapped/unmapped, because that may not produce the correct results.
5179 * For instance, if a native window have a non-native parent which is
5180 * hidden, but its native parent is viewable then showing the window
5181 * would make it viewable to X but its not viewable wrt the non-native
5182 * hierarchy. In order to handle this we track the gdk side viewability
5183 * and only map really viewable windows.
5185 * There are two exceptions though:
5187 * For foreign windows we don't want ever change the mapped state
5188 * except when explicitly done via gdk_window_show/hide, as this may
5189 * cause problems for client owning the foreign window when its window
5190 * is suddenly mapped or unmapped.
5192 * For toplevel windows embedded in a foreign window (e.g. a plug)
5193 * we sometimes synthesize a map of a window, but the native
5194 * window is really shown by the embedder, so we don't want to
5195 * do the show ourselves. We can't really tell this case from the normal
5196 * toplevel show as such toplevels are seen by gdk as parents of the
5197 * root window, so we make an exception for all toplevels.
5200 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5202 impl_class->show ((GdkWindow *)w, FALSE);
5204 impl_class->hide ((GdkWindow *)w);
5212 /* Returns TRUE If the native window was mapped or unmapped */
5214 _gdk_window_update_viewable (GdkWindow *window)
5218 if (window->window_type == GDK_WINDOW_FOREIGN ||
5219 window->window_type == GDK_WINDOW_ROOT)
5221 else if (gdk_window_is_toplevel (window) ||
5222 window->parent->viewable)
5223 viewable = GDK_WINDOW_IS_MAPPED (window);
5227 return set_viewable (window, viewable);
5231 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5233 GdkWindowImplClass *impl_class;
5234 gboolean was_mapped, was_viewable;
5237 g_return_if_fail (GDK_IS_WINDOW (window));
5239 if (window->destroyed)
5242 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5243 was_viewable = window->viewable;
5246 /* Keep children in (reverse) stacking order */
5247 gdk_window_raise_internal (window);
5249 if (gdk_window_has_impl (window))
5252 gdk_synthesize_window_state (window,
5253 GDK_WINDOW_STATE_WITHDRAWN,
5254 GDK_WINDOW_STATE_FOCUSED);
5261 did_show = _gdk_window_update_viewable (window);
5263 /* If it was already viewable the backend show op won't be called, call it
5264 again to ensure things happen right if the mapped tracking was not right
5265 for e.g. a foreign window.
5266 Dunno if this is strictly needed but its what happened pre-csw.
5267 Also show if not done by gdk_window_update_viewable. */
5268 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5270 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5271 impl_class->show (window, !did_show ? was_mapped : TRUE);
5274 if (!was_mapped && !gdk_window_has_impl (window))
5276 if (window->event_mask & GDK_STRUCTURE_MASK)
5277 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5279 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5280 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5283 if (!was_mapped || raise)
5285 recompute_visible_regions (window, TRUE, FALSE);
5287 /* If any decendants became visible we need to send visibility notify */
5288 gdk_window_update_visibility_recursively (window, NULL);
5290 if (gdk_window_is_viewable (window))
5292 _gdk_synthesize_crossing_events_for_geometry_change (window);
5293 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5299 * gdk_window_show_unraised:
5300 * @window: a #GdkWindow
5302 * Shows a #GdkWindow onscreen, but does not modify its stacking
5303 * order. In contrast, gdk_window_show() will raise the window
5304 * to the top of the window stack.
5306 * On the X11 platform, in Xlib terms, this function calls
5307 * XMapWindow() (it also updates some internal GDK state, which means
5308 * that you can't really use XMapWindow() directly on a GDK window).
5311 gdk_window_show_unraised (GdkWindow *window)
5313 gdk_window_show_internal (window, FALSE);
5318 * @window: a #GdkWindow
5320 * Raises @window to the top of the Z-order (stacking order), so that
5321 * other windows with the same parent window appear below @window.
5322 * This is true whether or not the windows are visible.
5324 * If @window is a toplevel, the window manager may choose to deny the
5325 * request to move the window in the Z-order, gdk_window_raise() only
5326 * requests the restack, does not guarantee it.
5329 gdk_window_raise (GdkWindow *window)
5331 g_return_if_fail (GDK_IS_WINDOW (window));
5333 if (window->destroyed)
5336 gdk_window_flush_if_exposing (window);
5338 /* Keep children in (reverse) stacking order */
5339 gdk_window_raise_internal (window);
5341 recompute_visible_regions (window, TRUE, FALSE);
5343 if (gdk_window_is_viewable (window) &&
5344 !window->input_only)
5345 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5349 gdk_window_lower_internal (GdkWindow *window)
5351 GdkWindow *parent = window->parent;
5352 GdkWindowImplClass *impl_class;
5354 GList *native_children;
5359 parent->children = g_list_remove (parent->children, window);
5360 parent->children = g_list_append (parent->children, window);
5363 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5364 /* Just do native lower for toplevels */
5365 if (gdk_window_is_toplevel (window) ||
5366 /* The restack_under codepath should work correctly even if the parent
5367 is native, but it relies on the order of ->children to be correct,
5368 and some apps like SWT reorder the x windows without gdks knowledge,
5369 so we use lower directly in order to make these behave as before
5370 when using native windows */
5371 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5373 impl_class->lower (window);
5375 else if (gdk_window_has_impl (window))
5377 above = find_native_sibling_above (parent, window);
5380 listhead.data = window;
5381 listhead.next = NULL;
5382 listhead.prev = NULL;
5383 impl_class->restack_under ((GdkWindow *)above, &listhead);
5386 impl_class->raise (window);
5390 native_children = NULL;
5391 get_all_native_children (window, &native_children);
5392 if (native_children != NULL)
5394 above = find_native_sibling_above (parent, window);
5397 impl_class->restack_under ((GdkWindow *)above,
5401 /* Right order, since native_children is bottom-topmost first */
5402 for (l = native_children; l != NULL; l = l->next)
5403 impl_class->raise (l->data);
5406 g_list_free (native_children);
5413 gdk_window_invalidate_in_parent (GdkWindow *private)
5415 GdkRectangle r, child;
5417 if (gdk_window_is_toplevel (private))
5420 /* get the visible rectangle of the parent */
5422 r.width = private->parent->width;
5423 r.height = private->parent->height;
5425 child.x = private->x;
5426 child.y = private->y;
5427 child.width = private->width;
5428 child.height = private->height;
5429 gdk_rectangle_intersect (&r, &child, &r);
5431 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5437 * @window: a #GdkWindow
5439 * Lowers @window to the bottom of the Z-order (stacking order), so that
5440 * other windows with the same parent window appear above @window.
5441 * This is true whether or not the other windows are visible.
5443 * If @window is a toplevel, the window manager may choose to deny the
5444 * request to move the window in the Z-order, gdk_window_lower() only
5445 * requests the restack, does not guarantee it.
5447 * Note that gdk_window_show() raises the window again, so don't call this
5448 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5451 gdk_window_lower (GdkWindow *window)
5453 g_return_if_fail (GDK_IS_WINDOW (window));
5455 if (window->destroyed)
5458 gdk_window_flush_if_exposing (window);
5460 /* Keep children in (reverse) stacking order */
5461 gdk_window_lower_internal (window);
5463 recompute_visible_regions (window, TRUE, FALSE);
5465 _gdk_synthesize_crossing_events_for_geometry_change (window);
5466 gdk_window_invalidate_in_parent (window);
5470 * gdk_window_restack:
5471 * @window: a #GdkWindow
5472 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5475 * Changes the position of @window in the Z-order (stacking order), so that
5476 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5479 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5480 * lowers the window.
5482 * If @window is a toplevel, the window manager may choose to deny the
5483 * request to move the window in the Z-order, gdk_window_restack() only
5484 * requests the restack, does not guarantee it.
5489 gdk_window_restack (GdkWindow *window,
5493 GdkWindowImplClass *impl_class;
5495 GdkWindow *above_native;
5496 GList *sibling_link;
5497 GList *native_children;
5500 g_return_if_fail (GDK_IS_WINDOW (window));
5501 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5503 if (window->destroyed)
5506 if (sibling == NULL)
5509 gdk_window_raise (window);
5511 gdk_window_lower (window);
5515 gdk_window_flush_if_exposing (window);
5517 if (gdk_window_is_toplevel (window))
5519 g_return_if_fail (gdk_window_is_toplevel (sibling));
5520 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5521 impl_class->restack_toplevel (window, sibling, above);
5525 parent = window->parent;
5528 sibling_link = g_list_find (parent->children, sibling);
5529 g_return_if_fail (sibling_link != NULL);
5530 if (sibling_link == NULL)
5533 parent->children = g_list_remove (parent->children, window);
5535 parent->children = g_list_insert_before (parent->children,
5539 parent->children = g_list_insert_before (parent->children,
5543 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5544 if (gdk_window_has_impl (window))
5546 above_native = find_native_sibling_above (parent, window);
5549 listhead.data = window;
5550 listhead.next = NULL;
5551 listhead.prev = NULL;
5552 impl_class->restack_under (above_native, &listhead);
5555 impl_class->raise (window);
5559 native_children = NULL;
5560 get_all_native_children (window, &native_children);
5561 if (native_children != NULL)
5563 above_native = find_native_sibling_above (parent, window);
5565 impl_class->restack_under (above_native,
5569 /* Right order, since native_children is bottom-topmost first */
5570 for (l = native_children; l != NULL; l = l->next)
5571 impl_class->raise (l->data);
5574 g_list_free (native_children);
5579 recompute_visible_regions (window, TRUE, FALSE);
5581 _gdk_synthesize_crossing_events_for_geometry_change (window);
5582 gdk_window_invalidate_in_parent (window);
5588 * @window: a #GdkWindow
5590 * Like gdk_window_show_unraised(), but also raises the window to the
5591 * top of the window stack (moves the window to the front of the
5594 * This function maps a window so it's visible onscreen. Its opposite
5595 * is gdk_window_hide().
5597 * When implementing a #GtkWidget, you should call this function on the widget's
5598 * #GdkWindow as part of the "map" method.
5601 gdk_window_show (GdkWindow *window)
5603 gdk_window_show_internal (window, TRUE);
5608 * @window: a #GdkWindow
5610 * For toplevel windows, withdraws them, so they will no longer be
5611 * known to the window manager; for all windows, unmaps them, so
5612 * they won't be displayed. Normally done automatically as
5613 * part of gtk_widget_hide().
5616 gdk_window_hide (GdkWindow *window)
5618 GdkWindowImplClass *impl_class;
5619 gboolean was_mapped, did_hide;
5621 g_return_if_fail (GDK_IS_WINDOW (window));
5623 if (window->destroyed)
5626 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5628 if (gdk_window_has_impl (window))
5631 if (GDK_WINDOW_IS_MAPPED (window))
5632 gdk_synthesize_window_state (window,
5634 GDK_WINDOW_STATE_WITHDRAWN);
5636 else if (was_mapped)
5638 GdkDisplay *display;
5639 GdkDeviceManager *device_manager;
5642 /* May need to break grabs on children */
5643 display = gdk_window_get_display (window);
5644 device_manager = gdk_display_get_device_manager (display);
5646 /* Get all devices */
5647 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5648 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5649 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5651 for (d = devices; d; d = d->next)
5653 GdkDevice *device = d->data;
5655 if (_gdk_display_end_device_grab (display,
5657 _gdk_display_get_next_serial (display),
5660 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5663 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5664 g_list_free (devices);
5667 did_hide = _gdk_window_update_viewable (window);
5669 /* Hide foreign window as those are not handled by update_viewable. */
5670 if (gdk_window_has_impl (window) && (!did_hide))
5672 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5673 impl_class->hide (window);
5676 recompute_visible_regions (window, TRUE, FALSE);
5678 /* all decendants became non-visible, we need to send visibility notify */
5679 gdk_window_update_visibility_recursively (window, NULL);
5681 if (was_mapped && !gdk_window_has_impl (window))
5683 if (window->event_mask & GDK_STRUCTURE_MASK)
5684 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5686 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5687 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5689 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5692 /* Invalidate the rect */
5694 gdk_window_invalidate_in_parent (window);
5698 * gdk_window_withdraw:
5699 * @window: a toplevel #GdkWindow
5701 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5702 * This function is not really useful as gdk_window_hide() automatically
5703 * withdraws toplevel windows before hiding them.
5706 gdk_window_withdraw (GdkWindow *window)
5708 GdkWindowImplClass *impl_class;
5709 gboolean was_mapped;
5711 g_return_if_fail (GDK_IS_WINDOW (window));
5713 if (window->destroyed)
5716 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5718 if (gdk_window_has_impl (window))
5720 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5721 impl_class->withdraw (window);
5725 if (window->event_mask & GDK_STRUCTURE_MASK)
5726 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5728 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5729 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5731 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5734 recompute_visible_regions (window, TRUE, FALSE);
5739 * gdk_window_set_events:
5740 * @window: a #GdkWindow
5741 * @event_mask: event mask for @window
5743 * The event mask for a window determines which events will be reported
5744 * for that window from all master input devices. For example, an event mask
5745 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5746 * press events. The event mask is the bitwise OR of values from the
5747 * #GdkEventMask enumeration.
5750 gdk_window_set_events (GdkWindow *window,
5751 GdkEventMask event_mask)
5753 GdkWindowImplClass *impl_class;
5754 GdkDisplay *display;
5756 g_return_if_fail (GDK_IS_WINDOW (window));
5758 if (window->destroyed)
5761 /* If motion hint is disabled, enable motion events again */
5762 display = gdk_window_get_display (window);
5763 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5764 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5766 GList *devices = window->devices_inside;
5770 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5771 devices = devices->next;
5775 window->event_mask = event_mask;
5777 if (gdk_window_has_impl (window))
5779 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5780 impl_class->set_events (window,
5781 get_native_event_mask (window));
5787 * gdk_window_get_events:
5788 * @window: a #GdkWindow
5790 * Gets the event mask for @window for all master input devices. See
5791 * gdk_window_set_events().
5793 * Return value: event mask for @window
5796 gdk_window_get_events (GdkWindow *window)
5798 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5800 if (window->destroyed)
5803 return window->event_mask;
5807 * gdk_window_set_device_events:
5808 * @window: a #GdkWindow
5809 * @device: #GdkDevice to enable events for.
5810 * @event_mask: event mask for @window
5812 * Sets the event mask for a given device (Normally a floating device, not
5813 * attached to any visible pointer) to @window. For example, an event mask
5814 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5815 * press events. The event mask is the bitwise OR of values from the
5816 * #GdkEventMask enumeration.
5821 gdk_window_set_device_events (GdkWindow *window,
5823 GdkEventMask event_mask)
5825 GdkEventMask device_mask;
5826 GdkDisplay *display;
5829 g_return_if_fail (GDK_IS_WINDOW (window));
5830 g_return_if_fail (GDK_IS_DEVICE (device));
5832 if (GDK_WINDOW_DESTROYED (window))
5835 /* If motion hint is disabled, enable motion events again */
5836 display = gdk_window_get_display (window);
5837 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5838 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5839 _gdk_display_enable_motion_hints (display, device);
5841 if (G_UNLIKELY (!window->device_events))
5842 window->device_events = g_hash_table_new (NULL, NULL);
5844 if (event_mask == 0)
5846 /* FIXME: unsetting events on a master device
5847 * would restore window->event_mask
5849 g_hash_table_remove (window->device_events, device);
5852 g_hash_table_insert (window->device_events, device,
5853 GINT_TO_POINTER (event_mask));
5855 native = gdk_window_get_toplevel (window);
5857 while (gdk_window_is_offscreen (native))
5859 native = gdk_offscreen_window_get_embedder (native);
5861 if (native == NULL ||
5862 (!_gdk_window_has_impl (native) &&
5863 !gdk_window_is_viewable (native)))
5866 native = gdk_window_get_toplevel (native);
5869 device_mask = get_native_device_event_mask (window, device);
5870 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5874 * gdk_window_get_device_events:
5875 * @window: a #GdkWindow.
5876 * @device: a #GdkDevice.
5878 * Returns the event mask for @window corresponding to an specific device.
5880 * Returns: device event mask for @window
5885 gdk_window_get_device_events (GdkWindow *window,
5890 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5891 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5893 if (GDK_WINDOW_DESTROYED (window))
5896 if (!window->device_events)
5899 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5901 /* FIXME: device could be controlled by window->event_mask */
5907 gdk_window_move_resize_toplevel (GdkWindow *window,
5914 cairo_region_t *old_region, *new_region;
5915 GdkWindowImplClass *impl_class;
5922 is_resize = (width != -1) || (height != -1);
5924 if (gdk_window_is_viewable (window) &&
5925 !window->input_only)
5928 old_region = cairo_region_copy (window->clip_region);
5931 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5932 impl_class->move_resize (window, with_move, x, y, width, height);
5934 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5936 recompute_visible_regions (window, TRUE, FALSE);
5940 new_region = cairo_region_copy (window->clip_region);
5942 /* This is the newly exposed area (due to any resize),
5943 * X will expose it, but lets do that without the roundtrip
5945 cairo_region_subtract (new_region, old_region);
5946 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
5948 cairo_region_destroy (old_region);
5949 cairo_region_destroy (new_region);
5952 _gdk_synthesize_crossing_events_for_geometry_change (window);
5957 move_native_children (GdkWindow *private)
5961 GdkWindowImplClass *impl_class;
5963 for (l = private->children; l; l = l->next)
5967 if (child->impl != private->impl)
5969 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
5970 impl_class->move_resize (child, TRUE,
5972 child->width, child->height);
5975 move_native_children (child);
5980 collect_native_child_region_helper (GdkWindow *window,
5981 GdkWindowImpl *impl,
5982 cairo_region_t **region,
5987 cairo_region_t *tmp;
5990 for (l = window->children; l != NULL; l = l->next)
5994 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
5997 if (child->impl != impl)
5999 tmp = cairo_region_copy (child->clip_region);
6000 cairo_region_translate (tmp,
6001 x_offset + child->x,
6002 y_offset + child->y);
6003 if (*region == NULL)
6007 cairo_region_union (*region, tmp);
6008 cairo_region_destroy (tmp);
6012 collect_native_child_region_helper (child, impl, region,
6013 x_offset + child->x,
6014 y_offset + child->y);
6020 static cairo_region_t *
6021 collect_native_child_region (GdkWindow *window,
6022 gboolean include_this)
6024 cairo_region_t *region;
6026 if (include_this && gdk_window_has_impl (window) && window->viewable)
6027 return cairo_region_copy (window->clip_region);
6031 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6038 gdk_window_move_resize_internal (GdkWindow *window,
6045 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
6046 cairo_region_t *old_native_child_region, *new_native_child_region;
6047 GdkWindow *impl_window;
6048 GdkWindowImplClass *impl_class;
6050 int old_x, old_y, old_abs_x, old_abs_y;
6053 g_return_if_fail (GDK_IS_WINDOW (window));
6055 if (window->destroyed)
6058 if (gdk_window_is_toplevel (window))
6060 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6064 /* Bail early if no change */
6065 if (window->width == width &&
6066 window->height == height &&
6072 gdk_window_flush_if_exposing (window);
6074 /* Handle child windows */
6080 impl_window = gdk_window_get_impl_window (window);
6085 old_native_child_region = NULL;
6086 if (gdk_window_is_viewable (window) &&
6087 !window->input_only)
6091 old_region = cairo_region_copy (window->clip_region);
6092 old_layered = cairo_region_copy (window->layered_region);
6093 /* Adjust regions to parent window coords */
6094 cairo_region_translate (old_region, window->x, window->y);
6095 cairo_region_translate (old_layered, window->x, window->y);
6097 old_native_child_region = collect_native_child_region (window, TRUE);
6098 if (old_native_child_region)
6100 /* Adjust region to parent window coords */
6101 cairo_region_translate (old_native_child_region, window->x, window->y);
6103 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6104 * source or destination for a delayed GdkWindowRegionMove. So, we need
6105 * to flush those here for the parent window and all overlapped subwindows
6106 * of it. And we need to do this before setting the new clips as those will be
6109 gdk_window_flush_recursive (window->parent);
6113 /* Set the new position and size */
6119 if (!(width < 0 && height < 0))
6123 window->width = width;
6126 window->height = height;
6129 dx = window->x - old_x;
6130 dy = window->y - old_y;
6132 old_abs_x = window->abs_x;
6133 old_abs_y = window->abs_y;
6135 recompute_visible_regions (window, TRUE, FALSE);
6137 new_native_child_region = NULL;
6138 if (old_native_child_region)
6140 new_native_child_region = collect_native_child_region (window, TRUE);
6141 /* Adjust region to parent window coords */
6142 cairo_region_translate (new_native_child_region, window->x, window->y);
6145 if (gdk_window_has_impl (window))
6147 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6149 /* Do the actual move after recomputing things, as this will have set the shape to
6150 the now correct one, thus avoiding copying regions that should not be copied. */
6151 impl_class->move_resize (window, TRUE,
6152 window->x, window->y,
6153 window->width, window->height);
6155 else if (old_abs_x != window->abs_x ||
6156 old_abs_y != window->abs_y)
6157 move_native_children (window);
6161 new_region = cairo_region_copy (window->clip_region);
6162 /* Adjust region to parent window coords */
6163 cairo_region_translate (new_region, window->x, window->y);
6166 * Part of the data at the new location can be copied from the
6167 * old location, this area is the intersection of the old region
6168 * moved as the copy will move it and then intersected with
6172 * Everything in the old and new regions that is not copied must be
6173 * invalidated (including children) as this is newly exposed
6175 if (window->has_alpha_background)
6176 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6178 copy_area = cairo_region_copy (new_region);
6180 /* Don't copy from a previously layered region */
6181 cairo_region_translate (old_layered, dx, dy);
6182 cairo_region_subtract (copy_area, old_layered);
6184 /* Don't copy into a layered region */
6185 cairo_region_translate (copy_area, -window->x, -window->y);
6186 cairo_region_subtract (copy_area, window->layered_region);
6187 cairo_region_translate (copy_area, window->x, window->y);
6189 cairo_region_union (new_region, old_region);
6191 if (old_native_child_region)
6193 /* Don't copy from inside native children, as this is copied by
6194 * the native window move.
6196 cairo_region_subtract (old_region, old_native_child_region);
6198 cairo_region_translate (old_region, dx, dy);
6200 cairo_region_intersect (copy_area, old_region);
6202 if (new_native_child_region)
6204 /* Don't copy any bits that would cause a read from the moved
6205 native windows, as we can't read that data */
6206 cairo_region_translate (new_native_child_region, dx, dy);
6207 cairo_region_subtract (copy_area, new_native_child_region);
6208 cairo_region_translate (new_native_child_region, -dx, -dy);
6211 cairo_region_subtract (new_region, copy_area);
6213 /* Convert old region to impl coords */
6214 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6216 /* convert from parent coords to impl */
6217 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6219 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6221 /* Invalidate affected part in the parent window
6222 * (no higher window should be affected)
6223 * We also invalidate any children in that area, which could include
6224 * this window if it still overlaps that area.
6226 if (old_native_child_region)
6228 /* No need to expose the region that the native window move copies */
6229 cairo_region_translate (old_native_child_region, dx, dy);
6230 cairo_region_intersect (old_native_child_region, new_native_child_region);
6231 cairo_region_subtract (new_region, old_native_child_region);
6233 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6235 cairo_region_destroy (old_region);
6236 cairo_region_destroy (old_layered);
6237 cairo_region_destroy (new_region);
6240 if (old_native_child_region)
6242 cairo_region_destroy (old_native_child_region);
6243 cairo_region_destroy (new_native_child_region);
6246 _gdk_synthesize_crossing_events_for_geometry_change (window);
6253 * @window: a #GdkWindow
6254 * @x: X coordinate relative to window's parent
6255 * @y: Y coordinate relative to window's parent
6257 * Repositions a window relative to its parent window.
6258 * For toplevel windows, window managers may ignore or modify the move;
6259 * you should probably use gtk_window_move() on a #GtkWindow widget
6260 * anyway, instead of using GDK functions. For child windows,
6261 * the move will reliably succeed.
6263 * If you're also planning to resize the window, use gdk_window_move_resize()
6264 * to both move and resize simultaneously, for a nicer visual effect.
6267 gdk_window_move (GdkWindow *window,
6271 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6275 * gdk_window_resize:
6276 * @window: a #GdkWindow
6277 * @width: new width of the window
6278 * @height: new height of the window
6280 * Resizes @window; for toplevel windows, asks the window manager to resize
6281 * the window. The window manager may not allow the resize. When using GTK+,
6282 * use gtk_window_resize() instead of this low-level GDK function.
6284 * Windows may not be resized below 1x1.
6286 * If you're also planning to move the window, use gdk_window_move_resize()
6287 * to both move and resize simultaneously, for a nicer visual effect.
6290 gdk_window_resize (GdkWindow *window,
6294 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6299 * gdk_window_move_resize:
6300 * @window: a #GdkWindow
6301 * @x: new X position relative to window's parent
6302 * @y: new Y position relative to window's parent
6304 * @height: new height
6306 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6307 * except that both operations are performed at once, avoiding strange
6308 * visual effects. (i.e. the user may be able to see the window first
6309 * move, then resize, if you don't use gdk_window_move_resize().)
6312 gdk_window_move_resize (GdkWindow *window,
6318 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6323 * gdk_window_scroll:
6324 * @window: a #GdkWindow
6325 * @dx: Amount to scroll in the X direction
6326 * @dy: Amount to scroll in the Y direction
6328 * Scroll the contents of @window, both pixels and children, by the
6329 * given amount. @window itself does not move. Portions of the window
6330 * that the scroll operation brings in from offscreen areas are
6331 * invalidated. The invalidated region may be bigger than what would
6332 * strictly be necessary.
6334 * For X11, a minimum area will be invalidated if the window has no
6335 * subwindows, or if the edges of the window's parent do not extend
6336 * beyond the edges of the window. In other cases, a multi-step process
6337 * is used to scroll the window which may produce temporary visual
6338 * artifacts and unnecessary invalidations.
6341 gdk_window_scroll (GdkWindow *window,
6345 GdkWindow *impl_window;
6346 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6347 cairo_region_t *old_native_child_region, *new_native_child_region;
6350 g_return_if_fail (GDK_IS_WINDOW (window));
6352 if (dx == 0 && dy == 0)
6355 if (window->destroyed)
6358 gdk_window_flush_if_exposing (window);
6360 old_layered_area = cairo_region_copy (window->layered_region);
6361 old_native_child_region = collect_native_child_region (window, FALSE);
6362 if (old_native_child_region)
6364 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6365 * source or destination for a delayed GdkWindowRegionMove. So, we need
6366 * to flush those here for the window and all overlapped subwindows
6367 * of it. And we need to do this before setting the new clips as those will be
6370 gdk_window_flush_recursive (window);
6374 /* First move all child windows, without causing invalidation */
6376 tmp_list = window->children;
6379 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6381 /* Just update the positions, the bits will move with the copy */
6385 tmp_list = tmp_list->next;
6388 recompute_visible_regions (window, FALSE, TRUE);
6390 new_native_child_region = NULL;
6391 if (old_native_child_region)
6392 new_native_child_region = collect_native_child_region (window, FALSE);
6394 move_native_children (window);
6396 /* Then copy the actual bits of the window w/ child windows */
6398 impl_window = gdk_window_get_impl_window (window);
6400 /* Calculate the area that can be gotten by copying the old area */
6401 if (window->has_alpha_background)
6402 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6404 copy_area = cairo_region_copy (window->clip_region);
6405 cairo_region_subtract (copy_area, old_layered_area);
6406 if (old_native_child_region)
6408 /* Don't copy from inside native children, as this is copied by
6409 * the native window move.
6411 cairo_region_subtract (copy_area, old_native_child_region);
6413 /* Don't copy any bits that would cause a read from the moved
6414 native windows, as we can't read that data */
6415 cairo_region_subtract (copy_area, new_native_child_region);
6417 cairo_region_translate (copy_area, dx, dy);
6418 cairo_region_intersect (copy_area, window->clip_region);
6419 cairo_region_subtract (copy_area, window->layered_region);
6421 /* And the rest need to be invalidated */
6422 noncopy_area = cairo_region_copy (window->clip_region);
6423 cairo_region_subtract (noncopy_area, copy_area);
6425 /* convert from window coords to impl */
6426 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6428 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6430 /* Invalidate not copied regions */
6431 if (old_native_child_region)
6433 /* No need to expose the region that the native window move copies */
6434 cairo_region_translate (old_native_child_region, dx, dy);
6435 cairo_region_intersect (old_native_child_region, new_native_child_region);
6436 cairo_region_subtract (noncopy_area, old_native_child_region);
6438 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6440 cairo_region_destroy (noncopy_area);
6441 cairo_region_destroy (old_layered_area);
6443 if (old_native_child_region)
6445 cairo_region_destroy (old_native_child_region);
6446 cairo_region_destroy (new_native_child_region);
6449 _gdk_synthesize_crossing_events_for_geometry_change (window);
6453 * gdk_window_move_region:
6454 * @window: a #GdkWindow
6455 * @region: The #cairo_region_t to move
6456 * @dx: Amount to move in the X direction
6457 * @dy: Amount to move in the Y direction
6459 * Move the part of @window indicated by @region by @dy pixels in the Y
6460 * direction and @dx pixels in the X direction. The portions of @region
6461 * that not covered by the new position of @region are invalidated.
6463 * Child windows are not moved.
6468 gdk_window_move_region (GdkWindow *window,
6469 const cairo_region_t *region,
6473 GdkWindow *impl_window;
6474 cairo_region_t *nocopy_area;
6475 cairo_region_t *copy_area;
6477 g_return_if_fail (GDK_IS_WINDOW (window));
6478 g_return_if_fail (region != NULL);
6480 if (dx == 0 && dy == 0)
6483 if (window->destroyed)
6486 impl_window = gdk_window_get_impl_window (window);
6488 /* compute source regions */
6489 if (window->has_alpha_background)
6490 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6492 copy_area = cairo_region_copy (region);
6493 cairo_region_intersect (copy_area, window->clip_region_with_children);
6494 cairo_region_subtract (copy_area, window->layered_region);
6495 remove_layered_child_area (window, copy_area);
6497 /* compute destination regions */
6498 cairo_region_translate (copy_area, dx, dy);
6499 cairo_region_intersect (copy_area, window->clip_region_with_children);
6500 cairo_region_subtract (copy_area, window->layered_region);
6501 remove_layered_child_area (window, copy_area);
6503 /* Invalidate parts of the region (source and dest) not covered
6505 nocopy_area = cairo_region_copy (region);
6506 cairo_region_translate (nocopy_area, dx, dy);
6507 cairo_region_union (nocopy_area, region);
6508 cairo_region_subtract (nocopy_area, copy_area);
6510 /* convert from window coords to impl */
6511 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6512 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6514 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6515 cairo_region_destroy (nocopy_area);
6519 * gdk_window_set_background:
6520 * @window: a #GdkWindow
6521 * @color: a #GdkColor
6523 * Sets the background color of @window. (However, when using GTK+,
6524 * set the background of a widget with gtk_widget_modify_bg() - if
6525 * you're an application - or gtk_style_set_background() - if you're
6526 * implementing a custom widget.)
6528 * See also gdk_window_set_background_pattern().
6530 * Deprecated: 3.4: Use gdk_window_set_background_rgba() instead.
6533 gdk_window_set_background (GdkWindow *window,
6534 const GdkColor *color)
6536 cairo_pattern_t *pattern;
6538 g_return_if_fail (GDK_IS_WINDOW (window));
6540 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6541 color->green / 65535.,
6542 color->blue / 65535.);
6544 gdk_window_set_background_pattern (window, pattern);
6546 cairo_pattern_destroy (pattern);
6550 * gdk_window_set_background_rgba:
6551 * @window: a #GdkWindow
6552 * @rgba: a #GdkRGBA color
6554 * Sets the background color of @window.
6556 * See also gdk_window_set_background_pattern().
6559 gdk_window_set_background_rgba (GdkWindow *window,
6562 cairo_pattern_t *pattern;
6564 g_return_if_fail (GDK_IS_WINDOW (window));
6565 g_return_if_fail (rgba != NULL);
6567 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6568 rgba->blue, rgba->alpha);
6570 gdk_window_set_background_pattern (window, pattern);
6572 cairo_pattern_destroy (pattern);
6576 /* Updates has_alpha_background recursively for all child windows
6577 that have parent-relative alpha */
6579 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6584 for (l = window->children; l; l = l->next)
6588 if (child->background == NULL &&
6589 child->has_alpha_background != window->has_alpha_background)
6591 child->has_alpha_background = window->has_alpha_background;
6592 recompute_visible_regions (child, TRUE, FALSE);
6593 _gdk_window_propagate_has_alpha_background (child);
6599 * gdk_window_set_background_pattern:
6600 * @window: a #GdkWindow
6601 * @pattern: (allow-none): a pattern to use, or %NULL
6603 * Sets the background of @window.
6605 * A background of %NULL means that the window will inherit its
6606 * background form its parent window.
6608 * The windowing system will normally fill a window with its background
6609 * when the window is obscured then exposed.
6612 gdk_window_set_background_pattern (GdkWindow *window,
6613 cairo_pattern_t *pattern)
6616 cairo_pattern_type_t type;
6618 g_return_if_fail (GDK_IS_WINDOW (window));
6620 if (window->input_only)
6624 cairo_pattern_reference (pattern);
6625 if (window->background)
6626 cairo_pattern_destroy (window->background);
6627 window->background = pattern;
6631 if (pattern == NULL)
6633 /* parent-relative, copy has_alpha from parent */
6634 if (window->parent == NULL ||
6635 window->parent->window_type == GDK_WINDOW_ROOT)
6638 has_alpha = window->parent->has_alpha_background;
6642 type = cairo_pattern_get_type (pattern);
6644 if (type == CAIRO_PATTERN_TYPE_SOLID)
6647 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6651 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6652 type == CAIRO_PATTERN_TYPE_RADIAL)
6658 cairo_pattern_get_color_stop_count (pattern, &n);
6660 for (i = 0; i < n; i++)
6662 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6663 NULL, NULL, NULL, &alpha);
6671 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6673 cairo_surface_t *surface;
6674 cairo_content_t content;
6676 cairo_pattern_get_surface (pattern, &surface);
6677 content = cairo_surface_get_content (surface);
6679 (content == CAIRO_CONTENT_ALPHA) ||
6680 (content == CAIRO_CONTENT_COLOR_ALPHA);
6684 if (has_alpha != window->has_alpha_background)
6686 window->has_alpha_background = has_alpha;
6687 recompute_visible_regions (window, TRUE, FALSE);
6689 _gdk_window_propagate_has_alpha_background (window);
6692 if (gdk_window_has_impl (window))
6694 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6695 impl_class->set_background (window, pattern);
6698 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6702 * gdk_window_get_background_pattern:
6705 * Gets the pattern used to clear the background on @window. If @window
6706 * does not have its own background and reuses the parent's, %NULL is
6707 * returned and you'll have to query it yourself.
6709 * Returns: (transfer none): The pattern to use for the background or
6710 * %NULL to use the parent's background.
6715 gdk_window_get_background_pattern (GdkWindow *window)
6717 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6719 return window->background;
6723 gdk_window_set_cursor_internal (GdkWindow *window,
6727 if (GDK_WINDOW_DESTROYED (window))
6730 if (window->window_type == GDK_WINDOW_ROOT ||
6731 window->window_type == GDK_WINDOW_FOREIGN)
6732 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6735 GdkPointerWindowInfo *pointer_info;
6736 GdkDisplay *display;
6738 display = gdk_window_get_display (window);
6739 pointer_info = _gdk_display_get_pointer_info (display, device);
6741 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6742 update_cursor (display, device);
6747 * gdk_window_get_cursor:
6748 * @window: a #GdkWindow
6750 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6751 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6752 * there is no custom cursor set on the specified window, and it is
6753 * using the cursor for its parent window.
6755 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6756 * object is owned by the #GdkWindow and should not be unreferenced
6757 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6763 gdk_window_get_cursor (GdkWindow *window)
6765 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6767 return window->cursor;
6771 * gdk_window_set_cursor:
6772 * @window: a #GdkWindow
6773 * @cursor: (allow-none): a cursor
6775 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6776 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6777 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6778 * to gdk_window_set_cursor() means that @window will use the cursor of its
6779 * parent window. Most windows should use this default.
6782 gdk_window_set_cursor (GdkWindow *window,
6785 GdkDisplay *display;
6787 g_return_if_fail (GDK_IS_WINDOW (window));
6789 display = gdk_window_get_display (window);
6793 g_object_unref (window->cursor);
6794 window->cursor = NULL;
6797 if (!GDK_WINDOW_DESTROYED (window))
6799 GdkDeviceManager *device_manager;
6803 window->cursor = g_object_ref (cursor);
6805 device_manager = gdk_display_get_device_manager (display);
6806 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6808 for (d = devices; d; d = d->next)
6814 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6817 gdk_window_set_cursor_internal (window, device, window->cursor);
6820 g_list_free (devices);
6821 g_object_notify (G_OBJECT (window), "cursor");
6826 * gdk_window_get_device_cursor:
6827 * @window: a #GdkWindow.
6828 * @device: a master, pointer #GdkDevice.
6830 * Retrieves a #GdkCursor pointer for the @device currently set on the
6831 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6832 * there is no custom cursor set on the specified window, and it is
6833 * using the cursor for its parent window.
6835 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6836 * object is owned by the #GdkWindow and should not be unreferenced
6837 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6843 gdk_window_get_device_cursor (GdkWindow *window,
6846 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6847 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6848 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6849 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6851 return g_hash_table_lookup (window->device_cursor, device);
6855 * gdk_window_set_device_cursor:
6856 * @window: a #Gdkwindow
6857 * @device: a master, pointer #GdkDevice
6858 * @cursor: a #GdkCursor
6860 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6861 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6862 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6863 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6864 * @window will use the cursor of its parent window. Most windows should
6870 gdk_window_set_device_cursor (GdkWindow *window,
6874 g_return_if_fail (GDK_IS_WINDOW (window));
6875 g_return_if_fail (GDK_IS_DEVICE (device));
6876 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6877 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6880 g_hash_table_remove (window->device_cursor, device);
6882 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6884 gdk_window_set_cursor_internal (window, device, cursor);
6888 * gdk_window_get_geometry:
6889 * @window: a #GdkWindow
6890 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6891 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6892 * @width: (out) (allow-none): return location for width of window
6893 * @height: (out) (allow-none): return location for height of window
6895 * Any of the return location arguments to this function may be %NULL,
6896 * if you aren't interested in getting the value of that field.
6898 * The X and Y coordinates returned are relative to the parent window
6899 * of @window, which for toplevels usually means relative to the
6900 * window decorations (titlebar, etc.) rather than relative to the
6901 * root window (screen-size background window).
6903 * On the X11 platform, the geometry is obtained from the X server,
6904 * so reflects the latest position of @window; this may be out-of-sync
6905 * with the position of @window delivered in the most-recently-processed
6906 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6907 * position from the most recent configure event.
6910 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6911 * to call gdk_window_get_position(), gdk_window_get_width() and
6912 * gdk_window_get_height() instead, because it avoids the roundtrip to
6913 * the X server and because these functions support the full 32-bit
6914 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6915 * the 16-bit coordinates of X11.
6919 gdk_window_get_geometry (GdkWindow *window,
6926 GdkWindowImplClass *impl_class;
6930 GDK_NOTE (MULTIHEAD,
6931 g_message ("gdk_window_get_geometry(): Window needs "
6932 "to be non-NULL to be multi head safe"));
6933 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6936 g_return_if_fail (GDK_IS_WINDOW (window));
6938 if (!GDK_WINDOW_DESTROYED (window))
6940 if (gdk_window_has_impl (window))
6942 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6943 impl_class->get_geometry (window, x, y,
6945 /* This reports the position wrt to the native parent, we need to convert
6946 it to be relative to the client side parent */
6947 parent = window->parent;
6948 if (parent && !gdk_window_has_impl (parent))
6951 *x -= parent->abs_x;
6953 *y -= parent->abs_y;
6963 *width = window->width;
6965 *height = window->height;
6971 * gdk_window_get_width:
6972 * @window: a #GdkWindow
6974 * Returns the width of the given @window.
6976 * On the X11 platform the returned size is the size reported in the
6977 * most-recently-processed configure event, rather than the current
6978 * size on the X server.
6980 * Returns: The width of @window
6985 gdk_window_get_width (GdkWindow *window)
6987 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6989 return window->width;
6993 * gdk_window_get_height:
6994 * @window: a #GdkWindow
6996 * Returns the height of the given @window.
6998 * On the X11 platform the returned size is the size reported in the
6999 * most-recently-processed configure event, rather than the current
7000 * size on the X server.
7002 * Returns: The height of @window
7007 gdk_window_get_height (GdkWindow *window)
7009 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7011 return window->height;
7015 * gdk_window_get_origin:
7016 * @window: a #GdkWindow
7017 * @x: (out) (allow-none): return location for X coordinate
7018 * @y: (out) (allow-none): return location for Y coordinate
7020 * Obtains the position of a window in root window coordinates.
7021 * (Compare with gdk_window_get_position() and
7022 * gdk_window_get_geometry() which return the position of a window
7023 * relative to its parent window.)
7025 * Return value: not meaningful, ignore
7028 gdk_window_get_origin (GdkWindow *window,
7032 GdkWindowImplClass *impl_class;
7034 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7036 if (GDK_WINDOW_DESTROYED (window))
7045 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7046 impl_class->get_root_coords (window,
7055 * gdk_window_get_root_coords:
7056 * @window: a #GdkWindow
7057 * @x: X coordinate in window
7058 * @y: Y coordinate in window
7059 * @root_x: (out): return location for X coordinate
7060 * @root_y: (out): return location for Y coordinate
7062 * Obtains the position of a window position in root
7063 * window coordinates. This is similar to
7064 * gdk_window_get_origin() but allows you go pass
7065 * in any position in the window, not just the origin.
7070 gdk_window_get_root_coords (GdkWindow *window,
7076 GdkWindowImplClass *impl_class;
7078 g_return_if_fail (GDK_IS_WINDOW (window));
7080 if (GDK_WINDOW_DESTROYED (window))
7087 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7088 impl_class->get_root_coords (window,
7095 * gdk_window_coords_to_parent:
7096 * @window: a child window
7097 * @x: X coordinate in child's coordinate system
7098 * @y: Y coordinate in child's coordinate system
7099 * @parent_x: (out) (allow-none): return location for X coordinate
7100 * in parent's coordinate system, or %NULL
7101 * @parent_y: (out) (allow-none): return location for Y coordinate
7102 * in parent's coordinate system, or %NULL
7104 * Transforms window coordinates from a child window to its parent
7105 * window, where the parent window is the normal parent as returned by
7106 * gdk_window_get_parent() for normal windows, and the window's
7107 * embedder as returned by gdk_offscreen_window_get_embedder() for
7108 * offscreen windows.
7110 * For normal windows, calling this function is equivalent to adding
7111 * the return values of gdk_window_get_position() to the child coordinates.
7112 * For offscreen windows however (which can be arbitrarily transformed),
7113 * this function calls the GdkWindow::to-embedder: signal to translate
7116 * You should always use this function when writing generic code that
7117 * walks up a window hierarchy.
7119 * See also: gdk_window_coords_from_parent()
7124 gdk_window_coords_to_parent (GdkWindow *window,
7130 g_return_if_fail (GDK_IS_WINDOW (window));
7132 if (gdk_window_is_offscreen (window))
7136 to_embedder (window, x, y, &px, &py);
7147 *parent_x = x + window->x;
7150 *parent_y = y + window->y;
7155 * gdk_window_coords_from_parent:
7156 * @window: a child window
7157 * @parent_x: X coordinate in parent's coordinate system
7158 * @parent_y: Y coordinate in parent's coordinate system
7159 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7160 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7162 * Transforms window coordinates from a parent window to a child
7163 * window, where the parent window is the normal parent as returned by
7164 * gdk_window_get_parent() for normal windows, and the window's
7165 * embedder as returned by gdk_offscreen_window_get_embedder() for
7166 * offscreen windows.
7168 * For normal windows, calling this function is equivalent to subtracting
7169 * the return values of gdk_window_get_position() from the parent coordinates.
7170 * For offscreen windows however (which can be arbitrarily transformed),
7171 * this function calls the GdkWindow::from-embedder: signal to translate
7174 * You should always use this function when writing generic code that
7175 * walks down a window hierarchy.
7177 * See also: gdk_window_coords_to_parent()
7182 gdk_window_coords_from_parent (GdkWindow *window,
7188 g_return_if_fail (GDK_IS_WINDOW (window));
7190 if (gdk_window_is_offscreen (window))
7194 from_embedder (window, parent_x, parent_y, &cx, &cy);
7205 *x = parent_x - window->x;
7208 *y = parent_y - window->y;
7213 * gdk_window_shape_combine_region:
7214 * @window: a #GdkWindow
7215 * @shape_region: (allow-none): region of window to be non-transparent
7216 * @offset_x: X position of @shape_region in @window coordinates
7217 * @offset_y: Y position of @shape_region in @window coordinates
7219 * Makes pixels in @window outside @shape_region be transparent,
7220 * so that the window may be nonrectangular.
7222 * If @shape_region is %NULL, the shape will be unset, so the whole
7223 * window will be opaque again. @offset_x and @offset_y are ignored
7224 * if @shape_region is %NULL.
7226 * On the X11 platform, this uses an X server extension which is
7227 * widely available on most common platforms, but not available on
7228 * very old X servers, and occasionally the implementation will be
7229 * buggy. On servers without the shape extension, this function
7232 * This function works on both toplevel and child windows.
7235 gdk_window_shape_combine_region (GdkWindow *window,
7236 const cairo_region_t *shape_region,
7240 cairo_region_t *old_region, *new_region, *diff;
7242 g_return_if_fail (GDK_IS_WINDOW (window));
7244 if (GDK_WINDOW_DESTROYED (window))
7247 if (!window->shape && shape_region == NULL)
7250 window->shaped = (shape_region != NULL);
7253 cairo_region_destroy (window->shape);
7256 if (GDK_WINDOW_IS_MAPPED (window))
7257 old_region = cairo_region_copy (window->clip_region);
7261 window->shape = cairo_region_copy (shape_region);
7262 cairo_region_translate (window->shape, offset_x, offset_y);
7265 window->shape = NULL;
7267 recompute_visible_regions (window, TRUE, FALSE);
7269 if (gdk_window_has_impl (window) &&
7270 !should_apply_clip_as_shape (window))
7271 apply_shape (window, window->shape);
7275 new_region = cairo_region_copy (window->clip_region);
7277 /* New area in the window, needs invalidation */
7278 diff = cairo_region_copy (new_region);
7279 cairo_region_subtract (diff, old_region);
7281 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7283 cairo_region_destroy (diff);
7285 if (!gdk_window_is_toplevel (window))
7287 /* New area in the non-root parent window, needs invalidation */
7288 diff = cairo_region_copy (old_region);
7289 cairo_region_subtract (diff, new_region);
7291 /* Adjust region to parent window coords */
7292 cairo_region_translate (diff, window->x, window->y);
7294 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7296 cairo_region_destroy (diff);
7299 cairo_region_destroy (new_region);
7300 cairo_region_destroy (old_region);
7305 do_child_shapes (GdkWindow *window,
7309 cairo_region_t *region;
7313 r.width = window->width;
7314 r.height = window->height;
7316 region = cairo_region_create_rectangle (&r);
7317 remove_child_area (window, NULL, FALSE, region, NULL);
7319 if (merge && window->shape)
7320 cairo_region_subtract (region, window->shape);
7322 gdk_window_shape_combine_region (window, region, 0, 0);
7326 * gdk_window_set_child_shapes:
7327 * @window: a #GdkWindow
7329 * Sets the shape mask of @window to the union of shape masks
7330 * for all children of @window, ignoring the shape mask of @window
7331 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7332 * the shape mask of @window in the masks to be merged.
7335 gdk_window_set_child_shapes (GdkWindow *window)
7337 g_return_if_fail (GDK_IS_WINDOW (window));
7339 do_child_shapes (window, FALSE);
7343 * gdk_window_merge_child_shapes:
7344 * @window: a #GdkWindow
7346 * Merges the shape masks for any child windows into the
7347 * shape mask for @window. i.e. the union of all masks
7348 * for @window and its children will become the new mask
7349 * for @window. See gdk_window_shape_combine_region().
7351 * This function is distinct from gdk_window_set_child_shapes()
7352 * because it includes @window's shape mask in the set of shapes to
7356 gdk_window_merge_child_shapes (GdkWindow *window)
7358 g_return_if_fail (GDK_IS_WINDOW (window));
7360 do_child_shapes (window, TRUE);
7364 * gdk_window_input_shape_combine_region:
7365 * @window: a #GdkWindow
7366 * @shape_region: region of window to be non-transparent
7367 * @offset_x: X position of @shape_region in @window coordinates
7368 * @offset_y: Y position of @shape_region in @window coordinates
7370 * Like gdk_window_shape_combine_region(), but the shape applies
7371 * only to event handling. Mouse events which happen while
7372 * the pointer position corresponds to an unset bit in the
7373 * mask will be passed on the window below @window.
7375 * An input shape is typically used with RGBA windows.
7376 * The alpha channel of the window defines which pixels are
7377 * invisible and allows for nicely antialiased borders,
7378 * and the input shape controls where the window is
7381 * On the X11 platform, this requires version 1.1 of the
7384 * On the Win32 platform, this functionality is not present and the
7385 * function does nothing.
7390 gdk_window_input_shape_combine_region (GdkWindow *window,
7391 const cairo_region_t *shape_region,
7395 GdkWindowImplClass *impl_class;
7397 g_return_if_fail (GDK_IS_WINDOW (window));
7399 if (GDK_WINDOW_DESTROYED (window))
7402 if (window->input_shape)
7403 cairo_region_destroy (window->input_shape);
7407 window->input_shape = cairo_region_copy (shape_region);
7408 cairo_region_translate (window->input_shape, offset_x, offset_y);
7411 window->input_shape = NULL;
7413 if (gdk_window_has_impl (window))
7415 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7416 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7419 /* Pointer may have e.g. moved outside window due to the input mask change */
7420 _gdk_synthesize_crossing_events_for_geometry_change (window);
7424 do_child_input_shapes (GdkWindow *window,
7428 cairo_region_t *region;
7432 r.width = window->width;
7433 r.height = window->height;
7435 region = cairo_region_create_rectangle (&r);
7436 remove_child_area (window, NULL, TRUE, region, NULL);
7438 if (merge && window->shape)
7439 cairo_region_subtract (region, window->shape);
7440 if (merge && window->input_shape)
7441 cairo_region_subtract (region, window->input_shape);
7443 gdk_window_input_shape_combine_region (window, region, 0, 0);
7448 * gdk_window_set_child_input_shapes:
7449 * @window: a #GdkWindow
7451 * Sets the input shape mask of @window to the union of input shape masks
7452 * for all children of @window, ignoring the input shape mask of @window
7453 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7454 * the input shape mask of @window in the masks to be merged.
7459 gdk_window_set_child_input_shapes (GdkWindow *window)
7461 g_return_if_fail (GDK_IS_WINDOW (window));
7463 do_child_input_shapes (window, FALSE);
7467 * gdk_window_merge_child_input_shapes:
7468 * @window: a #GdkWindow
7470 * Merges the input shape masks for any child windows into the
7471 * input shape mask for @window. i.e. the union of all input masks
7472 * for @window and its children will become the new input mask
7473 * for @window. See gdk_window_input_shape_combine_region().
7475 * This function is distinct from gdk_window_set_child_input_shapes()
7476 * because it includes @window's input shape mask in the set of
7477 * shapes to be merged.
7482 gdk_window_merge_child_input_shapes (GdkWindow *window)
7484 g_return_if_fail (GDK_IS_WINDOW (window));
7486 do_child_input_shapes (window, TRUE);
7491 * gdk_window_set_static_gravities:
7492 * @window: a #GdkWindow
7493 * @use_static: %TRUE to turn on static gravity
7495 * Set the bit gravity of the given window to static, and flag it so
7496 * all children get static subwindow gravity. This is used if you are
7497 * implementing scary features that involve deep knowledge of the
7498 * windowing system. Don't worry about it unless you have to.
7500 * Return value: %TRUE if the server supports static gravity
7503 gdk_window_set_static_gravities (GdkWindow *window,
7504 gboolean use_static)
7506 GdkWindowImplClass *impl_class;
7508 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7510 if (gdk_window_has_impl (window))
7512 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7513 return impl_class->set_static_gravities (window, use_static);
7520 * gdk_window_get_composited:
7521 * @window: a #GdkWindow
7523 * Determines whether @window is composited.
7525 * See gdk_window_set_composited().
7527 * Returns: %TRUE if the window is composited.
7532 gdk_window_get_composited (GdkWindow *window)
7534 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7536 return window->composited;
7540 * gdk_window_set_composited:
7541 * @window: a #GdkWindow
7542 * @composited: %TRUE to set the window as composited
7544 * Sets a #GdkWindow as composited, or unsets it. Composited
7545 * windows do not automatically have their contents drawn to
7546 * the screen. Drawing is redirected to an offscreen buffer
7547 * and an expose event is emitted on the parent of the composited
7548 * window. It is the responsibility of the parent's expose handler
7549 * to manually merge the off-screen content onto the screen in
7550 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7553 * It only makes sense for child windows to be composited; see
7554 * gdk_window_set_opacity() if you need translucent toplevel
7557 * An additional effect of this call is that the area of this
7558 * window is no longer clipped from regions marked for
7559 * invalidation on its parent. Draws done on the parent
7560 * window are also no longer clipped by the child.
7562 * This call is only supported on some systems (currently,
7563 * only X11 with new enough Xcomposite and Xdamage extensions).
7564 * You must call gdk_display_supports_composite() to check if
7565 * setting a window as composited is supported before
7566 * attempting to do so.
7571 gdk_window_set_composited (GdkWindow *window,
7572 gboolean composited)
7574 GdkDisplay *display;
7575 GdkWindowImplClass *impl_class;
7577 g_return_if_fail (GDK_IS_WINDOW (window));
7579 composited = composited != FALSE;
7581 if (window->composited == composited)
7585 gdk_window_ensure_native (window);
7587 display = gdk_window_get_display (window);
7589 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7591 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7593 g_warning ("gdk_window_set_composited called but "
7594 "compositing is not supported");
7598 impl_class->set_composited (window, composited);
7600 recompute_visible_regions (window, TRUE, FALSE);
7602 if (GDK_WINDOW_IS_MAPPED (window))
7603 gdk_window_invalidate_in_parent (window);
7605 window->composited = composited;
7609 * gdk_window_get_modal_hint:
7610 * @window: A toplevel #GdkWindow.
7612 * Determines whether or not the window manager is hinted that @window
7613 * has modal behaviour.
7615 * Return value: whether or not the window has the modal hint set.
7620 gdk_window_get_modal_hint (GdkWindow *window)
7622 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7624 return window->modal_hint;
7628 * gdk_window_get_accept_focus:
7629 * @window: a toplevel #GdkWindow.
7631 * Determines whether or not the desktop environment shuld be hinted that
7632 * the window does not want to receive input focus.
7634 * Return value: whether or not the window should receive input focus.
7639 gdk_window_get_accept_focus (GdkWindow *window)
7641 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7643 return window->accept_focus;
7647 * gdk_window_get_focus_on_map:
7648 * @window: a toplevel #GdkWindow.
7650 * Determines whether or not the desktop environment should be hinted that the
7651 * window does not want to receive input focus when it is mapped.
7653 * Return value: whether or not the window wants to receive input focus when
7659 gdk_window_get_focus_on_map (GdkWindow *window)
7661 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7663 return window->focus_on_map;
7667 * gdk_window_is_input_only:
7668 * @window: a toplevel #GdkWindow
7670 * Determines whether or not the window is an input only window.
7672 * Return value: %TRUE if @window is input only
7677 gdk_window_is_input_only (GdkWindow *window)
7679 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7681 return window->input_only;
7685 * gdk_window_is_shaped:
7686 * @window: a toplevel #GdkWindow
7688 * Determines whether or not the window is shaped.
7690 * Return value: %TRUE if @window is shaped
7695 gdk_window_is_shaped (GdkWindow *window)
7697 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7699 return window->shaped;
7703 _gdk_window_add_damage (GdkWindow *toplevel,
7704 cairo_region_t *damaged_region)
7706 GdkDisplay *display;
7707 GdkEvent event = { 0, };
7708 event.expose.type = GDK_DAMAGE;
7709 event.expose.window = toplevel;
7710 event.expose.send_event = FALSE;
7711 event.expose.region = damaged_region;
7712 cairo_region_get_extents (event.expose.region, &event.expose.area);
7713 display = gdk_window_get_display (event.expose.window);
7714 _gdk_event_queue_append (display, gdk_event_copy (&event));
7717 /* Gets the toplevel for a window as used for events,
7718 i.e. including offscreen parents */
7720 get_event_parent (GdkWindow *window)
7722 if (gdk_window_is_offscreen (window))
7723 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7725 return window->parent;
7728 /* Gets the toplevel for a window as used for events,
7729 i.e. including offscreen parents going up to the native
7732 get_event_toplevel (GdkWindow *window)
7736 while ((parent = get_event_parent (window)) != NULL &&
7737 (parent->window_type != GDK_WINDOW_ROOT))
7744 _gdk_window_event_parent_of (GdkWindow *parent,
7755 w = get_event_parent (w);
7762 update_cursor (GdkDisplay *display,
7765 GdkWindow *cursor_window, *parent, *toplevel;
7766 GdkWindow *pointer_window;
7767 GdkWindowImplClass *impl_class;
7768 GdkPointerWindowInfo *pointer_info;
7769 GdkDeviceGrabInfo *grab;
7772 pointer_info = _gdk_display_get_pointer_info (display, device);
7773 pointer_window = pointer_info->window_under_pointer;
7775 /* We ignore the serials here and just pick the last grab
7776 we've sent, as that would shortly be used anyway. */
7777 grab = _gdk_display_get_last_device_grab (display, device);
7780 /* the pointer is not in a descendant of the grab window */
7781 !_gdk_window_event_parent_of (grab->window, pointer_window))
7783 /* use the cursor from the grab window */
7784 cursor_window = grab->window;
7788 /* otherwise use the cursor from the pointer window */
7789 cursor_window = pointer_window;
7792 /* Find the first window with the cursor actually set, as
7793 the cursor is inherited from the parent */
7794 while (cursor_window->cursor == NULL &&
7795 (parent = get_event_parent (cursor_window)) != NULL &&
7796 parent->window_type != GDK_WINDOW_ROOT)
7797 cursor_window = parent;
7799 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7802 cursor = cursor_window->cursor;
7804 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7805 * which native window has what cursor set. */
7806 toplevel = get_event_toplevel (pointer_window);
7807 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7808 impl_class->set_device_cursor (toplevel, device, cursor);
7812 point_in_window (GdkWindow *window,
7817 x >= 0 && x < window->width &&
7818 y >= 0 && y < window->height &&
7819 (window->shape == NULL ||
7820 cairo_region_contains_point (window->shape,
7822 (window->input_shape == NULL ||
7823 cairo_region_contains_point (window->input_shape,
7828 convert_native_coords_to_toplevel (GdkWindow *window,
7831 gdouble *toplevel_x,
7832 gdouble *toplevel_y)
7839 while (!gdk_window_is_toplevel (window))
7843 window = window->parent;
7853 convert_toplevel_coords_to_window (GdkWindow *window,
7861 GList *children, *l;
7867 while ((parent = get_event_parent (window)) != NULL &&
7868 (parent->window_type != GDK_WINDOW_ROOT))
7870 children = g_list_prepend (children, window);
7874 for (l = children; l != NULL; l = l->next)
7875 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7877 g_list_free (children);
7884 pick_embedded_child (GdkWindow *window,
7891 g_signal_emit (window,
7892 signals[PICK_EMBEDDED_CHILD], 0,
7899 _gdk_window_find_child_at (GdkWindow *window,
7904 double child_x, child_y;
7907 if (point_in_window (window, x, y))
7909 /* Children is ordered in reverse stack order, i.e. first is topmost */
7910 for (l = window->children; l != NULL; l = l->next)
7914 if (!GDK_WINDOW_IS_MAPPED (sub))
7917 gdk_window_coords_from_parent ((GdkWindow *)sub,
7919 &child_x, &child_y);
7920 if (point_in_window (sub, child_x, child_y))
7921 return (GdkWindow *)sub;
7924 if (window->num_offscreen_children > 0)
7926 sub = pick_embedded_child (window,
7929 return (GdkWindow *)sub;
7937 _gdk_window_find_descendant_at (GdkWindow *window,
7944 gdouble child_x, child_y;
7948 if (point_in_window (window, x, y))
7953 /* Children is ordered in reverse stack order, i.e. first is topmost */
7954 for (l = window->children; l != NULL; l = l->next)
7958 if (!GDK_WINDOW_IS_MAPPED (sub))
7961 gdk_window_coords_from_parent ((GdkWindow *)sub,
7963 &child_x, &child_y);
7964 if (point_in_window (sub, child_x, child_y))
7974 window->num_offscreen_children > 0)
7976 sub = pick_embedded_child (window,
7982 from_embedder (sub, x, y, &x, &y);
7990 /* Not in window at all */
8004 * @window: a toplevel #GdkWindow
8006 * Emits a short beep associated to @window in the appropriate
8007 * display, if supported. Otherwise, emits a short beep on
8008 * the display just as gdk_display_beep().
8013 gdk_window_beep (GdkWindow *window)
8015 GdkDisplay *display;
8016 GdkWindow *toplevel;
8018 g_return_if_fail (GDK_IS_WINDOW (window));
8020 if (GDK_WINDOW_DESTROYED (window))
8023 toplevel = get_event_toplevel (window);
8024 display = gdk_window_get_display (window);
8028 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
8032 /* If windows fail to beep, we beep the display. */
8033 gdk_display_beep (display);
8037 * gdk_window_set_support_multidevice:
8038 * @window: a #GdkWindow.
8039 * @support_multidevice: %TRUE to enable multidevice support in @window.
8041 * This function will enable multidevice features in @window.
8043 * Multidevice aware windows will need to handle properly multiple,
8044 * per device enter/leave events, device grabs and grab ownerships.
8049 gdk_window_set_support_multidevice (GdkWindow *window,
8050 gboolean support_multidevice)
8052 g_return_if_fail (GDK_IS_WINDOW (window));
8054 if (GDK_WINDOW_DESTROYED (window))
8057 if (window->support_multidevice == support_multidevice)
8060 window->support_multidevice = support_multidevice;
8062 /* FIXME: What to do if called when some pointers are inside the window ? */
8066 * gdk_window_get_support_multidevice:
8067 * @window: a #GdkWindow.
8069 * Returns %TRUE if the window is aware of the existence of multiple
8072 * Returns: %TRUE if the window handles multidevice features.
8077 gdk_window_get_support_multidevice (GdkWindow *window)
8079 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8081 if (GDK_WINDOW_DESTROYED (window))
8084 return window->support_multidevice;
8087 static const guint type_masks[] = {
8088 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8089 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8090 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8091 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8092 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8093 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8094 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8095 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8096 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8097 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8098 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8099 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8100 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8101 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8102 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8103 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8104 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8105 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8106 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8107 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8108 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8109 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8110 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8111 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8112 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8113 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8114 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8115 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8116 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8117 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8118 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8119 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8120 0, /* GDK_WINDOW_STATE = 32 */
8121 0, /* GDK_SETTING = 33 */
8122 0, /* GDK_OWNER_CHANGE = 34 */
8123 0, /* GDK_GRAB_BROKEN = 35 */
8124 0, /* GDK_DAMAGE = 36 */
8125 GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */
8126 GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */
8127 GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */
8128 GDK_TOUCH_MASK /* GDK_TOUCH_CANCEL = 40 */
8130 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8132 /* send motion events if the right buttons are down */
8134 update_evmask_for_button_motion (guint evmask,
8135 GdkModifierType mask)
8137 if (evmask & GDK_BUTTON_MOTION_MASK &&
8138 mask & (GDK_BUTTON1_MASK |
8143 evmask |= GDK_POINTER_MOTION_MASK;
8145 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8146 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8147 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8148 evmask |= GDK_POINTER_MOTION_MASK;
8154 is_button_type (GdkEventType type)
8156 return type == GDK_BUTTON_PRESS ||
8157 type == GDK_2BUTTON_PRESS ||
8158 type == GDK_3BUTTON_PRESS ||
8159 type == GDK_BUTTON_RELEASE ||
8160 type == GDK_TOUCH_BEGIN ||
8161 type == GDK_TOUCH_END ||
8166 is_motion_type (GdkEventType type)
8168 return type == GDK_MOTION_NOTIFY ||
8169 type == GDK_TOUCH_UPDATE ||
8170 type == GDK_ENTER_NOTIFY ||
8171 type == GDK_LEAVE_NOTIFY;
8175 is_touch_type (GdkEventType type)
8177 return type == GDK_TOUCH_BEGIN ||
8178 type == GDK_TOUCH_UPDATE ||
8179 type == GDK_TOUCH_END ||
8180 type == GDK_TOUCH_CANCEL;
8184 find_common_ancestor (GdkWindow *win1,
8188 GList *path1 = NULL, *path2 = NULL;
8189 GList *list1, *list2;
8192 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8194 path1 = g_list_prepend (path1, tmp);
8195 tmp = get_event_parent (tmp);
8199 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8201 path2 = g_list_prepend (path2, tmp);
8202 tmp = get_event_parent (tmp);
8208 while (list1 && list2 && (list1->data == list2->data))
8211 list1 = g_list_next (list1);
8212 list2 = g_list_next (list2);
8214 g_list_free (path1);
8215 g_list_free (path2);
8221 _gdk_make_event (GdkWindow *window,
8223 GdkEvent *event_in_queue,
8224 gboolean before_event)
8226 GdkEvent *event = gdk_event_new (type);
8228 GdkModifierType the_state;
8230 the_time = gdk_event_get_time (event_in_queue);
8231 gdk_event_get_state (event_in_queue, &the_state);
8233 event->any.window = g_object_ref (window);
8234 event->any.send_event = FALSE;
8235 if (event_in_queue && event_in_queue->any.send_event)
8236 event->any.send_event = TRUE;
8240 case GDK_MOTION_NOTIFY:
8241 event->motion.time = the_time;
8242 event->motion.axes = NULL;
8243 event->motion.state = the_state;
8246 case GDK_BUTTON_PRESS:
8247 case GDK_2BUTTON_PRESS:
8248 case GDK_3BUTTON_PRESS:
8249 case GDK_BUTTON_RELEASE:
8250 event->button.time = the_time;
8251 event->button.axes = NULL;
8252 event->button.state = the_state;
8255 case GDK_TOUCH_BEGIN:
8256 case GDK_TOUCH_UPDATE:
8258 case GDK_TOUCH_CANCEL:
8259 event->touch.time = the_time;
8260 event->touch.axes = NULL;
8261 event->touch.state = the_state;
8265 event->scroll.time = the_time;
8266 event->scroll.state = the_state;
8270 case GDK_KEY_RELEASE:
8271 event->key.time = the_time;
8272 event->key.state = the_state;
8275 case GDK_ENTER_NOTIFY:
8276 case GDK_LEAVE_NOTIFY:
8277 event->crossing.time = the_time;
8278 event->crossing.state = the_state;
8281 case GDK_PROPERTY_NOTIFY:
8282 event->property.time = the_time;
8283 event->property.state = the_state;
8286 case GDK_SELECTION_CLEAR:
8287 case GDK_SELECTION_REQUEST:
8288 case GDK_SELECTION_NOTIFY:
8289 event->selection.time = the_time;
8292 case GDK_PROXIMITY_IN:
8293 case GDK_PROXIMITY_OUT:
8294 event->proximity.time = the_time;
8297 case GDK_DRAG_ENTER:
8298 case GDK_DRAG_LEAVE:
8299 case GDK_DRAG_MOTION:
8300 case GDK_DRAG_STATUS:
8301 case GDK_DROP_START:
8302 case GDK_DROP_FINISHED:
8303 event->dnd.time = the_time;
8306 case GDK_FOCUS_CHANGE:
8310 case GDK_CLIENT_EVENT:
8311 case GDK_VISIBILITY_NOTIFY:
8322 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8324 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8327 _gdk_event_queue_append (gdk_window_get_display (window), event);
8333 send_crossing_event (GdkDisplay *display,
8334 GdkWindow *toplevel,
8337 GdkCrossingMode mode,
8338 GdkNotifyType notify_type,
8339 GdkWindow *subwindow,
8341 GdkDevice *source_device,
8344 GdkModifierType mask,
8346 GdkEvent *event_in_queue,
8350 guint32 window_event_mask, type_event_mask;
8351 GdkDeviceGrabInfo *grab;
8352 GdkTouchGrabInfo *touch_grab = NULL;
8353 GdkPointerWindowInfo *pointer_info;
8354 gboolean block_event = FALSE;
8355 GdkEventSequence *sequence;
8357 grab = _gdk_display_has_device_grab (display, device, serial);
8358 pointer_info = _gdk_display_get_pointer_info (display, device);
8360 sequence = gdk_event_get_event_sequence (event_in_queue);
8362 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
8366 if (window != touch_grab->window)
8369 window_event_mask = touch_grab->event_mask;
8371 else if (grab != NULL &&
8372 !grab->owner_events)
8374 /* !owner_event => only report events wrt grab window, ignore rest */
8375 if ((GdkWindow *)window != grab->window)
8377 window_event_mask = grab->event_mask;
8380 window_event_mask = window->event_mask;
8382 if (type == GDK_ENTER_NOTIFY &&
8383 pointer_info->need_touch_press_enter &&
8384 mode != GDK_CROSSING_TOUCH_BEGIN &&
8385 mode != GDK_CROSSING_TOUCH_END)
8389 else if (type == GDK_LEAVE_NOTIFY)
8391 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8392 window->devices_inside = g_list_remove (window->devices_inside, device);
8394 if (!window->support_multidevice && window->devices_inside)
8396 /* Block leave events unless it's the last pointer */
8402 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8404 if (!window->support_multidevice && window->devices_inside)
8406 /* Only emit enter events for the first device */
8410 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8411 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8412 !g_list_find (window->devices_inside, device))
8413 window->devices_inside = g_list_prepend (window->devices_inside, device);
8419 if (window_event_mask & type_event_mask)
8421 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8422 gdk_event_set_device (event, device);
8425 gdk_event_set_source_device (event, source_device);
8427 event->crossing.time = time_;
8428 event->crossing.subwindow = subwindow;
8430 g_object_ref (subwindow);
8431 convert_toplevel_coords_to_window ((GdkWindow *)window,
8432 toplevel_x, toplevel_y,
8433 &event->crossing.x, &event->crossing.y);
8434 event->crossing.x_root = toplevel_x + toplevel->x;
8435 event->crossing.y_root = toplevel_y + toplevel->y;
8436 event->crossing.mode = mode;
8437 event->crossing.detail = notify_type;
8438 event->crossing.focus = FALSE;
8439 event->crossing.state = mask;
8444 /* The coordinates are in the toplevel window that src/dest are in.
8445 * src and dest are always (if != NULL) in the same toplevel, as
8446 * we get a leave-notify and set the window_under_pointer to null
8447 * before crossing to another toplevel.
8450 _gdk_synthesize_crossing_events (GdkDisplay *display,
8454 GdkDevice *source_device,
8455 GdkCrossingMode mode,
8458 GdkModifierType mask,
8460 GdkEvent *event_in_queue,
8462 gboolean non_linear)
8465 GdkWindow *win, *last, *next;
8469 GdkWindow *toplevel;
8470 GdkNotifyType notify_type;
8472 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8477 return; /* No crossings generated between src and dest */
8479 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8481 if (a && gdk_window_get_device_events (src, device) == 0)
8484 if (b && gdk_window_get_device_events (dest, device) == 0)
8491 c = find_common_ancestor (a, b);
8493 non_linear |= (c != a) && (c != b);
8495 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8497 toplevel = gdk_window_get_toplevel (a);
8499 /* Traverse up from a to (excluding) c sending leave events */
8501 notify_type = GDK_NOTIFY_NONLINEAR;
8503 notify_type = GDK_NOTIFY_INFERIOR;
8505 notify_type = GDK_NOTIFY_ANCESTOR;
8506 send_crossing_event (display, toplevel,
8507 a, GDK_LEAVE_NOTIFY,
8510 NULL, device, source_device,
8511 toplevel_x, toplevel_y,
8519 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8521 notify_type = GDK_NOTIFY_VIRTUAL;
8524 win = get_event_parent (a);
8525 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8527 send_crossing_event (display, toplevel,
8528 win, GDK_LEAVE_NOTIFY,
8532 device, source_device,
8533 toplevel_x, toplevel_y,
8539 win = get_event_parent (win);
8544 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8546 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8548 /* Traverse down from c to b */
8552 win = get_event_parent (b);
8553 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8555 path = g_list_prepend (path, win);
8556 win = get_event_parent (win);
8560 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8562 notify_type = GDK_NOTIFY_VIRTUAL;
8568 list = g_list_next (list);
8574 send_crossing_event (display, toplevel,
8575 win, GDK_ENTER_NOTIFY,
8579 device, source_device,
8580 toplevel_x, toplevel_y,
8590 notify_type = GDK_NOTIFY_NONLINEAR;
8592 notify_type = GDK_NOTIFY_ANCESTOR;
8594 notify_type = GDK_NOTIFY_INFERIOR;
8596 send_crossing_event (display, toplevel,
8597 b, GDK_ENTER_NOTIFY,
8601 device, source_device,
8602 toplevel_x, toplevel_y,
8609 /* Returns the window inside the event window with the pointer in it
8610 * at the specified coordinates, or NULL if its not in any child of
8611 * the toplevel. It also takes into account !owner_events grabs.
8614 get_pointer_window (GdkDisplay *display,
8615 GdkWindow *event_window,
8621 GdkWindow *pointer_window;
8622 GdkDeviceGrabInfo *grab;
8623 GdkPointerWindowInfo *pointer_info;
8625 pointer_info = _gdk_display_get_pointer_info (display, device);
8627 if (event_window == pointer_info->toplevel_under_pointer)
8629 _gdk_window_find_descendant_at (event_window,
8630 toplevel_x, toplevel_y,
8633 pointer_window = NULL;
8635 grab = _gdk_display_has_device_grab (display, device, serial);
8637 !grab->owner_events &&
8638 pointer_window != grab->window)
8639 pointer_window = NULL;
8641 return pointer_window;
8645 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8649 GdkPointerWindowInfo *device_info;
8651 device_info = _gdk_display_get_pointer_info (display, device);
8653 if (device_info->window_under_pointer)
8654 g_object_unref (device_info->window_under_pointer);
8655 device_info->window_under_pointer = window;
8659 g_object_ref (window);
8660 update_cursor (display, device);
8663 _gdk_display_enable_motion_hints (display, device);
8668 * @window: the #GdkWindow which will own the grab (the grab window).
8669 * @owner_events: if %FALSE then all pointer events are reported with respect to
8670 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8671 * events for this application are reported as normal, but pointer events outside
8672 * this application are reported with respect to @window and only if selected by
8673 * @event_mask. In either mode, unreported events are discarded.
8674 * @event_mask: specifies the event mask, which is used in accordance with
8675 * @owner_events. Note that only pointer events (i.e. button and motion events)
8677 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8678 * window during the grab. If the pointer is outside @confine_to, it will
8679 * automatically be moved to the closest edge of @confine_to and enter
8680 * and leave events will be generated as necessary.
8681 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8682 * the normal cursors are used for @window and its descendants, and the cursor
8683 * for @window is used for all other windows.
8684 * @time_: the timestamp of the event which led to this pointer grab. This usually
8685 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8686 * the time isn't known.
8688 * Grabs the pointer (usually a mouse) so that all events are passed to this
8689 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8690 * the grab window becomes unviewable.
8691 * This overrides any previous pointer grab by this client.
8693 * Pointer grabs are used for operations which need complete control over mouse
8694 * events, even if the mouse leaves the application.
8695 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8696 * the #GtkHPaned and #GtkVPaned widgets.
8698 * Note that if the event mask of an X window has selected both button press and
8699 * button release events, then a button press event will cause an automatic
8700 * pointer grab until the button is released.
8701 * X does this automatically since most applications expect to receive button
8702 * press and release events in pairs.
8703 * It is equivalent to a pointer grab on the window with @owner_events set to
8706 * If you set up anything at the time you take the grab that needs to be cleaned
8707 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8708 * are emitted when the grab ends unvoluntarily.
8710 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8712 * Deprecated: 3.0: Use gdk_device_grab() instead.
8715 gdk_pointer_grab (GdkWindow * window,
8716 gboolean owner_events,
8717 GdkEventMask event_mask,
8718 GdkWindow * confine_to,
8723 GdkDisplay *display;
8724 GdkDeviceManager *device_manager;
8726 GdkGrabStatus res = 0;
8728 GList *devices, *dev;
8730 g_return_val_if_fail (window != NULL, 0);
8731 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8732 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8734 /* We need a native window for confine to to work, ensure we have one */
8737 if (!gdk_window_ensure_native (confine_to))
8739 g_warning ("Can't confine to grabbed window, not native");
8744 /* Non-viewable client side window => fail */
8745 if (!_gdk_window_has_impl (window) &&
8746 !gdk_window_is_viewable (window))
8747 return GDK_GRAB_NOT_VIEWABLE;
8749 native = gdk_window_get_toplevel (window);
8750 while (gdk_window_is_offscreen (native))
8752 native = gdk_offscreen_window_get_embedder (native);
8754 if (native == NULL ||
8755 (!_gdk_window_has_impl (native) &&
8756 !gdk_window_is_viewable (native)))
8757 return GDK_GRAB_NOT_VIEWABLE;
8759 native = gdk_window_get_toplevel (native);
8762 display = gdk_window_get_display (window);
8764 serial = _gdk_display_get_next_serial (display);
8765 device_manager = gdk_display_get_device_manager (display);
8766 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8768 /* FIXME: Should this be generic to all backends? */
8769 /* FIXME: What happens with extended devices? */
8770 for (dev = devices; dev; dev = dev->next)
8774 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8777 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8780 get_native_grab_event_mask (event_mask),
8785 if (res == GDK_GRAB_SUCCESS)
8786 _gdk_display_add_device_grab (display,
8798 /* FIXME: handle errors when grabbing */
8800 g_list_free (devices);
8806 * gdk_keyboard_grab:
8807 * @window: the #GdkWindow which will own the grab (the grab window).
8808 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8809 * @window. If %TRUE then keyboard events for this application are
8810 * reported as normal, but keyboard events outside this application
8811 * are reported with respect to @window. Both key press and key
8812 * release events are always reported, independant of the event mask
8813 * set by the application.
8814 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8817 * Grabs the keyboard so that all events are passed to this
8818 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8819 * This overrides any previous keyboard grab by this client.
8821 * If you set up anything at the time you take the grab that needs to be cleaned
8822 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8823 * are emitted when the grab ends unvoluntarily.
8825 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8827 * Deprecated: 3.0: Use gdk_device_grab() instead.
8830 gdk_keyboard_grab (GdkWindow *window,
8831 gboolean owner_events,
8835 GdkDisplay *display;
8836 GdkDeviceManager *device_manager;
8838 GdkGrabStatus res = 0;
8840 GList *devices, *dev;
8842 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8844 /* Non-viewable client side window => fail */
8845 if (!_gdk_window_has_impl (window) &&
8846 !gdk_window_is_viewable (window))
8847 return GDK_GRAB_NOT_VIEWABLE;
8849 native = gdk_window_get_toplevel (window);
8851 while (gdk_window_is_offscreen (native))
8853 native = gdk_offscreen_window_get_embedder (native);
8855 if (native == NULL ||
8856 (!_gdk_window_has_impl (native) &&
8857 !gdk_window_is_viewable (native)))
8858 return GDK_GRAB_NOT_VIEWABLE;
8860 native = gdk_window_get_toplevel (native);
8863 display = gdk_window_get_display (window);
8864 serial = _gdk_display_get_next_serial (display);
8865 device_manager = gdk_display_get_device_manager (display);
8866 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8868 /* FIXME: Should this be generic to all backends? */
8869 /* FIXME: What happens with extended devices? */
8870 for (dev = devices; dev; dev = dev->next)
8874 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8877 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8880 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8885 if (res == GDK_GRAB_SUCCESS)
8886 _gdk_display_add_device_grab (display,
8897 /* FIXME: handle errors when grabbing */
8899 g_list_free (devices);
8905 * gdk_window_geometry_changed:
8906 * @window: an embedded offscreen #GdkWindow
8908 * This function informs GDK that the geometry of an embedded
8909 * offscreen window has changed. This is necessary for GDK to keep
8910 * track of which offscreen window the pointer is in.
8915 gdk_window_geometry_changed (GdkWindow *window)
8917 _gdk_synthesize_crossing_events_for_geometry_change (window);
8921 source_events_device_added (GdkDeviceManager *device_manager,
8926 GdkEventMask event_mask;
8927 GdkInputSource source;
8929 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
8933 source = gdk_device_get_source (device);
8935 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8936 GINT_TO_POINTER (source)));
8938 gdk_window_set_device_events (window, device, event_mask);
8942 source_events_device_changed (GdkDeviceManager *device_manager,
8947 GdkInputSource source;
8948 GdkEventMask event_mask;
8952 type = gdk_device_get_device_type (device);
8953 source = gdk_device_get_source (device);
8955 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8956 GINT_TO_POINTER (source)));
8961 if (type == GDK_DEVICE_TYPE_FLOATING)
8963 /* The device was just floated, enable its event mask */
8964 gdk_window_set_device_events (window, device, event_mask);
8966 else if (type == GDK_DEVICE_TYPE_SLAVE)
8967 gdk_window_set_device_events (window, device, 0);
8971 * gdk_window_set_source_events:
8972 * @window: a #GdkWindow
8973 * @source: a #GdkInputSource to define the source class.
8974 * @event_mask: event mask for @window
8976 * Sets the event mask for any floating device (i.e. not attached to any
8977 * visible pointer) that has the source defined as @source. This event
8978 * mask will be applied both to currently existing, newly added devices
8979 * after this call, and devices being attached/detached.
8984 gdk_window_set_source_events (GdkWindow *window,
8985 GdkInputSource source,
8986 GdkEventMask event_mask)
8988 GdkDeviceManager *device_manager;
8989 GdkDisplay *display;
8993 g_return_if_fail (GDK_IS_WINDOW (window));
8995 display = gdk_window_get_display (window);
8996 device_manager = gdk_display_get_device_manager (display);
8998 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
9000 /* Set event mask for existing devices */
9001 for (d = devices; d; d = d->next)
9003 GdkDevice *device = d->data;
9005 if (source == gdk_device_get_source (device))
9006 gdk_window_set_device_events (window, device, event_mask);
9009 g_list_free (devices);
9011 /* Update accounting */
9012 if (G_UNLIKELY (!window->source_event_masks))
9013 window->source_event_masks = g_hash_table_new (NULL, NULL);
9016 g_hash_table_insert (window->source_event_masks,
9017 GUINT_TO_POINTER (source),
9018 GUINT_TO_POINTER (event_mask));
9020 g_hash_table_remove (window->source_event_masks,
9021 GUINT_TO_POINTER (source));
9023 size = g_hash_table_size (window->source_event_masks);
9025 /* Update handler if needed */
9026 if (!window->device_added_handler_id && size > 0)
9028 window->device_added_handler_id =
9029 g_signal_connect (device_manager, "device-added",
9030 G_CALLBACK (source_events_device_added), window);
9031 window->device_changed_handler_id =
9032 g_signal_connect (device_manager, "device-changed",
9033 G_CALLBACK (source_events_device_changed), window);
9035 else if (window->device_added_handler_id && size == 0)
9036 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
9040 * gdk_window_get_source_events:
9041 * @window: a #GdkWindow
9042 * @source: a #GdkInputSource to define the source class.
9044 * Returns the event mask for @window corresponding to the device class specified
9047 * Returns: source event mask for @window
9050 gdk_window_get_source_events (GdkWindow *window,
9051 GdkInputSource source)
9053 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
9055 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
9056 GUINT_TO_POINTER (source)));
9060 do_synthesize_crossing_event (gpointer data)
9062 GdkDisplay *display;
9063 GdkWindow *changed_toplevel;
9064 GHashTableIter iter;
9065 gpointer key, value;
9068 changed_toplevel = data;
9070 changed_toplevel->synthesize_crossing_event_queued = FALSE;
9072 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9075 display = gdk_window_get_display (changed_toplevel);
9076 serial = _gdk_display_get_next_serial (display);
9077 g_hash_table_iter_init (&iter, display->pointers_info);
9079 while (g_hash_table_iter_next (&iter, &key, &value))
9081 GdkWindow *new_window_under_pointer;
9082 GdkPointerWindowInfo *pointer_info = value;
9083 GdkDevice *device = key;
9085 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9087 new_window_under_pointer =
9088 get_pointer_window (display, changed_toplevel,
9090 pointer_info->toplevel_x,
9091 pointer_info->toplevel_y,
9093 if (new_window_under_pointer != pointer_info->window_under_pointer)
9095 _gdk_synthesize_crossing_events (display,
9096 pointer_info->window_under_pointer,
9097 new_window_under_pointer,
9098 device, pointer_info->last_slave,
9099 GDK_CROSSING_NORMAL,
9100 pointer_info->toplevel_x,
9101 pointer_info->toplevel_y,
9102 pointer_info->state,
9107 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9116 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9118 GdkWindow *toplevel;
9120 toplevel = get_event_toplevel (changed_window);
9122 if (!toplevel->synthesize_crossing_event_queued)
9124 toplevel->synthesize_crossing_event_queued = TRUE;
9126 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9127 do_synthesize_crossing_event,
9128 g_object_ref (toplevel),
9133 /* Don't use for crossing events */
9135 get_event_window (GdkDisplay *display,
9137 GdkEventSequence *sequence,
9138 GdkWindow *pointer_window,
9140 GdkModifierType mask,
9142 gboolean pointer_emulated,
9145 guint evmask, emulated_mask = 0;
9146 GdkWindow *grab_window;
9147 GdkDeviceGrabInfo *grab;
9148 GdkTouchGrabInfo *touch_grab;
9150 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
9151 grab = _gdk_display_get_last_device_grab (display, device);
9153 if (is_touch_type (type) && pointer_emulated)
9157 case GDK_TOUCH_BEGIN:
9158 emulated_mask |= GDK_BUTTON_PRESS_MASK;
9160 case GDK_TOUCH_UPDATE:
9161 emulated_mask |= GDK_BUTTON_MOTION_MASK;
9164 emulated_mask |= GDK_BUTTON_RELEASE_MASK;
9170 if (touch_grab != NULL &&
9171 (!grab || grab->implicit || touch_grab->serial >= grab->serial_start))
9173 evmask = touch_grab->event_mask;
9174 evmask = update_evmask_for_button_motion (evmask, mask);
9176 if (evmask & (type_masks[type] | emulated_mask))
9179 *evmask_out = evmask;
9180 return touch_grab->window;
9186 if (grab != NULL && !grab->owner_events)
9188 evmask = grab->event_mask;
9189 evmask = update_evmask_for_button_motion (evmask, mask);
9191 grab_window = grab->window;
9193 if (evmask & (type_masks[type] | emulated_mask))
9196 *evmask_out = evmask;
9203 while (pointer_window != NULL)
9205 evmask = pointer_window->event_mask;
9206 evmask = update_evmask_for_button_motion (evmask, mask);
9208 if (evmask & (type_masks[type] | emulated_mask))
9211 *evmask_out = evmask;
9212 return pointer_window;
9215 pointer_window = get_event_parent (pointer_window);
9221 evmask = grab->event_mask;
9222 evmask = update_evmask_for_button_motion (evmask, mask);
9224 if (evmask & (type_masks[type] | emulated_mask))
9227 *evmask_out = evmask;
9228 return grab->window;
9238 proxy_pointer_event (GdkDisplay *display,
9239 GdkEvent *source_event,
9242 GdkWindow *toplevel_window, *event_window;
9243 GdkWindow *pointer_window;
9244 GdkPointerWindowInfo *pointer_info;
9245 GdkDevice *device, *source_device;
9248 gdouble toplevel_x, toplevel_y;
9250 gboolean non_linear, need_synthetic_enter = FALSE;
9253 event_type = source_event->type;
9254 event_window = source_event->any.window;
9255 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9256 gdk_event_get_state (source_event, &state);
9257 time_ = gdk_event_get_time (source_event);
9258 device = gdk_event_get_device (source_event);
9259 source_device = gdk_event_get_source_device (source_event);
9260 pointer_info = _gdk_display_get_pointer_info (display, device);
9261 toplevel_window = convert_native_coords_to_toplevel (event_window,
9262 toplevel_x, toplevel_y,
9263 &toplevel_x, &toplevel_y);
9266 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9267 source_event->type == GDK_ENTER_NOTIFY) &&
9268 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9269 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9272 if (pointer_info->need_touch_press_enter &&
9273 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHSCREEN &&
9274 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHPAD &&
9275 (source_event->type != GDK_TOUCH_UPDATE ||
9276 _gdk_event_get_pointer_emulated (source_event)))
9278 pointer_info->need_touch_press_enter = FALSE;
9279 need_synthetic_enter = TRUE;
9282 /* If we get crossing events with subwindow unexpectedly being NULL
9283 that means there is a native subwindow that gdk doesn't know about.
9284 We track these and forward them, with the correct virtual window
9286 This is important to get right, as metacity uses gdk for the frame
9287 windows, but gdk doesn't know about the client windows reparented
9289 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9290 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9291 (source_event->type == GDK_ENTER_NOTIFY &&
9292 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9293 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9294 source_event->crossing.subwindow == NULL)
9296 /* Left for an unknown (to gdk) subwindow */
9298 /* Send leave events from window under pointer to event window
9299 that will get the subwindow == NULL window */
9300 _gdk_synthesize_crossing_events (display,
9301 pointer_info->window_under_pointer,
9303 device, source_device,
9304 source_event->crossing.mode,
9305 toplevel_x, toplevel_y,
9311 /* Send subwindow == NULL event */
9312 send_crossing_event (display,
9316 source_event->crossing.mode,
9317 source_event->crossing.detail,
9319 device, source_device,
9320 toplevel_x, toplevel_y,
9325 _gdk_display_set_window_under_pointer (display, device, NULL);
9329 pointer_window = get_pointer_window (display, toplevel_window, device,
9330 toplevel_x, toplevel_y, serial);
9332 if (((source_event->type == GDK_ENTER_NOTIFY &&
9333 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9334 (source_event->type == GDK_LEAVE_NOTIFY &&
9335 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9336 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9337 source_event->crossing.subwindow == NULL)
9339 /* Entered from an unknown (to gdk) subwindow */
9341 /* Send subwindow == NULL event */
9342 send_crossing_event (display,
9346 source_event->crossing.mode,
9347 source_event->crossing.detail,
9349 device, source_device,
9350 toplevel_x, toplevel_y,
9355 /* Send enter events from event window to pointer_window */
9356 _gdk_synthesize_crossing_events (display,
9359 device, source_device,
9360 source_event->crossing.mode,
9361 toplevel_x, toplevel_y,
9364 serial, non_linear);
9365 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9369 if ((source_event->type != GDK_TOUCH_UPDATE ||
9370 _gdk_event_get_pointer_emulated (source_event)) &&
9371 pointer_info->window_under_pointer != pointer_window)
9373 /* Either a toplevel crossing notify that ended up inside a child window,
9374 or a motion notify that got into another child window */
9376 /* Different than last time, send crossing events */
9377 _gdk_synthesize_crossing_events (display,
9378 pointer_info->window_under_pointer,
9380 device, source_device,
9381 GDK_CROSSING_NORMAL,
9382 toplevel_x, toplevel_y,
9385 serial, non_linear);
9386 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9388 else if (source_event->type == GDK_MOTION_NOTIFY ||
9389 source_event->type == GDK_TOUCH_UPDATE)
9391 GdkWindow *event_win;
9394 GdkEventSequence *sequence;
9396 sequence = gdk_event_get_event_sequence (source_event);
9398 event_win = get_event_window (display,
9405 _gdk_event_get_pointer_emulated (source_event),
9408 if (event_type == GDK_TOUCH_UPDATE)
9410 if (_gdk_event_get_pointer_emulated (source_event))
9412 /* Touch events emulating pointer events are transformed back
9413 * to pointer events if:
9414 * 1 - The event window doesn't select for touch events
9415 * 2 - There's no touch grab for this sequence, which means
9416 * it was started as a pointer sequence, but a device
9417 * grab added touch events afterwards, the sequence must
9418 * not mutate in this case.
9420 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9421 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9422 event_type = GDK_MOTION_NOTIFY;
9424 else if ((evmask & GDK_TOUCH_MASK) == 0)
9428 if (is_touch_type (source_event->type) && !is_touch_type (event_type))
9429 state |= GDK_BUTTON1_MASK;
9432 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9433 gdk_window_get_device_events (event_win, device) == 0)
9436 /* The last device to interact with the window was a touch device,
9437 * which synthesized a leave notify event, so synthesize another enter
9438 * notify to tell the pointer is on the window.
9440 if (need_synthetic_enter)
9441 _gdk_synthesize_crossing_events (display,
9442 NULL, pointer_window,
9443 device, source_device,
9444 GDK_CROSSING_DEVICE_SWITCH,
9445 toplevel_x, toplevel_y,
9452 event_type == GDK_MOTION_NOTIFY &&
9453 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9455 gulong *device_serial;
9457 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9459 if (!device_serial ||
9460 (*device_serial != 0 &&
9461 serial < *device_serial))
9462 event_win = NULL; /* Ignore event */
9466 *device_serial = G_MAXULONG;
9473 if (!display->ignore_core_events)
9475 event = gdk_event_new (event_type);
9476 event->any.window = g_object_ref (event_win);
9477 event->any.send_event = source_event->any.send_event;
9479 gdk_event_set_device (event, gdk_event_get_device (source_event));
9480 gdk_event_set_source_device (event, source_device);
9482 if (event_type == GDK_TOUCH_UPDATE)
9484 event->touch.time = time_;
9485 event->touch.state = state | GDK_BUTTON1_MASK;
9486 event->touch.sequence = source_event->touch.sequence;
9487 convert_toplevel_coords_to_window (event_win,
9488 toplevel_x, toplevel_y,
9489 &event->touch.x, &event->touch.y);
9490 gdk_event_get_root_coords (source_event,
9491 &event->touch.x_root,
9492 &event->touch.y_root);
9494 event->touch.axes = g_memdup (source_event->touch.axes,
9495 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9499 event->motion.time = time_;
9500 event->motion.state = state;
9501 event->motion.is_hint = is_hint;
9503 convert_toplevel_coords_to_window (event_win,
9504 toplevel_x, toplevel_y,
9505 &event->motion.x, &event->motion.y);
9506 gdk_event_get_root_coords (source_event,
9507 &event->motion.x_root,
9508 &event->motion.y_root);
9510 if (is_touch_type (source_event->type))
9511 event->motion.axes = g_memdup (source_event->touch.axes,
9512 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9514 event->motion.axes = g_memdup (source_event->motion.axes,
9515 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9518 /* Just insert the event */
9519 _gdk_event_queue_insert_after (gdk_window_get_display (event_win),
9520 source_event, event);
9524 /* unlink all move events from queue.
9525 We handle our own, including our emulated masks. */
9529 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9530 GDK_BUTTON2_MASK | \
9531 GDK_BUTTON3_MASK | \
9532 GDK_BUTTON4_MASK | \
9536 proxy_button_event (GdkEvent *source_event,
9539 GdkWindow *toplevel_window, *event_window;
9540 GdkWindow *event_win;
9541 GdkWindow *pointer_window;
9544 GdkPointerWindowInfo *pointer_info;
9545 GdkDeviceGrabInfo *pointer_grab;
9549 gdouble toplevel_x, toplevel_y;
9550 GdkDisplay *display;
9552 GdkDevice *device, *source_device;
9553 GdkEventMask evmask;
9554 GdkEventSequence *sequence;
9556 type = source_event->any.type;
9557 event_window = source_event->any.window;
9558 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9559 gdk_event_get_state (source_event, &state);
9560 time_ = gdk_event_get_time (source_event);
9561 device = gdk_event_get_device (source_event);
9562 source_device = gdk_event_get_source_device (source_event);
9563 display = gdk_window_get_display (source_event->any.window);
9564 toplevel_window = convert_native_coords_to_toplevel (event_window,
9565 toplevel_x, toplevel_y,
9566 &toplevel_x, &toplevel_y);
9568 sequence = gdk_event_get_event_sequence (source_event);
9570 pointer_info = _gdk_display_get_pointer_info (display, device);
9571 pointer_grab = _gdk_display_has_device_grab (display, device, serial);
9573 if ((type == GDK_BUTTON_PRESS ||
9574 type == GDK_TOUCH_BEGIN) &&
9575 !source_event->any.send_event &&
9577 (type == GDK_TOUCH_BEGIN && pointer_grab->implicit &&
9578 !_gdk_event_get_pointer_emulated (source_event))))
9581 _gdk_window_find_descendant_at (toplevel_window,
9582 toplevel_x, toplevel_y,
9585 /* Find the event window, that gets the grab */
9588 (parent = get_event_parent (w)) != NULL &&
9589 parent->window_type != GDK_WINDOW_ROOT)
9591 if (w->event_mask & GDK_BUTTON_PRESS_MASK &&
9592 (type == GDK_BUTTON_PRESS ||
9593 _gdk_event_get_pointer_emulated (source_event)))
9596 if (type == GDK_TOUCH_BEGIN &&
9597 w->event_mask & GDK_TOUCH_MASK)
9606 if (type == GDK_TOUCH_BEGIN &&
9607 pointer_window->event_mask & GDK_TOUCH_MASK)
9609 _gdk_display_add_touch_grab (display, device, sequence,
9610 pointer_window, event_window,
9611 gdk_window_get_events (pointer_window),
9614 else if (type == GDK_BUTTON_PRESS ||
9615 _gdk_event_get_pointer_emulated (source_event))
9617 _gdk_display_add_device_grab (display,
9623 gdk_window_get_events (pointer_window),
9627 _gdk_display_device_grab_update (display, device,
9628 source_device, serial);
9633 pointer_window = get_pointer_window (display, toplevel_window, device,
9634 toplevel_x, toplevel_y,
9637 event_win = get_event_window (display,
9643 _gdk_event_get_pointer_emulated (source_event),
9646 if (type == GDK_TOUCH_BEGIN || type == GDK_TOUCH_END)
9648 if (_gdk_event_get_pointer_emulated (source_event))
9650 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9651 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9653 if (type == GDK_TOUCH_BEGIN)
9654 type = GDK_BUTTON_PRESS;
9655 else if (type == GDK_TOUCH_END)
9656 type = GDK_BUTTON_RELEASE;
9659 else if ((evmask & GDK_TOUCH_MASK) == 0)
9663 if (source_event->type == GDK_TOUCH_END && !is_touch_type (type))
9664 state |= GDK_BUTTON1_MASK;
9666 if (event_win == NULL || display->ignore_core_events)
9669 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9670 gdk_window_get_device_events (event_win, device) == 0)
9673 if ((type == GDK_BUTTON_PRESS ||
9674 (type == GDK_TOUCH_BEGIN &&
9675 _gdk_event_get_pointer_emulated (source_event))) &&
9676 pointer_info->need_touch_press_enter)
9678 GdkCrossingMode mode;
9680 /* The last device to interact with the window was a touch device,
9681 * which synthesized a leave notify event, so synthesize another enter
9682 * notify to tell the pointer is on the window.
9684 if (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN ||
9685 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHPAD)
9686 mode = GDK_CROSSING_TOUCH_BEGIN;
9688 mode = GDK_CROSSING_DEVICE_SWITCH;
9690 pointer_info->need_touch_press_enter = FALSE;
9691 _gdk_synthesize_crossing_events (display,
9693 pointer_info->window_under_pointer,
9694 device, source_device, mode,
9695 toplevel_x, toplevel_y,
9696 state, time_, source_event,
9700 event = _gdk_make_event (event_win, type, source_event, FALSE);
9704 case GDK_BUTTON_PRESS:
9705 case GDK_BUTTON_RELEASE:
9706 event->button.button = source_event->button.button;
9707 convert_toplevel_coords_to_window (event_win,
9708 toplevel_x, toplevel_y,
9709 &event->button.x, &event->button.y);
9710 gdk_event_get_root_coords (source_event,
9711 &event->button.x_root,
9712 &event->button.y_root);
9713 gdk_event_set_device (event, gdk_event_get_device (source_event));
9714 gdk_event_set_source_device (event, source_device);
9716 if (type == GDK_BUTTON_RELEASE)
9717 event->button.state |= GDK_BUTTON1_MASK;
9719 if (is_touch_type (source_event->type))
9721 event->button.button = 1;
9722 event->button.axes = g_memdup (source_event->touch.axes,
9723 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9727 event->button.button = source_event->button.button;
9728 event->button.axes = g_memdup (source_event->button.axes,
9729 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9732 if (type == GDK_BUTTON_PRESS)
9733 _gdk_event_button_generate (display, event);
9734 else if ((type == GDK_BUTTON_RELEASE ||
9735 (type == GDK_TOUCH_END &&
9736 _gdk_event_get_pointer_emulated (source_event))) &&
9737 pointer_window == pointer_info->window_under_pointer &&
9738 (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN ||
9739 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHPAD))
9741 /* Synthesize a leave notify event
9742 * whenever a touch device is released
9744 pointer_info->need_touch_press_enter = TRUE;
9745 _gdk_synthesize_crossing_events (display,
9746 pointer_window, NULL,
9747 device, source_device,
9748 GDK_CROSSING_TOUCH_END,
9749 toplevel_x, toplevel_y,
9755 case GDK_TOUCH_BEGIN:
9757 convert_toplevel_coords_to_window (event_win,
9758 toplevel_x, toplevel_y,
9759 &event->button.x, &event->button.y);
9760 gdk_event_get_root_coords (source_event,
9761 &event->touch.x_root,
9762 &event->touch.y_root);
9763 event->touch.state = state;
9764 event->touch.device = source_event->touch.device;
9765 event->touch.axes = g_memdup (source_event->touch.axes,
9766 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9767 event->touch.sequence = source_event->touch.sequence;
9769 gdk_event_set_source_device (event, source_device);
9771 if ((type == GDK_TOUCH_END &&
9772 _gdk_event_get_pointer_emulated (source_event)) &&
9773 pointer_window == pointer_info->window_under_pointer &&
9774 (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN ||
9775 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHPAD))
9777 /* Synthesize a leave notify event
9778 * whenever a touch device is released
9780 pointer_info->need_touch_press_enter = TRUE;
9781 _gdk_synthesize_crossing_events (display,
9782 pointer_window, NULL,
9783 device, source_device,
9784 GDK_CROSSING_TOUCH_END,
9785 toplevel_x, toplevel_y,
9792 event->scroll.direction = source_event->scroll.direction;
9793 convert_toplevel_coords_to_window (event_win,
9794 toplevel_x, toplevel_y,
9795 &event->scroll.x, &event->scroll.y);
9796 event->scroll.x_root = source_event->scroll.x_root;
9797 event->scroll.y_root = source_event->scroll.y_root;
9798 event->scroll.state = state;
9799 event->scroll.device = source_event->scroll.device;
9800 gdk_event_set_source_device (event, source_device);
9807 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9810 #ifdef DEBUG_WINDOW_PRINTING
9812 gdk_window_print (GdkWindow *window,
9816 const char *window_types[] = {
9826 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9827 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9828 window->x, window->y,
9829 window->width, window->height
9832 if (gdk_window_has_impl (window))
9834 #ifdef GDK_WINDOWING_X11
9835 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9839 if (window->window_type != GDK_WINDOW_CHILD)
9840 g_print (" %s", window_types[window->window_type]);
9842 if (window->input_only)
9843 g_print (" input-only");
9846 g_print (" shaped");
9848 if (!gdk_window_is_visible ((GdkWindow *)window))
9849 g_print (" hidden");
9851 g_print (" abs[%d,%d]",
9852 window->abs_x, window->abs_y);
9854 cairo_region_get_extents (window->clip_region, &r);
9855 if (cairo_region_is_empty (window->clip_region))
9856 g_print (" clipbox[empty]");
9858 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9865 gdk_window_print_tree (GdkWindow *window,
9867 gboolean include_input_only)
9871 if (window->input_only && !include_input_only)
9874 gdk_window_print (window, indent);
9876 for (l = window->children; l != NULL; l = l->next)
9877 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9880 #endif /* DEBUG_WINDOW_PRINTING */
9883 _gdk_windowing_got_event (GdkDisplay *display,
9888 GdkWindow *event_window;
9890 gboolean unlink_event;
9891 GdkDeviceGrabInfo *button_release_grab;
9892 GdkPointerWindowInfo *pointer_info = NULL;
9893 GdkDevice *device, *source_device;
9894 gboolean is_toplevel;
9896 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9897 display->last_event_time = gdk_event_get_time (event);
9899 device = gdk_event_get_device (event);
9900 source_device = gdk_event_get_source_device (event);
9906 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
9908 pointer_info = _gdk_display_get_pointer_info (display, device);
9910 if (source_device != pointer_info->last_slave &&
9911 gdk_device_get_device_type (source_device) == GDK_DEVICE_TYPE_SLAVE)
9912 pointer_info->last_slave = source_device;
9914 source_device = pointer_info->last_slave;
9917 g_object_get (device, "input-mode", &mode, NULL);
9918 _gdk_display_device_grab_update (display, device, source_device, serial);
9920 if (mode == GDK_MODE_DISABLED ||
9921 !_gdk_display_check_grab_ownership (display, device, serial))
9923 /* Device events are blocked by another
9924 * device grab, or the device is disabled
9926 unlink_event = TRUE;
9931 event_window = event->any.window;
9935 #ifdef DEBUG_WINDOW_PRINTING
9936 if (event->type == GDK_KEY_PRESS &&
9937 (event->key.keyval == 0xa7 ||
9938 event->key.keyval == 0xbd))
9940 gdk_window_print_tree (event_window, 0, event->key.keyval == 0xbd);
9944 if (event->type == GDK_VISIBILITY_NOTIFY)
9946 event_window->native_visibility = event->visibility.state;
9947 gdk_window_update_visibility_recursively (event_window, event_window);
9951 if (!(is_button_type (event->type) ||
9952 is_motion_type (event->type)) ||
9953 event_window->window_type == GDK_WINDOW_ROOT)
9956 is_toplevel = gdk_window_is_toplevel (event_window);
9958 if ((event->type == GDK_ENTER_NOTIFY ||
9959 event->type == GDK_LEAVE_NOTIFY) &&
9960 (event->crossing.mode == GDK_CROSSING_GRAB ||
9961 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9962 (_gdk_display_has_device_grab (display, device, serial) ||
9963 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9965 /* We synthesize all crossing events due to grabs ourselves,
9966 * so we ignore the native ones caused by our native pointer_grab
9967 * calls. Otherwise we would proxy these crossing event and cause
9968 * multiple copies of crossing events for grabs.
9970 * We do want to handle grabs from other clients though, as for
9971 * instance alt-tab in metacity causes grabs like these and
9972 * we want to handle those. Thus the has_pointer_grab check.
9974 * Implicit grabs on child windows create some grabbing events
9975 * that are sent before the button press. This means we can't
9976 * detect these with the has_pointer_grab check (as the implicit
9977 * grab is only noticed when we get button press event), so we
9978 * detect these events by checking for INFERIOR enter or leave
9979 * events. These should never be a problem to filter out.
9982 /* We ended up in this window after some (perhaps other clients)
9983 * grab, so update the toplevel_under_window state
9986 event->type == GDK_ENTER_NOTIFY &&
9987 event->crossing.mode == GDK_CROSSING_UNGRAB)
9989 if (pointer_info->toplevel_under_pointer)
9990 g_object_unref (pointer_info->toplevel_under_pointer);
9991 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9994 unlink_event = TRUE;
9998 /* Track toplevel_under_pointer */
10001 if (event->type == GDK_ENTER_NOTIFY &&
10002 event->crossing.detail != GDK_NOTIFY_INFERIOR)
10004 if (pointer_info->toplevel_under_pointer)
10005 g_object_unref (pointer_info->toplevel_under_pointer);
10006 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
10008 else if (event->type == GDK_LEAVE_NOTIFY &&
10009 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
10010 pointer_info->toplevel_under_pointer == event_window)
10012 if (pointer_info->toplevel_under_pointer)
10013 g_object_unref (pointer_info->toplevel_under_pointer);
10014 pointer_info->toplevel_under_pointer = NULL;
10018 if (pointer_info &&
10019 (!is_touch_type (event->type) ||
10020 _gdk_event_get_pointer_emulated (event)))
10022 guint old_state, old_button;
10024 /* Store last pointer window and position/state */
10025 old_state = pointer_info->state;
10026 old_button = pointer_info->button;
10028 gdk_event_get_coords (event, &x, &y);
10029 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
10030 pointer_info->toplevel_x = x;
10031 pointer_info->toplevel_y = y;
10032 gdk_event_get_state (event, &pointer_info->state);
10034 if (event->type == GDK_BUTTON_PRESS ||
10035 event->type == GDK_BUTTON_RELEASE)
10036 pointer_info->button = event->button.button;
10037 else if (event->type == GDK_TOUCH_BEGIN ||
10038 event->type == GDK_TOUCH_END)
10039 pointer_info->button = 1;
10042 (pointer_info->state != old_state ||
10043 pointer_info->button != old_button))
10044 _gdk_display_enable_motion_hints (display, device);
10047 unlink_event = FALSE;
10048 if (is_motion_type (event->type))
10049 unlink_event = proxy_pointer_event (display, event, serial);
10050 else if (is_button_type (event->type))
10051 unlink_event = proxy_button_event (event, serial);
10053 if ((event->type == GDK_BUTTON_RELEASE ||
10054 event->type == GDK_TOUCH_END) &&
10055 !event->any.send_event)
10057 GdkEventSequence *sequence;
10059 sequence = gdk_event_get_event_sequence (event);
10060 if (event->type == GDK_TOUCH_END && sequence)
10062 _gdk_display_end_touch_grab (display, device, sequence);
10065 if (event->type == GDK_BUTTON_RELEASE ||
10066 _gdk_event_get_pointer_emulated (event))
10068 button_release_grab =
10069 _gdk_display_has_device_grab (display, device, serial);
10071 if (button_release_grab &&
10072 button_release_grab->implicit &&
10073 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
10075 button_release_grab->serial_end = serial;
10076 button_release_grab->implicit_ungrab = FALSE;
10077 _gdk_display_device_grab_update (display, device, source_device, serial);
10085 _gdk_event_queue_remove_link (display, event_link);
10086 g_list_free_1 (event_link);
10087 gdk_event_free (event);
10092 * gdk_window_create_similar_surface:
10093 * @window: window to make new surface similar to
10094 * @content: the content for the new surface
10095 * @width: width of the new surface
10096 * @height: height of the new surface
10098 * Create a new surface that is as compatible as possible with the
10099 * given @window. For example the new surface will have the same
10100 * fallback resolution and font options as @window. Generally, the new
10101 * surface will also use the same backend as @window, unless that is
10102 * not possible for some reason. The type of the returned surface may
10103 * be examined with cairo_surface_get_type().
10105 * Initially the surface contents are all 0 (transparent if contents
10106 * have transparency, black otherwise.)
10108 * Returns: a pointer to the newly allocated surface. The caller
10109 * owns the surface and should call cairo_surface_destroy() when done
10112 * This function always returns a valid pointer, but it will return a
10113 * pointer to a "nil" surface if @other is already in an error state
10114 * or any other error occurs.
10119 gdk_window_create_similar_surface (GdkWindow * window,
10120 cairo_content_t content,
10124 cairo_surface_t *window_surface, *surface;
10126 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
10128 window_surface = _gdk_window_ref_cairo_surface (window);
10130 switch (_gdk_rendering_mode)
10132 case GDK_RENDERING_MODE_RECORDING:
10134 cairo_rectangle_t rect = { 0, 0, width, height };
10135 surface = cairo_recording_surface_create (content, &rect);
10138 case GDK_RENDERING_MODE_IMAGE:
10139 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
10140 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
10143 case GDK_RENDERING_MODE_SIMILAR:
10145 surface = cairo_surface_create_similar (window_surface,
10151 cairo_surface_destroy (window_surface);
10157 * gdk_window_focus:
10158 * @window: a #GdkWindow
10159 * @timestamp: timestamp of the event triggering the window focus
10161 * Sets keyboard focus to @window. In most cases, gtk_window_present()
10162 * should be used on a #GtkWindow, rather than calling this function.
10166 gdk_window_focus (GdkWindow *window,
10169 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
10173 * gdk_window_set_type_hint:
10174 * @window: A toplevel #GdkWindow
10175 * @hint: A hint of the function this window will have
10177 * The application can use this call to provide a hint to the window
10178 * manager about the functionality of a window. The window manager
10179 * can use this information when determining the decoration and behaviour
10182 * The hint must be set before the window is mapped.
10185 gdk_window_set_type_hint (GdkWindow *window,
10186 GdkWindowTypeHint hint)
10188 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
10192 * gdk_window_get_type_hint:
10193 * @window: A toplevel #GdkWindow
10195 * This function returns the type hint set for a window.
10197 * Return value: The type hint set for @window
10202 gdk_window_get_type_hint (GdkWindow *window)
10204 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
10208 * gdk_window_set_modal_hint:
10209 * @window: A toplevel #GdkWindow
10210 * @modal: %TRUE if the window is modal, %FALSE otherwise.
10212 * The application can use this hint to tell the window manager
10213 * that a certain window has modal behaviour. The window manager
10214 * can use this information to handle modal windows in a special
10217 * You should only use this on windows for which you have
10218 * previously called gdk_window_set_transient_for()
10221 gdk_window_set_modal_hint (GdkWindow *window,
10224 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
10228 * gdk_window_set_skip_taskbar_hint:
10229 * @window: a toplevel #GdkWindow
10230 * @skips_taskbar: %TRUE to skip the taskbar
10232 * Toggles whether a window should appear in a task list or window
10233 * list. If a window's semantic type as specified with
10234 * gdk_window_set_type_hint() already fully describes the window, this
10235 * function should <emphasis>not</emphasis> be called in addition,
10236 * instead you should allow the window to be treated according to
10237 * standard policy for its semantic type.
10242 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
10243 gboolean skips_taskbar)
10245 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
10249 * gdk_window_set_skip_pager_hint:
10250 * @window: a toplevel #GdkWindow
10251 * @skips_pager: %TRUE to skip the pager
10253 * Toggles whether a window should appear in a pager (workspace
10254 * switcher, or other desktop utility program that displays a small
10255 * thumbnail representation of the windows on the desktop). If a
10256 * window's semantic type as specified with gdk_window_set_type_hint()
10257 * already fully describes the window, this function should
10258 * <emphasis>not</emphasis> be called in addition, instead you should
10259 * allow the window to be treated according to standard policy for
10260 * its semantic type.
10265 gdk_window_set_skip_pager_hint (GdkWindow *window,
10266 gboolean skips_pager)
10268 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
10272 * gdk_window_set_urgency_hint:
10273 * @window: a toplevel #GdkWindow
10274 * @urgent: %TRUE if the window is urgent
10276 * Toggles whether a window needs the user's
10277 * urgent attention.
10282 gdk_window_set_urgency_hint (GdkWindow *window,
10285 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
10289 * gdk_window_set_geometry_hints:
10290 * @window: a toplevel #GdkWindow
10291 * @geometry: geometry hints
10292 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
10294 * Sets the geometry hints for @window. Hints flagged in @geom_mask
10295 * are set, hints not flagged in @geom_mask are unset.
10296 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
10298 * This function provides hints to the windowing system about
10299 * acceptable sizes for a toplevel window. The purpose of
10300 * this is to constrain user resizing, but the windowing system
10301 * will typically (but is not required to) also constrain the
10302 * current size of the window to the provided values and
10303 * constrain programatic resizing via gdk_window_resize() or
10304 * gdk_window_move_resize().
10306 * Note that on X11, this effect has no effect on windows
10307 * of type %GDK_WINDOW_TEMP or windows where override redirect
10308 * has been turned on via gdk_window_set_override_redirect()
10309 * since these windows are not resizable by the user.
10311 * Since you can't count on the windowing system doing the
10312 * constraints for programmatic resizes, you should generally
10313 * call gdk_window_constrain_size() yourself to determine
10314 * appropriate sizes.
10318 gdk_window_set_geometry_hints (GdkWindow *window,
10319 const GdkGeometry *geometry,
10320 GdkWindowHints geom_mask)
10322 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
10326 * gdk_window_set_title:
10327 * @window: a toplevel #GdkWindow
10328 * @title: title of @window
10330 * Sets the title of a toplevel window, to be displayed in the titlebar.
10331 * If you haven't explicitly set the icon name for the window
10332 * (using gdk_window_set_icon_name()), the icon name will be set to
10333 * @title as well. @title must be in UTF-8 encoding (as with all
10334 * user-readable strings in GDK/GTK+). @title may not be %NULL.
10337 gdk_window_set_title (GdkWindow *window,
10338 const gchar *title)
10340 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
10344 * gdk_window_set_role:
10345 * @window: a toplevel #GdkWindow
10346 * @role: a string indicating its role
10348 * When using GTK+, typically you should use gtk_window_set_role() instead
10349 * of this low-level function.
10351 * The window manager and session manager use a window's role to
10352 * distinguish it from other kinds of window in the same application.
10353 * When an application is restarted after being saved in a previous
10354 * session, all windows with the same title and role are treated as
10355 * interchangeable. So if you have two windows with the same title
10356 * that should be distinguished for session management purposes, you
10357 * should set the role on those windows. It doesn't matter what string
10358 * you use for the role, as long as you have a different role for each
10359 * non-interchangeable kind of window.
10363 gdk_window_set_role (GdkWindow *window,
10366 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
10370 * gdk_window_set_startup_id:
10371 * @window: a toplevel #GdkWindow
10372 * @startup_id: a string with startup-notification identifier
10374 * When using GTK+, typically you should use gtk_window_set_startup_id()
10375 * instead of this low-level function.
10381 gdk_window_set_startup_id (GdkWindow *window,
10382 const gchar *startup_id)
10384 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
10388 * gdk_window_set_transient_for:
10389 * @window: a toplevel #GdkWindow
10390 * @parent: another toplevel #GdkWindow
10392 * Indicates to the window manager that @window is a transient dialog
10393 * associated with the application window @parent. This allows the
10394 * window manager to do things like center @window on @parent and
10395 * keep @window above @parent.
10397 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10401 gdk_window_set_transient_for (GdkWindow *window,
10404 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10408 * gdk_window_get_root_origin:
10409 * @window: a toplevel #GdkWindow
10410 * @x: (out): return location for X position of window frame
10411 * @y: (out): return location for Y position of window frame
10413 * Obtains the top-left corner of the window manager frame in root
10414 * window coordinates.
10418 gdk_window_get_root_origin (GdkWindow *window,
10422 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10426 * gdk_window_get_frame_extents:
10427 * @window: a toplevel #GdkWindow
10428 * @rect: rectangle to fill with bounding box of the window frame
10430 * Obtains the bounding box of the window, including window manager
10431 * titlebar/borders if any. The frame position is given in root window
10432 * coordinates. To get the position of the window itself (rather than
10433 * the frame) in root window coordinates, use gdk_window_get_origin().
10437 gdk_window_get_frame_extents (GdkWindow *window,
10438 GdkRectangle *rect)
10440 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10444 * gdk_window_set_override_redirect:
10445 * @window: a toplevel #GdkWindow
10446 * @override_redirect: %TRUE if window should be override redirect
10448 * An override redirect window is not under the control of the window manager.
10449 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10450 * be entirely under the control of the application. The window manager
10451 * can't see the override redirect window at all.
10453 * Override redirect should only be used for short-lived temporary
10454 * windows, such as popup menus. #GtkMenu uses an override redirect
10455 * window in its implementation, for example.
10459 gdk_window_set_override_redirect (GdkWindow *window,
10460 gboolean override_redirect)
10462 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10466 * gdk_window_set_accept_focus:
10467 * @window: a toplevel #GdkWindow
10468 * @accept_focus: %TRUE if the window should receive input focus
10470 * Setting @accept_focus to %FALSE hints the desktop environment that the
10471 * window doesn't want to receive input focus.
10473 * On X, it is the responsibility of the window manager to interpret this
10474 * hint. ICCCM-compliant window manager usually respect it.
10479 gdk_window_set_accept_focus (GdkWindow *window,
10480 gboolean accept_focus)
10482 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10486 * gdk_window_set_focus_on_map:
10487 * @window: a toplevel #GdkWindow
10488 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10490 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10491 * window doesn't want to receive input focus when it is mapped.
10492 * focus_on_map should be turned off for windows that aren't triggered
10493 * interactively (such as popups from network activity).
10495 * On X, it is the responsibility of the window manager to interpret
10496 * this hint. Window managers following the freedesktop.org window
10497 * manager extension specification should respect it.
10502 gdk_window_set_focus_on_map (GdkWindow *window,
10503 gboolean focus_on_map)
10505 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10509 * gdk_window_set_icon_list:
10510 * @window: The #GdkWindow toplevel window to set the icon of.
10511 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10512 * A list of pixbufs, of different sizes.
10514 * Sets a list of icons for the window. One of these will be used
10515 * to represent the window when it has been iconified. The icon is
10516 * usually shown in an icon box or some sort of task bar. Which icon
10517 * size is shown depends on the window manager. The window manager
10518 * can scale the icon but setting several size icons can give better
10519 * image quality since the window manager may only need to scale the
10520 * icon by a small amount or not at all.
10524 gdk_window_set_icon_list (GdkWindow *window,
10527 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10531 * gdk_window_set_icon_name:
10532 * @window: a toplevel #GdkWindow
10533 * @name: (allow-none): name of window while iconified (minimized)
10535 * Windows may have a name used while minimized, distinct from the
10536 * name they display in their titlebar. Most of the time this is a bad
10537 * idea from a user interface standpoint. But you can set such a name
10538 * with this function, if you like.
10540 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10541 * will not update the icon title.
10543 * Using %NULL for @name unsets the icon title; further calls to
10544 * gdk_window_set_title() will again update the icon title as well.
10547 gdk_window_set_icon_name (GdkWindow *window,
10550 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10554 * gdk_window_iconify:
10555 * @window: a toplevel #GdkWindow
10557 * Asks to iconify (minimize) @window. The window manager may choose
10558 * to ignore the request, but normally will honor it. Using
10559 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10561 * This function only makes sense when @window is a toplevel window.
10565 gdk_window_iconify (GdkWindow *window)
10567 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10571 * gdk_window_deiconify:
10572 * @window: a toplevel #GdkWindow
10574 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10575 * choose to ignore the request to deiconify. When using GTK+,
10576 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10577 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10578 * unminimizes it, and puts it on the current desktop.
10582 gdk_window_deiconify (GdkWindow *window)
10584 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10588 * gdk_window_stick:
10589 * @window: a toplevel #GdkWindow
10591 * "Pins" a window such that it's on all workspaces and does not scroll
10592 * with viewports, for window managers that have scrollable viewports.
10593 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10595 * On the X11 platform, this function depends on window manager
10596 * support, so may have no effect with many window managers. However,
10597 * GDK will do the best it can to convince the window manager to stick
10598 * the window. For window managers that don't support this operation,
10599 * there's nothing you can do to force it to happen.
10603 gdk_window_stick (GdkWindow *window)
10605 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10609 * gdk_window_unstick:
10610 * @window: a toplevel #GdkWindow
10612 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10613 * and gtk_window_unstick().
10617 gdk_window_unstick (GdkWindow *window)
10619 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10623 * gdk_window_maximize:
10624 * @window: a toplevel #GdkWindow
10626 * Maximizes the window. If the window was already maximized, then
10627 * this function does nothing.
10629 * On X11, asks the window manager to maximize @window, if the window
10630 * manager supports this operation. Not all window managers support
10631 * this, and some deliberately ignore it or don't have a concept of
10632 * "maximized"; so you can't rely on the maximization actually
10633 * happening. But it will happen with most standard window managers,
10634 * and GDK makes a best effort to get it to happen.
10636 * On Windows, reliably maximizes the window.
10640 gdk_window_maximize (GdkWindow *window)
10642 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10646 * gdk_window_unmaximize:
10647 * @window: a toplevel #GdkWindow
10649 * Unmaximizes the window. If the window wasn't maximized, then this
10650 * function does nothing.
10652 * On X11, asks the window manager to unmaximize @window, if the
10653 * window manager supports this operation. Not all window managers
10654 * support this, and some deliberately ignore it or don't have a
10655 * concept of "maximized"; so you can't rely on the unmaximization
10656 * actually happening. But it will happen with most standard window
10657 * managers, and GDK makes a best effort to get it to happen.
10659 * On Windows, reliably unmaximizes the window.
10663 gdk_window_unmaximize (GdkWindow *window)
10665 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10669 * gdk_window_fullscreen:
10670 * @window: a toplevel #GdkWindow
10672 * Moves the window into fullscreen mode. This means the
10673 * window covers the entire screen and is above any panels
10676 * If the window was already fullscreen, then this function does nothing.
10678 * On X11, asks the window manager to put @window in a fullscreen
10679 * state, if the window manager supports this operation. Not all
10680 * window managers support this, and some deliberately ignore it or
10681 * don't have a concept of "fullscreen"; so you can't rely on the
10682 * fullscreenification actually happening. But it will happen with
10683 * most standard window managers, and GDK makes a best effort to get
10689 gdk_window_fullscreen (GdkWindow *window)
10691 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10695 * gdk_window_unfullscreen:
10696 * @window: a toplevel #GdkWindow
10698 * Moves the window out of fullscreen mode. If the window was not
10699 * fullscreen, does nothing.
10701 * On X11, asks the window manager to move @window out of the fullscreen
10702 * state, if the window manager supports this operation. Not all
10703 * window managers support this, and some deliberately ignore it or
10704 * don't have a concept of "fullscreen"; so you can't rely on the
10705 * unfullscreenification actually happening. But it will happen with
10706 * most standard window managers, and GDK makes a best effort to get
10712 gdk_window_unfullscreen (GdkWindow *window)
10714 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10718 * gdk_window_set_keep_above:
10719 * @window: a toplevel #GdkWindow
10720 * @setting: whether to keep @window above other windows
10722 * Set if @window must be kept above other windows. If the
10723 * window was already above, then this function does nothing.
10725 * On X11, asks the window manager to keep @window above, if the window
10726 * manager supports this operation. Not all window managers support
10727 * this, and some deliberately ignore it or don't have a concept of
10728 * "keep above"; so you can't rely on the window being kept above.
10729 * But it will happen with most standard window managers,
10730 * and GDK makes a best effort to get it to happen.
10735 gdk_window_set_keep_above (GdkWindow *window,
10738 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10742 * gdk_window_set_keep_below:
10743 * @window: a toplevel #GdkWindow
10744 * @setting: whether to keep @window below other windows
10746 * Set if @window must be kept below other windows. If the
10747 * window was already below, then this function does nothing.
10749 * On X11, asks the window manager to keep @window below, if the window
10750 * manager supports this operation. Not all window managers support
10751 * this, and some deliberately ignore it or don't have a concept of
10752 * "keep below"; so you can't rely on the window being kept below.
10753 * But it will happen with most standard window managers,
10754 * and GDK makes a best effort to get it to happen.
10759 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10761 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10765 * gdk_window_get_group:
10766 * @window: a toplevel #GdkWindow
10768 * Returns the group leader window for @window. See gdk_window_set_group().
10770 * Return value: (transfer none): the group leader window for @window
10775 gdk_window_get_group (GdkWindow *window)
10777 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10781 * gdk_window_set_group:
10782 * @window: a toplevel #GdkWindow
10783 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10785 * Sets the group leader window for @window. By default,
10786 * GDK sets the group leader for all toplevel windows
10787 * to a global window implicitly created by GDK. With this function
10788 * you can override this default.
10790 * The group leader window allows the window manager to distinguish
10791 * all windows that belong to a single application. It may for example
10792 * allow users to minimize/unminimize all windows belonging to an
10793 * application at once. You should only set a non-default group window
10794 * if your application pretends to be multiple applications.
10797 gdk_window_set_group (GdkWindow *window,
10800 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10804 * gdk_window_set_decorations:
10805 * @window: a toplevel #GdkWindow
10806 * @decorations: decoration hint mask
10808 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10809 * This function sets the traditional Motif window manager hints that tell the
10810 * window manager which decorations you would like your window to have.
10811 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10812 * using the GDK function directly.
10814 * The @decorations argument is the logical OR of the fields in
10815 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10816 * mask, the other bits indicate which decorations should be turned off.
10817 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10818 * which decorations should be turned on.
10820 * Most window managers honor a decorations hint of 0 to disable all decorations,
10821 * but very few honor all possible combinations of bits.
10825 gdk_window_set_decorations (GdkWindow *window,
10826 GdkWMDecoration decorations)
10828 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10832 * gdk_window_get_decorations:
10833 * @window: The toplevel #GdkWindow to get the decorations from
10834 * @decorations: (out): The window decorations will be written here
10836 * Returns the decorations set on the GdkWindow with
10837 * gdk_window_set_decorations().
10839 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10842 gdk_window_get_decorations(GdkWindow *window,
10843 GdkWMDecoration *decorations)
10845 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10849 * gdk_window_set_functions:
10850 * @window: a toplevel #GdkWindow
10851 * @functions: bitmask of operations to allow on @window
10853 * Sets hints about the window management functions to make available
10854 * via buttons on the window frame.
10856 * On the X backend, this function sets the traditional Motif window
10857 * manager hint for this purpose. However, few window managers do
10858 * anything reliable or interesting with this hint. Many ignore it
10861 * The @functions argument is the logical OR of values from the
10862 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
10863 * then the other bits indicate which functions to disable; if
10864 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
10869 gdk_window_set_functions (GdkWindow *window,
10870 GdkWMFunction functions)
10872 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
10876 * gdk_window_begin_resize_drag_for_device:
10877 * @window: a toplevel #GdkWindow
10878 * @edge: the edge or corner from which the drag is started
10879 * @device: the device used for the operation
10880 * @button: the button being used to drag
10881 * @root_x: root window X coordinate of mouse click that began the drag
10882 * @root_y: root window Y coordinate of mouse click that began the drag
10883 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10885 * Begins a window resize operation (for a toplevel window).
10886 * You might use this function to implement a "window resize grip," for
10887 * example; in fact #GtkStatusbar uses it. The function works best
10888 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
10889 * fallback implementation for other window managers.
10894 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
10895 GdkWindowEdge edge,
10902 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
10906 * gdk_window_begin_resize_drag:
10907 * @window: a toplevel #GdkWindow
10908 * @edge: the edge or corner from which the drag is started
10909 * @button: the button being used to drag
10910 * @root_x: root window X coordinate of mouse click that began the drag
10911 * @root_y: root window Y coordinate of mouse click that began the drag
10912 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10914 * Begins a window resize operation (for a toplevel window).
10916 * This function assumes that the drag is controlled by the
10917 * client pointer device, use gdk_window_begin_resize_drag_for_device()
10918 * to begin a drag with a different device.
10921 gdk_window_begin_resize_drag (GdkWindow *window,
10922 GdkWindowEdge edge,
10928 GdkDeviceManager *device_manager;
10931 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10932 device = gdk_device_manager_get_client_pointer (device_manager);
10933 gdk_window_begin_resize_drag_for_device (window, edge,
10934 device, button, root_x, root_y, timestamp);
10938 * gdk_window_begin_move_drag_for_device:
10939 * @window: a toplevel #GdkWindow
10940 * @device: the device used for the operation
10941 * @button: the button being used to drag
10942 * @root_x: root window X coordinate of mouse click that began the drag
10943 * @root_y: root window Y coordinate of mouse click that began the drag
10944 * @timestamp: timestamp of mouse click that began the drag
10946 * Begins a window move operation (for a toplevel window).
10947 * You might use this function to implement a "window move grip," for
10948 * example. The function works best with window managers that support
10949 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
10950 * Window Manager Hints</ulink>, but has a fallback implementation for
10951 * other window managers.
10956 gdk_window_begin_move_drag_for_device (GdkWindow *window,
10963 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
10964 device, button, root_x, root_y, timestamp);
10968 * gdk_window_begin_move_drag:
10969 * @window: a toplevel #GdkWindow
10970 * @button: the button being used to drag
10971 * @root_x: root window X coordinate of mouse click that began the drag
10972 * @root_y: root window Y coordinate of mouse click that began the drag
10973 * @timestamp: timestamp of mouse click that began the drag
10975 * Begins a window move operation (for a toplevel window).
10977 * This function assumes that the drag is controlled by the
10978 * client pointer device, use gdk_window_begin_move_drag_for_device()
10979 * to begin a drag with a different device.
10982 gdk_window_begin_move_drag (GdkWindow *window,
10988 GdkDeviceManager *device_manager;
10991 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10992 device = gdk_device_manager_get_client_pointer (device_manager);
10993 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
10997 * gdk_window_enable_synchronized_configure:
10998 * @window: a toplevel #GdkWindow
11000 * Indicates that the application will cooperate with the window
11001 * system in synchronizing the window repaint with the window
11002 * manager during resizing operations. After an application calls
11003 * this function, it must call gdk_window_configure_finished() every
11004 * time it has finished all processing associated with a set of
11005 * Configure events. Toplevel GTK+ windows automatically use this
11008 * On X, calling this function makes @window participate in the
11009 * _NET_WM_SYNC_REQUEST window manager protocol.
11014 gdk_window_enable_synchronized_configure (GdkWindow *window)
11016 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
11020 * gdk_window_configure_finished:
11021 * @window: a toplevel #GdkWindow
11023 * Signal to the window system that the application has finished
11024 * handling Configure events it has received. Window Managers can
11025 * use this to better synchronize the frame repaint with the
11026 * application. GTK+ applications will automatically call this
11027 * function when appropriate.
11029 * This function can only be called if gdk_window_enable_synchronized_configure()
11030 * was called previously.
11035 gdk_window_configure_finished (GdkWindow *window)
11037 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
11041 * gdk_window_set_opacity:
11042 * @window: a top-level #GdkWindow
11043 * @opacity: opacity
11045 * Request the windowing system to make @window partially transparent,
11046 * with opacity 0 being fully transparent and 1 fully opaque. (Values
11047 * of the opacity parameter are clamped to the [0,1] range.)
11049 * On X11, this works only on X screens with a compositing manager
11052 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
11053 * For making non-toplevel windows translucent, see
11054 * gdk_window_set_composited().
11059 gdk_window_set_opacity (GdkWindow *window,
11062 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
11065 /* This function is called when the XWindow is really gone.
11068 gdk_window_destroy_notify (GdkWindow *window)
11070 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
11074 * gdk_window_register_dnd:
11075 * @window: a #GdkWindow.
11077 * Registers a window as a potential drop destination.
11080 gdk_window_register_dnd (GdkWindow *window)
11082 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
11086 * gdk_window_get_drag_protocol:
11087 * @window: the destination window
11088 * @target: (out) (allow-none) (transfer full): location of the window
11089 * where the drop should happen. This may be @window or a proxy window,
11090 * or %NULL if @window does not support Drag and Drop.
11092 * Finds out the DND protocol supported by a window.
11094 * Returns: the supported DND protocol.
11099 gdk_window_get_drag_protocol (GdkWindow *window,
11100 GdkWindow **target)
11102 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
11104 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
11109 * @window: the source window for this drag.
11110 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11111 * as list of #GdkAtoms
11113 * Starts a drag and creates a new drag context for it.
11114 * This function assumes that the drag is controlled by the
11115 * client pointer device, use gdk_drag_begin_for_device() to
11116 * begin a drag with a different device.
11118 * This function is called by the drag source.
11120 * Return value: (transfer full): a newly created #GdkDragContext
11123 gdk_drag_begin (GdkWindow *window,
11126 GdkDeviceManager *device_manager;
11129 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11130 device = gdk_device_manager_get_client_pointer (device_manager);
11132 return gdk_drag_begin_for_device (window, device, targets);
11136 * gdk_drag_begin_for_device:
11137 * @window: the source window for this drag
11138 * @device: the device that controls this drag
11139 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11140 * as list of #GdkAtoms
11142 * Starts a drag and creates a new drag context for it.
11144 * This function is called by the drag source.
11146 * Return value: (transfer full): a newly created #GdkDragContext
11149 gdk_drag_begin_for_device (GdkWindow *window,
11153 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
11157 * gdk_test_render_sync:
11158 * @window: a mapped #GdkWindow
11160 * Retrieves a pixel from @window to force the windowing
11161 * system to carry out any pending rendering commands.
11163 * This function is intended to be used to synchronize with rendering
11164 * pipelines, to benchmark windowing system rendering operations.
11169 gdk_test_render_sync (GdkWindow *window)
11171 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
11175 * gdk_test_simulate_key:
11176 * @window: a #GdkWindow to simulate a key event for
11177 * @x: x coordinate within @window for the key event
11178 * @y: y coordinate within @window for the key event
11179 * @keyval: A GDK keyboard value
11180 * @modifiers: Keyboard modifiers the event is setup with
11181 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
11183 * This function is intended to be used in GTK+ test programs.
11184 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
11185 * the given (@x,@y) coordinates within @window and simulate a
11186 * key press or release event.
11188 * When the mouse pointer is warped to the target location, use
11189 * of this function outside of test programs that run in their
11190 * own virtual windowing system (e.g. Xvfb) is not recommended.
11191 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
11192 * be warped and @window origin will be used as mouse pointer
11193 * location for the event.
11195 * Also, gdk_test_simulate_key() is a fairly low level function,
11196 * for most testing purposes, gtk_test_widget_send_key() is the
11197 * right function to call which will generate a key press event
11198 * followed by its accompanying key release event.
11200 * Returns: whether all actions necessary for a key event simulation
11201 * were carried out successfully
11206 gdk_test_simulate_key (GdkWindow *window,
11210 GdkModifierType modifiers,
11211 GdkEventType key_pressrelease)
11213 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11214 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
11218 * gdk_test_simulate_button:
11219 * @window: a #GdkWindow to simulate a button event for
11220 * @x: x coordinate within @window for the button event
11221 * @y: y coordinate within @window for the button event
11222 * @button: Number of the pointer button for the event, usually 1, 2 or 3
11223 * @modifiers: Keyboard modifiers the event is setup with
11224 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
11226 * This function is intended to be used in GTK+ test programs.
11227 * It will warp the mouse pointer to the given (@x,@y) coordinates
11228 * within @window and simulate a button press or release event.
11229 * Because the mouse pointer needs to be warped to the target
11230 * location, use of this function outside of test programs that
11231 * run in their own virtual windowing system (e.g. Xvfb) is not
11234 * Also, gdk_test_simulate_button() is a fairly low level function,
11235 * for most testing purposes, gtk_test_widget_click() is the right
11236 * function to call which will generate a button press event followed
11237 * by its accompanying button release event.
11239 * Returns: whether all actions necessary for a button event simulation
11240 * were carried out successfully
11245 gdk_test_simulate_button (GdkWindow *window,
11248 guint button, /*1..3*/
11249 GdkModifierType modifiers,
11250 GdkEventType button_pressrelease)
11252 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11253 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
11257 * gdk_property_get:
11258 * @window: a #GdkWindow
11259 * @property: the property to retrieve
11260 * @type: the desired property type, or %GDK_NONE, if any type of data
11261 * is acceptable. If this does not match the actual
11262 * type, then @actual_format and @actual_length will
11263 * be filled in, a warning will be printed to stderr
11264 * and no data will be returned.
11265 * @offset: the offset into the property at which to begin
11266 * retrieving data, in 4 byte units.
11267 * @length: the length of the data to retrieve in bytes. Data is
11268 * considered to be retrieved in 4 byte chunks, so @length
11269 * will be rounded up to the next highest 4 byte boundary
11270 * (so be careful not to pass a value that might overflow
11271 * when rounded up).
11272 * @pdelete: if %TRUE, delete the property after retrieving the
11274 * @actual_property_type: (out) (transfer none): location to store the
11275 * actual type of the property.
11276 * @actual_format: (out): location to store the actual return format of the
11277 * data; either 8, 16 or 32 bits.
11278 * @actual_length: location to store the length of the retrieved data, in
11279 * bytes. Data returned in the 32 bit format is stored
11280 * in a long variable, so the actual number of 32 bit
11281 * elements should be be calculated via
11282 * @actual_length / sizeof(glong) to ensure portability to
11284 * @data: (out) (array length=actual_length) (transfer full): location
11285 * to store a pointer to the data. The retrieved data should be
11286 * freed with g_free() when you are finished using it.
11288 * Retrieves a portion of the contents of a property. If the
11289 * property does not exist, then the function returns %FALSE,
11290 * and %GDK_NONE will be stored in @actual_property_type.
11294 * The XGetWindowProperty() function that gdk_property_get()
11295 * uses has a very confusing and complicated set of semantics.
11296 * Unfortunately, gdk_property_get() makes the situation
11297 * worse instead of better (the semantics should be considered
11298 * undefined), and also prints warnings to stderr in cases where it
11299 * should return a useful error to the program. You are advised to use
11300 * XGetWindowProperty() directly until a replacement function for
11301 * gdk_property_get()
11306 * Returns: %TRUE if data was successfully received and stored
11307 * in @data, otherwise %FALSE.
11310 gdk_property_get (GdkWindow *window,
11316 GdkAtom *actual_property_type,
11317 gint *actual_format_type,
11318 gint *actual_length,
11321 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11322 ->get_property (window, property, type, offset, length, pdelete,
11323 actual_property_type, actual_format_type,
11324 actual_length, data);
11328 * gdk_property_change: (skip)
11329 * @window: a #GdkWindow
11330 * @property: the property to change
11331 * @type: the new type for the property. If @mode is
11332 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11333 * must match the existing type or an error will occur.
11334 * @format: the new format for the property. If @mode is
11335 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11336 * must match the existing format or an error will occur.
11337 * @mode: a value describing how the new data is to be combined
11338 * with the current data.
11339 * @data: the data (a <literal>guchar *</literal>
11340 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
11341 * depending on @format), cast to a <literal>guchar *</literal>.
11342 * @nelements: the number of elements of size determined by the format,
11343 * contained in @data.
11345 * Changes the contents of a property on a window.
11348 gdk_property_change (GdkWindow *window,
11353 const guchar *data,
11356 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11357 ->change_property (window, property, type, format, mode, data, nelements);
11361 * gdk_property_delete:
11362 * @window: a #GdkWindow
11363 * @property: the property to delete
11365 * Deletes a property from a window.
11368 gdk_property_delete (GdkWindow *window,
11371 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);