1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <cairo-gobject.h>
30 #include "gdkwindow.h"
32 #include "gdkrectangle.h"
33 #include "gdkinternals.h"
35 #include "gdkscreenprivate.h"
36 #include "gdkdisplayprivate.h"
37 #include "gdkdeviceprivate.h"
38 #include "gdkvisualprivate.h"
39 #include "gdkmarshalers.h"
40 #include "gdkwindowimpl.h"
44 #undef DEBUG_WINDOW_PRINTING
49 * @Short_description: Onscreen display areas in the target window system
52 * A #GdkWindow is a (usually) rectangular region on the screen.
53 * It's a low-level object, used to implement high-level objects such as
54 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
55 * window, the thing a user might think of as a "window" with a titlebar and
56 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
57 * #GtkButton has a #GdkWindow associated with it.
59 * <refsect2 id="COMPOSITED-WINDOWS">
60 * <title>Composited Windows</title>
62 * Normally, the windowing system takes care of rendering the contents of a
63 * child window onto its parent window. This mechanism can be intercepted by
64 * calling gdk_window_set_composited() on the child window. For a
65 * <firstterm>composited</firstterm> window it is the responsibility of the
66 * application to render the window contents at the right spot.
69 * <refsect2 id="OFFSCREEN-WINDOWS">
70 * <title>Offscreen Windows</title>
72 * Offscreen windows are more general than composited windows, since they allow
73 * not only to modify the rendering of the child window onto its parent, but
74 * also to apply coordinate transformations.
76 * To integrate an offscreen window into a window hierarchy, one has to call
77 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
78 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
79 * select an offscreen child at given coordinates, and the
80 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
81 * offscreen window are used to translate coordinates between the embedder and
82 * the offscreen window.
84 * For rendering an offscreen window onto its embedder, the contents of the
85 * offscreen window are available as a surface, via
86 * gdk_offscreen_window_get_surface().
92 /* Historically a GdkWindow always matches a platform native window,
93 * be it a toplevel window or a child window. In this setup the
94 * GdkWindow (and other GdkDrawables) were platform independent classes,
95 * and the actual platform specific implementation was in a delegate
96 * object available as "impl" in the window object.
98 * With the addition of client side windows and offscreen windows this
99 * changes a bit. The application-visible GdkWindow object behaves as
100 * it did before, but not all such windows now have a corresponding native
101 * window. Instead windows that are "client side" are emulated by the gdk
102 * code such that clipping, drawing, moving, events etc work as expected.
104 * For GdkWindows that have a native window the "impl" object is the
105 * same as before. However, for all client side windows the impl object
106 * is shared with its parent (i.e. all client windows descendants of one
107 * native window has the same impl.
109 * Additionally there is a new type of platform independent impl object,
110 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
111 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
112 * windows). Such windows work by allocating a #cairo_surface_t as the backing
113 * store for drawing operations, which is resized with the window.
115 * GdkWindows have a pointer to the "impl window" they are in, i.e.
116 * the topmost GdkWindow which have the same "impl" value. This is stored
117 * in impl_window, which is different from the window itself only for client
119 * All GdkWindows (native or not) track the position of the window in the parent
120 * (x, y), the size of the window (width, height), the position of the window
121 * with respect to the impl window (abs_x, abs_y). We also track the clip
122 * region of the window wrt parent windows and siblings, in window-relative
123 * coordinates with and without child windows included (clip_region,
124 * clip_region_with_children).
126 * All toplevel windows are native windows, but also child windows can be
127 * native (although not children of offscreens). We always listen to
128 * a basic set of events (see get_native_event_mask) for these windows
129 * so that we can emulate events for any client side children.
131 * For native windows we apply the calculated clip region as a window shape
132 * so that eg. client side siblings that overlap the native child properly
133 * draws over the native child window.
135 * In order to minimize flicker and for performance we use a couple of cacheing
136 * tricks. First of all, every time we do a window to window copy area, for instance
137 * when moving a client side window or when scrolling/moving a region in a window
138 * we store this in outstanding_moves instead of applying immediately. We then
139 * delay this move until we really need it (because something depends on being
140 * able to read it), or until we're handing a redraw from an expose/invalidation
141 * (actually we delay it past redraw, but before blitting the double buffer
142 * to the window). This gives us two advantages. First of all it minimizes the time
143 * from the window is moved to the exposes related to that move, secondly it allows
144 * us to be smart about how to do the copy. We combine multiple moves into one (when
145 * possible) and we don't actually do copies to anything that is or will be
146 * invalidated and exposed anyway.
148 * Secondly, we use something called a "implicit paint" during repaint handling.
149 * An implicit paint is similar to a regular paint for the paint stack, but it is
150 * not put on the stack. Instead, it is set on the impl window, and later when
151 * regular gdk_window_begin_paint_region() happen on a window of this impl window
152 * we reuse the surface from the implicit paint. During repaint we create and at the
153 * end flush an implicit paint, which means we can collect all the paints on
154 * multiple client side windows in the same backing store.
157 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
159 /* This adds a local value to the GdkVisibilityState enum */
160 #define GDK_VISIBILITY_NOT_VIEWABLE 3
163 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
177 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
181 struct _GdkWindowPaint
183 cairo_region_t *region;
184 cairo_surface_t *surface;
185 cairo_region_t *flushed;
187 guint uses_implicit : 1;
191 cairo_region_t *dest_region; /* The destination region */
192 int dx, dy; /* The amount that the source was moved to reach dest_region */
193 } GdkWindowRegionMove;
197 static void gdk_window_drop_cairo_surface (GdkWindow *private);
199 static void gdk_window_free_paint_stack (GdkWindow *window);
201 static void gdk_window_finalize (GObject *object);
203 static void gdk_window_set_property (GObject *object,
207 static void gdk_window_get_property (GObject *object,
212 static void gdk_window_clear_backing_region (GdkWindow *window,
213 cairo_region_t *region);
215 static void recompute_visible_regions (GdkWindow *private,
216 gboolean recalculate_siblings,
217 gboolean recalculate_children);
218 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
219 static void gdk_window_flush_recursive (GdkWindow *window);
220 static void do_move_region_bits_on_impl (GdkWindow *window,
221 cairo_region_t *region, /* In impl window coords */
223 static void gdk_window_invalidate_in_parent (GdkWindow *private);
224 static void move_native_children (GdkWindow *private);
225 static void update_cursor (GdkDisplay *display,
227 static void impl_window_add_update_area (GdkWindow *impl_window,
228 cairo_region_t *region);
229 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
230 static void gdk_window_invalidate_region_full (GdkWindow *window,
231 const cairo_region_t *region,
232 gboolean invalidate_children,
234 static void gdk_window_invalidate_rect_full (GdkWindow *window,
235 const GdkRectangle *rect,
236 gboolean invalidate_children,
238 static void _gdk_window_propagate_has_alpha_background (GdkWindow *window);
239 static cairo_surface_t *gdk_window_ref_impl_surface (GdkWindow *window);
241 static guint signals[LAST_SIGNAL] = { 0 };
243 static gpointer parent_class = NULL;
245 static const cairo_user_data_key_t gdk_window_cairo_key;
247 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
249 #ifdef DEBUG_WINDOW_PRINTING
251 print_region (cairo_region_t *region)
253 GString *s = g_string_new ("{");
254 if (cairo_region_is_empty (region))
256 g_string_append (s, "empty");
260 int num = cairo_region_num_rectangles (region);
261 cairo_rectangle_int_t r;
265 cairo_region_get_rectangle (region, 0, &r);
266 g_string_append_printf (s, "%dx%d @%d,%d", r.width, r.height, r.x, r.y);
270 cairo_region_get_extents (region, &r);
271 g_string_append_printf (s, "extent: %dx%d @%d,%d, details: ", r.width, r.height, r.x, r.y);
272 for (int i = 0; i < num; i++)
274 g_string_append_printf (s, "[%dx%d @%d,%d]", r.width, r.height, r.x, r.y);
276 g_string_append (s, ", ");
280 g_string_append (s, "}");
281 return g_string_free (s, FALSE);
286 _gdk_paintable_get_type (void)
288 static GType paintable_type = 0;
292 const GTypeInfo paintable_info =
294 sizeof (GdkPaintableIface), /* class_size */
295 NULL, /* base_init */
296 NULL, /* base_finalize */
299 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
300 g_intern_static_string ("GdkPaintable"),
303 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
306 return paintable_type;
310 gdk_window_init (GdkWindow *window)
312 /* 0-initialization is good for all other fields. */
314 window->window_type = GDK_WINDOW_CHILD;
316 window->state = GDK_WINDOW_STATE_WITHDRAWN;
317 window->fullscreen_mode = GDK_FULLSCREEN_ON_CURRENT_MONITOR;
320 window->toplevel_window_type = -1;
322 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
323 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
324 /* Default to unobscured since some backends don't send visibility events */
325 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
327 window->device_cursor = g_hash_table_new_full (NULL, NULL,
328 NULL, g_object_unref);
331 /* Stop and return on the first non-NULL parent */
333 accumulate_get_window (GSignalInvocationHint *ihint,
335 const GValue *handler_return,
338 g_value_copy (handler_return, return_accu);
339 /* Continue while returning NULL */
340 return g_value_get_object (handler_return) == NULL;
344 create_surface_accumulator (GSignalInvocationHint *ihint,
346 const GValue *handler_return,
349 g_value_copy (handler_return, return_accu);
351 /* Stop on the first non-NULL return value */
352 return g_value_get_boxed (handler_return) == NULL;
355 static GQuark quark_pointer_window = 0;
358 gdk_window_class_init (GdkWindowClass *klass)
360 GObjectClass *object_class = G_OBJECT_CLASS (klass);
362 parent_class = g_type_class_peek_parent (klass);
364 object_class->finalize = gdk_window_finalize;
365 object_class->set_property = gdk_window_set_property;
366 object_class->get_property = gdk_window_get_property;
368 klass->create_surface = _gdk_offscreen_window_create_surface;
370 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
378 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
379 * gdk_window_get_cursor() for details.
383 g_object_class_install_property (object_class,
385 g_param_spec_object ("cursor",
392 * GdkWindow::pick-embedded-child:
393 * @window: the window on which the signal is emitted
394 * @x: x coordinate in the window
395 * @y: y coordinate in the window
397 * The ::pick-embedded-child signal is emitted to find an embedded
398 * child at the given position.
400 * Returns: (transfer none): the #GdkWindow of the embedded child at
405 signals[PICK_EMBEDDED_CHILD] =
406 g_signal_new (g_intern_static_string ("pick-embedded-child"),
407 G_OBJECT_CLASS_TYPE (object_class),
409 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
410 accumulate_get_window, NULL,
411 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
418 * GdkWindow::to-embedder:
419 * @window: the offscreen window on which the signal is emitted
420 * @offscreen_x: x coordinate in the offscreen window
421 * @offscreen_y: y coordinate in the offscreen window
422 * @embedder_x: (out) (type double): return location for the x
423 * coordinate in the embedder window
424 * @embedder_y: (out) (type double): return location for the y
425 * coordinate in the embedder window
427 * The ::to-embedder signal is emitted to translate coordinates
428 * in an offscreen window to its embedder.
430 * See also #GtkWindow::from-embedder.
434 signals[TO_EMBEDDER] =
435 g_signal_new (g_intern_static_string ("to-embedder"),
436 G_OBJECT_CLASS_TYPE (object_class),
438 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
440 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
449 * GdkWindow::from-embedder:
450 * @window: the offscreen window on which the signal is emitted
451 * @embedder_x: x coordinate in the embedder window
452 * @embedder_y: y coordinate in the embedder window
453 * @offscreen_x: (out) (type double): return location for the x
454 * coordinate in the offscreen window
455 * @offscreen_y: (out) (type double): return location for the y
456 * coordinate in the offscreen window
458 * The ::from-embedder signal is emitted to translate coordinates
459 * in the embedder of an offscreen window to the offscreen window.
461 * See also #GtkWindow::to-embedder.
465 signals[FROM_EMBEDDER] =
466 g_signal_new (g_intern_static_string ("from-embedder"),
467 G_OBJECT_CLASS_TYPE (object_class),
469 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
471 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
480 * GdkWindow::create-surface:
481 * @window: the offscreen window on which the signal is emitted
482 * @width: the width of the offscreen surface to create
483 * @height: the height of the offscreen surface to create
485 * The ::create-surface signal is emitted when an offscreen window
486 * needs its surface (re)created, which happens either when the the
487 * window is first drawn to, or when the window is being
488 * resized. The first signal handler that returns a non-%NULL
489 * surface will stop any further signal emission, and its surface
492 * Note that it is not possible to access the window's previous
493 * surface from within any callback of this signal. Calling
494 * gdk_offscreen_window_get_surface() will lead to a crash.
496 * Returns: the newly created #cairo_surface_t for the offscreen window
500 signals[CREATE_SURFACE] =
501 g_signal_new (g_intern_static_string ("create-surface"),
502 G_OBJECT_CLASS_TYPE (object_class),
504 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
505 create_surface_accumulator, NULL,
506 _gdk_marshal_BOXED__INT_INT,
507 CAIRO_GOBJECT_TYPE_SURFACE,
514 device_removed_cb (GdkDeviceManager *device_manager,
518 window->devices_inside = g_list_remove (window->devices_inside, device);
519 g_hash_table_remove (window->device_cursor, device);
521 if (window->device_events)
522 g_hash_table_remove (window->device_events, device);
526 gdk_window_finalize (GObject *object)
528 GdkWindow *window = GDK_WINDOW (object);
529 GdkDeviceManager *device_manager;
531 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
532 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
534 if (!GDK_WINDOW_DESTROYED (window))
536 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
538 g_warning ("losing last reference to undestroyed window\n");
539 _gdk_window_destroy (window, FALSE);
542 /* We use TRUE here, to keep us from actually calling
543 * XDestroyWindow() on the window
545 _gdk_window_destroy (window, TRUE);
548 gdk_window_drop_cairo_surface (window);
552 g_object_unref (window->impl);
556 if (window->impl_window != window)
558 g_object_unref (window->impl_window);
559 window->impl_window = NULL;
563 cairo_region_destroy (window->shape);
565 if (window->input_shape)
566 cairo_region_destroy (window->input_shape);
569 g_object_unref (window->cursor);
571 if (window->device_cursor)
572 g_hash_table_destroy (window->device_cursor);
574 if (window->device_events)
575 g_hash_table_destroy (window->device_events);
577 if (window->source_event_masks)
578 g_hash_table_destroy (window->source_event_masks);
580 if (window->devices_inside)
581 g_list_free (window->devices_inside);
583 if (window->layered_region)
584 cairo_region_destroy (window->layered_region);
586 G_OBJECT_CLASS (parent_class)->finalize (object);
590 gdk_window_set_property (GObject *object,
595 GdkWindow *window = (GdkWindow *)object;
600 gdk_window_set_cursor (window, g_value_get_object (value));
604 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
610 gdk_window_get_property (GObject *object,
615 GdkWindow *window = (GdkWindow *) object;
620 g_value_set_object (value, gdk_window_get_cursor (window));
624 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
630 gdk_window_is_offscreen (GdkWindow *window)
632 return window->window_type == GDK_WINDOW_OFFSCREEN;
636 gdk_window_get_impl_window (GdkWindow *window)
638 return window->impl_window;
642 _gdk_window_get_impl_window (GdkWindow *window)
644 return gdk_window_get_impl_window (window);
648 gdk_window_has_impl (GdkWindow *window)
650 return window->impl_window == window;
654 gdk_window_is_toplevel (GdkWindow *window)
657 window->parent == NULL ||
658 window->parent->window_type == GDK_WINDOW_ROOT;
662 _gdk_window_has_impl (GdkWindow *window)
664 return gdk_window_has_impl (window);
668 gdk_window_has_no_impl (GdkWindow *window)
670 return window->impl_window != window;
674 gdk_window_has_alpha (GdkWindow *window)
676 return !gdk_window_has_impl (window) &&
677 (window->has_alpha_background || window->alpha != 255);
681 remove_layered_child_area (GdkWindow *window,
682 cairo_region_t *region)
685 cairo_region_t *child_region;
689 for (l = window->children; l; l = l->next)
693 /* If region is empty already, no need to do
694 anything potentially costly */
695 if (cairo_region_is_empty (region))
698 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
701 /* Ignore offscreen children, as they don't draw in their parent and
702 * don't take part in the clipping */
703 if (gdk_window_is_offscreen (child))
706 /* Only non-impl children with alpha add to the layered region */
707 if (!gdk_window_has_alpha (child))
712 r.width = child->width;
713 r.height = child->height;
715 /* Bail early if child totally outside region */
716 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
719 child_region = cairo_region_create_rectangle (&r);
722 /* Adjust shape region to parent window coords */
723 cairo_region_translate (child->shape, child->x, child->y);
724 cairo_region_intersect (child_region, child->shape);
725 cairo_region_translate (child->shape, -child->x, -child->y);
728 cairo_region_subtract (region, child_region);
729 cairo_region_destroy (child_region);
734 remove_child_area (GdkWindow *window,
737 cairo_region_t *region,
738 cairo_region_t *layered_region)
741 cairo_region_t *child_region;
744 cairo_region_t *shape;
746 for (l = window->children; l; l = l->next)
753 /* If region is empty already, no need to do
754 anything potentially costly */
755 if (cairo_region_is_empty (region))
758 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
761 /* Ignore offscreen children, as they don't draw in their parent and
762 * don't take part in the clipping */
763 if (gdk_window_is_offscreen (child))
768 r.width = child->width;
769 r.height = child->height;
771 /* Bail early if child totally outside region */
772 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
775 child_region = cairo_region_create_rectangle (&r);
779 /* Adjust shape region to parent window coords */
780 cairo_region_translate (child->shape, child->x, child->y);
781 cairo_region_intersect (child_region, child->shape);
782 cairo_region_translate (child->shape, -child->x, -child->y);
784 else if (window->window_type == GDK_WINDOW_FOREIGN)
786 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
789 cairo_region_intersect (child_region, shape);
790 cairo_region_destroy (shape);
796 if (child->input_shape)
797 cairo_region_intersect (child_region, child->input_shape);
798 else if (window->window_type == GDK_WINDOW_FOREIGN)
800 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
803 cairo_region_intersect (child_region, shape);
804 cairo_region_destroy (shape);
809 if (gdk_window_has_alpha (child))
811 if (layered_region != NULL)
812 cairo_region_union (layered_region, child_region);
815 cairo_region_subtract (region, child_region);
816 cairo_region_destroy (child_region);
820 static GdkVisibilityState
821 effective_visibility (GdkWindow *window)
823 GdkVisibilityState native;
825 if (!gdk_window_is_viewable (window))
826 return GDK_VISIBILITY_NOT_VIEWABLE;
828 native = window->impl_window->native_visibility;
830 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
831 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
832 return GDK_VISIBILITY_FULLY_OBSCURED;
833 else if (native == GDK_VISIBILITY_UNOBSCURED)
834 return window->visibility;
835 else /* native PARTIAL, private partial or unobscured */
836 return GDK_VISIBILITY_PARTIAL;
840 gdk_window_update_visibility (GdkWindow *window)
842 GdkVisibilityState new_visibility;
845 new_visibility = effective_visibility (window);
847 if (new_visibility != window->effective_visibility)
849 window->effective_visibility = new_visibility;
851 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
852 window->event_mask & GDK_VISIBILITY_NOTIFY_MASK)
854 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
856 event->visibility.state = new_visibility;
862 gdk_window_update_visibility_recursively (GdkWindow *window,
863 GdkWindow *only_for_impl)
868 gdk_window_update_visibility (window);
869 for (l = window->children; l != NULL; l = l->next)
872 if ((only_for_impl == NULL) ||
873 (only_for_impl == child->impl_window))
874 gdk_window_update_visibility_recursively (child, only_for_impl);
879 should_apply_clip_as_shape (GdkWindow *window)
882 gdk_window_has_impl (window) &&
883 /* Not for offscreens */
884 !gdk_window_is_offscreen (window) &&
885 /* or for toplevels */
886 !gdk_window_is_toplevel (window) &&
887 /* or for foreign windows */
888 window->window_type != GDK_WINDOW_FOREIGN &&
889 /* or for the root window */
890 window->window_type != GDK_WINDOW_ROOT;
894 apply_shape (GdkWindow *window,
895 cairo_region_t *region)
897 GdkWindowImplClass *impl_class;
899 /* We trash whether we applied a shape so that
900 we can avoid unsetting it many times, which
901 could happen in e.g. apply_clip_as_shape as
902 windows get resized */
903 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
905 impl_class->shape_combine_region (window,
907 else if (window->applied_shape)
908 impl_class->shape_combine_region (window,
911 window->applied_shape = region != NULL;
915 region_rect_equal (const cairo_region_t *region,
916 const GdkRectangle *rect)
918 GdkRectangle extents;
920 if (cairo_region_num_rectangles (region) != 1)
923 cairo_region_get_extents (region, &extents);
925 return extents.x == rect->x &&
926 extents.y == rect->y &&
927 extents.width == rect->width &&
928 extents.height == rect->height;
932 apply_clip_as_shape (GdkWindow *window)
937 r.width = window->width;
938 r.height = window->height;
940 /* We only apply the clip region if would differ
941 from the actual clip region implied by the size
942 of the window. This is to avoid unneccessarily
943 adding meaningless shapes to all native subwindows */
944 if (!region_rect_equal (window->clip_region, &r))
945 apply_shape (window, window->clip_region);
947 apply_shape (window, NULL);
951 recompute_visible_regions_internal (GdkWindow *private,
952 gboolean recalculate_clip,
953 gboolean recalculate_siblings,
954 gboolean recalculate_children)
959 cairo_region_t *new_clip, *new_layered;
960 gboolean clip_region_changed;
961 gboolean abs_pos_changed;
962 int old_abs_x, old_abs_y;
964 old_abs_x = private->abs_x;
965 old_abs_y = private->abs_y;
967 /* Update absolute position */
968 if (gdk_window_has_impl (private))
970 /* Native window starts here */
976 private->abs_x = private->parent->abs_x + private->x;
977 private->abs_y = private->parent->abs_y + private->y;
981 private->abs_x != old_abs_x ||
982 private->abs_y != old_abs_y;
984 /* Update clip region based on:
987 * siblings in parents above window
989 clip_region_changed = FALSE;
990 if (recalculate_clip)
992 new_layered = cairo_region_create ();
993 if (private->viewable)
995 /* Calculate visible region (sans children) in parent window coords */
998 r.width = private->width;
999 r.height = private->height;
1000 new_clip = cairo_region_create_rectangle (&r);
1002 if (!gdk_window_is_toplevel (private))
1004 cairo_region_intersect (new_clip, private->parent->clip_region);
1005 cairo_region_union (new_layered, private->parent->layered_region);
1007 /* Remove all overlapping children from parent. */
1008 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
1011 /* Convert from parent coords to window coords */
1012 cairo_region_translate (new_clip, -private->x, -private->y);
1013 cairo_region_translate (new_layered, -private->x, -private->y);
1016 cairo_region_intersect (new_clip, private->shape);
1019 new_clip = cairo_region_create ();
1021 cairo_region_intersect (new_layered, new_clip);
1023 if (private->clip_region == NULL ||
1024 !cairo_region_equal (private->clip_region, new_clip))
1025 clip_region_changed = TRUE;
1027 if (private->layered_region == NULL ||
1028 !cairo_region_equal (private->layered_region, new_layered))
1029 clip_region_changed = TRUE;
1031 if (private->clip_region)
1032 cairo_region_destroy (private->clip_region);
1033 private->clip_region = new_clip;
1035 if (private->layered_region != NULL)
1036 cairo_region_destroy (private->layered_region);
1037 private->layered_region = new_layered;
1039 if (private->clip_region_with_children)
1040 cairo_region_destroy (private->clip_region_with_children);
1041 private->clip_region_with_children = cairo_region_copy (private->clip_region);
1042 if (private->window_type != GDK_WINDOW_ROOT)
1043 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
1046 if (clip_region_changed)
1048 GdkVisibilityState visibility;
1049 gboolean fully_visible;
1051 if (cairo_region_is_empty (private->clip_region))
1052 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1057 fully_visible = cairo_region_equal (private->clip_region,
1064 r.width = private->width;
1065 r.height = private->height;
1066 fully_visible = region_rect_equal (private->clip_region, &r);
1070 visibility = GDK_VISIBILITY_UNOBSCURED;
1072 visibility = GDK_VISIBILITY_PARTIAL;
1075 if (private->visibility != visibility)
1077 private->visibility = visibility;
1078 gdk_window_update_visibility (private);
1082 /* Update all children, recursively (except for root, where children are not exact). */
1083 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1084 private->window_type != GDK_WINDOW_ROOT)
1086 for (l = private->children; l; l = l->next)
1089 /* Only recalculate clip if the the clip region changed, otherwise
1090 * there is no way the child clip region could change (its has not e.g. moved)
1091 * Except if recalculate_children is set to force child updates
1093 recompute_visible_regions_internal (child,
1094 recalculate_clip && (clip_region_changed || recalculate_children),
1099 if (clip_region_changed &&
1100 should_apply_clip_as_shape (private))
1101 apply_clip_as_shape (private);
1103 if (recalculate_siblings &&
1104 !gdk_window_is_toplevel (private))
1106 /* If we moved a child window in parent or changed the stacking order, then we
1107 * need to recompute the visible area of all the other children in the parent
1109 for (l = private->parent->children; l; l = l->next)
1113 if (child != private)
1114 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1117 /* We also need to recompute the _with_children clip for the parent */
1118 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1121 if (private->cairo_surface && gdk_window_has_impl (private))
1123 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1125 private->cairo_surface = iface->resize_cairo_surface (private,
1126 private->cairo_surface,
1130 else if (private->cairo_surface)
1131 gdk_window_drop_cairo_surface (private);
1134 /* Call this when private has changed in one or more of these ways:
1138 * stacking order of window changed
1141 * It will recalculate abs_x/y and the clip regions
1143 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1144 * for recalculate_siblings. (Mostly used internally for the recursion)
1146 * If a child window was removed (and you can't use that child for
1147 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1150 recompute_visible_regions (GdkWindow *private,
1151 gboolean recalculate_siblings,
1152 gboolean recalculate_children)
1154 recompute_visible_regions_internal (private,
1156 recalculate_siblings,
1157 recalculate_children);
1161 _gdk_window_update_size (GdkWindow *window)
1163 recompute_visible_regions (window, TRUE, FALSE);
1166 /* Find the native window that would be just above "child"
1167 * in the native stacking order if "child" was a native window
1168 * (it doesn't have to be native). If there is no such native
1169 * window inside this native parent then NULL is returned.
1170 * If child is NULL, find lowest native window in parent.
1173 find_native_sibling_above_helper (GdkWindow *parent,
1181 l = g_list_find (parent->children, child);
1182 g_assert (l != NULL); /* Better be a child of its parent... */
1183 l = l->prev; /* Start looking at the one above the child */
1186 l = g_list_last (parent->children);
1188 for (; l != NULL; l = l->prev)
1192 if (gdk_window_has_impl (w))
1195 g_assert (parent != w);
1196 w = find_native_sibling_above_helper (w, NULL);
1206 find_native_sibling_above (GdkWindow *parent,
1211 w = find_native_sibling_above_helper (parent, child);
1215 if (gdk_window_has_impl (parent))
1218 return find_native_sibling_above (parent->parent, parent);
1222 get_native_device_event_mask (GdkWindow *private,
1225 GdkEventMask event_mask;
1228 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1230 event_mask = private->event_mask;
1232 if (private->window_type == GDK_WINDOW_ROOT ||
1233 private->window_type == GDK_WINDOW_FOREIGN)
1239 /* Do whatever the app asks to, since the app
1240 * may be asking for weird things for native windows,
1241 * but don't use motion hints as that may affect non-native
1242 * child windows that don't want it. Also, we need to
1243 * set all the app-specified masks since they will be picked
1244 * up by any implicit grabs (i.e. if they were not set as
1245 * native we would not get the events we need). */
1246 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1248 /* We need thse for all native windows so we can
1249 emulate events on children: */
1252 GDK_VISIBILITY_NOTIFY_MASK |
1253 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1255 /* Additionally we select for pointer and button events
1256 * for toplevels as we need to get these to emulate
1257 * them for non-native subwindows. Even though we don't
1258 * select on them for all native windows we will get them
1259 * as the events are propagated out to the first window
1260 * that select for them.
1261 * Not selecting for button press on all windows is an
1262 * important thing, because in X only one client can do
1263 * so, and we don't want to unexpectedly prevent another
1264 * client from doing it.
1266 * We also need to do the same if the app selects for button presses
1267 * because then we will get implicit grabs for this window, and the
1268 * event mask used for that grab is based on the rest of the mask
1269 * for the window, but we might need more events than this window
1270 * lists due to some non-native child window.
1272 if (gdk_window_is_toplevel (private) ||
1273 mask & GDK_BUTTON_PRESS_MASK)
1276 GDK_POINTER_MOTION_MASK |
1277 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1285 get_native_grab_event_mask (GdkEventMask grab_mask)
1287 /* Similar to the above but for pointer events only */
1289 GDK_POINTER_MOTION_MASK |
1290 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1291 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1294 ~GDK_POINTER_MOTION_HINT_MASK);
1298 get_native_event_mask (GdkWindow *private)
1300 return get_native_device_event_mask (private, NULL);
1303 /* Puts the native window in the right order wrt the other native windows
1304 * in the hierarchy, given the position it has in the client side data.
1305 * This is useful if some operation changed the stacking order.
1306 * This calls assumes the native window is now topmost in its native parent.
1309 sync_native_window_stack_position (GdkWindow *window)
1312 GdkWindowImplClass *impl_class;
1313 GList listhead = {0};
1315 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1317 above = find_native_sibling_above (window->parent, window);
1320 listhead.data = window;
1321 impl_class->restack_under (above, &listhead);
1326 * gdk_window_new: (constructor)
1327 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1328 * the default root window for the default display.
1329 * @attributes: attributes of the new window
1330 * @attributes_mask: (type GdkWindowAttributesType): mask indicating which
1331 * fields in @attributes are valid
1333 * Creates a new #GdkWindow using the attributes from
1334 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1335 * more details. Note: to use this on displays other than the default
1336 * display, @parent must be specified.
1338 * Return value: (transfer full): the new #GdkWindow
1341 gdk_window_new (GdkWindow *parent,
1342 GdkWindowAttr *attributes,
1343 gint attributes_mask)
1347 GdkDisplay *display;
1350 GdkEventMask event_mask;
1351 GdkWindow *real_parent;
1352 GdkDeviceManager *device_manager;
1354 g_return_val_if_fail (attributes != NULL, NULL);
1358 GDK_NOTE (MULTIHEAD,
1359 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1361 screen = gdk_screen_get_default ();
1362 parent = gdk_screen_get_root_window (screen);
1365 screen = gdk_window_get_screen (parent);
1367 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1369 if (GDK_WINDOW_DESTROYED (parent))
1371 g_warning ("gdk_window_new(): parent is destroyed\n");
1375 if (attributes_mask & GDK_WA_VISUAL)
1377 g_return_val_if_fail (gdk_visual_get_screen (attributes->visual) == screen, NULL);
1380 display = gdk_screen_get_display (screen);
1382 window = _gdk_display_create_window (display);
1384 /* Windows with a foreign parent are treated as if they are children
1385 * of the root window, except for actual creation.
1387 real_parent = parent;
1388 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1389 parent = gdk_screen_get_root_window (screen);
1391 window->parent = parent;
1393 window->accept_focus = TRUE;
1394 window->focus_on_map = TRUE;
1396 if (attributes_mask & GDK_WA_X)
1401 if (attributes_mask & GDK_WA_Y)
1408 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1409 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1410 window->alpha = 255;
1412 if (attributes->wclass == GDK_INPUT_ONLY)
1414 /* Backwards compatiblity - we've always ignored
1415 * attributes->window_type for input-only windows
1418 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1419 window->window_type = GDK_WINDOW_TEMP;
1421 window->window_type = GDK_WINDOW_CHILD;
1424 window->window_type = attributes->window_type;
1427 switch (window->window_type)
1429 case GDK_WINDOW_TOPLEVEL:
1430 case GDK_WINDOW_TEMP:
1431 case GDK_WINDOW_OFFSCREEN:
1432 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1433 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1434 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1435 case GDK_WINDOW_CHILD:
1439 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1443 if (attributes_mask & GDK_WA_VISUAL)
1444 window->visual = attributes->visual;
1446 window->visual = gdk_screen_get_system_visual (screen);
1448 window->event_mask = attributes->event_mask;
1450 if (attributes->wclass == GDK_INPUT_OUTPUT)
1452 window->input_only = FALSE;
1453 window->depth = window->visual->depth;
1455 /* XXX: Cache this somehow? */
1456 window->background = cairo_pattern_create_rgba (0, 0, 0, 0);
1457 window->has_alpha_background = TRUE;
1462 window->input_only = TRUE;
1466 window->parent->children = g_list_prepend (window->parent->children, window);
1469 if (window->parent->window_type == GDK_WINDOW_ROOT)
1470 native = TRUE; /* Always use native windows for toplevels */
1471 else if (!window->input_only &&
1472 (attributes_mask & GDK_WA_VISUAL &&
1473 attributes->visual != gdk_window_get_visual (window->parent)))
1474 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1476 if (gdk_window_is_offscreen (window))
1478 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1479 window->impl_window = window;
1483 event_mask = get_native_event_mask (window);
1485 /* Create the impl */
1486 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1487 window->impl_window = window;
1489 /* This will put the native window topmost in the native parent, which may
1490 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1491 if (!_gdk_window_has_impl (real_parent))
1492 sync_native_window_stack_position (window);
1496 window->impl_window = g_object_ref (window->parent->impl_window);
1497 window->impl = g_object_ref (window->impl_window->impl);
1500 recompute_visible_regions (window, TRUE, FALSE);
1502 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1503 (attributes->cursor) :
1506 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1507 g_signal_connect (device_manager, "device-removed",
1508 G_CALLBACK (device_removed_cb), window);
1514 is_parent_of (GdkWindow *parent,
1525 w = gdk_window_get_parent (w);
1532 change_impl (GdkWindow *private,
1533 GdkWindow *impl_window,
1538 GdkWindowImpl *old_impl;
1539 GdkWindow *old_impl_window;
1541 old_impl = private->impl;
1542 old_impl_window = private->impl_window;
1543 if (private != impl_window)
1544 private->impl_window = g_object_ref (impl_window);
1546 private->impl_window = private;
1547 private->impl = g_object_ref (new);
1548 if (old_impl_window != private)
1549 g_object_unref (old_impl_window);
1550 g_object_unref (old_impl);
1552 for (l = private->children; l != NULL; l = l->next)
1556 if (child->impl == old_impl)
1557 change_impl (child, impl_window, new);
1562 reparent_to_impl (GdkWindow *private)
1567 GdkWindowImplClass *impl_class;
1569 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1571 /* Enumerate in reverse order so we get the right order for the native
1572 windows (first in childrens list is topmost, and reparent places on top) */
1573 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1577 if (child->impl == private->impl)
1578 reparent_to_impl (child);
1581 show = impl_class->reparent ((GdkWindow *)child,
1582 (GdkWindow *)private,
1583 child->x, child->y);
1585 gdk_window_show_unraised ((GdkWindow *)child);
1592 * gdk_window_reparent:
1593 * @window: a #GdkWindow
1594 * @new_parent: new parent to move @window into
1595 * @x: X location inside the new parent
1596 * @y: Y location inside the new parent
1598 * Reparents @window into the given @new_parent. The window being
1599 * reparented will be unmapped as a side effect.
1603 gdk_window_reparent (GdkWindow *window,
1604 GdkWindow *new_parent,
1608 GdkWindow *old_parent;
1610 gboolean show, was_mapped, applied_clip_as_shape;
1611 gboolean do_reparent_to_impl;
1612 GdkEventMask old_native_event_mask;
1613 GdkWindowImplClass *impl_class;
1615 g_return_if_fail (GDK_IS_WINDOW (window));
1616 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1617 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1619 if (GDK_WINDOW_DESTROYED (window) ||
1620 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1623 screen = gdk_window_get_screen (window);
1625 new_parent = gdk_screen_get_root_window (screen);
1627 /* No input-output children of input-only windows */
1628 if (new_parent->input_only && !window->input_only)
1631 /* Don't create loops in hierarchy */
1632 if (is_parent_of (window, new_parent))
1635 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1636 To make sure we're ok, just wipe it. */
1637 gdk_window_drop_cairo_surface (window);
1639 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1640 old_parent = window->parent;
1642 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1645 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1646 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1647 new_parent->window_type == GDK_WINDOW_FOREIGN)
1648 gdk_window_ensure_native (window);
1650 applied_clip_as_shape = should_apply_clip_as_shape (window);
1652 old_native_event_mask = 0;
1653 do_reparent_to_impl = FALSE;
1654 if (gdk_window_has_impl (window))
1656 old_native_event_mask = get_native_event_mask (window);
1658 show = impl_class->reparent (window, new_parent, x, y);
1662 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1663 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1664 new_parent->window_type != GDK_WINDOW_FOREIGN);
1667 gdk_window_hide (window);
1669 do_reparent_to_impl = TRUE;
1670 change_impl (window,
1671 new_parent->impl_window,
1675 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1678 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1680 new_parent = gdk_screen_get_root_window (screen);
1684 old_parent->children = g_list_remove (old_parent->children, window);
1686 window->parent = new_parent;
1690 new_parent->children = g_list_prepend (new_parent->children, window);
1692 /* Switch the window type as appropriate */
1694 switch (GDK_WINDOW_TYPE (new_parent))
1696 case GDK_WINDOW_ROOT:
1697 case GDK_WINDOW_FOREIGN:
1698 if (window->toplevel_window_type != -1)
1699 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1700 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1701 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1703 case GDK_WINDOW_OFFSCREEN:
1704 case GDK_WINDOW_TOPLEVEL:
1705 case GDK_WINDOW_CHILD:
1706 case GDK_WINDOW_TEMP:
1707 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1708 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1710 /* Save the original window type so we can restore it if the
1711 * window is reparented back to be a toplevel
1713 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1714 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1718 /* We might have changed window type for a native windows, so we
1719 need to change the event mask too. */
1720 if (gdk_window_has_impl (window))
1722 GdkEventMask native_event_mask = get_native_event_mask (window);
1724 if (native_event_mask != old_native_event_mask)
1725 impl_class->set_events (window, native_event_mask);
1728 _gdk_window_update_viewable (window);
1730 if (window->background == NULL)
1732 /* parent relative background, update has_alpha_background */
1733 if (window->parent == NULL ||
1734 window->parent->window_type == GDK_WINDOW_ROOT)
1735 window->has_alpha_background = FALSE;
1737 window->has_alpha_background = window->parent->has_alpha_background;
1740 recompute_visible_regions (window, TRUE, FALSE);
1741 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1742 recompute_visible_regions (old_parent, FALSE, TRUE);
1744 _gdk_window_propagate_has_alpha_background (window);
1746 /* We used to apply the clip as the shape, but no more.
1747 Reset this to the real shape */
1748 if (gdk_window_has_impl (window) &&
1749 applied_clip_as_shape &&
1750 !should_apply_clip_as_shape (window))
1751 apply_shape (window, window->shape);
1753 if (do_reparent_to_impl)
1754 reparent_to_impl (window);
1757 /* The reparent will have put the native window topmost in the native parent,
1758 * which may be wrong wrt other native windows in the non-native hierarchy,
1760 if (!gdk_window_has_impl (new_parent))
1761 sync_native_window_stack_position (window);
1765 gdk_window_show_unraised (window);
1767 _gdk_synthesize_crossing_events_for_geometry_change (window);
1771 * gdk_window_ensure_native:
1772 * @window: a #GdkWindow
1774 * Tries to ensure that there is a window-system native window for this
1775 * GdkWindow. This may fail in some situations, returning %FALSE.
1777 * Offscreen window and children of them can never have native windows.
1779 * Some backends may not support native child windows.
1781 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1786 gdk_window_ensure_native (GdkWindow *window)
1788 GdkWindow *impl_window;
1789 GdkWindowImpl *new_impl, *old_impl;
1790 GdkDisplay *display;
1794 GdkWindowImplClass *impl_class;
1796 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1798 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1799 GDK_WINDOW_DESTROYED (window))
1802 impl_window = gdk_window_get_impl_window (window);
1804 if (gdk_window_is_offscreen (impl_window))
1805 return FALSE; /* native in offscreens not supported */
1807 if (impl_window == window)
1808 /* Already has an impl, and its not offscreen . */
1811 /* Need to create a native window */
1813 gdk_window_drop_cairo_surface (window);
1815 screen = gdk_window_get_screen (window);
1816 display = gdk_screen_get_display (screen);
1818 old_impl = window->impl;
1819 _gdk_display_create_window_impl (display,
1820 window, window->parent,
1822 get_native_event_mask (window),
1824 new_impl = window->impl;
1826 window->impl = old_impl;
1827 change_impl (window, window, new_impl);
1829 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1831 /* Native window creation will put the native window topmost in the
1832 * native parent, which may be wrong wrt the position of the previous
1833 * non-native window wrt to the other non-native children, so correct this.
1835 above = find_native_sibling_above (window->parent, window);
1838 listhead.data = window;
1839 listhead.prev = NULL;
1840 listhead.next = NULL;
1841 impl_class->restack_under ((GdkWindow *)above, &listhead);
1844 recompute_visible_regions (window, FALSE, FALSE);
1846 /* The shape may not have been set, as the clip region doesn't actually
1847 change, so do it here manually */
1848 if (should_apply_clip_as_shape (window))
1849 apply_clip_as_shape (window);
1851 reparent_to_impl (window);
1853 if (!window->input_only)
1854 impl_class->set_background (window, window->background);
1856 impl_class->input_shape_combine_region (window,
1857 window->input_shape,
1860 if (gdk_window_is_viewable (window))
1861 impl_class->show (window, FALSE);
1867 * _gdk_event_filter_unref:
1868 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1869 * @filter: A window filter
1871 * Release a reference to @filter. Note this function may
1872 * mutate the list storage, so you need to handle this
1873 * if iterating over a list of filters.
1876 _gdk_event_filter_unref (GdkWindow *window,
1877 GdkEventFilter *filter)
1883 filters = &_gdk_default_filters;
1885 filters = &window->filters;
1887 tmp_list = *filters;
1890 GdkEventFilter *iter_filter = tmp_list->data;
1894 tmp_list = tmp_list->next;
1896 if (iter_filter != filter)
1899 g_assert (iter_filter->ref_count > 0);
1901 filter->ref_count--;
1902 if (filter->ref_count != 0)
1905 *filters = g_list_remove_link (*filters, node);
1907 g_list_free_1 (node);
1912 window_remove_filters (GdkWindow *window)
1914 while (window->filters)
1915 _gdk_event_filter_unref (window, window->filters->data);
1919 update_pointer_info_foreach (GdkDisplay *display,
1921 GdkPointerWindowInfo *pointer_info,
1924 GdkWindow *window = user_data;
1926 if (pointer_info->toplevel_under_pointer == window)
1928 g_object_unref (pointer_info->toplevel_under_pointer);
1929 pointer_info->toplevel_under_pointer = NULL;
1934 window_remove_from_pointer_info (GdkWindow *window,
1935 GdkDisplay *display)
1937 _gdk_display_pointer_info_foreach (display,
1938 update_pointer_info_foreach,
1943 * _gdk_window_destroy_hierarchy:
1944 * @window: a #GdkWindow
1945 * @recursing: If TRUE, then this is being called because a parent
1947 * @recursing_native: If TRUE, then this is being called because a native parent
1948 * was destroyed. This generally means that the call to the
1949 * windowing system to destroy the window can be omitted, since
1950 * it will be destroyed as a result of the parent being destroyed.
1951 * Unless @foreign_destroy.
1952 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1953 * external agency. The window has already been destroyed and no
1954 * windowing system calls should be made. (This may never happen
1955 * for some windowing systems.)
1957 * Internal function to destroy a window. Like gdk_window_destroy(),
1958 * but does not drop the reference count created by gdk_window_new().
1961 _gdk_window_destroy_hierarchy (GdkWindow *window,
1963 gboolean recursing_native,
1964 gboolean foreign_destroy)
1966 GdkWindowImplClass *impl_class;
1967 GdkWindow *temp_window;
1969 GdkDisplay *display;
1973 g_return_if_fail (GDK_IS_WINDOW (window));
1975 if (GDK_WINDOW_DESTROYED (window))
1978 display = gdk_window_get_display (window);
1979 screen = gdk_window_get_screen (window);
1980 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1981 if (temp_window == window)
1982 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1985 switch (window->window_type)
1987 case GDK_WINDOW_ROOT:
1988 if (!screen->closed)
1990 g_error ("attempted to destroy root window");
1993 /* else fall thru */
1994 case GDK_WINDOW_TOPLEVEL:
1995 case GDK_WINDOW_CHILD:
1996 case GDK_WINDOW_TEMP:
1997 case GDK_WINDOW_FOREIGN:
1998 case GDK_WINDOW_OFFSCREEN:
1999 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
2001 /* Logically, it probably makes more sense to send
2002 * a "destroy yourself" message to the foreign window
2003 * whether or not it's in our hierarchy; but for historical
2004 * reasons, we only send "destroy yourself" messages to
2005 * foreign windows in our hierarchy.
2009 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2011 if (gdk_window_has_impl (window))
2012 impl_class->destroy_foreign (window);
2015 /* Also for historical reasons, we remove any filters
2016 * on a foreign window when it or a parent is destroyed;
2017 * this likely causes problems if two separate portions
2018 * of code are maintaining filter lists on a foreign window.
2020 window_remove_filters (window);
2026 if (window->parent->children)
2027 window->parent->children = g_list_remove (window->parent->children, window);
2030 GDK_WINDOW_IS_MAPPED (window))
2032 recompute_visible_regions (window, TRUE, FALSE);
2033 gdk_window_invalidate_in_parent (window);
2037 gdk_window_free_paint_stack (window);
2039 if (window->background)
2041 cairo_pattern_destroy (window->background);
2042 window->background = NULL;
2045 if (window->window_type == GDK_WINDOW_FOREIGN)
2046 g_assert (window->children == NULL);
2049 children = tmp = window->children;
2050 window->children = NULL;
2054 temp_window = tmp->data;
2058 _gdk_window_destroy_hierarchy (temp_window,
2060 recursing_native || gdk_window_has_impl (window),
2064 g_list_free (children);
2067 _gdk_window_clear_update_area (window);
2069 gdk_window_drop_cairo_surface (window);
2071 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2073 if (gdk_window_has_impl (window))
2074 impl_class->destroy (window, recursing_native,
2078 /* hide to make sure we repaint and break grabs */
2079 gdk_window_hide (window);
2082 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2083 window->parent = NULL;
2084 window->destroyed = TRUE;
2086 window_remove_filters (window);
2088 window_remove_from_pointer_info (window, display);
2090 if (window->clip_region)
2092 cairo_region_destroy (window->clip_region);
2093 window->clip_region = NULL;
2096 if (window->clip_region_with_children)
2098 cairo_region_destroy (window->clip_region_with_children);
2099 window->clip_region_with_children = NULL;
2102 g_list_free_full (window->outstanding_moves, (GDestroyNotify) gdk_window_region_move_free);
2103 window->outstanding_moves = NULL;
2110 * _gdk_window_destroy:
2111 * @window: a #GdkWindow
2112 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2113 * external agency. The window has already been destroyed and no
2114 * windowing system calls should be made. (This may never happen
2115 * for some windowing systems.)
2117 * Internal function to destroy a window. Like gdk_window_destroy(),
2118 * but does not drop the reference count created by gdk_window_new().
2121 _gdk_window_destroy (GdkWindow *window,
2122 gboolean foreign_destroy)
2124 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2128 * gdk_window_destroy:
2129 * @window: a #GdkWindow
2131 * Destroys the window system resources associated with @window and decrements @window's
2132 * reference count. The window system resources for all children of @window are also
2133 * destroyed, but the children's reference counts are not decremented.
2135 * Note that a window will not be destroyed automatically when its reference count
2136 * reaches zero. You must call this function yourself before that happens.
2140 gdk_window_destroy (GdkWindow *window)
2142 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2143 g_object_unref (window);
2147 * gdk_window_set_user_data:
2148 * @window: a #GdkWindow
2149 * @user_data: (allow-none) (type GObject.Object): user data
2151 * For most purposes this function is deprecated in favor of
2152 * g_object_set_data(). However, for historical reasons GTK+ stores
2153 * the #GtkWidget that owns a #GdkWindow as user data on the
2154 * #GdkWindow. So, custom widget implementations should use
2155 * this function for that. If GTK+ receives an event for a #GdkWindow,
2156 * and the user data for the window is non-%NULL, GTK+ will assume the
2157 * user data is a #GtkWidget, and forward the event to that widget.
2161 gdk_window_set_user_data (GdkWindow *window,
2164 g_return_if_fail (GDK_IS_WINDOW (window));
2166 window->user_data = user_data;
2170 * gdk_window_get_user_data:
2171 * @window: a #GdkWindow
2172 * @data: (out): return location for user data
2174 * Retrieves the user data for @window, which is normally the widget
2175 * that @window belongs to. See gdk_window_set_user_data().
2179 gdk_window_get_user_data (GdkWindow *window,
2182 g_return_if_fail (GDK_IS_WINDOW (window));
2184 *data = window->user_data;
2188 * gdk_window_get_window_type:
2189 * @window: a #GdkWindow
2191 * Gets the type of the window. See #GdkWindowType.
2193 * Return value: type of window
2196 gdk_window_get_window_type (GdkWindow *window)
2198 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2200 return GDK_WINDOW_TYPE (window);
2204 * gdk_window_get_visual:
2205 * @window: a #GdkWindow
2207 * Gets the #GdkVisual describing the pixel format of @window.
2209 * Return value: (transfer none): a #GdkVisual
2214 gdk_window_get_visual (GdkWindow *window)
2216 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2218 return window->visual;
2222 * gdk_window_get_screen:
2223 * @window: a #GdkWindow
2225 * Gets the #GdkScreen associated with a #GdkWindow.
2227 * Return value: (transfer none): the #GdkScreen associated with @window
2232 gdk_window_get_screen (GdkWindow *window)
2234 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2236 return gdk_visual_get_screen (window->visual);
2240 * gdk_window_get_display:
2241 * @window: a #GdkWindow
2243 * Gets the #GdkDisplay associated with a #GdkWindow.
2245 * Return value: (transfer none): the #GdkDisplay associated with @window
2250 gdk_window_get_display (GdkWindow *window)
2252 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2254 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2257 * gdk_window_is_destroyed:
2258 * @window: a #GdkWindow
2260 * Check to see if a window is destroyed..
2262 * Return value: %TRUE if the window is destroyed
2267 gdk_window_is_destroyed (GdkWindow *window)
2269 return GDK_WINDOW_DESTROYED (window);
2273 to_embedder (GdkWindow *window,
2274 gdouble offscreen_x,
2275 gdouble offscreen_y,
2276 gdouble *embedder_x,
2277 gdouble *embedder_y)
2279 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2280 offscreen_x, offscreen_y,
2281 embedder_x, embedder_y);
2285 from_embedder (GdkWindow *window,
2288 gdouble *offscreen_x,
2289 gdouble *offscreen_y)
2291 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2292 embedder_x, embedder_y,
2293 offscreen_x, offscreen_y);
2297 * gdk_window_has_native:
2298 * @window: a #GdkWindow
2300 * Checks whether the window has a native window or not. Note that
2301 * you can use gdk_window_ensure_native() if a native window is needed.
2303 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2308 gdk_window_has_native (GdkWindow *window)
2310 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2312 return window->parent == NULL || window->parent->impl != window->impl;
2316 * gdk_window_get_position:
2317 * @window: a #GdkWindow
2318 * @x: (out) (allow-none): X coordinate of window
2319 * @y: (out) (allow-none): Y coordinate of window
2321 * Obtains the position of the window as reported in the
2322 * most-recently-processed #GdkEventConfigure. Contrast with
2323 * gdk_window_get_geometry() which queries the X server for the
2324 * current window position, regardless of which events have been
2325 * received or processed.
2327 * The position coordinates are relative to the window's parent window.
2331 gdk_window_get_position (GdkWindow *window,
2335 g_return_if_fail (GDK_IS_WINDOW (window));
2344 * gdk_window_get_parent:
2345 * @window: a #GdkWindow
2347 * Obtains the parent of @window, as known to GDK. Does not query the
2348 * X server; thus this returns the parent as passed to gdk_window_new(),
2349 * not the actual parent. This should never matter unless you're using
2350 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2351 * matter for toplevel windows, because the window manager may choose
2354 * Note that you should use gdk_window_get_effective_parent() when
2355 * writing generic code that walks up a window hierarchy, because
2356 * gdk_window_get_parent() will most likely not do what you expect if
2357 * there are offscreen windows in the hierarchy.
2359 * Return value: (transfer none): parent of @window
2362 gdk_window_get_parent (GdkWindow *window)
2364 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2366 return window->parent;
2370 * gdk_window_get_effective_parent:
2371 * @window: a #GdkWindow
2373 * Obtains the parent of @window, as known to GDK. Works like
2374 * gdk_window_get_parent() for normal windows, but returns the
2375 * window's embedder for offscreen windows.
2377 * See also: gdk_offscreen_window_get_embedder()
2379 * Return value: (transfer none): effective parent of @window
2384 gdk_window_get_effective_parent (GdkWindow *window)
2386 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2388 if (gdk_window_is_offscreen (window))
2389 return gdk_offscreen_window_get_embedder (window);
2391 return window->parent;
2395 * gdk_window_get_toplevel:
2396 * @window: a #GdkWindow
2398 * Gets the toplevel window that's an ancestor of @window.
2400 * Any window type but %GDK_WINDOW_CHILD is considered a
2401 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2402 * has a root window as parent.
2404 * Note that you should use gdk_window_get_effective_toplevel() when
2405 * you want to get to a window's toplevel as seen on screen, because
2406 * gdk_window_get_toplevel() will most likely not do what you expect
2407 * if there are offscreen windows in the hierarchy.
2409 * Return value: (transfer none): the toplevel window containing @window
2412 gdk_window_get_toplevel (GdkWindow *window)
2414 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2416 while (window->window_type == GDK_WINDOW_CHILD)
2418 if (gdk_window_is_toplevel (window))
2420 window = window->parent;
2427 * gdk_window_get_effective_toplevel:
2428 * @window: a #GdkWindow
2430 * Gets the toplevel window that's an ancestor of @window.
2432 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2433 * embedder as its parent, using gdk_window_get_effective_parent().
2435 * See also: gdk_offscreen_window_get_embedder()
2437 * Return value: (transfer none): the effective toplevel window containing @window
2442 gdk_window_get_effective_toplevel (GdkWindow *window)
2446 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2448 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2449 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2456 * gdk_window_get_children:
2457 * @window: a #GdkWindow
2459 * Gets the list of children of @window known to GDK.
2460 * This function only returns children created via GDK,
2461 * so for example it's useless when used with the root window;
2462 * it only returns windows an application created itself.
2464 * The returned list must be freed, but the elements in the
2467 * Return value: (transfer container) (element-type GdkWindow):
2468 * list of child windows inside @window
2471 gdk_window_get_children (GdkWindow *window)
2473 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2475 if (GDK_WINDOW_DESTROYED (window))
2478 return g_list_copy (window->children);
2482 * gdk_window_peek_children:
2483 * @window: a #GdkWindow
2485 * Like gdk_window_get_children(), but does not copy the list of
2486 * children, so the list does not need to be freed.
2488 * Return value: (transfer none) (element-type GdkWindow):
2489 * a reference to the list of child windows in @window
2492 gdk_window_peek_children (GdkWindow *window)
2494 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2496 if (GDK_WINDOW_DESTROYED (window))
2499 return window->children;
2503 * gdk_window_add_filter: (skip)
2504 * @window: (allow-none): a #GdkWindow
2505 * @function: filter callback
2506 * @data: data to pass to filter callback
2508 * Adds an event filter to @window, allowing you to intercept events
2509 * before they reach GDK. This is a low-level operation and makes it
2510 * easy to break GDK and/or GTK+, so you have to know what you're
2511 * doing. Pass %NULL for @window to get all events for all windows,
2512 * instead of events for a specific window.
2514 * If you are interested in X GenericEvents, bear in mind that
2515 * XGetEventData() has been already called on the event, and
2516 * XFreeEventData() must not be called within @function.
2519 gdk_window_add_filter (GdkWindow *window,
2520 GdkFilterFunc function,
2524 GdkEventFilter *filter;
2526 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2528 if (window && GDK_WINDOW_DESTROYED (window))
2531 /* Filters are for the native events on the native window, so
2532 ensure there is a native window. */
2534 gdk_window_ensure_native (window);
2537 tmp_list = window->filters;
2539 tmp_list = _gdk_default_filters;
2543 filter = (GdkEventFilter *)tmp_list->data;
2544 if ((filter->function == function) && (filter->data == data))
2546 filter->ref_count++;
2549 tmp_list = tmp_list->next;
2552 filter = g_new (GdkEventFilter, 1);
2553 filter->function = function;
2554 filter->data = data;
2555 filter->ref_count = 1;
2559 window->filters = g_list_append (window->filters, filter);
2561 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2565 * gdk_window_remove_filter: (skip)
2566 * @window: a #GdkWindow
2567 * @function: previously-added filter function
2568 * @data: user data for previously-added filter function
2570 * Remove a filter previously added with gdk_window_add_filter().
2573 gdk_window_remove_filter (GdkWindow *window,
2574 GdkFilterFunc function,
2578 GdkEventFilter *filter;
2580 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2583 tmp_list = window->filters;
2585 tmp_list = _gdk_default_filters;
2589 filter = (GdkEventFilter *)tmp_list->data;
2590 tmp_list = tmp_list->next;
2592 if ((filter->function == function) && (filter->data == data))
2594 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2596 _gdk_event_filter_unref (window, filter);
2604 * gdk_screen_get_toplevel_windows:
2605 * @screen: The #GdkScreen where the toplevels are located.
2607 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2608 * A toplevel window is a child of the root window (see
2609 * gdk_get_default_root_window()).
2611 * The returned list should be freed with g_list_free(), but
2612 * its elements need not be freed.
2614 * Return value: (transfer container) (element-type GdkWindow):
2615 * list of toplevel windows, free with g_list_free()
2620 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2622 GdkWindow * root_window;
2623 GList *new_list = NULL;
2626 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2628 root_window = gdk_screen_get_root_window (screen);
2630 tmp_list = root_window->children;
2633 GdkWindow *w = tmp_list->data;
2635 if (w->window_type != GDK_WINDOW_FOREIGN)
2636 new_list = g_list_prepend (new_list, w);
2637 tmp_list = tmp_list->next;
2644 * gdk_window_is_visible:
2645 * @window: a #GdkWindow
2647 * Checks whether the window has been mapped (with gdk_window_show() or
2648 * gdk_window_show_unraised()).
2650 * Return value: %TRUE if the window is mapped
2653 gdk_window_is_visible (GdkWindow *window)
2655 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2657 return GDK_WINDOW_IS_MAPPED (window);
2661 * gdk_window_is_viewable:
2662 * @window: a #GdkWindow
2664 * Check if the window and all ancestors of the window are
2665 * mapped. (This is not necessarily "viewable" in the X sense, since
2666 * we only check as far as we have GDK window parents, not to the root
2669 * Return value: %TRUE if the window is viewable
2672 gdk_window_is_viewable (GdkWindow *window)
2674 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2676 if (window->destroyed)
2679 return window->viewable;
2683 * gdk_window_get_state:
2684 * @window: a #GdkWindow
2686 * Gets the bitwise OR of the currently active window state flags,
2687 * from the #GdkWindowState enumeration.
2689 * Return value: window state bitfield
2692 gdk_window_get_state (GdkWindow *window)
2694 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2696 return window->state;
2699 static cairo_content_t
2700 gdk_window_get_content (GdkWindow *window)
2702 cairo_surface_t *surface;
2703 cairo_content_t content;
2705 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2707 surface = gdk_window_ref_impl_surface (window);
2708 content = cairo_surface_get_content (surface);
2709 cairo_surface_destroy (surface);
2714 /* This creates an empty "implicit" paint region for the impl window.
2715 * By itself this does nothing, but real paints to this window
2716 * or children of it can use this surface as backing to avoid allocating
2717 * multiple surfaces for subwindow rendering. When doing so they
2718 * add to the region of the implicit paint region, which will be
2719 * pushed to the window when the implicit paint region is ended.
2720 * Such paints should not copy anything to the window on paint end, but
2721 * should rely on the implicit paint end.
2722 * The implicit paint will be automatically ended if someone draws
2723 * directly to the window or a child window.
2726 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect,
2727 gboolean with_alpha, guint8 alpha)
2729 GdkWindowPaint *paint;
2731 g_assert (gdk_window_has_impl (window));
2733 if (GDK_IS_PAINTABLE (window->impl))
2734 return FALSE; /* Implementation does double buffering */
2736 if (window->paint_stack != NULL)
2737 return FALSE; /* Don't stack implicit paints */
2739 /* Never do implicit paints for foreign windows, they don't need
2740 * double buffer combination since they have no client side children,
2741 * and creating surfaces for them is risky since they could disappear
2744 if (window->window_type == GDK_WINDOW_FOREIGN)
2747 paint = g_new (GdkWindowPaint, 1);
2748 paint->region = cairo_region_create (); /* Empty */
2749 paint->uses_implicit = FALSE;
2750 paint->flushed = NULL;
2751 paint->alpha = alpha;
2752 paint->surface = gdk_window_create_similar_surface (window,
2753 with_alpha ? CAIRO_CONTENT_COLOR_ALPHA : gdk_window_get_content (window),
2754 MAX (rect->width, 1),
2755 MAX (rect->height, 1));
2756 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2758 window->implicit_paint = g_slist_prepend (window->implicit_paint, paint);
2763 static cairo_surface_t *
2764 gdk_window_ref_impl_surface (GdkWindow *window)
2766 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2770 gdk_cairo_create_for_impl (GdkWindow *window)
2772 cairo_surface_t *surface;
2775 surface = gdk_window_ref_impl_surface (window);
2776 cr = cairo_create (surface);
2778 cairo_surface_destroy (surface);
2783 /* This is called whenever something is drawing directly to the
2784 * window, bypassing the double buffering. When this happens we
2785 * need to mark any the currently drawn data in the double buffer
2786 * as invalid to avoid later drawing it back over the directly
2787 * rendered pixels. We also need to mark this region as "flushed"
2788 * so that if we later try to paint on it double-buffered we need
2789 * to read back the on-window pixels rather than relying on what
2790 * is in the current double-buffer pixmap.
2792 * Note that this doesn't correctly handle the case where the
2793 * non-double buffered drawing uses transparency and relies on
2794 * what the windows below it draws. A fix for that would require
2795 * drawing the existing double-buffered background to the window,
2796 * but that causes ugly flashes. Non-double buffered drawing is
2797 * typically only used in old code or when the drawed widget
2798 * already has a double-buffering layer, and in these cases the
2799 * pixels are opaque anyway. If you need transparency, don't
2800 * disable double buffering.
2803 gdk_window_flush_implicit_paint (GdkWindow *window)
2805 GdkWindow *impl_window;
2806 GdkWindowPaint *paint;
2807 cairo_region_t *region;
2810 impl_window = gdk_window_get_impl_window (window);
2811 if (impl_window->implicit_paint == NULL)
2814 /* There is no proper way to flush any non-toplevel implicit
2815 paint, because direct rendering is not compatible with
2816 opacity rendering, as it requires an opacity group.
2818 We warn and flush just the outermost paint in this case.
2820 l = g_slist_last (impl_window->implicit_paint);
2821 if (l != impl_window->implicit_paint)
2822 g_warning ("Non double buffered drawing not supported inside transparent windows");
2826 region = cairo_region_copy (window->clip_region_with_children);
2827 cairo_region_translate (region, window->abs_x, window->abs_y);
2829 /* Anything in the whole flushed window that was drawn is now
2830 considered unpainted, so that we don't push it back at the
2831 end of the implicit paint overwriting the directly rendered
2833 cairo_region_subtract (paint->region, region);
2835 /* Save flushed area so we can read it back if we draw over it later */
2836 if (paint->flushed == NULL)
2837 paint->flushed = region;
2840 cairo_region_union (paint->flushed, region);
2841 cairo_region_destroy (region);
2845 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2847 gdk_window_end_implicit_paint (GdkWindow *window)
2849 GdkWindowPaint *paint;
2851 g_assert (gdk_window_has_impl (window));
2853 g_assert (window->implicit_paint != NULL);
2855 paint = window->implicit_paint->data;
2857 window->implicit_paint = g_slist_delete_link (window->implicit_paint,
2858 window->implicit_paint);
2860 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region) && paint->alpha > 0)
2862 GdkWindowPaint *parent_paint = NULL;
2865 /* Some regions are valid, push these to window now */
2866 if (window->implicit_paint)
2868 parent_paint = window->implicit_paint->data;
2870 /* If the toplevel implicit paint was flushed, restore it now
2871 before we blend over it. */
2872 if (parent_paint->flushed != NULL &&
2873 !cairo_region_is_empty (parent_paint->flushed))
2875 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (window);
2876 cairo_region_t *flushed = cairo_region_copy (parent_paint->flushed);
2878 cr = cairo_create (parent_paint->surface);
2879 cairo_set_source_surface (cr, source_surface, 0, 0);
2880 cairo_surface_destroy (source_surface);
2882 cairo_region_intersect (flushed, paint->region);
2883 gdk_cairo_region (cr, flushed);
2886 cairo_region_subtract (parent_paint->flushed, flushed);
2887 cairo_region_destroy (flushed);
2893 cr = cairo_create (parent_paint->surface);
2896 cr = gdk_cairo_create_for_impl (window);
2898 gdk_cairo_region (cr, paint->region);
2900 cairo_set_source_surface (cr, paint->surface, 0, 0);
2901 if (paint->alpha == 255)
2903 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2908 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2909 cairo_paint_with_alpha (cr, paint->alpha / 255.0);
2915 cairo_region_union (parent_paint->region, paint->region);
2918 cairo_region_destroy (paint->region);
2920 cairo_region_destroy (paint->flushed);
2921 cairo_surface_destroy (paint->surface);
2926 * gdk_window_begin_paint_rect:
2927 * @window: a #GdkWindow
2928 * @rectangle: rectangle you intend to draw to
2930 * A convenience wrapper around gdk_window_begin_paint_region() which
2931 * creates a rectangular region for you. See
2932 * gdk_window_begin_paint_region() for details.
2936 gdk_window_begin_paint_rect (GdkWindow *window,
2937 const GdkRectangle *rectangle)
2939 cairo_region_t *region;
2941 g_return_if_fail (GDK_IS_WINDOW (window));
2943 region = cairo_region_create_rectangle (rectangle);
2944 gdk_window_begin_paint_region (window, region);
2945 cairo_region_destroy (region);
2949 * gdk_window_begin_paint_region:
2950 * @window: a #GdkWindow
2951 * @region: region you intend to draw to
2953 * Indicates that you are beginning the process of redrawing @region.
2954 * A backing store (offscreen buffer) large enough to contain @region
2955 * will be created. The backing store will be initialized with the
2956 * background color or background surface for @window. Then, all
2957 * drawing operations performed on @window will be diverted to the
2958 * backing store. When you call gdk_window_end_paint(), the backing
2959 * store will be copied to @window, making it visible onscreen. Only
2960 * the part of @window contained in @region will be modified; that is,
2961 * drawing operations are clipped to @region.
2963 * The net result of all this is to remove flicker, because the user
2964 * sees the finished product appear all at once when you call
2965 * gdk_window_end_paint(). If you draw to @window directly without
2966 * calling gdk_window_begin_paint_region(), the user may see flicker
2967 * as individual drawing operations are performed in sequence. The
2968 * clipping and background-initializing features of
2969 * gdk_window_begin_paint_region() are conveniences for the
2970 * programmer, so you can avoid doing that work yourself.
2972 * When using GTK+, the widget system automatically places calls to
2973 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2974 * emissions of the expose_event signal. That is, if you're writing an
2975 * expose event handler, you can assume that the exposed area in
2976 * #GdkEventExpose has already been cleared to the window background,
2977 * is already set as the clip region, and already has a backing store.
2978 * Therefore in most cases, application code need not call
2979 * gdk_window_begin_paint_region(). (You can disable the automatic
2980 * calls around expose events on a widget-by-widget basis by calling
2981 * gtk_widget_set_double_buffered().)
2983 * If you call this function multiple times before calling the
2984 * matching gdk_window_end_paint(), the backing stores are pushed onto
2985 * a stack. gdk_window_end_paint() copies the topmost backing store
2986 * onscreen, subtracts the topmost region from all other regions in
2987 * the stack, and pops the stack. All drawing operations affect only
2988 * the topmost backing store in the stack. One matching call to
2989 * gdk_window_end_paint() is required for each call to
2990 * gdk_window_begin_paint_region().
2994 gdk_window_begin_paint_region (GdkWindow *window,
2995 const cairo_region_t *region)
2997 #ifdef USE_BACKING_STORE
2998 GdkRectangle clip_box;
2999 GdkWindowPaint *paint, *implicit_paint;
3000 GdkWindow *impl_window;
3003 g_return_if_fail (GDK_IS_WINDOW (window));
3005 if (GDK_WINDOW_DESTROYED (window))
3008 if (GDK_IS_PAINTABLE (window->impl))
3010 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3012 if (iface->begin_paint_region)
3013 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
3018 impl_window = gdk_window_get_impl_window (window);
3019 implicit_paint = impl_window->implicit_paint != NULL ? impl_window->implicit_paint->data : NULL;
3021 paint = g_new (GdkWindowPaint, 1);
3022 paint->region = cairo_region_copy (region);
3024 cairo_region_intersect (paint->region, window->clip_region_with_children);
3025 cairo_region_get_extents (paint->region, &clip_box);
3027 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
3029 /* Mark the region as valid on the implicit paint */
3032 cairo_region_union (implicit_paint->region, paint->region);
3034 /* Convert back to normal coords */
3035 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
3039 paint->uses_implicit = TRUE;
3040 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
3041 window->abs_x + clip_box.x,
3042 window->abs_y + clip_box.y,
3043 MAX (clip_box.width, 1),
3044 MAX (clip_box.height, 1));
3048 paint->uses_implicit = FALSE;
3049 paint->surface = gdk_window_create_similar_surface (window,
3050 gdk_window_get_content (window),
3051 MAX (clip_box.width, 1),
3052 MAX (clip_box.height, 1));
3055 /* Normally alpha backgrounded client side windows are composited on the implicit paint
3056 by being drawn in back to front order. However, if implicit paints are not used, for
3057 instance if it was flushed due to a non-double-buffered paint in the middle of the
3058 expose we need to copy in the existing data here. */
3059 if (gdk_window_has_alpha (window) &&
3061 (implicit_paint && implicit_paint->flushed != NULL && !cairo_region_is_empty (implicit_paint->flushed))))
3063 cairo_t *cr = cairo_create (paint->surface);
3064 /* We can't use gdk_cairo_set_source_window here, as that might
3065 flush the implicit paint at an unfortunate time, since this
3066 would be detected as a draw during non-expose time */
3067 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (impl_window);
3068 cairo_set_source_surface (cr, source_surface,
3069 - (window->abs_x + clip_box.x),
3070 - (window->abs_y + clip_box.y));
3071 cairo_surface_destroy (source_surface);
3073 /* Only read back the flushed area if any */
3076 cairo_region_t *flushed = cairo_region_copy (implicit_paint->flushed);
3077 /* Convert from impl coords */
3078 cairo_region_translate (flushed, -window->abs_x, -window->abs_y);
3079 cairo_region_intersect (flushed, paint->region);
3080 gdk_cairo_region (cr, flushed);
3083 /* Convert to impl coords */
3084 cairo_region_translate (flushed, window->abs_x, window->abs_y);
3085 cairo_region_subtract (implicit_paint->flushed, flushed);
3086 cairo_region_destroy (flushed);
3092 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3094 for (list = window->paint_stack; list != NULL; list = list->next)
3096 GdkWindowPaint *tmp_paint = list->data;
3098 cairo_region_subtract (tmp_paint->region, paint->region);
3101 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
3103 if (!cairo_region_is_empty (paint->region))
3105 gdk_window_clear_backing_region (window,
3109 #endif /* USE_BACKING_STORE */
3113 * gdk_window_end_paint:
3114 * @window: a #GdkWindow
3116 * Indicates that the backing store created by the most recent call to
3117 * gdk_window_begin_paint_region() should be copied onscreen and
3118 * deleted, leaving the next-most-recent backing store or no backing
3119 * store at all as the active paint region. See
3120 * gdk_window_begin_paint_region() for full details. It is an error to
3121 * call this function without a matching
3122 * gdk_window_begin_paint_region() first.
3126 gdk_window_end_paint (GdkWindow *window)
3128 #ifdef USE_BACKING_STORE
3129 GdkWindow *composited;
3130 GdkWindowPaint *paint;
3131 GdkRectangle clip_box;
3132 cairo_region_t *full_clip;
3134 g_return_if_fail (GDK_IS_WINDOW (window));
3136 if (GDK_WINDOW_DESTROYED (window))
3139 if (GDK_IS_PAINTABLE (window->impl))
3141 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3143 if (iface->end_paint)
3144 iface->end_paint ((GdkPaintable*)window->impl);
3148 if (window->paint_stack == NULL)
3150 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3154 paint = window->paint_stack->data;
3156 window->paint_stack = g_slist_delete_link (window->paint_stack,
3157 window->paint_stack);
3159 cairo_region_get_extents (paint->region, &clip_box);
3161 if (!paint->uses_implicit)
3165 gdk_window_flush_outstanding_moves (window);
3167 full_clip = cairo_region_copy (window->clip_region_with_children);
3168 cairo_region_intersect (full_clip, paint->region);
3170 cr = gdk_cairo_create (window);
3171 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3172 cairo_set_source_surface (cr, paint->surface, 0, 0);
3173 gdk_cairo_region (cr, full_clip);
3177 cairo_region_destroy (full_clip);
3180 cairo_surface_destroy (paint->surface);
3181 cairo_region_destroy (paint->region);
3184 /* find a composited window in our hierarchy to signal its
3185 * parent to redraw, calculating the clip box as we go...
3187 * stop if parent becomes NULL since then we'd have nowhere
3188 * to draw (ie: 'composited' will always be non-NULL here).
3190 for (composited = window;
3192 composited = composited->parent)
3194 clip_box.x += composited->x;
3195 clip_box.y += composited->y;
3196 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3197 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3199 if (composited->composited)
3201 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3206 #endif /* USE_BACKING_STORE */
3210 gdk_window_free_paint_stack (GdkWindow *window)
3212 if (window->paint_stack)
3214 GSList *tmp_list = window->paint_stack;
3218 GdkWindowPaint *paint = tmp_list->data;
3220 if (tmp_list == window->paint_stack)
3221 cairo_surface_destroy (paint->surface);
3223 cairo_region_destroy (paint->region);
3226 tmp_list = tmp_list->next;
3229 g_slist_free (window->paint_stack);
3230 window->paint_stack = NULL;
3235 do_move_region_bits_on_impl (GdkWindow *impl_window,
3236 cairo_region_t *dest_region, /* In impl window coords */
3239 GdkWindowImplClass *impl_class;
3241 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3243 impl_class->translate (impl_window, dest_region, dx, dy);
3246 static GdkWindowRegionMove *
3247 gdk_window_region_move_new (cairo_region_t *region,
3250 GdkWindowRegionMove *move;
3252 move = g_slice_new (GdkWindowRegionMove);
3253 move->dest_region = cairo_region_copy (region);
3261 gdk_window_region_move_free (GdkWindowRegionMove *move)
3263 cairo_region_destroy (move->dest_region);
3264 g_slice_free (GdkWindowRegionMove, move);
3268 append_move_region (GdkWindow *impl_window,
3269 cairo_region_t *new_dest_region,
3272 GdkWindowRegionMove *move, *old_move;
3273 cairo_region_t *new_total_region, *old_total_region;
3274 cairo_region_t *source_overlaps_destination;
3275 cairo_region_t *non_overwritten;
3276 gboolean added_move;
3279 if (cairo_region_is_empty (new_dest_region))
3282 /* In principle this could just append the move to the list of outstanding
3283 moves that will be replayed before drawing anything when we're handling
3284 exposes. However, we'd like to do a bit better since its commonly the case
3285 that we get multiple copies where A is copied to B and then B is copied
3286 to C, and we'd like to express this as a simple copy A to C operation. */
3288 /* We approach this by taking the new move and pushing it ahead of moves
3289 starting at the end of the list and stopping when its not safe to do so.
3290 It's not safe to push past a move if either the source of the new move
3291 is in the destination of the old move, or if the destination of the new
3292 move is in the source of the new move, or if the destination of the new
3293 move overlaps the destination of the old move. We simplify this by
3294 just comparing the total regions (src + dest) */
3295 new_total_region = cairo_region_copy (new_dest_region);
3296 cairo_region_translate (new_total_region, -dx, -dy);
3297 cairo_region_union (new_total_region, new_dest_region);
3300 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3305 old_total_region = cairo_region_copy (old_move->dest_region);
3306 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3307 cairo_region_union (old_total_region, old_move->dest_region);
3309 cairo_region_intersect (old_total_region, new_total_region);
3310 /* If these regions intersect then its not safe to push the
3311 new region before the old one */
3312 if (!cairo_region_is_empty (old_total_region))
3314 /* The area where the new moves source overlaps the old ones
3316 source_overlaps_destination = cairo_region_copy (new_dest_region);
3317 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3318 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3319 cairo_region_translate (source_overlaps_destination, dx, dy);
3321 /* We can do all sort of optimizations here, but to do things safely it becomes
3322 quite complicated. However, a very common case is that you copy something first,
3323 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3324 in the same direction). We'd like to detect this case and optimize it to one
3326 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3328 /* This means we might be able to replace the old move and the new one
3329 with the new one read from the old ones source, and a second copy of
3330 the non-overwritten parts of the old move. However, such a split
3331 is only valid if the source in the old move isn't overwritten
3332 by the destination of the new one */
3334 /* the new destination of old move if split is ok: */
3335 non_overwritten = cairo_region_copy (old_move->dest_region);
3336 cairo_region_subtract (non_overwritten, new_dest_region);
3337 /* move to source region */
3338 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3340 cairo_region_intersect (non_overwritten, new_dest_region);
3341 if (cairo_region_is_empty (non_overwritten))
3344 move = gdk_window_region_move_new (new_dest_region,
3348 impl_window->outstanding_moves =
3349 g_list_insert_before (impl_window->outstanding_moves,
3351 cairo_region_subtract (old_move->dest_region, new_dest_region);
3353 cairo_region_destroy (non_overwritten);
3356 cairo_region_destroy (source_overlaps_destination);
3357 cairo_region_destroy (old_total_region);
3360 cairo_region_destroy (old_total_region);
3363 cairo_region_destroy (new_total_region);
3367 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3370 impl_window->outstanding_moves =
3371 g_list_prepend (impl_window->outstanding_moves,
3374 impl_window->outstanding_moves =
3375 g_list_insert_before (impl_window->outstanding_moves,
3380 /* Moves bits and update area by dx/dy in impl window.
3381 Takes ownership of region to avoid copy (because we may change it) */
3383 move_region_on_impl (GdkWindow *impl_window,
3384 cairo_region_t *region, /* In impl window coords */
3389 if ((dx == 0 && dy == 0) ||
3390 cairo_region_is_empty (region))
3392 cairo_region_destroy (region);
3396 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3398 /* Move any old invalid regions in the copy source area by dx/dy */
3399 if (impl_window->update_area)
3401 cairo_region_t *update_area;
3403 update_area = cairo_region_copy (region);
3405 /* Convert from target to source */
3406 cairo_region_translate (update_area, -dx, -dy);
3407 cairo_region_intersect (update_area, impl_window->update_area);
3408 /* We only copy the area, so keep the old update area invalid.
3409 It would be safe to remove it too, as code that uses
3410 move_region_on_impl generally also invalidate the source
3411 area. However, it would just use waste cycles. */
3414 cairo_region_translate (update_area, dx, dy);
3415 cairo_region_union (impl_window->update_area, update_area);
3417 /* This area of the destination is now invalid,
3418 so no need to copy to it. */
3419 cairo_region_subtract (region, update_area);
3421 cairo_region_destroy (update_area);
3424 /* If we're currently exposing this window, don't copy to this
3425 destination, as it will be overdrawn when the expose is done,
3426 instead invalidate it and repaint later. */
3427 for (l = impl_window->implicit_paint; l != NULL; l = l->next)
3429 GdkWindowPaint *implicit_paint = l->data;
3430 cairo_region_t *exposing;
3432 exposing = cairo_region_copy (implicit_paint->region);
3433 cairo_region_intersect (exposing, region);
3434 cairo_region_subtract (region, exposing);
3436 impl_window_add_update_area (impl_window, exposing);
3437 cairo_region_destroy (exposing);
3440 append_move_region (impl_window, region, dx, dy);
3442 cairo_region_destroy (region);
3445 /* Flushes all outstanding changes to the window, call this
3446 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3449 gdk_window_flush_outstanding_moves (GdkWindow *window)
3451 GdkWindow *impl_window;
3452 GList *l, *outstanding;
3453 GdkWindowRegionMove *move;
3455 impl_window = gdk_window_get_impl_window (window);
3456 outstanding = impl_window->outstanding_moves;
3457 impl_window->outstanding_moves = NULL;
3459 for (l = outstanding; l != NULL; l = l->next)
3463 do_move_region_bits_on_impl (impl_window,
3464 move->dest_region, move->dx, move->dy);
3466 gdk_window_region_move_free (move);
3469 g_list_free (outstanding);
3474 * @window: a #GdkWindow
3476 * Flush all outstanding cached operations on a window, leaving the
3477 * window in a state which reflects all that has been drawn before.
3479 * Gdk uses multiple kinds of caching to get better performance and
3480 * nicer drawing. For instance, during exposes all paints to a window
3481 * using double buffered rendering are keep on a surface until the last
3482 * window has been exposed. It also delays window moves/scrolls until
3483 * as long as possible until next update to avoid tearing when moving
3486 * Normally this should be completely invisible to applications, as
3487 * we automatically flush the windows when required, but this might
3488 * be needed if you for instance mix direct native drawing with
3489 * gdk drawing. For Gtk widgets that don't use double buffering this
3490 * will be called automatically before sending the expose event.
3495 gdk_window_flush (GdkWindow *window)
3497 gdk_window_flush_outstanding_moves (window);
3498 gdk_window_flush_implicit_paint (window);
3502 gdk_window_flush_recursive_helper (GdkWindow *window,
3503 GdkWindowImpl *impl)
3508 for (l = window->children; l != NULL; l = l->next)
3512 if (child->impl == impl)
3513 /* Same impl, ignore */
3514 gdk_window_flush_recursive_helper (child, impl);
3516 gdk_window_flush_recursive (child);
3521 gdk_window_flush_recursive (GdkWindow *window)
3523 gdk_window_flush (window);
3524 gdk_window_flush_recursive_helper (window, window->impl);
3528 * gdk_window_get_clip_region:
3529 * @window: a #GdkWindow
3531 * Computes the region of a window that potentially can be written
3532 * to by drawing primitives. This region may not take into account
3533 * other factors such as if the window is obscured by other windows,
3534 * but no area outside of this region will be affected by drawing
3537 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3538 * when you are done.
3541 gdk_window_get_clip_region (GdkWindow *window)
3543 cairo_region_t *result;
3545 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3547 result = cairo_region_copy (window->clip_region);
3549 if (window->paint_stack)
3551 cairo_region_t *paint_region = cairo_region_create ();
3552 GSList *tmp_list = window->paint_stack;
3556 GdkWindowPaint *paint = tmp_list->data;
3558 cairo_region_union (paint_region, paint->region);
3560 tmp_list = tmp_list->next;
3563 cairo_region_intersect (result, paint_region);
3564 cairo_region_destroy (paint_region);
3571 * gdk_window_get_visible_region:
3572 * @window: a #GdkWindow
3574 * Computes the region of the @window that is potentially visible.
3575 * This does not necessarily take into account if the window is
3576 * obscured by other windows, but no area outside of this region
3579 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3580 * when you are done.
3583 gdk_window_get_visible_region (GdkWindow *window)
3585 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3587 return cairo_region_copy (window->clip_region);
3591 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint)
3593 GdkWindow *bg_window;
3594 cairo_pattern_t *pattern = NULL;
3595 int x_offset = 0, y_offset = 0;
3598 cr = cairo_create (paint->surface);
3600 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3602 pattern = gdk_window_get_background_pattern (bg_window);
3606 x_offset += bg_window->x;
3607 y_offset += bg_window->y;
3612 cairo_translate (cr, -x_offset, -y_offset);
3613 cairo_set_source (cr, pattern);
3614 cairo_translate (cr, x_offset, y_offset);
3617 cairo_set_source_rgb (cr, 0, 0, 0);
3623 gdk_window_clear_backing_region (GdkWindow *window,
3624 cairo_region_t *region)
3626 GdkWindowPaint *paint = window->paint_stack->data;
3627 cairo_region_t *clip;
3630 if (GDK_WINDOW_DESTROYED (window))
3633 cr = setup_backing_rect (window, paint);
3635 clip = cairo_region_copy (paint->region);
3636 cairo_region_intersect (clip, region);
3638 gdk_cairo_region (cr, clip);
3643 cairo_region_destroy (clip);
3647 gdk_window_drop_cairo_surface (GdkWindow *window)
3649 if (window->cairo_surface)
3651 cairo_surface_finish (window->cairo_surface);
3652 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3654 window->cairo_surface = NULL;
3659 gdk_window_cairo_surface_destroy (void *data)
3661 GdkWindow *window = data;
3663 window->cairo_surface = NULL;
3666 static cairo_surface_t *
3667 gdk_window_create_cairo_surface (GdkWindow *window,
3671 cairo_surface_t *surface, *subsurface;
3673 surface = gdk_window_ref_impl_surface (window);
3674 if (gdk_window_has_impl (window))
3677 subsurface = cairo_surface_create_for_rectangle (surface,
3682 cairo_surface_destroy (surface);
3688 _gdk_window_ref_cairo_surface (GdkWindow *window)
3690 cairo_surface_t *surface;
3692 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3694 if (window->paint_stack)
3696 GdkWindowPaint *paint = window->paint_stack->data;
3698 surface = paint->surface;
3699 cairo_surface_reference (surface);
3704 /* This will be drawing directly to the window, so flush implicit paint */
3705 gdk_window_flush (window);
3707 if (!window->cairo_surface)
3709 window->cairo_surface = gdk_window_create_cairo_surface (window,
3713 if (window->cairo_surface)
3715 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3716 window, gdk_window_cairo_surface_destroy);
3720 cairo_surface_reference (window->cairo_surface);
3722 surface = window->cairo_surface;
3730 * @window: a #GdkWindow
3732 * Creates a Cairo context for drawing to @window.
3735 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3736 * produce undefined results, so avoid it at all costs.
3739 * Return value: A newly created Cairo context. Free with
3740 * cairo_destroy() when you are done drawing.
3745 gdk_cairo_create (GdkWindow *window)
3747 cairo_surface_t *surface;
3750 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3752 surface = _gdk_window_ref_cairo_surface (window);
3753 cr = cairo_create (surface);
3755 if (!window->paint_stack)
3757 gdk_cairo_region (cr, window->clip_region_with_children);
3762 GdkWindowPaint *paint = window->paint_stack->data;
3764 /* Only needs to clip to region if piggybacking
3765 on an implicit paint */
3766 if (paint->uses_implicit)
3768 gdk_cairo_region (cr, paint->region);
3773 cairo_surface_destroy (surface);
3778 /* Code for dirty-region queueing
3780 static GSList *update_windows = NULL;
3781 static guint update_idle = 0;
3782 static gboolean debug_updates = FALSE;
3784 static inline gboolean
3785 gdk_window_is_ancestor (GdkWindow *window,
3786 GdkWindow *ancestor)
3790 GdkWindow *parent = window->parent;
3792 if (parent == ancestor)
3802 gdk_window_add_update_window (GdkWindow *window)
3805 GSList *prev = NULL;
3806 gboolean has_ancestor_in_list = FALSE;
3808 for (tmp = update_windows; tmp; tmp = tmp->next)
3810 GdkWindow *parent = window->parent;
3812 /* check if tmp is an ancestor of "window"; if it is, set a
3813 * flag indicating that all following windows are either
3814 * children of "window" or from a differen hierarchy
3816 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3817 has_ancestor_in_list = TRUE;
3819 /* insert in reverse stacking order when adding around siblings,
3820 * so processing updates properly paints over lower stacked windows
3822 if (parent == GDK_WINDOW (tmp->data)->parent)
3824 gint index = g_list_index (parent->children, window);
3825 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3827 gint sibling_index = g_list_index (parent->children, tmp->data);
3828 if (index > sibling_index)
3832 /* here, tmp got advanced past all lower stacked siblings */
3833 tmp = g_slist_prepend (tmp, window);
3837 update_windows = tmp;
3841 /* if "window" has an ancestor in the list and tmp is one of
3842 * "window's" children, insert "window" before tmp
3844 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3846 tmp = g_slist_prepend (tmp, window);
3851 update_windows = tmp;
3855 /* if we're at the end of the list and had an ancestor it it,
3856 * append to the list
3858 if (! tmp->next && has_ancestor_in_list)
3860 tmp = g_slist_append (tmp, window);
3867 /* if all above checks failed ("window" is from a different
3868 * hierarchy than what is already in the list) or the list is
3871 update_windows = g_slist_prepend (update_windows, window);
3875 gdk_window_remove_update_window (GdkWindow *window)
3877 update_windows = g_slist_remove (update_windows, window);
3881 gdk_window_update_idle (gpointer data)
3883 gdk_window_process_all_updates ();
3889 gdk_window_is_toplevel_frozen (GdkWindow *window)
3891 GdkWindow *toplevel;
3893 toplevel = gdk_window_get_toplevel (window);
3895 return toplevel->update_and_descendants_freeze_count > 0;
3899 gdk_window_schedule_update (GdkWindow *window)
3902 (window->update_freeze_count ||
3903 gdk_window_is_toplevel_frozen (window)))
3908 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3909 gdk_window_update_idle,
3914 _gdk_window_process_updates_recurse (GdkWindow *window,
3915 cairo_region_t *expose_region)
3918 cairo_region_t *clipped_expose_region;
3919 GdkRectangle clip_box;
3920 GList *l, *children;
3921 gboolean end_implicit;
3923 if (cairo_region_is_empty (expose_region))
3926 if (gdk_window_is_offscreen (window->impl_window) &&
3927 gdk_window_has_impl (window))
3928 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3930 end_implicit = FALSE;
3931 if (window->alpha != 255 && !gdk_window_has_impl (window))
3933 if (window->alpha == 0)
3936 cairo_region_get_extents (expose_region, &clip_box);
3937 clip_box.x += window->abs_x;
3938 clip_box.y += window->abs_y;
3939 end_implicit = gdk_window_begin_implicit_paint (window->impl_window, &clip_box, TRUE, window->alpha);
3942 /* Paint the window before the children, clipped to the window region
3943 with visible child windows removed */
3944 clipped_expose_region = cairo_region_copy (expose_region);
3945 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3947 if (!cairo_region_is_empty (clipped_expose_region) &&
3950 if (window->event_mask & GDK_EXPOSURE_MASK)
3954 event.expose.type = GDK_EXPOSE;
3955 event.expose.window = g_object_ref (window);
3956 event.expose.send_event = FALSE;
3957 event.expose.count = 0;
3958 event.expose.region = clipped_expose_region;
3959 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
3961 _gdk_event_emit (&event);
3963 g_object_unref (window);
3965 else if (window->window_type != GDK_WINDOW_FOREIGN)
3967 /* No exposure mask set, so nothing will be drawn, the
3968 * app relies on the background being what it specified
3969 * for the window. So, we need to clear this manually.
3971 * For foreign windows if expose is not set that generally
3972 * means some other client paints them, so don't clear
3975 * We use begin/end_paint around the clear so that we can
3976 * piggyback on the implicit paint */
3978 gdk_window_begin_paint_region (window, clipped_expose_region);
3979 /* The actual clear happens in begin_paint_region */
3980 gdk_window_end_paint (window);
3983 cairo_region_destroy (clipped_expose_region);
3985 /* Make this reentrancy safe for expose handlers freeing windows */
3986 children = g_list_copy (window->children);
3987 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3989 /* Iterate over children, starting at bottommost */
3990 for (l = g_list_last (children); l != NULL; l = l->prev)
3994 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3997 /* Ignore offscreen children, as they don't draw in their parent and
3998 * don't take part in the clipping */
3999 if (gdk_window_is_offscreen (child))
4002 /* Client side child, expose */
4003 if (child->impl == window->impl)
4005 cairo_region_translate (expose_region, -child->x, -child->y);
4006 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
4007 cairo_region_translate (expose_region, child->x, child->y);
4011 g_list_free_full (children, g_object_unref);
4014 gdk_window_end_implicit_paint (window->impl_window);
4017 /* Process and remove any invalid area on the native window by creating
4018 * expose events for the window and all non-native descendants.
4019 * Also processes any outstanding moves on the window before doing
4020 * any drawing. Note that its possible to have outstanding moves without
4021 * any invalid area as we use the update idle mechanism to coalesce
4022 * multiple moves as well as multiple invalidations.
4025 gdk_window_process_updates_internal (GdkWindow *window)
4027 GdkWindowImplClass *impl_class;
4028 gboolean save_region = FALSE;
4029 GdkRectangle clip_box;
4031 /* Ensure the window lives while updating it */
4032 g_object_ref (window);
4034 /* If an update got queued during update processing, we can get a
4035 * window in the update queue that has an empty update_area.
4038 if (window->update_area)
4040 cairo_region_t *update_area = window->update_area;
4041 window->update_area = NULL;
4043 if (gdk_window_is_viewable (window))
4045 cairo_region_t *expose_region;
4046 gboolean end_implicit;
4048 /* Clip to part visible in toplevel */
4049 cairo_region_intersect (update_area, window->clip_region);
4053 /* Make sure we see the red invalid area before redrawing. */
4054 gdk_display_sync (gdk_window_get_display (window));
4058 /* At this point we will be completely redrawing all of update_area.
4059 * If we have any outstanding moves that end up moving stuff inside
4060 * this area we don't actually need to move that as that part would
4061 * be overdrawn by the expose anyway. So, in order to copy less data
4062 * we remove these areas from the outstanding moves.
4064 if (window->outstanding_moves)
4066 GdkWindowRegionMove *move;
4067 cairo_region_t *remove;
4070 remove = cairo_region_copy (update_area);
4071 /* We iterate backwards, starting from the state that would be
4072 if we had applied all the moves. */
4073 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
4078 /* Don't need this area */
4079 cairo_region_subtract (move->dest_region, remove);
4081 /* However if any of the destination we do need has a source
4082 in the updated region we do need that as a destination for
4083 the earlier moves */
4084 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4085 cairo_region_subtract (remove, move->dest_region);
4087 if (cairo_region_is_empty (move->dest_region))
4089 gdk_window_region_move_free (move);
4090 window->outstanding_moves =
4091 g_list_delete_link (window->outstanding_moves, l);
4093 else /* move back */
4094 cairo_region_translate (move->dest_region, move->dx, move->dy);
4096 cairo_region_destroy (remove);
4099 /* By now we a set of window moves that should be applied, and then
4100 * an update region that should be repainted. A trivial implementation
4101 * would just do that in order, however in order to get nicer drawing
4102 * we do some tricks:
4104 * First of all, each subwindow expose may be double buffered by
4105 * itself (depending on widget setting) via
4106 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4107 * creating a single surface the size of the invalid area on the
4108 * native window which all the individual normal paints will draw
4109 * into. This way in the normal case there will be only one surface
4110 * allocated and only once surface draw done for all the windows
4111 * in this native window.
4112 * There are a couple of reasons this may fail, for instance, some
4113 * backends (like quartz) do its own double buffering, so we disable
4114 * gdk double buffering there. Secondly, some subwindow could be
4115 * non-double buffered and draw directly to the window outside a
4116 * begin/end_paint pair. That will be lead to a gdk_window_flush
4117 * which immediately executes all outstanding moves and paints+removes
4118 * the implicit paint (further paints will allocate their own surfaces).
4120 * Secondly, in the case of implicit double buffering we expose all
4121 * the child windows into the implicit surface before we execute
4122 * the outstanding moves. This way we minimize the time between
4123 * doing the moves and rendering the new update area, thus minimizing
4124 * flashing. Of course, if any subwindow is non-double buffered we
4125 * well flush earlier than that.
4127 * Thirdly, after having done the outstanding moves we queue an
4128 * "antiexpose" on the area that will be drawn by the expose, which
4129 * means that any invalid region on the native window side before
4130 * the first expose drawing operation will be discarded, as it
4131 * has by then been overdrawn with valid data. This means we can
4132 * avoid doing the unnecessary repaint any outstanding expose events.
4135 cairo_region_get_extents (update_area, &clip_box);
4136 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box, FALSE, 255);
4137 expose_region = cairo_region_copy (update_area);
4138 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4141 /* Rendering is not double buffered by gdk, do outstanding
4142 * moves and queue antiexposure immediately. No need to do
4144 gdk_window_flush_outstanding_moves (window);
4145 save_region = impl_class->queue_antiexpose (window, update_area);
4147 /* Render the invalid areas to the implicit paint, by sending exposes.
4148 * May flush if non-double buffered widget draw. */
4149 impl_class->process_updates_recurse (window, expose_region);
4153 /* Do moves right before exposes are rendered to the window */
4154 gdk_window_flush_outstanding_moves (window);
4156 /* By this time we know that any outstanding expose for this
4157 * area is invalid and we can avoid it, so queue an antiexpose.
4158 * we have already started drawing to the window, so it would
4159 * be to late to anti-expose now. Since this is merely an
4160 * optimization we just avoid doing it at all in that case.
4162 if (window->implicit_paint != NULL && !((GdkWindowPaint *)window->implicit_paint->data)->flushed)
4163 save_region = impl_class->queue_antiexpose (window, update_area);
4165 gdk_window_end_implicit_paint (window);
4167 cairo_region_destroy (expose_region);
4170 cairo_region_destroy (update_area);
4173 if (window->outstanding_moves)
4175 /* Flush any outstanding moves, may happen if we moved a window but got
4176 no actual invalid area */
4177 gdk_window_flush_outstanding_moves (window);
4180 g_object_unref (window);
4184 flush_all_displays (void)
4186 GSList *displays, *l;
4188 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4189 for (l = displays; l; l = l->next)
4190 gdk_display_flush (l->data);
4192 g_slist_free (displays);
4196 before_process_all_updates (void)
4198 GSList *displays, *l;
4199 GdkDisplayClass *display_class;
4201 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4202 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4203 for (l = displays; l; l = l->next)
4204 display_class->before_process_all_updates (l->data);
4206 g_slist_free (displays);
4210 after_process_all_updates (void)
4212 GSList *displays, *l;
4213 GdkDisplayClass *display_class;
4215 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4216 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4217 for (l = displays; l; l = l->next)
4218 display_class->after_process_all_updates (l->data);
4220 g_slist_free (displays);
4223 /* Currently it is not possible to override
4224 * gdk_window_process_all_updates in the same manner as
4225 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4226 * by implementing the GdkPaintable interface. If in the future a
4227 * backend would need this, the right solution would be to add a
4228 * method to GdkDisplay that can be optionally
4229 * NULL. gdk_window_process_all_updates can then walk the list of open
4230 * displays and call the mehod.
4234 * gdk_window_process_all_updates:
4236 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4237 * in the application.
4241 gdk_window_process_all_updates (void)
4243 GSList *old_update_windows = update_windows;
4244 GSList *tmp_list = update_windows;
4245 static gboolean in_process_all_updates = FALSE;
4246 static gboolean got_recursive_update = FALSE;
4248 if (in_process_all_updates)
4250 /* We can't do this now since that would recurse, so
4251 delay it until after the recursion is done. */
4252 got_recursive_update = TRUE;
4257 in_process_all_updates = TRUE;
4258 got_recursive_update = FALSE;
4261 g_source_remove (update_idle);
4263 update_windows = NULL;
4266 before_process_all_updates ();
4268 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4272 GdkWindow *window = tmp_list->data;
4274 if (!GDK_WINDOW_DESTROYED (window))
4276 if (window->update_freeze_count ||
4277 gdk_window_is_toplevel_frozen (window))
4278 gdk_window_add_update_window (window);
4280 gdk_window_process_updates_internal (window);
4283 g_object_unref (window);
4284 tmp_list = tmp_list->next;
4287 g_slist_free (old_update_windows);
4289 flush_all_displays ();
4291 after_process_all_updates ();
4293 in_process_all_updates = FALSE;
4295 /* If we ignored a recursive call, schedule a
4296 redraw now so that it eventually happens,
4297 otherwise we could miss an update if nothing
4298 else schedules an update. */
4299 if (got_recursive_update && !update_idle)
4301 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4302 gdk_window_update_idle,
4307 * gdk_window_process_updates:
4308 * @window: a #GdkWindow
4309 * @update_children: whether to also process updates for child windows
4311 * Sends one or more expose events to @window. The areas in each
4312 * expose event will cover the entire update area for the window (see
4313 * gdk_window_invalidate_region() for details). Normally GDK calls
4314 * gdk_window_process_all_updates() on your behalf, so there's no
4315 * need to call this function unless you want to force expose events
4316 * to be delivered immediately and synchronously (vs. the usual
4317 * case, where GDK delivers them in an idle handler). Occasionally
4318 * this is useful to produce nicer scrolling behavior, for example.
4322 gdk_window_process_updates (GdkWindow *window,
4323 gboolean update_children)
4325 GdkWindow *impl_window;
4327 g_return_if_fail (GDK_IS_WINDOW (window));
4329 if (GDK_WINDOW_DESTROYED (window))
4332 /* Make sure the window lives during the expose callouts */
4333 g_object_ref (window);
4335 impl_window = gdk_window_get_impl_window (window);
4336 if ((impl_window->update_area ||
4337 impl_window->outstanding_moves) &&
4338 !impl_window->update_freeze_count &&
4339 !gdk_window_is_toplevel_frozen (window) &&
4341 /* Don't recurse into process_updates_internal, we'll
4342 * do the update later when idle instead. */
4343 impl_window->implicit_paint == NULL)
4345 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4346 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4349 if (update_children)
4351 /* process updates in reverse stacking order so composition or
4352 * painting over achieves the desired effect for offscreen windows
4354 GList *node, *children;
4356 children = g_list_copy (window->children);
4357 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4359 for (node = g_list_last (children); node; node = node->prev)
4361 gdk_window_process_updates (node->data, TRUE);
4362 g_object_unref (node->data);
4365 g_list_free (children);
4368 g_object_unref (window);
4372 gdk_window_invalidate_rect_full (GdkWindow *window,
4373 const GdkRectangle *rect,
4374 gboolean invalidate_children,
4377 GdkRectangle window_rect;
4378 cairo_region_t *region;
4380 g_return_if_fail (GDK_IS_WINDOW (window));
4382 if (GDK_WINDOW_DESTROYED (window))
4385 if (window->input_only || !window->viewable)
4392 window_rect.width = window->width;
4393 window_rect.height = window->height;
4394 rect = &window_rect;
4397 region = cairo_region_create_rectangle (rect);
4398 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4399 cairo_region_destroy (region);
4403 * gdk_window_invalidate_rect:
4404 * @window: a #GdkWindow
4405 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4407 * @invalidate_children: whether to also invalidate child windows
4409 * A convenience wrapper around gdk_window_invalidate_region() which
4410 * invalidates a rectangular region. See
4411 * gdk_window_invalidate_region() for details.
4414 gdk_window_invalidate_rect (GdkWindow *window,
4415 const GdkRectangle *rect,
4416 gboolean invalidate_children)
4418 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4422 draw_ugly_color (GdkWindow *window,
4423 const cairo_region_t *region)
4427 cr = gdk_cairo_create (window);
4428 /* Draw ugly color all over the newly-invalid region */
4429 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4430 gdk_cairo_region (cr, region);
4437 impl_window_add_update_area (GdkWindow *impl_window,
4438 cairo_region_t *region)
4440 if (impl_window->update_area)
4441 cairo_region_union (impl_window->update_area, region);
4444 gdk_window_add_update_window (impl_window);
4445 impl_window->update_area = cairo_region_copy (region);
4446 gdk_window_schedule_update (impl_window);
4450 /* clear_bg controls if the region will be cleared to
4451 * the background pattern if the exposure mask is not
4452 * set for the window, whereas this might not otherwise be
4453 * done (unless necessary to emulate background settings).
4454 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4455 * need to clear the background, such as when exposing the area beneath a
4456 * hidden or moved window, but not when an app requests repaint or when the
4457 * windowing system exposes a newly visible area (because then the windowing
4458 * system has already cleared the area).
4461 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4462 const cairo_region_t *region,
4464 GdkWindowChildFunc child_func,
4467 GdkWindow *impl_window;
4468 cairo_region_t *visible_region;
4471 g_return_if_fail (GDK_IS_WINDOW (window));
4473 if (GDK_WINDOW_DESTROYED (window))
4476 if (window->input_only ||
4477 !window->viewable ||
4478 cairo_region_is_empty (region) ||
4479 window->window_type == GDK_WINDOW_ROOT)
4482 visible_region = gdk_window_get_visible_region (window);
4483 cairo_region_intersect (visible_region, region);
4485 tmp_list = window->children;
4488 GdkWindow *child = tmp_list->data;
4490 if (!child->input_only)
4492 cairo_region_t *child_region;
4493 GdkRectangle child_rect;
4495 child_rect.x = child->x;
4496 child_rect.y = child->y;
4497 child_rect.width = child->width;
4498 child_rect.height = child->height;
4499 child_region = cairo_region_create_rectangle (&child_rect);
4501 /* remove child area from the invalid area of the parent */
4502 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4503 !child->composited &&
4504 !gdk_window_is_offscreen (child))
4505 cairo_region_subtract (visible_region, child_region);
4507 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4509 cairo_region_t *tmp = cairo_region_copy (region);
4511 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4512 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4513 cairo_region_intersect (child_region, tmp);
4515 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4516 child_region, clear_bg, child_func, user_data);
4518 cairo_region_destroy (tmp);
4521 cairo_region_destroy (child_region);
4524 tmp_list = tmp_list->next;
4527 impl_window = gdk_window_get_impl_window (window);
4529 if (!cairo_region_is_empty (visible_region) ||
4530 /* Even if we're not exposing anything, make sure we process
4531 idles for windows with outstanding moves */
4532 (impl_window->outstanding_moves != NULL &&
4533 impl_window->update_area == NULL))
4536 draw_ugly_color (window, region);
4538 /* Convert to impl coords */
4539 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4541 /* Only invalidate area if app requested expose events or if
4542 we need to clear the area (by request or to emulate background
4543 clearing for non-native windows or native windows with no support
4544 for window backgrounds */
4545 if (window->event_mask & GDK_EXPOSURE_MASK ||
4546 clear_bg == CLEAR_BG_ALL ||
4547 clear_bg == CLEAR_BG_WINCLEARED)
4548 impl_window_add_update_area (impl_window, visible_region);
4551 cairo_region_destroy (visible_region);
4555 * gdk_window_invalidate_maybe_recurse:
4556 * @window: a #GdkWindow
4557 * @region: a #cairo_region_t
4558 * @child_func: (scope call) (allow-none): function to use to decide if to
4559 * recurse to a child, %NULL means never recurse.
4560 * @user_data: data passed to @child_func
4562 * Adds @region to the update area for @window. The update area is the
4563 * region that needs to be redrawn, or "dirty region." The call
4564 * gdk_window_process_updates() sends one or more expose events to the
4565 * window, which together cover the entire update area. An
4566 * application would normally redraw the contents of @window in
4567 * response to those expose events.
4569 * GDK will call gdk_window_process_all_updates() on your behalf
4570 * whenever your program returns to the main loop and becomes idle, so
4571 * normally there's no need to do that manually, you just need to
4572 * invalidate regions that you know should be redrawn.
4574 * The @child_func parameter controls whether the region of
4575 * each child window that intersects @region will also be invalidated.
4576 * Only children for which @child_func returns TRUE will have the area
4580 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4581 const cairo_region_t *region,
4582 GdkWindowChildFunc child_func,
4585 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4586 child_func, user_data);
4590 true_predicate (GdkWindow *window,
4597 gdk_window_invalidate_region_full (GdkWindow *window,
4598 const cairo_region_t *region,
4599 gboolean invalidate_children,
4602 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4603 invalidate_children ?
4604 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4609 * gdk_window_invalidate_region:
4610 * @window: a #GdkWindow
4611 * @region: a #cairo_region_t
4612 * @invalidate_children: %TRUE to also invalidate child windows
4614 * Adds @region to the update area for @window. The update area is the
4615 * region that needs to be redrawn, or "dirty region." The call
4616 * gdk_window_process_updates() sends one or more expose events to the
4617 * window, which together cover the entire update area. An
4618 * application would normally redraw the contents of @window in
4619 * response to those expose events.
4621 * GDK will call gdk_window_process_all_updates() on your behalf
4622 * whenever your program returns to the main loop and becomes idle, so
4623 * normally there's no need to do that manually, you just need to
4624 * invalidate regions that you know should be redrawn.
4626 * The @invalidate_children parameter controls whether the region of
4627 * each child window that intersects @region will also be invalidated.
4628 * If %FALSE, then the update area for child windows will remain
4629 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4630 * fine grained control over which children are invalidated.
4633 gdk_window_invalidate_region (GdkWindow *window,
4634 const cairo_region_t *region,
4635 gboolean invalidate_children)
4637 gdk_window_invalidate_maybe_recurse (window, region,
4638 invalidate_children ?
4639 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4644 * _gdk_window_invalidate_for_expose:
4645 * @window: a #GdkWindow
4646 * @region: a #cairo_region_t
4648 * Adds @region to the update area for @window. The update area is the
4649 * region that needs to be redrawn, or "dirty region." The call
4650 * gdk_window_process_updates() sends one or more expose events to the
4651 * window, which together cover the entire update area. An
4652 * application would normally redraw the contents of @window in
4653 * response to those expose events.
4655 * GDK will call gdk_window_process_all_updates() on your behalf
4656 * whenever your program returns to the main loop and becomes idle, so
4657 * normally there's no need to do that manually, you just need to
4658 * invalidate regions that you know should be redrawn.
4660 * This version of invalidation is used when you recieve expose events
4661 * from the native window system. It exposes the native window, plus
4662 * any non-native child windows (but not native child windows, as those would
4663 * have gotten their own expose events).
4666 _gdk_window_invalidate_for_expose (GdkWindow *window,
4667 cairo_region_t *region)
4669 GdkWindowRegionMove *move;
4670 cairo_region_t *move_region;
4673 /* Any invalidations comming from the windowing system will
4674 be in areas that may be moved by outstanding moves,
4675 so we need to modify the expose region correspondingly,
4676 otherwise we would expose in the wrong place, as the
4677 outstanding moves will be copied before we draw the
4679 for (l = window->outstanding_moves; l != NULL; l = l->next)
4683 /* covert to move source region */
4684 move_region = cairo_region_copy (move->dest_region);
4685 cairo_region_translate (move_region, -move->dx, -move->dy);
4687 /* Move area of region that intersects with move source
4688 by dx, dy of the move*/
4689 cairo_region_intersect (move_region, region);
4690 cairo_region_subtract (region, move_region);
4691 cairo_region_translate (move_region, move->dx, move->dy);
4692 cairo_region_union (region, move_region);
4694 cairo_region_destroy (move_region);
4697 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4698 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4704 * gdk_window_get_update_area:
4705 * @window: a #GdkWindow
4707 * Transfers ownership of the update area from @window to the caller
4708 * of the function. That is, after calling this function, @window will
4709 * no longer have an invalid/dirty region; the update area is removed
4710 * from @window and handed to you. If a window has no update area,
4711 * gdk_window_get_update_area() returns %NULL. You are responsible for
4712 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4714 * Return value: the update area for @window
4717 gdk_window_get_update_area (GdkWindow *window)
4719 GdkWindow *impl_window;
4720 cairo_region_t *tmp_region, *to_remove;
4722 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4724 impl_window = gdk_window_get_impl_window (window);
4726 if (impl_window->update_area)
4728 tmp_region = cairo_region_copy (window->clip_region_with_children);
4729 /* Convert to impl coords */
4730 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4731 cairo_region_intersect (tmp_region, impl_window->update_area);
4733 if (cairo_region_is_empty (tmp_region))
4735 cairo_region_destroy (tmp_region);
4740 /* Convert from impl coords */
4741 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4743 /* Don't remove any update area that is overlapped by non-opaque windows
4744 (children or siblings) with alpha, as these really need to be repainted
4745 independently of this window. */
4746 to_remove = cairo_region_copy (tmp_region);
4747 cairo_region_subtract (to_remove, window->parent->layered_region);
4748 remove_layered_child_area (window, to_remove);
4750 /* Remove from update_area */
4751 cairo_region_translate (to_remove, window->abs_x, window->abs_y);
4752 cairo_region_subtract (impl_window->update_area, to_remove);
4754 cairo_region_destroy (to_remove);
4756 if (cairo_region_is_empty (impl_window->update_area) &&
4757 impl_window->outstanding_moves == NULL)
4759 cairo_region_destroy (impl_window->update_area);
4760 impl_window->update_area = NULL;
4762 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4773 * _gdk_window_clear_update_area:
4774 * @window: a #GdkWindow.
4776 * Internal function to clear the update area for a window. This
4777 * is called when the window is hidden or destroyed.
4780 _gdk_window_clear_update_area (GdkWindow *window)
4782 g_return_if_fail (GDK_IS_WINDOW (window));
4784 if (window->update_area)
4786 gdk_window_remove_update_window (window);
4788 cairo_region_destroy (window->update_area);
4789 window->update_area = NULL;
4794 * gdk_window_freeze_updates:
4795 * @window: a #GdkWindow
4797 * Temporarily freezes a window such that it won't receive expose
4798 * events. The window will begin receiving expose events again when
4799 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4800 * has been called more than once, gdk_window_thaw_updates() must be called
4801 * an equal number of times to begin processing exposes.
4804 gdk_window_freeze_updates (GdkWindow *window)
4806 GdkWindow *impl_window;
4808 g_return_if_fail (GDK_IS_WINDOW (window));
4810 impl_window = gdk_window_get_impl_window (window);
4811 impl_window->update_freeze_count++;
4815 * gdk_window_thaw_updates:
4816 * @window: a #GdkWindow
4818 * Thaws a window frozen with gdk_window_freeze_updates().
4821 gdk_window_thaw_updates (GdkWindow *window)
4823 GdkWindow *impl_window;
4825 g_return_if_fail (GDK_IS_WINDOW (window));
4827 impl_window = gdk_window_get_impl_window (window);
4829 g_return_if_fail (impl_window->update_freeze_count > 0);
4831 if (--impl_window->update_freeze_count == 0)
4832 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4836 * gdk_window_freeze_toplevel_updates_libgtk_only:
4837 * @window: a #GdkWindow
4839 * Temporarily freezes a window and all its descendants such that it won't
4840 * receive expose events. The window will begin receiving expose events
4841 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4842 * gdk_window_freeze_toplevel_updates_libgtk_only()
4843 * has been called more than once,
4844 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4845 * an equal number of times to begin processing exposes.
4847 * This function is not part of the GDK public API and is only
4851 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4853 g_return_if_fail (GDK_IS_WINDOW (window));
4854 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4856 window->update_and_descendants_freeze_count++;
4860 * gdk_window_thaw_toplevel_updates_libgtk_only:
4861 * @window: a #GdkWindow
4863 * Thaws a window frozen with
4864 * gdk_window_freeze_toplevel_updates_libgtk_only().
4866 * This function is not part of the GDK public API and is only
4870 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4872 g_return_if_fail (GDK_IS_WINDOW (window));
4873 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4874 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4876 window->update_and_descendants_freeze_count--;
4878 gdk_window_schedule_update (window);
4882 * gdk_window_set_debug_updates:
4883 * @setting: %TRUE to turn on update debugging
4885 * With update debugging enabled, calls to
4886 * gdk_window_invalidate_region() clear the invalidated region of the
4887 * screen to a noticeable color, and GDK pauses for a short time
4888 * before sending exposes to windows during
4889 * gdk_window_process_updates(). The net effect is that you can see
4890 * the invalid region for each window and watch redraws as they
4891 * occur. This allows you to diagnose inefficiencies in your application.
4893 * In essence, because the GDK rendering model prevents all flicker,
4894 * if you are redrawing the same region 400 times you may never
4895 * notice, aside from noticing a speed problem. Enabling update
4896 * debugging causes GTK to flicker slowly and noticeably, so you can
4897 * see exactly what's being redrawn when, in what order.
4899 * The --gtk-debug=updates command line option passed to GTK+ programs
4900 * enables this debug option at application startup time. That's
4901 * usually more useful than calling gdk_window_set_debug_updates()
4902 * yourself, though you might want to use this function to enable
4903 * updates sometime after application startup time.
4907 gdk_window_set_debug_updates (gboolean setting)
4909 debug_updates = setting;
4913 * gdk_window_constrain_size:
4914 * @geometry: a #GdkGeometry structure
4915 * @flags: a mask indicating what portions of @geometry are set
4916 * @width: desired width of window
4917 * @height: desired height of the window
4918 * @new_width: (out): location to store resulting width
4919 * @new_height: (out): location to store resulting height
4921 * Constrains a desired width and height according to a
4922 * set of geometry hints (such as minimum and maximum size).
4925 gdk_window_constrain_size (GdkGeometry *geometry,
4932 /* This routine is partially borrowed from fvwm.
4934 * Copyright 1993, Robert Nation
4935 * You may use this code for any purpose, as long as the original
4936 * copyright remains in the source code and all documentation
4938 * which in turn borrows parts of the algorithm from uwm
4941 gint min_height = 0;
4942 gint base_width = 0;
4943 gint base_height = 0;
4946 gint max_width = G_MAXINT;
4947 gint max_height = G_MAXINT;
4949 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4951 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4953 base_width = geometry->base_width;
4954 base_height = geometry->base_height;
4955 min_width = geometry->min_width;
4956 min_height = geometry->min_height;
4958 else if (flags & GDK_HINT_BASE_SIZE)
4960 base_width = geometry->base_width;
4961 base_height = geometry->base_height;
4962 min_width = geometry->base_width;
4963 min_height = geometry->base_height;
4965 else if (flags & GDK_HINT_MIN_SIZE)
4967 base_width = geometry->min_width;
4968 base_height = geometry->min_height;
4969 min_width = geometry->min_width;
4970 min_height = geometry->min_height;
4973 if (flags & GDK_HINT_MAX_SIZE)
4975 max_width = geometry->max_width ;
4976 max_height = geometry->max_height;
4979 if (flags & GDK_HINT_RESIZE_INC)
4981 xinc = MAX (xinc, geometry->width_inc);
4982 yinc = MAX (yinc, geometry->height_inc);
4985 /* clamp width and height to min and max values
4987 width = CLAMP (width, min_width, max_width);
4988 height = CLAMP (height, min_height, max_height);
4990 /* shrink to base + N * inc
4992 width = base_width + FLOOR (width - base_width, xinc);
4993 height = base_height + FLOOR (height - base_height, yinc);
4995 /* constrain aspect ratio, according to:
4998 * min_aspect <= -------- <= max_aspect
5002 if (flags & GDK_HINT_ASPECT &&
5003 geometry->min_aspect > 0 &&
5004 geometry->max_aspect > 0)
5008 if (geometry->min_aspect * height > width)
5010 delta = FLOOR (height - width / geometry->min_aspect, yinc);
5011 if (height - delta >= min_height)
5015 delta = FLOOR (height * geometry->min_aspect - width, xinc);
5016 if (width + delta <= max_width)
5021 if (geometry->max_aspect * height < width)
5023 delta = FLOOR (width - height * geometry->max_aspect, xinc);
5024 if (width - delta >= min_width)
5028 delta = FLOOR (width / geometry->max_aspect - height, yinc);
5029 if (height + delta <= max_height)
5038 *new_height = height;
5042 * gdk_window_get_pointer:
5043 * @window: a #GdkWindow
5044 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
5045 * return the X coordinate
5046 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
5047 * return the Y coordinate
5048 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
5051 * Obtains the current pointer position and modifier state.
5052 * The position is given in coordinates relative to the upper left
5053 * corner of @window.
5055 * Return value: (transfer none): the window containing the pointer (as with
5056 * gdk_window_at_pointer()), or %NULL if the window containing the
5057 * pointer isn't known to GDK
5059 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
5062 gdk_window_get_pointer (GdkWindow *window,
5065 GdkModifierType *mask)
5067 GdkDisplay *display;
5069 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5071 display = gdk_window_get_display (window);
5073 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
5077 * gdk_window_get_device_position:
5078 * @window: a #GdkWindow.
5079 * @device: pointer #GdkDevice to query to.
5080 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5081 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5082 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5084 * Obtains the current device position and modifier state.
5085 * The position is given in coordinates relative to the upper left
5086 * corner of @window.
5088 * Return value: (transfer none): The window underneath @device (as with
5089 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
5094 gdk_window_get_device_position (GdkWindow *window,
5098 GdkModifierType *mask)
5101 GdkModifierType tmp_mask;
5102 gboolean normal_child;
5104 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5105 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5106 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
5108 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
5112 /* We got the coords on the impl, convert to the window */
5113 tmp_x -= window->abs_x;
5114 tmp_y -= window->abs_y;
5123 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
5126 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5131 * gdk_get_default_root_window:
5133 * Obtains the root window (parent all other windows are inside)
5134 * for the default display and screen.
5136 * Return value: (transfer none): the default root window
5139 gdk_get_default_root_window (void)
5141 return gdk_screen_get_root_window (gdk_screen_get_default ());
5145 get_all_native_children (GdkWindow *window,
5151 for (l = window->children; l != NULL; l = l->next)
5155 if (gdk_window_has_impl (child))
5156 *native = g_list_prepend (*native, child);
5158 get_all_native_children (child, native);
5164 gdk_window_raise_internal (GdkWindow *window)
5166 GdkWindow *parent = window->parent;
5168 GList *native_children;
5170 GdkWindowImplClass *impl_class;
5174 parent->children = g_list_remove (parent->children, window);
5175 parent->children = g_list_prepend (parent->children, window);
5178 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5179 /* Just do native raise for toplevels */
5180 if (gdk_window_is_toplevel (window) ||
5181 /* The restack_under codepath should work correctly even if the parent
5182 is native, but it relies on the order of ->children to be correct,
5183 and some apps like SWT reorder the x windows without gdks knowledge,
5184 so we use raise directly in order to make these behave as before
5185 when using native windows */
5186 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5188 impl_class->raise (window);
5190 else if (gdk_window_has_impl (window))
5192 above = find_native_sibling_above (parent, window);
5195 listhead.data = window;
5196 listhead.next = NULL;
5197 listhead.prev = NULL;
5198 impl_class->restack_under ((GdkWindow *)above,
5202 impl_class->raise (window);
5206 native_children = NULL;
5207 get_all_native_children (window, &native_children);
5208 if (native_children != NULL)
5210 above = find_native_sibling_above (parent, window);
5213 impl_class->restack_under (above, native_children);
5216 /* Right order, since native_children is bottom-topmost first */
5217 for (l = native_children; l != NULL; l = l->next)
5218 impl_class->raise (l->data);
5221 g_list_free (native_children);
5227 /* Returns TRUE If the native window was mapped or unmapped */
5229 set_viewable (GdkWindow *w,
5233 GdkWindowImplClass *impl_class;
5236 if (w->viewable == val)
5242 recompute_visible_regions (w, FALSE, FALSE);
5244 for (l = w->children; l != NULL; l = l->next)
5248 if (GDK_WINDOW_IS_MAPPED (child) &&
5249 child->window_type != GDK_WINDOW_FOREIGN)
5250 set_viewable (child, val);
5253 if (gdk_window_has_impl (w) &&
5254 w->window_type != GDK_WINDOW_FOREIGN &&
5255 !gdk_window_is_toplevel (w))
5257 /* For most native windows we show/hide them not when they are
5258 * mapped/unmapped, because that may not produce the correct results.
5259 * For instance, if a native window have a non-native parent which is
5260 * hidden, but its native parent is viewable then showing the window
5261 * would make it viewable to X but its not viewable wrt the non-native
5262 * hierarchy. In order to handle this we track the gdk side viewability
5263 * and only map really viewable windows.
5265 * There are two exceptions though:
5267 * For foreign windows we don't want ever change the mapped state
5268 * except when explicitly done via gdk_window_show/hide, as this may
5269 * cause problems for client owning the foreign window when its window
5270 * is suddenly mapped or unmapped.
5272 * For toplevel windows embedded in a foreign window (e.g. a plug)
5273 * we sometimes synthesize a map of a window, but the native
5274 * window is really shown by the embedder, so we don't want to
5275 * do the show ourselves. We can't really tell this case from the normal
5276 * toplevel show as such toplevels are seen by gdk as parents of the
5277 * root window, so we make an exception for all toplevels.
5280 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5282 impl_class->show ((GdkWindow *)w, FALSE);
5284 impl_class->hide ((GdkWindow *)w);
5292 /* Returns TRUE If the native window was mapped or unmapped */
5294 _gdk_window_update_viewable (GdkWindow *window)
5298 if (window->window_type == GDK_WINDOW_FOREIGN ||
5299 window->window_type == GDK_WINDOW_ROOT)
5301 else if (gdk_window_is_toplevel (window) ||
5302 window->parent->viewable)
5303 viewable = GDK_WINDOW_IS_MAPPED (window);
5307 return set_viewable (window, viewable);
5311 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5313 GdkWindowImplClass *impl_class;
5314 gboolean was_mapped, was_viewable;
5317 g_return_if_fail (GDK_IS_WINDOW (window));
5319 if (window->destroyed)
5322 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5323 was_viewable = window->viewable;
5326 /* Keep children in (reverse) stacking order */
5327 gdk_window_raise_internal (window);
5329 if (gdk_window_has_impl (window))
5332 gdk_synthesize_window_state (window,
5333 GDK_WINDOW_STATE_WITHDRAWN,
5334 GDK_WINDOW_STATE_FOCUSED);
5341 did_show = _gdk_window_update_viewable (window);
5343 /* If it was already viewable the backend show op won't be called, call it
5344 again to ensure things happen right if the mapped tracking was not right
5345 for e.g. a foreign window.
5346 Dunno if this is strictly needed but its what happened pre-csw.
5347 Also show if not done by gdk_window_update_viewable. */
5348 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5350 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5351 impl_class->show (window, !did_show ? was_mapped : TRUE);
5354 if (!was_mapped && !gdk_window_has_impl (window))
5356 if (window->event_mask & GDK_STRUCTURE_MASK)
5357 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5359 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5360 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5363 if (!was_mapped || raise)
5365 recompute_visible_regions (window, TRUE, FALSE);
5367 /* If any decendants became visible we need to send visibility notify */
5368 gdk_window_update_visibility_recursively (window, NULL);
5370 if (gdk_window_is_viewable (window))
5372 _gdk_synthesize_crossing_events_for_geometry_change (window);
5373 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5379 * gdk_window_show_unraised:
5380 * @window: a #GdkWindow
5382 * Shows a #GdkWindow onscreen, but does not modify its stacking
5383 * order. In contrast, gdk_window_show() will raise the window
5384 * to the top of the window stack.
5386 * On the X11 platform, in Xlib terms, this function calls
5387 * XMapWindow() (it also updates some internal GDK state, which means
5388 * that you can't really use XMapWindow() directly on a GDK window).
5391 gdk_window_show_unraised (GdkWindow *window)
5393 gdk_window_show_internal (window, FALSE);
5398 * @window: a #GdkWindow
5400 * Raises @window to the top of the Z-order (stacking order), so that
5401 * other windows with the same parent window appear below @window.
5402 * This is true whether or not the windows are visible.
5404 * If @window is a toplevel, the window manager may choose to deny the
5405 * request to move the window in the Z-order, gdk_window_raise() only
5406 * requests the restack, does not guarantee it.
5409 gdk_window_raise (GdkWindow *window)
5411 g_return_if_fail (GDK_IS_WINDOW (window));
5413 if (window->destroyed)
5416 /* Keep children in (reverse) stacking order */
5417 gdk_window_raise_internal (window);
5419 recompute_visible_regions (window, TRUE, FALSE);
5421 if (gdk_window_is_viewable (window) &&
5422 !window->input_only)
5423 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5427 gdk_window_lower_internal (GdkWindow *window)
5429 GdkWindow *parent = window->parent;
5430 GdkWindowImplClass *impl_class;
5432 GList *native_children;
5437 parent->children = g_list_remove (parent->children, window);
5438 parent->children = g_list_append (parent->children, window);
5441 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5442 /* Just do native lower for toplevels */
5443 if (gdk_window_is_toplevel (window) ||
5444 /* The restack_under codepath should work correctly even if the parent
5445 is native, but it relies on the order of ->children to be correct,
5446 and some apps like SWT reorder the x windows without gdks knowledge,
5447 so we use lower directly in order to make these behave as before
5448 when using native windows */
5449 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5451 impl_class->lower (window);
5453 else if (gdk_window_has_impl (window))
5455 above = find_native_sibling_above (parent, window);
5458 listhead.data = window;
5459 listhead.next = NULL;
5460 listhead.prev = NULL;
5461 impl_class->restack_under ((GdkWindow *)above, &listhead);
5464 impl_class->raise (window);
5468 native_children = NULL;
5469 get_all_native_children (window, &native_children);
5470 if (native_children != NULL)
5472 above = find_native_sibling_above (parent, window);
5475 impl_class->restack_under ((GdkWindow *)above,
5479 /* Right order, since native_children is bottom-topmost first */
5480 for (l = native_children; l != NULL; l = l->next)
5481 impl_class->raise (l->data);
5484 g_list_free (native_children);
5491 gdk_window_invalidate_in_parent (GdkWindow *private)
5493 GdkRectangle r, child;
5495 if (gdk_window_is_toplevel (private))
5498 /* get the visible rectangle of the parent */
5500 r.width = private->parent->width;
5501 r.height = private->parent->height;
5503 child.x = private->x;
5504 child.y = private->y;
5505 child.width = private->width;
5506 child.height = private->height;
5507 gdk_rectangle_intersect (&r, &child, &r);
5509 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5515 * @window: a #GdkWindow
5517 * Lowers @window to the bottom of the Z-order (stacking order), so that
5518 * other windows with the same parent window appear above @window.
5519 * This is true whether or not the other windows are visible.
5521 * If @window is a toplevel, the window manager may choose to deny the
5522 * request to move the window in the Z-order, gdk_window_lower() only
5523 * requests the restack, does not guarantee it.
5525 * Note that gdk_window_show() raises the window again, so don't call this
5526 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5529 gdk_window_lower (GdkWindow *window)
5531 g_return_if_fail (GDK_IS_WINDOW (window));
5533 if (window->destroyed)
5536 /* Keep children in (reverse) stacking order */
5537 gdk_window_lower_internal (window);
5539 recompute_visible_regions (window, TRUE, FALSE);
5541 _gdk_synthesize_crossing_events_for_geometry_change (window);
5542 gdk_window_invalidate_in_parent (window);
5546 * gdk_window_restack:
5547 * @window: a #GdkWindow
5548 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5551 * Changes the position of @window in the Z-order (stacking order), so that
5552 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5555 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5556 * lowers the window.
5558 * If @window is a toplevel, the window manager may choose to deny the
5559 * request to move the window in the Z-order, gdk_window_restack() only
5560 * requests the restack, does not guarantee it.
5565 gdk_window_restack (GdkWindow *window,
5569 GdkWindowImplClass *impl_class;
5571 GdkWindow *above_native;
5572 GList *sibling_link;
5573 GList *native_children;
5576 g_return_if_fail (GDK_IS_WINDOW (window));
5577 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5579 if (window->destroyed)
5582 if (sibling == NULL)
5585 gdk_window_raise (window);
5587 gdk_window_lower (window);
5591 if (gdk_window_is_toplevel (window))
5593 g_return_if_fail (gdk_window_is_toplevel (sibling));
5594 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5595 impl_class->restack_toplevel (window, sibling, above);
5599 parent = window->parent;
5602 sibling_link = g_list_find (parent->children, sibling);
5603 g_return_if_fail (sibling_link != NULL);
5604 if (sibling_link == NULL)
5607 parent->children = g_list_remove (parent->children, window);
5609 parent->children = g_list_insert_before (parent->children,
5613 parent->children = g_list_insert_before (parent->children,
5617 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5618 if (gdk_window_has_impl (window))
5620 above_native = find_native_sibling_above (parent, window);
5623 listhead.data = window;
5624 listhead.next = NULL;
5625 listhead.prev = NULL;
5626 impl_class->restack_under (above_native, &listhead);
5629 impl_class->raise (window);
5633 native_children = NULL;
5634 get_all_native_children (window, &native_children);
5635 if (native_children != NULL)
5637 above_native = find_native_sibling_above (parent, window);
5639 impl_class->restack_under (above_native,
5643 /* Right order, since native_children is bottom-topmost first */
5644 for (l = native_children; l != NULL; l = l->next)
5645 impl_class->raise (l->data);
5648 g_list_free (native_children);
5653 recompute_visible_regions (window, TRUE, FALSE);
5655 _gdk_synthesize_crossing_events_for_geometry_change (window);
5656 gdk_window_invalidate_in_parent (window);
5662 * @window: a #GdkWindow
5664 * Like gdk_window_show_unraised(), but also raises the window to the
5665 * top of the window stack (moves the window to the front of the
5668 * This function maps a window so it's visible onscreen. Its opposite
5669 * is gdk_window_hide().
5671 * When implementing a #GtkWidget, you should call this function on the widget's
5672 * #GdkWindow as part of the "map" method.
5675 gdk_window_show (GdkWindow *window)
5677 gdk_window_show_internal (window, TRUE);
5682 * @window: a #GdkWindow
5684 * For toplevel windows, withdraws them, so they will no longer be
5685 * known to the window manager; for all windows, unmaps them, so
5686 * they won't be displayed. Normally done automatically as
5687 * part of gtk_widget_hide().
5690 gdk_window_hide (GdkWindow *window)
5692 GdkWindowImplClass *impl_class;
5693 gboolean was_mapped, did_hide;
5695 g_return_if_fail (GDK_IS_WINDOW (window));
5697 if (window->destroyed)
5700 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5702 if (gdk_window_has_impl (window))
5705 if (GDK_WINDOW_IS_MAPPED (window))
5706 gdk_synthesize_window_state (window,
5708 GDK_WINDOW_STATE_WITHDRAWN);
5710 else if (was_mapped)
5712 GdkDisplay *display;
5713 GdkDeviceManager *device_manager;
5716 /* May need to break grabs on children */
5717 display = gdk_window_get_display (window);
5718 device_manager = gdk_display_get_device_manager (display);
5720 /* Get all devices */
5721 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5722 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5723 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5725 for (d = devices; d; d = d->next)
5727 GdkDevice *device = d->data;
5729 if (_gdk_display_end_device_grab (display,
5731 _gdk_display_get_next_serial (display),
5734 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5737 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5738 g_list_free (devices);
5741 did_hide = _gdk_window_update_viewable (window);
5743 /* Hide foreign window as those are not handled by update_viewable. */
5744 if (gdk_window_has_impl (window) && (!did_hide))
5746 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5747 impl_class->hide (window);
5750 recompute_visible_regions (window, TRUE, FALSE);
5752 /* all decendants became non-visible, we need to send visibility notify */
5753 gdk_window_update_visibility_recursively (window, NULL);
5755 if (was_mapped && !gdk_window_has_impl (window))
5757 if (window->event_mask & GDK_STRUCTURE_MASK)
5758 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5760 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5761 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5763 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5766 /* Invalidate the rect */
5768 gdk_window_invalidate_in_parent (window);
5772 * gdk_window_withdraw:
5773 * @window: a toplevel #GdkWindow
5775 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5776 * This function is not really useful as gdk_window_hide() automatically
5777 * withdraws toplevel windows before hiding them.
5780 gdk_window_withdraw (GdkWindow *window)
5782 GdkWindowImplClass *impl_class;
5783 gboolean was_mapped;
5785 g_return_if_fail (GDK_IS_WINDOW (window));
5787 if (window->destroyed)
5790 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5792 if (gdk_window_has_impl (window))
5794 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5795 impl_class->withdraw (window);
5799 if (window->event_mask & GDK_STRUCTURE_MASK)
5800 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5802 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5803 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5805 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5808 recompute_visible_regions (window, TRUE, FALSE);
5813 * gdk_window_set_events:
5814 * @window: a #GdkWindow
5815 * @event_mask: event mask for @window
5817 * The event mask for a window determines which events will be reported
5818 * for that window from all master input devices. For example, an event mask
5819 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5820 * press events. The event mask is the bitwise OR of values from the
5821 * #GdkEventMask enumeration.
5824 gdk_window_set_events (GdkWindow *window,
5825 GdkEventMask event_mask)
5827 GdkWindowImplClass *impl_class;
5828 GdkDisplay *display;
5830 g_return_if_fail (GDK_IS_WINDOW (window));
5832 if (window->destroyed)
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))
5840 GList *devices = window->devices_inside;
5844 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5845 devices = devices->next;
5849 window->event_mask = event_mask;
5851 if (gdk_window_has_impl (window))
5853 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5854 impl_class->set_events (window,
5855 get_native_event_mask (window));
5861 * gdk_window_get_events:
5862 * @window: a #GdkWindow
5864 * Gets the event mask for @window for all master input devices. See
5865 * gdk_window_set_events().
5867 * Return value: event mask for @window
5870 gdk_window_get_events (GdkWindow *window)
5872 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5874 if (window->destroyed)
5877 return window->event_mask;
5881 * gdk_window_set_device_events:
5882 * @window: a #GdkWindow
5883 * @device: #GdkDevice to enable events for.
5884 * @event_mask: event mask for @window
5886 * Sets the event mask for a given device (Normally a floating device, not
5887 * attached to any visible pointer) to @window. For example, an event mask
5888 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5889 * press events. The event mask is the bitwise OR of values from the
5890 * #GdkEventMask enumeration.
5895 gdk_window_set_device_events (GdkWindow *window,
5897 GdkEventMask event_mask)
5899 GdkEventMask device_mask;
5900 GdkDisplay *display;
5903 g_return_if_fail (GDK_IS_WINDOW (window));
5904 g_return_if_fail (GDK_IS_DEVICE (device));
5906 if (GDK_WINDOW_DESTROYED (window))
5909 /* If motion hint is disabled, enable motion events again */
5910 display = gdk_window_get_display (window);
5911 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5912 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5913 _gdk_display_enable_motion_hints (display, device);
5915 if (G_UNLIKELY (!window->device_events))
5916 window->device_events = g_hash_table_new (NULL, NULL);
5918 if (event_mask == 0)
5920 /* FIXME: unsetting events on a master device
5921 * would restore window->event_mask
5923 g_hash_table_remove (window->device_events, device);
5926 g_hash_table_insert (window->device_events, device,
5927 GINT_TO_POINTER (event_mask));
5929 native = gdk_window_get_toplevel (window);
5931 while (gdk_window_is_offscreen (native))
5933 native = gdk_offscreen_window_get_embedder (native);
5935 if (native == NULL ||
5936 (!_gdk_window_has_impl (native) &&
5937 !gdk_window_is_viewable (native)))
5940 native = gdk_window_get_toplevel (native);
5943 device_mask = get_native_device_event_mask (window, device);
5944 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5948 * gdk_window_get_device_events:
5949 * @window: a #GdkWindow.
5950 * @device: a #GdkDevice.
5952 * Returns the event mask for @window corresponding to an specific device.
5954 * Returns: device event mask for @window
5959 gdk_window_get_device_events (GdkWindow *window,
5964 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5965 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5967 if (GDK_WINDOW_DESTROYED (window))
5970 if (!window->device_events)
5973 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5975 /* FIXME: device could be controlled by window->event_mask */
5981 gdk_window_move_resize_toplevel (GdkWindow *window,
5988 cairo_region_t *old_region, *new_region;
5989 GdkWindowImplClass *impl_class;
5996 is_resize = (width != -1) || (height != -1);
5998 if (gdk_window_is_viewable (window) &&
5999 !window->input_only)
6002 old_region = cairo_region_copy (window->clip_region);
6005 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6006 impl_class->move_resize (window, with_move, x, y, width, height);
6008 /* Avoid recomputing for pure toplevel moves, for performance reasons */
6010 recompute_visible_regions (window, TRUE, FALSE);
6014 new_region = cairo_region_copy (window->clip_region);
6016 /* This is the newly exposed area (due to any resize),
6017 * X will expose it, but lets do that without the roundtrip
6019 cairo_region_subtract (new_region, old_region);
6020 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
6022 cairo_region_destroy (old_region);
6023 cairo_region_destroy (new_region);
6026 _gdk_synthesize_crossing_events_for_geometry_change (window);
6031 move_native_children (GdkWindow *private)
6035 GdkWindowImplClass *impl_class;
6037 for (l = private->children; l; l = l->next)
6041 if (child->impl != private->impl)
6043 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
6044 impl_class->move_resize (child, TRUE,
6046 child->width, child->height);
6049 move_native_children (child);
6054 collect_native_child_region_helper (GdkWindow *window,
6055 GdkWindowImpl *impl,
6056 cairo_region_t **region,
6061 cairo_region_t *tmp;
6064 for (l = window->children; l != NULL; l = l->next)
6068 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
6071 if (child->impl != impl)
6073 tmp = cairo_region_copy (child->clip_region);
6074 cairo_region_translate (tmp,
6075 x_offset + child->x,
6076 y_offset + child->y);
6077 if (*region == NULL)
6081 cairo_region_union (*region, tmp);
6082 cairo_region_destroy (tmp);
6086 collect_native_child_region_helper (child, impl, region,
6087 x_offset + child->x,
6088 y_offset + child->y);
6094 static cairo_region_t *
6095 collect_native_child_region (GdkWindow *window,
6096 gboolean include_this)
6098 cairo_region_t *region;
6100 if (include_this && gdk_window_has_impl (window) && window->viewable)
6101 return cairo_region_copy (window->clip_region);
6105 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6112 gdk_window_move_resize_internal (GdkWindow *window,
6119 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
6120 cairo_region_t *old_native_child_region, *new_native_child_region;
6121 GdkWindow *impl_window;
6122 GdkWindowImplClass *impl_class;
6124 int old_x, old_y, old_abs_x, old_abs_y;
6127 g_return_if_fail (GDK_IS_WINDOW (window));
6129 if (window->destroyed)
6132 if (gdk_window_is_toplevel (window))
6134 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6138 /* Bail early if no change */
6139 if (window->width == width &&
6140 window->height == height &&
6146 /* Handle child windows */
6152 impl_window = gdk_window_get_impl_window (window);
6157 old_native_child_region = NULL;
6158 if (gdk_window_is_viewable (window) &&
6159 !window->input_only)
6163 old_region = cairo_region_copy (window->clip_region);
6164 old_layered = cairo_region_copy (window->layered_region);
6165 /* Adjust regions to parent window coords */
6166 cairo_region_translate (old_region, window->x, window->y);
6167 cairo_region_translate (old_layered, window->x, window->y);
6169 old_native_child_region = collect_native_child_region (window, TRUE);
6170 if (old_native_child_region)
6172 /* Adjust region to parent window coords */
6173 cairo_region_translate (old_native_child_region, window->x, window->y);
6175 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6176 * source or destination for a delayed GdkWindowRegionMove. So, we need
6177 * to flush those here for the parent window and all overlapped subwindows
6178 * of it. And we need to do this before setting the new clips as those will be
6181 gdk_window_flush_recursive (window->parent);
6185 /* Set the new position and size */
6191 if (!(width < 0 && height < 0))
6195 window->width = width;
6198 window->height = height;
6201 dx = window->x - old_x;
6202 dy = window->y - old_y;
6204 old_abs_x = window->abs_x;
6205 old_abs_y = window->abs_y;
6207 recompute_visible_regions (window, TRUE, FALSE);
6209 new_native_child_region = NULL;
6210 if (old_native_child_region)
6212 new_native_child_region = collect_native_child_region (window, TRUE);
6213 /* Adjust region to parent window coords */
6214 cairo_region_translate (new_native_child_region, window->x, window->y);
6217 if (gdk_window_has_impl (window))
6219 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6221 /* Do the actual move after recomputing things, as this will have set the shape to
6222 the now correct one, thus avoiding copying regions that should not be copied. */
6223 impl_class->move_resize (window, TRUE,
6224 window->x, window->y,
6225 window->width, window->height);
6227 else if (old_abs_x != window->abs_x ||
6228 old_abs_y != window->abs_y)
6229 move_native_children (window);
6233 new_region = cairo_region_copy (window->clip_region);
6234 /* Adjust region to parent window coords */
6235 cairo_region_translate (new_region, window->x, window->y);
6238 * Part of the data at the new location can be copied from the
6239 * old location, this area is the intersection of the old region
6240 * moved as the copy will move it and then intersected with
6244 * Everything in the old and new regions that is not copied must be
6245 * invalidated (including children) as this is newly exposed
6247 if (gdk_window_has_alpha (window))
6248 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6250 copy_area = cairo_region_copy (new_region);
6252 /* Don't copy from a previously layered region */
6253 cairo_region_translate (old_layered, dx, dy);
6254 cairo_region_subtract (copy_area, old_layered);
6256 /* Don't copy into a layered region */
6257 cairo_region_translate (copy_area, -window->x, -window->y);
6258 cairo_region_subtract (copy_area, window->layered_region);
6259 cairo_region_translate (copy_area, window->x, window->y);
6261 cairo_region_union (new_region, old_region);
6263 if (old_native_child_region)
6265 /* Don't copy from inside native children, as this is copied by
6266 * the native window move.
6268 cairo_region_subtract (old_region, old_native_child_region);
6270 cairo_region_translate (old_region, dx, dy);
6272 cairo_region_intersect (copy_area, old_region);
6274 if (new_native_child_region)
6276 /* Don't copy any bits that would cause a read from the moved
6277 native windows, as we can't read that data */
6278 cairo_region_translate (new_native_child_region, dx, dy);
6279 cairo_region_subtract (copy_area, new_native_child_region);
6280 cairo_region_translate (new_native_child_region, -dx, -dy);
6283 cairo_region_subtract (new_region, copy_area);
6285 /* Convert old region to impl coords */
6286 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6288 /* convert from parent coords to impl */
6289 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6291 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6293 /* Invalidate affected part in the parent window
6294 * (no higher window should be affected)
6295 * We also invalidate any children in that area, which could include
6296 * this window if it still overlaps that area.
6298 if (old_native_child_region)
6300 /* No need to expose the region that the native window move copies */
6301 cairo_region_translate (old_native_child_region, dx, dy);
6302 cairo_region_intersect (old_native_child_region, new_native_child_region);
6303 cairo_region_subtract (new_region, old_native_child_region);
6305 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6307 cairo_region_destroy (old_region);
6308 cairo_region_destroy (old_layered);
6309 cairo_region_destroy (new_region);
6312 if (old_native_child_region)
6314 cairo_region_destroy (old_native_child_region);
6315 cairo_region_destroy (new_native_child_region);
6318 _gdk_synthesize_crossing_events_for_geometry_change (window);
6325 * @window: a #GdkWindow
6326 * @x: X coordinate relative to window's parent
6327 * @y: Y coordinate relative to window's parent
6329 * Repositions a window relative to its parent window.
6330 * For toplevel windows, window managers may ignore or modify the move;
6331 * you should probably use gtk_window_move() on a #GtkWindow widget
6332 * anyway, instead of using GDK functions. For child windows,
6333 * the move will reliably succeed.
6335 * If you're also planning to resize the window, use gdk_window_move_resize()
6336 * to both move and resize simultaneously, for a nicer visual effect.
6339 gdk_window_move (GdkWindow *window,
6343 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6347 * gdk_window_resize:
6348 * @window: a #GdkWindow
6349 * @width: new width of the window
6350 * @height: new height of the window
6352 * Resizes @window; for toplevel windows, asks the window manager to resize
6353 * the window. The window manager may not allow the resize. When using GTK+,
6354 * use gtk_window_resize() instead of this low-level GDK function.
6356 * Windows may not be resized below 1x1.
6358 * If you're also planning to move the window, use gdk_window_move_resize()
6359 * to both move and resize simultaneously, for a nicer visual effect.
6362 gdk_window_resize (GdkWindow *window,
6366 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6371 * gdk_window_move_resize:
6372 * @window: a #GdkWindow
6373 * @x: new X position relative to window's parent
6374 * @y: new Y position relative to window's parent
6376 * @height: new height
6378 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6379 * except that both operations are performed at once, avoiding strange
6380 * visual effects. (i.e. the user may be able to see the window first
6381 * move, then resize, if you don't use gdk_window_move_resize().)
6384 gdk_window_move_resize (GdkWindow *window,
6390 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6395 * gdk_window_scroll:
6396 * @window: a #GdkWindow
6397 * @dx: Amount to scroll in the X direction
6398 * @dy: Amount to scroll in the Y direction
6400 * Scroll the contents of @window, both pixels and children, by the
6401 * given amount. @window itself does not move. Portions of the window
6402 * that the scroll operation brings in from offscreen areas are
6403 * invalidated. The invalidated region may be bigger than what would
6404 * strictly be necessary.
6406 * For X11, a minimum area will be invalidated if the window has no
6407 * subwindows, or if the edges of the window's parent do not extend
6408 * beyond the edges of the window. In other cases, a multi-step process
6409 * is used to scroll the window which may produce temporary visual
6410 * artifacts and unnecessary invalidations.
6413 gdk_window_scroll (GdkWindow *window,
6417 GdkWindow *impl_window;
6418 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6419 cairo_region_t *old_native_child_region, *new_native_child_region;
6422 g_return_if_fail (GDK_IS_WINDOW (window));
6424 if (dx == 0 && dy == 0)
6427 if (window->destroyed)
6430 old_layered_area = cairo_region_copy (window->layered_region);
6431 old_native_child_region = collect_native_child_region (window, FALSE);
6432 if (old_native_child_region)
6434 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6435 * source or destination for a delayed GdkWindowRegionMove. So, we need
6436 * to flush those here for the window and all overlapped subwindows
6437 * of it. And we need to do this before setting the new clips as those will be
6440 gdk_window_flush_recursive (window);
6444 /* First move all child windows, without causing invalidation */
6446 tmp_list = window->children;
6449 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6451 /* Just update the positions, the bits will move with the copy */
6455 tmp_list = tmp_list->next;
6458 recompute_visible_regions (window, FALSE, TRUE);
6460 new_native_child_region = NULL;
6461 if (old_native_child_region)
6462 new_native_child_region = collect_native_child_region (window, FALSE);
6464 move_native_children (window);
6466 /* Then copy the actual bits of the window w/ child windows */
6468 impl_window = gdk_window_get_impl_window (window);
6470 /* Calculate the area that can be gotten by copying the old area */
6471 if (gdk_window_has_alpha (window))
6472 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6474 copy_area = cairo_region_copy (window->clip_region);
6475 cairo_region_subtract (copy_area, old_layered_area);
6476 if (old_native_child_region)
6478 /* Don't copy from inside native children, as this is copied by
6479 * the native window move.
6481 cairo_region_subtract (copy_area, old_native_child_region);
6483 /* Don't copy any bits that would cause a read from the moved
6484 native windows, as we can't read that data */
6485 cairo_region_subtract (copy_area, new_native_child_region);
6487 cairo_region_translate (copy_area, dx, dy);
6488 cairo_region_intersect (copy_area, window->clip_region);
6489 cairo_region_subtract (copy_area, window->layered_region);
6491 /* And the rest need to be invalidated */
6492 noncopy_area = cairo_region_copy (window->clip_region);
6493 cairo_region_subtract (noncopy_area, copy_area);
6495 /* convert from window coords to impl */
6496 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6498 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6500 /* Invalidate not copied regions */
6501 if (old_native_child_region)
6503 /* No need to expose the region that the native window move copies */
6504 cairo_region_translate (old_native_child_region, dx, dy);
6505 cairo_region_intersect (old_native_child_region, new_native_child_region);
6506 cairo_region_subtract (noncopy_area, old_native_child_region);
6508 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6510 cairo_region_destroy (noncopy_area);
6511 cairo_region_destroy (old_layered_area);
6513 if (old_native_child_region)
6515 cairo_region_destroy (old_native_child_region);
6516 cairo_region_destroy (new_native_child_region);
6519 _gdk_synthesize_crossing_events_for_geometry_change (window);
6523 * gdk_window_move_region:
6524 * @window: a #GdkWindow
6525 * @region: The #cairo_region_t to move
6526 * @dx: Amount to move in the X direction
6527 * @dy: Amount to move in the Y direction
6529 * Move the part of @window indicated by @region by @dy pixels in the Y
6530 * direction and @dx pixels in the X direction. The portions of @region
6531 * that not covered by the new position of @region are invalidated.
6533 * Child windows are not moved.
6538 gdk_window_move_region (GdkWindow *window,
6539 const cairo_region_t *region,
6543 GdkWindow *impl_window;
6544 cairo_region_t *nocopy_area;
6545 cairo_region_t *copy_area;
6547 g_return_if_fail (GDK_IS_WINDOW (window));
6548 g_return_if_fail (region != NULL);
6550 if (dx == 0 && dy == 0)
6553 if (window->destroyed)
6556 impl_window = gdk_window_get_impl_window (window);
6558 /* compute source regions */
6559 if (gdk_window_has_alpha (window))
6560 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6562 copy_area = cairo_region_copy (region);
6563 cairo_region_intersect (copy_area, window->clip_region_with_children);
6564 cairo_region_subtract (copy_area, window->layered_region);
6565 remove_layered_child_area (window, copy_area);
6567 /* compute destination regions */
6568 cairo_region_translate (copy_area, dx, dy);
6569 cairo_region_intersect (copy_area, window->clip_region_with_children);
6570 cairo_region_subtract (copy_area, window->layered_region);
6571 remove_layered_child_area (window, copy_area);
6573 /* Invalidate parts of the region (source and dest) not covered
6575 nocopy_area = cairo_region_copy (region);
6576 cairo_region_translate (nocopy_area, dx, dy);
6577 cairo_region_union (nocopy_area, region);
6578 cairo_region_subtract (nocopy_area, copy_area);
6580 /* convert from window coords to impl */
6581 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6582 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6584 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6585 cairo_region_destroy (nocopy_area);
6589 * gdk_window_set_background:
6590 * @window: a #GdkWindow
6591 * @color: a #GdkColor
6593 * Sets the background color of @window. (However, when using GTK+,
6594 * set the background of a widget with gtk_widget_modify_bg() - if
6595 * you're an application - or gtk_style_set_background() - if you're
6596 * implementing a custom widget.)
6598 * See also gdk_window_set_background_pattern().
6600 * Deprecated: 3.4: Use gdk_window_set_background_rgba() instead.
6603 gdk_window_set_background (GdkWindow *window,
6604 const GdkColor *color)
6606 cairo_pattern_t *pattern;
6608 g_return_if_fail (GDK_IS_WINDOW (window));
6610 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6611 color->green / 65535.,
6612 color->blue / 65535.);
6614 gdk_window_set_background_pattern (window, pattern);
6616 cairo_pattern_destroy (pattern);
6620 * gdk_window_set_background_rgba:
6621 * @window: a #GdkWindow
6622 * @rgba: a #GdkRGBA color
6624 * Sets the background color of @window.
6626 * See also gdk_window_set_background_pattern().
6629 gdk_window_set_background_rgba (GdkWindow *window,
6630 const GdkRGBA *rgba)
6632 cairo_pattern_t *pattern;
6634 g_return_if_fail (GDK_IS_WINDOW (window));
6635 g_return_if_fail (rgba != NULL);
6637 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6638 rgba->blue, rgba->alpha);
6640 gdk_window_set_background_pattern (window, pattern);
6642 cairo_pattern_destroy (pattern);
6646 /* Updates has_alpha_background recursively for all child windows
6647 that have parent-relative alpha */
6649 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6654 for (l = window->children; l; l = l->next)
6658 if (child->background == NULL &&
6659 child->has_alpha_background != window->has_alpha_background)
6661 child->has_alpha_background = window->has_alpha_background;
6662 recompute_visible_regions (child, TRUE, FALSE);
6663 _gdk_window_propagate_has_alpha_background (child);
6669 * gdk_window_set_background_pattern:
6670 * @window: a #GdkWindow
6671 * @pattern: (allow-none): a pattern to use, or %NULL
6673 * Sets the background of @window.
6675 * A background of %NULL means that the window will inherit its
6676 * background form its parent window.
6678 * The windowing system will normally fill a window with its background
6679 * when the window is obscured then exposed.
6682 gdk_window_set_background_pattern (GdkWindow *window,
6683 cairo_pattern_t *pattern)
6686 cairo_pattern_type_t type;
6688 g_return_if_fail (GDK_IS_WINDOW (window));
6690 if (window->input_only)
6694 cairo_pattern_reference (pattern);
6695 if (window->background)
6696 cairo_pattern_destroy (window->background);
6697 window->background = pattern;
6701 if (pattern == NULL)
6703 /* parent-relative, copy has_alpha from parent */
6704 if (window->parent == NULL ||
6705 window->parent->window_type == GDK_WINDOW_ROOT)
6708 has_alpha = window->parent->has_alpha_background;
6712 type = cairo_pattern_get_type (pattern);
6714 if (type == CAIRO_PATTERN_TYPE_SOLID)
6717 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6721 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6722 type == CAIRO_PATTERN_TYPE_RADIAL)
6728 cairo_pattern_get_color_stop_count (pattern, &n);
6730 for (i = 0; i < n; i++)
6732 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6733 NULL, NULL, NULL, &alpha);
6741 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6743 cairo_surface_t *surface;
6744 cairo_content_t content;
6746 cairo_pattern_get_surface (pattern, &surface);
6747 content = cairo_surface_get_content (surface);
6749 (content == CAIRO_CONTENT_ALPHA) ||
6750 (content == CAIRO_CONTENT_COLOR_ALPHA);
6754 if (has_alpha != window->has_alpha_background)
6756 window->has_alpha_background = has_alpha;
6757 recompute_visible_regions (window, TRUE, FALSE);
6759 _gdk_window_propagate_has_alpha_background (window);
6762 if (gdk_window_has_impl (window))
6764 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6765 impl_class->set_background (window, pattern);
6768 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6772 * gdk_window_get_background_pattern:
6775 * Gets the pattern used to clear the background on @window. If @window
6776 * does not have its own background and reuses the parent's, %NULL is
6777 * returned and you'll have to query it yourself.
6779 * Returns: (transfer none): The pattern to use for the background or
6780 * %NULL to use the parent's background.
6785 gdk_window_get_background_pattern (GdkWindow *window)
6787 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6789 return window->background;
6793 gdk_window_set_cursor_internal (GdkWindow *window,
6797 if (GDK_WINDOW_DESTROYED (window))
6800 if (window->window_type == GDK_WINDOW_ROOT ||
6801 window->window_type == GDK_WINDOW_FOREIGN)
6802 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6805 GdkPointerWindowInfo *pointer_info;
6806 GdkDisplay *display;
6808 display = gdk_window_get_display (window);
6809 pointer_info = _gdk_display_get_pointer_info (display, device);
6811 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6812 update_cursor (display, device);
6817 * gdk_window_get_cursor:
6818 * @window: a #GdkWindow
6820 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6821 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6822 * there is no custom cursor set on the specified window, and it is
6823 * using the cursor for its parent window.
6825 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6826 * object is owned by the #GdkWindow and should not be unreferenced
6827 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6833 gdk_window_get_cursor (GdkWindow *window)
6835 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6837 return window->cursor;
6841 * gdk_window_set_cursor:
6842 * @window: a #GdkWindow
6843 * @cursor: (allow-none): a cursor
6845 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6846 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6847 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6848 * to gdk_window_set_cursor() means that @window will use the cursor of its
6849 * parent window. Most windows should use this default.
6852 gdk_window_set_cursor (GdkWindow *window,
6855 GdkDisplay *display;
6857 g_return_if_fail (GDK_IS_WINDOW (window));
6859 display = gdk_window_get_display (window);
6863 g_object_unref (window->cursor);
6864 window->cursor = NULL;
6867 if (!GDK_WINDOW_DESTROYED (window))
6869 GdkDeviceManager *device_manager;
6873 window->cursor = g_object_ref (cursor);
6875 device_manager = gdk_display_get_device_manager (display);
6876 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6878 for (d = devices; d; d = d->next)
6884 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6887 gdk_window_set_cursor_internal (window, device, window->cursor);
6890 g_list_free (devices);
6891 g_object_notify (G_OBJECT (window), "cursor");
6896 * gdk_window_get_device_cursor:
6897 * @window: a #GdkWindow.
6898 * @device: a master, pointer #GdkDevice.
6900 * Retrieves a #GdkCursor pointer for the @device currently set on the
6901 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6902 * there is no custom cursor set on the specified window, and it is
6903 * using the cursor for its parent window.
6905 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6906 * object is owned by the #GdkWindow and should not be unreferenced
6907 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6913 gdk_window_get_device_cursor (GdkWindow *window,
6916 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6917 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6918 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6919 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6921 return g_hash_table_lookup (window->device_cursor, device);
6925 * gdk_window_set_device_cursor:
6926 * @window: a #Gdkwindow
6927 * @device: a master, pointer #GdkDevice
6928 * @cursor: a #GdkCursor
6930 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6931 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6932 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6933 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6934 * @window will use the cursor of its parent window. Most windows should
6940 gdk_window_set_device_cursor (GdkWindow *window,
6944 g_return_if_fail (GDK_IS_WINDOW (window));
6945 g_return_if_fail (GDK_IS_DEVICE (device));
6946 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6947 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6950 g_hash_table_remove (window->device_cursor, device);
6952 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6954 gdk_window_set_cursor_internal (window, device, cursor);
6958 * gdk_window_get_geometry:
6959 * @window: a #GdkWindow
6960 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6961 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6962 * @width: (out) (allow-none): return location for width of window
6963 * @height: (out) (allow-none): return location for height of window
6965 * Any of the return location arguments to this function may be %NULL,
6966 * if you aren't interested in getting the value of that field.
6968 * The X and Y coordinates returned are relative to the parent window
6969 * of @window, which for toplevels usually means relative to the
6970 * window decorations (titlebar, etc.) rather than relative to the
6971 * root window (screen-size background window).
6973 * On the X11 platform, the geometry is obtained from the X server,
6974 * so reflects the latest position of @window; this may be out-of-sync
6975 * with the position of @window delivered in the most-recently-processed
6976 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6977 * position from the most recent configure event.
6980 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6981 * to call gdk_window_get_position(), gdk_window_get_width() and
6982 * gdk_window_get_height() instead, because it avoids the roundtrip to
6983 * the X server and because these functions support the full 32-bit
6984 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6985 * the 16-bit coordinates of X11.
6989 gdk_window_get_geometry (GdkWindow *window,
6996 GdkWindowImplClass *impl_class;
7000 GDK_NOTE (MULTIHEAD,
7001 g_message ("gdk_window_get_geometry(): Window needs "
7002 "to be non-NULL to be multi head safe"));
7003 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
7006 g_return_if_fail (GDK_IS_WINDOW (window));
7008 if (!GDK_WINDOW_DESTROYED (window))
7010 if (gdk_window_has_impl (window))
7012 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7013 impl_class->get_geometry (window, x, y,
7015 /* This reports the position wrt to the native parent, we need to convert
7016 it to be relative to the client side parent */
7017 parent = window->parent;
7018 if (parent && !gdk_window_has_impl (parent))
7021 *x -= parent->abs_x;
7023 *y -= parent->abs_y;
7033 *width = window->width;
7035 *height = window->height;
7041 * gdk_window_get_width:
7042 * @window: a #GdkWindow
7044 * Returns the width of the given @window.
7046 * On the X11 platform the returned size is the size reported in the
7047 * most-recently-processed configure event, rather than the current
7048 * size on the X server.
7050 * Returns: The width of @window
7055 gdk_window_get_width (GdkWindow *window)
7057 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7059 return window->width;
7063 * gdk_window_get_height:
7064 * @window: a #GdkWindow
7066 * Returns the height of the given @window.
7068 * On the X11 platform the returned size is the size reported in the
7069 * most-recently-processed configure event, rather than the current
7070 * size on the X server.
7072 * Returns: The height of @window
7077 gdk_window_get_height (GdkWindow *window)
7079 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7081 return window->height;
7085 * gdk_window_get_origin:
7086 * @window: a #GdkWindow
7087 * @x: (out) (allow-none): return location for X coordinate
7088 * @y: (out) (allow-none): return location for Y coordinate
7090 * Obtains the position of a window in root window coordinates.
7091 * (Compare with gdk_window_get_position() and
7092 * gdk_window_get_geometry() which return the position of a window
7093 * relative to its parent window.)
7095 * Return value: not meaningful, ignore
7098 gdk_window_get_origin (GdkWindow *window,
7102 GdkWindowImplClass *impl_class;
7104 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7106 if (GDK_WINDOW_DESTROYED (window))
7115 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7116 impl_class->get_root_coords (window,
7125 * gdk_window_get_root_coords:
7126 * @window: a #GdkWindow
7127 * @x: X coordinate in window
7128 * @y: Y coordinate in window
7129 * @root_x: (out): return location for X coordinate
7130 * @root_y: (out): return location for Y coordinate
7132 * Obtains the position of a window position in root
7133 * window coordinates. This is similar to
7134 * gdk_window_get_origin() but allows you go pass
7135 * in any position in the window, not just the origin.
7140 gdk_window_get_root_coords (GdkWindow *window,
7146 GdkWindowImplClass *impl_class;
7148 g_return_if_fail (GDK_IS_WINDOW (window));
7150 if (GDK_WINDOW_DESTROYED (window))
7157 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7158 impl_class->get_root_coords (window,
7165 * gdk_window_coords_to_parent:
7166 * @window: a child window
7167 * @x: X coordinate in child's coordinate system
7168 * @y: Y coordinate in child's coordinate system
7169 * @parent_x: (out) (allow-none): return location for X coordinate
7170 * in parent's coordinate system, or %NULL
7171 * @parent_y: (out) (allow-none): return location for Y coordinate
7172 * in parent's coordinate system, or %NULL
7174 * Transforms window coordinates from a child window to its parent
7175 * window, where the parent window is the normal parent as returned by
7176 * gdk_window_get_parent() for normal windows, and the window's
7177 * embedder as returned by gdk_offscreen_window_get_embedder() for
7178 * offscreen windows.
7180 * For normal windows, calling this function is equivalent to adding
7181 * the return values of gdk_window_get_position() to the child coordinates.
7182 * For offscreen windows however (which can be arbitrarily transformed),
7183 * this function calls the GdkWindow::to-embedder: signal to translate
7186 * You should always use this function when writing generic code that
7187 * walks up a window hierarchy.
7189 * See also: gdk_window_coords_from_parent()
7194 gdk_window_coords_to_parent (GdkWindow *window,
7200 g_return_if_fail (GDK_IS_WINDOW (window));
7202 if (gdk_window_is_offscreen (window))
7206 to_embedder (window, x, y, &px, &py);
7217 *parent_x = x + window->x;
7220 *parent_y = y + window->y;
7225 * gdk_window_coords_from_parent:
7226 * @window: a child window
7227 * @parent_x: X coordinate in parent's coordinate system
7228 * @parent_y: Y coordinate in parent's coordinate system
7229 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7230 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7232 * Transforms window coordinates from a parent window to a child
7233 * window, where the parent window is the normal parent as returned by
7234 * gdk_window_get_parent() for normal windows, and the window's
7235 * embedder as returned by gdk_offscreen_window_get_embedder() for
7236 * offscreen windows.
7238 * For normal windows, calling this function is equivalent to subtracting
7239 * the return values of gdk_window_get_position() from the parent coordinates.
7240 * For offscreen windows however (which can be arbitrarily transformed),
7241 * this function calls the GdkWindow::from-embedder: signal to translate
7244 * You should always use this function when writing generic code that
7245 * walks down a window hierarchy.
7247 * See also: gdk_window_coords_to_parent()
7252 gdk_window_coords_from_parent (GdkWindow *window,
7258 g_return_if_fail (GDK_IS_WINDOW (window));
7260 if (gdk_window_is_offscreen (window))
7264 from_embedder (window, parent_x, parent_y, &cx, &cy);
7275 *x = parent_x - window->x;
7278 *y = parent_y - window->y;
7283 * gdk_window_shape_combine_region:
7284 * @window: a #GdkWindow
7285 * @shape_region: (allow-none): region of window to be non-transparent
7286 * @offset_x: X position of @shape_region in @window coordinates
7287 * @offset_y: Y position of @shape_region in @window coordinates
7289 * Makes pixels in @window outside @shape_region be transparent,
7290 * so that the window may be nonrectangular.
7292 * If @shape_region is %NULL, the shape will be unset, so the whole
7293 * window will be opaque again. @offset_x and @offset_y are ignored
7294 * if @shape_region is %NULL.
7296 * On the X11 platform, this uses an X server extension which is
7297 * widely available on most common platforms, but not available on
7298 * very old X servers, and occasionally the implementation will be
7299 * buggy. On servers without the shape extension, this function
7302 * This function works on both toplevel and child windows.
7305 gdk_window_shape_combine_region (GdkWindow *window,
7306 const cairo_region_t *shape_region,
7310 cairo_region_t *old_region, *new_region, *diff;
7312 g_return_if_fail (GDK_IS_WINDOW (window));
7314 if (GDK_WINDOW_DESTROYED (window))
7317 if (!window->shape && shape_region == NULL)
7320 window->shaped = (shape_region != NULL);
7323 cairo_region_destroy (window->shape);
7326 if (GDK_WINDOW_IS_MAPPED (window))
7327 old_region = cairo_region_copy (window->clip_region);
7331 window->shape = cairo_region_copy (shape_region);
7332 cairo_region_translate (window->shape, offset_x, offset_y);
7335 window->shape = NULL;
7337 recompute_visible_regions (window, TRUE, FALSE);
7339 if (gdk_window_has_impl (window) &&
7340 !should_apply_clip_as_shape (window))
7341 apply_shape (window, window->shape);
7345 new_region = cairo_region_copy (window->clip_region);
7347 /* New area in the window, needs invalidation */
7348 diff = cairo_region_copy (new_region);
7349 cairo_region_subtract (diff, old_region);
7351 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7353 cairo_region_destroy (diff);
7355 if (!gdk_window_is_toplevel (window))
7357 /* New area in the non-root parent window, needs invalidation */
7358 diff = cairo_region_copy (old_region);
7359 cairo_region_subtract (diff, new_region);
7361 /* Adjust region to parent window coords */
7362 cairo_region_translate (diff, window->x, window->y);
7364 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7366 cairo_region_destroy (diff);
7369 cairo_region_destroy (new_region);
7370 cairo_region_destroy (old_region);
7375 do_child_shapes (GdkWindow *window,
7379 cairo_region_t *region;
7383 r.width = window->width;
7384 r.height = window->height;
7386 region = cairo_region_create_rectangle (&r);
7387 remove_child_area (window, NULL, FALSE, region, NULL);
7389 if (merge && window->shape)
7390 cairo_region_subtract (region, window->shape);
7392 gdk_window_shape_combine_region (window, region, 0, 0);
7396 * gdk_window_set_child_shapes:
7397 * @window: a #GdkWindow
7399 * Sets the shape mask of @window to the union of shape masks
7400 * for all children of @window, ignoring the shape mask of @window
7401 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7402 * the shape mask of @window in the masks to be merged.
7405 gdk_window_set_child_shapes (GdkWindow *window)
7407 g_return_if_fail (GDK_IS_WINDOW (window));
7409 do_child_shapes (window, FALSE);
7413 * gdk_window_merge_child_shapes:
7414 * @window: a #GdkWindow
7416 * Merges the shape masks for any child windows into the
7417 * shape mask for @window. i.e. the union of all masks
7418 * for @window and its children will become the new mask
7419 * for @window. See gdk_window_shape_combine_region().
7421 * This function is distinct from gdk_window_set_child_shapes()
7422 * because it includes @window's shape mask in the set of shapes to
7426 gdk_window_merge_child_shapes (GdkWindow *window)
7428 g_return_if_fail (GDK_IS_WINDOW (window));
7430 do_child_shapes (window, TRUE);
7434 * gdk_window_input_shape_combine_region:
7435 * @window: a #GdkWindow
7436 * @shape_region: region of window to be non-transparent
7437 * @offset_x: X position of @shape_region in @window coordinates
7438 * @offset_y: Y position of @shape_region in @window coordinates
7440 * Like gdk_window_shape_combine_region(), but the shape applies
7441 * only to event handling. Mouse events which happen while
7442 * the pointer position corresponds to an unset bit in the
7443 * mask will be passed on the window below @window.
7445 * An input shape is typically used with RGBA windows.
7446 * The alpha channel of the window defines which pixels are
7447 * invisible and allows for nicely antialiased borders,
7448 * and the input shape controls where the window is
7451 * On the X11 platform, this requires version 1.1 of the
7454 * On the Win32 platform, this functionality is not present and the
7455 * function does nothing.
7460 gdk_window_input_shape_combine_region (GdkWindow *window,
7461 const cairo_region_t *shape_region,
7465 GdkWindowImplClass *impl_class;
7467 g_return_if_fail (GDK_IS_WINDOW (window));
7469 if (GDK_WINDOW_DESTROYED (window))
7472 if (window->input_shape)
7473 cairo_region_destroy (window->input_shape);
7477 window->input_shape = cairo_region_copy (shape_region);
7478 cairo_region_translate (window->input_shape, offset_x, offset_y);
7481 window->input_shape = NULL;
7483 if (gdk_window_has_impl (window))
7485 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7486 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7489 /* Pointer may have e.g. moved outside window due to the input mask change */
7490 _gdk_synthesize_crossing_events_for_geometry_change (window);
7494 do_child_input_shapes (GdkWindow *window,
7498 cairo_region_t *region;
7502 r.width = window->width;
7503 r.height = window->height;
7505 region = cairo_region_create_rectangle (&r);
7506 remove_child_area (window, NULL, TRUE, region, NULL);
7508 if (merge && window->shape)
7509 cairo_region_subtract (region, window->shape);
7510 if (merge && window->input_shape)
7511 cairo_region_subtract (region, window->input_shape);
7513 gdk_window_input_shape_combine_region (window, region, 0, 0);
7518 * gdk_window_set_child_input_shapes:
7519 * @window: a #GdkWindow
7521 * Sets the input shape mask of @window to the union of input shape masks
7522 * for all children of @window, ignoring the input shape mask of @window
7523 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7524 * the input shape mask of @window in the masks to be merged.
7529 gdk_window_set_child_input_shapes (GdkWindow *window)
7531 g_return_if_fail (GDK_IS_WINDOW (window));
7533 do_child_input_shapes (window, FALSE);
7537 * gdk_window_merge_child_input_shapes:
7538 * @window: a #GdkWindow
7540 * Merges the input shape masks for any child windows into the
7541 * input shape mask for @window. i.e. the union of all input masks
7542 * for @window and its children will become the new input mask
7543 * for @window. See gdk_window_input_shape_combine_region().
7545 * This function is distinct from gdk_window_set_child_input_shapes()
7546 * because it includes @window's input shape mask in the set of
7547 * shapes to be merged.
7552 gdk_window_merge_child_input_shapes (GdkWindow *window)
7554 g_return_if_fail (GDK_IS_WINDOW (window));
7556 do_child_input_shapes (window, TRUE);
7561 * gdk_window_set_static_gravities:
7562 * @window: a #GdkWindow
7563 * @use_static: %TRUE to turn on static gravity
7565 * Set the bit gravity of the given window to static, and flag it so
7566 * all children get static subwindow gravity. This is used if you are
7567 * implementing scary features that involve deep knowledge of the
7568 * windowing system. Don't worry about it unless you have to.
7570 * Return value: %TRUE if the server supports static gravity
7573 gdk_window_set_static_gravities (GdkWindow *window,
7574 gboolean use_static)
7576 GdkWindowImplClass *impl_class;
7578 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7580 if (gdk_window_has_impl (window))
7582 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7583 return impl_class->set_static_gravities (window, use_static);
7590 * gdk_window_get_composited:
7591 * @window: a #GdkWindow
7593 * Determines whether @window is composited.
7595 * See gdk_window_set_composited().
7597 * Returns: %TRUE if the window is composited.
7602 gdk_window_get_composited (GdkWindow *window)
7604 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7606 return window->composited;
7610 * gdk_window_set_composited:
7611 * @window: a #GdkWindow
7612 * @composited: %TRUE to set the window as composited
7614 * Sets a #GdkWindow as composited, or unsets it. Composited
7615 * windows do not automatically have their contents drawn to
7616 * the screen. Drawing is redirected to an offscreen buffer
7617 * and an expose event is emitted on the parent of the composited
7618 * window. It is the responsibility of the parent's expose handler
7619 * to manually merge the off-screen content onto the screen in
7620 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7623 * It only makes sense for child windows to be composited; see
7624 * gdk_window_set_opacity() if you need translucent toplevel
7627 * An additional effect of this call is that the area of this
7628 * window is no longer clipped from regions marked for
7629 * invalidation on its parent. Draws done on the parent
7630 * window are also no longer clipped by the child.
7632 * This call is only supported on some systems (currently,
7633 * only X11 with new enough Xcomposite and Xdamage extensions).
7634 * You must call gdk_display_supports_composite() to check if
7635 * setting a window as composited is supported before
7636 * attempting to do so.
7641 gdk_window_set_composited (GdkWindow *window,
7642 gboolean composited)
7644 GdkDisplay *display;
7645 GdkWindowImplClass *impl_class;
7647 g_return_if_fail (GDK_IS_WINDOW (window));
7649 composited = composited != FALSE;
7651 if (window->composited == composited)
7655 gdk_window_ensure_native (window);
7657 display = gdk_window_get_display (window);
7659 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7661 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7663 g_warning ("gdk_window_set_composited called but "
7664 "compositing is not supported");
7668 impl_class->set_composited (window, composited);
7670 recompute_visible_regions (window, TRUE, FALSE);
7672 if (GDK_WINDOW_IS_MAPPED (window))
7673 gdk_window_invalidate_in_parent (window);
7675 window->composited = composited;
7679 * gdk_window_get_modal_hint:
7680 * @window: A toplevel #GdkWindow.
7682 * Determines whether or not the window manager is hinted that @window
7683 * has modal behaviour.
7685 * Return value: whether or not the window has the modal hint set.
7690 gdk_window_get_modal_hint (GdkWindow *window)
7692 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7694 return window->modal_hint;
7698 * gdk_window_get_accept_focus:
7699 * @window: a toplevel #GdkWindow.
7701 * Determines whether or not the desktop environment shuld be hinted that
7702 * the window does not want to receive input focus.
7704 * Return value: whether or not the window should receive input focus.
7709 gdk_window_get_accept_focus (GdkWindow *window)
7711 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7713 return window->accept_focus;
7717 * gdk_window_get_focus_on_map:
7718 * @window: a toplevel #GdkWindow.
7720 * Determines whether or not the desktop environment should be hinted that the
7721 * window does not want to receive input focus when it is mapped.
7723 * Return value: whether or not the window wants to receive input focus when
7729 gdk_window_get_focus_on_map (GdkWindow *window)
7731 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7733 return window->focus_on_map;
7737 * gdk_window_is_input_only:
7738 * @window: a toplevel #GdkWindow
7740 * Determines whether or not the window is an input only window.
7742 * Return value: %TRUE if @window is input only
7747 gdk_window_is_input_only (GdkWindow *window)
7749 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7751 return window->input_only;
7755 * gdk_window_is_shaped:
7756 * @window: a toplevel #GdkWindow
7758 * Determines whether or not the window is shaped.
7760 * Return value: %TRUE if @window is shaped
7765 gdk_window_is_shaped (GdkWindow *window)
7767 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7769 return window->shaped;
7773 _gdk_window_add_damage (GdkWindow *toplevel,
7774 cairo_region_t *damaged_region)
7776 GdkDisplay *display;
7777 GdkEvent event = { 0, };
7778 event.expose.type = GDK_DAMAGE;
7779 event.expose.window = toplevel;
7780 event.expose.send_event = FALSE;
7781 event.expose.region = damaged_region;
7782 cairo_region_get_extents (event.expose.region, &event.expose.area);
7783 display = gdk_window_get_display (event.expose.window);
7784 _gdk_event_queue_append (display, gdk_event_copy (&event));
7787 /* Gets the toplevel for a window as used for events,
7788 i.e. including offscreen parents */
7790 get_event_parent (GdkWindow *window)
7792 if (gdk_window_is_offscreen (window))
7793 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7795 return window->parent;
7798 /* Gets the toplevel for a window as used for events,
7799 i.e. including offscreen parents going up to the native
7802 get_event_toplevel (GdkWindow *window)
7806 while ((parent = get_event_parent (window)) != NULL &&
7807 (parent->window_type != GDK_WINDOW_ROOT))
7814 _gdk_window_event_parent_of (GdkWindow *parent,
7825 w = get_event_parent (w);
7832 update_cursor (GdkDisplay *display,
7835 GdkWindow *cursor_window, *parent, *toplevel;
7836 GdkWindow *pointer_window;
7837 GdkWindowImplClass *impl_class;
7838 GdkPointerWindowInfo *pointer_info;
7839 GdkDeviceGrabInfo *grab;
7842 pointer_info = _gdk_display_get_pointer_info (display, device);
7843 pointer_window = pointer_info->window_under_pointer;
7845 /* We ignore the serials here and just pick the last grab
7846 we've sent, as that would shortly be used anyway. */
7847 grab = _gdk_display_get_last_device_grab (display, device);
7850 /* the pointer is not in a descendant of the grab window */
7851 !_gdk_window_event_parent_of (grab->window, pointer_window))
7853 /* use the cursor from the grab window */
7854 cursor_window = grab->window;
7858 /* otherwise use the cursor from the pointer window */
7859 cursor_window = pointer_window;
7862 /* Find the first window with the cursor actually set, as
7863 the cursor is inherited from the parent */
7864 while (cursor_window->cursor == NULL &&
7865 (parent = get_event_parent (cursor_window)) != NULL &&
7866 parent->window_type != GDK_WINDOW_ROOT)
7867 cursor_window = parent;
7869 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7872 cursor = cursor_window->cursor;
7874 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7875 * which native window has what cursor set. */
7876 toplevel = get_event_toplevel (pointer_window);
7877 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7878 impl_class->set_device_cursor (toplevel, device, cursor);
7882 point_in_window (GdkWindow *window,
7887 x >= 0 && x < window->width &&
7888 y >= 0 && y < window->height &&
7889 (window->shape == NULL ||
7890 cairo_region_contains_point (window->shape,
7892 (window->input_shape == NULL ||
7893 cairo_region_contains_point (window->input_shape,
7898 convert_native_coords_to_toplevel (GdkWindow *window,
7901 gdouble *toplevel_x,
7902 gdouble *toplevel_y)
7909 while (!gdk_window_is_toplevel (window))
7913 window = window->parent;
7923 convert_toplevel_coords_to_window (GdkWindow *window,
7931 GList *children, *l;
7937 while ((parent = get_event_parent (window)) != NULL &&
7938 (parent->window_type != GDK_WINDOW_ROOT))
7940 children = g_list_prepend (children, window);
7944 for (l = children; l != NULL; l = l->next)
7945 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7947 g_list_free (children);
7954 pick_embedded_child (GdkWindow *window,
7961 g_signal_emit (window,
7962 signals[PICK_EMBEDDED_CHILD], 0,
7969 _gdk_window_find_child_at (GdkWindow *window,
7974 double child_x, child_y;
7977 if (point_in_window (window, x, y))
7979 /* Children is ordered in reverse stack order, i.e. first is topmost */
7980 for (l = window->children; l != NULL; l = l->next)
7984 if (!GDK_WINDOW_IS_MAPPED (sub))
7987 gdk_window_coords_from_parent ((GdkWindow *)sub,
7989 &child_x, &child_y);
7990 if (point_in_window (sub, child_x, child_y))
7991 return (GdkWindow *)sub;
7994 if (window->num_offscreen_children > 0)
7996 sub = pick_embedded_child (window,
7999 return (GdkWindow *)sub;
8007 _gdk_window_find_descendant_at (GdkWindow *window,
8014 gdouble child_x, child_y;
8018 if (point_in_window (window, x, y))
8023 /* Children is ordered in reverse stack order, i.e. first is topmost */
8024 for (l = window->children; l != NULL; l = l->next)
8028 if (!GDK_WINDOW_IS_MAPPED (sub))
8031 gdk_window_coords_from_parent ((GdkWindow *)sub,
8033 &child_x, &child_y);
8034 if (point_in_window (sub, child_x, child_y))
8044 window->num_offscreen_children > 0)
8046 sub = pick_embedded_child (window,
8052 from_embedder (sub, x, y, &x, &y);
8060 /* Not in window at all */
8074 * @window: a toplevel #GdkWindow
8076 * Emits a short beep associated to @window in the appropriate
8077 * display, if supported. Otherwise, emits a short beep on
8078 * the display just as gdk_display_beep().
8083 gdk_window_beep (GdkWindow *window)
8085 GdkDisplay *display;
8086 GdkWindow *toplevel;
8088 g_return_if_fail (GDK_IS_WINDOW (window));
8090 if (GDK_WINDOW_DESTROYED (window))
8093 toplevel = get_event_toplevel (window);
8094 display = gdk_window_get_display (window);
8098 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
8102 /* If windows fail to beep, we beep the display. */
8103 gdk_display_beep (display);
8107 * gdk_window_set_support_multidevice:
8108 * @window: a #GdkWindow.
8109 * @support_multidevice: %TRUE to enable multidevice support in @window.
8111 * This function will enable multidevice features in @window.
8113 * Multidevice aware windows will need to handle properly multiple,
8114 * per device enter/leave events, device grabs and grab ownerships.
8119 gdk_window_set_support_multidevice (GdkWindow *window,
8120 gboolean support_multidevice)
8122 g_return_if_fail (GDK_IS_WINDOW (window));
8124 if (GDK_WINDOW_DESTROYED (window))
8127 if (window->support_multidevice == support_multidevice)
8130 window->support_multidevice = support_multidevice;
8132 /* FIXME: What to do if called when some pointers are inside the window ? */
8136 * gdk_window_get_support_multidevice:
8137 * @window: a #GdkWindow.
8139 * Returns %TRUE if the window is aware of the existence of multiple
8142 * Returns: %TRUE if the window handles multidevice features.
8147 gdk_window_get_support_multidevice (GdkWindow *window)
8149 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8151 if (GDK_WINDOW_DESTROYED (window))
8154 return window->support_multidevice;
8157 static const guint type_masks[] = {
8158 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8159 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8160 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8161 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8162 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8163 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8164 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8165 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8166 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8167 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8168 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8169 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8170 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8171 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8172 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8173 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8174 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8175 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8176 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8177 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8178 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8179 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8180 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8181 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8182 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8183 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8184 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8185 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8186 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8187 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8188 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8189 GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK,/* GDK_SCROLL= 31 */
8190 0, /* GDK_WINDOW_STATE = 32 */
8191 0, /* GDK_SETTING = 33 */
8192 0, /* GDK_OWNER_CHANGE = 34 */
8193 0, /* GDK_GRAB_BROKEN = 35 */
8194 0, /* GDK_DAMAGE = 36 */
8195 GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */
8196 GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */
8197 GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */
8198 GDK_TOUCH_MASK /* GDK_TOUCH_CANCEL = 40 */
8200 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8202 /* send motion events if the right buttons are down */
8204 update_evmask_for_button_motion (guint evmask,
8205 GdkModifierType mask)
8207 if (evmask & GDK_BUTTON_MOTION_MASK &&
8208 mask & (GDK_BUTTON1_MASK |
8213 evmask |= GDK_POINTER_MOTION_MASK;
8215 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8216 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8217 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8218 evmask |= GDK_POINTER_MOTION_MASK;
8224 is_button_type (GdkEventType type)
8226 return type == GDK_BUTTON_PRESS ||
8227 type == GDK_2BUTTON_PRESS ||
8228 type == GDK_3BUTTON_PRESS ||
8229 type == GDK_BUTTON_RELEASE ||
8230 type == GDK_TOUCH_BEGIN ||
8231 type == GDK_TOUCH_END ||
8236 is_motion_type (GdkEventType type)
8238 return type == GDK_MOTION_NOTIFY ||
8239 type == GDK_TOUCH_UPDATE ||
8240 type == GDK_ENTER_NOTIFY ||
8241 type == GDK_LEAVE_NOTIFY;
8245 is_touch_type (GdkEventType type)
8247 return type == GDK_TOUCH_BEGIN ||
8248 type == GDK_TOUCH_UPDATE ||
8249 type == GDK_TOUCH_END ||
8250 type == GDK_TOUCH_CANCEL;
8254 find_common_ancestor (GdkWindow *win1,
8258 GList *path1 = NULL, *path2 = NULL;
8259 GList *list1, *list2;
8262 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8264 path1 = g_list_prepend (path1, tmp);
8265 tmp = get_event_parent (tmp);
8269 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8271 path2 = g_list_prepend (path2, tmp);
8272 tmp = get_event_parent (tmp);
8278 while (list1 && list2 && (list1->data == list2->data))
8281 list1 = g_list_next (list1);
8282 list2 = g_list_next (list2);
8284 g_list_free (path1);
8285 g_list_free (path2);
8291 _gdk_make_event (GdkWindow *window,
8293 GdkEvent *event_in_queue,
8294 gboolean before_event)
8296 GdkEvent *event = gdk_event_new (type);
8298 GdkModifierType the_state;
8300 the_time = gdk_event_get_time (event_in_queue);
8301 gdk_event_get_state (event_in_queue, &the_state);
8303 event->any.window = g_object_ref (window);
8304 event->any.send_event = FALSE;
8305 if (event_in_queue && event_in_queue->any.send_event)
8306 event->any.send_event = TRUE;
8310 case GDK_MOTION_NOTIFY:
8311 event->motion.time = the_time;
8312 event->motion.axes = NULL;
8313 event->motion.state = the_state;
8316 case GDK_BUTTON_PRESS:
8317 case GDK_2BUTTON_PRESS:
8318 case GDK_3BUTTON_PRESS:
8319 case GDK_BUTTON_RELEASE:
8320 event->button.time = the_time;
8321 event->button.axes = NULL;
8322 event->button.state = the_state;
8325 case GDK_TOUCH_BEGIN:
8326 case GDK_TOUCH_UPDATE:
8328 case GDK_TOUCH_CANCEL:
8329 event->touch.time = the_time;
8330 event->touch.axes = NULL;
8331 event->touch.state = the_state;
8335 event->scroll.time = the_time;
8336 event->scroll.state = the_state;
8340 case GDK_KEY_RELEASE:
8341 event->key.time = the_time;
8342 event->key.state = the_state;
8345 case GDK_ENTER_NOTIFY:
8346 case GDK_LEAVE_NOTIFY:
8347 event->crossing.time = the_time;
8348 event->crossing.state = the_state;
8351 case GDK_PROPERTY_NOTIFY:
8352 event->property.time = the_time;
8353 event->property.state = the_state;
8356 case GDK_SELECTION_CLEAR:
8357 case GDK_SELECTION_REQUEST:
8358 case GDK_SELECTION_NOTIFY:
8359 event->selection.time = the_time;
8362 case GDK_PROXIMITY_IN:
8363 case GDK_PROXIMITY_OUT:
8364 event->proximity.time = the_time;
8367 case GDK_DRAG_ENTER:
8368 case GDK_DRAG_LEAVE:
8369 case GDK_DRAG_MOTION:
8370 case GDK_DRAG_STATUS:
8371 case GDK_DROP_START:
8372 case GDK_DROP_FINISHED:
8373 event->dnd.time = the_time;
8376 case GDK_FOCUS_CHANGE:
8380 case GDK_CLIENT_EVENT:
8381 case GDK_VISIBILITY_NOTIFY:
8392 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8394 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8397 _gdk_event_queue_append (gdk_window_get_display (window), event);
8403 send_crossing_event (GdkDisplay *display,
8404 GdkWindow *toplevel,
8407 GdkCrossingMode mode,
8408 GdkNotifyType notify_type,
8409 GdkWindow *subwindow,
8411 GdkDevice *source_device,
8414 GdkModifierType mask,
8416 GdkEvent *event_in_queue,
8420 guint32 window_event_mask, type_event_mask;
8421 GdkDeviceGrabInfo *grab;
8422 GdkTouchGrabInfo *touch_grab = NULL;
8423 GdkPointerWindowInfo *pointer_info;
8424 gboolean block_event = FALSE;
8425 GdkEventSequence *sequence;
8427 grab = _gdk_display_has_device_grab (display, device, serial);
8428 pointer_info = _gdk_display_get_pointer_info (display, device);
8430 sequence = gdk_event_get_event_sequence (event_in_queue);
8432 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
8436 if (window != touch_grab->window)
8439 window_event_mask = touch_grab->event_mask;
8441 else if (grab != NULL &&
8442 !grab->owner_events)
8444 /* !owner_event => only report events wrt grab window, ignore rest */
8445 if ((GdkWindow *)window != grab->window)
8447 window_event_mask = grab->event_mask;
8450 window_event_mask = window->event_mask;
8452 if (type == GDK_ENTER_NOTIFY &&
8453 (pointer_info->need_touch_press_enter ||
8454 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN) &&
8455 mode != GDK_CROSSING_TOUCH_BEGIN &&
8456 mode != GDK_CROSSING_TOUCH_END)
8458 pointer_info->need_touch_press_enter = TRUE;
8461 else if (type == GDK_LEAVE_NOTIFY)
8463 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8464 window->devices_inside = g_list_remove (window->devices_inside, device);
8466 if (!window->support_multidevice && window->devices_inside)
8468 /* Block leave events unless it's the last pointer */
8474 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8476 if (!window->support_multidevice && window->devices_inside)
8478 /* Only emit enter events for the first device */
8482 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8483 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8484 !g_list_find (window->devices_inside, device))
8485 window->devices_inside = g_list_prepend (window->devices_inside, device);
8491 if (window_event_mask & type_event_mask)
8493 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8494 gdk_event_set_device (event, device);
8497 gdk_event_set_source_device (event, source_device);
8499 event->crossing.time = time_;
8500 event->crossing.subwindow = subwindow;
8502 g_object_ref (subwindow);
8503 convert_toplevel_coords_to_window ((GdkWindow *)window,
8504 toplevel_x, toplevel_y,
8505 &event->crossing.x, &event->crossing.y);
8506 event->crossing.x_root = toplevel_x + toplevel->x;
8507 event->crossing.y_root = toplevel_y + toplevel->y;
8508 event->crossing.mode = mode;
8509 event->crossing.detail = notify_type;
8510 event->crossing.focus = FALSE;
8511 event->crossing.state = mask;
8516 /* The coordinates are in the toplevel window that src/dest are in.
8517 * src and dest are always (if != NULL) in the same toplevel, as
8518 * we get a leave-notify and set the window_under_pointer to null
8519 * before crossing to another toplevel.
8522 _gdk_synthesize_crossing_events (GdkDisplay *display,
8526 GdkDevice *source_device,
8527 GdkCrossingMode mode,
8530 GdkModifierType mask,
8532 GdkEvent *event_in_queue,
8534 gboolean non_linear)
8537 GdkWindow *win, *last, *next;
8541 GdkWindow *toplevel;
8542 GdkNotifyType notify_type;
8544 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8549 return; /* No crossings generated between src and dest */
8551 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8553 if (a && gdk_window_get_device_events (src, device) == 0)
8556 if (b && gdk_window_get_device_events (dest, device) == 0)
8563 c = find_common_ancestor (a, b);
8565 non_linear |= (c != a) && (c != b);
8567 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8569 toplevel = gdk_window_get_toplevel (a);
8571 /* Traverse up from a to (excluding) c sending leave events */
8573 notify_type = GDK_NOTIFY_NONLINEAR;
8575 notify_type = GDK_NOTIFY_INFERIOR;
8577 notify_type = GDK_NOTIFY_ANCESTOR;
8578 send_crossing_event (display, toplevel,
8579 a, GDK_LEAVE_NOTIFY,
8582 NULL, device, source_device,
8583 toplevel_x, toplevel_y,
8591 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8593 notify_type = GDK_NOTIFY_VIRTUAL;
8596 win = get_event_parent (a);
8597 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8599 send_crossing_event (display, toplevel,
8600 win, GDK_LEAVE_NOTIFY,
8604 device, source_device,
8605 toplevel_x, toplevel_y,
8611 win = get_event_parent (win);
8616 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8618 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8620 /* Traverse down from c to b */
8624 win = get_event_parent (b);
8625 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8627 path = g_list_prepend (path, win);
8628 win = get_event_parent (win);
8632 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8634 notify_type = GDK_NOTIFY_VIRTUAL;
8640 list = g_list_next (list);
8646 send_crossing_event (display, toplevel,
8647 win, GDK_ENTER_NOTIFY,
8651 device, source_device,
8652 toplevel_x, toplevel_y,
8662 notify_type = GDK_NOTIFY_NONLINEAR;
8664 notify_type = GDK_NOTIFY_ANCESTOR;
8666 notify_type = GDK_NOTIFY_INFERIOR;
8668 send_crossing_event (display, toplevel,
8669 b, GDK_ENTER_NOTIFY,
8673 device, source_device,
8674 toplevel_x, toplevel_y,
8681 /* Returns the window inside the event window with the pointer in it
8682 * at the specified coordinates, or NULL if its not in any child of
8683 * the toplevel. It also takes into account !owner_events grabs.
8686 get_pointer_window (GdkDisplay *display,
8687 GdkWindow *event_window,
8693 GdkWindow *pointer_window;
8694 GdkDeviceGrabInfo *grab;
8695 GdkPointerWindowInfo *pointer_info;
8697 pointer_info = _gdk_display_get_pointer_info (display, device);
8699 if (event_window == pointer_info->toplevel_under_pointer)
8701 _gdk_window_find_descendant_at (event_window,
8702 toplevel_x, toplevel_y,
8705 pointer_window = NULL;
8707 grab = _gdk_display_has_device_grab (display, device, serial);
8709 !grab->owner_events &&
8710 pointer_window != grab->window)
8711 pointer_window = NULL;
8713 return pointer_window;
8717 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8721 GdkPointerWindowInfo *device_info;
8723 device_info = _gdk_display_get_pointer_info (display, device);
8725 if (device_info->window_under_pointer)
8726 g_object_unref (device_info->window_under_pointer);
8727 device_info->window_under_pointer = window;
8731 g_object_ref (window);
8732 update_cursor (display, device);
8735 _gdk_display_enable_motion_hints (display, device);
8740 * @window: the #GdkWindow which will own the grab (the grab window).
8741 * @owner_events: if %FALSE then all pointer events are reported with respect to
8742 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8743 * events for this application are reported as normal, but pointer events outside
8744 * this application are reported with respect to @window and only if selected by
8745 * @event_mask. In either mode, unreported events are discarded.
8746 * @event_mask: specifies the event mask, which is used in accordance with
8747 * @owner_events. Note that only pointer events (i.e. button and motion events)
8749 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8750 * window during the grab. If the pointer is outside @confine_to, it will
8751 * automatically be moved to the closest edge of @confine_to and enter
8752 * and leave events will be generated as necessary.
8753 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8754 * the normal cursors are used for @window and its descendants, and the cursor
8755 * for @window is used for all other windows.
8756 * @time_: the timestamp of the event which led to this pointer grab. This usually
8757 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8758 * the time isn't known.
8760 * Grabs the pointer (usually a mouse) so that all events are passed to this
8761 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8762 * the grab window becomes unviewable.
8763 * This overrides any previous pointer grab by this client.
8765 * Pointer grabs are used for operations which need complete control over mouse
8766 * events, even if the mouse leaves the application.
8767 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8768 * the #GtkHPaned and #GtkVPaned widgets.
8770 * Note that if the event mask of an X window has selected both button press and
8771 * button release events, then a button press event will cause an automatic
8772 * pointer grab until the button is released.
8773 * X does this automatically since most applications expect to receive button
8774 * press and release events in pairs.
8775 * It is equivalent to a pointer grab on the window with @owner_events set to
8778 * If you set up anything at the time you take the grab that needs to be cleaned
8779 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8780 * are emitted when the grab ends unvoluntarily.
8782 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8784 * Deprecated: 3.0: Use gdk_device_grab() instead.
8787 gdk_pointer_grab (GdkWindow * window,
8788 gboolean owner_events,
8789 GdkEventMask event_mask,
8790 GdkWindow * confine_to,
8795 GdkDisplay *display;
8796 GdkDeviceManager *device_manager;
8798 GdkGrabStatus res = 0;
8800 GList *devices, *dev;
8802 g_return_val_if_fail (window != NULL, 0);
8803 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8804 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8806 /* We need a native window for confine to to work, ensure we have one */
8809 if (!gdk_window_ensure_native (confine_to))
8811 g_warning ("Can't confine to grabbed window, not native");
8816 /* Non-viewable client side window => fail */
8817 if (!_gdk_window_has_impl (window) &&
8818 !gdk_window_is_viewable (window))
8819 return GDK_GRAB_NOT_VIEWABLE;
8821 native = gdk_window_get_toplevel (window);
8822 while (gdk_window_is_offscreen (native))
8824 native = gdk_offscreen_window_get_embedder (native);
8826 if (native == NULL ||
8827 (!_gdk_window_has_impl (native) &&
8828 !gdk_window_is_viewable (native)))
8829 return GDK_GRAB_NOT_VIEWABLE;
8831 native = gdk_window_get_toplevel (native);
8834 display = gdk_window_get_display (window);
8836 serial = _gdk_display_get_next_serial (display);
8837 device_manager = gdk_display_get_device_manager (display);
8838 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8840 /* FIXME: Should this be generic to all backends? */
8841 /* FIXME: What happens with extended devices? */
8842 for (dev = devices; dev; dev = dev->next)
8846 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8849 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8852 get_native_grab_event_mask (event_mask),
8857 if (res == GDK_GRAB_SUCCESS)
8858 _gdk_display_add_device_grab (display,
8870 /* FIXME: handle errors when grabbing */
8872 g_list_free (devices);
8878 * gdk_keyboard_grab:
8879 * @window: the #GdkWindow which will own the grab (the grab window).
8880 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8881 * @window. If %TRUE then keyboard events for this application are
8882 * reported as normal, but keyboard events outside this application
8883 * are reported with respect to @window. Both key press and key
8884 * release events are always reported, independant of the event mask
8885 * set by the application.
8886 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8889 * Grabs the keyboard so that all events are passed to this
8890 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8891 * This overrides any previous keyboard grab by this client.
8893 * If you set up anything at the time you take the grab that needs to be cleaned
8894 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8895 * are emitted when the grab ends unvoluntarily.
8897 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8899 * Deprecated: 3.0: Use gdk_device_grab() instead.
8902 gdk_keyboard_grab (GdkWindow *window,
8903 gboolean owner_events,
8907 GdkDisplay *display;
8908 GdkDeviceManager *device_manager;
8910 GdkGrabStatus res = 0;
8912 GList *devices, *dev;
8914 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8916 /* Non-viewable client side window => fail */
8917 if (!_gdk_window_has_impl (window) &&
8918 !gdk_window_is_viewable (window))
8919 return GDK_GRAB_NOT_VIEWABLE;
8921 native = gdk_window_get_toplevel (window);
8923 while (gdk_window_is_offscreen (native))
8925 native = gdk_offscreen_window_get_embedder (native);
8927 if (native == NULL ||
8928 (!_gdk_window_has_impl (native) &&
8929 !gdk_window_is_viewable (native)))
8930 return GDK_GRAB_NOT_VIEWABLE;
8932 native = gdk_window_get_toplevel (native);
8935 display = gdk_window_get_display (window);
8936 serial = _gdk_display_get_next_serial (display);
8937 device_manager = gdk_display_get_device_manager (display);
8938 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8940 /* FIXME: Should this be generic to all backends? */
8941 /* FIXME: What happens with extended devices? */
8942 for (dev = devices; dev; dev = dev->next)
8946 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8949 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8952 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8957 if (res == GDK_GRAB_SUCCESS)
8958 _gdk_display_add_device_grab (display,
8969 /* FIXME: handle errors when grabbing */
8971 g_list_free (devices);
8977 * gdk_window_geometry_changed:
8978 * @window: an embedded offscreen #GdkWindow
8980 * This function informs GDK that the geometry of an embedded
8981 * offscreen window has changed. This is necessary for GDK to keep
8982 * track of which offscreen window the pointer is in.
8987 gdk_window_geometry_changed (GdkWindow *window)
8989 _gdk_synthesize_crossing_events_for_geometry_change (window);
8993 source_events_device_added (GdkDeviceManager *device_manager,
8998 GdkEventMask event_mask;
8999 GdkInputSource source;
9001 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
9005 source = gdk_device_get_source (device);
9007 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
9008 GINT_TO_POINTER (source)));
9010 gdk_window_set_device_events (window, device, event_mask);
9014 source_events_device_changed (GdkDeviceManager *device_manager,
9019 GdkInputSource source;
9020 GdkEventMask event_mask;
9024 type = gdk_device_get_device_type (device);
9025 source = gdk_device_get_source (device);
9027 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
9028 GINT_TO_POINTER (source)));
9033 if (type == GDK_DEVICE_TYPE_FLOATING)
9035 /* The device was just floated, enable its event mask */
9036 gdk_window_set_device_events (window, device, event_mask);
9038 else if (type == GDK_DEVICE_TYPE_SLAVE)
9039 gdk_window_set_device_events (window, device, 0);
9043 * gdk_window_set_source_events:
9044 * @window: a #GdkWindow
9045 * @source: a #GdkInputSource to define the source class.
9046 * @event_mask: event mask for @window
9048 * Sets the event mask for any floating device (i.e. not attached to any
9049 * visible pointer) that has the source defined as @source. This event
9050 * mask will be applied both to currently existing, newly added devices
9051 * after this call, and devices being attached/detached.
9056 gdk_window_set_source_events (GdkWindow *window,
9057 GdkInputSource source,
9058 GdkEventMask event_mask)
9060 GdkDeviceManager *device_manager;
9061 GdkDisplay *display;
9065 g_return_if_fail (GDK_IS_WINDOW (window));
9067 display = gdk_window_get_display (window);
9068 device_manager = gdk_display_get_device_manager (display);
9070 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
9072 /* Set event mask for existing devices */
9073 for (d = devices; d; d = d->next)
9075 GdkDevice *device = d->data;
9077 if (source == gdk_device_get_source (device))
9078 gdk_window_set_device_events (window, device, event_mask);
9081 g_list_free (devices);
9083 /* Update accounting */
9084 if (G_UNLIKELY (!window->source_event_masks))
9085 window->source_event_masks = g_hash_table_new (NULL, NULL);
9088 g_hash_table_insert (window->source_event_masks,
9089 GUINT_TO_POINTER (source),
9090 GUINT_TO_POINTER (event_mask));
9092 g_hash_table_remove (window->source_event_masks,
9093 GUINT_TO_POINTER (source));
9095 size = g_hash_table_size (window->source_event_masks);
9097 /* Update handler if needed */
9098 if (!window->device_added_handler_id && size > 0)
9100 window->device_added_handler_id =
9101 g_signal_connect (device_manager, "device-added",
9102 G_CALLBACK (source_events_device_added), window);
9103 window->device_changed_handler_id =
9104 g_signal_connect (device_manager, "device-changed",
9105 G_CALLBACK (source_events_device_changed), window);
9107 else if (window->device_added_handler_id && size == 0)
9108 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
9112 * gdk_window_get_source_events:
9113 * @window: a #GdkWindow
9114 * @source: a #GdkInputSource to define the source class.
9116 * Returns the event mask for @window corresponding to the device class specified
9119 * Returns: source event mask for @window
9122 gdk_window_get_source_events (GdkWindow *window,
9123 GdkInputSource source)
9125 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
9127 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
9128 GUINT_TO_POINTER (source)));
9132 do_synthesize_crossing_event (gpointer data)
9134 GdkDisplay *display;
9135 GdkWindow *changed_toplevel;
9136 GHashTableIter iter;
9137 gpointer key, value;
9140 changed_toplevel = data;
9142 changed_toplevel->synthesize_crossing_event_queued = FALSE;
9144 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9147 display = gdk_window_get_display (changed_toplevel);
9148 serial = _gdk_display_get_next_serial (display);
9149 g_hash_table_iter_init (&iter, display->pointers_info);
9151 while (g_hash_table_iter_next (&iter, &key, &value))
9153 GdkWindow *new_window_under_pointer;
9154 GdkPointerWindowInfo *pointer_info = value;
9155 GdkDevice *device = key;
9157 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9159 new_window_under_pointer =
9160 get_pointer_window (display, changed_toplevel,
9162 pointer_info->toplevel_x,
9163 pointer_info->toplevel_y,
9165 if (new_window_under_pointer != pointer_info->window_under_pointer)
9167 _gdk_synthesize_crossing_events (display,
9168 pointer_info->window_under_pointer,
9169 new_window_under_pointer,
9170 device, pointer_info->last_slave,
9171 GDK_CROSSING_NORMAL,
9172 pointer_info->toplevel_x,
9173 pointer_info->toplevel_y,
9174 pointer_info->state,
9179 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9188 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9190 GdkWindow *toplevel;
9192 toplevel = get_event_toplevel (changed_window);
9194 if (!toplevel->synthesize_crossing_event_queued)
9196 toplevel->synthesize_crossing_event_queued = TRUE;
9198 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9199 do_synthesize_crossing_event,
9200 g_object_ref (toplevel),
9205 /* Don't use for crossing events */
9207 get_event_window (GdkDisplay *display,
9209 GdkEventSequence *sequence,
9210 GdkWindow *pointer_window,
9212 GdkModifierType mask,
9214 gboolean pointer_emulated,
9217 guint evmask, emulated_mask = 0;
9218 GdkWindow *grab_window;
9219 GdkDeviceGrabInfo *grab;
9220 GdkTouchGrabInfo *touch_grab;
9222 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
9223 grab = _gdk_display_get_last_device_grab (display, device);
9225 if (is_touch_type (type) && pointer_emulated)
9229 case GDK_TOUCH_BEGIN:
9230 emulated_mask |= GDK_BUTTON_PRESS_MASK;
9232 case GDK_TOUCH_UPDATE:
9233 emulated_mask |= GDK_POINTER_MOTION_MASK;
9236 emulated_mask |= GDK_BUTTON_RELEASE_MASK;
9242 if (touch_grab != NULL &&
9243 (!grab || grab->implicit || touch_grab->serial >= grab->serial_start))
9245 evmask = touch_grab->event_mask;
9246 evmask = update_evmask_for_button_motion (evmask, mask);
9248 if (evmask & (type_masks[type] | emulated_mask))
9251 *evmask_out = evmask;
9252 return touch_grab->window;
9258 if (grab != NULL && !grab->owner_events)
9260 evmask = grab->event_mask;
9261 evmask = update_evmask_for_button_motion (evmask, mask);
9263 grab_window = grab->window;
9265 if (evmask & (type_masks[type] | emulated_mask))
9268 *evmask_out = evmask;
9275 while (pointer_window != NULL)
9277 evmask = pointer_window->event_mask;
9278 evmask = update_evmask_for_button_motion (evmask, mask);
9280 if (evmask & (type_masks[type] | emulated_mask))
9283 *evmask_out = evmask;
9284 return pointer_window;
9287 pointer_window = get_event_parent (pointer_window);
9293 evmask = grab->event_mask;
9294 evmask = update_evmask_for_button_motion (evmask, mask);
9296 if (evmask & (type_masks[type] | emulated_mask))
9299 *evmask_out = evmask;
9300 return grab->window;
9310 proxy_pointer_event (GdkDisplay *display,
9311 GdkEvent *source_event,
9314 GdkWindow *toplevel_window, *event_window;
9315 GdkWindow *pointer_window;
9316 GdkPointerWindowInfo *pointer_info;
9317 GdkDevice *device, *source_device;
9320 gdouble toplevel_x, toplevel_y;
9322 gboolean non_linear, need_synthetic_enter = FALSE;
9325 event_type = source_event->type;
9326 event_window = source_event->any.window;
9327 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9328 gdk_event_get_state (source_event, &state);
9329 time_ = gdk_event_get_time (source_event);
9330 device = gdk_event_get_device (source_event);
9331 source_device = gdk_event_get_source_device (source_event);
9332 pointer_info = _gdk_display_get_pointer_info (display, device);
9333 toplevel_window = convert_native_coords_to_toplevel (event_window,
9334 toplevel_x, toplevel_y,
9335 &toplevel_x, &toplevel_y);
9338 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9339 source_event->type == GDK_ENTER_NOTIFY) &&
9340 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9341 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9344 if (pointer_info->need_touch_press_enter &&
9345 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHSCREEN &&
9346 (source_event->type != GDK_TOUCH_UPDATE ||
9347 _gdk_event_get_pointer_emulated (source_event)))
9349 pointer_info->need_touch_press_enter = FALSE;
9350 need_synthetic_enter = TRUE;
9353 /* If we get crossing events with subwindow unexpectedly being NULL
9354 that means there is a native subwindow that gdk doesn't know about.
9355 We track these and forward them, with the correct virtual window
9357 This is important to get right, as metacity uses gdk for the frame
9358 windows, but gdk doesn't know about the client windows reparented
9360 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9361 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9362 (source_event->type == GDK_ENTER_NOTIFY &&
9363 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9364 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9365 source_event->crossing.subwindow == NULL)
9367 /* Left for an unknown (to gdk) subwindow */
9369 /* Send leave events from window under pointer to event window
9370 that will get the subwindow == NULL window */
9371 _gdk_synthesize_crossing_events (display,
9372 pointer_info->window_under_pointer,
9374 device, source_device,
9375 source_event->crossing.mode,
9376 toplevel_x, toplevel_y,
9382 /* Send subwindow == NULL event */
9383 send_crossing_event (display,
9387 source_event->crossing.mode,
9388 source_event->crossing.detail,
9390 device, source_device,
9391 toplevel_x, toplevel_y,
9396 _gdk_display_set_window_under_pointer (display, device, NULL);
9400 pointer_window = get_pointer_window (display, toplevel_window, device,
9401 toplevel_x, toplevel_y, serial);
9403 if (((source_event->type == GDK_ENTER_NOTIFY &&
9404 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9405 (source_event->type == GDK_LEAVE_NOTIFY &&
9406 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9407 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9408 source_event->crossing.subwindow == NULL)
9410 /* Entered from an unknown (to gdk) subwindow */
9412 /* Send subwindow == NULL event */
9413 send_crossing_event (display,
9417 source_event->crossing.mode,
9418 source_event->crossing.detail,
9420 device, source_device,
9421 toplevel_x, toplevel_y,
9426 /* Send enter events from event window to pointer_window */
9427 _gdk_synthesize_crossing_events (display,
9430 device, source_device,
9431 source_event->crossing.mode,
9432 toplevel_x, toplevel_y,
9435 serial, non_linear);
9436 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9440 if ((source_event->type != GDK_TOUCH_UPDATE ||
9441 _gdk_event_get_pointer_emulated (source_event)) &&
9442 pointer_info->window_under_pointer != pointer_window)
9444 /* Either a toplevel crossing notify that ended up inside a child window,
9445 or a motion notify that got into another child window */
9447 /* Different than last time, send crossing events */
9448 _gdk_synthesize_crossing_events (display,
9449 pointer_info->window_under_pointer,
9451 device, source_device,
9452 GDK_CROSSING_NORMAL,
9453 toplevel_x, toplevel_y,
9456 serial, non_linear);
9457 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9459 else if (source_event->type == GDK_MOTION_NOTIFY ||
9460 source_event->type == GDK_TOUCH_UPDATE)
9462 GdkWindow *event_win;
9465 GdkEventSequence *sequence;
9467 sequence = gdk_event_get_event_sequence (source_event);
9469 event_win = get_event_window (display,
9476 _gdk_event_get_pointer_emulated (source_event),
9479 if (event_type == GDK_TOUCH_UPDATE)
9481 if (_gdk_event_get_pointer_emulated (source_event))
9483 /* Touch events emulating pointer events are transformed back
9484 * to pointer events if:
9485 * 1 - The event window doesn't select for touch events
9486 * 2 - There's no touch grab for this sequence, which means
9487 * it was started as a pointer sequence, but a device
9488 * grab added touch events afterwards, the sequence must
9489 * not mutate in this case.
9491 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9492 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9493 event_type = GDK_MOTION_NOTIFY;
9495 else if ((evmask & GDK_TOUCH_MASK) == 0)
9499 if (is_touch_type (source_event->type) && !is_touch_type (event_type))
9500 state |= GDK_BUTTON1_MASK;
9503 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9504 gdk_window_get_device_events (event_win, device) == 0)
9507 /* The last device to interact with the window was a touch device,
9508 * which synthesized a leave notify event, so synthesize another enter
9509 * notify to tell the pointer is on the window.
9511 if (need_synthetic_enter)
9512 _gdk_synthesize_crossing_events (display,
9513 NULL, pointer_window,
9514 device, source_device,
9515 GDK_CROSSING_DEVICE_SWITCH,
9516 toplevel_x, toplevel_y,
9523 event_type == GDK_MOTION_NOTIFY &&
9524 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9526 gulong *device_serial;
9528 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9530 if (!device_serial ||
9531 (*device_serial != 0 &&
9532 serial < *device_serial))
9533 event_win = NULL; /* Ignore event */
9537 *device_serial = G_MAXULONG;
9544 event = gdk_event_new (event_type);
9545 event->any.window = g_object_ref (event_win);
9546 event->any.send_event = source_event->any.send_event;
9548 gdk_event_set_device (event, gdk_event_get_device (source_event));
9549 gdk_event_set_source_device (event, source_device);
9551 if (event_type == GDK_TOUCH_UPDATE)
9553 event->touch.time = time_;
9554 event->touch.state = state | GDK_BUTTON1_MASK;
9555 event->touch.sequence = source_event->touch.sequence;
9556 event->touch.emulating_pointer = source_event->touch.emulating_pointer;
9557 convert_toplevel_coords_to_window (event_win,
9558 toplevel_x, toplevel_y,
9559 &event->touch.x, &event->touch.y);
9560 gdk_event_get_root_coords (source_event,
9561 &event->touch.x_root,
9562 &event->touch.y_root);
9564 event->touch.axes = g_memdup (source_event->touch.axes,
9565 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9569 event->motion.time = time_;
9570 event->motion.state = state;
9571 event->motion.is_hint = is_hint;
9573 convert_toplevel_coords_to_window (event_win,
9574 toplevel_x, toplevel_y,
9575 &event->motion.x, &event->motion.y);
9576 gdk_event_get_root_coords (source_event,
9577 &event->motion.x_root,
9578 &event->motion.y_root);
9580 if (is_touch_type (source_event->type))
9581 event->motion.axes = g_memdup (source_event->touch.axes,
9582 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9584 event->motion.axes = g_memdup (source_event->motion.axes,
9585 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9588 /* Just insert the event */
9589 _gdk_event_queue_insert_after (gdk_window_get_display (event_win),
9590 source_event, event);
9593 /* unlink all move events from queue.
9594 We handle our own, including our emulated masks. */
9598 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9599 GDK_BUTTON2_MASK | \
9600 GDK_BUTTON3_MASK | \
9601 GDK_BUTTON4_MASK | \
9605 proxy_button_event (GdkEvent *source_event,
9608 GdkWindow *toplevel_window, *event_window;
9609 GdkWindow *event_win;
9610 GdkWindow *pointer_window;
9613 GdkPointerWindowInfo *pointer_info;
9614 GdkDeviceGrabInfo *pointer_grab;
9618 gdouble toplevel_x, toplevel_y;
9619 GdkDisplay *display;
9621 GdkDevice *device, *source_device;
9622 GdkEventMask evmask;
9623 GdkEventSequence *sequence;
9625 type = source_event->any.type;
9626 event_window = source_event->any.window;
9627 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9628 gdk_event_get_state (source_event, &state);
9629 time_ = gdk_event_get_time (source_event);
9630 device = gdk_event_get_device (source_event);
9631 source_device = gdk_event_get_source_device (source_event);
9632 display = gdk_window_get_display (source_event->any.window);
9633 toplevel_window = convert_native_coords_to_toplevel (event_window,
9634 toplevel_x, toplevel_y,
9635 &toplevel_x, &toplevel_y);
9637 sequence = gdk_event_get_event_sequence (source_event);
9639 pointer_info = _gdk_display_get_pointer_info (display, device);
9640 pointer_grab = _gdk_display_has_device_grab (display, device, serial);
9642 if ((type == GDK_BUTTON_PRESS ||
9643 type == GDK_TOUCH_BEGIN) &&
9644 !source_event->any.send_event &&
9646 (type == GDK_TOUCH_BEGIN && pointer_grab->implicit &&
9647 !_gdk_event_get_pointer_emulated (source_event))))
9650 _gdk_window_find_descendant_at (toplevel_window,
9651 toplevel_x, toplevel_y,
9654 /* Find the event window, that gets the grab */
9657 (parent = get_event_parent (w)) != NULL &&
9658 parent->window_type != GDK_WINDOW_ROOT)
9660 if (w->event_mask & GDK_BUTTON_PRESS_MASK &&
9661 (type == GDK_BUTTON_PRESS ||
9662 _gdk_event_get_pointer_emulated (source_event)))
9665 if (type == GDK_TOUCH_BEGIN &&
9666 w->event_mask & GDK_TOUCH_MASK)
9675 if (type == GDK_TOUCH_BEGIN &&
9676 pointer_window->event_mask & GDK_TOUCH_MASK)
9678 _gdk_display_add_touch_grab (display, device, sequence,
9679 pointer_window, event_window,
9680 gdk_window_get_events (pointer_window),
9683 else if (type == GDK_BUTTON_PRESS ||
9684 _gdk_event_get_pointer_emulated (source_event))
9686 _gdk_display_add_device_grab (display,
9692 gdk_window_get_events (pointer_window),
9696 _gdk_display_device_grab_update (display, device,
9697 source_device, serial);
9702 pointer_window = get_pointer_window (display, toplevel_window, device,
9703 toplevel_x, toplevel_y,
9706 event_win = get_event_window (display,
9712 _gdk_event_get_pointer_emulated (source_event),
9715 if (type == GDK_TOUCH_BEGIN || type == GDK_TOUCH_END)
9717 if (_gdk_event_get_pointer_emulated (source_event))
9719 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9720 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9722 if (type == GDK_TOUCH_BEGIN)
9723 type = GDK_BUTTON_PRESS;
9724 else if (type == GDK_TOUCH_END)
9725 type = GDK_BUTTON_RELEASE;
9728 else if ((evmask & GDK_TOUCH_MASK) == 0)
9732 if (source_event->type == GDK_TOUCH_END && !is_touch_type (type))
9733 state |= GDK_BUTTON1_MASK;
9735 if (event_win == NULL)
9738 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9739 gdk_window_get_device_events (event_win, device) == 0)
9742 if ((type == GDK_BUTTON_PRESS ||
9743 (type == GDK_TOUCH_BEGIN &&
9744 _gdk_event_get_pointer_emulated (source_event))) &&
9745 pointer_info->need_touch_press_enter)
9747 GdkCrossingMode mode;
9749 /* The last device to interact with the window was a touch device,
9750 * which synthesized a leave notify event, so synthesize another enter
9751 * notify to tell the pointer is on the window.
9753 if (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9754 mode = GDK_CROSSING_TOUCH_BEGIN;
9756 mode = GDK_CROSSING_DEVICE_SWITCH;
9758 pointer_info->need_touch_press_enter = FALSE;
9759 _gdk_synthesize_crossing_events (display,
9761 pointer_info->window_under_pointer,
9762 device, source_device, mode,
9763 toplevel_x, toplevel_y,
9764 state, time_, source_event,
9767 else if (type == GDK_SCROLL &&
9768 (((evmask & GDK_SMOOTH_SCROLL_MASK) == 0 &&
9769 source_event->scroll.direction == GDK_SCROLL_SMOOTH) ||
9770 ((evmask & GDK_SMOOTH_SCROLL_MASK) != 0 &&
9771 source_event->scroll.direction != GDK_SCROLL_SMOOTH &&
9772 _gdk_event_get_pointer_emulated (source_event))))
9775 event = _gdk_make_event (event_win, type, source_event, FALSE);
9779 case GDK_BUTTON_PRESS:
9780 case GDK_BUTTON_RELEASE:
9781 event->button.button = source_event->button.button;
9782 convert_toplevel_coords_to_window (event_win,
9783 toplevel_x, toplevel_y,
9784 &event->button.x, &event->button.y);
9785 gdk_event_get_root_coords (source_event,
9786 &event->button.x_root,
9787 &event->button.y_root);
9788 gdk_event_set_device (event, gdk_event_get_device (source_event));
9789 gdk_event_set_source_device (event, source_device);
9791 if (is_touch_type (source_event->type))
9793 if (type == GDK_BUTTON_RELEASE)
9794 event->button.state |= GDK_BUTTON1_MASK;
9795 event->button.button = 1;
9796 event->button.axes = g_memdup (source_event->touch.axes,
9797 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9801 event->button.button = source_event->button.button;
9802 event->button.axes = g_memdup (source_event->button.axes,
9803 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9806 if (type == GDK_BUTTON_PRESS)
9807 _gdk_event_button_generate (display, event);
9808 else if ((type == GDK_BUTTON_RELEASE ||
9809 (type == GDK_TOUCH_END &&
9810 _gdk_event_get_pointer_emulated (source_event))) &&
9811 pointer_window == pointer_info->window_under_pointer &&
9812 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9814 /* Synthesize a leave notify event
9815 * whenever a touch device is released
9817 pointer_info->need_touch_press_enter = TRUE;
9818 _gdk_synthesize_crossing_events (display,
9819 pointer_window, NULL,
9820 device, source_device,
9821 GDK_CROSSING_TOUCH_END,
9822 toplevel_x, toplevel_y,
9828 case GDK_TOUCH_BEGIN:
9830 convert_toplevel_coords_to_window (event_win,
9831 toplevel_x, toplevel_y,
9832 &event->button.x, &event->button.y);
9833 gdk_event_get_root_coords (source_event,
9834 &event->touch.x_root,
9835 &event->touch.y_root);
9836 event->touch.state = state;
9837 event->touch.device = source_event->touch.device;
9838 event->touch.axes = g_memdup (source_event->touch.axes,
9839 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9840 event->touch.sequence = source_event->touch.sequence;
9841 event->touch.emulating_pointer = source_event->touch.emulating_pointer;
9843 gdk_event_set_source_device (event, source_device);
9845 if ((type == GDK_TOUCH_END &&
9846 _gdk_event_get_pointer_emulated (source_event)) &&
9847 pointer_window == pointer_info->window_under_pointer &&
9848 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9850 /* Synthesize a leave notify event
9851 * whenever a touch device is released
9853 pointer_info->need_touch_press_enter = TRUE;
9854 _gdk_synthesize_crossing_events (display,
9855 pointer_window, NULL,
9856 device, source_device,
9857 GDK_CROSSING_TOUCH_END,
9858 toplevel_x, toplevel_y,
9865 event->scroll.direction = source_event->scroll.direction;
9866 convert_toplevel_coords_to_window (event_win,
9867 toplevel_x, toplevel_y,
9868 &event->scroll.x, &event->scroll.y);
9869 event->scroll.x_root = source_event->scroll.x_root;
9870 event->scroll.y_root = source_event->scroll.y_root;
9871 event->scroll.state = state;
9872 event->scroll.device = source_event->scroll.device;
9873 event->scroll.delta_x = source_event->scroll.delta_x;
9874 event->scroll.delta_y = source_event->scroll.delta_y;
9875 gdk_event_set_source_device (event, source_device);
9882 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9885 #ifdef DEBUG_WINDOW_PRINTING
9887 #ifdef GDK_WINDOWING_X11
9888 #include "x11/gdkx.h"
9892 gdk_window_print (GdkWindow *window,
9896 const char *window_types[] = {
9906 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9907 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9908 window->x, window->y,
9909 window->width, window->height
9912 if (gdk_window_has_impl (window))
9914 #ifdef GDK_WINDOWING_X11
9915 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9919 if (window->window_type != GDK_WINDOW_CHILD)
9920 g_print (" %s", window_types[window->window_type]);
9922 if (window->input_only)
9923 g_print (" input-only");
9926 g_print (" shaped");
9928 if (!gdk_window_is_visible ((GdkWindow *)window))
9929 g_print (" hidden");
9931 g_print (" abs[%d,%d]",
9932 window->abs_x, window->abs_y);
9934 s = print_region (window->clip_region);
9935 g_print (" clipbox[%s]", s);
9942 gdk_window_print_tree (GdkWindow *window,
9944 gboolean include_input_only)
9948 if (window->input_only && !include_input_only)
9951 gdk_window_print (window, indent);
9953 for (l = window->children; l != NULL; l = l->next)
9954 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9957 #endif /* DEBUG_WINDOW_PRINTING */
9960 _gdk_windowing_got_event (GdkDisplay *display,
9965 GdkWindow *event_window;
9967 gboolean unlink_event;
9968 GdkDeviceGrabInfo *button_release_grab;
9969 GdkPointerWindowInfo *pointer_info = NULL;
9970 GdkDevice *device, *source_device;
9971 gboolean is_toplevel;
9973 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9974 display->last_event_time = gdk_event_get_time (event);
9976 device = gdk_event_get_device (event);
9977 source_device = gdk_event_get_source_device (event);
9983 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
9985 pointer_info = _gdk_display_get_pointer_info (display, device);
9987 if (source_device != pointer_info->last_slave &&
9988 gdk_device_get_device_type (source_device) == GDK_DEVICE_TYPE_SLAVE)
9989 pointer_info->last_slave = source_device;
9990 else if (pointer_info->last_slave)
9991 source_device = pointer_info->last_slave;
9994 g_object_get (device, "input-mode", &mode, NULL);
9995 _gdk_display_device_grab_update (display, device, source_device, serial);
9997 if (mode == GDK_MODE_DISABLED ||
9998 !_gdk_display_check_grab_ownership (display, device, serial))
10000 /* Device events are blocked by another
10001 * device grab, or the device is disabled
10003 unlink_event = TRUE;
10008 event_window = event->any.window;
10012 #ifdef DEBUG_WINDOW_PRINTING
10013 if (event->type == GDK_KEY_PRESS &&
10014 (event->key.keyval == 0xa7 ||
10015 event->key.keyval == 0xbd))
10017 gdk_window_print_tree (event_window, 0, event->key.keyval == 0xbd);
10021 if (event->type == GDK_VISIBILITY_NOTIFY)
10023 event_window->native_visibility = event->visibility.state;
10024 gdk_window_update_visibility_recursively (event_window, event_window);
10028 if (!(is_button_type (event->type) ||
10029 is_motion_type (event->type)) ||
10030 event_window->window_type == GDK_WINDOW_ROOT)
10033 is_toplevel = gdk_window_is_toplevel (event_window);
10035 if ((event->type == GDK_ENTER_NOTIFY ||
10036 event->type == GDK_LEAVE_NOTIFY) &&
10037 (event->crossing.mode == GDK_CROSSING_GRAB ||
10038 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
10039 (_gdk_display_has_device_grab (display, device, serial) ||
10040 event->crossing.detail == GDK_NOTIFY_INFERIOR))
10042 /* We synthesize all crossing events due to grabs ourselves,
10043 * so we ignore the native ones caused by our native pointer_grab
10044 * calls. Otherwise we would proxy these crossing event and cause
10045 * multiple copies of crossing events for grabs.
10047 * We do want to handle grabs from other clients though, as for
10048 * instance alt-tab in metacity causes grabs like these and
10049 * we want to handle those. Thus the has_pointer_grab check.
10051 * Implicit grabs on child windows create some grabbing events
10052 * that are sent before the button press. This means we can't
10053 * detect these with the has_pointer_grab check (as the implicit
10054 * grab is only noticed when we get button press event), so we
10055 * detect these events by checking for INFERIOR enter or leave
10056 * events. These should never be a problem to filter out.
10059 /* We ended up in this window after some (perhaps other clients)
10060 * grab, so update the toplevel_under_window state
10063 event->type == GDK_ENTER_NOTIFY &&
10064 event->crossing.mode == GDK_CROSSING_UNGRAB)
10066 if (pointer_info->toplevel_under_pointer)
10067 g_object_unref (pointer_info->toplevel_under_pointer);
10068 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
10071 unlink_event = TRUE;
10075 /* Track toplevel_under_pointer */
10078 if (event->type == GDK_ENTER_NOTIFY &&
10079 event->crossing.detail != GDK_NOTIFY_INFERIOR)
10081 if (pointer_info->toplevel_under_pointer)
10082 g_object_unref (pointer_info->toplevel_under_pointer);
10083 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
10085 else if (event->type == GDK_LEAVE_NOTIFY &&
10086 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
10087 pointer_info->toplevel_under_pointer == event_window)
10089 if (pointer_info->toplevel_under_pointer)
10090 g_object_unref (pointer_info->toplevel_under_pointer);
10091 pointer_info->toplevel_under_pointer = NULL;
10095 if (pointer_info &&
10096 (!is_touch_type (event->type) ||
10097 _gdk_event_get_pointer_emulated (event)))
10099 guint old_state, old_button;
10101 /* Store last pointer window and position/state */
10102 old_state = pointer_info->state;
10103 old_button = pointer_info->button;
10105 gdk_event_get_coords (event, &x, &y);
10106 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
10107 pointer_info->toplevel_x = x;
10108 pointer_info->toplevel_y = y;
10109 gdk_event_get_state (event, &pointer_info->state);
10111 if (event->type == GDK_BUTTON_PRESS ||
10112 event->type == GDK_BUTTON_RELEASE)
10113 pointer_info->button = event->button.button;
10114 else if (event->type == GDK_TOUCH_BEGIN ||
10115 event->type == GDK_TOUCH_END)
10116 pointer_info->button = 1;
10119 (pointer_info->state != old_state ||
10120 pointer_info->button != old_button))
10121 _gdk_display_enable_motion_hints (display, device);
10124 unlink_event = FALSE;
10125 if (is_motion_type (event->type))
10126 unlink_event = proxy_pointer_event (display, event, serial);
10127 else if (is_button_type (event->type))
10128 unlink_event = proxy_button_event (event, serial);
10130 if ((event->type == GDK_BUTTON_RELEASE ||
10131 event->type == GDK_TOUCH_END) &&
10132 !event->any.send_event)
10134 GdkEventSequence *sequence;
10136 sequence = gdk_event_get_event_sequence (event);
10137 if (event->type == GDK_TOUCH_END && sequence)
10139 _gdk_display_end_touch_grab (display, device, sequence);
10142 if (event->type == GDK_BUTTON_RELEASE ||
10143 _gdk_event_get_pointer_emulated (event))
10145 button_release_grab =
10146 _gdk_display_has_device_grab (display, device, serial);
10148 if (button_release_grab &&
10149 button_release_grab->implicit &&
10150 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
10152 button_release_grab->serial_end = serial;
10153 button_release_grab->implicit_ungrab = FALSE;
10154 _gdk_display_device_grab_update (display, device, source_device, serial);
10162 _gdk_event_queue_remove_link (display, event_link);
10163 g_list_free_1 (event_link);
10164 gdk_event_free (event);
10169 * gdk_window_create_similar_surface:
10170 * @window: window to make new surface similar to
10171 * @content: the content for the new surface
10172 * @width: width of the new surface
10173 * @height: height of the new surface
10175 * Create a new surface that is as compatible as possible with the
10176 * given @window. For example the new surface will have the same
10177 * fallback resolution and font options as @window. Generally, the new
10178 * surface will also use the same backend as @window, unless that is
10179 * not possible for some reason. The type of the returned surface may
10180 * be examined with cairo_surface_get_type().
10182 * Initially the surface contents are all 0 (transparent if contents
10183 * have transparency, black otherwise.)
10185 * Returns: a pointer to the newly allocated surface. The caller
10186 * owns the surface and should call cairo_surface_destroy() when done
10189 * This function always returns a valid pointer, but it will return a
10190 * pointer to a "nil" surface if @other is already in an error state
10191 * or any other error occurs.
10196 gdk_window_create_similar_surface (GdkWindow * window,
10197 cairo_content_t content,
10201 cairo_surface_t *window_surface, *surface;
10203 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
10205 window_surface = gdk_window_ref_impl_surface (window);
10207 switch (_gdk_rendering_mode)
10209 case GDK_RENDERING_MODE_RECORDING:
10211 cairo_rectangle_t rect = { 0, 0, width, height };
10212 surface = cairo_recording_surface_create (content, &rect);
10215 case GDK_RENDERING_MODE_IMAGE:
10216 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
10217 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
10220 case GDK_RENDERING_MODE_SIMILAR:
10222 surface = cairo_surface_create_similar (window_surface,
10228 cairo_surface_destroy (window_surface);
10234 * gdk_window_focus:
10235 * @window: a #GdkWindow
10236 * @timestamp: timestamp of the event triggering the window focus
10238 * Sets keyboard focus to @window. In most cases, gtk_window_present()
10239 * should be used on a #GtkWindow, rather than calling this function.
10243 gdk_window_focus (GdkWindow *window,
10246 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
10250 * gdk_window_set_type_hint:
10251 * @window: A toplevel #GdkWindow
10252 * @hint: A hint of the function this window will have
10254 * The application can use this call to provide a hint to the window
10255 * manager about the functionality of a window. The window manager
10256 * can use this information when determining the decoration and behaviour
10259 * The hint must be set before the window is mapped.
10262 gdk_window_set_type_hint (GdkWindow *window,
10263 GdkWindowTypeHint hint)
10265 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
10269 * gdk_window_get_type_hint:
10270 * @window: A toplevel #GdkWindow
10272 * This function returns the type hint set for a window.
10274 * Return value: The type hint set for @window
10279 gdk_window_get_type_hint (GdkWindow *window)
10281 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
10285 * gdk_window_set_modal_hint:
10286 * @window: A toplevel #GdkWindow
10287 * @modal: %TRUE if the window is modal, %FALSE otherwise.
10289 * The application can use this hint to tell the window manager
10290 * that a certain window has modal behaviour. The window manager
10291 * can use this information to handle modal windows in a special
10294 * You should only use this on windows for which you have
10295 * previously called gdk_window_set_transient_for()
10298 gdk_window_set_modal_hint (GdkWindow *window,
10301 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
10305 * gdk_window_set_skip_taskbar_hint:
10306 * @window: a toplevel #GdkWindow
10307 * @skips_taskbar: %TRUE to skip the taskbar
10309 * Toggles whether a window should appear in a task list or window
10310 * list. If a window's semantic type as specified with
10311 * gdk_window_set_type_hint() already fully describes the window, this
10312 * function should <emphasis>not</emphasis> be called in addition,
10313 * instead you should allow the window to be treated according to
10314 * standard policy for its semantic type.
10319 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
10320 gboolean skips_taskbar)
10322 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
10326 * gdk_window_set_skip_pager_hint:
10327 * @window: a toplevel #GdkWindow
10328 * @skips_pager: %TRUE to skip the pager
10330 * Toggles whether a window should appear in a pager (workspace
10331 * switcher, or other desktop utility program that displays a small
10332 * thumbnail representation of the windows on the desktop). If a
10333 * window's semantic type as specified with gdk_window_set_type_hint()
10334 * already fully describes the window, this function should
10335 * <emphasis>not</emphasis> be called in addition, instead you should
10336 * allow the window to be treated according to standard policy for
10337 * its semantic type.
10342 gdk_window_set_skip_pager_hint (GdkWindow *window,
10343 gboolean skips_pager)
10345 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
10349 * gdk_window_set_urgency_hint:
10350 * @window: a toplevel #GdkWindow
10351 * @urgent: %TRUE if the window is urgent
10353 * Toggles whether a window needs the user's
10354 * urgent attention.
10359 gdk_window_set_urgency_hint (GdkWindow *window,
10362 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
10366 * gdk_window_set_geometry_hints:
10367 * @window: a toplevel #GdkWindow
10368 * @geometry: geometry hints
10369 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
10371 * Sets the geometry hints for @window. Hints flagged in @geom_mask
10372 * are set, hints not flagged in @geom_mask are unset.
10373 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
10375 * This function provides hints to the windowing system about
10376 * acceptable sizes for a toplevel window. The purpose of
10377 * this is to constrain user resizing, but the windowing system
10378 * will typically (but is not required to) also constrain the
10379 * current size of the window to the provided values and
10380 * constrain programatic resizing via gdk_window_resize() or
10381 * gdk_window_move_resize().
10383 * Note that on X11, this effect has no effect on windows
10384 * of type %GDK_WINDOW_TEMP or windows where override redirect
10385 * has been turned on via gdk_window_set_override_redirect()
10386 * since these windows are not resizable by the user.
10388 * Since you can't count on the windowing system doing the
10389 * constraints for programmatic resizes, you should generally
10390 * call gdk_window_constrain_size() yourself to determine
10391 * appropriate sizes.
10395 gdk_window_set_geometry_hints (GdkWindow *window,
10396 const GdkGeometry *geometry,
10397 GdkWindowHints geom_mask)
10399 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
10403 * gdk_window_set_title:
10404 * @window: a toplevel #GdkWindow
10405 * @title: title of @window
10407 * Sets the title of a toplevel window, to be displayed in the titlebar.
10408 * If you haven't explicitly set the icon name for the window
10409 * (using gdk_window_set_icon_name()), the icon name will be set to
10410 * @title as well. @title must be in UTF-8 encoding (as with all
10411 * user-readable strings in GDK/GTK+). @title may not be %NULL.
10414 gdk_window_set_title (GdkWindow *window,
10415 const gchar *title)
10417 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
10421 * gdk_window_set_role:
10422 * @window: a toplevel #GdkWindow
10423 * @role: a string indicating its role
10425 * When using GTK+, typically you should use gtk_window_set_role() instead
10426 * of this low-level function.
10428 * The window manager and session manager use a window's role to
10429 * distinguish it from other kinds of window in the same application.
10430 * When an application is restarted after being saved in a previous
10431 * session, all windows with the same title and role are treated as
10432 * interchangeable. So if you have two windows with the same title
10433 * that should be distinguished for session management purposes, you
10434 * should set the role on those windows. It doesn't matter what string
10435 * you use for the role, as long as you have a different role for each
10436 * non-interchangeable kind of window.
10440 gdk_window_set_role (GdkWindow *window,
10443 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
10447 * gdk_window_set_startup_id:
10448 * @window: a toplevel #GdkWindow
10449 * @startup_id: a string with startup-notification identifier
10451 * When using GTK+, typically you should use gtk_window_set_startup_id()
10452 * instead of this low-level function.
10458 gdk_window_set_startup_id (GdkWindow *window,
10459 const gchar *startup_id)
10461 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
10465 * gdk_window_set_transient_for:
10466 * @window: a toplevel #GdkWindow
10467 * @parent: another toplevel #GdkWindow
10469 * Indicates to the window manager that @window is a transient dialog
10470 * associated with the application window @parent. This allows the
10471 * window manager to do things like center @window on @parent and
10472 * keep @window above @parent.
10474 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10478 gdk_window_set_transient_for (GdkWindow *window,
10481 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10485 * gdk_window_get_root_origin:
10486 * @window: a toplevel #GdkWindow
10487 * @x: (out): return location for X position of window frame
10488 * @y: (out): return location for Y position of window frame
10490 * Obtains the top-left corner of the window manager frame in root
10491 * window coordinates.
10495 gdk_window_get_root_origin (GdkWindow *window,
10499 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10503 * gdk_window_get_frame_extents:
10504 * @window: a toplevel #GdkWindow
10505 * @rect: (out): rectangle to fill with bounding box of the window frame
10507 * Obtains the bounding box of the window, including window manager
10508 * titlebar/borders if any. The frame position is given in root window
10509 * coordinates. To get the position of the window itself (rather than
10510 * the frame) in root window coordinates, use gdk_window_get_origin().
10514 gdk_window_get_frame_extents (GdkWindow *window,
10515 GdkRectangle *rect)
10517 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10521 * gdk_window_set_override_redirect:
10522 * @window: a toplevel #GdkWindow
10523 * @override_redirect: %TRUE if window should be override redirect
10525 * An override redirect window is not under the control of the window manager.
10526 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10527 * be entirely under the control of the application. The window manager
10528 * can't see the override redirect window at all.
10530 * Override redirect should only be used for short-lived temporary
10531 * windows, such as popup menus. #GtkMenu uses an override redirect
10532 * window in its implementation, for example.
10536 gdk_window_set_override_redirect (GdkWindow *window,
10537 gboolean override_redirect)
10539 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10543 * gdk_window_set_accept_focus:
10544 * @window: a toplevel #GdkWindow
10545 * @accept_focus: %TRUE if the window should receive input focus
10547 * Setting @accept_focus to %FALSE hints the desktop environment that the
10548 * window doesn't want to receive input focus.
10550 * On X, it is the responsibility of the window manager to interpret this
10551 * hint. ICCCM-compliant window manager usually respect it.
10556 gdk_window_set_accept_focus (GdkWindow *window,
10557 gboolean accept_focus)
10559 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10563 * gdk_window_set_focus_on_map:
10564 * @window: a toplevel #GdkWindow
10565 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10567 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10568 * window doesn't want to receive input focus when it is mapped.
10569 * focus_on_map should be turned off for windows that aren't triggered
10570 * interactively (such as popups from network activity).
10572 * On X, it is the responsibility of the window manager to interpret
10573 * this hint. Window managers following the freedesktop.org window
10574 * manager extension specification should respect it.
10579 gdk_window_set_focus_on_map (GdkWindow *window,
10580 gboolean focus_on_map)
10582 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10586 * gdk_window_set_icon_list:
10587 * @window: The #GdkWindow toplevel window to set the icon of.
10588 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10589 * A list of pixbufs, of different sizes.
10591 * Sets a list of icons for the window. One of these will be used
10592 * to represent the window when it has been iconified. The icon is
10593 * usually shown in an icon box or some sort of task bar. Which icon
10594 * size is shown depends on the window manager. The window manager
10595 * can scale the icon but setting several size icons can give better
10596 * image quality since the window manager may only need to scale the
10597 * icon by a small amount or not at all.
10601 gdk_window_set_icon_list (GdkWindow *window,
10604 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10608 * gdk_window_set_icon_name:
10609 * @window: a toplevel #GdkWindow
10610 * @name: (allow-none): name of window while iconified (minimized)
10612 * Windows may have a name used while minimized, distinct from the
10613 * name they display in their titlebar. Most of the time this is a bad
10614 * idea from a user interface standpoint. But you can set such a name
10615 * with this function, if you like.
10617 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10618 * will not update the icon title.
10620 * Using %NULL for @name unsets the icon title; further calls to
10621 * gdk_window_set_title() will again update the icon title as well.
10624 gdk_window_set_icon_name (GdkWindow *window,
10627 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10631 * gdk_window_iconify:
10632 * @window: a toplevel #GdkWindow
10634 * Asks to iconify (minimize) @window. The window manager may choose
10635 * to ignore the request, but normally will honor it. Using
10636 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10638 * This function only makes sense when @window is a toplevel window.
10642 gdk_window_iconify (GdkWindow *window)
10644 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10648 * gdk_window_deiconify:
10649 * @window: a toplevel #GdkWindow
10651 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10652 * choose to ignore the request to deiconify. When using GTK+,
10653 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10654 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10655 * unminimizes it, and puts it on the current desktop.
10659 gdk_window_deiconify (GdkWindow *window)
10661 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10665 * gdk_window_stick:
10666 * @window: a toplevel #GdkWindow
10668 * "Pins" a window such that it's on all workspaces and does not scroll
10669 * with viewports, for window managers that have scrollable viewports.
10670 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10672 * On the X11 platform, this function depends on window manager
10673 * support, so may have no effect with many window managers. However,
10674 * GDK will do the best it can to convince the window manager to stick
10675 * the window. For window managers that don't support this operation,
10676 * there's nothing you can do to force it to happen.
10680 gdk_window_stick (GdkWindow *window)
10682 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10686 * gdk_window_unstick:
10687 * @window: a toplevel #GdkWindow
10689 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10690 * and gtk_window_unstick().
10694 gdk_window_unstick (GdkWindow *window)
10696 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10700 * gdk_window_maximize:
10701 * @window: a toplevel #GdkWindow
10703 * Maximizes the window. If the window was already maximized, then
10704 * this function does nothing.
10706 * On X11, asks the window manager to maximize @window, if the window
10707 * manager supports this operation. Not all window managers support
10708 * this, and some deliberately ignore it or don't have a concept of
10709 * "maximized"; so you can't rely on the maximization actually
10710 * happening. But it will happen with most standard window managers,
10711 * and GDK makes a best effort to get it to happen.
10713 * On Windows, reliably maximizes the window.
10717 gdk_window_maximize (GdkWindow *window)
10719 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10723 * gdk_window_unmaximize:
10724 * @window: a toplevel #GdkWindow
10726 * Unmaximizes the window. If the window wasn't maximized, then this
10727 * function does nothing.
10729 * On X11, asks the window manager to unmaximize @window, if the
10730 * window manager supports this operation. Not all window managers
10731 * support this, and some deliberately ignore it or don't have a
10732 * concept of "maximized"; so you can't rely on the unmaximization
10733 * actually happening. But it will happen with most standard window
10734 * managers, and GDK makes a best effort to get it to happen.
10736 * On Windows, reliably unmaximizes the window.
10740 gdk_window_unmaximize (GdkWindow *window)
10742 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10746 * gdk_window_fullscreen:
10747 * @window: a toplevel #GdkWindow
10749 * Moves the window into fullscreen mode. This means the
10750 * window covers the entire screen and is above any panels
10753 * If the window was already fullscreen, then this function does nothing.
10755 * On X11, asks the window manager to put @window in a fullscreen
10756 * state, if the window manager supports this operation. Not all
10757 * window managers support this, and some deliberately ignore it or
10758 * don't have a concept of "fullscreen"; so you can't rely on the
10759 * fullscreenification actually happening. But it will happen with
10760 * most standard window managers, and GDK makes a best effort to get
10766 gdk_window_fullscreen (GdkWindow *window)
10768 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10772 * gdk_window_set_fullscreen_mode:
10773 * @window: a toplevel #GdkWindow
10774 * @mode: fullscreen mode
10776 * Specifies whether the @window should span over all monitors (in a multi-head
10777 * setup) or only the current monitor when in fullscreen mode.
10779 * The @mode argument is from the #GdkFullscreenMode enumeration.
10780 * If #GDK_FULLSCREEN_ON_ALL_MONITORS is specified, the fullscreen @window will
10781 * span over all monitors from the #GdkScreen.
10783 * On X11, searches through the list of monitors from the #GdkScreen the ones
10784 * which delimit the 4 edges of the entire #GdkScreen and will ask the window
10785 * manager to span the @window over these monitors.
10787 * If the XINERAMA extension is not available or not usable, this function
10790 * Not all window managers support this, so you can't rely on the fullscreen
10791 * window to span over the multiple monitors when #GDK_FULLSCREEN_ON_ALL_MONITORS
10797 gdk_window_set_fullscreen_mode (GdkWindow *window,
10798 GdkFullscreenMode mode)
10800 GdkWindowImplClass *impl_class;
10802 g_return_if_fail (GDK_IS_WINDOW (window));
10804 if (window->fullscreen_mode != mode)
10806 window->fullscreen_mode = mode;
10808 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
10809 if (impl_class->apply_fullscreen_mode != NULL)
10810 impl_class->apply_fullscreen_mode (window);
10815 * gdk_window_get_fullscreen_mode:
10816 * @window: a toplevel #GdkWindow
10818 * Obtains the #GdkFullscreenMode of the @window.
10820 * Returns: The #GdkFullscreenMode applied to the window when fullscreen.
10825 gdk_window_get_fullscreen_mode (GdkWindow *window)
10827 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_FULLSCREEN_ON_CURRENT_MONITOR);
10829 return window->fullscreen_mode;
10833 * gdk_window_unfullscreen:
10834 * @window: a toplevel #GdkWindow
10836 * Moves the window out of fullscreen mode. If the window was not
10837 * fullscreen, does nothing.
10839 * On X11, asks the window manager to move @window out of the fullscreen
10840 * state, if the window manager supports this operation. Not all
10841 * window managers support this, and some deliberately ignore it or
10842 * don't have a concept of "fullscreen"; so you can't rely on the
10843 * unfullscreenification actually happening. But it will happen with
10844 * most standard window managers, and GDK makes a best effort to get
10850 gdk_window_unfullscreen (GdkWindow *window)
10852 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10856 * gdk_window_set_keep_above:
10857 * @window: a toplevel #GdkWindow
10858 * @setting: whether to keep @window above other windows
10860 * Set if @window must be kept above other windows. If the
10861 * window was already above, then this function does nothing.
10863 * On X11, asks the window manager to keep @window above, if the window
10864 * manager supports this operation. Not all window managers support
10865 * this, and some deliberately ignore it or don't have a concept of
10866 * "keep above"; so you can't rely on the window being kept above.
10867 * But it will happen with most standard window managers,
10868 * and GDK makes a best effort to get it to happen.
10873 gdk_window_set_keep_above (GdkWindow *window,
10876 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10880 * gdk_window_set_keep_below:
10881 * @window: a toplevel #GdkWindow
10882 * @setting: whether to keep @window below other windows
10884 * Set if @window must be kept below other windows. If the
10885 * window was already below, then this function does nothing.
10887 * On X11, asks the window manager to keep @window below, if the window
10888 * manager supports this operation. Not all window managers support
10889 * this, and some deliberately ignore it or don't have a concept of
10890 * "keep below"; so you can't rely on the window being kept below.
10891 * But it will happen with most standard window managers,
10892 * and GDK makes a best effort to get it to happen.
10897 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10899 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10903 * gdk_window_get_group:
10904 * @window: a toplevel #GdkWindow
10906 * Returns the group leader window for @window. See gdk_window_set_group().
10908 * Return value: (transfer none): the group leader window for @window
10913 gdk_window_get_group (GdkWindow *window)
10915 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10919 * gdk_window_set_group:
10920 * @window: a toplevel #GdkWindow
10921 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10923 * Sets the group leader window for @window. By default,
10924 * GDK sets the group leader for all toplevel windows
10925 * to a global window implicitly created by GDK. With this function
10926 * you can override this default.
10928 * The group leader window allows the window manager to distinguish
10929 * all windows that belong to a single application. It may for example
10930 * allow users to minimize/unminimize all windows belonging to an
10931 * application at once. You should only set a non-default group window
10932 * if your application pretends to be multiple applications.
10935 gdk_window_set_group (GdkWindow *window,
10938 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10942 * gdk_window_set_decorations:
10943 * @window: a toplevel #GdkWindow
10944 * @decorations: decoration hint mask
10946 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10947 * This function sets the traditional Motif window manager hints that tell the
10948 * window manager which decorations you would like your window to have.
10949 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10950 * using the GDK function directly.
10952 * The @decorations argument is the logical OR of the fields in
10953 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10954 * mask, the other bits indicate which decorations should be turned off.
10955 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10956 * which decorations should be turned on.
10958 * Most window managers honor a decorations hint of 0 to disable all decorations,
10959 * but very few honor all possible combinations of bits.
10963 gdk_window_set_decorations (GdkWindow *window,
10964 GdkWMDecoration decorations)
10966 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10970 * gdk_window_get_decorations:
10971 * @window: The toplevel #GdkWindow to get the decorations from
10972 * @decorations: (out): The window decorations will be written here
10974 * Returns the decorations set on the GdkWindow with
10975 * gdk_window_set_decorations().
10977 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10980 gdk_window_get_decorations(GdkWindow *window,
10981 GdkWMDecoration *decorations)
10983 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10987 * gdk_window_set_functions:
10988 * @window: a toplevel #GdkWindow
10989 * @functions: bitmask of operations to allow on @window
10991 * Sets hints about the window management functions to make available
10992 * via buttons on the window frame.
10994 * On the X backend, this function sets the traditional Motif window
10995 * manager hint for this purpose. However, few window managers do
10996 * anything reliable or interesting with this hint. Many ignore it
10999 * The @functions argument is the logical OR of values from the
11000 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
11001 * then the other bits indicate which functions to disable; if
11002 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
11007 gdk_window_set_functions (GdkWindow *window,
11008 GdkWMFunction functions)
11010 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
11014 * gdk_window_begin_resize_drag_for_device:
11015 * @window: a toplevel #GdkWindow
11016 * @edge: the edge or corner from which the drag is started
11017 * @device: the device used for the operation
11018 * @button: the button being used to drag
11019 * @root_x: root window X coordinate of mouse click that began the drag
11020 * @root_y: root window Y coordinate of mouse click that began the drag
11021 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
11023 * Begins a window resize operation (for a toplevel window).
11024 * You might use this function to implement a "window resize grip," for
11025 * example; in fact #GtkStatusbar uses it. The function works best
11026 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
11027 * fallback implementation for other window managers.
11032 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
11033 GdkWindowEdge edge,
11040 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
11044 * gdk_window_begin_resize_drag:
11045 * @window: a toplevel #GdkWindow
11046 * @edge: the edge or corner from which the drag is started
11047 * @button: the button being used to drag
11048 * @root_x: root window X coordinate of mouse click that began the drag
11049 * @root_y: root window Y coordinate of mouse click that began the drag
11050 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
11052 * Begins a window resize operation (for a toplevel window).
11054 * This function assumes that the drag is controlled by the
11055 * client pointer device, use gdk_window_begin_resize_drag_for_device()
11056 * to begin a drag with a different device.
11059 gdk_window_begin_resize_drag (GdkWindow *window,
11060 GdkWindowEdge edge,
11066 GdkDeviceManager *device_manager;
11069 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11070 device = gdk_device_manager_get_client_pointer (device_manager);
11071 gdk_window_begin_resize_drag_for_device (window, edge,
11072 device, button, root_x, root_y, timestamp);
11076 * gdk_window_begin_move_drag_for_device:
11077 * @window: a toplevel #GdkWindow
11078 * @device: the device used for the operation
11079 * @button: the button being used to drag
11080 * @root_x: root window X coordinate of mouse click that began the drag
11081 * @root_y: root window Y coordinate of mouse click that began the drag
11082 * @timestamp: timestamp of mouse click that began the drag
11084 * Begins a window move operation (for a toplevel window).
11085 * You might use this function to implement a "window move grip," for
11086 * example. The function works best with window managers that support
11087 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
11088 * Window Manager Hints</ulink>, but has a fallback implementation for
11089 * other window managers.
11094 gdk_window_begin_move_drag_for_device (GdkWindow *window,
11101 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
11102 device, button, root_x, root_y, timestamp);
11106 * gdk_window_begin_move_drag:
11107 * @window: a toplevel #GdkWindow
11108 * @button: the button being used to drag
11109 * @root_x: root window X coordinate of mouse click that began the drag
11110 * @root_y: root window Y coordinate of mouse click that began the drag
11111 * @timestamp: timestamp of mouse click that began the drag
11113 * Begins a window move operation (for a toplevel window).
11115 * This function assumes that the drag is controlled by the
11116 * client pointer device, use gdk_window_begin_move_drag_for_device()
11117 * to begin a drag with a different device.
11120 gdk_window_begin_move_drag (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);
11131 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
11135 * gdk_window_enable_synchronized_configure:
11136 * @window: a toplevel #GdkWindow
11138 * Indicates that the application will cooperate with the window
11139 * system in synchronizing the window repaint with the window
11140 * manager during resizing operations. After an application calls
11141 * this function, it must call gdk_window_configure_finished() every
11142 * time it has finished all processing associated with a set of
11143 * Configure events. Toplevel GTK+ windows automatically use this
11146 * On X, calling this function makes @window participate in the
11147 * _NET_WM_SYNC_REQUEST window manager protocol.
11152 gdk_window_enable_synchronized_configure (GdkWindow *window)
11154 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
11158 * gdk_window_configure_finished:
11159 * @window: a toplevel #GdkWindow
11161 * Signal to the window system that the application has finished
11162 * handling Configure events it has received. Window Managers can
11163 * use this to better synchronize the frame repaint with the
11164 * application. GTK+ applications will automatically call this
11165 * function when appropriate.
11167 * This function can only be called if gdk_window_enable_synchronized_configure()
11168 * was called previously.
11173 gdk_window_configure_finished (GdkWindow *window)
11175 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
11179 * gdk_window_set_opacity:
11180 * @window: a top-level or non-native #GdkWindow
11181 * @opacity: opacity
11183 * Set @window to render as partially transparent,
11184 * with opacity 0 being fully transparent and 1 fully opaque. (Values
11185 * of the opacity parameter are clamped to the [0,1] range.)
11187 * For toplevel windows this depends on support from the windowing system
11188 * that may not always be there. For instance, On X11, this works only on
11189 * X screens with a compositing manager running.
11191 * For child windows this function only works for non-native windows.
11193 * For setting up per-pixel alpha topelevels, see gdk_screen_get_rgba_visual(),
11194 * and for non-toplevels, see gdk_window_set_composited().
11196 * Support for non-toplevel windows was added in 3.8.
11201 gdk_window_set_opacity (GdkWindow *window,
11206 else if (opacity > 1)
11209 window->alpha = round (opacity * 255);
11211 if (window->destroyed)
11214 if (gdk_window_has_impl (window))
11215 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
11218 recompute_visible_regions (window, TRUE, FALSE);
11219 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
11223 /* This function is called when the XWindow is really gone.
11226 gdk_window_destroy_notify (GdkWindow *window)
11228 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
11232 * gdk_window_register_dnd:
11233 * @window: a #GdkWindow.
11235 * Registers a window as a potential drop destination.
11238 gdk_window_register_dnd (GdkWindow *window)
11240 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
11244 * gdk_window_get_drag_protocol:
11245 * @window: the destination window
11246 * @target: (out) (allow-none) (transfer full): location of the window
11247 * where the drop should happen. This may be @window or a proxy window,
11248 * or %NULL if @window does not support Drag and Drop.
11250 * Finds out the DND protocol supported by a window.
11252 * Returns: the supported DND protocol.
11257 gdk_window_get_drag_protocol (GdkWindow *window,
11258 GdkWindow **target)
11260 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
11262 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
11267 * @window: the source window for this drag.
11268 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11269 * as list of #GdkAtoms
11271 * Starts a drag and creates a new drag context for it.
11272 * This function assumes that the drag is controlled by the
11273 * client pointer device, use gdk_drag_begin_for_device() to
11274 * begin a drag with a different device.
11276 * This function is called by the drag source.
11278 * Return value: (transfer full): a newly created #GdkDragContext
11281 gdk_drag_begin (GdkWindow *window,
11284 GdkDeviceManager *device_manager;
11287 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11288 device = gdk_device_manager_get_client_pointer (device_manager);
11290 return gdk_drag_begin_for_device (window, device, targets);
11294 * gdk_drag_begin_for_device:
11295 * @window: the source window for this drag
11296 * @device: the device that controls this drag
11297 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11298 * as list of #GdkAtoms
11300 * Starts a drag and creates a new drag context for it.
11302 * This function is called by the drag source.
11304 * Return value: (transfer full): a newly created #GdkDragContext
11307 gdk_drag_begin_for_device (GdkWindow *window,
11311 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
11315 * gdk_test_render_sync:
11316 * @window: a mapped #GdkWindow
11318 * Retrieves a pixel from @window to force the windowing
11319 * system to carry out any pending rendering commands.
11321 * This function is intended to be used to synchronize with rendering
11322 * pipelines, to benchmark windowing system rendering operations.
11327 gdk_test_render_sync (GdkWindow *window)
11329 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
11333 * gdk_test_simulate_key:
11334 * @window: a #GdkWindow to simulate a key event for
11335 * @x: x coordinate within @window for the key event
11336 * @y: y coordinate within @window for the key event
11337 * @keyval: A GDK keyboard value
11338 * @modifiers: Keyboard modifiers the event is setup with
11339 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
11341 * This function is intended to be used in GTK+ test programs.
11342 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
11343 * the given (@x,@y) coordinates within @window and simulate a
11344 * key press or release event.
11346 * When the mouse pointer is warped to the target location, use
11347 * of this function outside of test programs that run in their
11348 * own virtual windowing system (e.g. Xvfb) is not recommended.
11349 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
11350 * be warped and @window origin will be used as mouse pointer
11351 * location for the event.
11353 * Also, gdk_test_simulate_key() is a fairly low level function,
11354 * for most testing purposes, gtk_test_widget_send_key() is the
11355 * right function to call which will generate a key press event
11356 * followed by its accompanying key release event.
11358 * Returns: whether all actions necessary for a key event simulation
11359 * were carried out successfully
11364 gdk_test_simulate_key (GdkWindow *window,
11368 GdkModifierType modifiers,
11369 GdkEventType key_pressrelease)
11371 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11372 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
11376 * gdk_test_simulate_button:
11377 * @window: a #GdkWindow to simulate a button event for
11378 * @x: x coordinate within @window for the button event
11379 * @y: y coordinate within @window for the button event
11380 * @button: Number of the pointer button for the event, usually 1, 2 or 3
11381 * @modifiers: Keyboard modifiers the event is setup with
11382 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
11384 * This function is intended to be used in GTK+ test programs.
11385 * It will warp the mouse pointer to the given (@x,@y) coordinates
11386 * within @window and simulate a button press or release event.
11387 * Because the mouse pointer needs to be warped to the target
11388 * location, use of this function outside of test programs that
11389 * run in their own virtual windowing system (e.g. Xvfb) is not
11392 * Also, gdk_test_simulate_button() is a fairly low level function,
11393 * for most testing purposes, gtk_test_widget_click() is the right
11394 * function to call which will generate a button press event followed
11395 * by its accompanying button release event.
11397 * Returns: whether all actions necessary for a button event simulation
11398 * were carried out successfully
11403 gdk_test_simulate_button (GdkWindow *window,
11406 guint button, /*1..3*/
11407 GdkModifierType modifiers,
11408 GdkEventType button_pressrelease)
11410 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11411 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
11415 * gdk_property_get:
11416 * @window: a #GdkWindow
11417 * @property: the property to retrieve
11418 * @type: the desired property type, or %GDK_NONE, if any type of data
11419 * is acceptable. If this does not match the actual
11420 * type, then @actual_format and @actual_length will
11421 * be filled in, a warning will be printed to stderr
11422 * and no data will be returned.
11423 * @offset: the offset into the property at which to begin
11424 * retrieving data, in 4 byte units.
11425 * @length: the length of the data to retrieve in bytes. Data is
11426 * considered to be retrieved in 4 byte chunks, so @length
11427 * will be rounded up to the next highest 4 byte boundary
11428 * (so be careful not to pass a value that might overflow
11429 * when rounded up).
11430 * @pdelete: if %TRUE, delete the property after retrieving the
11432 * @actual_property_type: (out) (transfer none): location to store the
11433 * actual type of the property.
11434 * @actual_format: (out): location to store the actual return format of the
11435 * data; either 8, 16 or 32 bits.
11436 * @actual_length: location to store the length of the retrieved data, in
11437 * bytes. Data returned in the 32 bit format is stored
11438 * in a long variable, so the actual number of 32 bit
11439 * elements should be be calculated via
11440 * @actual_length / sizeof(glong) to ensure portability to
11442 * @data: (out) (array length=actual_length) (transfer full): location
11443 * to store a pointer to the data. The retrieved data should be
11444 * freed with g_free() when you are finished using it.
11446 * Retrieves a portion of the contents of a property. If the
11447 * property does not exist, then the function returns %FALSE,
11448 * and %GDK_NONE will be stored in @actual_property_type.
11452 * The XGetWindowProperty() function that gdk_property_get()
11453 * uses has a very confusing and complicated set of semantics.
11454 * Unfortunately, gdk_property_get() makes the situation
11455 * worse instead of better (the semantics should be considered
11456 * undefined), and also prints warnings to stderr in cases where it
11457 * should return a useful error to the program. You are advised to use
11458 * XGetWindowProperty() directly until a replacement function for
11459 * gdk_property_get()
11464 * Returns: %TRUE if data was successfully received and stored
11465 * in @data, otherwise %FALSE.
11468 gdk_property_get (GdkWindow *window,
11474 GdkAtom *actual_property_type,
11475 gint *actual_format_type,
11476 gint *actual_length,
11479 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11480 ->get_property (window, property, type, offset, length, pdelete,
11481 actual_property_type, actual_format_type,
11482 actual_length, data);
11486 * gdk_property_change: (skip)
11487 * @window: a #GdkWindow
11488 * @property: the property to change
11489 * @type: the new type for the property. If @mode is
11490 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11491 * must match the existing type or an error will occur.
11492 * @format: the new format for the property. If @mode is
11493 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11494 * must match the existing format or an error will occur.
11495 * @mode: a value describing how the new data is to be combined
11496 * with the current data.
11497 * @data: the data (a <literal>guchar *</literal>
11498 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
11499 * depending on @format), cast to a <literal>guchar *</literal>.
11500 * @nelements: the number of elements of size determined by the format,
11501 * contained in @data.
11503 * Changes the contents of a property on a window.
11506 gdk_property_change (GdkWindow *window,
11511 const guchar *data,
11514 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11515 ->change_property (window, property, type, format, mode, data, nelements);
11519 * gdk_property_delete:
11520 * @window: a #GdkWindow
11521 * @property: the property to delete
11523 * Deletes a property from a window.
11526 gdk_property_delete (GdkWindow *window,
11529 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);