1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <cairo-gobject.h>
30 #include "gdkwindow.h"
32 #include "gdkrectangle.h"
33 #include "gdkinternals.h"
35 #include "gdkscreenprivate.h"
36 #include "gdkdisplayprivate.h"
37 #include "gdkdeviceprivate.h"
38 #include "gdkvisualprivate.h"
39 #include "gdkmarshalers.h"
40 #include "gdkwindowimpl.h"
44 #undef DEBUG_WINDOW_PRINTING
49 * @Short_description: Onscreen display areas in the target window system
52 * A #GdkWindow is a (usually) rectangular region on the screen.
53 * It's a low-level object, used to implement high-level objects such as
54 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
55 * window, the thing a user might think of as a "window" with a titlebar and
56 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
57 * #GtkButton has a #GdkWindow associated with it.
59 * <refsect2 id="COMPOSITED-WINDOWS">
60 * <title>Composited Windows</title>
62 * Normally, the windowing system takes care of rendering the contents of a
63 * child window onto its parent window. This mechanism can be intercepted by
64 * calling gdk_window_set_composited() on the child window. For a
65 * <firstterm>composited</firstterm> window it is the responsibility of the
66 * application to render the window contents at the right spot.
68 * <example id="composited-window-example">
69 * <title>Composited windows</title>
71 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/gdk/composited-window-example.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include>
72 * </programlisting></example>
74 * In the example <xref linkend="composited-window-example"/>, a button is
75 * placed inside of an event box inside of a window. The event box is set as
76 * composited and therefore is no longer automatically drawn to the screen.
78 * When the contents of the event box change, an expose event is generated on
79 * its parent window (which, in this case, belongs to the toplevel #GtkWindow).
80 * The expose handler for this widget is responsible for merging the changes
81 * back on the screen in the way that it wishes.
83 * In our case, we merge the contents with a 50% transparency. We also set the
84 * background colour of the window to red. The effect is that the background
85 * shows through the button.
88 * <refsect2 id="OFFSCREEN-WINDOWS">
89 * <title>Offscreen Windows</title>
91 * Offscreen windows are more general than composited windows, since they allow
92 * not only to modify the rendering of the child window onto its parent, but
93 * also to apply coordinate transformations.
95 * To integrate an offscreen window into a window hierarchy, one has to call
96 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
97 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
98 * select an offscreen child at given coordinates, and the
99 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
100 * offscreen window are used to translate coordinates between the embedder and
101 * the offscreen window.
103 * For rendering an offscreen window onto its embedder, the contents of the
104 * offscreen window are available as a surface, via
105 * gdk_offscreen_window_get_surface().
111 /* Historically a GdkWindow always matches a platform native window,
112 * be it a toplevel window or a child window. In this setup the
113 * GdkWindow (and other GdkDrawables) were platform independent classes,
114 * and the actual platform specific implementation was in a delegate
115 * object availible as "impl" in the window object.
117 * With the addition of client side windows and offscreen windows this
118 * changes a bit. The application-visible GdkWindow object behaves as
119 * it did before, but not all such windows now have a corresponding native
120 * window. Instead windows that are "client side" are emulated by the gdk
121 * code such that clipping, drawing, moving, events etc work as expected.
123 * For GdkWindows that have a native window the "impl" object is the
124 * same as before. However, for all client side windows the impl object
125 * is shared with its parent (i.e. all client windows descendants of one
126 * native window has the same impl.
128 * Additionally there is a new type of platform independent impl object,
129 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
130 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
131 * windows). Such windows work by allocating a #cairo_surface_t as the backing
132 * store for drawing operations, which is resized with the window.
134 * GdkWindows have a pointer to the "impl window" they are in, i.e.
135 * the topmost GdkWindow which have the same "impl" value. This is stored
136 * in impl_window, which is different from the window itself only for client
138 * All GdkWindows (native or not) track the position of the window in the parent
139 * (x, y), the size of the window (width, height), the position of the window
140 * with respect to the impl window (abs_x, abs_y). We also track the clip
141 * region of the window wrt parent windows and siblings, in window-relative
142 * coordinates with and without child windows included (clip_region,
143 * clip_region_with_children).
145 * All toplevel windows are native windows, but also child windows can be
146 * native (although not children of offscreens). We always listen to
147 * a basic set of events (see get_native_event_mask) for these windows
148 * so that we can emulate events for any client side children.
150 * For native windows we apply the calculated clip region as a window shape
151 * so that eg. client side siblings that overlap the native child properly
152 * draws over the native child window.
154 * In order to minimize flicker and for performance we use a couple of cacheing
155 * tricks. First of all, every time we do a window to window copy area, for instance
156 * when moving a client side window or when scrolling/moving a region in a window
157 * we store this in outstanding_moves instead of applying immediately. We then
158 * delay this move until we really need it (because something depends on being
159 * able to read it), or until we're handing a redraw from an expose/invalidation
160 * (actually we delay it past redraw, but before blitting the double buffer
161 * to the window). This gives us two advantages. First of all it minimizes the time
162 * from the window is moved to the exposes related to that move, secondly it allows
163 * us to be smart about how to do the copy. We combine multiple moves into one (when
164 * possible) and we don't actually do copies to anything that is or will be
165 * invalidated and exposed anyway.
167 * Secondly, we use something called a "implicit paint" during repaint handling.
168 * An implicit paint is similar to a regular paint for the paint stack, but it is
169 * not put on the stack. Instead, it is set on the impl window, and later when
170 * regular gdk_window_begin_paint_region() happen on a window of this impl window
171 * we reuse the surface from the implicit paint. During repaint we create and at the
172 * end flush an implicit paint, which means we can collect all the paints on
173 * multiple client side windows in the same backing store.
176 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
178 /* This adds a local value to the GdkVisibilityState enum */
179 #define GDK_VISIBILITY_NOT_VIEWABLE 3
182 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
196 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
200 struct _GdkWindowPaint
202 cairo_region_t *region;
203 cairo_surface_t *surface;
204 cairo_region_t *flushed;
205 guint uses_implicit : 1;
209 cairo_region_t *dest_region; /* The destination region */
210 int dx, dy; /* The amount that the source was moved to reach dest_region */
211 } GdkWindowRegionMove;
215 static void gdk_window_drop_cairo_surface (GdkWindow *private);
217 static void gdk_window_free_paint_stack (GdkWindow *window);
219 static void gdk_window_finalize (GObject *object);
221 static void gdk_window_set_property (GObject *object,
225 static void gdk_window_get_property (GObject *object,
230 static void gdk_window_clear_backing_region (GdkWindow *window,
231 cairo_region_t *region);
233 static void recompute_visible_regions (GdkWindow *private,
234 gboolean recalculate_siblings,
235 gboolean recalculate_children);
236 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
237 static void gdk_window_flush_recursive (GdkWindow *window);
238 static void do_move_region_bits_on_impl (GdkWindow *window,
239 cairo_region_t *region, /* In impl window coords */
241 static void gdk_window_invalidate_in_parent (GdkWindow *private);
242 static void move_native_children (GdkWindow *private);
243 static void update_cursor (GdkDisplay *display,
245 static void impl_window_add_update_area (GdkWindow *impl_window,
246 cairo_region_t *region);
247 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
248 static void gdk_window_invalidate_region_full (GdkWindow *window,
249 const cairo_region_t *region,
250 gboolean invalidate_children,
252 static void gdk_window_invalidate_rect_full (GdkWindow *window,
253 const GdkRectangle *rect,
254 gboolean invalidate_children,
256 static void _gdk_window_propagate_has_alpha_background (GdkWindow *window);
258 static guint signals[LAST_SIGNAL] = { 0 };
260 static gpointer parent_class = NULL;
262 static const cairo_user_data_key_t gdk_window_cairo_key;
264 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
267 _gdk_paintable_get_type (void)
269 static GType paintable_type = 0;
273 const GTypeInfo paintable_info =
275 sizeof (GdkPaintableIface), /* class_size */
276 NULL, /* base_init */
277 NULL, /* base_finalize */
280 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
281 g_intern_static_string ("GdkPaintable"),
284 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
287 return paintable_type;
291 gdk_window_init (GdkWindow *window)
293 /* 0-initialization is good for all other fields. */
295 window->window_type = GDK_WINDOW_CHILD;
297 window->state = GDK_WINDOW_STATE_WITHDRAWN;
300 window->toplevel_window_type = -1;
302 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
303 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
304 /* Default to unobscured since some backends don't send visibility events */
305 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
307 window->device_cursor = g_hash_table_new_full (NULL, NULL,
308 NULL, g_object_unref);
311 /* Stop and return on the first non-NULL parent */
313 accumulate_get_window (GSignalInvocationHint *ihint,
315 const GValue *handler_return,
318 g_value_copy (handler_return, return_accu);
319 /* Continue while returning NULL */
320 return g_value_get_object (handler_return) == NULL;
324 create_surface_accumulator (GSignalInvocationHint *ihint,
326 const GValue *handler_return,
329 g_value_copy (handler_return, return_accu);
331 /* Stop on the first non-NULL return value */
332 return g_value_get_boxed (handler_return) == NULL;
335 static GQuark quark_pointer_window = 0;
338 gdk_window_class_init (GdkWindowClass *klass)
340 GObjectClass *object_class = G_OBJECT_CLASS (klass);
342 parent_class = g_type_class_peek_parent (klass);
344 object_class->finalize = gdk_window_finalize;
345 object_class->set_property = gdk_window_set_property;
346 object_class->get_property = gdk_window_get_property;
348 klass->create_surface = _gdk_offscreen_window_create_surface;
350 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
358 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
359 * gdk_window_get_cursor() for details.
363 g_object_class_install_property (object_class,
365 g_param_spec_object ("cursor",
372 * GdkWindow::pick-embedded-child:
373 * @window: the window on which the signal is emitted
374 * @x: x coordinate in the window
375 * @y: y coordinate in the window
377 * The ::pick-embedded-child signal is emitted to find an embedded
378 * child at the given position.
380 * Returns: (transfer none): the #GdkWindow of the embedded child at
385 signals[PICK_EMBEDDED_CHILD] =
386 g_signal_new (g_intern_static_string ("pick-embedded-child"),
387 G_OBJECT_CLASS_TYPE (object_class),
389 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
390 accumulate_get_window, NULL,
391 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
398 * GdkWindow::to-embedder:
399 * @window: the offscreen window on which the signal is emitted
400 * @offscreen-x: x coordinate in the offscreen window
401 * @offscreen-y: y coordinate in the offscreen window
402 * @embedder-x: (out) (type double): return location for the x
403 * coordinate in the embedder window
404 * @embedder-y: (out) (type double): return location for the y
405 * coordinate in the embedder window
407 * The ::to-embedder signal is emitted to translate coordinates
408 * in an offscreen window to its embedder.
410 * See also #GtkWindow::from-embedder.
414 signals[TO_EMBEDDER] =
415 g_signal_new (g_intern_static_string ("to-embedder"),
416 G_OBJECT_CLASS_TYPE (object_class),
418 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
420 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
429 * GdkWindow::from-embedder:
430 * @window: the offscreen window on which the signal is emitted
431 * @embedder-x: x coordinate in the embedder window
432 * @embedder-y: y coordinate in the embedder window
433 * @offscreen-x: (out) (type double): return location for the x
434 * coordinate in the offscreen window
435 * @offscreen-y: (out) (type double): return location for the y
436 * coordinate in the offscreen window
438 * The ::from-embedder signal is emitted to translate coordinates
439 * in the embedder of an offscreen window to the offscreen window.
441 * See also #GtkWindow::to-embedder.
445 signals[FROM_EMBEDDER] =
446 g_signal_new (g_intern_static_string ("from-embedder"),
447 G_OBJECT_CLASS_TYPE (object_class),
449 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
451 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
460 * GdkWindow::create-surface:
461 * @window: the offscreen window on which the signal is emitted
462 * @width: the width of the offscreen surface to create
463 * @height: the height of the offscreen surface to create
465 * The ::create-surface signal is emitted when an offscreen window
466 * needs its surface (re)created, which happens either when the the
467 * window is first drawn to, or when the window is being
468 * resized. The first signal handler that returns a non-%NULL
469 * surface will stop any further signal emission, and its surface
472 * Note that it is not possible to access the window's previous
473 * surface from within any callback of this signal. Calling
474 * gdk_offscreen_window_get_surface() will lead to a crash.
476 * Returns: the newly created #cairo_surface_t for the offscreen window
480 signals[CREATE_SURFACE] =
481 g_signal_new (g_intern_static_string ("create-surface"),
482 G_OBJECT_CLASS_TYPE (object_class),
484 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
485 create_surface_accumulator, NULL,
486 _gdk_marshal_BOXED__INT_INT,
487 CAIRO_GOBJECT_TYPE_SURFACE,
494 device_removed_cb (GdkDeviceManager *device_manager,
498 window->devices_inside = g_list_remove (window->devices_inside, device);
499 g_hash_table_remove (window->device_cursor, device);
501 if (window->device_events)
502 g_hash_table_remove (window->device_events, device);
506 gdk_window_finalize (GObject *object)
508 GdkWindow *window = GDK_WINDOW (object);
509 GdkDeviceManager *device_manager;
511 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
512 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
514 if (!GDK_WINDOW_DESTROYED (window))
516 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
518 g_warning ("losing last reference to undestroyed window\n");
519 _gdk_window_destroy (window, FALSE);
522 /* We use TRUE here, to keep us from actually calling
523 * XDestroyWindow() on the window
525 _gdk_window_destroy (window, TRUE);
528 gdk_window_drop_cairo_surface (window);
532 g_object_unref (window->impl);
536 if (window->impl_window != window)
538 g_object_unref (window->impl_window);
539 window->impl_window = NULL;
543 cairo_region_destroy (window->shape);
545 if (window->input_shape)
546 cairo_region_destroy (window->input_shape);
549 g_object_unref (window->cursor);
551 if (window->device_cursor)
552 g_hash_table_destroy (window->device_cursor);
554 if (window->device_events)
555 g_hash_table_destroy (window->device_events);
557 if (window->source_event_masks)
558 g_hash_table_destroy (window->source_event_masks);
560 if (window->devices_inside)
561 g_list_free (window->devices_inside);
563 if (window->layered_region)
564 cairo_region_destroy (window->layered_region);
566 G_OBJECT_CLASS (parent_class)->finalize (object);
570 gdk_window_set_property (GObject *object,
575 GdkWindow *window = (GdkWindow *)object;
580 gdk_window_set_cursor (window, g_value_get_object (value));
584 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
590 gdk_window_get_property (GObject *object,
595 GdkWindow *window = (GdkWindow *) object;
600 g_value_set_object (value, gdk_window_get_cursor (window));
604 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
610 gdk_window_is_offscreen (GdkWindow *window)
612 return window->window_type == GDK_WINDOW_OFFSCREEN;
616 gdk_window_get_impl_window (GdkWindow *window)
618 return window->impl_window;
622 _gdk_window_get_impl_window (GdkWindow *window)
624 return gdk_window_get_impl_window (window);
628 gdk_window_has_impl (GdkWindow *window)
630 return window->impl_window == window;
634 gdk_window_is_toplevel (GdkWindow *window)
637 window->parent == NULL ||
638 window->parent->window_type == GDK_WINDOW_ROOT;
642 _gdk_window_has_impl (GdkWindow *window)
644 return gdk_window_has_impl (window);
648 gdk_window_has_no_impl (GdkWindow *window)
650 return window->impl_window != window;
654 remove_layered_child_area (GdkWindow *window,
655 cairo_region_t *region)
658 cairo_region_t *child_region;
662 for (l = window->children; l; l = l->next)
666 /* If region is empty already, no need to do
667 anything potentially costly */
668 if (cairo_region_is_empty (region))
671 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
674 /* Ignore offscreen children, as they don't draw in their parent and
675 * don't take part in the clipping */
676 if (gdk_window_is_offscreen (child))
679 /* Only non-impl children with alpha add to the layered region */
680 if (!child->has_alpha_background && gdk_window_has_impl (child))
685 r.width = child->width;
686 r.height = child->height;
688 /* Bail early if child totally outside region */
689 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
692 child_region = cairo_region_create_rectangle (&r);
695 /* Adjust shape region to parent window coords */
696 cairo_region_translate (child->shape, child->x, child->y);
697 cairo_region_intersect (child_region, child->shape);
698 cairo_region_translate (child->shape, -child->x, -child->y);
701 cairo_region_subtract (region, child_region);
702 cairo_region_destroy (child_region);
707 remove_child_area (GdkWindow *window,
710 cairo_region_t *region,
711 cairo_region_t *layered_region)
714 cairo_region_t *child_region;
717 cairo_region_t *shape;
719 for (l = window->children; l; l = l->next)
726 /* If region is empty already, no need to do
727 anything potentially costly */
728 if (cairo_region_is_empty (region))
731 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
734 /* Ignore offscreen children, as they don't draw in their parent and
735 * don't take part in the clipping */
736 if (gdk_window_is_offscreen (child))
741 r.width = child->width;
742 r.height = child->height;
744 /* Bail early if child totally outside region */
745 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
748 child_region = cairo_region_create_rectangle (&r);
752 /* Adjust shape region to parent window coords */
753 cairo_region_translate (child->shape, child->x, child->y);
754 cairo_region_intersect (child_region, child->shape);
755 cairo_region_translate (child->shape, -child->x, -child->y);
757 else if (window->window_type == GDK_WINDOW_FOREIGN)
759 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
762 cairo_region_intersect (child_region, shape);
763 cairo_region_destroy (shape);
769 if (child->input_shape)
770 cairo_region_intersect (child_region, child->input_shape);
771 else if (window->window_type == GDK_WINDOW_FOREIGN)
773 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
776 cairo_region_intersect (child_region, shape);
777 cairo_region_destroy (shape);
782 if (child->has_alpha_background)
784 if (layered_region != NULL)
785 cairo_region_union (layered_region, child_region);
788 cairo_region_subtract (region, child_region);
789 cairo_region_destroy (child_region);
793 static GdkVisibilityState
794 effective_visibility (GdkWindow *window)
796 GdkVisibilityState native;
798 if (!gdk_window_is_viewable (window))
799 return GDK_VISIBILITY_NOT_VIEWABLE;
801 native = window->impl_window->native_visibility;
803 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
804 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
805 return GDK_VISIBILITY_FULLY_OBSCURED;
806 else if (native == GDK_VISIBILITY_UNOBSCURED)
807 return window->visibility;
808 else /* native PARTIAL, private partial or unobscured */
809 return GDK_VISIBILITY_PARTIAL;
813 gdk_window_update_visibility (GdkWindow *window)
815 GdkVisibilityState new_visibility;
818 new_visibility = effective_visibility (window);
820 if (new_visibility != window->effective_visibility)
822 window->effective_visibility = new_visibility;
824 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
825 window->event_mask & GDK_VISIBILITY_NOTIFY_MASK)
827 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
829 event->visibility.state = new_visibility;
835 gdk_window_update_visibility_recursively (GdkWindow *window,
836 GdkWindow *only_for_impl)
841 gdk_window_update_visibility (window);
842 for (l = window->children; l != NULL; l = l->next)
845 if ((only_for_impl == NULL) ||
846 (only_for_impl == child->impl_window))
847 gdk_window_update_visibility_recursively (child, only_for_impl);
852 should_apply_clip_as_shape (GdkWindow *window)
855 gdk_window_has_impl (window) &&
856 /* Not for offscreens */
857 !gdk_window_is_offscreen (window) &&
858 /* or for toplevels */
859 !gdk_window_is_toplevel (window) &&
860 /* or for foreign windows */
861 window->window_type != GDK_WINDOW_FOREIGN &&
862 /* or for the root window */
863 window->window_type != GDK_WINDOW_ROOT;
867 apply_shape (GdkWindow *window,
868 cairo_region_t *region)
870 GdkWindowImplClass *impl_class;
872 /* We trash whether we applied a shape so that
873 we can avoid unsetting it many times, which
874 could happen in e.g. apply_clip_as_shape as
875 windows get resized */
876 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
878 impl_class->shape_combine_region (window,
880 else if (window->applied_shape)
881 impl_class->shape_combine_region (window,
884 window->applied_shape = region != NULL;
888 region_rect_equal (const cairo_region_t *region,
889 const GdkRectangle *rect)
891 GdkRectangle extents;
893 if (cairo_region_num_rectangles (region) != 1)
896 cairo_region_get_extents (region, &extents);
898 return extents.x == rect->x &&
899 extents.y == rect->y &&
900 extents.width == rect->width &&
901 extents.height == rect->height;
905 apply_clip_as_shape (GdkWindow *window)
910 r.width = window->width;
911 r.height = window->height;
913 /* We only apply the clip region if would differ
914 from the actual clip region implied by the size
915 of the window. This is to avoid unneccessarily
916 adding meaningless shapes to all native subwindows */
917 if (!region_rect_equal (window->clip_region, &r))
918 apply_shape (window, window->clip_region);
920 apply_shape (window, NULL);
924 recompute_visible_regions_internal (GdkWindow *private,
925 gboolean recalculate_clip,
926 gboolean recalculate_siblings,
927 gboolean recalculate_children)
932 cairo_region_t *new_clip, *new_layered;
933 gboolean clip_region_changed;
934 gboolean abs_pos_changed;
935 int old_abs_x, old_abs_y;
937 old_abs_x = private->abs_x;
938 old_abs_y = private->abs_y;
940 /* Update absolute position */
941 if (gdk_window_has_impl (private))
943 /* Native window starts here */
949 private->abs_x = private->parent->abs_x + private->x;
950 private->abs_y = private->parent->abs_y + private->y;
954 private->abs_x != old_abs_x ||
955 private->abs_y != old_abs_y;
957 /* Update clip region based on:
960 * siblings in parents above window
962 clip_region_changed = FALSE;
963 if (recalculate_clip)
965 new_layered = cairo_region_create ();
966 if (private->viewable)
968 /* Calculate visible region (sans children) in parent window coords */
971 r.width = private->width;
972 r.height = private->height;
973 new_clip = cairo_region_create_rectangle (&r);
975 if (!gdk_window_is_toplevel (private))
977 cairo_region_intersect (new_clip, private->parent->clip_region);
978 cairo_region_union (new_layered, private->parent->layered_region);
980 /* Remove all overlapping children from parent. */
981 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
984 /* Convert from parent coords to window coords */
985 cairo_region_translate (new_clip, -private->x, -private->y);
986 cairo_region_translate (new_layered, -private->x, -private->y);
989 cairo_region_intersect (new_clip, private->shape);
992 new_clip = cairo_region_create ();
994 cairo_region_intersect (new_layered, new_clip);
996 if (private->clip_region == NULL ||
997 !cairo_region_equal (private->clip_region, new_clip))
998 clip_region_changed = TRUE;
1000 if (private->layered_region == NULL ||
1001 !cairo_region_equal (private->layered_region, new_layered))
1002 clip_region_changed = TRUE;
1004 if (private->clip_region)
1005 cairo_region_destroy (private->clip_region);
1006 private->clip_region = new_clip;
1008 if (private->layered_region != NULL)
1009 cairo_region_destroy (private->layered_region);
1010 private->layered_region = new_layered;
1012 if (private->clip_region_with_children)
1013 cairo_region_destroy (private->clip_region_with_children);
1014 private->clip_region_with_children = cairo_region_copy (private->clip_region);
1015 if (private->window_type != GDK_WINDOW_ROOT)
1016 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
1019 if (clip_region_changed)
1021 GdkVisibilityState visibility;
1022 gboolean fully_visible;
1024 if (cairo_region_is_empty (private->clip_region))
1025 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1030 fully_visible = cairo_region_equal (private->clip_region,
1037 r.width = private->width;
1038 r.height = private->height;
1039 fully_visible = region_rect_equal (private->clip_region, &r);
1043 visibility = GDK_VISIBILITY_UNOBSCURED;
1045 visibility = GDK_VISIBILITY_PARTIAL;
1048 if (private->visibility != visibility)
1050 private->visibility = visibility;
1051 gdk_window_update_visibility (private);
1055 /* Update all children, recursively (except for root, where children are not exact). */
1056 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1057 private->window_type != GDK_WINDOW_ROOT)
1059 for (l = private->children; l; l = l->next)
1062 /* Only recalculate clip if the the clip region changed, otherwise
1063 * there is no way the child clip region could change (its has not e.g. moved)
1064 * Except if recalculate_children is set to force child updates
1066 recompute_visible_regions_internal (child,
1067 recalculate_clip && (clip_region_changed || recalculate_children),
1072 if (clip_region_changed &&
1073 should_apply_clip_as_shape (private))
1074 apply_clip_as_shape (private);
1076 if (recalculate_siblings &&
1077 !gdk_window_is_toplevel (private))
1079 /* If we moved a child window in parent or changed the stacking order, then we
1080 * need to recompute the visible area of all the other children in the parent
1082 for (l = private->parent->children; l; l = l->next)
1086 if (child != private)
1087 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1090 /* We also need to recompute the _with_children clip for the parent */
1091 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1094 if (private->cairo_surface && gdk_window_has_impl (private))
1096 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1098 private->cairo_surface = iface->resize_cairo_surface (private,
1099 private->cairo_surface,
1103 else if (private->cairo_surface)
1104 gdk_window_drop_cairo_surface (private);
1107 /* Call this when private has changed in one or more of these ways:
1111 * stacking order of window changed
1114 * It will recalculate abs_x/y and the clip regions
1116 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1117 * for recalculate_siblings. (Mostly used internally for the recursion)
1119 * If a child window was removed (and you can't use that child for
1120 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1123 recompute_visible_regions (GdkWindow *private,
1124 gboolean recalculate_siblings,
1125 gboolean recalculate_children)
1127 recompute_visible_regions_internal (private,
1129 recalculate_siblings,
1130 recalculate_children);
1134 _gdk_window_update_size (GdkWindow *window)
1136 recompute_visible_regions (window, TRUE, FALSE);
1139 /* Find the native window that would be just above "child"
1140 * in the native stacking order if "child" was a native window
1141 * (it doesn't have to be native). If there is no such native
1142 * window inside this native parent then NULL is returned.
1143 * If child is NULL, find lowest native window in parent.
1146 find_native_sibling_above_helper (GdkWindow *parent,
1154 l = g_list_find (parent->children, child);
1155 g_assert (l != NULL); /* Better be a child of its parent... */
1156 l = l->prev; /* Start looking at the one above the child */
1159 l = g_list_last (parent->children);
1161 for (; l != NULL; l = l->prev)
1165 if (gdk_window_has_impl (w))
1168 g_assert (parent != w);
1169 w = find_native_sibling_above_helper (w, NULL);
1179 find_native_sibling_above (GdkWindow *parent,
1184 w = find_native_sibling_above_helper (parent, child);
1188 if (gdk_window_has_impl (parent))
1191 return find_native_sibling_above (parent->parent, parent);
1195 get_native_device_event_mask (GdkWindow *private,
1198 GdkEventMask event_mask;
1201 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1203 event_mask = private->event_mask;
1205 if (private->window_type == GDK_WINDOW_ROOT ||
1206 private->window_type == GDK_WINDOW_FOREIGN)
1212 /* Do whatever the app asks to, since the app
1213 * may be asking for weird things for native windows,
1214 * but don't use motion hints as that may affect non-native
1215 * child windows that don't want it. Also, we need to
1216 * set all the app-specified masks since they will be picked
1217 * up by any implicit grabs (i.e. if they were not set as
1218 * native we would not get the events we need). */
1219 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1221 /* We need thse for all native windows so we can
1222 emulate events on children: */
1225 GDK_VISIBILITY_NOTIFY_MASK |
1226 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1228 /* Additionally we select for pointer and button events
1229 * for toplevels as we need to get these to emulate
1230 * them for non-native subwindows. Even though we don't
1231 * select on them for all native windows we will get them
1232 * as the events are propagated out to the first window
1233 * that select for them.
1234 * Not selecting for button press on all windows is an
1235 * important thing, because in X only one client can do
1236 * so, and we don't want to unexpectedly prevent another
1237 * client from doing it.
1239 * We also need to do the same if the app selects for button presses
1240 * because then we will get implicit grabs for this window, and the
1241 * event mask used for that grab is based on the rest of the mask
1242 * for the window, but we might need more events than this window
1243 * lists due to some non-native child window.
1245 if (gdk_window_is_toplevel (private) ||
1246 mask & GDK_BUTTON_PRESS_MASK)
1248 GDK_POINTER_MOTION_MASK |
1249 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1257 get_native_grab_event_mask (GdkEventMask grab_mask)
1259 /* Similar to the above but for pointer events only */
1261 GDK_POINTER_MOTION_MASK |
1262 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1263 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1266 ~GDK_POINTER_MOTION_HINT_MASK);
1270 get_native_event_mask (GdkWindow *private)
1272 return get_native_device_event_mask (private, NULL);
1275 /* Puts the native window in the right order wrt the other native windows
1276 * in the hierarchy, given the position it has in the client side data.
1277 * This is useful if some operation changed the stacking order.
1278 * This calls assumes the native window is now topmost in its native parent.
1281 sync_native_window_stack_position (GdkWindow *window)
1284 GdkWindowImplClass *impl_class;
1285 GList listhead = {0};
1287 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1289 above = find_native_sibling_above (window->parent, window);
1292 listhead.data = window;
1293 impl_class->restack_under (above, &listhead);
1298 * gdk_window_new: (constructor)
1299 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1300 * the default root window for the default display.
1301 * @attributes: attributes of the new window
1302 * @attributes_mask: mask indicating which fields in @attributes are valid
1304 * Creates a new #GdkWindow using the attributes from
1305 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1306 * more details. Note: to use this on displays other than the default
1307 * display, @parent must be specified.
1309 * Return value: (transfer full): the new #GdkWindow
1312 gdk_window_new (GdkWindow *parent,
1313 GdkWindowAttr *attributes,
1314 gint attributes_mask)
1318 GdkDisplay *display;
1321 GdkEventMask event_mask;
1322 GdkWindow *real_parent;
1323 GdkDeviceManager *device_manager;
1325 g_return_val_if_fail (attributes != NULL, NULL);
1329 GDK_NOTE (MULTIHEAD,
1330 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1332 screen = gdk_screen_get_default ();
1333 parent = gdk_screen_get_root_window (screen);
1336 screen = gdk_window_get_screen (parent);
1338 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1340 if (GDK_WINDOW_DESTROYED (parent))
1342 g_warning ("gdk_window_new(): parent is destroyed\n");
1346 display = gdk_screen_get_display (screen);
1348 window = _gdk_display_create_window (display);
1350 /* Windows with a foreign parent are treated as if they are children
1351 * of the root window, except for actual creation.
1353 real_parent = parent;
1354 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1355 parent = gdk_screen_get_root_window (screen);
1357 window->parent = parent;
1359 window->accept_focus = TRUE;
1360 window->focus_on_map = TRUE;
1362 if (attributes_mask & GDK_WA_X)
1367 if (attributes_mask & GDK_WA_Y)
1374 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1375 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1377 if (attributes->wclass == GDK_INPUT_ONLY)
1379 /* Backwards compatiblity - we've always ignored
1380 * attributes->window_type for input-only windows
1383 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1384 window->window_type = GDK_WINDOW_TEMP;
1386 window->window_type = GDK_WINDOW_CHILD;
1389 window->window_type = attributes->window_type;
1392 switch (window->window_type)
1394 case GDK_WINDOW_TOPLEVEL:
1395 case GDK_WINDOW_TEMP:
1396 case GDK_WINDOW_OFFSCREEN:
1397 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1398 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1399 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1400 case GDK_WINDOW_CHILD:
1404 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1408 if (attributes_mask & GDK_WA_VISUAL)
1409 window->visual = attributes->visual;
1411 window->visual = gdk_screen_get_system_visual (screen);
1413 window->event_mask = attributes->event_mask;
1415 if (attributes->wclass == GDK_INPUT_OUTPUT)
1417 window->input_only = FALSE;
1418 window->depth = window->visual->depth;
1420 /* XXX: Cache this somehow? */
1421 window->background = cairo_pattern_create_rgba (0, 0, 0, 0);
1422 window->has_alpha_background = TRUE;
1427 window->input_only = TRUE;
1431 window->parent->children = g_list_prepend (window->parent->children, window);
1434 if (window->parent->window_type == GDK_WINDOW_ROOT)
1435 native = TRUE; /* Always use native windows for toplevels */
1436 else if (!window->input_only &&
1437 (attributes_mask & GDK_WA_VISUAL &&
1438 attributes->visual != gdk_window_get_visual (window->parent)))
1439 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1441 if (gdk_window_is_offscreen (window))
1443 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1444 window->impl_window = window;
1448 event_mask = get_native_event_mask (window);
1450 /* Create the impl */
1451 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1452 window->impl_window = window;
1454 /* This will put the native window topmost in the native parent, which may
1455 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1456 if (!_gdk_window_has_impl (real_parent))
1457 sync_native_window_stack_position (window);
1461 window->impl_window = g_object_ref (window->parent->impl_window);
1462 window->impl = g_object_ref (window->impl_window->impl);
1465 recompute_visible_regions (window, TRUE, FALSE);
1467 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1468 (attributes->cursor) :
1471 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1472 g_signal_connect (device_manager, "device-removed",
1473 G_CALLBACK (device_removed_cb), window);
1479 is_parent_of (GdkWindow *parent,
1490 w = gdk_window_get_parent (w);
1497 change_impl (GdkWindow *private,
1498 GdkWindow *impl_window,
1503 GdkWindowImpl *old_impl;
1504 GdkWindow *old_impl_window;
1506 old_impl = private->impl;
1507 old_impl_window = private->impl_window;
1508 if (private != impl_window)
1509 private->impl_window = g_object_ref (impl_window);
1511 private->impl_window = private;
1512 private->impl = g_object_ref (new);
1513 if (old_impl_window != private)
1514 g_object_unref (old_impl_window);
1515 g_object_unref (old_impl);
1517 for (l = private->children; l != NULL; l = l->next)
1521 if (child->impl == old_impl)
1522 change_impl (child, impl_window, new);
1527 reparent_to_impl (GdkWindow *private)
1532 GdkWindowImplClass *impl_class;
1534 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1536 /* Enumerate in reverse order so we get the right order for the native
1537 windows (first in childrens list is topmost, and reparent places on top) */
1538 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1542 if (child->impl == private->impl)
1543 reparent_to_impl (child);
1546 show = impl_class->reparent ((GdkWindow *)child,
1547 (GdkWindow *)private,
1548 child->x, child->y);
1550 gdk_window_show_unraised ((GdkWindow *)child);
1557 * gdk_window_reparent:
1558 * @window: a #GdkWindow
1559 * @new_parent: new parent to move @window into
1560 * @x: X location inside the new parent
1561 * @y: Y location inside the new parent
1563 * Reparents @window into the given @new_parent. The window being
1564 * reparented will be unmapped as a side effect.
1568 gdk_window_reparent (GdkWindow *window,
1569 GdkWindow *new_parent,
1573 GdkWindow *old_parent;
1575 gboolean show, was_mapped, applied_clip_as_shape;
1576 gboolean do_reparent_to_impl;
1577 GdkEventMask old_native_event_mask;
1578 GdkWindowImplClass *impl_class;
1580 g_return_if_fail (GDK_IS_WINDOW (window));
1581 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1582 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1584 if (GDK_WINDOW_DESTROYED (window) ||
1585 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1588 screen = gdk_window_get_screen (window);
1590 new_parent = gdk_screen_get_root_window (screen);
1592 /* No input-output children of input-only windows */
1593 if (new_parent->input_only && !window->input_only)
1596 /* Don't create loops in hierarchy */
1597 if (is_parent_of (window, new_parent))
1600 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1601 To make sure we're ok, just wipe it. */
1602 gdk_window_drop_cairo_surface (window);
1604 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1605 old_parent = window->parent;
1607 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1610 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1611 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1612 new_parent->window_type == GDK_WINDOW_FOREIGN)
1613 gdk_window_ensure_native (window);
1615 applied_clip_as_shape = should_apply_clip_as_shape (window);
1617 old_native_event_mask = 0;
1618 do_reparent_to_impl = FALSE;
1619 if (gdk_window_has_impl (window))
1621 old_native_event_mask = get_native_event_mask (window);
1623 show = impl_class->reparent (window, new_parent, x, y);
1627 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1628 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1629 new_parent->window_type != GDK_WINDOW_FOREIGN);
1632 gdk_window_hide (window);
1634 do_reparent_to_impl = TRUE;
1635 change_impl (window,
1636 new_parent->impl_window,
1640 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1643 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1645 new_parent = gdk_screen_get_root_window (screen);
1649 old_parent->children = g_list_remove (old_parent->children, window);
1651 window->parent = new_parent;
1655 new_parent->children = g_list_prepend (new_parent->children, window);
1657 /* Switch the window type as appropriate */
1659 switch (GDK_WINDOW_TYPE (new_parent))
1661 case GDK_WINDOW_ROOT:
1662 case GDK_WINDOW_FOREIGN:
1663 if (window->toplevel_window_type != -1)
1664 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1665 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1666 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1668 case GDK_WINDOW_OFFSCREEN:
1669 case GDK_WINDOW_TOPLEVEL:
1670 case GDK_WINDOW_CHILD:
1671 case GDK_WINDOW_TEMP:
1672 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1673 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1675 /* Save the original window type so we can restore it if the
1676 * window is reparented back to be a toplevel
1678 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1679 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1683 /* We might have changed window type for a native windows, so we
1684 need to change the event mask too. */
1685 if (gdk_window_has_impl (window))
1687 GdkEventMask native_event_mask = get_native_event_mask (window);
1689 if (native_event_mask != old_native_event_mask)
1690 impl_class->set_events (window, native_event_mask);
1693 _gdk_window_update_viewable (window);
1695 if (window->background == NULL)
1697 /* parent relative background, update has_alpha_background */
1698 if (window->parent == NULL ||
1699 window->parent->window_type == GDK_WINDOW_ROOT)
1700 window->has_alpha_background = FALSE;
1702 window->has_alpha_background = window->parent->has_alpha_background;
1705 recompute_visible_regions (window, TRUE, FALSE);
1706 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1707 recompute_visible_regions (old_parent, FALSE, TRUE);
1709 _gdk_window_propagate_has_alpha_background (window);
1711 /* We used to apply the clip as the shape, but no more.
1712 Reset this to the real shape */
1713 if (gdk_window_has_impl (window) &&
1714 applied_clip_as_shape &&
1715 !should_apply_clip_as_shape (window))
1716 apply_shape (window, window->shape);
1718 if (do_reparent_to_impl)
1719 reparent_to_impl (window);
1722 /* The reparent will have put the native window topmost in the native parent,
1723 * which may be wrong wrt other native windows in the non-native hierarchy,
1725 if (!gdk_window_has_impl (new_parent))
1726 sync_native_window_stack_position (window);
1730 gdk_window_show_unraised (window);
1732 _gdk_synthesize_crossing_events_for_geometry_change (window);
1736 * gdk_window_ensure_native:
1737 * @window: a #GdkWindow
1739 * Tries to ensure that there is a window-system native window for this
1740 * GdkWindow. This may fail in some situations, returning %FALSE.
1742 * Offscreen window and children of them can never have native windows.
1744 * Some backends may not support native child windows.
1746 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1751 gdk_window_ensure_native (GdkWindow *window)
1753 GdkWindow *impl_window;
1754 GdkWindowImpl *new_impl, *old_impl;
1755 GdkDisplay *display;
1759 GdkWindowImplClass *impl_class;
1761 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1763 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1764 GDK_WINDOW_DESTROYED (window))
1767 impl_window = gdk_window_get_impl_window (window);
1769 if (gdk_window_is_offscreen (impl_window))
1770 return FALSE; /* native in offscreens not supported */
1772 if (impl_window == window)
1773 /* Already has an impl, and its not offscreen . */
1776 /* Need to create a native window */
1778 gdk_window_drop_cairo_surface (window);
1780 screen = gdk_window_get_screen (window);
1781 display = gdk_screen_get_display (screen);
1783 old_impl = window->impl;
1784 _gdk_display_create_window_impl (display,
1785 window, window->parent,
1787 get_native_event_mask (window),
1789 new_impl = window->impl;
1791 window->impl = old_impl;
1792 change_impl (window, window, new_impl);
1794 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1796 /* Native window creation will put the native window topmost in the
1797 * native parent, which may be wrong wrt the position of the previous
1798 * non-native window wrt to the other non-native children, so correct this.
1800 above = find_native_sibling_above (window->parent, window);
1803 listhead.data = window;
1804 listhead.prev = NULL;
1805 listhead.next = NULL;
1806 impl_class->restack_under ((GdkWindow *)above, &listhead);
1809 recompute_visible_regions (window, FALSE, FALSE);
1811 /* The shape may not have been set, as the clip region doesn't actually
1812 change, so do it here manually */
1813 if (should_apply_clip_as_shape (window))
1814 apply_clip_as_shape (window);
1816 reparent_to_impl (window);
1818 if (!window->input_only)
1819 impl_class->set_background (window, window->background);
1821 impl_class->input_shape_combine_region (window,
1822 window->input_shape,
1825 if (gdk_window_is_viewable (window))
1826 impl_class->show (window, FALSE);
1832 * _gdk_event_filter_unref:
1833 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1834 * @filter: A window filter
1836 * Release a reference to @filter. Note this function may
1837 * mutate the list storage, so you need to handle this
1838 * if iterating over a list of filters.
1841 _gdk_event_filter_unref (GdkWindow *window,
1842 GdkEventFilter *filter)
1848 filters = &_gdk_default_filters;
1850 filters = &window->filters;
1852 tmp_list = *filters;
1855 GdkEventFilter *iter_filter = tmp_list->data;
1859 tmp_list = tmp_list->next;
1861 if (iter_filter != filter)
1864 g_assert (iter_filter->ref_count > 0);
1866 filter->ref_count--;
1867 if (filter->ref_count != 0)
1870 *filters = g_list_remove_link (*filters, node);
1872 g_list_free_1 (node);
1877 window_remove_filters (GdkWindow *window)
1879 while (window->filters)
1880 _gdk_event_filter_unref (window, window->filters->data);
1884 update_pointer_info_foreach (GdkDisplay *display,
1886 GdkPointerWindowInfo *pointer_info,
1889 GdkWindow *window = user_data;
1891 if (pointer_info->toplevel_under_pointer == window)
1893 g_object_unref (pointer_info->toplevel_under_pointer);
1894 pointer_info->toplevel_under_pointer = NULL;
1899 window_remove_from_pointer_info (GdkWindow *window,
1900 GdkDisplay *display)
1902 _gdk_display_pointer_info_foreach (display,
1903 update_pointer_info_foreach,
1908 * _gdk_window_destroy_hierarchy:
1909 * @window: a #GdkWindow
1910 * @recursing: If TRUE, then this is being called because a parent
1912 * @recursing_native: If TRUE, then this is being called because a native parent
1913 * was destroyed. This generally means that the call to the
1914 * windowing system to destroy the window can be omitted, since
1915 * it will be destroyed as a result of the parent being destroyed.
1916 * Unless @foreign_destroy.
1917 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1918 * external agency. The window has already been destroyed and no
1919 * windowing system calls should be made. (This may never happen
1920 * for some windowing systems.)
1922 * Internal function to destroy a window. Like gdk_window_destroy(),
1923 * but does not drop the reference count created by gdk_window_new().
1926 _gdk_window_destroy_hierarchy (GdkWindow *window,
1928 gboolean recursing_native,
1929 gboolean foreign_destroy)
1931 GdkWindowImplClass *impl_class;
1932 GdkWindow *temp_window;
1934 GdkDisplay *display;
1938 g_return_if_fail (GDK_IS_WINDOW (window));
1940 if (GDK_WINDOW_DESTROYED (window))
1943 display = gdk_window_get_display (window);
1944 screen = gdk_window_get_screen (window);
1945 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
1946 if (temp_window == window)
1947 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
1950 switch (window->window_type)
1952 case GDK_WINDOW_ROOT:
1953 if (!screen->closed)
1955 g_error ("attempted to destroy root window");
1958 /* else fall thru */
1959 case GDK_WINDOW_TOPLEVEL:
1960 case GDK_WINDOW_CHILD:
1961 case GDK_WINDOW_TEMP:
1962 case GDK_WINDOW_FOREIGN:
1963 case GDK_WINDOW_OFFSCREEN:
1964 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
1966 /* Logically, it probably makes more sense to send
1967 * a "destroy yourself" message to the foreign window
1968 * whether or not it's in our hierarchy; but for historical
1969 * reasons, we only send "destroy yourself" messages to
1970 * foreign windows in our hierarchy.
1974 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1976 if (gdk_window_has_impl (window))
1977 impl_class->destroy_foreign (window);
1980 /* Also for historical reasons, we remove any filters
1981 * on a foreign window when it or a parent is destroyed;
1982 * this likely causes problems if two separate portions
1983 * of code are maintaining filter lists on a foreign window.
1985 window_remove_filters (window);
1991 if (window->parent->children)
1992 window->parent->children = g_list_remove (window->parent->children, window);
1995 GDK_WINDOW_IS_MAPPED (window))
1997 recompute_visible_regions (window, TRUE, FALSE);
1998 gdk_window_invalidate_in_parent (window);
2002 gdk_window_free_paint_stack (window);
2004 if (window->background)
2006 cairo_pattern_destroy (window->background);
2007 window->background = NULL;
2010 if (window->window_type == GDK_WINDOW_FOREIGN)
2011 g_assert (window->children == NULL);
2014 children = tmp = window->children;
2015 window->children = NULL;
2019 temp_window = tmp->data;
2023 _gdk_window_destroy_hierarchy (temp_window,
2025 recursing_native || gdk_window_has_impl (window),
2029 g_list_free (children);
2032 _gdk_window_clear_update_area (window);
2034 gdk_window_drop_cairo_surface (window);
2036 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2038 if (gdk_window_has_impl (window))
2039 impl_class->destroy (window, recursing_native,
2043 /* hide to make sure we repaint and break grabs */
2044 gdk_window_hide (window);
2047 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2048 window->parent = NULL;
2049 window->destroyed = TRUE;
2051 window_remove_filters (window);
2053 window_remove_from_pointer_info (window, display);
2055 if (window->clip_region)
2057 cairo_region_destroy (window->clip_region);
2058 window->clip_region = NULL;
2061 if (window->clip_region_with_children)
2063 cairo_region_destroy (window->clip_region_with_children);
2064 window->clip_region_with_children = NULL;
2067 g_list_free_full (window->outstanding_moves, (GDestroyNotify) gdk_window_region_move_free);
2068 window->outstanding_moves = NULL;
2075 * _gdk_window_destroy:
2076 * @window: a #GdkWindow
2077 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2078 * external agency. The window has already been destroyed and no
2079 * windowing system calls should be made. (This may never happen
2080 * for some windowing systems.)
2082 * Internal function to destroy a window. Like gdk_window_destroy(),
2083 * but does not drop the reference count created by gdk_window_new().
2086 _gdk_window_destroy (GdkWindow *window,
2087 gboolean foreign_destroy)
2089 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2093 * gdk_window_destroy:
2094 * @window: a #GdkWindow
2096 * Destroys the window system resources associated with @window and decrements @window's
2097 * reference count. The window system resources for all children of @window are also
2098 * destroyed, but the children's reference counts are not decremented.
2100 * Note that a window will not be destroyed automatically when its reference count
2101 * reaches zero. You must call this function yourself before that happens.
2105 gdk_window_destroy (GdkWindow *window)
2107 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2108 g_object_unref (window);
2112 * gdk_window_set_user_data:
2113 * @window: a #GdkWindow
2114 * @user_data: (allow-none) (type GObject.Object): user data
2116 * For most purposes this function is deprecated in favor of
2117 * g_object_set_data(). However, for historical reasons GTK+ stores
2118 * the #GtkWidget that owns a #GdkWindow as user data on the
2119 * #GdkWindow. So, custom widget implementations should use
2120 * this function for that. If GTK+ receives an event for a #GdkWindow,
2121 * and the user data for the window is non-%NULL, GTK+ will assume the
2122 * user data is a #GtkWidget, and forward the event to that widget.
2126 gdk_window_set_user_data (GdkWindow *window,
2129 g_return_if_fail (GDK_IS_WINDOW (window));
2131 window->user_data = user_data;
2135 * gdk_window_get_user_data:
2136 * @window: a #GdkWindow
2137 * @data: (out): return location for user data
2139 * Retrieves the user data for @window, which is normally the widget
2140 * that @window belongs to. See gdk_window_set_user_data().
2144 gdk_window_get_user_data (GdkWindow *window,
2147 g_return_if_fail (GDK_IS_WINDOW (window));
2149 *data = window->user_data;
2153 * gdk_window_get_window_type:
2154 * @window: a #GdkWindow
2156 * Gets the type of the window. See #GdkWindowType.
2158 * Return value: type of window
2161 gdk_window_get_window_type (GdkWindow *window)
2163 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2165 return GDK_WINDOW_TYPE (window);
2169 * gdk_window_get_visual:
2170 * @window: a #GdkWindow
2172 * Gets the #GdkVisual describing the pixel format of @window.
2174 * Return value: (transfer none): a #GdkVisual
2179 gdk_window_get_visual (GdkWindow *window)
2181 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2183 return window->visual;
2187 * gdk_window_get_screen:
2188 * @window: a #GdkWindow
2190 * Gets the #GdkScreen associated with a #GdkWindow.
2192 * Return value: (transfer none): the #GdkScreen associated with @window
2197 gdk_window_get_screen (GdkWindow *window)
2199 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2201 return gdk_visual_get_screen (window->visual);
2205 * gdk_window_get_display:
2206 * @window: a #GdkWindow
2208 * Gets the #GdkDisplay associated with a #GdkWindow.
2210 * Return value: (transfer none): the #GdkDisplay associated with @window
2215 gdk_window_get_display (GdkWindow *window)
2217 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2219 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2222 * gdk_window_is_destroyed:
2223 * @window: a #GdkWindow
2225 * Check to see if a window is destroyed..
2227 * Return value: %TRUE if the window is destroyed
2232 gdk_window_is_destroyed (GdkWindow *window)
2234 return GDK_WINDOW_DESTROYED (window);
2238 to_embedder (GdkWindow *window,
2239 gdouble offscreen_x,
2240 gdouble offscreen_y,
2241 gdouble *embedder_x,
2242 gdouble *embedder_y)
2244 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2245 offscreen_x, offscreen_y,
2246 embedder_x, embedder_y);
2250 from_embedder (GdkWindow *window,
2253 gdouble *offscreen_x,
2254 gdouble *offscreen_y)
2256 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2257 embedder_x, embedder_y,
2258 offscreen_x, offscreen_y);
2262 * gdk_window_has_native:
2263 * @window: a #GdkWindow
2265 * Checks whether the window has a native window or not. Note that
2266 * you can use gdk_window_ensure_native() if a native window is needed.
2268 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2273 gdk_window_has_native (GdkWindow *window)
2275 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2277 return window->parent == NULL || window->parent->impl != window->impl;
2281 * gdk_window_get_position:
2282 * @window: a #GdkWindow
2283 * @x: (out) (allow-none): X coordinate of window
2284 * @y: (out) (allow-none): Y coordinate of window
2286 * Obtains the position of the window as reported in the
2287 * most-recently-processed #GdkEventConfigure. Contrast with
2288 * gdk_window_get_geometry() which queries the X server for the
2289 * current window position, regardless of which events have been
2290 * received or processed.
2292 * The position coordinates are relative to the window's parent window.
2296 gdk_window_get_position (GdkWindow *window,
2300 g_return_if_fail (GDK_IS_WINDOW (window));
2309 * gdk_window_get_parent:
2310 * @window: a #GdkWindow
2312 * Obtains the parent of @window, as known to GDK. Does not query the
2313 * X server; thus this returns the parent as passed to gdk_window_new(),
2314 * not the actual parent. This should never matter unless you're using
2315 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2316 * matter for toplevel windows, because the window manager may choose
2319 * Note that you should use gdk_window_get_effective_parent() when
2320 * writing generic code that walks up a window hierarchy, because
2321 * gdk_window_get_parent() will most likely not do what you expect if
2322 * there are offscreen windows in the hierarchy.
2324 * Return value: (transfer none): parent of @window
2327 gdk_window_get_parent (GdkWindow *window)
2329 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2331 return window->parent;
2335 * gdk_window_get_effective_parent:
2336 * @window: a #GdkWindow
2338 * Obtains the parent of @window, as known to GDK. Works like
2339 * gdk_window_get_parent() for normal windows, but returns the
2340 * window's embedder for offscreen windows.
2342 * See also: gdk_offscreen_window_get_embedder()
2344 * Return value: (transfer none): effective parent of @window
2349 gdk_window_get_effective_parent (GdkWindow *window)
2351 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2353 if (gdk_window_is_offscreen (window))
2354 return gdk_offscreen_window_get_embedder (window);
2356 return window->parent;
2360 * gdk_window_get_toplevel:
2361 * @window: a #GdkWindow
2363 * Gets the toplevel window that's an ancestor of @window.
2365 * Any window type but %GDK_WINDOW_CHILD is considered a
2366 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2367 * has a root window as parent.
2369 * Note that you should use gdk_window_get_effective_toplevel() when
2370 * you want to get to a window's toplevel as seen on screen, because
2371 * gdk_window_get_toplevel() will most likely not do what you expect
2372 * if there are offscreen windows in the hierarchy.
2374 * Return value: (transfer none): the toplevel window containing @window
2377 gdk_window_get_toplevel (GdkWindow *window)
2379 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2381 while (window->window_type == GDK_WINDOW_CHILD)
2383 if (gdk_window_is_toplevel (window))
2385 window = window->parent;
2392 * gdk_window_get_effective_toplevel:
2393 * @window: a #GdkWindow
2395 * Gets the toplevel window that's an ancestor of @window.
2397 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2398 * embedder as its parent, using gdk_window_get_effective_parent().
2400 * See also: gdk_offscreen_window_get_embedder()
2402 * Return value: (transfer none): the effective toplevel window containing @window
2407 gdk_window_get_effective_toplevel (GdkWindow *window)
2411 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2413 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2414 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2421 * gdk_window_get_children:
2422 * @window: a #GdkWindow
2424 * Gets the list of children of @window known to GDK.
2425 * This function only returns children created via GDK,
2426 * so for example it's useless when used with the root window;
2427 * it only returns windows an application created itself.
2429 * The returned list must be freed, but the elements in the
2432 * Return value: (transfer container) (element-type GdkWindow):
2433 * list of child windows inside @window
2436 gdk_window_get_children (GdkWindow *window)
2438 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2440 if (GDK_WINDOW_DESTROYED (window))
2443 return g_list_copy (window->children);
2447 * gdk_window_peek_children:
2448 * @window: a #GdkWindow
2450 * Like gdk_window_get_children(), but does not copy the list of
2451 * children, so the list does not need to be freed.
2453 * Return value: (transfer none) (element-type GdkWindow):
2454 * a reference to the list of child windows in @window
2457 gdk_window_peek_children (GdkWindow *window)
2459 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2461 if (GDK_WINDOW_DESTROYED (window))
2464 return window->children;
2468 * gdk_window_add_filter: (skip)
2469 * @window: (allow-none): a #GdkWindow
2470 * @function: filter callback
2471 * @data: data to pass to filter callback
2473 * Adds an event filter to @window, allowing you to intercept events
2474 * before they reach GDK. This is a low-level operation and makes it
2475 * easy to break GDK and/or GTK+, so you have to know what you're
2476 * doing. Pass %NULL for @window to get all events for all windows,
2477 * instead of events for a specific window.
2479 * If you are interested in X GenericEvents, bear in mind that
2480 * XGetEventData() has been already called on the event, and
2481 * XFreeEventData() must not be called within @function.
2484 gdk_window_add_filter (GdkWindow *window,
2485 GdkFilterFunc function,
2489 GdkEventFilter *filter;
2491 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2493 if (window && GDK_WINDOW_DESTROYED (window))
2496 /* Filters are for the native events on the native window, so
2497 ensure there is a native window. */
2499 gdk_window_ensure_native (window);
2502 tmp_list = window->filters;
2504 tmp_list = _gdk_default_filters;
2508 filter = (GdkEventFilter *)tmp_list->data;
2509 if ((filter->function == function) && (filter->data == data))
2511 filter->ref_count++;
2514 tmp_list = tmp_list->next;
2517 filter = g_new (GdkEventFilter, 1);
2518 filter->function = function;
2519 filter->data = data;
2520 filter->ref_count = 1;
2524 window->filters = g_list_append (window->filters, filter);
2526 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2530 * gdk_window_remove_filter: (skip)
2531 * @window: a #GdkWindow
2532 * @function: previously-added filter function
2533 * @data: user data for previously-added filter function
2535 * Remove a filter previously added with gdk_window_add_filter().
2538 gdk_window_remove_filter (GdkWindow *window,
2539 GdkFilterFunc function,
2543 GdkEventFilter *filter;
2545 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2548 tmp_list = window->filters;
2550 tmp_list = _gdk_default_filters;
2554 filter = (GdkEventFilter *)tmp_list->data;
2555 tmp_list = tmp_list->next;
2557 if ((filter->function == function) && (filter->data == data))
2559 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2561 _gdk_event_filter_unref (window, filter);
2569 * gdk_screen_get_toplevel_windows:
2570 * @screen: The #GdkScreen where the toplevels are located.
2572 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2573 * A toplevel window is a child of the root window (see
2574 * gdk_get_default_root_window()).
2576 * The returned list should be freed with g_list_free(), but
2577 * its elements need not be freed.
2579 * Return value: (transfer container) (element-type GdkWindow):
2580 * list of toplevel windows, free with g_list_free()
2585 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2587 GdkWindow * root_window;
2588 GList *new_list = NULL;
2591 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2593 root_window = gdk_screen_get_root_window (screen);
2595 tmp_list = root_window->children;
2598 GdkWindow *w = tmp_list->data;
2600 if (w->window_type != GDK_WINDOW_FOREIGN)
2601 new_list = g_list_prepend (new_list, w);
2602 tmp_list = tmp_list->next;
2609 * gdk_window_is_visible:
2610 * @window: a #GdkWindow
2612 * Checks whether the window has been mapped (with gdk_window_show() or
2613 * gdk_window_show_unraised()).
2615 * Return value: %TRUE if the window is mapped
2618 gdk_window_is_visible (GdkWindow *window)
2620 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2622 return GDK_WINDOW_IS_MAPPED (window);
2626 * gdk_window_is_viewable:
2627 * @window: a #GdkWindow
2629 * Check if the window and all ancestors of the window are
2630 * mapped. (This is not necessarily "viewable" in the X sense, since
2631 * we only check as far as we have GDK window parents, not to the root
2634 * Return value: %TRUE if the window is viewable
2637 gdk_window_is_viewable (GdkWindow *window)
2639 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2641 if (window->destroyed)
2644 return window->viewable;
2648 * gdk_window_get_state:
2649 * @window: a #GdkWindow
2651 * Gets the bitwise OR of the currently active window state flags,
2652 * from the #GdkWindowState enumeration.
2654 * Return value: window state bitfield
2657 gdk_window_get_state (GdkWindow *window)
2659 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2661 return window->state;
2664 static cairo_content_t
2665 gdk_window_get_content (GdkWindow *window)
2667 cairo_surface_t *surface;
2668 cairo_content_t content;
2670 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2672 surface = _gdk_window_ref_cairo_surface (window);
2673 content = cairo_surface_get_content (surface);
2674 cairo_surface_destroy (surface);
2679 /* This creates an empty "implicit" paint region for the impl window.
2680 * By itself this does nothing, but real paints to this window
2681 * or children of it can use this surface as backing to avoid allocating
2682 * multiple surfaces for subwindow rendering. When doing so they
2683 * add to the region of the implicit paint region, which will be
2684 * pushed to the window when the implicit paint region is ended.
2685 * Such paints should not copy anything to the window on paint end, but
2686 * should rely on the implicit paint end.
2687 * The implicit paint will be automatically ended if someone draws
2688 * directly to the window or a child window.
2691 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
2693 GdkWindowPaint *paint;
2695 g_assert (gdk_window_has_impl (window));
2697 if (GDK_IS_PAINTABLE (window->impl))
2698 return FALSE; /* Implementation does double buffering */
2700 if (window->paint_stack != NULL ||
2701 window->implicit_paint != NULL)
2702 return FALSE; /* Don't stack implicit paints */
2704 /* Never do implicit paints for foreign windows, they don't need
2705 * double buffer combination since they have no client side children,
2706 * and creating surfaces for them is risky since they could disappear
2709 if (window->window_type == GDK_WINDOW_FOREIGN)
2712 paint = g_new (GdkWindowPaint, 1);
2713 paint->region = cairo_region_create (); /* Empty */
2714 paint->uses_implicit = FALSE;
2715 paint->flushed = NULL;
2716 paint->surface = gdk_window_create_similar_surface (window,
2717 gdk_window_get_content (window),
2718 MAX (rect->width, 1),
2719 MAX (rect->height, 1));
2720 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2722 window->implicit_paint = paint;
2727 static cairo_surface_t *
2728 gdk_window_ref_impl_surface (GdkWindow *window)
2730 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2734 gdk_cairo_create_for_impl (GdkWindow *window)
2736 cairo_surface_t *surface;
2739 surface = gdk_window_ref_impl_surface (window);
2740 cr = cairo_create (surface);
2742 cairo_surface_destroy (surface);
2747 /* Ensure that all content related to this (sub)window is pushed to the
2748 native region. If there is an active paint then that area is not
2749 pushed, in order to not show partially finished double buffers. */
2751 gdk_window_flush_implicit_paint (GdkWindow *window)
2753 GdkWindow *impl_window;
2754 GdkWindowPaint *paint;
2755 cairo_region_t *region;
2758 impl_window = gdk_window_get_impl_window (window);
2759 if (impl_window->implicit_paint == NULL)
2762 paint = impl_window->implicit_paint;
2763 region = cairo_region_copy (window->clip_region_with_children);
2765 cairo_region_translate (region, window->abs_x, window->abs_y);
2767 if (paint->flushed == NULL)
2768 paint->flushed = cairo_region_copy (region);
2770 cairo_region_union (paint->flushed, region);
2772 cairo_region_intersect (region, paint->region);
2774 /* Don't flush active double buffers, as that may show partially done
2776 for (list = window->paint_stack; list != NULL; list = list->next)
2778 GdkWindowPaint *tmp_paint = list->data;
2780 cairo_region_subtract (region, tmp_paint->region);
2783 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (region))
2787 /* Remove flushed region from the implicit paint */
2788 cairo_region_subtract (paint->region, region);
2790 /* Some regions are valid, push these to window now */
2791 cr = gdk_cairo_create_for_impl (window);
2792 gdk_cairo_region (cr, region);
2794 cairo_set_source_surface (cr, paint->surface, 0, 0);
2795 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2800 cairo_region_destroy (region);
2803 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2805 gdk_window_end_implicit_paint (GdkWindow *window)
2807 GdkWindowPaint *paint;
2809 g_assert (gdk_window_has_impl (window));
2811 g_assert (window->implicit_paint != NULL);
2813 paint = window->implicit_paint;
2815 window->implicit_paint = NULL;
2817 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region))
2821 /* Some regions are valid, push these to window now */
2822 cr = gdk_cairo_create_for_impl (window);
2823 gdk_cairo_region (cr, paint->region);
2825 cairo_set_source_surface (cr, paint->surface, 0, 0);
2826 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2831 cairo_region_destroy (paint->region);
2833 cairo_region_destroy (paint->flushed);
2834 cairo_surface_destroy (paint->surface);
2839 * gdk_window_begin_paint_rect:
2840 * @window: a #GdkWindow
2841 * @rectangle: rectangle you intend to draw to
2843 * A convenience wrapper around gdk_window_begin_paint_region() which
2844 * creates a rectangular region for you. See
2845 * gdk_window_begin_paint_region() for details.
2849 gdk_window_begin_paint_rect (GdkWindow *window,
2850 const GdkRectangle *rectangle)
2852 cairo_region_t *region;
2854 g_return_if_fail (GDK_IS_WINDOW (window));
2856 region = cairo_region_create_rectangle (rectangle);
2857 gdk_window_begin_paint_region (window, region);
2858 cairo_region_destroy (region);
2862 * gdk_window_begin_paint_region:
2863 * @window: a #GdkWindow
2864 * @region: region you intend to draw to
2866 * Indicates that you are beginning the process of redrawing @region.
2867 * A backing store (offscreen buffer) large enough to contain @region
2868 * will be created. The backing store will be initialized with the
2869 * background color or background surface for @window. Then, all
2870 * drawing operations performed on @window will be diverted to the
2871 * backing store. When you call gdk_window_end_paint(), the backing
2872 * store will be copied to @window, making it visible onscreen. Only
2873 * the part of @window contained in @region will be modified; that is,
2874 * drawing operations are clipped to @region.
2876 * The net result of all this is to remove flicker, because the user
2877 * sees the finished product appear all at once when you call
2878 * gdk_window_end_paint(). If you draw to @window directly without
2879 * calling gdk_window_begin_paint_region(), the user may see flicker
2880 * as individual drawing operations are performed in sequence. The
2881 * clipping and background-initializing features of
2882 * gdk_window_begin_paint_region() are conveniences for the
2883 * programmer, so you can avoid doing that work yourself.
2885 * When using GTK+, the widget system automatically places calls to
2886 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
2887 * emissions of the expose_event signal. That is, if you're writing an
2888 * expose event handler, you can assume that the exposed area in
2889 * #GdkEventExpose has already been cleared to the window background,
2890 * is already set as the clip region, and already has a backing store.
2891 * Therefore in most cases, application code need not call
2892 * gdk_window_begin_paint_region(). (You can disable the automatic
2893 * calls around expose events on a widget-by-widget basis by calling
2894 * gtk_widget_set_double_buffered().)
2896 * If you call this function multiple times before calling the
2897 * matching gdk_window_end_paint(), the backing stores are pushed onto
2898 * a stack. gdk_window_end_paint() copies the topmost backing store
2899 * onscreen, subtracts the topmost region from all other regions in
2900 * the stack, and pops the stack. All drawing operations affect only
2901 * the topmost backing store in the stack. One matching call to
2902 * gdk_window_end_paint() is required for each call to
2903 * gdk_window_begin_paint_region().
2907 gdk_window_begin_paint_region (GdkWindow *window,
2908 const cairo_region_t *region)
2910 #ifdef USE_BACKING_STORE
2911 GdkRectangle clip_box;
2912 GdkWindowPaint *paint, *implicit_paint;
2913 GdkWindow *impl_window;
2916 g_return_if_fail (GDK_IS_WINDOW (window));
2918 if (GDK_WINDOW_DESTROYED (window))
2921 if (GDK_IS_PAINTABLE (window->impl))
2923 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
2925 if (iface->begin_paint_region)
2926 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
2931 impl_window = gdk_window_get_impl_window (window);
2932 implicit_paint = impl_window->implicit_paint;
2934 paint = g_new (GdkWindowPaint, 1);
2935 paint->region = cairo_region_copy (region);
2937 cairo_region_intersect (paint->region, window->clip_region_with_children);
2938 cairo_region_get_extents (paint->region, &clip_box);
2940 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
2942 /* Mark the region as valid on the implicit paint */
2945 cairo_region_union (implicit_paint->region, paint->region);
2947 /* Convert back to normal coords */
2948 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
2952 paint->uses_implicit = TRUE;
2953 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
2954 window->abs_x + clip_box.x,
2955 window->abs_y + clip_box.y,
2956 MAX (clip_box.width, 1),
2957 MAX (clip_box.height, 1));
2961 paint->uses_implicit = FALSE;
2962 paint->surface = gdk_window_create_similar_surface (window,
2963 gdk_window_get_content (window),
2964 MAX (clip_box.width, 1),
2965 MAX (clip_box.height, 1));
2968 /* Normally alpha backgrounded client side windows are composited on the implicit paint
2969 by being drawn in back to front order. However, if implicit paints are not used, for
2970 instance if it was flushed due to a non-double-buffered paint in the middle of the
2971 expose we need to copy in the existing data here. */
2972 if (!gdk_window_has_impl (window) &&
2973 window->has_alpha_background &&
2975 (implicit_paint && implicit_paint->flushed != NULL && !cairo_region_is_empty (implicit_paint->flushed))))
2977 cairo_t *cr = cairo_create (paint->surface);
2978 /* We can't use gdk_cairo_set_source_window here, as that might
2979 flush the implicit paint at an unfortunate time, since this
2980 would be detected as a draw during non-expose time */
2981 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (impl_window);
2982 cairo_set_source_surface (cr, source_surface,
2983 - (window->abs_x + clip_box.x),
2984 - (window->abs_y + clip_box.y));
2985 cairo_surface_destroy (source_surface);
2987 /* Only read back the flushed area if any */
2990 cairo_region_t *flushed = cairo_region_copy (implicit_paint->flushed);
2991 /* Convert from impl coords */
2992 cairo_region_translate (flushed, -window->abs_x, -window->abs_y);
2993 cairo_region_intersect (flushed, paint->region);
2994 gdk_cairo_region (cr, flushed);
2997 /* Convert to impl coords */
2998 cairo_region_translate (flushed, window->abs_x, window->abs_y);
2999 cairo_region_subtract (implicit_paint->flushed, flushed);
3000 cairo_region_destroy (flushed);
3006 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3008 for (list = window->paint_stack; list != NULL; list = list->next)
3010 GdkWindowPaint *tmp_paint = list->data;
3012 cairo_region_subtract (tmp_paint->region, paint->region);
3015 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
3017 if (!cairo_region_is_empty (paint->region))
3019 gdk_window_clear_backing_region (window,
3023 #endif /* USE_BACKING_STORE */
3027 * gdk_window_end_paint:
3028 * @window: a #GdkWindow
3030 * Indicates that the backing store created by the most recent call to
3031 * gdk_window_begin_paint_region() should be copied onscreen and
3032 * deleted, leaving the next-most-recent backing store or no backing
3033 * store at all as the active paint region. See
3034 * gdk_window_begin_paint_region() for full details. It is an error to
3035 * call this function without a matching
3036 * gdk_window_begin_paint_region() first.
3040 gdk_window_end_paint (GdkWindow *window)
3042 #ifdef USE_BACKING_STORE
3043 GdkWindow *composited;
3044 GdkWindowPaint *paint;
3045 GdkRectangle clip_box;
3046 cairo_region_t *full_clip;
3048 g_return_if_fail (GDK_IS_WINDOW (window));
3050 if (GDK_WINDOW_DESTROYED (window))
3053 if (GDK_IS_PAINTABLE (window->impl))
3055 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3057 if (iface->end_paint)
3058 iface->end_paint ((GdkPaintable*)window->impl);
3062 if (window->paint_stack == NULL)
3064 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3068 paint = window->paint_stack->data;
3070 window->paint_stack = g_slist_delete_link (window->paint_stack,
3071 window->paint_stack);
3073 cairo_region_get_extents (paint->region, &clip_box);
3075 if (!paint->uses_implicit)
3079 gdk_window_flush_outstanding_moves (window);
3081 full_clip = cairo_region_copy (window->clip_region_with_children);
3082 cairo_region_intersect (full_clip, paint->region);
3084 cr = gdk_cairo_create (window);
3085 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3086 cairo_set_source_surface (cr, paint->surface, 0, 0);
3087 gdk_cairo_region (cr, full_clip);
3091 cairo_region_destroy (full_clip);
3094 cairo_surface_destroy (paint->surface);
3095 cairo_region_destroy (paint->region);
3098 /* find a composited window in our hierarchy to signal its
3099 * parent to redraw, calculating the clip box as we go...
3101 * stop if parent becomes NULL since then we'd have nowhere
3102 * to draw (ie: 'composited' will always be non-NULL here).
3104 for (composited = window;
3106 composited = composited->parent)
3108 clip_box.x += composited->x;
3109 clip_box.y += composited->y;
3110 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3111 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3113 if (composited->composited)
3115 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3120 #endif /* USE_BACKING_STORE */
3124 gdk_window_free_paint_stack (GdkWindow *window)
3126 if (window->paint_stack)
3128 GSList *tmp_list = window->paint_stack;
3132 GdkWindowPaint *paint = tmp_list->data;
3134 if (tmp_list == window->paint_stack)
3135 cairo_surface_destroy (paint->surface);
3137 cairo_region_destroy (paint->region);
3140 tmp_list = tmp_list->next;
3143 g_slist_free (window->paint_stack);
3144 window->paint_stack = NULL;
3149 do_move_region_bits_on_impl (GdkWindow *impl_window,
3150 cairo_region_t *dest_region, /* In impl window coords */
3153 GdkWindowImplClass *impl_class;
3155 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3157 impl_class->translate (impl_window, dest_region, dx, dy);
3160 static GdkWindowRegionMove *
3161 gdk_window_region_move_new (cairo_region_t *region,
3164 GdkWindowRegionMove *move;
3166 move = g_slice_new (GdkWindowRegionMove);
3167 move->dest_region = cairo_region_copy (region);
3175 gdk_window_region_move_free (GdkWindowRegionMove *move)
3177 cairo_region_destroy (move->dest_region);
3178 g_slice_free (GdkWindowRegionMove, move);
3182 append_move_region (GdkWindow *impl_window,
3183 cairo_region_t *new_dest_region,
3186 GdkWindowRegionMove *move, *old_move;
3187 cairo_region_t *new_total_region, *old_total_region;
3188 cairo_region_t *source_overlaps_destination;
3189 cairo_region_t *non_overwritten;
3190 gboolean added_move;
3193 if (cairo_region_is_empty (new_dest_region))
3196 /* In principle this could just append the move to the list of outstanding
3197 moves that will be replayed before drawing anything when we're handling
3198 exposes. However, we'd like to do a bit better since its commonly the case
3199 that we get multiple copies where A is copied to B and then B is copied
3200 to C, and we'd like to express this as a simple copy A to C operation. */
3202 /* We approach this by taking the new move and pushing it ahead of moves
3203 starting at the end of the list and stopping when its not safe to do so.
3204 It's not safe to push past a move if either the source of the new move
3205 is in the destination of the old move, or if the destination of the new
3206 move is in the source of the new move, or if the destination of the new
3207 move overlaps the destination of the old move. We simplify this by
3208 just comparing the total regions (src + dest) */
3209 new_total_region = cairo_region_copy (new_dest_region);
3210 cairo_region_translate (new_total_region, -dx, -dy);
3211 cairo_region_union (new_total_region, new_dest_region);
3214 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3219 old_total_region = cairo_region_copy (old_move->dest_region);
3220 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3221 cairo_region_union (old_total_region, old_move->dest_region);
3223 cairo_region_intersect (old_total_region, new_total_region);
3224 /* If these regions intersect then its not safe to push the
3225 new region before the old one */
3226 if (!cairo_region_is_empty (old_total_region))
3228 /* The area where the new moves source overlaps the old ones
3230 source_overlaps_destination = cairo_region_copy (new_dest_region);
3231 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3232 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3233 cairo_region_translate (source_overlaps_destination, dx, dy);
3235 /* We can do all sort of optimizations here, but to do things safely it becomes
3236 quite complicated. However, a very common case is that you copy something first,
3237 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3238 in the same direction). We'd like to detect this case and optimize it to one
3240 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3242 /* This means we might be able to replace the old move and the new one
3243 with the new one read from the old ones source, and a second copy of
3244 the non-overwritten parts of the old move. However, such a split
3245 is only valid if the source in the old move isn't overwritten
3246 by the destination of the new one */
3248 /* the new destination of old move if split is ok: */
3249 non_overwritten = cairo_region_copy (old_move->dest_region);
3250 cairo_region_subtract (non_overwritten, new_dest_region);
3251 /* move to source region */
3252 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3254 cairo_region_intersect (non_overwritten, new_dest_region);
3255 if (cairo_region_is_empty (non_overwritten))
3258 move = gdk_window_region_move_new (new_dest_region,
3262 impl_window->outstanding_moves =
3263 g_list_insert_before (impl_window->outstanding_moves,
3265 cairo_region_subtract (old_move->dest_region, new_dest_region);
3267 cairo_region_destroy (non_overwritten);
3270 cairo_region_destroy (source_overlaps_destination);
3271 cairo_region_destroy (old_total_region);
3274 cairo_region_destroy (old_total_region);
3277 cairo_region_destroy (new_total_region);
3281 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3284 impl_window->outstanding_moves =
3285 g_list_prepend (impl_window->outstanding_moves,
3288 impl_window->outstanding_moves =
3289 g_list_insert_before (impl_window->outstanding_moves,
3294 /* Moves bits and update area by dx/dy in impl window.
3295 Takes ownership of region to avoid copy (because we may change it) */
3297 move_region_on_impl (GdkWindow *impl_window,
3298 cairo_region_t *region, /* In impl window coords */
3301 if ((dx == 0 && dy == 0) ||
3302 cairo_region_is_empty (region))
3304 cairo_region_destroy (region);
3308 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3310 /* Move any old invalid regions in the copy source area by dx/dy */
3311 if (impl_window->update_area)
3313 cairo_region_t *update_area;
3315 update_area = cairo_region_copy (region);
3317 /* Convert from target to source */
3318 cairo_region_translate (update_area, -dx, -dy);
3319 cairo_region_intersect (update_area, impl_window->update_area);
3320 /* We only copy the area, so keep the old update area invalid.
3321 It would be safe to remove it too, as code that uses
3322 move_region_on_impl generally also invalidate the source
3323 area. However, it would just use waste cycles. */
3326 cairo_region_translate (update_area, dx, dy);
3327 cairo_region_union (impl_window->update_area, update_area);
3329 /* This area of the destination is now invalid,
3330 so no need to copy to it. */
3331 cairo_region_subtract (region, update_area);
3333 cairo_region_destroy (update_area);
3336 /* If we're currently exposing this window, don't copy to this
3337 destination, as it will be overdrawn when the expose is done,
3338 instead invalidate it and repaint later. */
3339 if (impl_window->implicit_paint)
3341 GdkWindowPaint *implicit_paint = impl_window->implicit_paint;
3342 cairo_region_t *exposing;
3344 exposing = cairo_region_copy (implicit_paint->region);
3345 cairo_region_intersect (exposing, region);
3346 cairo_region_subtract (region, exposing);
3348 impl_window_add_update_area (impl_window, exposing);
3349 cairo_region_destroy (exposing);
3352 append_move_region (impl_window, region, dx, dy);
3354 cairo_region_destroy (region);
3357 /* Flushes all outstanding changes to the window, call this
3358 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3361 gdk_window_flush_outstanding_moves (GdkWindow *window)
3363 GdkWindow *impl_window;
3364 GList *l, *outstanding;
3365 GdkWindowRegionMove *move;
3367 impl_window = gdk_window_get_impl_window (window);
3368 outstanding = impl_window->outstanding_moves;
3369 impl_window->outstanding_moves = NULL;
3371 for (l = outstanding; l != NULL; l = l->next)
3375 do_move_region_bits_on_impl (impl_window,
3376 move->dest_region, move->dx, move->dy);
3378 gdk_window_region_move_free (move);
3381 g_list_free (outstanding);
3386 * @window: a #GdkWindow
3388 * Flush all outstanding cached operations on a window, leaving the
3389 * window in a state which reflects all that has been drawn before.
3391 * Gdk uses multiple kinds of caching to get better performance and
3392 * nicer drawing. For instance, during exposes all paints to a window
3393 * using double buffered rendering are keep on a surface until the last
3394 * window has been exposed. It also delays window moves/scrolls until
3395 * as long as possible until next update to avoid tearing when moving
3398 * Normally this should be completely invisible to applications, as
3399 * we automatically flush the windows when required, but this might
3400 * be needed if you for instance mix direct native drawing with
3401 * gdk drawing. For Gtk widgets that don't use double buffering this
3402 * will be called automatically before sending the expose event.
3407 gdk_window_flush (GdkWindow *window)
3409 gdk_window_flush_outstanding_moves (window);
3410 gdk_window_flush_implicit_paint (window);
3413 /* If we're about to move/resize or otherwise change the
3414 * hierarchy of a client side window in an impl and we're
3415 * called from an expose event handler then we need to
3416 * flush any already painted parts of the implicit paint
3417 * that are not part of the current paint, as these may
3418 * be used when scrolling or may overdraw the changes
3419 * caused by the hierarchy change.
3422 gdk_window_flush_if_exposing (GdkWindow *window)
3424 GdkWindow *impl_window;
3426 impl_window = gdk_window_get_impl_window (window);
3428 /* If we're in an implicit paint (i.e. in an expose handler, flush
3429 all the already finished exposes to get things to an uptodate state. */
3430 if (impl_window->implicit_paint)
3431 gdk_window_flush (window);
3436 gdk_window_flush_recursive_helper (GdkWindow *window,
3437 GdkWindowImpl *impl)
3442 for (l = window->children; l != NULL; l = l->next)
3446 if (child->impl == impl)
3447 /* Same impl, ignore */
3448 gdk_window_flush_recursive_helper (child, impl);
3450 gdk_window_flush_recursive (child);
3455 gdk_window_flush_recursive (GdkWindow *window)
3457 gdk_window_flush (window);
3458 gdk_window_flush_recursive_helper (window, window->impl);
3462 * gdk_window_get_clip_region:
3463 * @window: a #GdkWindow
3465 * Computes the region of a window that potentially can be written
3466 * to by drawing primitives. This region may not take into account
3467 * other factors such as if the window is obscured by other windows,
3468 * but no area outside of this region will be affected by drawing
3471 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3472 * when you are done.
3475 gdk_window_get_clip_region (GdkWindow *window)
3477 cairo_region_t *result;
3479 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3481 result = cairo_region_copy (window->clip_region);
3483 if (window->paint_stack)
3485 cairo_region_t *paint_region = cairo_region_create ();
3486 GSList *tmp_list = window->paint_stack;
3490 GdkWindowPaint *paint = tmp_list->data;
3492 cairo_region_union (paint_region, paint->region);
3494 tmp_list = tmp_list->next;
3497 cairo_region_intersect (result, paint_region);
3498 cairo_region_destroy (paint_region);
3505 * gdk_window_get_visible_region:
3506 * @window: a #GdkWindow
3508 * Computes the region of the @window that is potentially visible.
3509 * This does not necessarily take into account if the window is
3510 * obscured by other windows, but no area outside of this region
3513 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3514 * when you are done.
3517 gdk_window_get_visible_region (GdkWindow *window)
3519 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3521 return cairo_region_copy (window->clip_region);
3525 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint)
3527 GdkWindow *bg_window;
3528 cairo_pattern_t *pattern = NULL;
3529 int x_offset = 0, y_offset = 0;
3532 cr = cairo_create (paint->surface);
3534 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3536 pattern = gdk_window_get_background_pattern (bg_window);
3540 x_offset += bg_window->x;
3541 y_offset += bg_window->y;
3546 cairo_translate (cr, -x_offset, -y_offset);
3547 cairo_set_source (cr, pattern);
3548 cairo_translate (cr, x_offset, y_offset);
3551 cairo_set_source_rgb (cr, 0, 0, 0);
3557 gdk_window_clear_backing_region (GdkWindow *window,
3558 cairo_region_t *region)
3560 GdkWindowPaint *paint = window->paint_stack->data;
3561 cairo_region_t *clip;
3564 if (GDK_WINDOW_DESTROYED (window))
3567 cr = setup_backing_rect (window, paint);
3569 clip = cairo_region_copy (paint->region);
3570 cairo_region_intersect (clip, region);
3572 gdk_cairo_region (cr, clip);
3577 cairo_region_destroy (clip);
3581 gdk_window_drop_cairo_surface (GdkWindow *window)
3583 if (window->cairo_surface)
3585 cairo_surface_finish (window->cairo_surface);
3586 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3588 window->cairo_surface = NULL;
3593 gdk_window_cairo_surface_destroy (void *data)
3595 GdkWindow *window = data;
3597 window->cairo_surface = NULL;
3600 static cairo_surface_t *
3601 gdk_window_create_cairo_surface (GdkWindow *window,
3605 cairo_surface_t *surface, *subsurface;
3607 surface = gdk_window_ref_impl_surface (window);
3608 if (gdk_window_has_impl (window))
3611 subsurface = cairo_surface_create_for_rectangle (surface,
3616 cairo_surface_destroy (surface);
3622 _gdk_window_ref_cairo_surface (GdkWindow *window)
3624 cairo_surface_t *surface;
3626 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3628 if (window->paint_stack)
3630 GdkWindowPaint *paint = window->paint_stack->data;
3632 surface = paint->surface;
3633 cairo_surface_reference (surface);
3638 /* This will be drawing directly to the window, so flush implicit paint */
3639 gdk_window_flush (window);
3641 if (!window->cairo_surface)
3643 window->cairo_surface = gdk_window_create_cairo_surface (window,
3647 if (window->cairo_surface)
3649 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3650 window, gdk_window_cairo_surface_destroy);
3654 cairo_surface_reference (window->cairo_surface);
3656 surface = window->cairo_surface;
3664 * @window: a #GdkWindow
3666 * Creates a Cairo context for drawing to @window.
3669 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3670 * produce undefined results, so avoid it at all costs.
3673 * Return value: A newly created Cairo context. Free with
3674 * cairo_destroy() when you are done drawing.
3679 gdk_cairo_create (GdkWindow *window)
3681 cairo_surface_t *surface;
3684 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3686 surface = _gdk_window_ref_cairo_surface (window);
3687 cr = cairo_create (surface);
3689 if (!window->paint_stack)
3691 gdk_cairo_region (cr, window->clip_region_with_children);
3696 GdkWindowPaint *paint = window->paint_stack->data;
3698 /* Only needs to clip to region if piggybacking
3699 on an implicit paint */
3700 if (paint->uses_implicit)
3702 gdk_cairo_region (cr, paint->region);
3707 cairo_surface_destroy (surface);
3712 /* Code for dirty-region queueing
3714 static GSList *update_windows = NULL;
3715 static guint update_idle = 0;
3716 static gboolean debug_updates = FALSE;
3718 static inline gboolean
3719 gdk_window_is_ancestor (GdkWindow *window,
3720 GdkWindow *ancestor)
3724 GdkWindow *parent = window->parent;
3726 if (parent == ancestor)
3736 gdk_window_add_update_window (GdkWindow *window)
3739 GSList *prev = NULL;
3740 gboolean has_ancestor_in_list = FALSE;
3742 for (tmp = update_windows; tmp; tmp = tmp->next)
3744 GdkWindow *parent = window->parent;
3746 /* check if tmp is an ancestor of "window"; if it is, set a
3747 * flag indicating that all following windows are either
3748 * children of "window" or from a differen hierarchy
3750 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3751 has_ancestor_in_list = TRUE;
3753 /* insert in reverse stacking order when adding around siblings,
3754 * so processing updates properly paints over lower stacked windows
3756 if (parent == GDK_WINDOW (tmp->data)->parent)
3758 gint index = g_list_index (parent->children, window);
3759 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3761 gint sibling_index = g_list_index (parent->children, tmp->data);
3762 if (index > sibling_index)
3766 /* here, tmp got advanced past all lower stacked siblings */
3767 tmp = g_slist_prepend (tmp, window);
3771 update_windows = tmp;
3775 /* if "window" has an ancestor in the list and tmp is one of
3776 * "window's" children, insert "window" before tmp
3778 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3780 tmp = g_slist_prepend (tmp, window);
3785 update_windows = tmp;
3789 /* if we're at the end of the list and had an ancestor it it,
3790 * append to the list
3792 if (! tmp->next && has_ancestor_in_list)
3794 tmp = g_slist_append (tmp, window);
3801 /* if all above checks failed ("window" is from a different
3802 * hierarchy than what is already in the list) or the list is
3805 update_windows = g_slist_prepend (update_windows, window);
3809 gdk_window_remove_update_window (GdkWindow *window)
3811 update_windows = g_slist_remove (update_windows, window);
3815 gdk_window_update_idle (gpointer data)
3817 gdk_window_process_all_updates ();
3823 gdk_window_is_toplevel_frozen (GdkWindow *window)
3825 GdkWindow *toplevel;
3827 toplevel = gdk_window_get_toplevel (window);
3829 return toplevel->update_and_descendants_freeze_count > 0;
3833 gdk_window_schedule_update (GdkWindow *window)
3836 (window->update_freeze_count ||
3837 gdk_window_is_toplevel_frozen (window)))
3842 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
3843 gdk_window_update_idle,
3848 _gdk_window_process_updates_recurse (GdkWindow *window,
3849 cairo_region_t *expose_region)
3852 cairo_region_t *clipped_expose_region;
3853 GList *l, *children;
3855 if (cairo_region_is_empty (expose_region))
3858 if (gdk_window_is_offscreen (window->impl_window) &&
3859 gdk_window_has_impl (window))
3860 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3863 /* Paint the window before the children, clipped to the window region
3864 with visible child windows removed */
3865 clipped_expose_region = cairo_region_copy (expose_region);
3866 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3868 if (!cairo_region_is_empty (clipped_expose_region) &&
3871 if (window->event_mask & GDK_EXPOSURE_MASK)
3875 event.expose.type = GDK_EXPOSE;
3876 event.expose.window = g_object_ref (window);
3877 event.expose.send_event = FALSE;
3878 event.expose.count = 0;
3879 event.expose.region = clipped_expose_region;
3880 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
3882 _gdk_event_emit (&event);
3884 g_object_unref (window);
3886 else if (window->window_type != GDK_WINDOW_FOREIGN)
3888 /* No exposure mask set, so nothing will be drawn, the
3889 * app relies on the background being what it specified
3890 * for the window. So, we need to clear this manually.
3892 * For foreign windows if expose is not set that generally
3893 * means some other client paints them, so don't clear
3896 * We use begin/end_paint around the clear so that we can
3897 * piggyback on the implicit paint */
3899 gdk_window_begin_paint_region (window, clipped_expose_region);
3900 /* The actual clear happens in begin_paint_region */
3901 gdk_window_end_paint (window);
3904 cairo_region_destroy (clipped_expose_region);
3906 /* Make this reentrancy safe for expose handlers freeing windows */
3907 children = g_list_copy (window->children);
3908 g_list_foreach (children, (GFunc)g_object_ref, NULL);
3910 /* Iterate over children, starting at bottommost */
3911 for (l = g_list_last (children); l != NULL; l = l->prev)
3915 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
3918 /* Ignore offscreen children, as they don't draw in their parent and
3919 * don't take part in the clipping */
3920 if (gdk_window_is_offscreen (child))
3923 /* Client side child, expose */
3924 if (child->impl == window->impl)
3926 cairo_region_translate (expose_region, -child->x, -child->y);
3927 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
3928 cairo_region_translate (expose_region, child->x, child->y);
3932 g_list_free_full (children, g_object_unref);
3936 /* Process and remove any invalid area on the native window by creating
3937 * expose events for the window and all non-native descendants.
3938 * Also processes any outstanding moves on the window before doing
3939 * any drawing. Note that its possible to have outstanding moves without
3940 * any invalid area as we use the update idle mechanism to coalesce
3941 * multiple moves as well as multiple invalidations.
3944 gdk_window_process_updates_internal (GdkWindow *window)
3946 GdkWindowImplClass *impl_class;
3947 gboolean save_region = FALSE;
3948 GdkRectangle clip_box;
3950 /* Ensure the window lives while updating it */
3951 g_object_ref (window);
3953 /* If an update got queued during update processing, we can get a
3954 * window in the update queue that has an empty update_area.
3957 if (window->update_area)
3959 cairo_region_t *update_area = window->update_area;
3960 window->update_area = NULL;
3962 if (gdk_window_is_viewable (window))
3964 cairo_region_t *expose_region;
3965 gboolean end_implicit;
3967 /* Clip to part visible in toplevel */
3968 cairo_region_intersect (update_area, window->clip_region);
3972 /* Make sure we see the red invalid area before redrawing. */
3973 gdk_display_sync (gdk_window_get_display (window));
3977 /* At this point we will be completely redrawing all of update_area.
3978 * If we have any outstanding moves that end up moving stuff inside
3979 * this area we don't actually need to move that as that part would
3980 * be overdrawn by the expose anyway. So, in order to copy less data
3981 * we remove these areas from the outstanding moves.
3983 if (window->outstanding_moves)
3985 GdkWindowRegionMove *move;
3986 cairo_region_t *remove;
3989 remove = cairo_region_copy (update_area);
3990 /* We iterate backwards, starting from the state that would be
3991 if we had applied all the moves. */
3992 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
3997 /* Don't need this area */
3998 cairo_region_subtract (move->dest_region, remove);
4000 /* However if any of the destination we do need has a source
4001 in the updated region we do need that as a destination for
4002 the earlier moves */
4003 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4004 cairo_region_subtract (remove, move->dest_region);
4006 if (cairo_region_is_empty (move->dest_region))
4008 gdk_window_region_move_free (move);
4009 window->outstanding_moves =
4010 g_list_delete_link (window->outstanding_moves, l);
4012 else /* move back */
4013 cairo_region_translate (move->dest_region, move->dx, move->dy);
4015 cairo_region_destroy (remove);
4018 /* By now we a set of window moves that should be applied, and then
4019 * an update region that should be repainted. A trivial implementation
4020 * would just do that in order, however in order to get nicer drawing
4021 * we do some tricks:
4023 * First of all, each subwindow expose may be double buffered by
4024 * itself (depending on widget setting) via
4025 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4026 * creating a single surface the size of the invalid area on the
4027 * native window which all the individual normal paints will draw
4028 * into. This way in the normal case there will be only one surface
4029 * allocated and only once surface draw done for all the windows
4030 * in this native window.
4031 * There are a couple of reasons this may fail, for instance, some
4032 * backends (like quartz) do its own double buffering, so we disable
4033 * gdk double buffering there. Secondly, some subwindow could be
4034 * non-double buffered and draw directly to the window outside a
4035 * begin/end_paint pair. That will be lead to a gdk_window_flush
4036 * which immediately executes all outstanding moves and paints+removes
4037 * the implicit paint (further paints will allocate their own surfaces).
4039 * Secondly, in the case of implicit double buffering we expose all
4040 * the child windows into the implicit surface before we execute
4041 * the outstanding moves. This way we minimize the time between
4042 * doing the moves and rendering the new update area, thus minimizing
4043 * flashing. Of course, if any subwindow is non-double buffered we
4044 * well flush earlier than that.
4046 * Thirdly, after having done the outstanding moves we queue an
4047 * "antiexpose" on the area that will be drawn by the expose, which
4048 * means that any invalid region on the native window side before
4049 * the first expose drawing operation will be discarded, as it
4050 * has by then been overdrawn with valid data. This means we can
4051 * avoid doing the unnecessary repaint any outstanding expose events.
4054 cairo_region_get_extents (update_area, &clip_box);
4055 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box);
4056 expose_region = cairo_region_copy (update_area);
4057 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4060 /* Rendering is not double buffered by gdk, do outstanding
4061 * moves and queue antiexposure immediately. No need to do
4063 gdk_window_flush_outstanding_moves (window);
4064 save_region = impl_class->queue_antiexpose (window, update_area);
4066 /* Render the invalid areas to the implicit paint, by sending exposes.
4067 * May flush if non-double buffered widget draw. */
4068 impl_class->process_updates_recurse (window, expose_region);
4072 /* Do moves right before exposes are rendered to the window */
4073 gdk_window_flush_outstanding_moves (window);
4075 /* By this time we know that any outstanding expose for this
4076 * area is invalid and we can avoid it, so queue an antiexpose.
4077 * we have already started drawing to the window, so it would
4078 * be to late to anti-expose now. Since this is merely an
4079 * optimization we just avoid doing it at all in that case.
4081 if (window->implicit_paint != NULL && !window->implicit_paint->flushed)
4082 save_region = impl_class->queue_antiexpose (window, update_area);
4084 gdk_window_end_implicit_paint (window);
4086 cairo_region_destroy (expose_region);
4089 cairo_region_destroy (update_area);
4092 if (window->outstanding_moves)
4094 /* Flush any outstanding moves, may happen if we moved a window but got
4095 no actual invalid area */
4096 gdk_window_flush_outstanding_moves (window);
4099 g_object_unref (window);
4103 flush_all_displays (void)
4105 GSList *displays, *l;
4107 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4108 for (l = displays; l; l = l->next)
4109 gdk_display_flush (l->data);
4111 g_slist_free (displays);
4115 before_process_all_updates (void)
4117 GSList *displays, *l;
4118 GdkDisplayClass *display_class;
4120 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4121 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4122 for (l = displays; l; l = l->next)
4123 display_class->before_process_all_updates (l->data);
4125 g_slist_free (displays);
4129 after_process_all_updates (void)
4131 GSList *displays, *l;
4132 GdkDisplayClass *display_class;
4134 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4135 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4136 for (l = displays; l; l = l->next)
4137 display_class->after_process_all_updates (l->data);
4139 g_slist_free (displays);
4142 /* Currently it is not possible to override
4143 * gdk_window_process_all_updates in the same manner as
4144 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4145 * by implementing the GdkPaintable interface. If in the future a
4146 * backend would need this, the right solution would be to add a
4147 * method to GdkDisplay that can be optionally
4148 * NULL. gdk_window_process_all_updates can then walk the list of open
4149 * displays and call the mehod.
4153 * gdk_window_process_all_updates:
4155 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4156 * in the application.
4160 gdk_window_process_all_updates (void)
4162 GSList *old_update_windows = update_windows;
4163 GSList *tmp_list = update_windows;
4164 static gboolean in_process_all_updates = FALSE;
4165 static gboolean got_recursive_update = FALSE;
4167 if (in_process_all_updates)
4169 /* We can't do this now since that would recurse, so
4170 delay it until after the recursion is done. */
4171 got_recursive_update = TRUE;
4176 in_process_all_updates = TRUE;
4177 got_recursive_update = FALSE;
4180 g_source_remove (update_idle);
4182 update_windows = NULL;
4185 before_process_all_updates ();
4187 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4191 GdkWindow *window = tmp_list->data;
4193 if (!GDK_WINDOW_DESTROYED (window))
4195 if (window->update_freeze_count ||
4196 gdk_window_is_toplevel_frozen (window))
4197 gdk_window_add_update_window (window);
4199 gdk_window_process_updates_internal (window);
4202 g_object_unref (window);
4203 tmp_list = tmp_list->next;
4206 g_slist_free (old_update_windows);
4208 flush_all_displays ();
4210 after_process_all_updates ();
4212 in_process_all_updates = FALSE;
4214 /* If we ignored a recursive call, schedule a
4215 redraw now so that it eventually happens,
4216 otherwise we could miss an update if nothing
4217 else schedules an update. */
4218 if (got_recursive_update && !update_idle)
4220 gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
4221 gdk_window_update_idle,
4226 * gdk_window_process_updates:
4227 * @window: a #GdkWindow
4228 * @update_children: whether to also process updates for child windows
4230 * Sends one or more expose events to @window. The areas in each
4231 * expose event will cover the entire update area for the window (see
4232 * gdk_window_invalidate_region() for details). Normally GDK calls
4233 * gdk_window_process_all_updates() on your behalf, so there's no
4234 * need to call this function unless you want to force expose events
4235 * to be delivered immediately and synchronously (vs. the usual
4236 * case, where GDK delivers them in an idle handler). Occasionally
4237 * this is useful to produce nicer scrolling behavior, for example.
4241 gdk_window_process_updates (GdkWindow *window,
4242 gboolean update_children)
4244 GdkWindow *impl_window;
4246 g_return_if_fail (GDK_IS_WINDOW (window));
4248 if (GDK_WINDOW_DESTROYED (window))
4251 /* Make sure the window lives during the expose callouts */
4252 g_object_ref (window);
4254 impl_window = gdk_window_get_impl_window (window);
4255 if ((impl_window->update_area ||
4256 impl_window->outstanding_moves) &&
4257 !impl_window->update_freeze_count &&
4258 !gdk_window_is_toplevel_frozen (window) &&
4260 /* Don't recurse into process_updates_internal, we'll
4261 * do the update later when idle instead. */
4262 impl_window->implicit_paint == NULL)
4264 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4265 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4268 if (update_children)
4270 /* process updates in reverse stacking order so composition or
4271 * painting over achieves the desired effect for offscreen windows
4273 GList *node, *children;
4275 children = g_list_copy (window->children);
4276 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4278 for (node = g_list_last (children); node; node = node->prev)
4280 gdk_window_process_updates (node->data, TRUE);
4281 g_object_unref (node->data);
4284 g_list_free (children);
4287 g_object_unref (window);
4291 gdk_window_invalidate_rect_full (GdkWindow *window,
4292 const GdkRectangle *rect,
4293 gboolean invalidate_children,
4296 GdkRectangle window_rect;
4297 cairo_region_t *region;
4299 g_return_if_fail (GDK_IS_WINDOW (window));
4301 if (GDK_WINDOW_DESTROYED (window))
4304 if (window->input_only || !window->viewable)
4311 window_rect.width = window->width;
4312 window_rect.height = window->height;
4313 rect = &window_rect;
4316 region = cairo_region_create_rectangle (rect);
4317 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4318 cairo_region_destroy (region);
4322 * gdk_window_invalidate_rect:
4323 * @window: a #GdkWindow
4324 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4326 * @invalidate_children: whether to also invalidate child windows
4328 * A convenience wrapper around gdk_window_invalidate_region() which
4329 * invalidates a rectangular region. See
4330 * gdk_window_invalidate_region() for details.
4333 gdk_window_invalidate_rect (GdkWindow *window,
4334 const GdkRectangle *rect,
4335 gboolean invalidate_children)
4337 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4341 draw_ugly_color (GdkWindow *window,
4342 const cairo_region_t *region)
4346 cr = gdk_cairo_create (window);
4347 /* Draw ugly color all over the newly-invalid region */
4348 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4349 gdk_cairo_region (cr, region);
4356 impl_window_add_update_area (GdkWindow *impl_window,
4357 cairo_region_t *region)
4359 if (impl_window->update_area)
4360 cairo_region_union (impl_window->update_area, region);
4363 gdk_window_add_update_window (impl_window);
4364 impl_window->update_area = cairo_region_copy (region);
4365 gdk_window_schedule_update (impl_window);
4369 /* clear_bg controls if the region will be cleared to
4370 * the background pattern if the exposure mask is not
4371 * set for the window, whereas this might not otherwise be
4372 * done (unless necessary to emulate background settings).
4373 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4374 * need to clear the background, such as when exposing the area beneath a
4375 * hidden or moved window, but not when an app requests repaint or when the
4376 * windowing system exposes a newly visible area (because then the windowing
4377 * system has already cleared the area).
4380 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4381 const cairo_region_t *region,
4383 GdkWindowChildFunc child_func,
4386 GdkWindow *impl_window;
4387 cairo_region_t *visible_region;
4390 g_return_if_fail (GDK_IS_WINDOW (window));
4392 if (GDK_WINDOW_DESTROYED (window))
4395 if (window->input_only ||
4396 !window->viewable ||
4397 cairo_region_is_empty (region) ||
4398 window->window_type == GDK_WINDOW_ROOT)
4401 visible_region = gdk_window_get_visible_region (window);
4402 cairo_region_intersect (visible_region, region);
4404 tmp_list = window->children;
4407 GdkWindow *child = tmp_list->data;
4409 if (!child->input_only)
4411 cairo_region_t *child_region;
4412 GdkRectangle child_rect;
4414 child_rect.x = child->x;
4415 child_rect.y = child->y;
4416 child_rect.width = child->width;
4417 child_rect.height = child->height;
4418 child_region = cairo_region_create_rectangle (&child_rect);
4420 /* remove child area from the invalid area of the parent */
4421 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4422 !child->composited &&
4423 !gdk_window_is_offscreen (child))
4424 cairo_region_subtract (visible_region, child_region);
4426 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4428 cairo_region_t *tmp = cairo_region_copy (region);
4430 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4431 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4432 cairo_region_intersect (child_region, tmp);
4434 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4435 child_region, clear_bg, child_func, user_data);
4437 cairo_region_destroy (tmp);
4440 cairo_region_destroy (child_region);
4443 tmp_list = tmp_list->next;
4446 impl_window = gdk_window_get_impl_window (window);
4448 if (!cairo_region_is_empty (visible_region) ||
4449 /* Even if we're not exposing anything, make sure we process
4450 idles for windows with outstanding moves */
4451 (impl_window->outstanding_moves != NULL &&
4452 impl_window->update_area == NULL))
4455 draw_ugly_color (window, region);
4457 /* Convert to impl coords */
4458 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4460 /* Only invalidate area if app requested expose events or if
4461 we need to clear the area (by request or to emulate background
4462 clearing for non-native windows or native windows with no support
4463 for window backgrounds */
4464 if (window->event_mask & GDK_EXPOSURE_MASK ||
4465 clear_bg == CLEAR_BG_ALL ||
4466 clear_bg == CLEAR_BG_WINCLEARED)
4467 impl_window_add_update_area (impl_window, visible_region);
4470 cairo_region_destroy (visible_region);
4474 * gdk_window_invalidate_maybe_recurse:
4475 * @window: a #GdkWindow
4476 * @region: a #cairo_region_t
4477 * @child_func: (scope call) (allow-none): function to use to decide if to
4478 * recurse to a child, %NULL means never recurse.
4479 * @user_data: data passed to @child_func
4481 * Adds @region to the update area for @window. The update area is the
4482 * region that needs to be redrawn, or "dirty region." The call
4483 * gdk_window_process_updates() sends one or more expose events to the
4484 * window, which together cover the entire update area. An
4485 * application would normally redraw the contents of @window in
4486 * response to those expose events.
4488 * GDK will call gdk_window_process_all_updates() on your behalf
4489 * whenever your program returns to the main loop and becomes idle, so
4490 * normally there's no need to do that manually, you just need to
4491 * invalidate regions that you know should be redrawn.
4493 * The @child_func parameter controls whether the region of
4494 * each child window that intersects @region will also be invalidated.
4495 * Only children for which @child_func returns TRUE will have the area
4499 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4500 const cairo_region_t *region,
4501 GdkWindowChildFunc child_func,
4504 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4505 child_func, user_data);
4509 true_predicate (GdkWindow *window,
4516 gdk_window_invalidate_region_full (GdkWindow *window,
4517 const cairo_region_t *region,
4518 gboolean invalidate_children,
4521 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4522 invalidate_children ?
4523 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4528 * gdk_window_invalidate_region:
4529 * @window: a #GdkWindow
4530 * @region: a #cairo_region_t
4531 * @invalidate_children: %TRUE to also invalidate child windows
4533 * Adds @region to the update area for @window. The update area is the
4534 * region that needs to be redrawn, or "dirty region." The call
4535 * gdk_window_process_updates() sends one or more expose events to the
4536 * window, which together cover the entire update area. An
4537 * application would normally redraw the contents of @window in
4538 * response to those expose events.
4540 * GDK will call gdk_window_process_all_updates() on your behalf
4541 * whenever your program returns to the main loop and becomes idle, so
4542 * normally there's no need to do that manually, you just need to
4543 * invalidate regions that you know should be redrawn.
4545 * The @invalidate_children parameter controls whether the region of
4546 * each child window that intersects @region will also be invalidated.
4547 * If %FALSE, then the update area for child windows will remain
4548 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4549 * fine grained control over which children are invalidated.
4552 gdk_window_invalidate_region (GdkWindow *window,
4553 const cairo_region_t *region,
4554 gboolean invalidate_children)
4556 gdk_window_invalidate_maybe_recurse (window, region,
4557 invalidate_children ?
4558 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4563 * _gdk_window_invalidate_for_expose:
4564 * @window: a #GdkWindow
4565 * @region: a #cairo_region_t
4567 * Adds @region to the update area for @window. The update area is the
4568 * region that needs to be redrawn, or "dirty region." The call
4569 * gdk_window_process_updates() sends one or more expose events to the
4570 * window, which together cover the entire update area. An
4571 * application would normally redraw the contents of @window in
4572 * response to those expose events.
4574 * GDK will call gdk_window_process_all_updates() on your behalf
4575 * whenever your program returns to the main loop and becomes idle, so
4576 * normally there's no need to do that manually, you just need to
4577 * invalidate regions that you know should be redrawn.
4579 * This version of invalidation is used when you recieve expose events
4580 * from the native window system. It exposes the native window, plus
4581 * any non-native child windows (but not native child windows, as those would
4582 * have gotten their own expose events).
4585 _gdk_window_invalidate_for_expose (GdkWindow *window,
4586 cairo_region_t *region)
4588 GdkWindowRegionMove *move;
4589 cairo_region_t *move_region;
4592 /* Any invalidations comming from the windowing system will
4593 be in areas that may be moved by outstanding moves,
4594 so we need to modify the expose region correspondingly,
4595 otherwise we would expose in the wrong place, as the
4596 outstanding moves will be copied before we draw the
4598 for (l = window->outstanding_moves; l != NULL; l = l->next)
4602 /* covert to move source region */
4603 move_region = cairo_region_copy (move->dest_region);
4604 cairo_region_translate (move_region, -move->dx, -move->dy);
4606 /* Move area of region that intersects with move source
4607 by dx, dy of the move*/
4608 cairo_region_intersect (move_region, region);
4609 cairo_region_subtract (region, move_region);
4610 cairo_region_translate (move_region, move->dx, move->dy);
4611 cairo_region_union (region, move_region);
4613 cairo_region_destroy (move_region);
4616 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4617 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4623 * gdk_window_get_update_area:
4624 * @window: a #GdkWindow
4626 * Transfers ownership of the update area from @window to the caller
4627 * of the function. That is, after calling this function, @window will
4628 * no longer have an invalid/dirty region; the update area is removed
4629 * from @window and handed to you. If a window has no update area,
4630 * gdk_window_get_update_area() returns %NULL. You are responsible for
4631 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4633 * Return value: the update area for @window
4636 gdk_window_get_update_area (GdkWindow *window)
4638 GdkWindow *impl_window;
4639 cairo_region_t *tmp_region, *to_remove;
4641 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4643 impl_window = gdk_window_get_impl_window (window);
4645 if (impl_window->update_area)
4647 tmp_region = cairo_region_copy (window->clip_region_with_children);
4648 /* Convert to impl coords */
4649 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4650 cairo_region_intersect (tmp_region, impl_window->update_area);
4652 if (cairo_region_is_empty (tmp_region))
4654 cairo_region_destroy (tmp_region);
4659 /* Convert from impl coords */
4660 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4662 /* Don't remove any update area that is overlapped by non-opaque windows
4663 (children or siblings) with alpha, as these really need to be repainted
4664 independently of this window. */
4665 to_remove = cairo_region_copy (tmp_region);
4666 cairo_region_subtract (to_remove, window->parent->layered_region);
4667 remove_layered_child_area (window, to_remove);
4669 /* Remove from update_area */
4670 cairo_region_translate (to_remove, window->abs_x, window->abs_y);
4671 cairo_region_subtract (impl_window->update_area, to_remove);
4673 cairo_region_destroy (to_remove);
4675 if (cairo_region_is_empty (impl_window->update_area) &&
4676 impl_window->outstanding_moves == NULL)
4678 cairo_region_destroy (impl_window->update_area);
4679 impl_window->update_area = NULL;
4681 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4692 * _gdk_window_clear_update_area:
4693 * @window: a #GdkWindow.
4695 * Internal function to clear the update area for a window. This
4696 * is called when the window is hidden or destroyed.
4699 _gdk_window_clear_update_area (GdkWindow *window)
4701 g_return_if_fail (GDK_IS_WINDOW (window));
4703 if (window->update_area)
4705 gdk_window_remove_update_window (window);
4707 cairo_region_destroy (window->update_area);
4708 window->update_area = NULL;
4713 * gdk_window_freeze_updates:
4714 * @window: a #GdkWindow
4716 * Temporarily freezes a window such that it won't receive expose
4717 * events. The window will begin receiving expose events again when
4718 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4719 * has been called more than once, gdk_window_thaw_updates() must be called
4720 * an equal number of times to begin processing exposes.
4723 gdk_window_freeze_updates (GdkWindow *window)
4725 GdkWindow *impl_window;
4727 g_return_if_fail (GDK_IS_WINDOW (window));
4729 impl_window = gdk_window_get_impl_window (window);
4730 impl_window->update_freeze_count++;
4734 * gdk_window_thaw_updates:
4735 * @window: a #GdkWindow
4737 * Thaws a window frozen with gdk_window_freeze_updates().
4740 gdk_window_thaw_updates (GdkWindow *window)
4742 GdkWindow *impl_window;
4744 g_return_if_fail (GDK_IS_WINDOW (window));
4746 impl_window = gdk_window_get_impl_window (window);
4748 g_return_if_fail (impl_window->update_freeze_count > 0);
4750 if (--impl_window->update_freeze_count == 0)
4751 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4755 * gdk_window_freeze_toplevel_updates_libgtk_only:
4756 * @window: a #GdkWindow
4758 * Temporarily freezes a window and all its descendants such that it won't
4759 * receive expose events. The window will begin receiving expose events
4760 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4761 * gdk_window_freeze_toplevel_updates_libgtk_only()
4762 * has been called more than once,
4763 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4764 * an equal number of times to begin processing exposes.
4766 * This function is not part of the GDK public API and is only
4770 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4772 g_return_if_fail (GDK_IS_WINDOW (window));
4773 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4775 window->update_and_descendants_freeze_count++;
4779 * gdk_window_thaw_toplevel_updates_libgtk_only:
4780 * @window: a #GdkWindow
4782 * Thaws a window frozen with
4783 * gdk_window_freeze_toplevel_updates_libgtk_only().
4785 * This function is not part of the GDK public API and is only
4789 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4791 g_return_if_fail (GDK_IS_WINDOW (window));
4792 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4793 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4795 window->update_and_descendants_freeze_count--;
4797 gdk_window_schedule_update (window);
4801 * gdk_window_set_debug_updates:
4802 * @setting: %TRUE to turn on update debugging
4804 * With update debugging enabled, calls to
4805 * gdk_window_invalidate_region() clear the invalidated region of the
4806 * screen to a noticeable color, and GDK pauses for a short time
4807 * before sending exposes to windows during
4808 * gdk_window_process_updates(). The net effect is that you can see
4809 * the invalid region for each window and watch redraws as they
4810 * occur. This allows you to diagnose inefficiencies in your application.
4812 * In essence, because the GDK rendering model prevents all flicker,
4813 * if you are redrawing the same region 400 times you may never
4814 * notice, aside from noticing a speed problem. Enabling update
4815 * debugging causes GTK to flicker slowly and noticeably, so you can
4816 * see exactly what's being redrawn when, in what order.
4818 * The --gtk-debug=updates command line option passed to GTK+ programs
4819 * enables this debug option at application startup time. That's
4820 * usually more useful than calling gdk_window_set_debug_updates()
4821 * yourself, though you might want to use this function to enable
4822 * updates sometime after application startup time.
4826 gdk_window_set_debug_updates (gboolean setting)
4828 debug_updates = setting;
4832 * gdk_window_constrain_size:
4833 * @geometry: a #GdkGeometry structure
4834 * @flags: a mask indicating what portions of @geometry are set
4835 * @width: desired width of window
4836 * @height: desired height of the window
4837 * @new_width: (out): location to store resulting width
4838 * @new_height: (out): location to store resulting height
4840 * Constrains a desired width and height according to a
4841 * set of geometry hints (such as minimum and maximum size).
4844 gdk_window_constrain_size (GdkGeometry *geometry,
4851 /* This routine is partially borrowed from fvwm.
4853 * Copyright 1993, Robert Nation
4854 * You may use this code for any purpose, as long as the original
4855 * copyright remains in the source code and all documentation
4857 * which in turn borrows parts of the algorithm from uwm
4860 gint min_height = 0;
4861 gint base_width = 0;
4862 gint base_height = 0;
4865 gint max_width = G_MAXINT;
4866 gint max_height = G_MAXINT;
4868 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
4870 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
4872 base_width = geometry->base_width;
4873 base_height = geometry->base_height;
4874 min_width = geometry->min_width;
4875 min_height = geometry->min_height;
4877 else if (flags & GDK_HINT_BASE_SIZE)
4879 base_width = geometry->base_width;
4880 base_height = geometry->base_height;
4881 min_width = geometry->base_width;
4882 min_height = geometry->base_height;
4884 else if (flags & GDK_HINT_MIN_SIZE)
4886 base_width = geometry->min_width;
4887 base_height = geometry->min_height;
4888 min_width = geometry->min_width;
4889 min_height = geometry->min_height;
4892 if (flags & GDK_HINT_MAX_SIZE)
4894 max_width = geometry->max_width ;
4895 max_height = geometry->max_height;
4898 if (flags & GDK_HINT_RESIZE_INC)
4900 xinc = MAX (xinc, geometry->width_inc);
4901 yinc = MAX (yinc, geometry->height_inc);
4904 /* clamp width and height to min and max values
4906 width = CLAMP (width, min_width, max_width);
4907 height = CLAMP (height, min_height, max_height);
4909 /* shrink to base + N * inc
4911 width = base_width + FLOOR (width - base_width, xinc);
4912 height = base_height + FLOOR (height - base_height, yinc);
4914 /* constrain aspect ratio, according to:
4917 * min_aspect <= -------- <= max_aspect
4921 if (flags & GDK_HINT_ASPECT &&
4922 geometry->min_aspect > 0 &&
4923 geometry->max_aspect > 0)
4927 if (geometry->min_aspect * height > width)
4929 delta = FLOOR (height - width / geometry->min_aspect, yinc);
4930 if (height - delta >= min_height)
4934 delta = FLOOR (height * geometry->min_aspect - width, xinc);
4935 if (width + delta <= max_width)
4940 if (geometry->max_aspect * height < width)
4942 delta = FLOOR (width - height * geometry->max_aspect, xinc);
4943 if (width - delta >= min_width)
4947 delta = FLOOR (width / geometry->max_aspect - height, yinc);
4948 if (height + delta <= max_height)
4957 *new_height = height;
4961 * gdk_window_get_pointer:
4962 * @window: a #GdkWindow
4963 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
4964 * return the X coordinate
4965 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
4966 * return the Y coordinate
4967 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
4970 * Obtains the current pointer position and modifier state.
4971 * The position is given in coordinates relative to the upper left
4972 * corner of @window.
4974 * Return value: (transfer none): the window containing the pointer (as with
4975 * gdk_window_at_pointer()), or %NULL if the window containing the
4976 * pointer isn't known to GDK
4978 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
4981 gdk_window_get_pointer (GdkWindow *window,
4984 GdkModifierType *mask)
4986 GdkDisplay *display;
4988 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4990 display = gdk_window_get_display (window);
4992 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
4996 * gdk_window_get_device_position:
4997 * @window: a #GdkWindow.
4998 * @device: pointer #GdkDevice to query to.
4999 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5000 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5001 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5003 * Obtains the current device position and modifier state.
5004 * The position is given in coordinates relative to the upper left
5005 * corner of @window.
5007 * Return value: (transfer none): The window underneath @device (as with
5008 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
5013 gdk_window_get_device_position (GdkWindow *window,
5017 GdkModifierType *mask)
5020 GdkModifierType tmp_mask;
5021 gboolean normal_child;
5023 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5024 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5025 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
5027 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
5031 /* We got the coords on the impl, convert to the window */
5032 tmp_x -= window->abs_x;
5033 tmp_y -= window->abs_y;
5042 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
5045 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5050 * gdk_get_default_root_window:
5052 * Obtains the root window (parent all other windows are inside)
5053 * for the default display and screen.
5055 * Return value: (transfer none): the default root window
5058 gdk_get_default_root_window (void)
5060 return gdk_screen_get_root_window (gdk_screen_get_default ());
5064 get_all_native_children (GdkWindow *window,
5070 for (l = window->children; l != NULL; l = l->next)
5074 if (gdk_window_has_impl (child))
5075 *native = g_list_prepend (*native, child);
5077 get_all_native_children (child, native);
5083 gdk_window_raise_internal (GdkWindow *window)
5085 GdkWindow *parent = window->parent;
5087 GList *native_children;
5089 GdkWindowImplClass *impl_class;
5093 parent->children = g_list_remove (parent->children, window);
5094 parent->children = g_list_prepend (parent->children, window);
5097 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5098 /* Just do native raise for toplevels */
5099 if (gdk_window_is_toplevel (window) ||
5100 /* The restack_under codepath should work correctly even if the parent
5101 is native, but it relies on the order of ->children to be correct,
5102 and some apps like SWT reorder the x windows without gdks knowledge,
5103 so we use raise directly in order to make these behave as before
5104 when using native windows */
5105 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5107 impl_class->raise (window);
5109 else if (gdk_window_has_impl (window))
5111 above = find_native_sibling_above (parent, window);
5114 listhead.data = window;
5115 listhead.next = NULL;
5116 listhead.prev = NULL;
5117 impl_class->restack_under ((GdkWindow *)above,
5121 impl_class->raise (window);
5125 native_children = NULL;
5126 get_all_native_children (window, &native_children);
5127 if (native_children != NULL)
5129 above = find_native_sibling_above (parent, window);
5132 impl_class->restack_under (above, native_children);
5135 /* Right order, since native_children is bottom-topmost first */
5136 for (l = native_children; l != NULL; l = l->next)
5137 impl_class->raise (l->data);
5140 g_list_free (native_children);
5146 /* Returns TRUE If the native window was mapped or unmapped */
5148 set_viewable (GdkWindow *w,
5152 GdkWindowImplClass *impl_class;
5155 if (w->viewable == val)
5161 recompute_visible_regions (w, FALSE, FALSE);
5163 for (l = w->children; l != NULL; l = l->next)
5167 if (GDK_WINDOW_IS_MAPPED (child) &&
5168 child->window_type != GDK_WINDOW_FOREIGN)
5169 set_viewable (child, val);
5172 if (gdk_window_has_impl (w) &&
5173 w->window_type != GDK_WINDOW_FOREIGN &&
5174 !gdk_window_is_toplevel (w))
5176 /* For most native windows we show/hide them not when they are
5177 * mapped/unmapped, because that may not produce the correct results.
5178 * For instance, if a native window have a non-native parent which is
5179 * hidden, but its native parent is viewable then showing the window
5180 * would make it viewable to X but its not viewable wrt the non-native
5181 * hierarchy. In order to handle this we track the gdk side viewability
5182 * and only map really viewable windows.
5184 * There are two exceptions though:
5186 * For foreign windows we don't want ever change the mapped state
5187 * except when explicitly done via gdk_window_show/hide, as this may
5188 * cause problems for client owning the foreign window when its window
5189 * is suddenly mapped or unmapped.
5191 * For toplevel windows embedded in a foreign window (e.g. a plug)
5192 * we sometimes synthesize a map of a window, but the native
5193 * window is really shown by the embedder, so we don't want to
5194 * do the show ourselves. We can't really tell this case from the normal
5195 * toplevel show as such toplevels are seen by gdk as parents of the
5196 * root window, so we make an exception for all toplevels.
5199 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5201 impl_class->show ((GdkWindow *)w, FALSE);
5203 impl_class->hide ((GdkWindow *)w);
5211 /* Returns TRUE If the native window was mapped or unmapped */
5213 _gdk_window_update_viewable (GdkWindow *window)
5217 if (window->window_type == GDK_WINDOW_FOREIGN ||
5218 window->window_type == GDK_WINDOW_ROOT)
5220 else if (gdk_window_is_toplevel (window) ||
5221 window->parent->viewable)
5222 viewable = GDK_WINDOW_IS_MAPPED (window);
5226 return set_viewable (window, viewable);
5230 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5232 GdkWindowImplClass *impl_class;
5233 gboolean was_mapped, was_viewable;
5236 g_return_if_fail (GDK_IS_WINDOW (window));
5238 if (window->destroyed)
5241 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5242 was_viewable = window->viewable;
5245 /* Keep children in (reverse) stacking order */
5246 gdk_window_raise_internal (window);
5248 if (gdk_window_has_impl (window))
5251 gdk_synthesize_window_state (window,
5252 GDK_WINDOW_STATE_WITHDRAWN,
5253 GDK_WINDOW_STATE_FOCUSED);
5260 did_show = _gdk_window_update_viewable (window);
5262 /* If it was already viewable the backend show op won't be called, call it
5263 again to ensure things happen right if the mapped tracking was not right
5264 for e.g. a foreign window.
5265 Dunno if this is strictly needed but its what happened pre-csw.
5266 Also show if not done by gdk_window_update_viewable. */
5267 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5269 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5270 impl_class->show (window, !did_show ? was_mapped : TRUE);
5273 if (!was_mapped && !gdk_window_has_impl (window))
5275 if (window->event_mask & GDK_STRUCTURE_MASK)
5276 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5278 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5279 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5282 if (!was_mapped || raise)
5284 recompute_visible_regions (window, TRUE, FALSE);
5286 /* If any decendants became visible we need to send visibility notify */
5287 gdk_window_update_visibility_recursively (window, NULL);
5289 if (gdk_window_is_viewable (window))
5291 _gdk_synthesize_crossing_events_for_geometry_change (window);
5292 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5298 * gdk_window_show_unraised:
5299 * @window: a #GdkWindow
5301 * Shows a #GdkWindow onscreen, but does not modify its stacking
5302 * order. In contrast, gdk_window_show() will raise the window
5303 * to the top of the window stack.
5305 * On the X11 platform, in Xlib terms, this function calls
5306 * XMapWindow() (it also updates some internal GDK state, which means
5307 * that you can't really use XMapWindow() directly on a GDK window).
5310 gdk_window_show_unraised (GdkWindow *window)
5312 gdk_window_show_internal (window, FALSE);
5317 * @window: a #GdkWindow
5319 * Raises @window to the top of the Z-order (stacking order), so that
5320 * other windows with the same parent window appear below @window.
5321 * This is true whether or not the windows are visible.
5323 * If @window is a toplevel, the window manager may choose to deny the
5324 * request to move the window in the Z-order, gdk_window_raise() only
5325 * requests the restack, does not guarantee it.
5328 gdk_window_raise (GdkWindow *window)
5330 g_return_if_fail (GDK_IS_WINDOW (window));
5332 if (window->destroyed)
5335 gdk_window_flush_if_exposing (window);
5337 /* Keep children in (reverse) stacking order */
5338 gdk_window_raise_internal (window);
5340 recompute_visible_regions (window, TRUE, FALSE);
5342 if (gdk_window_is_viewable (window) &&
5343 !window->input_only)
5344 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5348 gdk_window_lower_internal (GdkWindow *window)
5350 GdkWindow *parent = window->parent;
5351 GdkWindowImplClass *impl_class;
5353 GList *native_children;
5358 parent->children = g_list_remove (parent->children, window);
5359 parent->children = g_list_append (parent->children, window);
5362 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5363 /* Just do native lower for toplevels */
5364 if (gdk_window_is_toplevel (window) ||
5365 /* The restack_under codepath should work correctly even if the parent
5366 is native, but it relies on the order of ->children to be correct,
5367 and some apps like SWT reorder the x windows without gdks knowledge,
5368 so we use lower directly in order to make these behave as before
5369 when using native windows */
5370 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5372 impl_class->lower (window);
5374 else if (gdk_window_has_impl (window))
5376 above = find_native_sibling_above (parent, window);
5379 listhead.data = window;
5380 listhead.next = NULL;
5381 listhead.prev = NULL;
5382 impl_class->restack_under ((GdkWindow *)above, &listhead);
5385 impl_class->raise (window);
5389 native_children = NULL;
5390 get_all_native_children (window, &native_children);
5391 if (native_children != NULL)
5393 above = find_native_sibling_above (parent, window);
5396 impl_class->restack_under ((GdkWindow *)above,
5400 /* Right order, since native_children is bottom-topmost first */
5401 for (l = native_children; l != NULL; l = l->next)
5402 impl_class->raise (l->data);
5405 g_list_free (native_children);
5412 gdk_window_invalidate_in_parent (GdkWindow *private)
5414 GdkRectangle r, child;
5416 if (gdk_window_is_toplevel (private))
5419 /* get the visible rectangle of the parent */
5421 r.width = private->parent->width;
5422 r.height = private->parent->height;
5424 child.x = private->x;
5425 child.y = private->y;
5426 child.width = private->width;
5427 child.height = private->height;
5428 gdk_rectangle_intersect (&r, &child, &r);
5430 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5436 * @window: a #GdkWindow
5438 * Lowers @window to the bottom of the Z-order (stacking order), so that
5439 * other windows with the same parent window appear above @window.
5440 * This is true whether or not the other windows are visible.
5442 * If @window is a toplevel, the window manager may choose to deny the
5443 * request to move the window in the Z-order, gdk_window_lower() only
5444 * requests the restack, does not guarantee it.
5446 * Note that gdk_window_show() raises the window again, so don't call this
5447 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5450 gdk_window_lower (GdkWindow *window)
5452 g_return_if_fail (GDK_IS_WINDOW (window));
5454 if (window->destroyed)
5457 gdk_window_flush_if_exposing (window);
5459 /* Keep children in (reverse) stacking order */
5460 gdk_window_lower_internal (window);
5462 recompute_visible_regions (window, TRUE, FALSE);
5464 _gdk_synthesize_crossing_events_for_geometry_change (window);
5465 gdk_window_invalidate_in_parent (window);
5469 * gdk_window_restack:
5470 * @window: a #GdkWindow
5471 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5474 * Changes the position of @window in the Z-order (stacking order), so that
5475 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5478 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5479 * lowers the window.
5481 * If @window is a toplevel, the window manager may choose to deny the
5482 * request to move the window in the Z-order, gdk_window_restack() only
5483 * requests the restack, does not guarantee it.
5488 gdk_window_restack (GdkWindow *window,
5492 GdkWindowImplClass *impl_class;
5494 GdkWindow *above_native;
5495 GList *sibling_link;
5496 GList *native_children;
5499 g_return_if_fail (GDK_IS_WINDOW (window));
5500 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5502 if (window->destroyed)
5505 if (sibling == NULL)
5508 gdk_window_raise (window);
5510 gdk_window_lower (window);
5514 gdk_window_flush_if_exposing (window);
5516 if (gdk_window_is_toplevel (window))
5518 g_return_if_fail (gdk_window_is_toplevel (sibling));
5519 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5520 impl_class->restack_toplevel (window, sibling, above);
5524 parent = window->parent;
5527 sibling_link = g_list_find (parent->children, sibling);
5528 g_return_if_fail (sibling_link != NULL);
5529 if (sibling_link == NULL)
5532 parent->children = g_list_remove (parent->children, window);
5534 parent->children = g_list_insert_before (parent->children,
5538 parent->children = g_list_insert_before (parent->children,
5542 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5543 if (gdk_window_has_impl (window))
5545 above_native = find_native_sibling_above (parent, window);
5548 listhead.data = window;
5549 listhead.next = NULL;
5550 listhead.prev = NULL;
5551 impl_class->restack_under (above_native, &listhead);
5554 impl_class->raise (window);
5558 native_children = NULL;
5559 get_all_native_children (window, &native_children);
5560 if (native_children != NULL)
5562 above_native = find_native_sibling_above (parent, window);
5564 impl_class->restack_under (above_native,
5568 /* Right order, since native_children is bottom-topmost first */
5569 for (l = native_children; l != NULL; l = l->next)
5570 impl_class->raise (l->data);
5573 g_list_free (native_children);
5578 recompute_visible_regions (window, TRUE, FALSE);
5580 _gdk_synthesize_crossing_events_for_geometry_change (window);
5581 gdk_window_invalidate_in_parent (window);
5587 * @window: a #GdkWindow
5589 * Like gdk_window_show_unraised(), but also raises the window to the
5590 * top of the window stack (moves the window to the front of the
5593 * This function maps a window so it's visible onscreen. Its opposite
5594 * is gdk_window_hide().
5596 * When implementing a #GtkWidget, you should call this function on the widget's
5597 * #GdkWindow as part of the "map" method.
5600 gdk_window_show (GdkWindow *window)
5602 gdk_window_show_internal (window, TRUE);
5607 * @window: a #GdkWindow
5609 * For toplevel windows, withdraws them, so they will no longer be
5610 * known to the window manager; for all windows, unmaps them, so
5611 * they won't be displayed. Normally done automatically as
5612 * part of gtk_widget_hide().
5615 gdk_window_hide (GdkWindow *window)
5617 GdkWindowImplClass *impl_class;
5618 gboolean was_mapped, did_hide;
5620 g_return_if_fail (GDK_IS_WINDOW (window));
5622 if (window->destroyed)
5625 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5627 if (gdk_window_has_impl (window))
5630 if (GDK_WINDOW_IS_MAPPED (window))
5631 gdk_synthesize_window_state (window,
5633 GDK_WINDOW_STATE_WITHDRAWN);
5635 else if (was_mapped)
5637 GdkDisplay *display;
5638 GdkDeviceManager *device_manager;
5641 /* May need to break grabs on children */
5642 display = gdk_window_get_display (window);
5643 device_manager = gdk_display_get_device_manager (display);
5645 /* Get all devices */
5646 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5647 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5648 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5650 for (d = devices; d; d = d->next)
5652 GdkDevice *device = d->data;
5654 if (_gdk_display_end_device_grab (display,
5656 _gdk_display_get_next_serial (display),
5659 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5662 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5663 g_list_free (devices);
5666 did_hide = _gdk_window_update_viewable (window);
5668 /* Hide foreign window as those are not handled by update_viewable. */
5669 if (gdk_window_has_impl (window) && (!did_hide))
5671 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5672 impl_class->hide (window);
5675 recompute_visible_regions (window, TRUE, FALSE);
5677 /* all decendants became non-visible, we need to send visibility notify */
5678 gdk_window_update_visibility_recursively (window, NULL);
5680 if (was_mapped && !gdk_window_has_impl (window))
5682 if (window->event_mask & GDK_STRUCTURE_MASK)
5683 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5685 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5686 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5688 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5691 /* Invalidate the rect */
5693 gdk_window_invalidate_in_parent (window);
5697 * gdk_window_withdraw:
5698 * @window: a toplevel #GdkWindow
5700 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5701 * This function is not really useful as gdk_window_hide() automatically
5702 * withdraws toplevel windows before hiding them.
5705 gdk_window_withdraw (GdkWindow *window)
5707 GdkWindowImplClass *impl_class;
5708 gboolean was_mapped;
5710 g_return_if_fail (GDK_IS_WINDOW (window));
5712 if (window->destroyed)
5715 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5717 if (gdk_window_has_impl (window))
5719 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5720 impl_class->withdraw (window);
5724 if (window->event_mask & GDK_STRUCTURE_MASK)
5725 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5727 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5728 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5730 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5733 recompute_visible_regions (window, TRUE, FALSE);
5738 * gdk_window_set_events:
5739 * @window: a #GdkWindow
5740 * @event_mask: event mask for @window
5742 * The event mask for a window determines which events will be reported
5743 * for that window from all master input devices. For example, an event mask
5744 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5745 * press events. The event mask is the bitwise OR of values from the
5746 * #GdkEventMask enumeration.
5749 gdk_window_set_events (GdkWindow *window,
5750 GdkEventMask event_mask)
5752 GdkWindowImplClass *impl_class;
5753 GdkDisplay *display;
5755 g_return_if_fail (GDK_IS_WINDOW (window));
5757 if (window->destroyed)
5760 /* If motion hint is disabled, enable motion events again */
5761 display = gdk_window_get_display (window);
5762 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5763 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5765 GList *devices = window->devices_inside;
5769 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5770 devices = devices->next;
5774 window->event_mask = event_mask;
5776 if (gdk_window_has_impl (window))
5778 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5779 impl_class->set_events (window,
5780 get_native_event_mask (window));
5786 * gdk_window_get_events:
5787 * @window: a #GdkWindow
5789 * Gets the event mask for @window for all master input devices. See
5790 * gdk_window_set_events().
5792 * Return value: event mask for @window
5795 gdk_window_get_events (GdkWindow *window)
5797 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5799 if (window->destroyed)
5802 return window->event_mask;
5806 * gdk_window_set_device_events:
5807 * @window: a #GdkWindow
5808 * @device: #GdkDevice to enable events for.
5809 * @event_mask: event mask for @window
5811 * Sets the event mask for a given device (Normally a floating device, not
5812 * attached to any visible pointer) to @window. For example, an event mask
5813 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5814 * press events. The event mask is the bitwise OR of values from the
5815 * #GdkEventMask enumeration.
5820 gdk_window_set_device_events (GdkWindow *window,
5822 GdkEventMask event_mask)
5824 GdkEventMask device_mask;
5825 GdkDisplay *display;
5828 g_return_if_fail (GDK_IS_WINDOW (window));
5829 g_return_if_fail (GDK_IS_DEVICE (device));
5831 if (GDK_WINDOW_DESTROYED (window))
5834 /* If motion hint is disabled, enable motion events again */
5835 display = gdk_window_get_display (window);
5836 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5837 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5838 _gdk_display_enable_motion_hints (display, device);
5840 if (G_UNLIKELY (!window->device_events))
5841 window->device_events = g_hash_table_new (NULL, NULL);
5843 if (event_mask == 0)
5845 /* FIXME: unsetting events on a master device
5846 * would restore window->event_mask
5848 g_hash_table_remove (window->device_events, device);
5851 g_hash_table_insert (window->device_events, device,
5852 GINT_TO_POINTER (event_mask));
5854 native = gdk_window_get_toplevel (window);
5856 while (gdk_window_is_offscreen (native))
5858 native = gdk_offscreen_window_get_embedder (native);
5860 if (native == NULL ||
5861 (!_gdk_window_has_impl (native) &&
5862 !gdk_window_is_viewable (native)))
5865 native = gdk_window_get_toplevel (native);
5868 device_mask = get_native_device_event_mask (window, device);
5869 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
5873 * gdk_window_get_device_events:
5874 * @window: a #GdkWindow.
5875 * @device: a #GdkDevice.
5877 * Returns the event mask for @window corresponding to an specific device.
5879 * Returns: device event mask for @window
5884 gdk_window_get_device_events (GdkWindow *window,
5889 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5890 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
5892 if (GDK_WINDOW_DESTROYED (window))
5895 if (!window->device_events)
5898 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
5900 /* FIXME: device could be controlled by window->event_mask */
5906 gdk_window_move_resize_toplevel (GdkWindow *window,
5913 cairo_region_t *old_region, *new_region;
5914 GdkWindowImplClass *impl_class;
5921 is_resize = (width != -1) || (height != -1);
5923 if (gdk_window_is_viewable (window) &&
5924 !window->input_only)
5927 old_region = cairo_region_copy (window->clip_region);
5930 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5931 impl_class->move_resize (window, with_move, x, y, width, height);
5933 /* Avoid recomputing for pure toplevel moves, for performance reasons */
5935 recompute_visible_regions (window, TRUE, FALSE);
5939 new_region = cairo_region_copy (window->clip_region);
5941 /* This is the newly exposed area (due to any resize),
5942 * X will expose it, but lets do that without the roundtrip
5944 cairo_region_subtract (new_region, old_region);
5945 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
5947 cairo_region_destroy (old_region);
5948 cairo_region_destroy (new_region);
5951 _gdk_synthesize_crossing_events_for_geometry_change (window);
5956 move_native_children (GdkWindow *private)
5960 GdkWindowImplClass *impl_class;
5962 for (l = private->children; l; l = l->next)
5966 if (child->impl != private->impl)
5968 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
5969 impl_class->move_resize (child, TRUE,
5971 child->width, child->height);
5974 move_native_children (child);
5979 collect_native_child_region_helper (GdkWindow *window,
5980 GdkWindowImpl *impl,
5981 cairo_region_t **region,
5986 cairo_region_t *tmp;
5989 for (l = window->children; l != NULL; l = l->next)
5993 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
5996 if (child->impl != impl)
5998 tmp = cairo_region_copy (child->clip_region);
5999 cairo_region_translate (tmp,
6000 x_offset + child->x,
6001 y_offset + child->y);
6002 if (*region == NULL)
6006 cairo_region_union (*region, tmp);
6007 cairo_region_destroy (tmp);
6011 collect_native_child_region_helper (child, impl, region,
6012 x_offset + child->x,
6013 y_offset + child->y);
6019 static cairo_region_t *
6020 collect_native_child_region (GdkWindow *window,
6021 gboolean include_this)
6023 cairo_region_t *region;
6025 if (include_this && gdk_window_has_impl (window) && window->viewable)
6026 return cairo_region_copy (window->clip_region);
6030 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6037 gdk_window_move_resize_internal (GdkWindow *window,
6044 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
6045 cairo_region_t *old_native_child_region, *new_native_child_region;
6046 GdkWindow *impl_window;
6047 GdkWindowImplClass *impl_class;
6049 int old_x, old_y, old_abs_x, old_abs_y;
6052 g_return_if_fail (GDK_IS_WINDOW (window));
6054 if (window->destroyed)
6057 if (gdk_window_is_toplevel (window))
6059 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6063 /* Bail early if no change */
6064 if (window->width == width &&
6065 window->height == height &&
6071 gdk_window_flush_if_exposing (window);
6073 /* Handle child windows */
6079 impl_window = gdk_window_get_impl_window (window);
6084 old_native_child_region = NULL;
6085 if (gdk_window_is_viewable (window) &&
6086 !window->input_only)
6090 old_region = cairo_region_copy (window->clip_region);
6091 old_layered = cairo_region_copy (window->layered_region);
6092 /* Adjust regions to parent window coords */
6093 cairo_region_translate (old_region, window->x, window->y);
6094 cairo_region_translate (old_layered, window->x, window->y);
6096 old_native_child_region = collect_native_child_region (window, TRUE);
6097 if (old_native_child_region)
6099 /* Adjust region to parent window coords */
6100 cairo_region_translate (old_native_child_region, window->x, window->y);
6102 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6103 * source or destination for a delayed GdkWindowRegionMove. So, we need
6104 * to flush those here for the parent window and all overlapped subwindows
6105 * of it. And we need to do this before setting the new clips as those will be
6108 gdk_window_flush_recursive (window->parent);
6112 /* Set the new position and size */
6118 if (!(width < 0 && height < 0))
6122 window->width = width;
6125 window->height = height;
6128 dx = window->x - old_x;
6129 dy = window->y - old_y;
6131 old_abs_x = window->abs_x;
6132 old_abs_y = window->abs_y;
6134 recompute_visible_regions (window, TRUE, FALSE);
6136 new_native_child_region = NULL;
6137 if (old_native_child_region)
6139 new_native_child_region = collect_native_child_region (window, TRUE);
6140 /* Adjust region to parent window coords */
6141 cairo_region_translate (new_native_child_region, window->x, window->y);
6144 if (gdk_window_has_impl (window))
6146 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6148 /* Do the actual move after recomputing things, as this will have set the shape to
6149 the now correct one, thus avoiding copying regions that should not be copied. */
6150 impl_class->move_resize (window, TRUE,
6151 window->x, window->y,
6152 window->width, window->height);
6154 else if (old_abs_x != window->abs_x ||
6155 old_abs_y != window->abs_y)
6156 move_native_children (window);
6160 new_region = cairo_region_copy (window->clip_region);
6161 /* Adjust region to parent window coords */
6162 cairo_region_translate (new_region, window->x, window->y);
6165 * Part of the data at the new location can be copied from the
6166 * old location, this area is the intersection of the old region
6167 * moved as the copy will move it and then intersected with
6171 * Everything in the old and new regions that is not copied must be
6172 * invalidated (including children) as this is newly exposed
6174 if (window->has_alpha_background)
6175 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6177 copy_area = cairo_region_copy (new_region);
6179 /* Don't copy from a previously layered region */
6180 cairo_region_translate (old_layered, dx, dy);
6181 cairo_region_subtract (copy_area, old_layered);
6183 /* Don't copy into a layered region */
6184 cairo_region_translate (copy_area, -window->x, -window->y);
6185 cairo_region_subtract (copy_area, window->layered_region);
6186 cairo_region_translate (copy_area, window->x, window->y);
6188 cairo_region_union (new_region, old_region);
6190 if (old_native_child_region)
6192 /* Don't copy from inside native children, as this is copied by
6193 * the native window move.
6195 cairo_region_subtract (old_region, old_native_child_region);
6197 cairo_region_translate (old_region, dx, dy);
6199 cairo_region_intersect (copy_area, old_region);
6201 if (new_native_child_region)
6203 /* Don't copy any bits that would cause a read from the moved
6204 native windows, as we can't read that data */
6205 cairo_region_translate (new_native_child_region, dx, dy);
6206 cairo_region_subtract (copy_area, new_native_child_region);
6207 cairo_region_translate (new_native_child_region, -dx, -dy);
6210 cairo_region_subtract (new_region, copy_area);
6212 /* Convert old region to impl coords */
6213 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6215 /* convert from parent coords to impl */
6216 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6218 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6220 /* Invalidate affected part in the parent window
6221 * (no higher window should be affected)
6222 * We also invalidate any children in that area, which could include
6223 * this window if it still overlaps that area.
6225 if (old_native_child_region)
6227 /* No need to expose the region that the native window move copies */
6228 cairo_region_translate (old_native_child_region, dx, dy);
6229 cairo_region_intersect (old_native_child_region, new_native_child_region);
6230 cairo_region_subtract (new_region, old_native_child_region);
6232 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6234 cairo_region_destroy (old_region);
6235 cairo_region_destroy (old_layered);
6236 cairo_region_destroy (new_region);
6239 if (old_native_child_region)
6241 cairo_region_destroy (old_native_child_region);
6242 cairo_region_destroy (new_native_child_region);
6245 _gdk_synthesize_crossing_events_for_geometry_change (window);
6252 * @window: a #GdkWindow
6253 * @x: X coordinate relative to window's parent
6254 * @y: Y coordinate relative to window's parent
6256 * Repositions a window relative to its parent window.
6257 * For toplevel windows, window managers may ignore or modify the move;
6258 * you should probably use gtk_window_move() on a #GtkWindow widget
6259 * anyway, instead of using GDK functions. For child windows,
6260 * the move will reliably succeed.
6262 * If you're also planning to resize the window, use gdk_window_move_resize()
6263 * to both move and resize simultaneously, for a nicer visual effect.
6266 gdk_window_move (GdkWindow *window,
6270 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6274 * gdk_window_resize:
6275 * @window: a #GdkWindow
6276 * @width: new width of the window
6277 * @height: new height of the window
6279 * Resizes @window; for toplevel windows, asks the window manager to resize
6280 * the window. The window manager may not allow the resize. When using GTK+,
6281 * use gtk_window_resize() instead of this low-level GDK function.
6283 * Windows may not be resized below 1x1.
6285 * If you're also planning to move the window, use gdk_window_move_resize()
6286 * to both move and resize simultaneously, for a nicer visual effect.
6289 gdk_window_resize (GdkWindow *window,
6293 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6298 * gdk_window_move_resize:
6299 * @window: a #GdkWindow
6300 * @x: new X position relative to window's parent
6301 * @y: new Y position relative to window's parent
6303 * @height: new height
6305 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6306 * except that both operations are performed at once, avoiding strange
6307 * visual effects. (i.e. the user may be able to see the window first
6308 * move, then resize, if you don't use gdk_window_move_resize().)
6311 gdk_window_move_resize (GdkWindow *window,
6317 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6322 * gdk_window_scroll:
6323 * @window: a #GdkWindow
6324 * @dx: Amount to scroll in the X direction
6325 * @dy: Amount to scroll in the Y direction
6327 * Scroll the contents of @window, both pixels and children, by the
6328 * given amount. @window itself does not move. Portions of the window
6329 * that the scroll operation brings in from offscreen areas are
6330 * invalidated. The invalidated region may be bigger than what would
6331 * strictly be necessary.
6333 * For X11, a minimum area will be invalidated if the window has no
6334 * subwindows, or if the edges of the window's parent do not extend
6335 * beyond the edges of the window. In other cases, a multi-step process
6336 * is used to scroll the window which may produce temporary visual
6337 * artifacts and unnecessary invalidations.
6340 gdk_window_scroll (GdkWindow *window,
6344 GdkWindow *impl_window;
6345 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6346 cairo_region_t *old_native_child_region, *new_native_child_region;
6349 g_return_if_fail (GDK_IS_WINDOW (window));
6351 if (dx == 0 && dy == 0)
6354 if (window->destroyed)
6357 gdk_window_flush_if_exposing (window);
6359 old_layered_area = cairo_region_copy (window->layered_region);
6360 old_native_child_region = collect_native_child_region (window, FALSE);
6361 if (old_native_child_region)
6363 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6364 * source or destination for a delayed GdkWindowRegionMove. So, we need
6365 * to flush those here for the window and all overlapped subwindows
6366 * of it. And we need to do this before setting the new clips as those will be
6369 gdk_window_flush_recursive (window);
6373 /* First move all child windows, without causing invalidation */
6375 tmp_list = window->children;
6378 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6380 /* Just update the positions, the bits will move with the copy */
6384 tmp_list = tmp_list->next;
6387 recompute_visible_regions (window, FALSE, TRUE);
6389 new_native_child_region = NULL;
6390 if (old_native_child_region)
6391 new_native_child_region = collect_native_child_region (window, FALSE);
6393 move_native_children (window);
6395 /* Then copy the actual bits of the window w/ child windows */
6397 impl_window = gdk_window_get_impl_window (window);
6399 /* Calculate the area that can be gotten by copying the old area */
6400 if (window->has_alpha_background)
6401 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6403 copy_area = cairo_region_copy (window->clip_region);
6404 cairo_region_subtract (copy_area, old_layered_area);
6405 if (old_native_child_region)
6407 /* Don't copy from inside native children, as this is copied by
6408 * the native window move.
6410 cairo_region_subtract (copy_area, old_native_child_region);
6412 /* Don't copy any bits that would cause a read from the moved
6413 native windows, as we can't read that data */
6414 cairo_region_subtract (copy_area, new_native_child_region);
6416 cairo_region_translate (copy_area, dx, dy);
6417 cairo_region_intersect (copy_area, window->clip_region);
6418 cairo_region_subtract (copy_area, window->layered_region);
6420 /* And the rest need to be invalidated */
6421 noncopy_area = cairo_region_copy (window->clip_region);
6422 cairo_region_subtract (noncopy_area, copy_area);
6424 /* convert from window coords to impl */
6425 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6427 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6429 /* Invalidate not copied regions */
6430 if (old_native_child_region)
6432 /* No need to expose the region that the native window move copies */
6433 cairo_region_translate (old_native_child_region, dx, dy);
6434 cairo_region_intersect (old_native_child_region, new_native_child_region);
6435 cairo_region_subtract (noncopy_area, old_native_child_region);
6437 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6439 cairo_region_destroy (noncopy_area);
6440 cairo_region_destroy (old_layered_area);
6442 if (old_native_child_region)
6444 cairo_region_destroy (old_native_child_region);
6445 cairo_region_destroy (new_native_child_region);
6448 _gdk_synthesize_crossing_events_for_geometry_change (window);
6452 * gdk_window_move_region:
6453 * @window: a #GdkWindow
6454 * @region: The #cairo_region_t to move
6455 * @dx: Amount to move in the X direction
6456 * @dy: Amount to move in the Y direction
6458 * Move the part of @window indicated by @region by @dy pixels in the Y
6459 * direction and @dx pixels in the X direction. The portions of @region
6460 * that not covered by the new position of @region are invalidated.
6462 * Child windows are not moved.
6467 gdk_window_move_region (GdkWindow *window,
6468 const cairo_region_t *region,
6472 GdkWindow *impl_window;
6473 cairo_region_t *nocopy_area;
6474 cairo_region_t *copy_area;
6476 g_return_if_fail (GDK_IS_WINDOW (window));
6477 g_return_if_fail (region != NULL);
6479 if (dx == 0 && dy == 0)
6482 if (window->destroyed)
6485 impl_window = gdk_window_get_impl_window (window);
6487 /* compute source regions */
6488 if (window->has_alpha_background)
6489 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6491 copy_area = cairo_region_copy (region);
6492 cairo_region_intersect (copy_area, window->clip_region_with_children);
6493 cairo_region_subtract (copy_area, window->layered_region);
6494 remove_layered_child_area (window, copy_area);
6496 /* compute destination regions */
6497 cairo_region_translate (copy_area, dx, dy);
6498 cairo_region_intersect (copy_area, window->clip_region_with_children);
6499 cairo_region_subtract (copy_area, window->layered_region);
6500 remove_layered_child_area (window, copy_area);
6502 /* Invalidate parts of the region (source and dest) not covered
6504 nocopy_area = cairo_region_copy (region);
6505 cairo_region_translate (nocopy_area, dx, dy);
6506 cairo_region_union (nocopy_area, region);
6507 cairo_region_subtract (nocopy_area, copy_area);
6509 /* convert from window coords to impl */
6510 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6511 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6513 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6514 cairo_region_destroy (nocopy_area);
6518 * gdk_window_set_background:
6519 * @window: a #GdkWindow
6520 * @color: a #GdkColor
6522 * Sets the background color of @window. (However, when using GTK+,
6523 * set the background of a widget with gtk_widget_modify_bg() - if
6524 * you're an application - or gtk_style_set_background() - if you're
6525 * implementing a custom widget.)
6527 * See also gdk_window_set_background_pattern().
6529 * Deprecated: 3.4: Use gdk_window_set_background_rgba() instead.
6532 gdk_window_set_background (GdkWindow *window,
6533 const GdkColor *color)
6535 cairo_pattern_t *pattern;
6537 g_return_if_fail (GDK_IS_WINDOW (window));
6539 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6540 color->green / 65535.,
6541 color->blue / 65535.);
6543 gdk_window_set_background_pattern (window, pattern);
6545 cairo_pattern_destroy (pattern);
6549 * gdk_window_set_background_rgba:
6550 * @window: a #GdkWindow
6551 * @rgba: a #GdkRGBA color
6553 * Sets the background color of @window.
6555 * See also gdk_window_set_background_pattern().
6558 gdk_window_set_background_rgba (GdkWindow *window,
6561 cairo_pattern_t *pattern;
6563 g_return_if_fail (GDK_IS_WINDOW (window));
6564 g_return_if_fail (rgba != NULL);
6566 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6567 rgba->blue, rgba->alpha);
6569 gdk_window_set_background_pattern (window, pattern);
6571 cairo_pattern_destroy (pattern);
6575 /* Updates has_alpha_background recursively for all child windows
6576 that have parent-relative alpha */
6578 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6583 for (l = window->children; l; l = l->next)
6587 if (child->background == NULL &&
6588 child->has_alpha_background != window->has_alpha_background)
6590 child->has_alpha_background = window->has_alpha_background;
6591 recompute_visible_regions (child, TRUE, FALSE);
6592 _gdk_window_propagate_has_alpha_background (child);
6598 * gdk_window_set_background_pattern:
6599 * @window: a #GdkWindow
6600 * @pattern: (allow-none): a pattern to use, or %NULL
6602 * Sets the background of @window.
6604 * A background of %NULL means that the window will inherit its
6605 * background form its parent window.
6607 * The windowing system will normally fill a window with its background
6608 * when the window is obscured then exposed.
6611 gdk_window_set_background_pattern (GdkWindow *window,
6612 cairo_pattern_t *pattern)
6615 cairo_pattern_type_t type;
6617 g_return_if_fail (GDK_IS_WINDOW (window));
6619 if (window->input_only)
6623 cairo_pattern_reference (pattern);
6624 if (window->background)
6625 cairo_pattern_destroy (window->background);
6626 window->background = pattern;
6630 if (pattern == NULL)
6632 /* parent-relative, copy has_alpha from parent */
6633 if (window->parent == NULL ||
6634 window->parent->window_type == GDK_WINDOW_ROOT)
6637 has_alpha = window->parent->has_alpha_background;
6641 type = cairo_pattern_get_type (pattern);
6643 if (type == CAIRO_PATTERN_TYPE_SOLID)
6646 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6650 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6651 type == CAIRO_PATTERN_TYPE_RADIAL)
6657 cairo_pattern_get_color_stop_count (pattern, &n);
6659 for (i = 0; i < n; i++)
6661 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6662 NULL, NULL, NULL, &alpha);
6670 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6672 cairo_surface_t *surface;
6673 cairo_content_t content;
6675 cairo_pattern_get_surface (pattern, &surface);
6676 content = cairo_surface_get_content (surface);
6678 (content == CAIRO_CONTENT_ALPHA) ||
6679 (content == CAIRO_CONTENT_COLOR_ALPHA);
6683 if (has_alpha != window->has_alpha_background)
6685 window->has_alpha_background = has_alpha;
6686 recompute_visible_regions (window, TRUE, FALSE);
6688 _gdk_window_propagate_has_alpha_background (window);
6691 if (gdk_window_has_impl (window))
6693 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6694 impl_class->set_background (window, pattern);
6697 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6701 * gdk_window_get_background_pattern:
6704 * Gets the pattern used to clear the background on @window. If @window
6705 * does not have its own background and reuses the parent's, %NULL is
6706 * returned and you'll have to query it yourself.
6708 * Returns: (transfer none): The pattern to use for the background or
6709 * %NULL to use the parent's background.
6714 gdk_window_get_background_pattern (GdkWindow *window)
6716 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6718 return window->background;
6722 gdk_window_set_cursor_internal (GdkWindow *window,
6726 if (GDK_WINDOW_DESTROYED (window))
6729 if (window->window_type == GDK_WINDOW_ROOT ||
6730 window->window_type == GDK_WINDOW_FOREIGN)
6731 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6734 GdkPointerWindowInfo *pointer_info;
6735 GdkDisplay *display;
6737 display = gdk_window_get_display (window);
6738 pointer_info = _gdk_display_get_pointer_info (display, device);
6740 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6741 update_cursor (display, device);
6746 * gdk_window_get_cursor:
6747 * @window: a #GdkWindow
6749 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6750 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6751 * there is no custom cursor set on the specified window, and it is
6752 * using the cursor for its parent window.
6754 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6755 * object is owned by the #GdkWindow and should not be unreferenced
6756 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6762 gdk_window_get_cursor (GdkWindow *window)
6764 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6766 return window->cursor;
6770 * gdk_window_set_cursor:
6771 * @window: a #GdkWindow
6772 * @cursor: (allow-none): a cursor
6774 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6775 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6776 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6777 * to gdk_window_set_cursor() means that @window will use the cursor of its
6778 * parent window. Most windows should use this default.
6781 gdk_window_set_cursor (GdkWindow *window,
6784 GdkDisplay *display;
6786 g_return_if_fail (GDK_IS_WINDOW (window));
6788 display = gdk_window_get_display (window);
6792 g_object_unref (window->cursor);
6793 window->cursor = NULL;
6796 if (!GDK_WINDOW_DESTROYED (window))
6798 GdkDeviceManager *device_manager;
6802 window->cursor = g_object_ref (cursor);
6804 device_manager = gdk_display_get_device_manager (display);
6805 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6807 for (d = devices; d; d = d->next)
6813 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6816 gdk_window_set_cursor_internal (window, device, window->cursor);
6819 g_list_free (devices);
6820 g_object_notify (G_OBJECT (window), "cursor");
6825 * gdk_window_get_device_cursor:
6826 * @window: a #GdkWindow.
6827 * @device: a master, pointer #GdkDevice.
6829 * Retrieves a #GdkCursor pointer for the @device currently set on the
6830 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6831 * there is no custom cursor set on the specified window, and it is
6832 * using the cursor for its parent window.
6834 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6835 * object is owned by the #GdkWindow and should not be unreferenced
6836 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6842 gdk_window_get_device_cursor (GdkWindow *window,
6845 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6846 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6847 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6848 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6850 return g_hash_table_lookup (window->device_cursor, device);
6854 * gdk_window_set_device_cursor:
6855 * @window: a #Gdkwindow
6856 * @device: a master, pointer #GdkDevice
6857 * @cursor: a #GdkCursor
6859 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6860 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6861 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
6862 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
6863 * @window will use the cursor of its parent window. Most windows should
6869 gdk_window_set_device_cursor (GdkWindow *window,
6873 g_return_if_fail (GDK_IS_WINDOW (window));
6874 g_return_if_fail (GDK_IS_DEVICE (device));
6875 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
6876 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
6879 g_hash_table_remove (window->device_cursor, device);
6881 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
6883 gdk_window_set_cursor_internal (window, device, cursor);
6887 * gdk_window_get_geometry:
6888 * @window: a #GdkWindow
6889 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
6890 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
6891 * @width: (out) (allow-none): return location for width of window
6892 * @height: (out) (allow-none): return location for height of window
6894 * Any of the return location arguments to this function may be %NULL,
6895 * if you aren't interested in getting the value of that field.
6897 * The X and Y coordinates returned are relative to the parent window
6898 * of @window, which for toplevels usually means relative to the
6899 * window decorations (titlebar, etc.) rather than relative to the
6900 * root window (screen-size background window).
6902 * On the X11 platform, the geometry is obtained from the X server,
6903 * so reflects the latest position of @window; this may be out-of-sync
6904 * with the position of @window delivered in the most-recently-processed
6905 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
6906 * position from the most recent configure event.
6909 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
6910 * to call gdk_window_get_position(), gdk_window_get_width() and
6911 * gdk_window_get_height() instead, because it avoids the roundtrip to
6912 * the X server and because these functions support the full 32-bit
6913 * coordinate space, whereas gdk_window_get_geometry() is restricted to
6914 * the 16-bit coordinates of X11.
6918 gdk_window_get_geometry (GdkWindow *window,
6925 GdkWindowImplClass *impl_class;
6929 GDK_NOTE (MULTIHEAD,
6930 g_message ("gdk_window_get_geometry(): Window needs "
6931 "to be non-NULL to be multi head safe"));
6932 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
6935 g_return_if_fail (GDK_IS_WINDOW (window));
6937 if (!GDK_WINDOW_DESTROYED (window))
6939 if (gdk_window_has_impl (window))
6941 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6942 impl_class->get_geometry (window, x, y,
6944 /* This reports the position wrt to the native parent, we need to convert
6945 it to be relative to the client side parent */
6946 parent = window->parent;
6947 if (parent && !gdk_window_has_impl (parent))
6950 *x -= parent->abs_x;
6952 *y -= parent->abs_y;
6962 *width = window->width;
6964 *height = window->height;
6970 * gdk_window_get_width:
6971 * @window: a #GdkWindow
6973 * Returns the width of the given @window.
6975 * On the X11 platform the returned size is the size reported in the
6976 * most-recently-processed configure event, rather than the current
6977 * size on the X server.
6979 * Returns: The width of @window
6984 gdk_window_get_width (GdkWindow *window)
6986 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6988 return window->width;
6992 * gdk_window_get_height:
6993 * @window: a #GdkWindow
6995 * Returns the height of the given @window.
6997 * On the X11 platform the returned size is the size reported in the
6998 * most-recently-processed configure event, rather than the current
6999 * size on the X server.
7001 * Returns: The height of @window
7006 gdk_window_get_height (GdkWindow *window)
7008 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7010 return window->height;
7014 * gdk_window_get_origin:
7015 * @window: a #GdkWindow
7016 * @x: (out) (allow-none): return location for X coordinate
7017 * @y: (out) (allow-none): return location for Y coordinate
7019 * Obtains the position of a window in root window coordinates.
7020 * (Compare with gdk_window_get_position() and
7021 * gdk_window_get_geometry() which return the position of a window
7022 * relative to its parent window.)
7024 * Return value: not meaningful, ignore
7027 gdk_window_get_origin (GdkWindow *window,
7031 GdkWindowImplClass *impl_class;
7033 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7035 if (GDK_WINDOW_DESTROYED (window))
7044 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7045 impl_class->get_root_coords (window,
7054 * gdk_window_get_root_coords:
7055 * @window: a #GdkWindow
7056 * @x: X coordinate in window
7057 * @y: Y coordinate in window
7058 * @root_x: (out): return location for X coordinate
7059 * @root_y: (out): return location for Y coordinate
7061 * Obtains the position of a window position in root
7062 * window coordinates. This is similar to
7063 * gdk_window_get_origin() but allows you go pass
7064 * in any position in the window, not just the origin.
7069 gdk_window_get_root_coords (GdkWindow *window,
7075 GdkWindowImplClass *impl_class;
7077 g_return_if_fail (GDK_IS_WINDOW (window));
7079 if (GDK_WINDOW_DESTROYED (window))
7086 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7087 impl_class->get_root_coords (window,
7094 * gdk_window_coords_to_parent:
7095 * @window: a child window
7096 * @x: X coordinate in child's coordinate system
7097 * @y: Y coordinate in child's coordinate system
7098 * @parent_x: (out) (allow-none): return location for X coordinate
7099 * in parent's coordinate system, or %NULL
7100 * @parent_y: (out) (allow-none): return location for Y coordinate
7101 * in parent's coordinate system, or %NULL
7103 * Transforms window coordinates from a child window to its parent
7104 * window, where the parent window is the normal parent as returned by
7105 * gdk_window_get_parent() for normal windows, and the window's
7106 * embedder as returned by gdk_offscreen_window_get_embedder() for
7107 * offscreen windows.
7109 * For normal windows, calling this function is equivalent to adding
7110 * the return values of gdk_window_get_position() to the child coordinates.
7111 * For offscreen windows however (which can be arbitrarily transformed),
7112 * this function calls the GdkWindow::to-embedder: signal to translate
7115 * You should always use this function when writing generic code that
7116 * walks up a window hierarchy.
7118 * See also: gdk_window_coords_from_parent()
7123 gdk_window_coords_to_parent (GdkWindow *window,
7129 g_return_if_fail (GDK_IS_WINDOW (window));
7131 if (gdk_window_is_offscreen (window))
7135 to_embedder (window, x, y, &px, &py);
7146 *parent_x = x + window->x;
7149 *parent_y = y + window->y;
7154 * gdk_window_coords_from_parent:
7155 * @window: a child window
7156 * @parent_x: X coordinate in parent's coordinate system
7157 * @parent_y: Y coordinate in parent's coordinate system
7158 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7159 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7161 * Transforms window coordinates from a parent window to a child
7162 * window, where the parent window is the normal parent as returned by
7163 * gdk_window_get_parent() for normal windows, and the window's
7164 * embedder as returned by gdk_offscreen_window_get_embedder() for
7165 * offscreen windows.
7167 * For normal windows, calling this function is equivalent to subtracting
7168 * the return values of gdk_window_get_position() from the parent coordinates.
7169 * For offscreen windows however (which can be arbitrarily transformed),
7170 * this function calls the GdkWindow::from-embedder: signal to translate
7173 * You should always use this function when writing generic code that
7174 * walks down a window hierarchy.
7176 * See also: gdk_window_coords_to_parent()
7181 gdk_window_coords_from_parent (GdkWindow *window,
7187 g_return_if_fail (GDK_IS_WINDOW (window));
7189 if (gdk_window_is_offscreen (window))
7193 from_embedder (window, parent_x, parent_y, &cx, &cy);
7204 *x = parent_x - window->x;
7207 *y = parent_y - window->y;
7212 * gdk_window_shape_combine_region:
7213 * @window: a #GdkWindow
7214 * @shape_region: (allow-none): region of window to be non-transparent
7215 * @offset_x: X position of @shape_region in @window coordinates
7216 * @offset_y: Y position of @shape_region in @window coordinates
7218 * Makes pixels in @window outside @shape_region be transparent,
7219 * so that the window may be nonrectangular.
7221 * If @shape_region is %NULL, the shape will be unset, so the whole
7222 * window will be opaque again. @offset_x and @offset_y are ignored
7223 * if @shape_region is %NULL.
7225 * On the X11 platform, this uses an X server extension which is
7226 * widely available on most common platforms, but not available on
7227 * very old X servers, and occasionally the implementation will be
7228 * buggy. On servers without the shape extension, this function
7231 * This function works on both toplevel and child windows.
7234 gdk_window_shape_combine_region (GdkWindow *window,
7235 const cairo_region_t *shape_region,
7239 cairo_region_t *old_region, *new_region, *diff;
7241 g_return_if_fail (GDK_IS_WINDOW (window));
7243 if (GDK_WINDOW_DESTROYED (window))
7246 if (!window->shape && shape_region == NULL)
7249 window->shaped = (shape_region != NULL);
7252 cairo_region_destroy (window->shape);
7255 if (GDK_WINDOW_IS_MAPPED (window))
7256 old_region = cairo_region_copy (window->clip_region);
7260 window->shape = cairo_region_copy (shape_region);
7261 cairo_region_translate (window->shape, offset_x, offset_y);
7264 window->shape = NULL;
7266 recompute_visible_regions (window, TRUE, FALSE);
7268 if (gdk_window_has_impl (window) &&
7269 !should_apply_clip_as_shape (window))
7270 apply_shape (window, window->shape);
7274 new_region = cairo_region_copy (window->clip_region);
7276 /* New area in the window, needs invalidation */
7277 diff = cairo_region_copy (new_region);
7278 cairo_region_subtract (diff, old_region);
7280 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7282 cairo_region_destroy (diff);
7284 if (!gdk_window_is_toplevel (window))
7286 /* New area in the non-root parent window, needs invalidation */
7287 diff = cairo_region_copy (old_region);
7288 cairo_region_subtract (diff, new_region);
7290 /* Adjust region to parent window coords */
7291 cairo_region_translate (diff, window->x, window->y);
7293 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7295 cairo_region_destroy (diff);
7298 cairo_region_destroy (new_region);
7299 cairo_region_destroy (old_region);
7304 do_child_shapes (GdkWindow *window,
7308 cairo_region_t *region;
7312 r.width = window->width;
7313 r.height = window->height;
7315 region = cairo_region_create_rectangle (&r);
7316 remove_child_area (window, NULL, FALSE, region, NULL);
7318 if (merge && window->shape)
7319 cairo_region_subtract (region, window->shape);
7321 gdk_window_shape_combine_region (window, region, 0, 0);
7325 * gdk_window_set_child_shapes:
7326 * @window: a #GdkWindow
7328 * Sets the shape mask of @window to the union of shape masks
7329 * for all children of @window, ignoring the shape mask of @window
7330 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7331 * the shape mask of @window in the masks to be merged.
7334 gdk_window_set_child_shapes (GdkWindow *window)
7336 g_return_if_fail (GDK_IS_WINDOW (window));
7338 do_child_shapes (window, FALSE);
7342 * gdk_window_merge_child_shapes:
7343 * @window: a #GdkWindow
7345 * Merges the shape masks for any child windows into the
7346 * shape mask for @window. i.e. the union of all masks
7347 * for @window and its children will become the new mask
7348 * for @window. See gdk_window_shape_combine_region().
7350 * This function is distinct from gdk_window_set_child_shapes()
7351 * because it includes @window's shape mask in the set of shapes to
7355 gdk_window_merge_child_shapes (GdkWindow *window)
7357 g_return_if_fail (GDK_IS_WINDOW (window));
7359 do_child_shapes (window, TRUE);
7363 * gdk_window_input_shape_combine_region:
7364 * @window: a #GdkWindow
7365 * @shape_region: region of window to be non-transparent
7366 * @offset_x: X position of @shape_region in @window coordinates
7367 * @offset_y: Y position of @shape_region in @window coordinates
7369 * Like gdk_window_shape_combine_region(), but the shape applies
7370 * only to event handling. Mouse events which happen while
7371 * the pointer position corresponds to an unset bit in the
7372 * mask will be passed on the window below @window.
7374 * An input shape is typically used with RGBA windows.
7375 * The alpha channel of the window defines which pixels are
7376 * invisible and allows for nicely antialiased borders,
7377 * and the input shape controls where the window is
7380 * On the X11 platform, this requires version 1.1 of the
7383 * On the Win32 platform, this functionality is not present and the
7384 * function does nothing.
7389 gdk_window_input_shape_combine_region (GdkWindow *window,
7390 const cairo_region_t *shape_region,
7394 GdkWindowImplClass *impl_class;
7396 g_return_if_fail (GDK_IS_WINDOW (window));
7398 if (GDK_WINDOW_DESTROYED (window))
7401 if (window->input_shape)
7402 cairo_region_destroy (window->input_shape);
7406 window->input_shape = cairo_region_copy (shape_region);
7407 cairo_region_translate (window->input_shape, offset_x, offset_y);
7410 window->input_shape = NULL;
7412 if (gdk_window_has_impl (window))
7414 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7415 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7418 /* Pointer may have e.g. moved outside window due to the input mask change */
7419 _gdk_synthesize_crossing_events_for_geometry_change (window);
7423 do_child_input_shapes (GdkWindow *window,
7427 cairo_region_t *region;
7431 r.width = window->width;
7432 r.height = window->height;
7434 region = cairo_region_create_rectangle (&r);
7435 remove_child_area (window, NULL, TRUE, region, NULL);
7437 if (merge && window->shape)
7438 cairo_region_subtract (region, window->shape);
7439 if (merge && window->input_shape)
7440 cairo_region_subtract (region, window->input_shape);
7442 gdk_window_input_shape_combine_region (window, region, 0, 0);
7447 * gdk_window_set_child_input_shapes:
7448 * @window: a #GdkWindow
7450 * Sets the input shape mask of @window to the union of input shape masks
7451 * for all children of @window, ignoring the input shape mask of @window
7452 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7453 * the input shape mask of @window in the masks to be merged.
7458 gdk_window_set_child_input_shapes (GdkWindow *window)
7460 g_return_if_fail (GDK_IS_WINDOW (window));
7462 do_child_input_shapes (window, FALSE);
7466 * gdk_window_merge_child_input_shapes:
7467 * @window: a #GdkWindow
7469 * Merges the input shape masks for any child windows into the
7470 * input shape mask for @window. i.e. the union of all input masks
7471 * for @window and its children will become the new input mask
7472 * for @window. See gdk_window_input_shape_combine_region().
7474 * This function is distinct from gdk_window_set_child_input_shapes()
7475 * because it includes @window's input shape mask in the set of
7476 * shapes to be merged.
7481 gdk_window_merge_child_input_shapes (GdkWindow *window)
7483 g_return_if_fail (GDK_IS_WINDOW (window));
7485 do_child_input_shapes (window, TRUE);
7490 * gdk_window_set_static_gravities:
7491 * @window: a #GdkWindow
7492 * @use_static: %TRUE to turn on static gravity
7494 * Set the bit gravity of the given window to static, and flag it so
7495 * all children get static subwindow gravity. This is used if you are
7496 * implementing scary features that involve deep knowledge of the
7497 * windowing system. Don't worry about it unless you have to.
7499 * Return value: %TRUE if the server supports static gravity
7502 gdk_window_set_static_gravities (GdkWindow *window,
7503 gboolean use_static)
7505 GdkWindowImplClass *impl_class;
7507 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7509 if (gdk_window_has_impl (window))
7511 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7512 return impl_class->set_static_gravities (window, use_static);
7519 * gdk_window_get_composited:
7520 * @window: a #GdkWindow
7522 * Determines whether @window is composited.
7524 * See gdk_window_set_composited().
7526 * Returns: %TRUE if the window is composited.
7531 gdk_window_get_composited (GdkWindow *window)
7533 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7535 return window->composited;
7539 * gdk_window_set_composited:
7540 * @window: a #GdkWindow
7541 * @composited: %TRUE to set the window as composited
7543 * Sets a #GdkWindow as composited, or unsets it. Composited
7544 * windows do not automatically have their contents drawn to
7545 * the screen. Drawing is redirected to an offscreen buffer
7546 * and an expose event is emitted on the parent of the composited
7547 * window. It is the responsibility of the parent's expose handler
7548 * to manually merge the off-screen content onto the screen in
7549 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7552 * It only makes sense for child windows to be composited; see
7553 * gdk_window_set_opacity() if you need translucent toplevel
7556 * An additional effect of this call is that the area of this
7557 * window is no longer clipped from regions marked for
7558 * invalidation on its parent. Draws done on the parent
7559 * window are also no longer clipped by the child.
7561 * This call is only supported on some systems (currently,
7562 * only X11 with new enough Xcomposite and Xdamage extensions).
7563 * You must call gdk_display_supports_composite() to check if
7564 * setting a window as composited is supported before
7565 * attempting to do so.
7570 gdk_window_set_composited (GdkWindow *window,
7571 gboolean composited)
7573 GdkDisplay *display;
7574 GdkWindowImplClass *impl_class;
7576 g_return_if_fail (GDK_IS_WINDOW (window));
7578 composited = composited != FALSE;
7580 if (window->composited == composited)
7584 gdk_window_ensure_native (window);
7586 display = gdk_window_get_display (window);
7588 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7590 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7592 g_warning ("gdk_window_set_composited called but "
7593 "compositing is not supported");
7597 impl_class->set_composited (window, composited);
7599 recompute_visible_regions (window, TRUE, FALSE);
7601 if (GDK_WINDOW_IS_MAPPED (window))
7602 gdk_window_invalidate_in_parent (window);
7604 window->composited = composited;
7608 * gdk_window_get_modal_hint:
7609 * @window: A toplevel #GdkWindow.
7611 * Determines whether or not the window manager is hinted that @window
7612 * has modal behaviour.
7614 * Return value: whether or not the window has the modal hint set.
7619 gdk_window_get_modal_hint (GdkWindow *window)
7621 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7623 return window->modal_hint;
7627 * gdk_window_get_accept_focus:
7628 * @window: a toplevel #GdkWindow.
7630 * Determines whether or not the desktop environment shuld be hinted that
7631 * the window does not want to receive input focus.
7633 * Return value: whether or not the window should receive input focus.
7638 gdk_window_get_accept_focus (GdkWindow *window)
7640 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7642 return window->accept_focus;
7646 * gdk_window_get_focus_on_map:
7647 * @window: a toplevel #GdkWindow.
7649 * Determines whether or not the desktop environment should be hinted that the
7650 * window does not want to receive input focus when it is mapped.
7652 * Return value: whether or not the window wants to receive input focus when
7658 gdk_window_get_focus_on_map (GdkWindow *window)
7660 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7662 return window->focus_on_map;
7666 * gdk_window_is_input_only:
7667 * @window: a toplevel #GdkWindow
7669 * Determines whether or not the window is an input only window.
7671 * Return value: %TRUE if @window is input only
7676 gdk_window_is_input_only (GdkWindow *window)
7678 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7680 return window->input_only;
7684 * gdk_window_is_shaped:
7685 * @window: a toplevel #GdkWindow
7687 * Determines whether or not the window is shaped.
7689 * Return value: %TRUE if @window is shaped
7694 gdk_window_is_shaped (GdkWindow *window)
7696 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7698 return window->shaped;
7702 _gdk_window_add_damage (GdkWindow *toplevel,
7703 cairo_region_t *damaged_region)
7705 GdkDisplay *display;
7706 GdkEvent event = { 0, };
7707 event.expose.type = GDK_DAMAGE;
7708 event.expose.window = toplevel;
7709 event.expose.send_event = FALSE;
7710 event.expose.region = damaged_region;
7711 cairo_region_get_extents (event.expose.region, &event.expose.area);
7712 display = gdk_window_get_display (event.expose.window);
7713 _gdk_event_queue_append (display, gdk_event_copy (&event));
7716 /* Gets the toplevel for a window as used for events,
7717 i.e. including offscreen parents */
7719 get_event_parent (GdkWindow *window)
7721 if (gdk_window_is_offscreen (window))
7722 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7724 return window->parent;
7727 /* Gets the toplevel for a window as used for events,
7728 i.e. including offscreen parents going up to the native
7731 get_event_toplevel (GdkWindow *window)
7735 while ((parent = get_event_parent (window)) != NULL &&
7736 (parent->window_type != GDK_WINDOW_ROOT))
7743 _gdk_window_event_parent_of (GdkWindow *parent,
7754 w = get_event_parent (w);
7761 update_cursor (GdkDisplay *display,
7764 GdkWindow *cursor_window, *parent, *toplevel;
7765 GdkWindow *pointer_window;
7766 GdkWindowImplClass *impl_class;
7767 GdkPointerWindowInfo *pointer_info;
7768 GdkDeviceGrabInfo *grab;
7771 pointer_info = _gdk_display_get_pointer_info (display, device);
7772 pointer_window = pointer_info->window_under_pointer;
7774 /* We ignore the serials here and just pick the last grab
7775 we've sent, as that would shortly be used anyway. */
7776 grab = _gdk_display_get_last_device_grab (display, device);
7779 /* the pointer is not in a descendant of the grab window */
7780 !_gdk_window_event_parent_of (grab->window, pointer_window))
7782 /* use the cursor from the grab window */
7783 cursor_window = grab->window;
7787 /* otherwise use the cursor from the pointer window */
7788 cursor_window = pointer_window;
7791 /* Find the first window with the cursor actually set, as
7792 the cursor is inherited from the parent */
7793 while (cursor_window->cursor == NULL &&
7794 (parent = get_event_parent (cursor_window)) != NULL &&
7795 parent->window_type != GDK_WINDOW_ROOT)
7796 cursor_window = parent;
7798 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7801 cursor = cursor_window->cursor;
7803 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7804 * which native window has what cursor set. */
7805 toplevel = get_event_toplevel (pointer_window);
7806 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7807 impl_class->set_device_cursor (toplevel, device, cursor);
7811 point_in_window (GdkWindow *window,
7816 x >= 0 && x < window->width &&
7817 y >= 0 && y < window->height &&
7818 (window->shape == NULL ||
7819 cairo_region_contains_point (window->shape,
7821 (window->input_shape == NULL ||
7822 cairo_region_contains_point (window->input_shape,
7827 convert_native_coords_to_toplevel (GdkWindow *window,
7830 gdouble *toplevel_x,
7831 gdouble *toplevel_y)
7838 while (!gdk_window_is_toplevel (window))
7842 window = window->parent;
7852 convert_toplevel_coords_to_window (GdkWindow *window,
7860 GList *children, *l;
7866 while ((parent = get_event_parent (window)) != NULL &&
7867 (parent->window_type != GDK_WINDOW_ROOT))
7869 children = g_list_prepend (children, window);
7873 for (l = children; l != NULL; l = l->next)
7874 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
7876 g_list_free (children);
7883 pick_embedded_child (GdkWindow *window,
7890 g_signal_emit (window,
7891 signals[PICK_EMBEDDED_CHILD], 0,
7898 _gdk_window_find_child_at (GdkWindow *window,
7903 double child_x, child_y;
7906 if (point_in_window (window, x, y))
7908 /* Children is ordered in reverse stack order, i.e. first is topmost */
7909 for (l = window->children; l != NULL; l = l->next)
7913 if (!GDK_WINDOW_IS_MAPPED (sub))
7916 gdk_window_coords_from_parent ((GdkWindow *)sub,
7918 &child_x, &child_y);
7919 if (point_in_window (sub, child_x, child_y))
7920 return (GdkWindow *)sub;
7923 if (window->num_offscreen_children > 0)
7925 sub = pick_embedded_child (window,
7928 return (GdkWindow *)sub;
7936 _gdk_window_find_descendant_at (GdkWindow *window,
7943 gdouble child_x, child_y;
7947 if (point_in_window (window, x, y))
7952 /* Children is ordered in reverse stack order, i.e. first is topmost */
7953 for (l = window->children; l != NULL; l = l->next)
7957 if (!GDK_WINDOW_IS_MAPPED (sub))
7960 gdk_window_coords_from_parent ((GdkWindow *)sub,
7962 &child_x, &child_y);
7963 if (point_in_window (sub, child_x, child_y))
7973 window->num_offscreen_children > 0)
7975 sub = pick_embedded_child (window,
7981 from_embedder (sub, x, y, &x, &y);
7989 /* Not in window at all */
8003 * @window: a toplevel #GdkWindow
8005 * Emits a short beep associated to @window in the appropriate
8006 * display, if supported. Otherwise, emits a short beep on
8007 * the display just as gdk_display_beep().
8012 gdk_window_beep (GdkWindow *window)
8014 GdkDisplay *display;
8015 GdkWindow *toplevel;
8017 g_return_if_fail (GDK_IS_WINDOW (window));
8019 if (GDK_WINDOW_DESTROYED (window))
8022 toplevel = get_event_toplevel (window);
8023 display = gdk_window_get_display (window);
8027 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
8031 /* If windows fail to beep, we beep the display. */
8032 gdk_display_beep (display);
8036 * gdk_window_set_support_multidevice:
8037 * @window: a #GdkWindow.
8038 * @support_multidevice: %TRUE to enable multidevice support in @window.
8040 * This function will enable multidevice features in @window.
8042 * Multidevice aware windows will need to handle properly multiple,
8043 * per device enter/leave events, device grabs and grab ownerships.
8048 gdk_window_set_support_multidevice (GdkWindow *window,
8049 gboolean support_multidevice)
8051 g_return_if_fail (GDK_IS_WINDOW (window));
8053 if (GDK_WINDOW_DESTROYED (window))
8056 if (window->support_multidevice == support_multidevice)
8059 window->support_multidevice = support_multidevice;
8061 /* FIXME: What to do if called when some pointers are inside the window ? */
8065 * gdk_window_get_support_multidevice:
8066 * @window: a #GdkWindow.
8068 * Returns %TRUE if the window is aware of the existence of multiple
8071 * Returns: %TRUE if the window handles multidevice features.
8076 gdk_window_get_support_multidevice (GdkWindow *window)
8078 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8080 if (GDK_WINDOW_DESTROYED (window))
8083 return window->support_multidevice;
8086 static const guint type_masks[] = {
8087 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8088 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8089 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8090 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8091 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8092 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8093 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8094 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8095 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8096 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8097 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8098 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8099 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8100 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8101 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8102 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8103 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8104 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8105 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8106 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8107 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8108 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8109 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8110 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8111 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8112 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8113 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8114 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8115 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8116 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8117 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8118 GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK,/* GDK_SCROLL= 31 */
8119 0, /* GDK_WINDOW_STATE = 32 */
8120 0, /* GDK_SETTING = 33 */
8121 0, /* GDK_OWNER_CHANGE = 34 */
8122 0, /* GDK_GRAB_BROKEN = 35 */
8123 0, /* GDK_DAMAGE = 36 */
8124 GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */
8125 GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */
8126 GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */
8127 GDK_TOUCH_MASK /* GDK_TOUCH_CANCEL = 40 */
8129 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8131 /* send motion events if the right buttons are down */
8133 update_evmask_for_button_motion (guint evmask,
8134 GdkModifierType mask)
8136 if (evmask & GDK_BUTTON_MOTION_MASK &&
8137 mask & (GDK_BUTTON1_MASK |
8142 evmask |= GDK_POINTER_MOTION_MASK;
8144 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8145 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8146 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8147 evmask |= GDK_POINTER_MOTION_MASK;
8153 is_button_type (GdkEventType type)
8155 return type == GDK_BUTTON_PRESS ||
8156 type == GDK_2BUTTON_PRESS ||
8157 type == GDK_3BUTTON_PRESS ||
8158 type == GDK_BUTTON_RELEASE ||
8163 is_motion_type (GdkEventType type)
8165 return type == GDK_MOTION_NOTIFY ||
8166 type == GDK_ENTER_NOTIFY ||
8167 type == GDK_LEAVE_NOTIFY;
8171 find_common_ancestor (GdkWindow *win1,
8175 GList *path1 = NULL, *path2 = NULL;
8176 GList *list1, *list2;
8179 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8181 path1 = g_list_prepend (path1, tmp);
8182 tmp = get_event_parent (tmp);
8186 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8188 path2 = g_list_prepend (path2, tmp);
8189 tmp = get_event_parent (tmp);
8195 while (list1 && list2 && (list1->data == list2->data))
8198 list1 = g_list_next (list1);
8199 list2 = g_list_next (list2);
8201 g_list_free (path1);
8202 g_list_free (path2);
8208 _gdk_make_event (GdkWindow *window,
8210 GdkEvent *event_in_queue,
8211 gboolean before_event)
8213 GdkEvent *event = gdk_event_new (type);
8215 GdkModifierType the_state;
8217 the_time = gdk_event_get_time (event_in_queue);
8218 gdk_event_get_state (event_in_queue, &the_state);
8220 event->any.window = g_object_ref (window);
8221 event->any.send_event = FALSE;
8222 if (event_in_queue && event_in_queue->any.send_event)
8223 event->any.send_event = TRUE;
8227 case GDK_MOTION_NOTIFY:
8228 event->motion.time = the_time;
8229 event->motion.axes = NULL;
8230 event->motion.state = the_state;
8233 case GDK_BUTTON_PRESS:
8234 case GDK_2BUTTON_PRESS:
8235 case GDK_3BUTTON_PRESS:
8236 case GDK_BUTTON_RELEASE:
8237 event->button.time = the_time;
8238 event->button.axes = NULL;
8239 event->button.state = the_state;
8242 case GDK_TOUCH_BEGIN:
8243 case GDK_TOUCH_UPDATE:
8245 case GDK_TOUCH_CANCEL:
8246 event->touch.time = the_time;
8247 event->touch.axes = NULL;
8248 event->touch.state = the_state;
8253 event->scroll.time = the_time;
8254 event->scroll.state = the_state;
8258 case GDK_KEY_RELEASE:
8259 event->key.time = the_time;
8260 event->key.state = the_state;
8263 case GDK_ENTER_NOTIFY:
8264 case GDK_LEAVE_NOTIFY:
8265 event->crossing.time = the_time;
8266 event->crossing.state = the_state;
8269 case GDK_PROPERTY_NOTIFY:
8270 event->property.time = the_time;
8271 event->property.state = the_state;
8274 case GDK_SELECTION_CLEAR:
8275 case GDK_SELECTION_REQUEST:
8276 case GDK_SELECTION_NOTIFY:
8277 event->selection.time = the_time;
8280 case GDK_PROXIMITY_IN:
8281 case GDK_PROXIMITY_OUT:
8282 event->proximity.time = the_time;
8285 case GDK_DRAG_ENTER:
8286 case GDK_DRAG_LEAVE:
8287 case GDK_DRAG_MOTION:
8288 case GDK_DRAG_STATUS:
8289 case GDK_DROP_START:
8290 case GDK_DROP_FINISHED:
8291 event->dnd.time = the_time;
8294 case GDK_FOCUS_CHANGE:
8298 case GDK_CLIENT_EVENT:
8299 case GDK_VISIBILITY_NOTIFY:
8310 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8312 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8315 _gdk_event_queue_append (gdk_window_get_display (window), event);
8321 send_crossing_event (GdkDisplay *display,
8322 GdkWindow *toplevel,
8325 GdkCrossingMode mode,
8326 GdkNotifyType notify_type,
8327 GdkWindow *subwindow,
8329 GdkDevice *source_device,
8332 GdkModifierType mask,
8334 GdkEvent *event_in_queue,
8338 guint32 window_event_mask, type_event_mask;
8339 GdkDeviceGrabInfo *grab;
8340 GdkPointerWindowInfo *pointer_info;
8341 gboolean block_event = FALSE;
8343 grab = _gdk_display_has_device_grab (display, device, serial);
8344 pointer_info = _gdk_display_get_pointer_info (display, device);
8347 !grab->owner_events)
8349 /* !owner_event => only report events wrt grab window, ignore rest */
8350 if ((GdkWindow *)window != grab->window)
8352 window_event_mask = grab->event_mask;
8355 window_event_mask = window->event_mask;
8357 if (type == GDK_ENTER_NOTIFY &&
8358 pointer_info->need_touch_press_enter &&
8359 mode != GDK_CROSSING_TOUCH_BEGIN &&
8360 mode != GDK_CROSSING_TOUCH_END)
8364 else if (type == GDK_LEAVE_NOTIFY)
8366 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8367 window->devices_inside = g_list_remove (window->devices_inside, device);
8369 if (!window->support_multidevice && window->devices_inside)
8371 /* Block leave events unless it's the last pointer */
8377 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8379 if (!window->support_multidevice && window->devices_inside)
8381 /* Only emit enter events for the first device */
8385 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8386 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8387 !g_list_find (window->devices_inside, device))
8388 window->devices_inside = g_list_prepend (window->devices_inside, device);
8394 if (window_event_mask & type_event_mask)
8396 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8397 gdk_event_set_device (event, device);
8400 gdk_event_set_source_device (event, source_device);
8402 event->crossing.time = time_;
8403 event->crossing.subwindow = subwindow;
8405 g_object_ref (subwindow);
8406 convert_toplevel_coords_to_window ((GdkWindow *)window,
8407 toplevel_x, toplevel_y,
8408 &event->crossing.x, &event->crossing.y);
8409 event->crossing.x_root = toplevel_x + toplevel->x;
8410 event->crossing.y_root = toplevel_y + toplevel->y;
8411 event->crossing.mode = mode;
8412 event->crossing.detail = notify_type;
8413 event->crossing.focus = FALSE;
8414 event->crossing.state = mask;
8419 /* The coordinates are in the toplevel window that src/dest are in.
8420 * src and dest are always (if != NULL) in the same toplevel, as
8421 * we get a leave-notify and set the window_under_pointer to null
8422 * before crossing to another toplevel.
8425 _gdk_synthesize_crossing_events (GdkDisplay *display,
8429 GdkDevice *source_device,
8430 GdkCrossingMode mode,
8433 GdkModifierType mask,
8435 GdkEvent *event_in_queue,
8437 gboolean non_linear)
8440 GdkWindow *win, *last, *next;
8444 GdkWindow *toplevel;
8445 GdkNotifyType notify_type;
8447 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8452 return; /* No crossings generated between src and dest */
8454 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8456 if (a && gdk_window_get_device_events (src, device) == 0)
8459 if (b && gdk_window_get_device_events (dest, device) == 0)
8466 c = find_common_ancestor (a, b);
8468 non_linear |= (c != a) && (c != b);
8470 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8472 toplevel = gdk_window_get_toplevel (a);
8474 /* Traverse up from a to (excluding) c sending leave events */
8476 notify_type = GDK_NOTIFY_NONLINEAR;
8478 notify_type = GDK_NOTIFY_INFERIOR;
8480 notify_type = GDK_NOTIFY_ANCESTOR;
8481 send_crossing_event (display, toplevel,
8482 a, GDK_LEAVE_NOTIFY,
8485 NULL, device, source_device,
8486 toplevel_x, toplevel_y,
8494 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8496 notify_type = GDK_NOTIFY_VIRTUAL;
8499 win = get_event_parent (a);
8500 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8502 send_crossing_event (display, toplevel,
8503 win, GDK_LEAVE_NOTIFY,
8507 device, source_device,
8508 toplevel_x, toplevel_y,
8514 win = get_event_parent (win);
8519 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8521 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8523 /* Traverse down from c to b */
8527 win = get_event_parent (b);
8528 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8530 path = g_list_prepend (path, win);
8531 win = get_event_parent (win);
8535 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8537 notify_type = GDK_NOTIFY_VIRTUAL;
8543 list = g_list_next (list);
8549 send_crossing_event (display, toplevel,
8550 win, GDK_ENTER_NOTIFY,
8554 device, source_device,
8555 toplevel_x, toplevel_y,
8565 notify_type = GDK_NOTIFY_NONLINEAR;
8567 notify_type = GDK_NOTIFY_ANCESTOR;
8569 notify_type = GDK_NOTIFY_INFERIOR;
8571 send_crossing_event (display, toplevel,
8572 b, GDK_ENTER_NOTIFY,
8576 device, source_device,
8577 toplevel_x, toplevel_y,
8584 /* Returns the window inside the event window with the pointer in it
8585 * at the specified coordinates, or NULL if its not in any child of
8586 * the toplevel. It also takes into account !owner_events grabs.
8589 get_pointer_window (GdkDisplay *display,
8590 GdkWindow *event_window,
8596 GdkWindow *pointer_window;
8597 GdkDeviceGrabInfo *grab;
8598 GdkPointerWindowInfo *pointer_info;
8600 pointer_info = _gdk_display_get_pointer_info (display, device);
8602 if (event_window == pointer_info->toplevel_under_pointer)
8604 _gdk_window_find_descendant_at (event_window,
8605 toplevel_x, toplevel_y,
8608 pointer_window = NULL;
8610 grab = _gdk_display_has_device_grab (display, device, serial);
8612 !grab->owner_events &&
8613 pointer_window != grab->window)
8614 pointer_window = NULL;
8616 return pointer_window;
8620 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8624 GdkPointerWindowInfo *device_info;
8626 device_info = _gdk_display_get_pointer_info (display, device);
8628 if (device_info->window_under_pointer)
8629 g_object_unref (device_info->window_under_pointer);
8630 device_info->window_under_pointer = window;
8634 g_object_ref (window);
8635 update_cursor (display, device);
8638 _gdk_display_enable_motion_hints (display, device);
8643 * @window: the #GdkWindow which will own the grab (the grab window).
8644 * @owner_events: if %FALSE then all pointer events are reported with respect to
8645 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8646 * events for this application are reported as normal, but pointer events outside
8647 * this application are reported with respect to @window and only if selected by
8648 * @event_mask. In either mode, unreported events are discarded.
8649 * @event_mask: specifies the event mask, which is used in accordance with
8650 * @owner_events. Note that only pointer events (i.e. button and motion events)
8652 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8653 * window during the grab. If the pointer is outside @confine_to, it will
8654 * automatically be moved to the closest edge of @confine_to and enter
8655 * and leave events will be generated as necessary.
8656 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8657 * the normal cursors are used for @window and its descendants, and the cursor
8658 * for @window is used for all other windows.
8659 * @time_: the timestamp of the event which led to this pointer grab. This usually
8660 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8661 * the time isn't known.
8663 * Grabs the pointer (usually a mouse) so that all events are passed to this
8664 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8665 * the grab window becomes unviewable.
8666 * This overrides any previous pointer grab by this client.
8668 * Pointer grabs are used for operations which need complete control over mouse
8669 * events, even if the mouse leaves the application.
8670 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8671 * the #GtkHPaned and #GtkVPaned widgets.
8673 * Note that if the event mask of an X window has selected both button press and
8674 * button release events, then a button press event will cause an automatic
8675 * pointer grab until the button is released.
8676 * X does this automatically since most applications expect to receive button
8677 * press and release events in pairs.
8678 * It is equivalent to a pointer grab on the window with @owner_events set to
8681 * If you set up anything at the time you take the grab that needs to be cleaned
8682 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8683 * are emitted when the grab ends unvoluntarily.
8685 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8687 * Deprecated: 3.0: Use gdk_device_grab() instead.
8690 gdk_pointer_grab (GdkWindow * window,
8691 gboolean owner_events,
8692 GdkEventMask event_mask,
8693 GdkWindow * confine_to,
8698 GdkDisplay *display;
8699 GdkDeviceManager *device_manager;
8701 GdkGrabStatus res = 0;
8703 GList *devices, *dev;
8705 g_return_val_if_fail (window != NULL, 0);
8706 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8707 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8709 /* We need a native window for confine to to work, ensure we have one */
8712 if (!gdk_window_ensure_native (confine_to))
8714 g_warning ("Can't confine to grabbed window, not native");
8719 /* Non-viewable client side window => fail */
8720 if (!_gdk_window_has_impl (window) &&
8721 !gdk_window_is_viewable (window))
8722 return GDK_GRAB_NOT_VIEWABLE;
8724 native = gdk_window_get_toplevel (window);
8725 while (gdk_window_is_offscreen (native))
8727 native = gdk_offscreen_window_get_embedder (native);
8729 if (native == NULL ||
8730 (!_gdk_window_has_impl (native) &&
8731 !gdk_window_is_viewable (native)))
8732 return GDK_GRAB_NOT_VIEWABLE;
8734 native = gdk_window_get_toplevel (native);
8737 display = gdk_window_get_display (window);
8739 serial = _gdk_display_get_next_serial (display);
8740 device_manager = gdk_display_get_device_manager (display);
8741 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8743 /* FIXME: Should this be generic to all backends? */
8744 /* FIXME: What happens with extended devices? */
8745 for (dev = devices; dev; dev = dev->next)
8749 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8752 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8755 get_native_grab_event_mask (event_mask),
8760 if (res == GDK_GRAB_SUCCESS)
8761 _gdk_display_add_device_grab (display,
8773 /* FIXME: handle errors when grabbing */
8775 g_list_free (devices);
8781 * gdk_keyboard_grab:
8782 * @window: the #GdkWindow which will own the grab (the grab window).
8783 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8784 * @window. If %TRUE then keyboard events for this application are
8785 * reported as normal, but keyboard events outside this application
8786 * are reported with respect to @window. Both key press and key
8787 * release events are always reported, independant of the event mask
8788 * set by the application.
8789 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8792 * Grabs the keyboard so that all events are passed to this
8793 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8794 * This overrides any previous keyboard grab by this client.
8796 * If you set up anything at the time you take the grab that needs to be cleaned
8797 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8798 * are emitted when the grab ends unvoluntarily.
8800 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8802 * Deprecated: 3.0: Use gdk_device_grab() instead.
8805 gdk_keyboard_grab (GdkWindow *window,
8806 gboolean owner_events,
8810 GdkDisplay *display;
8811 GdkDeviceManager *device_manager;
8813 GdkGrabStatus res = 0;
8815 GList *devices, *dev;
8817 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8819 /* Non-viewable client side window => fail */
8820 if (!_gdk_window_has_impl (window) &&
8821 !gdk_window_is_viewable (window))
8822 return GDK_GRAB_NOT_VIEWABLE;
8824 native = gdk_window_get_toplevel (window);
8826 while (gdk_window_is_offscreen (native))
8828 native = gdk_offscreen_window_get_embedder (native);
8830 if (native == NULL ||
8831 (!_gdk_window_has_impl (native) &&
8832 !gdk_window_is_viewable (native)))
8833 return GDK_GRAB_NOT_VIEWABLE;
8835 native = gdk_window_get_toplevel (native);
8838 display = gdk_window_get_display (window);
8839 serial = _gdk_display_get_next_serial (display);
8840 device_manager = gdk_display_get_device_manager (display);
8841 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8843 /* FIXME: Should this be generic to all backends? */
8844 /* FIXME: What happens with extended devices? */
8845 for (dev = devices; dev; dev = dev->next)
8849 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
8852 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8855 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
8860 if (res == GDK_GRAB_SUCCESS)
8861 _gdk_display_add_device_grab (display,
8872 /* FIXME: handle errors when grabbing */
8874 g_list_free (devices);
8880 * gdk_window_geometry_changed:
8881 * @window: an embedded offscreen #GdkWindow
8883 * This function informs GDK that the geometry of an embedded
8884 * offscreen window has changed. This is necessary for GDK to keep
8885 * track of which offscreen window the pointer is in.
8890 gdk_window_geometry_changed (GdkWindow *window)
8892 _gdk_synthesize_crossing_events_for_geometry_change (window);
8896 source_events_device_added (GdkDeviceManager *device_manager,
8901 GdkEventMask event_mask;
8902 GdkInputSource source;
8904 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
8908 source = gdk_device_get_source (device);
8910 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8911 GINT_TO_POINTER (source)));
8913 gdk_window_set_device_events (window, device, event_mask);
8917 source_events_device_changed (GdkDeviceManager *device_manager,
8922 GdkInputSource source;
8923 GdkEventMask event_mask;
8927 type = gdk_device_get_device_type (device);
8928 source = gdk_device_get_source (device);
8930 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
8931 GINT_TO_POINTER (source)));
8936 if (type == GDK_DEVICE_TYPE_FLOATING)
8938 /* The device was just floated, enable its event mask */
8939 gdk_window_set_device_events (window, device, event_mask);
8941 else if (type == GDK_DEVICE_TYPE_SLAVE)
8942 gdk_window_set_device_events (window, device, 0);
8946 * gdk_window_set_source_events:
8947 * @window: a #GdkWindow
8948 * @source: a #GdkInputSource to define the source class.
8949 * @event_mask: event mask for @window
8951 * Sets the event mask for any floating device (i.e. not attached to any
8952 * visible pointer) that has the source defined as @source. This event
8953 * mask will be applied both to currently existing, newly added devices
8954 * after this call, and devices being attached/detached.
8959 gdk_window_set_source_events (GdkWindow *window,
8960 GdkInputSource source,
8961 GdkEventMask event_mask)
8963 GdkDeviceManager *device_manager;
8964 GdkDisplay *display;
8968 g_return_if_fail (GDK_IS_WINDOW (window));
8970 display = gdk_window_get_display (window);
8971 device_manager = gdk_display_get_device_manager (display);
8973 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
8975 /* Set event mask for existing devices */
8976 for (d = devices; d; d = d->next)
8978 GdkDevice *device = d->data;
8980 if (source == gdk_device_get_source (device))
8981 gdk_window_set_device_events (window, device, event_mask);
8984 g_list_free (devices);
8986 /* Update accounting */
8987 if (G_UNLIKELY (!window->source_event_masks))
8988 window->source_event_masks = g_hash_table_new (NULL, NULL);
8991 g_hash_table_insert (window->source_event_masks,
8992 GUINT_TO_POINTER (source),
8993 GUINT_TO_POINTER (event_mask));
8995 g_hash_table_remove (window->source_event_masks,
8996 GUINT_TO_POINTER (source));
8998 size = g_hash_table_size (window->source_event_masks);
9000 /* Update handler if needed */
9001 if (!window->device_added_handler_id && size > 0)
9003 window->device_added_handler_id =
9004 g_signal_connect (device_manager, "device-added",
9005 G_CALLBACK (source_events_device_added), window);
9006 window->device_changed_handler_id =
9007 g_signal_connect (device_manager, "device-changed",
9008 G_CALLBACK (source_events_device_changed), window);
9010 else if (window->device_added_handler_id && size == 0)
9011 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
9015 * gdk_window_get_source_events:
9016 * @window: a #GdkWindow
9017 * @source: a #GdkInputSource to define the source class.
9019 * Returns the event mask for @window corresponding to the device class specified
9022 * Returns: source event mask for @window
9025 gdk_window_get_source_events (GdkWindow *window,
9026 GdkInputSource source)
9028 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
9030 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
9031 GUINT_TO_POINTER (source)));
9035 do_synthesize_crossing_event (gpointer data)
9037 GdkDisplay *display;
9038 GdkWindow *changed_toplevel;
9039 GHashTableIter iter;
9040 gpointer key, value;
9043 changed_toplevel = data;
9045 changed_toplevel->synthesize_crossing_event_queued = FALSE;
9047 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9050 display = gdk_window_get_display (changed_toplevel);
9051 serial = _gdk_display_get_next_serial (display);
9052 g_hash_table_iter_init (&iter, display->pointers_info);
9054 while (g_hash_table_iter_next (&iter, &key, &value))
9056 GdkWindow *new_window_under_pointer;
9057 GdkPointerWindowInfo *pointer_info = value;
9058 GdkDevice *device = key;
9060 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9062 new_window_under_pointer =
9063 get_pointer_window (display, changed_toplevel,
9065 pointer_info->toplevel_x,
9066 pointer_info->toplevel_y,
9068 if (new_window_under_pointer != pointer_info->window_under_pointer)
9070 _gdk_synthesize_crossing_events (display,
9071 pointer_info->window_under_pointer,
9072 new_window_under_pointer,
9073 device, pointer_info->last_slave,
9074 GDK_CROSSING_NORMAL,
9075 pointer_info->toplevel_x,
9076 pointer_info->toplevel_y,
9077 pointer_info->state,
9082 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9091 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9093 GdkWindow *toplevel;
9095 toplevel = get_event_toplevel (changed_window);
9097 if (!toplevel->synthesize_crossing_event_queued)
9099 toplevel->synthesize_crossing_event_queued = TRUE;
9101 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9102 do_synthesize_crossing_event,
9103 g_object_ref (toplevel),
9108 /* Don't use for crossing events */
9110 get_event_window (GdkDisplay *display,
9112 GdkWindow *pointer_window,
9114 GdkModifierType mask,
9119 GdkWindow *grab_window;
9120 GdkDeviceGrabInfo *grab;
9122 grab = _gdk_display_has_device_grab (display, device, serial);
9124 if (grab != NULL && !grab->owner_events)
9126 evmask = grab->event_mask;
9127 evmask = update_evmask_for_button_motion (evmask, mask);
9129 grab_window = grab->window;
9131 if (evmask & type_masks[type])
9134 *evmask_out = evmask;
9141 while (pointer_window != NULL)
9143 evmask = pointer_window->event_mask;
9144 evmask = update_evmask_for_button_motion (evmask, mask);
9146 if (evmask & type_masks[type])
9149 *evmask_out = evmask;
9150 return pointer_window;
9153 pointer_window = get_event_parent (pointer_window);
9159 evmask = grab->event_mask;
9160 evmask = update_evmask_for_button_motion (evmask, mask);
9162 if (evmask & type_masks[type])
9165 *evmask_out = evmask;
9166 return grab->window;
9176 proxy_pointer_event (GdkDisplay *display,
9177 GdkEvent *source_event,
9180 GdkWindow *toplevel_window, *event_window;
9181 GdkWindow *pointer_window;
9182 GdkPointerWindowInfo *pointer_info;
9183 GdkDevice *device, *source_device;
9186 gdouble toplevel_x, toplevel_y;
9188 gboolean non_linear, need_synthetic_enter = FALSE;
9190 event_window = source_event->any.window;
9191 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9192 gdk_event_get_state (source_event, &state);
9193 time_ = gdk_event_get_time (source_event);
9194 device = gdk_event_get_device (source_event);
9195 source_device = gdk_event_get_source_device (source_event);
9196 pointer_info = _gdk_display_get_pointer_info (display, device);
9197 toplevel_window = convert_native_coords_to_toplevel (event_window,
9198 toplevel_x, toplevel_y,
9199 &toplevel_x, &toplevel_y);
9202 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9203 source_event->type == GDK_ENTER_NOTIFY) &&
9204 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9205 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9208 if (pointer_info->need_touch_press_enter &&
9209 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHSCREEN &&
9210 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHPAD)
9213 pointer_info->need_touch_press_enter = FALSE;
9214 need_synthetic_enter = TRUE;
9217 /* If we get crossing events with subwindow unexpectedly being NULL
9218 that means there is a native subwindow that gdk doesn't know about.
9219 We track these and forward them, with the correct virtual window
9221 This is important to get right, as metacity uses gdk for the frame
9222 windows, but gdk doesn't know about the client windows reparented
9224 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9225 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9226 (source_event->type == GDK_ENTER_NOTIFY &&
9227 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9228 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9229 source_event->crossing.subwindow == NULL)
9231 /* Left for an unknown (to gdk) subwindow */
9233 /* Send leave events from window under pointer to event window
9234 that will get the subwindow == NULL window */
9235 _gdk_synthesize_crossing_events (display,
9236 pointer_info->window_under_pointer,
9238 device, source_device,
9239 source_event->crossing.mode,
9240 toplevel_x, toplevel_y,
9246 /* Send subwindow == NULL event */
9247 send_crossing_event (display,
9251 source_event->crossing.mode,
9252 source_event->crossing.detail,
9254 device, source_device,
9255 toplevel_x, toplevel_y,
9260 _gdk_display_set_window_under_pointer (display, device, NULL);
9264 pointer_window = get_pointer_window (display, toplevel_window, device,
9265 toplevel_x, toplevel_y, serial);
9267 if (((source_event->type == GDK_ENTER_NOTIFY &&
9268 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9269 (source_event->type == GDK_LEAVE_NOTIFY &&
9270 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9271 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9272 source_event->crossing.subwindow == NULL)
9274 /* Entered from an unknown (to gdk) subwindow */
9276 /* Send subwindow == NULL event */
9277 send_crossing_event (display,
9281 source_event->crossing.mode,
9282 source_event->crossing.detail,
9284 device, source_device,
9285 toplevel_x, toplevel_y,
9290 /* Send enter events from event window to pointer_window */
9291 _gdk_synthesize_crossing_events (display,
9294 device, source_device,
9295 source_event->crossing.mode,
9296 toplevel_x, toplevel_y,
9299 serial, non_linear);
9300 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9304 if ((source_event->type != GDK_TOUCH_UPDATE ||
9305 _gdk_event_get_pointer_emulated (source_event)) &&
9306 pointer_info->window_under_pointer != pointer_window)
9308 /* Either a toplevel crossing notify that ended up inside a child window,
9309 or a motion notify that got into another child window */
9311 /* Different than last time, send crossing events */
9312 _gdk_synthesize_crossing_events (display,
9313 pointer_info->window_under_pointer,
9315 device, source_device,
9316 GDK_CROSSING_NORMAL,
9317 toplevel_x, toplevel_y,
9320 serial, non_linear);
9321 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9323 else if (source_event->type == GDK_MOTION_NOTIFY)
9325 GdkWindow *event_win;
9329 event_win = get_event_window (display,
9338 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9339 gdk_window_get_device_events (event_win, device) == 0)
9342 /* The last device to interact with the window was a touch device,
9343 * which synthesized a leave notify event, so synthesize another enter
9344 * notify to tell the pointer is on the window.
9346 if (need_synthetic_enter)
9347 _gdk_synthesize_crossing_events (display,
9348 NULL, pointer_window,
9349 device, source_device,
9350 GDK_CROSSING_DEVICE_SWITCH,
9351 toplevel_x, toplevel_y,
9357 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9359 gulong *device_serial;
9361 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9363 if (!device_serial ||
9364 (*device_serial != 0 &&
9365 serial < *device_serial))
9366 event_win = NULL; /* Ignore event */
9370 *device_serial = G_MAXULONG;
9374 if (event_win && !display->ignore_core_events)
9376 event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE);
9377 event->motion.time = time_;
9378 convert_toplevel_coords_to_window (event_win,
9379 toplevel_x, toplevel_y,
9380 &event->motion.x, &event->motion.y);
9381 event->motion.x_root = source_event->motion.x_root;
9382 event->motion.y_root = source_event->motion.y_root;
9383 event->motion.state = state;
9384 event->motion.is_hint = is_hint;
9385 event->motion.device = source_event->motion.device;
9386 event->motion.axes = g_memdup (source_event->motion.axes,
9387 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9388 gdk_event_set_source_device (event, source_device);
9392 /* unlink all move events from queue.
9393 We handle our own, including our emulated masks. */
9397 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9398 GDK_BUTTON2_MASK | \
9399 GDK_BUTTON3_MASK | \
9400 GDK_BUTTON4_MASK | \
9404 proxy_button_event (GdkEvent *source_event,
9407 GdkWindow *toplevel_window, *event_window;
9408 GdkWindow *event_win;
9409 GdkWindow *pointer_window;
9412 GdkPointerWindowInfo *pointer_info;
9416 gdouble toplevel_x, toplevel_y;
9417 GdkDisplay *display;
9419 GdkDevice *device, *source_device;
9421 type = source_event->any.type;
9422 event_window = source_event->any.window;
9423 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9424 gdk_event_get_state (source_event, &state);
9425 time_ = gdk_event_get_time (source_event);
9426 device = gdk_event_get_device (source_event);
9427 source_device = gdk_event_get_source_device (source_event);
9428 display = gdk_window_get_display (source_event->any.window);
9429 toplevel_window = convert_native_coords_to_toplevel (event_window,
9430 toplevel_x, toplevel_y,
9431 &toplevel_x, &toplevel_y);
9432 pointer_info = _gdk_display_get_pointer_info (display, device);
9434 if (type == GDK_BUTTON_PRESS &&
9435 !source_event->any.send_event &&
9436 _gdk_display_has_device_grab (display, device, serial) == NULL)
9439 _gdk_window_find_descendant_at (toplevel_window,
9440 toplevel_x, toplevel_y,
9443 /* Find the event window, that gets the grab */
9446 (parent = get_event_parent (w)) != NULL &&
9447 parent->window_type != GDK_WINDOW_ROOT)
9449 if (w->event_mask & GDK_BUTTON_PRESS_MASK)
9453 pointer_window = (GdkWindow *)w;
9455 _gdk_display_add_device_grab (display,
9461 gdk_window_get_events (pointer_window),
9465 _gdk_display_device_grab_update (display, device, source_device, serial);
9468 pointer_window = get_pointer_window (display, toplevel_window, device,
9469 toplevel_x, toplevel_y,
9472 event_win = get_event_window (display,
9478 if (event_win == NULL || display->ignore_core_events)
9481 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9482 gdk_window_get_device_events (event_win, device) == 0)
9485 if (type == GDK_BUTTON_PRESS &&
9486 pointer_info->need_touch_press_enter)
9488 GdkCrossingMode mode;
9490 /* The last device to interact with the window was a touch device,
9491 * which synthesized a leave notify event, so synthesize another enter
9492 * notify to tell the pointer is on the window.
9494 if (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN ||
9495 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHPAD)
9496 mode = GDK_CROSSING_TOUCH_BEGIN;
9498 mode = GDK_CROSSING_DEVICE_SWITCH;
9500 pointer_info->need_touch_press_enter = FALSE;
9501 _gdk_synthesize_crossing_events (display,
9503 pointer_info->window_under_pointer,
9504 device, source_device, mode,
9505 toplevel_x, toplevel_y,
9506 state, time_, source_event,
9510 event = _gdk_make_event (event_win, type, source_event, FALSE);
9514 case GDK_BUTTON_PRESS:
9515 case GDK_BUTTON_RELEASE:
9516 event->button.button = source_event->button.button;
9517 convert_toplevel_coords_to_window (event_win,
9518 toplevel_x, toplevel_y,
9519 &event->button.x, &event->button.y);
9520 event->button.x_root = source_event->button.x_root;
9521 event->button.y_root = source_event->button.y_root;
9522 event->button.state = state;
9523 event->button.device = source_event->button.device;
9524 event->button.axes = g_memdup (source_event->button.axes,
9525 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9527 gdk_event_set_source_device (event, source_device);
9529 if (type == GDK_BUTTON_PRESS)
9530 _gdk_event_button_generate (display, event);
9531 else if (type == GDK_BUTTON_RELEASE &&
9532 pointer_window == pointer_info->window_under_pointer &&
9533 (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN ||
9534 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHPAD))
9536 /* Synthesize a leave notify event
9537 * whenever a touch device is released
9539 pointer_info->need_touch_press_enter = TRUE;
9540 _gdk_synthesize_crossing_events (display,
9541 pointer_window, NULL,
9542 device, source_device,
9543 GDK_CROSSING_TOUCH_END,
9544 toplevel_x, toplevel_y,
9551 event->scroll.direction = source_event->scroll.direction;
9552 convert_toplevel_coords_to_window (event_win,
9553 toplevel_x, toplevel_y,
9554 &event->scroll.x, &event->scroll.y);
9555 event->scroll.x_root = source_event->scroll.x_root;
9556 event->scroll.y_root = source_event->scroll.y_root;
9557 event->scroll.state = state;
9558 event->scroll.device = source_event->scroll.device;
9559 gdk_event_set_source_device (event, source_device);
9566 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9569 #ifdef DEBUG_WINDOW_PRINTING
9571 gdk_window_print (GdkWindow *window,
9575 const char *window_types[] = {
9585 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9586 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9587 window->x, window->y,
9588 window->width, window->height
9591 if (gdk_window_has_impl (window))
9593 #ifdef GDK_WINDOWING_X11
9594 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9598 if (window->window_type != GDK_WINDOW_CHILD)
9599 g_print (" %s", window_types[window->window_type]);
9601 if (window->input_only)
9602 g_print (" input-only");
9605 g_print (" shaped");
9607 if (!gdk_window_is_visible ((GdkWindow *)window))
9608 g_print (" hidden");
9610 g_print (" abs[%d,%d]",
9611 window->abs_x, window->abs_y);
9613 cairo_region_get_extents (window->clip_region, &r);
9614 if (cairo_region_is_empty (window->clip_region))
9615 g_print (" clipbox[empty]");
9617 g_print (" clipbox[%d,%d %dx%d]", r.x, r.y, r.width, r.height);
9624 gdk_window_print_tree (GdkWindow *window,
9626 gboolean include_input_only)
9630 if (window->input_only && !include_input_only)
9633 gdk_window_print (window, indent);
9635 for (l = window->children; l != NULL; l = l->next)
9636 gdk_window_print_tree (l->data, indent + 4, include_input_only);
9639 #endif /* DEBUG_WINDOW_PRINTING */
9642 _gdk_windowing_got_event (GdkDisplay *display,
9647 GdkWindow *event_window;
9649 gboolean unlink_event;
9650 GdkDeviceGrabInfo *button_release_grab;
9651 GdkPointerWindowInfo *pointer_info = NULL;
9652 GdkDevice *device, *source_device;
9653 gboolean is_toplevel;
9655 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
9656 display->last_event_time = gdk_event_get_time (event);
9658 device = gdk_event_get_device (event);
9659 source_device = gdk_event_get_source_device (event);
9665 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
9667 pointer_info = _gdk_display_get_pointer_info (display, device);
9669 if (source_device != pointer_info->last_slave &&
9670 gdk_device_get_device_type (source_device) == GDK_DEVICE_TYPE_SLAVE)
9671 pointer_info->last_slave = source_device;
9673 source_device = pointer_info->last_slave;
9676 g_object_get (device, "input-mode", &mode, NULL);
9677 _gdk_display_device_grab_update (display, device, source_device, serial);
9679 if (mode == GDK_MODE_DISABLED ||
9680 !_gdk_display_check_grab_ownership (display, device, serial))
9682 /* Device events are blocked by another
9683 * device grab, or the device is disabled
9685 unlink_event = TRUE;
9690 event_window = event->any.window;
9694 #ifdef DEBUG_WINDOW_PRINTING
9695 if (event->type == GDK_KEY_PRESS &&
9696 (event->key.keyval == 0xa7 ||
9697 event->key.keyval == 0xbd))
9699 gdk_window_print_tree (event_window, 0, event->key.keyval == 0xbd);
9703 if (event->type == GDK_VISIBILITY_NOTIFY)
9705 event_window->native_visibility = event->visibility.state;
9706 gdk_window_update_visibility_recursively (event_window, event_window);
9710 if (!(is_button_type (event->type) ||
9711 is_motion_type (event->type)) ||
9712 event_window->window_type == GDK_WINDOW_ROOT)
9715 is_toplevel = gdk_window_is_toplevel (event_window);
9717 if ((event->type == GDK_ENTER_NOTIFY ||
9718 event->type == GDK_LEAVE_NOTIFY) &&
9719 (event->crossing.mode == GDK_CROSSING_GRAB ||
9720 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
9721 (_gdk_display_has_device_grab (display, device, serial) ||
9722 event->crossing.detail == GDK_NOTIFY_INFERIOR))
9724 /* We synthesize all crossing events due to grabs ourselves,
9725 * so we ignore the native ones caused by our native pointer_grab
9726 * calls. Otherwise we would proxy these crossing event and cause
9727 * multiple copies of crossing events for grabs.
9729 * We do want to handle grabs from other clients though, as for
9730 * instance alt-tab in metacity causes grabs like these and
9731 * we want to handle those. Thus the has_pointer_grab check.
9733 * Implicit grabs on child windows create some grabbing events
9734 * that are sent before the button press. This means we can't
9735 * detect these with the has_pointer_grab check (as the implicit
9736 * grab is only noticed when we get button press event), so we
9737 * detect these events by checking for INFERIOR enter or leave
9738 * events. These should never be a problem to filter out.
9741 /* We ended up in this window after some (perhaps other clients)
9742 * grab, so update the toplevel_under_window state
9745 event->type == GDK_ENTER_NOTIFY &&
9746 event->crossing.mode == GDK_CROSSING_UNGRAB)
9748 if (pointer_info->toplevel_under_pointer)
9749 g_object_unref (pointer_info->toplevel_under_pointer);
9750 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9753 unlink_event = TRUE;
9757 /* Track toplevel_under_pointer */
9760 if (event->type == GDK_ENTER_NOTIFY &&
9761 event->crossing.detail != GDK_NOTIFY_INFERIOR)
9763 if (pointer_info->toplevel_under_pointer)
9764 g_object_unref (pointer_info->toplevel_under_pointer);
9765 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
9767 else if (event->type == GDK_LEAVE_NOTIFY &&
9768 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
9769 pointer_info->toplevel_under_pointer == event_window)
9771 if (pointer_info->toplevel_under_pointer)
9772 g_object_unref (pointer_info->toplevel_under_pointer);
9773 pointer_info->toplevel_under_pointer = NULL;
9779 guint old_state, old_button;
9781 /* Store last pointer window and position/state */
9782 old_state = pointer_info->state;
9783 old_button = pointer_info->button;
9785 gdk_event_get_coords (event, &x, &y);
9786 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
9787 pointer_info->toplevel_x = x;
9788 pointer_info->toplevel_y = y;
9789 gdk_event_get_state (event, &pointer_info->state);
9791 if (event->type == GDK_BUTTON_PRESS ||
9792 event->type == GDK_BUTTON_RELEASE)
9793 pointer_info->button = event->button.button;
9796 (pointer_info->state != old_state ||
9797 pointer_info->button != old_button))
9798 _gdk_display_enable_motion_hints (display, device);
9801 unlink_event = FALSE;
9802 if (is_motion_type (event->type))
9803 unlink_event = proxy_pointer_event (display, event, serial);
9804 else if (is_button_type (event->type))
9805 unlink_event = proxy_button_event (event, serial);
9807 if (event->type == GDK_BUTTON_RELEASE && !event->any.send_event)
9809 button_release_grab = _gdk_display_has_device_grab (display, device, serial);
9810 if (button_release_grab &&
9811 button_release_grab->implicit &&
9812 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
9814 button_release_grab->serial_end = serial;
9815 button_release_grab->implicit_ungrab = FALSE;
9816 _gdk_display_device_grab_update (display, device, source_device, serial);
9823 _gdk_event_queue_remove_link (display, event_link);
9824 g_list_free_1 (event_link);
9825 gdk_event_free (event);
9830 * gdk_window_create_similar_surface:
9831 * @window: window to make new surface similar to
9832 * @content: the content for the new surface
9833 * @width: width of the new surface
9834 * @height: height of the new surface
9836 * Create a new surface that is as compatible as possible with the
9837 * given @window. For example the new surface will have the same
9838 * fallback resolution and font options as @window. Generally, the new
9839 * surface will also use the same backend as @window, unless that is
9840 * not possible for some reason. The type of the returned surface may
9841 * be examined with cairo_surface_get_type().
9843 * Initially the surface contents are all 0 (transparent if contents
9844 * have transparency, black otherwise.)
9846 * Returns: a pointer to the newly allocated surface. The caller
9847 * owns the surface and should call cairo_surface_destroy() when done
9850 * This function always returns a valid pointer, but it will return a
9851 * pointer to a "nil" surface if @other is already in an error state
9852 * or any other error occurs.
9857 gdk_window_create_similar_surface (GdkWindow * window,
9858 cairo_content_t content,
9862 cairo_surface_t *window_surface, *surface;
9864 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
9866 window_surface = _gdk_window_ref_cairo_surface (window);
9868 switch (_gdk_rendering_mode)
9870 case GDK_RENDERING_MODE_RECORDING:
9872 cairo_rectangle_t rect = { 0, 0, width, height };
9873 surface = cairo_recording_surface_create (content, &rect);
9876 case GDK_RENDERING_MODE_IMAGE:
9877 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
9878 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
9881 case GDK_RENDERING_MODE_SIMILAR:
9883 surface = cairo_surface_create_similar (window_surface,
9889 cairo_surface_destroy (window_surface);
9896 * @window: a #GdkWindow
9897 * @timestamp: timestamp of the event triggering the window focus
9899 * Sets keyboard focus to @window. In most cases, gtk_window_present()
9900 * should be used on a #GtkWindow, rather than calling this function.
9904 gdk_window_focus (GdkWindow *window,
9907 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
9911 * gdk_window_set_type_hint:
9912 * @window: A toplevel #GdkWindow
9913 * @hint: A hint of the function this window will have
9915 * The application can use this call to provide a hint to the window
9916 * manager about the functionality of a window. The window manager
9917 * can use this information when determining the decoration and behaviour
9920 * The hint must be set before the window is mapped.
9923 gdk_window_set_type_hint (GdkWindow *window,
9924 GdkWindowTypeHint hint)
9926 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
9930 * gdk_window_get_type_hint:
9931 * @window: A toplevel #GdkWindow
9933 * This function returns the type hint set for a window.
9935 * Return value: The type hint set for @window
9940 gdk_window_get_type_hint (GdkWindow *window)
9942 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
9946 * gdk_window_set_modal_hint:
9947 * @window: A toplevel #GdkWindow
9948 * @modal: %TRUE if the window is modal, %FALSE otherwise.
9950 * The application can use this hint to tell the window manager
9951 * that a certain window has modal behaviour. The window manager
9952 * can use this information to handle modal windows in a special
9955 * You should only use this on windows for which you have
9956 * previously called gdk_window_set_transient_for()
9959 gdk_window_set_modal_hint (GdkWindow *window,
9962 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
9966 * gdk_window_set_skip_taskbar_hint:
9967 * @window: a toplevel #GdkWindow
9968 * @skips_taskbar: %TRUE to skip the taskbar
9970 * Toggles whether a window should appear in a task list or window
9971 * list. If a window's semantic type as specified with
9972 * gdk_window_set_type_hint() already fully describes the window, this
9973 * function should <emphasis>not</emphasis> be called in addition,
9974 * instead you should allow the window to be treated according to
9975 * standard policy for its semantic type.
9980 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
9981 gboolean skips_taskbar)
9983 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
9987 * gdk_window_set_skip_pager_hint:
9988 * @window: a toplevel #GdkWindow
9989 * @skips_pager: %TRUE to skip the pager
9991 * Toggles whether a window should appear in a pager (workspace
9992 * switcher, or other desktop utility program that displays a small
9993 * thumbnail representation of the windows on the desktop). If a
9994 * window's semantic type as specified with gdk_window_set_type_hint()
9995 * already fully describes the window, this function should
9996 * <emphasis>not</emphasis> be called in addition, instead you should
9997 * allow the window to be treated according to standard policy for
9998 * its semantic type.
10003 gdk_window_set_skip_pager_hint (GdkWindow *window,
10004 gboolean skips_pager)
10006 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
10010 * gdk_window_set_urgency_hint:
10011 * @window: a toplevel #GdkWindow
10012 * @urgent: %TRUE if the window is urgent
10014 * Toggles whether a window needs the user's
10015 * urgent attention.
10020 gdk_window_set_urgency_hint (GdkWindow *window,
10023 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
10027 * gdk_window_set_geometry_hints:
10028 * @window: a toplevel #GdkWindow
10029 * @geometry: geometry hints
10030 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
10032 * Sets the geometry hints for @window. Hints flagged in @geom_mask
10033 * are set, hints not flagged in @geom_mask are unset.
10034 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
10036 * This function provides hints to the windowing system about
10037 * acceptable sizes for a toplevel window. The purpose of
10038 * this is to constrain user resizing, but the windowing system
10039 * will typically (but is not required to) also constrain the
10040 * current size of the window to the provided values and
10041 * constrain programatic resizing via gdk_window_resize() or
10042 * gdk_window_move_resize().
10044 * Note that on X11, this effect has no effect on windows
10045 * of type %GDK_WINDOW_TEMP or windows where override redirect
10046 * has been turned on via gdk_window_set_override_redirect()
10047 * since these windows are not resizable by the user.
10049 * Since you can't count on the windowing system doing the
10050 * constraints for programmatic resizes, you should generally
10051 * call gdk_window_constrain_size() yourself to determine
10052 * appropriate sizes.
10056 gdk_window_set_geometry_hints (GdkWindow *window,
10057 const GdkGeometry *geometry,
10058 GdkWindowHints geom_mask)
10060 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
10064 * gdk_window_set_title:
10065 * @window: a toplevel #GdkWindow
10066 * @title: title of @window
10068 * Sets the title of a toplevel window, to be displayed in the titlebar.
10069 * If you haven't explicitly set the icon name for the window
10070 * (using gdk_window_set_icon_name()), the icon name will be set to
10071 * @title as well. @title must be in UTF-8 encoding (as with all
10072 * user-readable strings in GDK/GTK+). @title may not be %NULL.
10075 gdk_window_set_title (GdkWindow *window,
10076 const gchar *title)
10078 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
10082 * gdk_window_set_role:
10083 * @window: a toplevel #GdkWindow
10084 * @role: a string indicating its role
10086 * When using GTK+, typically you should use gtk_window_set_role() instead
10087 * of this low-level function.
10089 * The window manager and session manager use a window's role to
10090 * distinguish it from other kinds of window in the same application.
10091 * When an application is restarted after being saved in a previous
10092 * session, all windows with the same title and role are treated as
10093 * interchangeable. So if you have two windows with the same title
10094 * that should be distinguished for session management purposes, you
10095 * should set the role on those windows. It doesn't matter what string
10096 * you use for the role, as long as you have a different role for each
10097 * non-interchangeable kind of window.
10101 gdk_window_set_role (GdkWindow *window,
10104 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
10108 * gdk_window_set_startup_id:
10109 * @window: a toplevel #GdkWindow
10110 * @startup_id: a string with startup-notification identifier
10112 * When using GTK+, typically you should use gtk_window_set_startup_id()
10113 * instead of this low-level function.
10119 gdk_window_set_startup_id (GdkWindow *window,
10120 const gchar *startup_id)
10122 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
10126 * gdk_window_set_transient_for:
10127 * @window: a toplevel #GdkWindow
10128 * @parent: another toplevel #GdkWindow
10130 * Indicates to the window manager that @window is a transient dialog
10131 * associated with the application window @parent. This allows the
10132 * window manager to do things like center @window on @parent and
10133 * keep @window above @parent.
10135 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10139 gdk_window_set_transient_for (GdkWindow *window,
10142 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10146 * gdk_window_get_root_origin:
10147 * @window: a toplevel #GdkWindow
10148 * @x: (out): return location for X position of window frame
10149 * @y: (out): return location for Y position of window frame
10151 * Obtains the top-left corner of the window manager frame in root
10152 * window coordinates.
10156 gdk_window_get_root_origin (GdkWindow *window,
10160 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10164 * gdk_window_get_frame_extents:
10165 * @window: a toplevel #GdkWindow
10166 * @rect: rectangle to fill with bounding box of the window frame
10168 * Obtains the bounding box of the window, including window manager
10169 * titlebar/borders if any. The frame position is given in root window
10170 * coordinates. To get the position of the window itself (rather than
10171 * the frame) in root window coordinates, use gdk_window_get_origin().
10175 gdk_window_get_frame_extents (GdkWindow *window,
10176 GdkRectangle *rect)
10178 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10182 * gdk_window_set_override_redirect:
10183 * @window: a toplevel #GdkWindow
10184 * @override_redirect: %TRUE if window should be override redirect
10186 * An override redirect window is not under the control of the window manager.
10187 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10188 * be entirely under the control of the application. The window manager
10189 * can't see the override redirect window at all.
10191 * Override redirect should only be used for short-lived temporary
10192 * windows, such as popup menus. #GtkMenu uses an override redirect
10193 * window in its implementation, for example.
10197 gdk_window_set_override_redirect (GdkWindow *window,
10198 gboolean override_redirect)
10200 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10204 * gdk_window_set_accept_focus:
10205 * @window: a toplevel #GdkWindow
10206 * @accept_focus: %TRUE if the window should receive input focus
10208 * Setting @accept_focus to %FALSE hints the desktop environment that the
10209 * window doesn't want to receive input focus.
10211 * On X, it is the responsibility of the window manager to interpret this
10212 * hint. ICCCM-compliant window manager usually respect it.
10217 gdk_window_set_accept_focus (GdkWindow *window,
10218 gboolean accept_focus)
10220 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10224 * gdk_window_set_focus_on_map:
10225 * @window: a toplevel #GdkWindow
10226 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10228 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10229 * window doesn't want to receive input focus when it is mapped.
10230 * focus_on_map should be turned off for windows that aren't triggered
10231 * interactively (such as popups from network activity).
10233 * On X, it is the responsibility of the window manager to interpret
10234 * this hint. Window managers following the freedesktop.org window
10235 * manager extension specification should respect it.
10240 gdk_window_set_focus_on_map (GdkWindow *window,
10241 gboolean focus_on_map)
10243 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10247 * gdk_window_set_icon_list:
10248 * @window: The #GdkWindow toplevel window to set the icon of.
10249 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10250 * A list of pixbufs, of different sizes.
10252 * Sets a list of icons for the window. One of these will be used
10253 * to represent the window when it has been iconified. The icon is
10254 * usually shown in an icon box or some sort of task bar. Which icon
10255 * size is shown depends on the window manager. The window manager
10256 * can scale the icon but setting several size icons can give better
10257 * image quality since the window manager may only need to scale the
10258 * icon by a small amount or not at all.
10262 gdk_window_set_icon_list (GdkWindow *window,
10265 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10269 * gdk_window_set_icon_name:
10270 * @window: a toplevel #GdkWindow
10271 * @name: (allow-none): name of window while iconified (minimized)
10273 * Windows may have a name used while minimized, distinct from the
10274 * name they display in their titlebar. Most of the time this is a bad
10275 * idea from a user interface standpoint. But you can set such a name
10276 * with this function, if you like.
10278 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10279 * will not update the icon title.
10281 * Using %NULL for @name unsets the icon title; further calls to
10282 * gdk_window_set_title() will again update the icon title as well.
10285 gdk_window_set_icon_name (GdkWindow *window,
10288 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10292 * gdk_window_iconify:
10293 * @window: a toplevel #GdkWindow
10295 * Asks to iconify (minimize) @window. The window manager may choose
10296 * to ignore the request, but normally will honor it. Using
10297 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10299 * This function only makes sense when @window is a toplevel window.
10303 gdk_window_iconify (GdkWindow *window)
10305 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10309 * gdk_window_deiconify:
10310 * @window: a toplevel #GdkWindow
10312 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10313 * choose to ignore the request to deiconify. When using GTK+,
10314 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10315 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10316 * unminimizes it, and puts it on the current desktop.
10320 gdk_window_deiconify (GdkWindow *window)
10322 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10326 * gdk_window_stick:
10327 * @window: a toplevel #GdkWindow
10329 * "Pins" a window such that it's on all workspaces and does not scroll
10330 * with viewports, for window managers that have scrollable viewports.
10331 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10333 * On the X11 platform, this function depends on window manager
10334 * support, so may have no effect with many window managers. However,
10335 * GDK will do the best it can to convince the window manager to stick
10336 * the window. For window managers that don't support this operation,
10337 * there's nothing you can do to force it to happen.
10341 gdk_window_stick (GdkWindow *window)
10343 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10347 * gdk_window_unstick:
10348 * @window: a toplevel #GdkWindow
10350 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10351 * and gtk_window_unstick().
10355 gdk_window_unstick (GdkWindow *window)
10357 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10361 * gdk_window_maximize:
10362 * @window: a toplevel #GdkWindow
10364 * Maximizes the window. If the window was already maximized, then
10365 * this function does nothing.
10367 * On X11, asks the window manager to maximize @window, if the window
10368 * manager supports this operation. Not all window managers support
10369 * this, and some deliberately ignore it or don't have a concept of
10370 * "maximized"; so you can't rely on the maximization actually
10371 * happening. But it will happen with most standard window managers,
10372 * and GDK makes a best effort to get it to happen.
10374 * On Windows, reliably maximizes the window.
10378 gdk_window_maximize (GdkWindow *window)
10380 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10384 * gdk_window_unmaximize:
10385 * @window: a toplevel #GdkWindow
10387 * Unmaximizes the window. If the window wasn't maximized, then this
10388 * function does nothing.
10390 * On X11, asks the window manager to unmaximize @window, if the
10391 * window manager supports this operation. Not all window managers
10392 * support this, and some deliberately ignore it or don't have a
10393 * concept of "maximized"; so you can't rely on the unmaximization
10394 * actually happening. But it will happen with most standard window
10395 * managers, and GDK makes a best effort to get it to happen.
10397 * On Windows, reliably unmaximizes the window.
10401 gdk_window_unmaximize (GdkWindow *window)
10403 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10407 * gdk_window_fullscreen:
10408 * @window: a toplevel #GdkWindow
10410 * Moves the window into fullscreen mode. This means the
10411 * window covers the entire screen and is above any panels
10414 * If the window was already fullscreen, then this function does nothing.
10416 * On X11, asks the window manager to put @window in a fullscreen
10417 * state, if the window manager supports this operation. Not all
10418 * window managers support this, and some deliberately ignore it or
10419 * don't have a concept of "fullscreen"; so you can't rely on the
10420 * fullscreenification actually happening. But it will happen with
10421 * most standard window managers, and GDK makes a best effort to get
10427 gdk_window_fullscreen (GdkWindow *window)
10429 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10433 * gdk_window_unfullscreen:
10434 * @window: a toplevel #GdkWindow
10436 * Moves the window out of fullscreen mode. If the window was not
10437 * fullscreen, does nothing.
10439 * On X11, asks the window manager to move @window out of the fullscreen
10440 * state, if the window manager supports this operation. Not all
10441 * window managers support this, and some deliberately ignore it or
10442 * don't have a concept of "fullscreen"; so you can't rely on the
10443 * unfullscreenification actually happening. But it will happen with
10444 * most standard window managers, and GDK makes a best effort to get
10450 gdk_window_unfullscreen (GdkWindow *window)
10452 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10456 * gdk_window_set_keep_above:
10457 * @window: a toplevel #GdkWindow
10458 * @setting: whether to keep @window above other windows
10460 * Set if @window must be kept above other windows. If the
10461 * window was already above, then this function does nothing.
10463 * On X11, asks the window manager to keep @window above, if the window
10464 * manager supports this operation. Not all window managers support
10465 * this, and some deliberately ignore it or don't have a concept of
10466 * "keep above"; so you can't rely on the window being kept above.
10467 * But it will happen with most standard window managers,
10468 * and GDK makes a best effort to get it to happen.
10473 gdk_window_set_keep_above (GdkWindow *window,
10476 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10480 * gdk_window_set_keep_below:
10481 * @window: a toplevel #GdkWindow
10482 * @setting: whether to keep @window below other windows
10484 * Set if @window must be kept below other windows. If the
10485 * window was already below, then this function does nothing.
10487 * On X11, asks the window manager to keep @window below, if the window
10488 * manager supports this operation. Not all window managers support
10489 * this, and some deliberately ignore it or don't have a concept of
10490 * "keep below"; so you can't rely on the window being kept below.
10491 * But it will happen with most standard window managers,
10492 * and GDK makes a best effort to get it to happen.
10497 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10499 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10503 * gdk_window_get_group:
10504 * @window: a toplevel #GdkWindow
10506 * Returns the group leader window for @window. See gdk_window_set_group().
10508 * Return value: (transfer none): the group leader window for @window
10513 gdk_window_get_group (GdkWindow *window)
10515 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10519 * gdk_window_set_group:
10520 * @window: a toplevel #GdkWindow
10521 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
10523 * Sets the group leader window for @window. By default,
10524 * GDK sets the group leader for all toplevel windows
10525 * to a global window implicitly created by GDK. With this function
10526 * you can override this default.
10528 * The group leader window allows the window manager to distinguish
10529 * all windows that belong to a single application. It may for example
10530 * allow users to minimize/unminimize all windows belonging to an
10531 * application at once. You should only set a non-default group window
10532 * if your application pretends to be multiple applications.
10535 gdk_window_set_group (GdkWindow *window,
10538 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
10542 * gdk_window_set_decorations:
10543 * @window: a toplevel #GdkWindow
10544 * @decorations: decoration hint mask
10546 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
10547 * This function sets the traditional Motif window manager hints that tell the
10548 * window manager which decorations you would like your window to have.
10549 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
10550 * using the GDK function directly.
10552 * The @decorations argument is the logical OR of the fields in
10553 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
10554 * mask, the other bits indicate which decorations should be turned off.
10555 * If #GDK_DECOR_ALL is not included, then the other bits indicate
10556 * which decorations should be turned on.
10558 * Most window managers honor a decorations hint of 0 to disable all decorations,
10559 * but very few honor all possible combinations of bits.
10563 gdk_window_set_decorations (GdkWindow *window,
10564 GdkWMDecoration decorations)
10566 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
10570 * gdk_window_get_decorations:
10571 * @window: The toplevel #GdkWindow to get the decorations from
10572 * @decorations: (out): The window decorations will be written here
10574 * Returns the decorations set on the GdkWindow with
10575 * gdk_window_set_decorations().
10577 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
10580 gdk_window_get_decorations(GdkWindow *window,
10581 GdkWMDecoration *decorations)
10583 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
10587 * gdk_window_set_functions:
10588 * @window: a toplevel #GdkWindow
10589 * @functions: bitmask of operations to allow on @window
10591 * Sets hints about the window management functions to make available
10592 * via buttons on the window frame.
10594 * On the X backend, this function sets the traditional Motif window
10595 * manager hint for this purpose. However, few window managers do
10596 * anything reliable or interesting with this hint. Many ignore it
10599 * The @functions argument is the logical OR of values from the
10600 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
10601 * then the other bits indicate which functions to disable; if
10602 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
10607 gdk_window_set_functions (GdkWindow *window,
10608 GdkWMFunction functions)
10610 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
10614 * gdk_window_begin_resize_drag_for_device:
10615 * @window: a toplevel #GdkWindow
10616 * @edge: the edge or corner from which the drag is started
10617 * @device: the device used for the operation
10618 * @button: the button being used to drag
10619 * @root_x: root window X coordinate of mouse click that began the drag
10620 * @root_y: root window Y coordinate of mouse click that began the drag
10621 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10623 * Begins a window resize operation (for a toplevel window).
10624 * You might use this function to implement a "window resize grip," for
10625 * example; in fact #GtkStatusbar uses it. The function works best
10626 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
10627 * fallback implementation for other window managers.
10632 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
10633 GdkWindowEdge edge,
10640 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
10644 * gdk_window_begin_resize_drag:
10645 * @window: a toplevel #GdkWindow
10646 * @edge: the edge or corner from which the drag is started
10647 * @button: the button being used to drag
10648 * @root_x: root window X coordinate of mouse click that began the drag
10649 * @root_y: root window Y coordinate of mouse click that began the drag
10650 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
10652 * Begins a window resize operation (for a toplevel window).
10654 * This function assumes that the drag is controlled by the
10655 * client pointer device, use gdk_window_begin_resize_drag_for_device()
10656 * to begin a drag with a different device.
10659 gdk_window_begin_resize_drag (GdkWindow *window,
10660 GdkWindowEdge edge,
10666 GdkDeviceManager *device_manager;
10669 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10670 device = gdk_device_manager_get_client_pointer (device_manager);
10671 gdk_window_begin_resize_drag_for_device (window, edge,
10672 device, button, root_x, root_y, timestamp);
10676 * gdk_window_begin_move_drag_for_device:
10677 * @window: a toplevel #GdkWindow
10678 * @device: the device used for the operation
10679 * @button: the button being used to drag
10680 * @root_x: root window X coordinate of mouse click that began the drag
10681 * @root_y: root window Y coordinate of mouse click that began the drag
10682 * @timestamp: timestamp of mouse click that began the drag
10684 * Begins a window move operation (for a toplevel window).
10685 * You might use this function to implement a "window move grip," for
10686 * example. The function works best with window managers that support
10687 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
10688 * Window Manager Hints</ulink>, but has a fallback implementation for
10689 * other window managers.
10694 gdk_window_begin_move_drag_for_device (GdkWindow *window,
10701 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
10702 device, button, root_x, root_y, timestamp);
10706 * gdk_window_begin_move_drag:
10707 * @window: a toplevel #GdkWindow
10708 * @button: the button being used to drag
10709 * @root_x: root window X coordinate of mouse click that began the drag
10710 * @root_y: root window Y coordinate of mouse click that began the drag
10711 * @timestamp: timestamp of mouse click that began the drag
10713 * Begins a window move operation (for a toplevel window).
10715 * This function assumes that the drag is controlled by the
10716 * client pointer device, use gdk_window_begin_move_drag_for_device()
10717 * to begin a drag with a different device.
10720 gdk_window_begin_move_drag (GdkWindow *window,
10726 GdkDeviceManager *device_manager;
10729 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10730 device = gdk_device_manager_get_client_pointer (device_manager);
10731 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
10735 * gdk_window_enable_synchronized_configure:
10736 * @window: a toplevel #GdkWindow
10738 * Indicates that the application will cooperate with the window
10739 * system in synchronizing the window repaint with the window
10740 * manager during resizing operations. After an application calls
10741 * this function, it must call gdk_window_configure_finished() every
10742 * time it has finished all processing associated with a set of
10743 * Configure events. Toplevel GTK+ windows automatically use this
10746 * On X, calling this function makes @window participate in the
10747 * _NET_WM_SYNC_REQUEST window manager protocol.
10752 gdk_window_enable_synchronized_configure (GdkWindow *window)
10754 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
10758 * gdk_window_configure_finished:
10759 * @window: a toplevel #GdkWindow
10761 * Signal to the window system that the application has finished
10762 * handling Configure events it has received. Window Managers can
10763 * use this to better synchronize the frame repaint with the
10764 * application. GTK+ applications will automatically call this
10765 * function when appropriate.
10767 * This function can only be called if gdk_window_enable_synchronized_configure()
10768 * was called previously.
10773 gdk_window_configure_finished (GdkWindow *window)
10775 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
10779 * gdk_window_set_opacity:
10780 * @window: a top-level #GdkWindow
10781 * @opacity: opacity
10783 * Request the windowing system to make @window partially transparent,
10784 * with opacity 0 being fully transparent and 1 fully opaque. (Values
10785 * of the opacity parameter are clamped to the [0,1] range.)
10787 * On X11, this works only on X screens with a compositing manager
10790 * For setting up per-pixel alpha, see gdk_screen_get_rgba_visual().
10791 * For making non-toplevel windows translucent, see
10792 * gdk_window_set_composited().
10797 gdk_window_set_opacity (GdkWindow *window,
10800 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
10803 /* This function is called when the XWindow is really gone.
10806 gdk_window_destroy_notify (GdkWindow *window)
10808 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
10812 * gdk_window_register_dnd:
10813 * @window: a #GdkWindow.
10815 * Registers a window as a potential drop destination.
10818 gdk_window_register_dnd (GdkWindow *window)
10820 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
10824 * gdk_window_get_drag_protocol:
10825 * @window: the destination window
10826 * @target: (out) (allow-none) (transfer full): location of the window
10827 * where the drop should happen. This may be @window or a proxy window,
10828 * or %NULL if @window does not support Drag and Drop.
10830 * Finds out the DND protocol supported by a window.
10832 * Returns: the supported DND protocol.
10837 gdk_window_get_drag_protocol (GdkWindow *window,
10838 GdkWindow **target)
10840 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
10842 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
10847 * @window: the source window for this drag.
10848 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10849 * as list of #GdkAtoms
10851 * Starts a drag and creates a new drag context for it.
10852 * This function assumes that the drag is controlled by the
10853 * client pointer device, use gdk_drag_begin_for_device() to
10854 * begin a drag with a different device.
10856 * This function is called by the drag source.
10858 * Return value: (transfer full): a newly created #GdkDragContext
10861 gdk_drag_begin (GdkWindow *window,
10864 GdkDeviceManager *device_manager;
10867 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
10868 device = gdk_device_manager_get_client_pointer (device_manager);
10870 return gdk_drag_begin_for_device (window, device, targets);
10874 * gdk_drag_begin_for_device:
10875 * @window: the source window for this drag
10876 * @device: the device that controls this drag
10877 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
10878 * as list of #GdkAtoms
10880 * Starts a drag and creates a new drag context for it.
10882 * This function is called by the drag source.
10884 * Return value: (transfer full): a newly created #GdkDragContext
10887 gdk_drag_begin_for_device (GdkWindow *window,
10891 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
10895 * gdk_test_render_sync:
10896 * @window: a mapped #GdkWindow
10898 * Retrieves a pixel from @window to force the windowing
10899 * system to carry out any pending rendering commands.
10901 * This function is intended to be used to synchronize with rendering
10902 * pipelines, to benchmark windowing system rendering operations.
10907 gdk_test_render_sync (GdkWindow *window)
10909 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
10913 * gdk_test_simulate_key:
10914 * @window: a #GdkWindow to simulate a key event for
10915 * @x: x coordinate within @window for the key event
10916 * @y: y coordinate within @window for the key event
10917 * @keyval: A GDK keyboard value
10918 * @modifiers: Keyboard modifiers the event is setup with
10919 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
10921 * This function is intended to be used in GTK+ test programs.
10922 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
10923 * the given (@x,@y) coordinates within @window and simulate a
10924 * key press or release event.
10926 * When the mouse pointer is warped to the target location, use
10927 * of this function outside of test programs that run in their
10928 * own virtual windowing system (e.g. Xvfb) is not recommended.
10929 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
10930 * be warped and @window origin will be used as mouse pointer
10931 * location for the event.
10933 * Also, gdk_test_simulate_key() is a fairly low level function,
10934 * for most testing purposes, gtk_test_widget_send_key() is the
10935 * right function to call which will generate a key press event
10936 * followed by its accompanying key release event.
10938 * Returns: whether all actions necessary for a key event simulation
10939 * were carried out successfully
10944 gdk_test_simulate_key (GdkWindow *window,
10948 GdkModifierType modifiers,
10949 GdkEventType key_pressrelease)
10951 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10952 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
10956 * gdk_test_simulate_button:
10957 * @window: a #GdkWindow to simulate a button event for
10958 * @x: x coordinate within @window for the button event
10959 * @y: y coordinate within @window for the button event
10960 * @button: Number of the pointer button for the event, usually 1, 2 or 3
10961 * @modifiers: Keyboard modifiers the event is setup with
10962 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
10964 * This function is intended to be used in GTK+ test programs.
10965 * It will warp the mouse pointer to the given (@x,@y) coordinates
10966 * within @window and simulate a button press or release event.
10967 * Because the mouse pointer needs to be warped to the target
10968 * location, use of this function outside of test programs that
10969 * run in their own virtual windowing system (e.g. Xvfb) is not
10972 * Also, gdk_test_simulate_button() is a fairly low level function,
10973 * for most testing purposes, gtk_test_widget_click() is the right
10974 * function to call which will generate a button press event followed
10975 * by its accompanying button release event.
10977 * Returns: whether all actions necessary for a button event simulation
10978 * were carried out successfully
10983 gdk_test_simulate_button (GdkWindow *window,
10986 guint button, /*1..3*/
10987 GdkModifierType modifiers,
10988 GdkEventType button_pressrelease)
10990 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
10991 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
10995 * gdk_property_get:
10996 * @window: a #GdkWindow
10997 * @property: the property to retrieve
10998 * @type: the desired property type, or %GDK_NONE, if any type of data
10999 * is acceptable. If this does not match the actual
11000 * type, then @actual_format and @actual_length will
11001 * be filled in, a warning will be printed to stderr
11002 * and no data will be returned.
11003 * @offset: the offset into the property at which to begin
11004 * retrieving data, in 4 byte units.
11005 * @length: the length of the data to retrieve in bytes. Data is
11006 * considered to be retrieved in 4 byte chunks, so @length
11007 * will be rounded up to the next highest 4 byte boundary
11008 * (so be careful not to pass a value that might overflow
11009 * when rounded up).
11010 * @pdelete: if %TRUE, delete the property after retrieving the
11012 * @actual_property_type: (out) (transfer none): location to store the
11013 * actual type of the property.
11014 * @actual_format: (out): location to store the actual return format of the
11015 * data; either 8, 16 or 32 bits.
11016 * @actual_length: location to store the length of the retrieved data, in
11017 * bytes. Data returned in the 32 bit format is stored
11018 * in a long variable, so the actual number of 32 bit
11019 * elements should be be calculated via
11020 * @actual_length / sizeof(glong) to ensure portability to
11022 * @data: (out) (array length=actual_length) (transfer full): location
11023 * to store a pointer to the data. The retrieved data should be
11024 * freed with g_free() when you are finished using it.
11026 * Retrieves a portion of the contents of a property. If the
11027 * property does not exist, then the function returns %FALSE,
11028 * and %GDK_NONE will be stored in @actual_property_type.
11032 * The XGetWindowProperty() function that gdk_property_get()
11033 * uses has a very confusing and complicated set of semantics.
11034 * Unfortunately, gdk_property_get() makes the situation
11035 * worse instead of better (the semantics should be considered
11036 * undefined), and also prints warnings to stderr in cases where it
11037 * should return a useful error to the program. You are advised to use
11038 * XGetWindowProperty() directly until a replacement function for
11039 * gdk_property_get()
11044 * Returns: %TRUE if data was successfully received and stored
11045 * in @data, otherwise %FALSE.
11048 gdk_property_get (GdkWindow *window,
11054 GdkAtom *actual_property_type,
11055 gint *actual_format_type,
11056 gint *actual_length,
11059 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11060 ->get_property (window, property, type, offset, length, pdelete,
11061 actual_property_type, actual_format_type,
11062 actual_length, data);
11066 * gdk_property_change: (skip)
11067 * @window: a #GdkWindow
11068 * @property: the property to change
11069 * @type: the new type for the property. If @mode is
11070 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11071 * must match the existing type or an error will occur.
11072 * @format: the new format for the property. If @mode is
11073 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11074 * must match the existing format or an error will occur.
11075 * @mode: a value describing how the new data is to be combined
11076 * with the current data.
11077 * @data: the data (a <literal>guchar *</literal>
11078 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
11079 * depending on @format), cast to a <literal>guchar *</literal>.
11080 * @nelements: the number of elements of size determined by the format,
11081 * contained in @data.
11083 * Changes the contents of a property on a window.
11086 gdk_property_change (GdkWindow *window,
11091 const guchar *data,
11094 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11095 ->change_property (window, property, type, format, mode, data, nelements);
11099 * gdk_property_delete:
11100 * @window: a #GdkWindow
11101 * @property: the property to delete
11103 * Deletes a property from a window.
11106 gdk_property_delete (GdkWindow *window,
11109 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);