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 "gdkframeclockidle.h"
41 #include "gdkwindowimpl.h"
45 #undef DEBUG_WINDOW_PRINTING
50 * @Short_description: Onscreen display areas in the target window system
53 * A #GdkWindow is a (usually) rectangular region on the screen.
54 * It's a low-level object, used to implement high-level objects such as
55 * #GtkWidget and #GtkWindow on the GTK+ level. A #GtkWindow is a toplevel
56 * window, the thing a user might think of as a "window" with a titlebar and
57 * so on; a #GtkWindow may contain many #GdkWindows. For example, each
58 * #GtkButton has a #GdkWindow associated with it.
60 * <refsect2 id="COMPOSITED-WINDOWS">
61 * <title>Composited Windows</title>
63 * Normally, the windowing system takes care of rendering the contents of a
64 * child window onto its parent window. This mechanism can be intercepted by
65 * calling gdk_window_set_composited() on the child window. For a
66 * <firstterm>composited</firstterm> window it is the responsibility of the
67 * application to render the window contents at the right spot.
70 * <refsect2 id="OFFSCREEN-WINDOWS">
71 * <title>Offscreen Windows</title>
73 * Offscreen windows are more general than composited windows, since they allow
74 * not only to modify the rendering of the child window onto its parent, but
75 * also to apply coordinate transformations.
77 * To integrate an offscreen window into a window hierarchy, one has to call
78 * gdk_offscreen_window_set_embedder() and handle a number of signals. The
79 * #GdkWindow::pick-embedded-child signal on the embedder window is used to
80 * select an offscreen child at given coordinates, and the
81 * #GdkWindow::to-embedder and #GdkWindow::from-embedder signals on the
82 * offscreen window are used to translate coordinates between the embedder and
83 * the offscreen window.
85 * For rendering an offscreen window onto its embedder, the contents of the
86 * offscreen window are available as a surface, via
87 * gdk_offscreen_window_get_surface().
93 /* Historically a GdkWindow always matches a platform native window,
94 * be it a toplevel window or a child window. In this setup the
95 * GdkWindow (and other GdkDrawables) were platform independent classes,
96 * and the actual platform specific implementation was in a delegate
97 * object available as "impl" in the window object.
99 * With the addition of client side windows and offscreen windows this
100 * changes a bit. The application-visible GdkWindow object behaves as
101 * it did before, but not all such windows now have a corresponding native
102 * window. Instead windows that are "client side" are emulated by the gdk
103 * code such that clipping, drawing, moving, events etc work as expected.
105 * For GdkWindows that have a native window the "impl" object is the
106 * same as before. However, for all client side windows the impl object
107 * is shared with its parent (i.e. all client windows descendants of one
108 * native window has the same impl.
110 * Additionally there is a new type of platform independent impl object,
111 * GdkOffscreenWindow. All windows of type GDK_WINDOW_OFFSCREEN get an impl
112 * of this type (while their children are generally GDK_WINDOW_CHILD virtual
113 * windows). Such windows work by allocating a #cairo_surface_t as the backing
114 * store for drawing operations, which is resized with the window.
116 * GdkWindows have a pointer to the "impl window" they are in, i.e.
117 * the topmost GdkWindow which have the same "impl" value. This is stored
118 * in impl_window, which is different from the window itself only for client
120 * All GdkWindows (native or not) track the position of the window in the parent
121 * (x, y), the size of the window (width, height), the position of the window
122 * with respect to the impl window (abs_x, abs_y). We also track the clip
123 * region of the window wrt parent windows and siblings, in window-relative
124 * coordinates with and without child windows included (clip_region,
125 * clip_region_with_children).
127 * All toplevel windows are native windows, but also child windows can be
128 * native (although not children of offscreens). We always listen to
129 * a basic set of events (see get_native_event_mask) for these windows
130 * so that we can emulate events for any client side children.
132 * For native windows we apply the calculated clip region as a window shape
133 * so that eg. client side siblings that overlap the native child properly
134 * draws over the native child window.
136 * In order to minimize flicker and for performance we use a couple of cacheing
137 * tricks. First of all, every time we do a window to window copy area, for instance
138 * when moving a client side window or when scrolling/moving a region in a window
139 * we store this in outstanding_moves instead of applying immediately. We then
140 * delay this move until we really need it (because something depends on being
141 * able to read it), or until we're handing a redraw from an expose/invalidation
142 * (actually we delay it past redraw, but before blitting the double buffer
143 * to the window). This gives us two advantages. First of all it minimizes the time
144 * from the window is moved to the exposes related to that move, secondly it allows
145 * us to be smart about how to do the copy. We combine multiple moves into one (when
146 * possible) and we don't actually do copies to anything that is or will be
147 * invalidated and exposed anyway.
149 * Secondly, we use something called a "implicit paint" during repaint handling.
150 * An implicit paint is similar to a regular paint for the paint stack, but it is
151 * not put on the stack. Instead, it is set on the impl window, and later when
152 * regular gdk_window_begin_paint_region() happen on a window of this impl window
153 * we reuse the surface from the implicit paint. During repaint we create and at the
154 * end flush an implicit paint, which means we can collect all the paints on
155 * multiple client side windows in the same backing store.
158 #define USE_BACKING_STORE /* Appears to work on Win32, too, now. */
160 /* This adds a local value to the GdkVisibilityState enum */
161 #define GDK_VISIBILITY_NOT_VIEWABLE 3
164 PICK_EMBEDDED_CHILD, /* only called if children are embedded */
179 CLEAR_BG_WINCLEARED, /* Clear backgrounds except those that the window system clears */
183 struct _GdkWindowPaint
185 cairo_region_t *region;
186 cairo_surface_t *surface;
187 cairo_region_t *flushed;
189 guint uses_implicit : 1;
193 cairo_region_t *dest_region; /* The destination region */
194 int dx, dy; /* The amount that the source was moved to reach dest_region */
195 } GdkWindowRegionMove;
199 static void gdk_window_drop_cairo_surface (GdkWindow *private);
201 static void gdk_window_free_paint_stack (GdkWindow *window);
203 static void gdk_window_finalize (GObject *object);
205 static void gdk_window_set_property (GObject *object,
209 static void gdk_window_get_property (GObject *object,
214 static void gdk_window_clear_backing_region (GdkWindow *window,
215 cairo_region_t *region);
217 static void recompute_visible_regions (GdkWindow *private,
218 gboolean recalculate_siblings,
219 gboolean recalculate_children);
220 static void gdk_window_flush_outstanding_moves (GdkWindow *window);
221 static void gdk_window_flush_recursive (GdkWindow *window);
222 static void do_move_region_bits_on_impl (GdkWindow *window,
223 cairo_region_t *region, /* In impl window coords */
225 static void gdk_window_invalidate_in_parent (GdkWindow *private);
226 static void move_native_children (GdkWindow *private);
227 static void update_cursor (GdkDisplay *display,
229 static void impl_window_add_update_area (GdkWindow *impl_window,
230 cairo_region_t *region);
231 static void gdk_window_region_move_free (GdkWindowRegionMove *move);
232 static void gdk_window_invalidate_region_full (GdkWindow *window,
233 const cairo_region_t *region,
234 gboolean invalidate_children,
236 static void gdk_window_invalidate_rect_full (GdkWindow *window,
237 const GdkRectangle *rect,
238 gboolean invalidate_children,
240 static void _gdk_window_propagate_has_alpha_background (GdkWindow *window);
241 static cairo_surface_t *gdk_window_ref_impl_surface (GdkWindow *window);
243 static void gdk_window_process_all_updates_internal (gboolean default_clock_only);
245 static void gdk_ensure_default_frame_clock (void);
247 static guint signals[LAST_SIGNAL] = { 0 };
249 static gpointer parent_class = NULL;
251 static const cairo_user_data_key_t gdk_window_cairo_key;
253 G_DEFINE_ABSTRACT_TYPE (GdkWindow, gdk_window, G_TYPE_OBJECT)
255 #ifdef DEBUG_WINDOW_PRINTING
257 print_region (cairo_region_t *region)
259 GString *s = g_string_new ("{");
260 if (cairo_region_is_empty (region))
262 g_string_append (s, "empty");
266 int num = cairo_region_num_rectangles (region);
267 cairo_rectangle_int_t r;
271 cairo_region_get_rectangle (region, 0, &r);
272 g_string_append_printf (s, "%dx%d @%d,%d", r.width, r.height, r.x, r.y);
276 cairo_region_get_extents (region, &r);
277 g_string_append_printf (s, "extent: %dx%d @%d,%d, details: ", r.width, r.height, r.x, r.y);
278 for (int i = 0; i < num; i++)
280 g_string_append_printf (s, "[%dx%d @%d,%d]", r.width, r.height, r.x, r.y);
282 g_string_append (s, ", ");
286 g_string_append (s, "}");
287 return g_string_free (s, FALSE);
292 _gdk_paintable_get_type (void)
294 static GType paintable_type = 0;
298 const GTypeInfo paintable_info =
300 sizeof (GdkPaintableIface), /* class_size */
301 NULL, /* base_init */
302 NULL, /* base_finalize */
305 paintable_type = g_type_register_static (G_TYPE_INTERFACE,
306 g_intern_static_string ("GdkPaintable"),
309 g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
312 return paintable_type;
316 gdk_window_init (GdkWindow *window)
318 /* 0-initialization is good for all other fields. */
320 window->window_type = GDK_WINDOW_CHILD;
322 window->state = GDK_WINDOW_STATE_WITHDRAWN;
323 window->fullscreen_mode = GDK_FULLSCREEN_ON_CURRENT_MONITOR;
326 window->toplevel_window_type = -1;
328 window->effective_visibility = GDK_VISIBILITY_NOT_VIEWABLE;
329 window->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
330 /* Default to unobscured since some backends don't send visibility events */
331 window->native_visibility = GDK_VISIBILITY_UNOBSCURED;
333 window->device_cursor = g_hash_table_new_full (NULL, NULL,
334 NULL, g_object_unref);
337 /* Stop and return on the first non-NULL parent */
339 accumulate_get_window (GSignalInvocationHint *ihint,
341 const GValue *handler_return,
344 g_value_copy (handler_return, return_accu);
345 /* Continue while returning NULL */
346 return g_value_get_object (handler_return) == NULL;
350 create_surface_accumulator (GSignalInvocationHint *ihint,
352 const GValue *handler_return,
355 g_value_copy (handler_return, return_accu);
357 /* Stop on the first non-NULL return value */
358 return g_value_get_boxed (handler_return) == NULL;
361 static GQuark quark_pointer_window = 0;
364 gdk_window_class_init (GdkWindowClass *klass)
366 GObjectClass *object_class = G_OBJECT_CLASS (klass);
368 parent_class = g_type_class_peek_parent (klass);
370 object_class->finalize = gdk_window_finalize;
371 object_class->set_property = gdk_window_set_property;
372 object_class->get_property = gdk_window_get_property;
374 klass->create_surface = _gdk_offscreen_window_create_surface;
376 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
384 * The mouse pointer for a #GdkWindow. See gdk_window_set_cursor() and
385 * gdk_window_get_cursor() for details.
389 g_object_class_install_property (object_class,
391 g_param_spec_object ("cursor",
398 * GdkWindow:paint-clock:
400 * The frame clock for a #GdkWindow, see #GdkFrameClock
402 * The frame clock remains the same for the lifetime of the window.
406 g_object_class_install_property (object_class,
408 g_param_spec_object ("paint-clock",
411 GDK_TYPE_FRAME_CLOCK,
415 * GdkWindow::pick-embedded-child:
416 * @window: the window on which the signal is emitted
417 * @x: x coordinate in the window
418 * @y: y coordinate in the window
420 * The ::pick-embedded-child signal is emitted to find an embedded
421 * child at the given position.
423 * Returns: (transfer none): the #GdkWindow of the embedded child at
428 signals[PICK_EMBEDDED_CHILD] =
429 g_signal_new (g_intern_static_string ("pick-embedded-child"),
430 G_OBJECT_CLASS_TYPE (object_class),
432 G_STRUCT_OFFSET (GdkWindowClass, pick_embedded_child),
433 accumulate_get_window, NULL,
434 _gdk_marshal_OBJECT__DOUBLE_DOUBLE,
441 * GdkWindow::to-embedder:
442 * @window: the offscreen window on which the signal is emitted
443 * @offscreen_x: x coordinate in the offscreen window
444 * @offscreen_y: y coordinate in the offscreen window
445 * @embedder_x: (out) (type double): return location for the x
446 * coordinate in the embedder window
447 * @embedder_y: (out) (type double): return location for the y
448 * coordinate in the embedder window
450 * The ::to-embedder signal is emitted to translate coordinates
451 * in an offscreen window to its embedder.
453 * See also #GtkWindow::from-embedder.
457 signals[TO_EMBEDDER] =
458 g_signal_new (g_intern_static_string ("to-embedder"),
459 G_OBJECT_CLASS_TYPE (object_class),
461 G_STRUCT_OFFSET (GdkWindowClass, to_embedder),
463 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
472 * GdkWindow::from-embedder:
473 * @window: the offscreen window on which the signal is emitted
474 * @embedder_x: x coordinate in the embedder window
475 * @embedder_y: y coordinate in the embedder window
476 * @offscreen_x: (out) (type double): return location for the x
477 * coordinate in the offscreen window
478 * @offscreen_y: (out) (type double): return location for the y
479 * coordinate in the offscreen window
481 * The ::from-embedder signal is emitted to translate coordinates
482 * in the embedder of an offscreen window to the offscreen window.
484 * See also #GtkWindow::to-embedder.
488 signals[FROM_EMBEDDER] =
489 g_signal_new (g_intern_static_string ("from-embedder"),
490 G_OBJECT_CLASS_TYPE (object_class),
492 G_STRUCT_OFFSET (GdkWindowClass, from_embedder),
494 _gdk_marshal_VOID__DOUBLE_DOUBLE_POINTER_POINTER,
503 * GdkWindow::create-surface:
504 * @window: the offscreen window on which the signal is emitted
505 * @width: the width of the offscreen surface to create
506 * @height: the height of the offscreen surface to create
508 * The ::create-surface signal is emitted when an offscreen window
509 * needs its surface (re)created, which happens either when the the
510 * window is first drawn to, or when the window is being
511 * resized. The first signal handler that returns a non-%NULL
512 * surface will stop any further signal emission, and its surface
515 * Note that it is not possible to access the window's previous
516 * surface from within any callback of this signal. Calling
517 * gdk_offscreen_window_get_surface() will lead to a crash.
519 * Returns: the newly created #cairo_surface_t for the offscreen window
523 signals[CREATE_SURFACE] =
524 g_signal_new (g_intern_static_string ("create-surface"),
525 G_OBJECT_CLASS_TYPE (object_class),
527 G_STRUCT_OFFSET (GdkWindowClass, create_surface),
528 create_surface_accumulator, NULL,
529 _gdk_marshal_BOXED__INT_INT,
530 CAIRO_GOBJECT_TYPE_SURFACE,
537 device_removed_cb (GdkDeviceManager *device_manager,
541 window->devices_inside = g_list_remove (window->devices_inside, device);
542 g_hash_table_remove (window->device_cursor, device);
544 if (window->device_events)
545 g_hash_table_remove (window->device_events, device);
549 gdk_window_finalize (GObject *object)
551 GdkWindow *window = GDK_WINDOW (object);
552 GdkDeviceManager *device_manager;
554 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
555 g_signal_handlers_disconnect_by_func (device_manager, device_removed_cb, window);
557 if (!GDK_WINDOW_DESTROYED (window))
559 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
561 g_warning ("losing last reference to undestroyed window\n");
562 _gdk_window_destroy (window, FALSE);
565 /* We use TRUE here, to keep us from actually calling
566 * XDestroyWindow() on the window
568 _gdk_window_destroy (window, TRUE);
571 gdk_window_drop_cairo_surface (window);
575 g_object_unref (window->impl);
579 if (window->impl_window != window)
581 g_object_unref (window->impl_window);
582 window->impl_window = NULL;
586 cairo_region_destroy (window->shape);
588 if (window->input_shape)
589 cairo_region_destroy (window->input_shape);
592 g_object_unref (window->cursor);
594 if (window->device_cursor)
595 g_hash_table_destroy (window->device_cursor);
597 if (window->device_events)
598 g_hash_table_destroy (window->device_events);
600 if (window->source_event_masks)
601 g_hash_table_destroy (window->source_event_masks);
603 if (window->devices_inside)
604 g_list_free (window->devices_inside);
606 if (window->layered_region)
607 cairo_region_destroy (window->layered_region);
609 G_OBJECT_CLASS (parent_class)->finalize (object);
613 gdk_window_set_property (GObject *object,
618 GdkWindow *window = (GdkWindow *)object;
623 gdk_window_set_cursor (window, g_value_get_object (value));
626 case PROP_FRAME_CLOCK:
627 gdk_window_set_frame_clock (window, g_value_get_object (value));
631 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
637 gdk_window_get_property (GObject *object,
642 GdkWindow *window = (GdkWindow *) object;
647 g_value_set_object (value, gdk_window_get_cursor (window));
650 case PROP_FRAME_CLOCK:
651 g_value_set_object (value, gdk_window_get_frame_clock (window));
655 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
661 gdk_window_is_offscreen (GdkWindow *window)
663 return window->window_type == GDK_WINDOW_OFFSCREEN;
667 gdk_window_get_impl_window (GdkWindow *window)
669 return window->impl_window;
673 _gdk_window_get_impl_window (GdkWindow *window)
675 return gdk_window_get_impl_window (window);
679 gdk_window_has_impl (GdkWindow *window)
681 return window->impl_window == window;
685 gdk_window_is_toplevel (GdkWindow *window)
688 window->parent == NULL ||
689 window->parent->window_type == GDK_WINDOW_ROOT;
693 _gdk_window_has_impl (GdkWindow *window)
695 return gdk_window_has_impl (window);
699 gdk_window_has_no_impl (GdkWindow *window)
701 return window->impl_window != window;
705 gdk_window_has_alpha (GdkWindow *window)
707 return !gdk_window_has_impl (window) &&
708 (window->has_alpha_background || window->alpha != 255);
712 remove_layered_child_area (GdkWindow *window,
713 cairo_region_t *region)
716 cairo_region_t *child_region;
720 for (l = window->children; l; l = l->next)
724 /* If region is empty already, no need to do
725 anything potentially costly */
726 if (cairo_region_is_empty (region))
729 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
732 /* Ignore offscreen children, as they don't draw in their parent and
733 * don't take part in the clipping */
734 if (gdk_window_is_offscreen (child))
737 /* Only non-impl children with alpha add to the layered region */
738 if (!gdk_window_has_alpha (child))
743 r.width = child->width;
744 r.height = child->height;
746 /* Bail early if child totally outside region */
747 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
750 child_region = cairo_region_create_rectangle (&r);
753 /* Adjust shape region to parent window coords */
754 cairo_region_translate (child->shape, child->x, child->y);
755 cairo_region_intersect (child_region, child->shape);
756 cairo_region_translate (child->shape, -child->x, -child->y);
759 cairo_region_subtract (region, child_region);
760 cairo_region_destroy (child_region);
765 remove_child_area (GdkWindow *window,
768 cairo_region_t *region,
769 cairo_region_t *layered_region)
772 cairo_region_t *child_region;
775 cairo_region_t *shape;
777 for (l = window->children; l; l = l->next)
784 /* If region is empty already, no need to do
785 anything potentially costly */
786 if (cairo_region_is_empty (region))
789 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
792 /* Ignore offscreen children, as they don't draw in their parent and
793 * don't take part in the clipping */
794 if (gdk_window_is_offscreen (child))
799 r.width = child->width;
800 r.height = child->height;
802 /* Bail early if child totally outside region */
803 if (cairo_region_contains_rectangle (region, &r) == CAIRO_REGION_OVERLAP_OUT)
806 child_region = cairo_region_create_rectangle (&r);
810 /* Adjust shape region to parent window coords */
811 cairo_region_translate (child->shape, child->x, child->y);
812 cairo_region_intersect (child_region, child->shape);
813 cairo_region_translate (child->shape, -child->x, -child->y);
815 else if (window->window_type == GDK_WINDOW_FOREIGN)
817 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_shape (child);
820 cairo_region_intersect (child_region, shape);
821 cairo_region_destroy (shape);
827 if (child->input_shape)
828 cairo_region_intersect (child_region, child->input_shape);
829 else if (window->window_type == GDK_WINDOW_FOREIGN)
831 shape = GDK_WINDOW_IMPL_GET_CLASS (child)->get_input_shape (child);
834 cairo_region_intersect (child_region, shape);
835 cairo_region_destroy (shape);
840 if (gdk_window_has_alpha (child))
842 if (layered_region != NULL)
843 cairo_region_union (layered_region, child_region);
846 cairo_region_subtract (region, child_region);
847 cairo_region_destroy (child_region);
851 static GdkVisibilityState
852 effective_visibility (GdkWindow *window)
854 GdkVisibilityState native;
856 if (!gdk_window_is_viewable (window))
857 return GDK_VISIBILITY_NOT_VIEWABLE;
859 native = window->impl_window->native_visibility;
861 if (native == GDK_VISIBILITY_FULLY_OBSCURED ||
862 window->visibility == GDK_VISIBILITY_FULLY_OBSCURED)
863 return GDK_VISIBILITY_FULLY_OBSCURED;
864 else if (native == GDK_VISIBILITY_UNOBSCURED)
865 return window->visibility;
866 else /* native PARTIAL, private partial or unobscured */
867 return GDK_VISIBILITY_PARTIAL;
871 gdk_window_update_visibility (GdkWindow *window)
873 GdkVisibilityState new_visibility;
876 new_visibility = effective_visibility (window);
878 if (new_visibility != window->effective_visibility)
880 window->effective_visibility = new_visibility;
882 if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE &&
883 window->event_mask & GDK_VISIBILITY_NOTIFY_MASK)
885 event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY,
887 event->visibility.state = new_visibility;
893 gdk_window_update_visibility_recursively (GdkWindow *window,
894 GdkWindow *only_for_impl)
899 gdk_window_update_visibility (window);
900 for (l = window->children; l != NULL; l = l->next)
903 if ((only_for_impl == NULL) ||
904 (only_for_impl == child->impl_window))
905 gdk_window_update_visibility_recursively (child, only_for_impl);
910 should_apply_clip_as_shape (GdkWindow *window)
913 gdk_window_has_impl (window) &&
914 /* Not for offscreens */
915 !gdk_window_is_offscreen (window) &&
916 /* or for toplevels */
917 !gdk_window_is_toplevel (window) &&
918 /* or for foreign windows */
919 window->window_type != GDK_WINDOW_FOREIGN &&
920 /* or for the root window */
921 window->window_type != GDK_WINDOW_ROOT;
925 apply_shape (GdkWindow *window,
926 cairo_region_t *region)
928 GdkWindowImplClass *impl_class;
930 /* We trash whether we applied a shape so that
931 we can avoid unsetting it many times, which
932 could happen in e.g. apply_clip_as_shape as
933 windows get resized */
934 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
936 impl_class->shape_combine_region (window,
938 else if (window->applied_shape)
939 impl_class->shape_combine_region (window,
942 window->applied_shape = region != NULL;
946 region_rect_equal (const cairo_region_t *region,
947 const GdkRectangle *rect)
949 GdkRectangle extents;
951 if (cairo_region_num_rectangles (region) != 1)
954 cairo_region_get_extents (region, &extents);
956 return extents.x == rect->x &&
957 extents.y == rect->y &&
958 extents.width == rect->width &&
959 extents.height == rect->height;
963 apply_clip_as_shape (GdkWindow *window)
968 r.width = window->width;
969 r.height = window->height;
971 /* We only apply the clip region if would differ
972 from the actual clip region implied by the size
973 of the window. This is to avoid unneccessarily
974 adding meaningless shapes to all native subwindows */
975 if (!region_rect_equal (window->clip_region, &r))
976 apply_shape (window, window->clip_region);
978 apply_shape (window, NULL);
982 recompute_visible_regions_internal (GdkWindow *private,
983 gboolean recalculate_clip,
984 gboolean recalculate_siblings,
985 gboolean recalculate_children)
990 cairo_region_t *new_clip, *new_layered;
991 gboolean clip_region_changed;
992 gboolean abs_pos_changed;
993 int old_abs_x, old_abs_y;
995 old_abs_x = private->abs_x;
996 old_abs_y = private->abs_y;
998 /* Update absolute position */
999 if (gdk_window_has_impl (private))
1001 /* Native window starts here */
1007 private->abs_x = private->parent->abs_x + private->x;
1008 private->abs_y = private->parent->abs_y + private->y;
1012 private->abs_x != old_abs_x ||
1013 private->abs_y != old_abs_y;
1015 /* Update clip region based on:
1018 * siblings in parents above window
1020 clip_region_changed = FALSE;
1021 if (recalculate_clip)
1023 new_layered = cairo_region_create ();
1024 if (private->viewable)
1026 /* Calculate visible region (sans children) in parent window coords */
1029 r.width = private->width;
1030 r.height = private->height;
1031 new_clip = cairo_region_create_rectangle (&r);
1033 if (!gdk_window_is_toplevel (private))
1035 cairo_region_intersect (new_clip, private->parent->clip_region);
1036 cairo_region_union (new_layered, private->parent->layered_region);
1038 /* Remove all overlapping children from parent. */
1039 remove_child_area (private->parent, private, FALSE, new_clip, new_layered);
1042 /* Convert from parent coords to window coords */
1043 cairo_region_translate (new_clip, -private->x, -private->y);
1044 cairo_region_translate (new_layered, -private->x, -private->y);
1047 cairo_region_intersect (new_clip, private->shape);
1050 new_clip = cairo_region_create ();
1052 cairo_region_intersect (new_layered, new_clip);
1054 if (private->clip_region == NULL ||
1055 !cairo_region_equal (private->clip_region, new_clip))
1056 clip_region_changed = TRUE;
1058 if (private->layered_region == NULL ||
1059 !cairo_region_equal (private->layered_region, new_layered))
1060 clip_region_changed = TRUE;
1062 if (private->clip_region)
1063 cairo_region_destroy (private->clip_region);
1064 private->clip_region = new_clip;
1066 if (private->layered_region != NULL)
1067 cairo_region_destroy (private->layered_region);
1068 private->layered_region = new_layered;
1070 if (private->clip_region_with_children)
1071 cairo_region_destroy (private->clip_region_with_children);
1072 private->clip_region_with_children = cairo_region_copy (private->clip_region);
1073 if (private->window_type != GDK_WINDOW_ROOT)
1074 remove_child_area (private, NULL, FALSE, private->clip_region_with_children, NULL);
1077 if (clip_region_changed)
1079 GdkVisibilityState visibility;
1080 gboolean fully_visible;
1082 if (cairo_region_is_empty (private->clip_region))
1083 visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1088 fully_visible = cairo_region_equal (private->clip_region,
1095 r.width = private->width;
1096 r.height = private->height;
1097 fully_visible = region_rect_equal (private->clip_region, &r);
1101 visibility = GDK_VISIBILITY_UNOBSCURED;
1103 visibility = GDK_VISIBILITY_PARTIAL;
1106 if (private->visibility != visibility)
1108 private->visibility = visibility;
1109 gdk_window_update_visibility (private);
1113 /* Update all children, recursively (except for root, where children are not exact). */
1114 if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
1115 private->window_type != GDK_WINDOW_ROOT)
1117 for (l = private->children; l; l = l->next)
1120 /* Only recalculate clip if the the clip region changed, otherwise
1121 * there is no way the child clip region could change (its has not e.g. moved)
1122 * Except if recalculate_children is set to force child updates
1124 recompute_visible_regions_internal (child,
1125 recalculate_clip && (clip_region_changed || recalculate_children),
1130 if (clip_region_changed &&
1131 should_apply_clip_as_shape (private))
1132 apply_clip_as_shape (private);
1134 if (recalculate_siblings &&
1135 !gdk_window_is_toplevel (private))
1137 /* If we moved a child window in parent or changed the stacking order, then we
1138 * need to recompute the visible area of all the other children in the parent
1140 for (l = private->parent->children; l; l = l->next)
1144 if (child != private)
1145 recompute_visible_regions_internal (child, TRUE, FALSE, FALSE);
1148 /* We also need to recompute the _with_children clip for the parent */
1149 recompute_visible_regions_internal (private->parent, TRUE, FALSE, FALSE);
1152 if (private->cairo_surface && gdk_window_has_impl (private))
1154 GdkWindowImplClass *iface = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1156 private->cairo_surface = iface->resize_cairo_surface (private,
1157 private->cairo_surface,
1161 else if (private->cairo_surface)
1162 gdk_window_drop_cairo_surface (private);
1165 /* Call this when private has changed in one or more of these ways:
1169 * stacking order of window changed
1172 * It will recalculate abs_x/y and the clip regions
1174 * Unless the window didn't change stacking order or size/pos, pass in TRUE
1175 * for recalculate_siblings. (Mostly used internally for the recursion)
1177 * If a child window was removed (and you can't use that child for
1178 * recompute_visible_regions), pass in TRUE for recalculate_children on the parent
1181 recompute_visible_regions (GdkWindow *private,
1182 gboolean recalculate_siblings,
1183 gboolean recalculate_children)
1185 recompute_visible_regions_internal (private,
1187 recalculate_siblings,
1188 recalculate_children);
1192 _gdk_window_update_size (GdkWindow *window)
1194 recompute_visible_regions (window, TRUE, FALSE);
1197 /* Find the native window that would be just above "child"
1198 * in the native stacking order if "child" was a native window
1199 * (it doesn't have to be native). If there is no such native
1200 * window inside this native parent then NULL is returned.
1201 * If child is NULL, find lowest native window in parent.
1204 find_native_sibling_above_helper (GdkWindow *parent,
1212 l = g_list_find (parent->children, child);
1213 g_assert (l != NULL); /* Better be a child of its parent... */
1214 l = l->prev; /* Start looking at the one above the child */
1217 l = g_list_last (parent->children);
1219 for (; l != NULL; l = l->prev)
1223 if (gdk_window_has_impl (w))
1226 g_assert (parent != w);
1227 w = find_native_sibling_above_helper (w, NULL);
1237 find_native_sibling_above (GdkWindow *parent,
1242 w = find_native_sibling_above_helper (parent, child);
1246 if (gdk_window_has_impl (parent))
1249 return find_native_sibling_above (parent->parent, parent);
1253 get_native_device_event_mask (GdkWindow *private,
1256 GdkEventMask event_mask;
1259 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
1261 event_mask = private->event_mask;
1263 if (private->window_type == GDK_WINDOW_ROOT ||
1264 private->window_type == GDK_WINDOW_FOREIGN)
1270 /* Do whatever the app asks to, since the app
1271 * may be asking for weird things for native windows,
1272 * but don't use motion hints as that may affect non-native
1273 * child windows that don't want it. Also, we need to
1274 * set all the app-specified masks since they will be picked
1275 * up by any implicit grabs (i.e. if they were not set as
1276 * native we would not get the events we need). */
1277 mask = private->event_mask & ~GDK_POINTER_MOTION_HINT_MASK;
1279 /* We need thse for all native windows so we can
1280 emulate events on children: */
1283 GDK_VISIBILITY_NOTIFY_MASK |
1284 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
1286 /* Additionally we select for pointer and button events
1287 * for toplevels as we need to get these to emulate
1288 * them for non-native subwindows. Even though we don't
1289 * select on them for all native windows we will get them
1290 * as the events are propagated out to the first window
1291 * that select for them.
1292 * Not selecting for button press on all windows is an
1293 * important thing, because in X only one client can do
1294 * so, and we don't want to unexpectedly prevent another
1295 * client from doing it.
1297 * We also need to do the same if the app selects for button presses
1298 * because then we will get implicit grabs for this window, and the
1299 * event mask used for that grab is based on the rest of the mask
1300 * for the window, but we might need more events than this window
1301 * lists due to some non-native child window.
1303 if (gdk_window_is_toplevel (private) ||
1304 mask & GDK_BUTTON_PRESS_MASK)
1307 GDK_POINTER_MOTION_MASK |
1308 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1316 get_native_grab_event_mask (GdkEventMask grab_mask)
1318 /* Similar to the above but for pointer events only */
1320 GDK_POINTER_MOTION_MASK |
1321 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1322 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1325 ~GDK_POINTER_MOTION_HINT_MASK);
1329 get_native_event_mask (GdkWindow *private)
1331 return get_native_device_event_mask (private, NULL);
1334 /* Puts the native window in the right order wrt the other native windows
1335 * in the hierarchy, given the position it has in the client side data.
1336 * This is useful if some operation changed the stacking order.
1337 * This calls assumes the native window is now topmost in its native parent.
1340 sync_native_window_stack_position (GdkWindow *window)
1343 GdkWindowImplClass *impl_class;
1344 GList listhead = {0};
1346 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1348 above = find_native_sibling_above (window->parent, window);
1351 listhead.data = window;
1352 impl_class->restack_under (above, &listhead);
1357 * gdk_window_new: (constructor)
1358 * @parent: (allow-none): a #GdkWindow, or %NULL to create the window as a child of
1359 * the default root window for the default display.
1360 * @attributes: attributes of the new window
1361 * @attributes_mask: (type GdkWindowAttributesType): mask indicating which
1362 * fields in @attributes are valid
1364 * Creates a new #GdkWindow using the attributes from
1365 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
1366 * more details. Note: to use this on displays other than the default
1367 * display, @parent must be specified.
1369 * Return value: (transfer full): the new #GdkWindow
1372 gdk_window_new (GdkWindow *parent,
1373 GdkWindowAttr *attributes,
1374 gint attributes_mask)
1378 GdkDisplay *display;
1381 GdkEventMask event_mask;
1382 GdkWindow *real_parent;
1383 GdkDeviceManager *device_manager;
1385 g_return_val_if_fail (attributes != NULL, NULL);
1389 GDK_NOTE (MULTIHEAD,
1390 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
1392 screen = gdk_screen_get_default ();
1393 parent = gdk_screen_get_root_window (screen);
1396 screen = gdk_window_get_screen (parent);
1398 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
1400 if (GDK_WINDOW_DESTROYED (parent))
1402 g_warning ("gdk_window_new(): parent is destroyed\n");
1406 if (attributes_mask & GDK_WA_VISUAL)
1408 g_return_val_if_fail (gdk_visual_get_screen (attributes->visual) == screen, NULL);
1411 display = gdk_screen_get_display (screen);
1413 window = _gdk_display_create_window (display);
1415 /* Windows with a foreign parent are treated as if they are children
1416 * of the root window, except for actual creation.
1418 real_parent = parent;
1419 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
1420 parent = gdk_screen_get_root_window (screen);
1422 window->parent = parent;
1424 window->accept_focus = TRUE;
1425 window->focus_on_map = TRUE;
1427 if (attributes_mask & GDK_WA_X)
1432 if (attributes_mask & GDK_WA_Y)
1439 window->width = (attributes->width > 1) ? (attributes->width) : (1);
1440 window->height = (attributes->height > 1) ? (attributes->height) : (1);
1441 window->alpha = 255;
1443 if (attributes->wclass == GDK_INPUT_ONLY)
1445 /* Backwards compatiblity - we've always ignored
1446 * attributes->window_type for input-only windows
1449 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
1450 window->window_type = GDK_WINDOW_TEMP;
1452 window->window_type = GDK_WINDOW_CHILD;
1455 window->window_type = attributes->window_type;
1458 switch (window->window_type)
1460 case GDK_WINDOW_TOPLEVEL:
1461 case GDK_WINDOW_TEMP:
1462 case GDK_WINDOW_OFFSCREEN:
1463 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
1464 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
1465 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
1466 case GDK_WINDOW_CHILD:
1470 g_warning (G_STRLOC "cannot make windows of type %d", window->window_type);
1474 if (attributes_mask & GDK_WA_VISUAL)
1475 window->visual = attributes->visual;
1477 window->visual = gdk_screen_get_system_visual (screen);
1479 window->event_mask = attributes->event_mask;
1481 if (attributes->wclass == GDK_INPUT_OUTPUT)
1483 window->input_only = FALSE;
1484 window->depth = window->visual->depth;
1486 /* XXX: Cache this somehow? */
1487 window->background = cairo_pattern_create_rgba (0, 0, 0, 0);
1488 window->has_alpha_background = TRUE;
1493 window->input_only = TRUE;
1497 window->parent->children = g_list_prepend (window->parent->children, window);
1500 if (window->parent->window_type == GDK_WINDOW_ROOT)
1501 native = TRUE; /* Always use native windows for toplevels */
1502 else if (!window->input_only &&
1503 (attributes_mask & GDK_WA_VISUAL &&
1504 attributes->visual != gdk_window_get_visual (window->parent)))
1505 native = TRUE; /* InputOutput window with different visual than parent, needs native window */
1507 if (gdk_window_is_offscreen (window))
1509 _gdk_offscreen_window_new (window, attributes, attributes_mask);
1510 window->impl_window = window;
1514 event_mask = get_native_event_mask (window);
1516 /* Create the impl */
1517 _gdk_display_create_window_impl (display, window, real_parent, screen, event_mask, attributes, attributes_mask);
1518 window->impl_window = window;
1520 /* This will put the native window topmost in the native parent, which may
1521 * be wrong wrt other native windows in the non-native hierarchy, so restack */
1522 if (!_gdk_window_has_impl (real_parent))
1523 sync_native_window_stack_position (window);
1527 window->impl_window = g_object_ref (window->parent->impl_window);
1528 window->impl = g_object_ref (window->impl_window->impl);
1531 recompute_visible_regions (window, TRUE, FALSE);
1533 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
1534 (attributes->cursor) :
1537 device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent));
1538 g_signal_connect (device_manager, "device-removed",
1539 G_CALLBACK (device_removed_cb), window);
1545 is_parent_of (GdkWindow *parent,
1556 w = gdk_window_get_parent (w);
1563 change_impl (GdkWindow *private,
1564 GdkWindow *impl_window,
1569 GdkWindowImpl *old_impl;
1570 GdkWindow *old_impl_window;
1572 old_impl = private->impl;
1573 old_impl_window = private->impl_window;
1574 if (private != impl_window)
1575 private->impl_window = g_object_ref (impl_window);
1577 private->impl_window = private;
1578 private->impl = g_object_ref (new);
1579 if (old_impl_window != private)
1580 g_object_unref (old_impl_window);
1581 g_object_unref (old_impl);
1583 for (l = private->children; l != NULL; l = l->next)
1587 if (child->impl == old_impl)
1588 change_impl (child, impl_window, new);
1593 reparent_to_impl (GdkWindow *private)
1598 GdkWindowImplClass *impl_class;
1600 impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
1602 /* Enumerate in reverse order so we get the right order for the native
1603 windows (first in childrens list is topmost, and reparent places on top) */
1604 for (l = g_list_last (private->children); l != NULL; l = l->prev)
1608 if (child->impl == private->impl)
1609 reparent_to_impl (child);
1612 show = impl_class->reparent ((GdkWindow *)child,
1613 (GdkWindow *)private,
1614 child->x, child->y);
1616 gdk_window_show_unraised ((GdkWindow *)child);
1623 * gdk_window_reparent:
1624 * @window: a #GdkWindow
1625 * @new_parent: new parent to move @window into
1626 * @x: X location inside the new parent
1627 * @y: Y location inside the new parent
1629 * Reparents @window into the given @new_parent. The window being
1630 * reparented will be unmapped as a side effect.
1634 gdk_window_reparent (GdkWindow *window,
1635 GdkWindow *new_parent,
1639 GdkWindow *old_parent;
1641 gboolean show, was_mapped, applied_clip_as_shape;
1642 gboolean do_reparent_to_impl;
1643 GdkEventMask old_native_event_mask;
1644 GdkWindowImplClass *impl_class;
1646 g_return_if_fail (GDK_IS_WINDOW (window));
1647 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1648 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1650 if (GDK_WINDOW_DESTROYED (window) ||
1651 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1654 screen = gdk_window_get_screen (window);
1656 new_parent = gdk_screen_get_root_window (screen);
1658 /* No input-output children of input-only windows */
1659 if (new_parent->input_only && !window->input_only)
1662 /* Don't create loops in hierarchy */
1663 if (is_parent_of (window, new_parent))
1666 /* This might be wrong in the new parent, e.g. for non-native surfaces.
1667 To make sure we're ok, just wipe it. */
1668 gdk_window_drop_cairo_surface (window);
1670 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1671 old_parent = window->parent;
1673 was_mapped = GDK_WINDOW_IS_MAPPED (window);
1676 /* Reparenting to toplevel. Ensure we have a native window so this can work */
1677 if (new_parent->window_type == GDK_WINDOW_ROOT ||
1678 new_parent->window_type == GDK_WINDOW_FOREIGN)
1679 gdk_window_ensure_native (window);
1681 applied_clip_as_shape = should_apply_clip_as_shape (window);
1683 old_native_event_mask = 0;
1684 do_reparent_to_impl = FALSE;
1685 if (gdk_window_has_impl (window))
1687 old_native_event_mask = get_native_event_mask (window);
1689 show = impl_class->reparent (window, new_parent, x, y);
1693 /* This shouldn't happen, as we created a native in this case, check anyway to see if that ever fails */
1694 g_assert (new_parent->window_type != GDK_WINDOW_ROOT &&
1695 new_parent->window_type != GDK_WINDOW_FOREIGN);
1698 gdk_window_hide (window);
1700 do_reparent_to_impl = TRUE;
1701 change_impl (window,
1702 new_parent->impl_window,
1706 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1709 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1711 new_parent = gdk_screen_get_root_window (screen);
1715 old_parent->children = g_list_remove (old_parent->children, window);
1717 window->parent = new_parent;
1721 new_parent->children = g_list_prepend (new_parent->children, window);
1723 /* Switch the window type as appropriate */
1725 switch (GDK_WINDOW_TYPE (new_parent))
1727 case GDK_WINDOW_ROOT:
1728 case GDK_WINDOW_FOREIGN:
1729 if (window->toplevel_window_type != -1)
1730 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1731 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1732 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1734 case GDK_WINDOW_OFFSCREEN:
1735 case GDK_WINDOW_TOPLEVEL:
1736 case GDK_WINDOW_CHILD:
1737 case GDK_WINDOW_TEMP:
1738 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
1739 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1741 /* Save the original window type so we can restore it if the
1742 * window is reparented back to be a toplevel
1744 window->toplevel_window_type = GDK_WINDOW_TYPE (window);
1745 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1749 /* We might have changed window type for a native windows, so we
1750 need to change the event mask too. */
1751 if (gdk_window_has_impl (window))
1753 GdkEventMask native_event_mask = get_native_event_mask (window);
1755 if (native_event_mask != old_native_event_mask)
1756 impl_class->set_events (window, native_event_mask);
1759 _gdk_window_update_viewable (window);
1761 if (window->background == NULL)
1763 /* parent relative background, update has_alpha_background */
1764 if (window->parent == NULL ||
1765 window->parent->window_type == GDK_WINDOW_ROOT)
1766 window->has_alpha_background = FALSE;
1768 window->has_alpha_background = window->parent->has_alpha_background;
1771 recompute_visible_regions (window, TRUE, FALSE);
1772 if (old_parent && GDK_WINDOW_TYPE (old_parent) != GDK_WINDOW_ROOT)
1773 recompute_visible_regions (old_parent, FALSE, TRUE);
1775 _gdk_window_propagate_has_alpha_background (window);
1777 /* We used to apply the clip as the shape, but no more.
1778 Reset this to the real shape */
1779 if (gdk_window_has_impl (window) &&
1780 applied_clip_as_shape &&
1781 !should_apply_clip_as_shape (window))
1782 apply_shape (window, window->shape);
1784 if (do_reparent_to_impl)
1785 reparent_to_impl (window);
1788 /* The reparent will have put the native window topmost in the native parent,
1789 * which may be wrong wrt other native windows in the non-native hierarchy,
1791 if (!gdk_window_has_impl (new_parent))
1792 sync_native_window_stack_position (window);
1796 gdk_window_show_unraised (window);
1798 _gdk_synthesize_crossing_events_for_geometry_change (window);
1802 * gdk_window_ensure_native:
1803 * @window: a #GdkWindow
1805 * Tries to ensure that there is a window-system native window for this
1806 * GdkWindow. This may fail in some situations, returning %FALSE.
1808 * Offscreen window and children of them can never have native windows.
1810 * Some backends may not support native child windows.
1812 * Returns: %TRUE if the window has a native window, %FALSE otherwise
1817 gdk_window_ensure_native (GdkWindow *window)
1819 GdkWindow *impl_window;
1820 GdkWindowImpl *new_impl, *old_impl;
1821 GdkDisplay *display;
1825 GdkWindowImplClass *impl_class;
1827 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1829 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
1830 GDK_WINDOW_DESTROYED (window))
1833 impl_window = gdk_window_get_impl_window (window);
1835 if (gdk_window_is_offscreen (impl_window))
1836 return FALSE; /* native in offscreens not supported */
1838 if (impl_window == window)
1839 /* Already has an impl, and its not offscreen . */
1842 /* Need to create a native window */
1844 gdk_window_drop_cairo_surface (window);
1846 screen = gdk_window_get_screen (window);
1847 display = gdk_screen_get_display (screen);
1849 old_impl = window->impl;
1850 _gdk_display_create_window_impl (display,
1851 window, window->parent,
1853 get_native_event_mask (window),
1855 new_impl = window->impl;
1857 window->impl = old_impl;
1858 change_impl (window, window, new_impl);
1860 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
1862 /* Native window creation will put the native window topmost in the
1863 * native parent, which may be wrong wrt the position of the previous
1864 * non-native window wrt to the other non-native children, so correct this.
1866 above = find_native_sibling_above (window->parent, window);
1869 listhead.data = window;
1870 listhead.prev = NULL;
1871 listhead.next = NULL;
1872 impl_class->restack_under ((GdkWindow *)above, &listhead);
1875 recompute_visible_regions (window, FALSE, FALSE);
1877 /* The shape may not have been set, as the clip region doesn't actually
1878 change, so do it here manually */
1879 if (should_apply_clip_as_shape (window))
1880 apply_clip_as_shape (window);
1882 reparent_to_impl (window);
1884 if (!window->input_only)
1885 impl_class->set_background (window, window->background);
1887 impl_class->input_shape_combine_region (window,
1888 window->input_shape,
1891 if (gdk_window_is_viewable (window))
1892 impl_class->show (window, FALSE);
1898 * _gdk_event_filter_unref:
1899 * @window: (allow-none): A #GdkWindow, or %NULL to be the global window
1900 * @filter: A window filter
1902 * Release a reference to @filter. Note this function may
1903 * mutate the list storage, so you need to handle this
1904 * if iterating over a list of filters.
1907 _gdk_event_filter_unref (GdkWindow *window,
1908 GdkEventFilter *filter)
1914 filters = &_gdk_default_filters;
1916 filters = &window->filters;
1918 tmp_list = *filters;
1921 GdkEventFilter *iter_filter = tmp_list->data;
1925 tmp_list = tmp_list->next;
1927 if (iter_filter != filter)
1930 g_assert (iter_filter->ref_count > 0);
1932 filter->ref_count--;
1933 if (filter->ref_count != 0)
1936 *filters = g_list_remove_link (*filters, node);
1938 g_list_free_1 (node);
1943 window_remove_filters (GdkWindow *window)
1945 while (window->filters)
1946 _gdk_event_filter_unref (window, window->filters->data);
1950 update_pointer_info_foreach (GdkDisplay *display,
1952 GdkPointerWindowInfo *pointer_info,
1955 GdkWindow *window = user_data;
1957 if (pointer_info->toplevel_under_pointer == window)
1959 g_object_unref (pointer_info->toplevel_under_pointer);
1960 pointer_info->toplevel_under_pointer = NULL;
1965 window_remove_from_pointer_info (GdkWindow *window,
1966 GdkDisplay *display)
1968 _gdk_display_pointer_info_foreach (display,
1969 update_pointer_info_foreach,
1974 * _gdk_window_destroy_hierarchy:
1975 * @window: a #GdkWindow
1976 * @recursing: If TRUE, then this is being called because a parent
1978 * @recursing_native: If TRUE, then this is being called because a native parent
1979 * was destroyed. This generally means that the call to the
1980 * windowing system to destroy the window can be omitted, since
1981 * it will be destroyed as a result of the parent being destroyed.
1982 * Unless @foreign_destroy.
1983 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
1984 * external agency. The window has already been destroyed and no
1985 * windowing system calls should be made. (This may never happen
1986 * for some windowing systems.)
1988 * Internal function to destroy a window. Like gdk_window_destroy(),
1989 * but does not drop the reference count created by gdk_window_new().
1992 _gdk_window_destroy_hierarchy (GdkWindow *window,
1994 gboolean recursing_native,
1995 gboolean foreign_destroy)
1997 GdkWindowImplClass *impl_class;
1998 GdkWindow *temp_window;
2000 GdkDisplay *display;
2004 g_return_if_fail (GDK_IS_WINDOW (window));
2006 if (GDK_WINDOW_DESTROYED (window))
2009 display = gdk_window_get_display (window);
2010 screen = gdk_window_get_screen (window);
2011 temp_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
2012 if (temp_window == window)
2013 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, NULL);
2016 switch (window->window_type)
2018 case GDK_WINDOW_ROOT:
2019 if (!screen->closed)
2021 g_error ("attempted to destroy root window");
2024 /* else fall thru */
2025 case GDK_WINDOW_TOPLEVEL:
2026 case GDK_WINDOW_CHILD:
2027 case GDK_WINDOW_TEMP:
2028 case GDK_WINDOW_FOREIGN:
2029 case GDK_WINDOW_OFFSCREEN:
2030 if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
2032 /* Logically, it probably makes more sense to send
2033 * a "destroy yourself" message to the foreign window
2034 * whether or not it's in our hierarchy; but for historical
2035 * reasons, we only send "destroy yourself" messages to
2036 * foreign windows in our hierarchy.
2040 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2042 if (gdk_window_has_impl (window))
2043 impl_class->destroy_foreign (window);
2046 /* Also for historical reasons, we remove any filters
2047 * on a foreign window when it or a parent is destroyed;
2048 * this likely causes problems if two separate portions
2049 * of code are maintaining filter lists on a foreign window.
2051 window_remove_filters (window);
2057 if (window->parent->children)
2058 window->parent->children = g_list_remove (window->parent->children, window);
2061 GDK_WINDOW_IS_MAPPED (window))
2063 recompute_visible_regions (window, TRUE, FALSE);
2064 gdk_window_invalidate_in_parent (window);
2068 gdk_window_free_paint_stack (window);
2070 if (window->background)
2072 cairo_pattern_destroy (window->background);
2073 window->background = NULL;
2076 if (window->window_type == GDK_WINDOW_FOREIGN)
2077 g_assert (window->children == NULL);
2080 children = tmp = window->children;
2081 window->children = NULL;
2085 temp_window = tmp->data;
2089 _gdk_window_destroy_hierarchy (temp_window,
2091 recursing_native || gdk_window_has_impl (window),
2095 g_list_free (children);
2098 _gdk_window_clear_update_area (window);
2100 gdk_window_drop_cairo_surface (window);
2102 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
2104 if (gdk_window_has_impl (window))
2105 impl_class->destroy (window, recursing_native,
2109 /* hide to make sure we repaint and break grabs */
2110 gdk_window_hide (window);
2113 window->state |= GDK_WINDOW_STATE_WITHDRAWN;
2114 window->parent = NULL;
2115 window->destroyed = TRUE;
2117 window_remove_filters (window);
2119 window_remove_from_pointer_info (window, display);
2121 if (window->clip_region)
2123 cairo_region_destroy (window->clip_region);
2124 window->clip_region = NULL;
2127 if (window->clip_region_with_children)
2129 cairo_region_destroy (window->clip_region_with_children);
2130 window->clip_region_with_children = NULL;
2133 g_list_free_full (window->outstanding_moves, (GDestroyNotify) gdk_window_region_move_free);
2134 window->outstanding_moves = NULL;
2141 * _gdk_window_destroy:
2142 * @window: a #GdkWindow
2143 * @foreign_destroy: If TRUE, the window or a parent was destroyed by some
2144 * external agency. The window has already been destroyed and no
2145 * windowing system calls should be made. (This may never happen
2146 * for some windowing systems.)
2148 * Internal function to destroy a window. Like gdk_window_destroy(),
2149 * but does not drop the reference count created by gdk_window_new().
2152 _gdk_window_destroy (GdkWindow *window,
2153 gboolean foreign_destroy)
2155 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, foreign_destroy);
2159 * gdk_window_destroy:
2160 * @window: a #GdkWindow
2162 * Destroys the window system resources associated with @window and decrements @window's
2163 * reference count. The window system resources for all children of @window are also
2164 * destroyed, but the children's reference counts are not decremented.
2166 * Note that a window will not be destroyed automatically when its reference count
2167 * reaches zero. You must call this function yourself before that happens.
2171 gdk_window_destroy (GdkWindow *window)
2173 _gdk_window_destroy_hierarchy (window, FALSE, FALSE, FALSE);
2174 g_object_unref (window);
2178 * gdk_window_set_user_data:
2179 * @window: a #GdkWindow
2180 * @user_data: (allow-none) (type GObject.Object): user data
2182 * For most purposes this function is deprecated in favor of
2183 * g_object_set_data(). However, for historical reasons GTK+ stores
2184 * the #GtkWidget that owns a #GdkWindow as user data on the
2185 * #GdkWindow. So, custom widget implementations should use
2186 * this function for that. If GTK+ receives an event for a #GdkWindow,
2187 * and the user data for the window is non-%NULL, GTK+ will assume the
2188 * user data is a #GtkWidget, and forward the event to that widget.
2192 gdk_window_set_user_data (GdkWindow *window,
2195 g_return_if_fail (GDK_IS_WINDOW (window));
2197 window->user_data = user_data;
2201 * gdk_window_get_user_data:
2202 * @window: a #GdkWindow
2203 * @data: (out): return location for user data
2205 * Retrieves the user data for @window, which is normally the widget
2206 * that @window belongs to. See gdk_window_set_user_data().
2210 gdk_window_get_user_data (GdkWindow *window,
2213 g_return_if_fail (GDK_IS_WINDOW (window));
2215 *data = window->user_data;
2219 * gdk_window_get_window_type:
2220 * @window: a #GdkWindow
2222 * Gets the type of the window. See #GdkWindowType.
2224 * Return value: type of window
2227 gdk_window_get_window_type (GdkWindow *window)
2229 g_return_val_if_fail (GDK_IS_WINDOW (window), (GdkWindowType) -1);
2231 return GDK_WINDOW_TYPE (window);
2235 * gdk_window_get_visual:
2236 * @window: a #GdkWindow
2238 * Gets the #GdkVisual describing the pixel format of @window.
2240 * Return value: (transfer none): a #GdkVisual
2245 gdk_window_get_visual (GdkWindow *window)
2247 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2249 return window->visual;
2253 * gdk_window_get_screen:
2254 * @window: a #GdkWindow
2256 * Gets the #GdkScreen associated with a #GdkWindow.
2258 * Return value: (transfer none): the #GdkScreen associated with @window
2263 gdk_window_get_screen (GdkWindow *window)
2265 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2267 return gdk_visual_get_screen (window->visual);
2271 * gdk_window_get_display:
2272 * @window: a #GdkWindow
2274 * Gets the #GdkDisplay associated with a #GdkWindow.
2276 * Return value: (transfer none): the #GdkDisplay associated with @window
2281 gdk_window_get_display (GdkWindow *window)
2283 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2285 return gdk_screen_get_display (gdk_visual_get_screen (window->visual));
2288 * gdk_window_is_destroyed:
2289 * @window: a #GdkWindow
2291 * Check to see if a window is destroyed..
2293 * Return value: %TRUE if the window is destroyed
2298 gdk_window_is_destroyed (GdkWindow *window)
2300 return GDK_WINDOW_DESTROYED (window);
2304 to_embedder (GdkWindow *window,
2305 gdouble offscreen_x,
2306 gdouble offscreen_y,
2307 gdouble *embedder_x,
2308 gdouble *embedder_y)
2310 g_signal_emit (window, signals[TO_EMBEDDER], 0,
2311 offscreen_x, offscreen_y,
2312 embedder_x, embedder_y);
2316 from_embedder (GdkWindow *window,
2319 gdouble *offscreen_x,
2320 gdouble *offscreen_y)
2322 g_signal_emit (window, signals[FROM_EMBEDDER], 0,
2323 embedder_x, embedder_y,
2324 offscreen_x, offscreen_y);
2328 * gdk_window_has_native:
2329 * @window: a #GdkWindow
2331 * Checks whether the window has a native window or not. Note that
2332 * you can use gdk_window_ensure_native() if a native window is needed.
2334 * Returns: %TRUE if the %window has a native window, %FALSE otherwise.
2339 gdk_window_has_native (GdkWindow *window)
2341 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2343 return window->parent == NULL || window->parent->impl != window->impl;
2347 * gdk_window_get_position:
2348 * @window: a #GdkWindow
2349 * @x: (out) (allow-none): X coordinate of window
2350 * @y: (out) (allow-none): Y coordinate of window
2352 * Obtains the position of the window as reported in the
2353 * most-recently-processed #GdkEventConfigure. Contrast with
2354 * gdk_window_get_geometry() which queries the X server for the
2355 * current window position, regardless of which events have been
2356 * received or processed.
2358 * The position coordinates are relative to the window's parent window.
2362 gdk_window_get_position (GdkWindow *window,
2366 g_return_if_fail (GDK_IS_WINDOW (window));
2375 * gdk_window_get_parent:
2376 * @window: a #GdkWindow
2378 * Obtains the parent of @window, as known to GDK. Does not query the
2379 * X server; thus this returns the parent as passed to gdk_window_new(),
2380 * not the actual parent. This should never matter unless you're using
2381 * Xlib calls mixed with GDK calls on the X11 platform. It may also
2382 * matter for toplevel windows, because the window manager may choose
2385 * Note that you should use gdk_window_get_effective_parent() when
2386 * writing generic code that walks up a window hierarchy, because
2387 * gdk_window_get_parent() will most likely not do what you expect if
2388 * there are offscreen windows in the hierarchy.
2390 * Return value: (transfer none): parent of @window
2393 gdk_window_get_parent (GdkWindow *window)
2395 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2397 return window->parent;
2401 * gdk_window_get_effective_parent:
2402 * @window: a #GdkWindow
2404 * Obtains the parent of @window, as known to GDK. Works like
2405 * gdk_window_get_parent() for normal windows, but returns the
2406 * window's embedder for offscreen windows.
2408 * See also: gdk_offscreen_window_get_embedder()
2410 * Return value: (transfer none): effective parent of @window
2415 gdk_window_get_effective_parent (GdkWindow *window)
2417 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2419 if (gdk_window_is_offscreen (window))
2420 return gdk_offscreen_window_get_embedder (window);
2422 return window->parent;
2426 * gdk_window_get_toplevel:
2427 * @window: a #GdkWindow
2429 * Gets the toplevel window that's an ancestor of @window.
2431 * Any window type but %GDK_WINDOW_CHILD is considered a
2432 * toplevel window, as is a %GDK_WINDOW_CHILD window that
2433 * has a root window as parent.
2435 * Note that you should use gdk_window_get_effective_toplevel() when
2436 * you want to get to a window's toplevel as seen on screen, because
2437 * gdk_window_get_toplevel() will most likely not do what you expect
2438 * if there are offscreen windows in the hierarchy.
2440 * Return value: (transfer none): the toplevel window containing @window
2443 gdk_window_get_toplevel (GdkWindow *window)
2445 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2447 while (window->window_type == GDK_WINDOW_CHILD)
2449 if (gdk_window_is_toplevel (window))
2451 window = window->parent;
2458 * gdk_window_get_effective_toplevel:
2459 * @window: a #GdkWindow
2461 * Gets the toplevel window that's an ancestor of @window.
2463 * Works like gdk_window_get_toplevel(), but treats an offscreen window's
2464 * embedder as its parent, using gdk_window_get_effective_parent().
2466 * See also: gdk_offscreen_window_get_embedder()
2468 * Return value: (transfer none): the effective toplevel window containing @window
2473 gdk_window_get_effective_toplevel (GdkWindow *window)
2477 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2479 while ((parent = gdk_window_get_effective_parent (window)) != NULL &&
2480 (gdk_window_get_window_type (parent) != GDK_WINDOW_ROOT))
2487 * gdk_window_get_children:
2488 * @window: a #GdkWindow
2490 * Gets the list of children of @window known to GDK.
2491 * This function only returns children created via GDK,
2492 * so for example it's useless when used with the root window;
2493 * it only returns windows an application created itself.
2495 * The returned list must be freed, but the elements in the
2498 * Return value: (transfer container) (element-type GdkWindow):
2499 * list of child windows inside @window
2502 gdk_window_get_children (GdkWindow *window)
2504 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2506 if (GDK_WINDOW_DESTROYED (window))
2509 return g_list_copy (window->children);
2513 * gdk_window_peek_children:
2514 * @window: a #GdkWindow
2516 * Like gdk_window_get_children(), but does not copy the list of
2517 * children, so the list does not need to be freed.
2519 * Return value: (transfer none) (element-type GdkWindow):
2520 * a reference to the list of child windows in @window
2523 gdk_window_peek_children (GdkWindow *window)
2525 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2527 if (GDK_WINDOW_DESTROYED (window))
2530 return window->children;
2534 * gdk_window_add_filter: (skip)
2535 * @window: (allow-none): a #GdkWindow
2536 * @function: filter callback
2537 * @data: data to pass to filter callback
2539 * Adds an event filter to @window, allowing you to intercept events
2540 * before they reach GDK. This is a low-level operation and makes it
2541 * easy to break GDK and/or GTK+, so you have to know what you're
2542 * doing. Pass %NULL for @window to get all events for all windows,
2543 * instead of events for a specific window.
2545 * If you are interested in X GenericEvents, bear in mind that
2546 * XGetEventData() has been already called on the event, and
2547 * XFreeEventData() must not be called within @function.
2550 gdk_window_add_filter (GdkWindow *window,
2551 GdkFilterFunc function,
2555 GdkEventFilter *filter;
2557 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2559 if (window && GDK_WINDOW_DESTROYED (window))
2562 /* Filters are for the native events on the native window, so
2563 ensure there is a native window. */
2565 gdk_window_ensure_native (window);
2568 tmp_list = window->filters;
2570 tmp_list = _gdk_default_filters;
2574 filter = (GdkEventFilter *)tmp_list->data;
2575 if ((filter->function == function) && (filter->data == data))
2577 filter->ref_count++;
2580 tmp_list = tmp_list->next;
2583 filter = g_new (GdkEventFilter, 1);
2584 filter->function = function;
2585 filter->data = data;
2586 filter->ref_count = 1;
2590 window->filters = g_list_append (window->filters, filter);
2592 _gdk_default_filters = g_list_append (_gdk_default_filters, filter);
2596 * gdk_window_remove_filter: (skip)
2597 * @window: a #GdkWindow
2598 * @function: previously-added filter function
2599 * @data: user data for previously-added filter function
2601 * Remove a filter previously added with gdk_window_add_filter().
2604 gdk_window_remove_filter (GdkWindow *window,
2605 GdkFilterFunc function,
2609 GdkEventFilter *filter;
2611 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2614 tmp_list = window->filters;
2616 tmp_list = _gdk_default_filters;
2620 filter = (GdkEventFilter *)tmp_list->data;
2621 tmp_list = tmp_list->next;
2623 if ((filter->function == function) && (filter->data == data))
2625 filter->flags |= GDK_EVENT_FILTER_REMOVED;
2627 _gdk_event_filter_unref (window, filter);
2635 * gdk_screen_get_toplevel_windows:
2636 * @screen: The #GdkScreen where the toplevels are located.
2638 * Obtains a list of all toplevel windows known to GDK on the screen @screen.
2639 * A toplevel window is a child of the root window (see
2640 * gdk_get_default_root_window()).
2642 * The returned list should be freed with g_list_free(), but
2643 * its elements need not be freed.
2645 * Return value: (transfer container) (element-type GdkWindow):
2646 * list of toplevel windows, free with g_list_free()
2651 gdk_screen_get_toplevel_windows (GdkScreen *screen)
2653 GdkWindow * root_window;
2654 GList *new_list = NULL;
2657 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
2659 root_window = gdk_screen_get_root_window (screen);
2661 tmp_list = root_window->children;
2664 GdkWindow *w = tmp_list->data;
2666 if (w->window_type != GDK_WINDOW_FOREIGN)
2667 new_list = g_list_prepend (new_list, w);
2668 tmp_list = tmp_list->next;
2675 * gdk_window_is_visible:
2676 * @window: a #GdkWindow
2678 * Checks whether the window has been mapped (with gdk_window_show() or
2679 * gdk_window_show_unraised()).
2681 * Return value: %TRUE if the window is mapped
2684 gdk_window_is_visible (GdkWindow *window)
2686 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2688 return GDK_WINDOW_IS_MAPPED (window);
2692 * gdk_window_is_viewable:
2693 * @window: a #GdkWindow
2695 * Check if the window and all ancestors of the window are
2696 * mapped. (This is not necessarily "viewable" in the X sense, since
2697 * we only check as far as we have GDK window parents, not to the root
2700 * Return value: %TRUE if the window is viewable
2703 gdk_window_is_viewable (GdkWindow *window)
2705 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2707 if (window->destroyed)
2710 return window->viewable;
2714 * gdk_window_get_state:
2715 * @window: a #GdkWindow
2717 * Gets the bitwise OR of the currently active window state flags,
2718 * from the #GdkWindowState enumeration.
2720 * Return value: window state bitfield
2723 gdk_window_get_state (GdkWindow *window)
2725 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2727 return window->state;
2730 static cairo_content_t
2731 gdk_window_get_content (GdkWindow *window)
2733 cairo_surface_t *surface;
2734 cairo_content_t content;
2736 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2738 surface = gdk_window_ref_impl_surface (window);
2739 content = cairo_surface_get_content (surface);
2740 cairo_surface_destroy (surface);
2745 /* This creates an empty "implicit" paint region for the impl window.
2746 * By itself this does nothing, but real paints to this window
2747 * or children of it can use this surface as backing to avoid allocating
2748 * multiple surfaces for subwindow rendering. When doing so they
2749 * add to the region of the implicit paint region, which will be
2750 * pushed to the window when the implicit paint region is ended.
2751 * Such paints should not copy anything to the window on paint end, but
2752 * should rely on the implicit paint end.
2753 * The implicit paint will be automatically ended if someone draws
2754 * directly to the window or a child window.
2757 gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect,
2758 gboolean with_alpha, guint8 alpha)
2760 GdkWindowPaint *paint;
2762 g_assert (gdk_window_has_impl (window));
2764 if (GDK_IS_PAINTABLE (window->impl))
2765 return FALSE; /* Implementation does double buffering */
2767 if (window->paint_stack != NULL)
2768 return FALSE; /* Don't stack implicit paints */
2770 /* Never do implicit paints for foreign windows, they don't need
2771 * double buffer combination since they have no client side children,
2772 * and creating surfaces for them is risky since they could disappear
2775 if (window->window_type == GDK_WINDOW_FOREIGN)
2778 paint = g_new (GdkWindowPaint, 1);
2779 paint->region = cairo_region_create (); /* Empty */
2780 paint->uses_implicit = FALSE;
2781 paint->flushed = NULL;
2782 paint->alpha = alpha;
2783 paint->surface = gdk_window_create_similar_surface (window,
2784 with_alpha ? CAIRO_CONTENT_COLOR_ALPHA : gdk_window_get_content (window),
2785 MAX (rect->width, 1),
2786 MAX (rect->height, 1));
2787 cairo_surface_set_device_offset (paint->surface, -rect->x, -rect->y);
2789 window->implicit_paint = g_slist_prepend (window->implicit_paint, paint);
2794 static cairo_surface_t *
2795 gdk_window_ref_impl_surface (GdkWindow *window)
2797 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->ref_cairo_surface (gdk_window_get_impl_window (window));
2801 gdk_cairo_create_for_impl (GdkWindow *window)
2803 cairo_surface_t *surface;
2806 surface = gdk_window_ref_impl_surface (window);
2807 cr = cairo_create (surface);
2809 cairo_surface_destroy (surface);
2814 /* This is called whenever something is drawing directly to the
2815 * window, bypassing the double buffering. When this happens we
2816 * need to mark any the currently drawn data in the double buffer
2817 * as invalid to avoid later drawing it back over the directly
2818 * rendered pixels. We also need to mark this region as "flushed"
2819 * so that if we later try to paint on it double-buffered we need
2820 * to read back the on-window pixels rather than relying on what
2821 * is in the current double-buffer pixmap.
2823 * Note that this doesn't correctly handle the case where the
2824 * non-double buffered drawing uses transparency and relies on
2825 * what the windows below it draws. A fix for that would require
2826 * drawing the existing double-buffered background to the window,
2827 * but that causes ugly flashes. Non-double buffered drawing is
2828 * typically only used in old code or when the drawed widget
2829 * already has a double-buffering layer, and in these cases the
2830 * pixels are opaque anyway. If you need transparency, don't
2831 * disable double buffering.
2834 gdk_window_flush_implicit_paint (GdkWindow *window)
2836 GdkWindow *impl_window;
2837 GdkWindowPaint *paint;
2838 cairo_region_t *region;
2841 impl_window = gdk_window_get_impl_window (window);
2842 if (impl_window->implicit_paint == NULL)
2845 /* There is no proper way to flush any non-toplevel implicit
2846 paint, because direct rendering is not compatible with
2847 opacity rendering, as it requires an opacity group.
2849 We warn and flush just the outermost paint in this case.
2851 l = g_slist_last (impl_window->implicit_paint);
2852 if (l != impl_window->implicit_paint)
2853 g_warning ("Non double buffered drawing not supported inside transparent windows");
2857 region = cairo_region_copy (window->clip_region_with_children);
2858 cairo_region_translate (region, window->abs_x, window->abs_y);
2860 /* Anything in the whole flushed window that was drawn is now
2861 considered unpainted, so that we don't push it back at the
2862 end of the implicit paint overwriting the directly rendered
2864 cairo_region_subtract (paint->region, region);
2866 /* Save flushed area so we can read it back if we draw over it later */
2867 if (paint->flushed == NULL)
2868 paint->flushed = region;
2871 cairo_region_union (paint->flushed, region);
2872 cairo_region_destroy (region);
2876 /* Ends an implicit paint, paired with gdk_window_begin_implicit_paint returning TRUE */
2878 gdk_window_end_implicit_paint (GdkWindow *window)
2880 GdkWindowPaint *paint;
2882 g_assert (gdk_window_has_impl (window));
2884 g_assert (window->implicit_paint != NULL);
2886 paint = window->implicit_paint->data;
2888 window->implicit_paint = g_slist_delete_link (window->implicit_paint,
2889 window->implicit_paint);
2891 if (!GDK_WINDOW_DESTROYED (window) && !cairo_region_is_empty (paint->region) && paint->alpha > 0)
2893 GdkWindowPaint *parent_paint = NULL;
2896 /* Some regions are valid, push these to window now */
2897 if (window->implicit_paint)
2899 parent_paint = window->implicit_paint->data;
2901 /* If the toplevel implicit paint was flushed, restore it now
2902 before we blend over it. */
2903 if (parent_paint->flushed != NULL &&
2904 !cairo_region_is_empty (parent_paint->flushed))
2906 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (window);
2907 cairo_region_t *flushed = cairo_region_copy (parent_paint->flushed);
2909 cr = cairo_create (parent_paint->surface);
2910 cairo_set_source_surface (cr, source_surface, 0, 0);
2911 cairo_surface_destroy (source_surface);
2913 cairo_region_intersect (flushed, paint->region);
2914 gdk_cairo_region (cr, flushed);
2917 cairo_region_subtract (parent_paint->flushed, flushed);
2918 cairo_region_destroy (flushed);
2924 cr = cairo_create (parent_paint->surface);
2927 cr = gdk_cairo_create_for_impl (window);
2929 gdk_cairo_region (cr, paint->region);
2931 cairo_set_source_surface (cr, paint->surface, 0, 0);
2932 if (paint->alpha == 255)
2934 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
2939 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2940 cairo_paint_with_alpha (cr, paint->alpha / 255.0);
2946 cairo_region_union (parent_paint->region, paint->region);
2949 cairo_region_destroy (paint->region);
2951 cairo_region_destroy (paint->flushed);
2952 cairo_surface_destroy (paint->surface);
2957 * gdk_window_begin_paint_rect:
2958 * @window: a #GdkWindow
2959 * @rectangle: rectangle you intend to draw to
2961 * A convenience wrapper around gdk_window_begin_paint_region() which
2962 * creates a rectangular region for you. See
2963 * gdk_window_begin_paint_region() for details.
2967 gdk_window_begin_paint_rect (GdkWindow *window,
2968 const GdkRectangle *rectangle)
2970 cairo_region_t *region;
2972 g_return_if_fail (GDK_IS_WINDOW (window));
2974 region = cairo_region_create_rectangle (rectangle);
2975 gdk_window_begin_paint_region (window, region);
2976 cairo_region_destroy (region);
2980 * gdk_window_begin_paint_region:
2981 * @window: a #GdkWindow
2982 * @region: region you intend to draw to
2984 * Indicates that you are beginning the process of redrawing @region.
2985 * A backing store (offscreen buffer) large enough to contain @region
2986 * will be created. The backing store will be initialized with the
2987 * background color or background surface for @window. Then, all
2988 * drawing operations performed on @window will be diverted to the
2989 * backing store. When you call gdk_window_end_paint(), the backing
2990 * store will be copied to @window, making it visible onscreen. Only
2991 * the part of @window contained in @region will be modified; that is,
2992 * drawing operations are clipped to @region.
2994 * The net result of all this is to remove flicker, because the user
2995 * sees the finished product appear all at once when you call
2996 * gdk_window_end_paint(). If you draw to @window directly without
2997 * calling gdk_window_begin_paint_region(), the user may see flicker
2998 * as individual drawing operations are performed in sequence. The
2999 * clipping and background-initializing features of
3000 * gdk_window_begin_paint_region() are conveniences for the
3001 * programmer, so you can avoid doing that work yourself.
3003 * When using GTK+, the widget system automatically places calls to
3004 * gdk_window_begin_paint_region() and gdk_window_end_paint() around
3005 * emissions of the expose_event signal. That is, if you're writing an
3006 * expose event handler, you can assume that the exposed area in
3007 * #GdkEventExpose has already been cleared to the window background,
3008 * is already set as the clip region, and already has a backing store.
3009 * Therefore in most cases, application code need not call
3010 * gdk_window_begin_paint_region(). (You can disable the automatic
3011 * calls around expose events on a widget-by-widget basis by calling
3012 * gtk_widget_set_double_buffered().)
3014 * If you call this function multiple times before calling the
3015 * matching gdk_window_end_paint(), the backing stores are pushed onto
3016 * a stack. gdk_window_end_paint() copies the topmost backing store
3017 * onscreen, subtracts the topmost region from all other regions in
3018 * the stack, and pops the stack. All drawing operations affect only
3019 * the topmost backing store in the stack. One matching call to
3020 * gdk_window_end_paint() is required for each call to
3021 * gdk_window_begin_paint_region().
3025 gdk_window_begin_paint_region (GdkWindow *window,
3026 const cairo_region_t *region)
3028 #ifdef USE_BACKING_STORE
3029 GdkRectangle clip_box;
3030 GdkWindowPaint *paint, *implicit_paint;
3031 GdkWindow *impl_window;
3034 g_return_if_fail (GDK_IS_WINDOW (window));
3036 if (GDK_WINDOW_DESTROYED (window))
3039 if (GDK_IS_PAINTABLE (window->impl))
3041 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3043 if (iface->begin_paint_region)
3044 iface->begin_paint_region ((GdkPaintable*)window->impl, window, region);
3049 impl_window = gdk_window_get_impl_window (window);
3050 implicit_paint = impl_window->implicit_paint != NULL ? impl_window->implicit_paint->data : NULL;
3052 paint = g_new (GdkWindowPaint, 1);
3053 paint->region = cairo_region_copy (region);
3055 cairo_region_intersect (paint->region, window->clip_region_with_children);
3056 cairo_region_get_extents (paint->region, &clip_box);
3058 cairo_region_translate (paint->region, window->abs_x, window->abs_y);
3060 /* Mark the region as valid on the implicit paint */
3063 cairo_region_union (implicit_paint->region, paint->region);
3065 /* Convert back to normal coords */
3066 cairo_region_translate (paint->region, -window->abs_x, -window->abs_y);
3070 paint->uses_implicit = TRUE;
3071 paint->surface = cairo_surface_create_for_rectangle (implicit_paint->surface,
3072 window->abs_x + clip_box.x,
3073 window->abs_y + clip_box.y,
3074 MAX (clip_box.width, 1),
3075 MAX (clip_box.height, 1));
3079 paint->uses_implicit = FALSE;
3080 paint->surface = gdk_window_create_similar_surface (window,
3081 gdk_window_get_content (window),
3082 MAX (clip_box.width, 1),
3083 MAX (clip_box.height, 1));
3086 /* Normally alpha backgrounded client side windows are composited on the implicit paint
3087 by being drawn in back to front order. However, if implicit paints are not used, for
3088 instance if it was flushed due to a non-double-buffered paint in the middle of the
3089 expose we need to copy in the existing data here. */
3090 if (gdk_window_has_alpha (window) &&
3092 (implicit_paint && implicit_paint->flushed != NULL && !cairo_region_is_empty (implicit_paint->flushed))))
3094 cairo_t *cr = cairo_create (paint->surface);
3095 /* We can't use gdk_cairo_set_source_window here, as that might
3096 flush the implicit paint at an unfortunate time, since this
3097 would be detected as a draw during non-expose time */
3098 cairo_surface_t *source_surface = gdk_window_ref_impl_surface (impl_window);
3099 cairo_set_source_surface (cr, source_surface,
3100 - (window->abs_x + clip_box.x),
3101 - (window->abs_y + clip_box.y));
3102 cairo_surface_destroy (source_surface);
3104 /* Only read back the flushed area if any */
3107 cairo_region_t *flushed = cairo_region_copy (implicit_paint->flushed);
3108 /* Convert from impl coords */
3109 cairo_region_translate (flushed, -window->abs_x, -window->abs_y);
3110 cairo_region_intersect (flushed, paint->region);
3111 gdk_cairo_region (cr, flushed);
3114 /* Convert to impl coords */
3115 cairo_region_translate (flushed, window->abs_x, window->abs_y);
3116 cairo_region_subtract (implicit_paint->flushed, flushed);
3117 cairo_region_destroy (flushed);
3123 cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
3125 for (list = window->paint_stack; list != NULL; list = list->next)
3127 GdkWindowPaint *tmp_paint = list->data;
3129 cairo_region_subtract (tmp_paint->region, paint->region);
3132 window->paint_stack = g_slist_prepend (window->paint_stack, paint);
3134 if (!cairo_region_is_empty (paint->region))
3136 gdk_window_clear_backing_region (window,
3140 #endif /* USE_BACKING_STORE */
3144 * gdk_window_end_paint:
3145 * @window: a #GdkWindow
3147 * Indicates that the backing store created by the most recent call to
3148 * gdk_window_begin_paint_region() should be copied onscreen and
3149 * deleted, leaving the next-most-recent backing store or no backing
3150 * store at all as the active paint region. See
3151 * gdk_window_begin_paint_region() for full details. It is an error to
3152 * call this function without a matching
3153 * gdk_window_begin_paint_region() first.
3157 gdk_window_end_paint (GdkWindow *window)
3159 #ifdef USE_BACKING_STORE
3160 GdkWindow *composited;
3161 GdkWindowPaint *paint;
3162 GdkRectangle clip_box;
3163 cairo_region_t *full_clip;
3165 g_return_if_fail (GDK_IS_WINDOW (window));
3167 if (GDK_WINDOW_DESTROYED (window))
3170 if (GDK_IS_PAINTABLE (window->impl))
3172 GdkPaintableIface *iface = GDK_PAINTABLE_GET_IFACE (window->impl);
3174 if (iface->end_paint)
3175 iface->end_paint ((GdkPaintable*)window->impl);
3179 if (window->paint_stack == NULL)
3181 g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
3185 paint = window->paint_stack->data;
3187 window->paint_stack = g_slist_delete_link (window->paint_stack,
3188 window->paint_stack);
3190 cairo_region_get_extents (paint->region, &clip_box);
3192 if (!paint->uses_implicit)
3196 gdk_window_flush_outstanding_moves (window);
3198 full_clip = cairo_region_copy (window->clip_region_with_children);
3199 cairo_region_intersect (full_clip, paint->region);
3201 cr = gdk_cairo_create (window);
3202 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3203 cairo_set_source_surface (cr, paint->surface, 0, 0);
3204 gdk_cairo_region (cr, full_clip);
3208 cairo_region_destroy (full_clip);
3211 cairo_surface_destroy (paint->surface);
3212 cairo_region_destroy (paint->region);
3215 /* find a composited window in our hierarchy to signal its
3216 * parent to redraw, calculating the clip box as we go...
3218 * stop if parent becomes NULL since then we'd have nowhere
3219 * to draw (ie: 'composited' will always be non-NULL here).
3221 for (composited = window;
3223 composited = composited->parent)
3225 clip_box.x += composited->x;
3226 clip_box.y += composited->y;
3227 clip_box.width = MIN (clip_box.width, composited->parent->width - clip_box.x);
3228 clip_box.height = MIN (clip_box.height, composited->parent->height - clip_box.y);
3230 if (composited->composited)
3232 gdk_window_invalidate_rect (GDK_WINDOW (composited->parent),
3237 #endif /* USE_BACKING_STORE */
3241 gdk_window_free_paint_stack (GdkWindow *window)
3243 if (window->paint_stack)
3245 GSList *tmp_list = window->paint_stack;
3249 GdkWindowPaint *paint = tmp_list->data;
3251 if (tmp_list == window->paint_stack)
3252 cairo_surface_destroy (paint->surface);
3254 cairo_region_destroy (paint->region);
3257 tmp_list = tmp_list->next;
3260 g_slist_free (window->paint_stack);
3261 window->paint_stack = NULL;
3266 do_move_region_bits_on_impl (GdkWindow *impl_window,
3267 cairo_region_t *dest_region, /* In impl window coords */
3270 GdkWindowImplClass *impl_class;
3272 impl_class = GDK_WINDOW_IMPL_GET_CLASS (impl_window->impl);
3274 impl_class->translate (impl_window, dest_region, dx, dy);
3277 static GdkWindowRegionMove *
3278 gdk_window_region_move_new (cairo_region_t *region,
3281 GdkWindowRegionMove *move;
3283 move = g_slice_new (GdkWindowRegionMove);
3284 move->dest_region = cairo_region_copy (region);
3292 gdk_window_region_move_free (GdkWindowRegionMove *move)
3294 cairo_region_destroy (move->dest_region);
3295 g_slice_free (GdkWindowRegionMove, move);
3299 append_move_region (GdkWindow *impl_window,
3300 cairo_region_t *new_dest_region,
3303 GdkWindowRegionMove *move, *old_move;
3304 cairo_region_t *new_total_region, *old_total_region;
3305 cairo_region_t *source_overlaps_destination;
3306 cairo_region_t *non_overwritten;
3307 gboolean added_move;
3310 if (cairo_region_is_empty (new_dest_region))
3313 /* In principle this could just append the move to the list of outstanding
3314 moves that will be replayed before drawing anything when we're handling
3315 exposes. However, we'd like to do a bit better since its commonly the case
3316 that we get multiple copies where A is copied to B and then B is copied
3317 to C, and we'd like to express this as a simple copy A to C operation. */
3319 /* We approach this by taking the new move and pushing it ahead of moves
3320 starting at the end of the list and stopping when its not safe to do so.
3321 It's not safe to push past a move if either the source of the new move
3322 is in the destination of the old move, or if the destination of the new
3323 move is in the source of the new move, or if the destination of the new
3324 move overlaps the destination of the old move. We simplify this by
3325 just comparing the total regions (src + dest) */
3326 new_total_region = cairo_region_copy (new_dest_region);
3327 cairo_region_translate (new_total_region, -dx, -dy);
3328 cairo_region_union (new_total_region, new_dest_region);
3331 for (l = g_list_last (impl_window->outstanding_moves); l != NULL; l = prev)
3336 old_total_region = cairo_region_copy (old_move->dest_region);
3337 cairo_region_translate (old_total_region, -old_move->dx, -old_move->dy);
3338 cairo_region_union (old_total_region, old_move->dest_region);
3340 cairo_region_intersect (old_total_region, new_total_region);
3341 /* If these regions intersect then its not safe to push the
3342 new region before the old one */
3343 if (!cairo_region_is_empty (old_total_region))
3345 /* The area where the new moves source overlaps the old ones
3347 source_overlaps_destination = cairo_region_copy (new_dest_region);
3348 cairo_region_translate (source_overlaps_destination, -dx, -dy);
3349 cairo_region_intersect (source_overlaps_destination, old_move->dest_region);
3350 cairo_region_translate (source_overlaps_destination, dx, dy);
3352 /* We can do all sort of optimizations here, but to do things safely it becomes
3353 quite complicated. However, a very common case is that you copy something first,
3354 then copy all that or a subset of it to a new location (i.e. if you scroll twice
3355 in the same direction). We'd like to detect this case and optimize it to one
3357 if (cairo_region_equal (source_overlaps_destination, new_dest_region))
3359 /* This means we might be able to replace the old move and the new one
3360 with the new one read from the old ones source, and a second copy of
3361 the non-overwritten parts of the old move. However, such a split
3362 is only valid if the source in the old move isn't overwritten
3363 by the destination of the new one */
3365 /* the new destination of old move if split is ok: */
3366 non_overwritten = cairo_region_copy (old_move->dest_region);
3367 cairo_region_subtract (non_overwritten, new_dest_region);
3368 /* move to source region */
3369 cairo_region_translate (non_overwritten, -old_move->dx, -old_move->dy);
3371 cairo_region_intersect (non_overwritten, new_dest_region);
3372 if (cairo_region_is_empty (non_overwritten))
3375 move = gdk_window_region_move_new (new_dest_region,
3379 impl_window->outstanding_moves =
3380 g_list_insert_before (impl_window->outstanding_moves,
3382 cairo_region_subtract (old_move->dest_region, new_dest_region);
3384 cairo_region_destroy (non_overwritten);
3387 cairo_region_destroy (source_overlaps_destination);
3388 cairo_region_destroy (old_total_region);
3391 cairo_region_destroy (old_total_region);
3394 cairo_region_destroy (new_total_region);
3398 move = gdk_window_region_move_new (new_dest_region, dx, dy);
3401 impl_window->outstanding_moves =
3402 g_list_prepend (impl_window->outstanding_moves,
3405 impl_window->outstanding_moves =
3406 g_list_insert_before (impl_window->outstanding_moves,
3411 /* Moves bits and update area by dx/dy in impl window.
3412 Takes ownership of region to avoid copy (because we may change it) */
3414 move_region_on_impl (GdkWindow *impl_window,
3415 cairo_region_t *region, /* In impl window coords */
3420 if ((dx == 0 && dy == 0) ||
3421 cairo_region_is_empty (region))
3423 cairo_region_destroy (region);
3427 g_assert (impl_window == gdk_window_get_impl_window (impl_window));
3429 /* Move any old invalid regions in the copy source area by dx/dy */
3430 if (impl_window->update_area)
3432 cairo_region_t *update_area;
3434 update_area = cairo_region_copy (region);
3436 /* Convert from target to source */
3437 cairo_region_translate (update_area, -dx, -dy);
3438 cairo_region_intersect (update_area, impl_window->update_area);
3439 /* We only copy the area, so keep the old update area invalid.
3440 It would be safe to remove it too, as code that uses
3441 move_region_on_impl generally also invalidate the source
3442 area. However, it would just use waste cycles. */
3445 cairo_region_translate (update_area, dx, dy);
3446 cairo_region_union (impl_window->update_area, update_area);
3448 /* This area of the destination is now invalid,
3449 so no need to copy to it. */
3450 cairo_region_subtract (region, update_area);
3452 cairo_region_destroy (update_area);
3455 /* If we're currently exposing this window, don't copy to this
3456 destination, as it will be overdrawn when the expose is done,
3457 instead invalidate it and repaint later. */
3458 for (l = impl_window->implicit_paint; l != NULL; l = l->next)
3460 GdkWindowPaint *implicit_paint = l->data;
3461 cairo_region_t *exposing;
3463 exposing = cairo_region_copy (implicit_paint->region);
3464 cairo_region_intersect (exposing, region);
3465 cairo_region_subtract (region, exposing);
3467 impl_window_add_update_area (impl_window, exposing);
3468 cairo_region_destroy (exposing);
3471 append_move_region (impl_window, region, dx, dy);
3473 cairo_region_destroy (region);
3476 /* Flushes all outstanding changes to the window, call this
3477 * before drawing directly to the window (i.e. outside a begin/end_paint pair).
3480 gdk_window_flush_outstanding_moves (GdkWindow *window)
3482 GdkWindow *impl_window;
3483 GList *l, *outstanding;
3484 GdkWindowRegionMove *move;
3486 impl_window = gdk_window_get_impl_window (window);
3487 outstanding = impl_window->outstanding_moves;
3488 impl_window->outstanding_moves = NULL;
3490 for (l = outstanding; l != NULL; l = l->next)
3494 do_move_region_bits_on_impl (impl_window,
3495 move->dest_region, move->dx, move->dy);
3497 gdk_window_region_move_free (move);
3500 g_list_free (outstanding);
3505 * @window: a #GdkWindow
3507 * Flush all outstanding cached operations on a window, leaving the
3508 * window in a state which reflects all that has been drawn before.
3510 * Gdk uses multiple kinds of caching to get better performance and
3511 * nicer drawing. For instance, during exposes all paints to a window
3512 * using double buffered rendering are keep on a surface until the last
3513 * window has been exposed. It also delays window moves/scrolls until
3514 * as long as possible until next update to avoid tearing when moving
3517 * Normally this should be completely invisible to applications, as
3518 * we automatically flush the windows when required, but this might
3519 * be needed if you for instance mix direct native drawing with
3520 * gdk drawing. For Gtk widgets that don't use double buffering this
3521 * will be called automatically before sending the expose event.
3526 gdk_window_flush (GdkWindow *window)
3528 gdk_window_flush_outstanding_moves (window);
3529 gdk_window_flush_implicit_paint (window);
3533 gdk_window_flush_recursive_helper (GdkWindow *window,
3534 GdkWindowImpl *impl)
3539 for (l = window->children; l != NULL; l = l->next)
3543 if (child->impl == impl)
3544 /* Same impl, ignore */
3545 gdk_window_flush_recursive_helper (child, impl);
3547 gdk_window_flush_recursive (child);
3552 gdk_window_flush_recursive (GdkWindow *window)
3554 gdk_window_flush (window);
3555 gdk_window_flush_recursive_helper (window, window->impl);
3559 * gdk_window_get_clip_region:
3560 * @window: a #GdkWindow
3562 * Computes the region of a window that potentially can be written
3563 * to by drawing primitives. This region may not take into account
3564 * other factors such as if the window is obscured by other windows,
3565 * but no area outside of this region will be affected by drawing
3568 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3569 * when you are done.
3572 gdk_window_get_clip_region (GdkWindow *window)
3574 cairo_region_t *result;
3576 g_return_val_if_fail (GDK_WINDOW (window), NULL);
3578 result = cairo_region_copy (window->clip_region);
3580 if (window->paint_stack)
3582 cairo_region_t *paint_region = cairo_region_create ();
3583 GSList *tmp_list = window->paint_stack;
3587 GdkWindowPaint *paint = tmp_list->data;
3589 cairo_region_union (paint_region, paint->region);
3591 tmp_list = tmp_list->next;
3594 cairo_region_intersect (result, paint_region);
3595 cairo_region_destroy (paint_region);
3602 * gdk_window_get_visible_region:
3603 * @window: a #GdkWindow
3605 * Computes the region of the @window that is potentially visible.
3606 * This does not necessarily take into account if the window is
3607 * obscured by other windows, but no area outside of this region
3610 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
3611 * when you are done.
3614 gdk_window_get_visible_region (GdkWindow *window)
3616 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3618 return cairo_region_copy (window->clip_region);
3622 setup_backing_rect (GdkWindow *window, GdkWindowPaint *paint)
3624 GdkWindow *bg_window;
3625 cairo_pattern_t *pattern = NULL;
3626 int x_offset = 0, y_offset = 0;
3629 cr = cairo_create (paint->surface);
3631 for (bg_window = window; bg_window; bg_window = bg_window->parent)
3633 pattern = gdk_window_get_background_pattern (bg_window);
3637 x_offset += bg_window->x;
3638 y_offset += bg_window->y;
3643 cairo_translate (cr, -x_offset, -y_offset);
3644 cairo_set_source (cr, pattern);
3645 cairo_translate (cr, x_offset, y_offset);
3648 cairo_set_source_rgb (cr, 0, 0, 0);
3654 gdk_window_clear_backing_region (GdkWindow *window,
3655 cairo_region_t *region)
3657 GdkWindowPaint *paint = window->paint_stack->data;
3658 cairo_region_t *clip;
3661 if (GDK_WINDOW_DESTROYED (window))
3664 cr = setup_backing_rect (window, paint);
3666 clip = cairo_region_copy (paint->region);
3667 cairo_region_intersect (clip, region);
3669 gdk_cairo_region (cr, clip);
3674 cairo_region_destroy (clip);
3678 gdk_window_drop_cairo_surface (GdkWindow *window)
3680 if (window->cairo_surface)
3682 cairo_surface_finish (window->cairo_surface);
3683 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3685 window->cairo_surface = NULL;
3690 gdk_window_cairo_surface_destroy (void *data)
3692 GdkWindow *window = data;
3694 window->cairo_surface = NULL;
3697 static cairo_surface_t *
3698 gdk_window_create_cairo_surface (GdkWindow *window,
3702 cairo_surface_t *surface, *subsurface;
3704 surface = gdk_window_ref_impl_surface (window);
3705 if (gdk_window_has_impl (window))
3708 subsurface = cairo_surface_create_for_rectangle (surface,
3713 cairo_surface_destroy (surface);
3719 _gdk_window_ref_cairo_surface (GdkWindow *window)
3721 cairo_surface_t *surface;
3723 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3725 if (window->paint_stack)
3727 GdkWindowPaint *paint = window->paint_stack->data;
3729 surface = paint->surface;
3730 cairo_surface_reference (surface);
3735 /* This will be drawing directly to the window, so flush implicit paint */
3736 gdk_window_flush (window);
3738 if (!window->cairo_surface)
3740 window->cairo_surface = gdk_window_create_cairo_surface (window,
3744 if (window->cairo_surface)
3746 cairo_surface_set_user_data (window->cairo_surface, &gdk_window_cairo_key,
3747 window, gdk_window_cairo_surface_destroy);
3751 cairo_surface_reference (window->cairo_surface);
3753 surface = window->cairo_surface;
3761 * @window: a #GdkWindow
3763 * Creates a Cairo context for drawing to @window.
3766 * Note that calling cairo_reset_clip() on the resulting #cairo_t will
3767 * produce undefined results, so avoid it at all costs.
3770 * Return value: A newly created Cairo context. Free with
3771 * cairo_destroy() when you are done drawing.
3776 gdk_cairo_create (GdkWindow *window)
3778 cairo_surface_t *surface;
3781 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3783 surface = _gdk_window_ref_cairo_surface (window);
3784 cr = cairo_create (surface);
3786 if (!window->paint_stack)
3788 gdk_cairo_region (cr, window->clip_region_with_children);
3793 GdkWindowPaint *paint = window->paint_stack->data;
3795 /* Only needs to clip to region if piggybacking
3796 on an implicit paint */
3797 if (paint->uses_implicit)
3799 gdk_cairo_region (cr, paint->region);
3804 cairo_surface_destroy (surface);
3809 /* Code for dirty-region queueing
3811 static GSList *update_windows = NULL;
3812 static GdkFrameClock *_gdk_default_frame_clock = NULL;
3813 static gboolean debug_updates = FALSE;
3815 static inline gboolean
3816 gdk_window_is_ancestor (GdkWindow *window,
3817 GdkWindow *ancestor)
3821 GdkWindow *parent = window->parent;
3823 if (parent == ancestor)
3833 gdk_window_add_update_window (GdkWindow *window)
3836 GSList *prev = NULL;
3837 gboolean has_ancestor_in_list = FALSE;
3839 for (tmp = update_windows; tmp; tmp = tmp->next)
3841 GdkWindow *parent = window->parent;
3843 /* check if tmp is an ancestor of "window"; if it is, set a
3844 * flag indicating that all following windows are either
3845 * children of "window" or from a differen hierarchy
3847 if (!has_ancestor_in_list && gdk_window_is_ancestor (window, tmp->data))
3848 has_ancestor_in_list = TRUE;
3850 /* insert in reverse stacking order when adding around siblings,
3851 * so processing updates properly paints over lower stacked windows
3853 if (parent == GDK_WINDOW (tmp->data)->parent)
3855 gint index = g_list_index (parent->children, window);
3856 for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
3858 gint sibling_index = g_list_index (parent->children, tmp->data);
3859 if (index > sibling_index)
3863 /* here, tmp got advanced past all lower stacked siblings */
3864 tmp = g_slist_prepend (tmp, window);
3868 update_windows = tmp;
3872 /* if "window" has an ancestor in the list and tmp is one of
3873 * "window's" children, insert "window" before tmp
3875 if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
3877 tmp = g_slist_prepend (tmp, window);
3882 update_windows = tmp;
3886 /* if we're at the end of the list and had an ancestor it it,
3887 * append to the list
3889 if (! tmp->next && has_ancestor_in_list)
3891 tmp = g_slist_append (tmp, window);
3898 /* if all above checks failed ("window" is from a different
3899 * hierarchy than what is already in the list) or the list is
3902 update_windows = g_slist_prepend (update_windows, window);
3906 gdk_window_remove_update_window (GdkWindow *window)
3908 update_windows = g_slist_remove (update_windows, window);
3912 gdk_window_paint_default_clock_updates (gpointer data)
3914 gdk_window_process_all_updates_internal (TRUE);
3918 gdk_ensure_default_frame_clock (void)
3920 if (_gdk_default_frame_clock == NULL)
3922 _gdk_default_frame_clock = g_object_new (GDK_TYPE_FRAME_CLOCK_IDLE,
3925 g_signal_connect (G_OBJECT (_gdk_default_frame_clock),
3927 G_CALLBACK (gdk_window_paint_default_clock_updates),
3933 gdk_window_is_toplevel_frozen (GdkWindow *window)
3935 GdkWindow *toplevel;
3937 toplevel = gdk_window_get_toplevel (window);
3939 return toplevel->update_and_descendants_freeze_count > 0;
3943 gdk_window_schedule_update (GdkWindow *window)
3946 (window->update_freeze_count ||
3947 gdk_window_is_toplevel_frozen (window)))
3950 gdk_frame_clock_request_phase (gdk_window_get_frame_clock (window),
3951 GDK_FRAME_CLOCK_PHASE_PAINT);
3955 _gdk_window_process_updates_recurse (GdkWindow *window,
3956 cairo_region_t *expose_region)
3959 cairo_region_t *clipped_expose_region;
3960 GdkRectangle clip_box;
3961 GList *l, *children;
3962 gboolean end_implicit;
3964 if (cairo_region_is_empty (expose_region))
3967 if (gdk_window_is_offscreen (window->impl_window) &&
3968 gdk_window_has_impl (window))
3969 _gdk_window_add_damage ((GdkWindow *) window->impl_window, expose_region);
3971 end_implicit = FALSE;
3972 if (window->alpha != 255 && !gdk_window_has_impl (window))
3974 if (window->alpha == 0)
3977 cairo_region_get_extents (expose_region, &clip_box);
3978 clip_box.x += window->abs_x;
3979 clip_box.y += window->abs_y;
3980 end_implicit = gdk_window_begin_implicit_paint (window->impl_window, &clip_box, TRUE, window->alpha);
3983 /* Paint the window before the children, clipped to the window region
3984 with visible child windows removed */
3985 clipped_expose_region = cairo_region_copy (expose_region);
3986 cairo_region_intersect (clipped_expose_region, window->clip_region_with_children);
3988 if (!cairo_region_is_empty (clipped_expose_region) &&
3991 if (window->event_mask & GDK_EXPOSURE_MASK)
3995 event.expose.type = GDK_EXPOSE;
3996 event.expose.window = g_object_ref (window);
3997 event.expose.send_event = FALSE;
3998 event.expose.count = 0;
3999 event.expose.region = clipped_expose_region;
4000 cairo_region_get_extents (clipped_expose_region, &event.expose.area);
4002 _gdk_event_emit (&event);
4004 g_object_unref (window);
4006 else if (window->window_type != GDK_WINDOW_FOREIGN)
4008 /* No exposure mask set, so nothing will be drawn, the
4009 * app relies on the background being what it specified
4010 * for the window. So, we need to clear this manually.
4012 * For foreign windows if expose is not set that generally
4013 * means some other client paints them, so don't clear
4016 * We use begin/end_paint around the clear so that we can
4017 * piggyback on the implicit paint */
4019 gdk_window_begin_paint_region (window, clipped_expose_region);
4020 /* The actual clear happens in begin_paint_region */
4021 gdk_window_end_paint (window);
4024 cairo_region_destroy (clipped_expose_region);
4026 /* Make this reentrancy safe for expose handlers freeing windows */
4027 children = g_list_copy (window->children);
4028 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4030 /* Iterate over children, starting at bottommost */
4031 for (l = g_list_last (children); l != NULL; l = l->prev)
4035 if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
4038 /* Ignore offscreen children, as they don't draw in their parent and
4039 * don't take part in the clipping */
4040 if (gdk_window_is_offscreen (child))
4043 /* Client side child, expose */
4044 if (child->impl == window->impl)
4046 cairo_region_translate (expose_region, -child->x, -child->y);
4047 _gdk_window_process_updates_recurse ((GdkWindow *)child, expose_region);
4048 cairo_region_translate (expose_region, child->x, child->y);
4052 g_list_free_full (children, g_object_unref);
4055 gdk_window_end_implicit_paint (window->impl_window);
4058 /* Process and remove any invalid area on the native window by creating
4059 * expose events for the window and all non-native descendants.
4060 * Also processes any outstanding moves on the window before doing
4061 * any drawing. Note that its possible to have outstanding moves without
4062 * any invalid area as we use the update idle mechanism to coalesce
4063 * multiple moves as well as multiple invalidations.
4066 gdk_window_process_updates_internal (GdkWindow *window)
4068 GdkWindowImplClass *impl_class;
4069 gboolean save_region = FALSE;
4070 GdkRectangle clip_box;
4072 /* Ensure the window lives while updating it */
4073 g_object_ref (window);
4075 /* If an update got queued during update processing, we can get a
4076 * window in the update queue that has an empty update_area.
4079 if (window->update_area)
4081 cairo_region_t *update_area = window->update_area;
4082 window->update_area = NULL;
4084 if (gdk_window_is_viewable (window))
4086 cairo_region_t *expose_region;
4087 gboolean end_implicit;
4089 /* Clip to part visible in toplevel */
4090 cairo_region_intersect (update_area, window->clip_region);
4094 /* Make sure we see the red invalid area before redrawing. */
4095 gdk_display_sync (gdk_window_get_display (window));
4099 /* At this point we will be completely redrawing all of update_area.
4100 * If we have any outstanding moves that end up moving stuff inside
4101 * this area we don't actually need to move that as that part would
4102 * be overdrawn by the expose anyway. So, in order to copy less data
4103 * we remove these areas from the outstanding moves.
4105 if (window->outstanding_moves)
4107 GdkWindowRegionMove *move;
4108 cairo_region_t *remove;
4111 remove = cairo_region_copy (update_area);
4112 /* We iterate backwards, starting from the state that would be
4113 if we had applied all the moves. */
4114 for (l = g_list_last (window->outstanding_moves); l != NULL; l = prev)
4119 /* Don't need this area */
4120 cairo_region_subtract (move->dest_region, remove);
4122 /* However if any of the destination we do need has a source
4123 in the updated region we do need that as a destination for
4124 the earlier moves */
4125 cairo_region_translate (move->dest_region, -move->dx, -move->dy);
4126 cairo_region_subtract (remove, move->dest_region);
4128 if (cairo_region_is_empty (move->dest_region))
4130 gdk_window_region_move_free (move);
4131 window->outstanding_moves =
4132 g_list_delete_link (window->outstanding_moves, l);
4134 else /* move back */
4135 cairo_region_translate (move->dest_region, move->dx, move->dy);
4137 cairo_region_destroy (remove);
4140 /* By now we a set of window moves that should be applied, and then
4141 * an update region that should be repainted. A trivial implementation
4142 * would just do that in order, however in order to get nicer drawing
4143 * we do some tricks:
4145 * First of all, each subwindow expose may be double buffered by
4146 * itself (depending on widget setting) via
4147 * gdk_window_begin/end_paint(). But we also do an "implicit" paint,
4148 * creating a single surface the size of the invalid area on the
4149 * native window which all the individual normal paints will draw
4150 * into. This way in the normal case there will be only one surface
4151 * allocated and only once surface draw done for all the windows
4152 * in this native window.
4153 * There are a couple of reasons this may fail, for instance, some
4154 * backends (like quartz) do its own double buffering, so we disable
4155 * gdk double buffering there. Secondly, some subwindow could be
4156 * non-double buffered and draw directly to the window outside a
4157 * begin/end_paint pair. That will be lead to a gdk_window_flush
4158 * which immediately executes all outstanding moves and paints+removes
4159 * the implicit paint (further paints will allocate their own surfaces).
4161 * Secondly, in the case of implicit double buffering we expose all
4162 * the child windows into the implicit surface before we execute
4163 * the outstanding moves. This way we minimize the time between
4164 * doing the moves and rendering the new update area, thus minimizing
4165 * flashing. Of course, if any subwindow is non-double buffered we
4166 * well flush earlier than that.
4168 * Thirdly, after having done the outstanding moves we queue an
4169 * "antiexpose" on the area that will be drawn by the expose, which
4170 * means that any invalid region on the native window side before
4171 * the first expose drawing operation will be discarded, as it
4172 * has by then been overdrawn with valid data. This means we can
4173 * avoid doing the unnecessary repaint any outstanding expose events.
4176 cairo_region_get_extents (update_area, &clip_box);
4177 end_implicit = gdk_window_begin_implicit_paint (window, &clip_box, FALSE, 255);
4178 expose_region = cairo_region_copy (update_area);
4179 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
4182 /* Rendering is not double buffered by gdk, do outstanding
4183 * moves and queue antiexposure immediately. No need to do
4185 gdk_window_flush_outstanding_moves (window);
4186 save_region = impl_class->queue_antiexpose (window, update_area);
4188 /* Render the invalid areas to the implicit paint, by sending exposes.
4189 * May flush if non-double buffered widget draw. */
4190 impl_class->process_updates_recurse (window, expose_region);
4194 /* Do moves right before exposes are rendered to the window */
4195 gdk_window_flush_outstanding_moves (window);
4197 /* By this time we know that any outstanding expose for this
4198 * area is invalid and we can avoid it, so queue an antiexpose.
4199 * we have already started drawing to the window, so it would
4200 * be to late to anti-expose now. Since this is merely an
4201 * optimization we just avoid doing it at all in that case.
4203 if (window->implicit_paint != NULL && !((GdkWindowPaint *)window->implicit_paint->data)->flushed)
4204 save_region = impl_class->queue_antiexpose (window, update_area);
4206 gdk_window_end_implicit_paint (window);
4208 cairo_region_destroy (expose_region);
4211 cairo_region_destroy (update_area);
4214 if (window->outstanding_moves)
4216 /* Flush any outstanding moves, may happen if we moved a window but got
4217 no actual invalid area */
4218 gdk_window_flush_outstanding_moves (window);
4221 g_object_unref (window);
4225 flush_all_displays (void)
4227 GSList *displays, *l;
4229 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4230 for (l = displays; l; l = l->next)
4231 gdk_display_flush (l->data);
4233 g_slist_free (displays);
4237 before_process_all_updates (void)
4239 GSList *displays, *l;
4240 GdkDisplayClass *display_class;
4242 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4243 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4244 for (l = displays; l; l = l->next)
4245 display_class->before_process_all_updates (l->data);
4247 g_slist_free (displays);
4251 after_process_all_updates (void)
4253 GSList *displays, *l;
4254 GdkDisplayClass *display_class;
4256 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
4257 display_class = GDK_DISPLAY_GET_CLASS (displays->data);
4258 for (l = displays; l; l = l->next)
4259 display_class->after_process_all_updates (l->data);
4261 g_slist_free (displays);
4265 * gdk_window_process_all_updates:
4267 * Calls gdk_window_process_updates() for all windows (see #GdkWindow)
4268 * in the application.
4272 gdk_window_process_all_updates (void)
4274 gdk_window_process_all_updates_internal (FALSE);
4277 /* Currently it is not possible to override
4278 * gdk_window_process_all_updates in the same manner as
4279 * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
4280 * by implementing the GdkPaintable interface. If in the future a
4281 * backend would need this, the right solution would be to add a
4282 * method to GdkDisplay that can be optionally
4283 * NULL. gdk_window_process_all_updates can then walk the list of open
4284 * displays and call the mehod.
4288 gdk_window_process_all_updates_internal (gboolean default_clock_only)
4290 GSList *old_update_windows = update_windows;
4291 GSList *tmp_list = update_windows;
4292 static gboolean in_process_all_updates = FALSE;
4293 static gboolean got_recursive_update = FALSE;
4295 if (in_process_all_updates)
4297 /* We can't do this now since that would recurse, so
4298 delay it until after the recursion is done. */
4299 got_recursive_update = TRUE;
4303 in_process_all_updates = TRUE;
4304 got_recursive_update = FALSE;
4306 update_windows = NULL;
4308 before_process_all_updates ();
4310 g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
4314 GdkWindow *window = tmp_list->data;
4316 if (!GDK_WINDOW_DESTROYED (window))
4318 if (window->update_freeze_count ||
4319 gdk_window_is_toplevel_frozen (window) ||
4320 (default_clock_only && window->frame_clock != NULL))
4321 gdk_window_add_update_window (window);
4323 gdk_window_process_updates_internal (window);
4326 g_object_unref (window);
4327 tmp_list = tmp_list->next;
4330 g_slist_free (old_update_windows);
4332 flush_all_displays ();
4334 after_process_all_updates ();
4336 in_process_all_updates = FALSE;
4338 /* If we ignored a recursive call, schedule a
4339 redraw now so that it eventually happens,
4340 otherwise we could miss an update if nothing
4341 else schedules an update. */
4342 if (got_recursive_update)
4343 gdk_window_schedule_update (NULL);
4348 PROCESS_UPDATES_NO_RECURSE,
4349 PROCESS_UPDATES_WITH_ALL_CHILDREN,
4350 PROCESS_UPDATES_WITH_SAME_CLOCK_CHILDREN
4354 gdk_window_process_updates_with_mode (GdkWindow *window,
4357 GdkWindow *impl_window;
4359 g_return_if_fail (GDK_IS_WINDOW (window));
4361 if (GDK_WINDOW_DESTROYED (window))
4364 /* Make sure the window lives during the expose callouts */
4365 g_object_ref (window);
4367 impl_window = gdk_window_get_impl_window (window);
4368 if ((impl_window->update_area ||
4369 impl_window->outstanding_moves) &&
4370 !impl_window->update_freeze_count &&
4371 !gdk_window_is_toplevel_frozen (window) &&
4373 /* Don't recurse into process_updates_internal, we'll
4374 * do the update later when idle instead. */
4375 impl_window->implicit_paint == NULL)
4377 gdk_window_process_updates_internal ((GdkWindow *)impl_window);
4378 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4381 if (recurse_mode != PROCESS_UPDATES_NO_RECURSE)
4383 /* process updates in reverse stacking order so composition or
4384 * painting over achieves the desired effect for offscreen windows
4386 GList *node, *children;
4388 children = g_list_copy (window->children);
4389 g_list_foreach (children, (GFunc)g_object_ref, NULL);
4391 for (node = g_list_last (children); node; node = node->prev)
4393 GdkWindow *child = node->data;
4394 if (recurse_mode == PROCESS_UPDATES_WITH_ALL_CHILDREN ||
4395 (recurse_mode == PROCESS_UPDATES_WITH_SAME_CLOCK_CHILDREN &&
4396 child->frame_clock == NULL))
4398 gdk_window_process_updates (child, TRUE);
4400 g_object_unref (child);
4403 g_list_free (children);
4406 g_object_unref (window);
4410 * gdk_window_process_updates:
4411 * @window: a #GdkWindow
4412 * @update_children: whether to also process updates for child windows
4414 * Sends one or more expose events to @window. The areas in each
4415 * expose event will cover the entire update area for the window (see
4416 * gdk_window_invalidate_region() for details). Normally GDK calls
4417 * gdk_window_process_all_updates() on your behalf, so there's no
4418 * need to call this function unless you want to force expose events
4419 * to be delivered immediately and synchronously (vs. the usual
4420 * case, where GDK delivers them in an idle handler). Occasionally
4421 * this is useful to produce nicer scrolling behavior, for example.
4425 gdk_window_process_updates (GdkWindow *window,
4426 gboolean update_children)
4428 g_return_if_fail (GDK_IS_WINDOW (window));
4430 return gdk_window_process_updates_with_mode (window,
4432 PROCESS_UPDATES_WITH_ALL_CHILDREN :
4433 PROCESS_UPDATES_NO_RECURSE);
4437 gdk_window_invalidate_rect_full (GdkWindow *window,
4438 const GdkRectangle *rect,
4439 gboolean invalidate_children,
4442 GdkRectangle window_rect;
4443 cairo_region_t *region;
4445 g_return_if_fail (GDK_IS_WINDOW (window));
4447 if (GDK_WINDOW_DESTROYED (window))
4450 if (window->input_only || !window->viewable)
4457 window_rect.width = window->width;
4458 window_rect.height = window->height;
4459 rect = &window_rect;
4462 region = cairo_region_create_rectangle (rect);
4463 gdk_window_invalidate_region_full (window, region, invalidate_children, clear_bg);
4464 cairo_region_destroy (region);
4468 * gdk_window_invalidate_rect:
4469 * @window: a #GdkWindow
4470 * @rect: (allow-none): rectangle to invalidate or %NULL to invalidate the whole
4472 * @invalidate_children: whether to also invalidate child windows
4474 * A convenience wrapper around gdk_window_invalidate_region() which
4475 * invalidates a rectangular region. See
4476 * gdk_window_invalidate_region() for details.
4479 gdk_window_invalidate_rect (GdkWindow *window,
4480 const GdkRectangle *rect,
4481 gboolean invalidate_children)
4483 gdk_window_invalidate_rect_full (window, rect, invalidate_children, CLEAR_BG_NONE);
4487 draw_ugly_color (GdkWindow *window,
4488 const cairo_region_t *region)
4492 cr = gdk_cairo_create (window);
4493 /* Draw ugly color all over the newly-invalid region */
4494 cairo_set_source_rgb (cr, 50000/65535., 10000/65535., 10000/65535.);
4495 gdk_cairo_region (cr, region);
4502 impl_window_add_update_area (GdkWindow *impl_window,
4503 cairo_region_t *region)
4505 if (impl_window->update_area)
4506 cairo_region_union (impl_window->update_area, region);
4509 gdk_window_add_update_window (impl_window);
4510 impl_window->update_area = cairo_region_copy (region);
4511 gdk_window_schedule_update (impl_window);
4515 /* clear_bg controls if the region will be cleared to
4516 * the background pattern if the exposure mask is not
4517 * set for the window, whereas this might not otherwise be
4518 * done (unless necessary to emulate background settings).
4519 * Set this to CLEAR_BG_WINCLEARED or CLEAR_BG_ALL if you
4520 * need to clear the background, such as when exposing the area beneath a
4521 * hidden or moved window, but not when an app requests repaint or when the
4522 * windowing system exposes a newly visible area (because then the windowing
4523 * system has already cleared the area).
4526 gdk_window_invalidate_maybe_recurse_full (GdkWindow *window,
4527 const cairo_region_t *region,
4529 GdkWindowChildFunc child_func,
4532 GdkWindow *impl_window;
4533 cairo_region_t *visible_region;
4536 g_return_if_fail (GDK_IS_WINDOW (window));
4538 if (GDK_WINDOW_DESTROYED (window))
4541 if (window->input_only ||
4542 !window->viewable ||
4543 cairo_region_is_empty (region) ||
4544 window->window_type == GDK_WINDOW_ROOT)
4547 visible_region = gdk_window_get_visible_region (window);
4548 cairo_region_intersect (visible_region, region);
4550 tmp_list = window->children;
4553 GdkWindow *child = tmp_list->data;
4555 if (!child->input_only)
4557 cairo_region_t *child_region;
4558 GdkRectangle child_rect;
4560 child_rect.x = child->x;
4561 child_rect.y = child->y;
4562 child_rect.width = child->width;
4563 child_rect.height = child->height;
4564 child_region = cairo_region_create_rectangle (&child_rect);
4566 /* remove child area from the invalid area of the parent */
4567 if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped &&
4568 !child->composited &&
4569 !gdk_window_is_offscreen (child))
4570 cairo_region_subtract (visible_region, child_region);
4572 if (child_func && (*child_func) ((GdkWindow *)child, user_data))
4574 cairo_region_t *tmp = cairo_region_copy (region);
4576 cairo_region_translate (tmp, - child_rect.x, - child_rect.y);
4577 cairo_region_translate (child_region, - child_rect.x, - child_rect.y);
4578 cairo_region_intersect (child_region, tmp);
4580 gdk_window_invalidate_maybe_recurse_full ((GdkWindow *)child,
4581 child_region, clear_bg, child_func, user_data);
4583 cairo_region_destroy (tmp);
4586 cairo_region_destroy (child_region);
4589 tmp_list = tmp_list->next;
4592 impl_window = gdk_window_get_impl_window (window);
4594 if (!cairo_region_is_empty (visible_region) ||
4595 /* Even if we're not exposing anything, make sure we process
4596 idles for windows with outstanding moves */
4597 (impl_window->outstanding_moves != NULL &&
4598 impl_window->update_area == NULL))
4601 draw_ugly_color (window, region);
4603 /* Convert to impl coords */
4604 cairo_region_translate (visible_region, window->abs_x, window->abs_y);
4606 /* Only invalidate area if app requested expose events or if
4607 we need to clear the area (by request or to emulate background
4608 clearing for non-native windows or native windows with no support
4609 for window backgrounds */
4610 if (window->event_mask & GDK_EXPOSURE_MASK ||
4611 clear_bg == CLEAR_BG_ALL ||
4612 clear_bg == CLEAR_BG_WINCLEARED)
4613 impl_window_add_update_area (impl_window, visible_region);
4616 cairo_region_destroy (visible_region);
4620 * gdk_window_invalidate_maybe_recurse:
4621 * @window: a #GdkWindow
4622 * @region: a #cairo_region_t
4623 * @child_func: (scope call) (allow-none): function to use to decide if to
4624 * recurse to a child, %NULL means never recurse.
4625 * @user_data: data passed to @child_func
4627 * Adds @region to the update area for @window. The update area is the
4628 * region that needs to be redrawn, or "dirty region." The call
4629 * gdk_window_process_updates() sends one or more expose events to the
4630 * window, which together cover the entire update area. An
4631 * application would normally redraw the contents of @window in
4632 * response to those expose events.
4634 * GDK will call gdk_window_process_all_updates() on your behalf
4635 * whenever your program returns to the main loop and becomes idle, so
4636 * normally there's no need to do that manually, you just need to
4637 * invalidate regions that you know should be redrawn.
4639 * The @child_func parameter controls whether the region of
4640 * each child window that intersects @region will also be invalidated.
4641 * Only children for which @child_func returns TRUE will have the area
4645 gdk_window_invalidate_maybe_recurse (GdkWindow *window,
4646 const cairo_region_t *region,
4647 GdkWindowChildFunc child_func,
4650 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_NONE,
4651 child_func, user_data);
4655 true_predicate (GdkWindow *window,
4662 gdk_window_invalidate_region_full (GdkWindow *window,
4663 const cairo_region_t *region,
4664 gboolean invalidate_children,
4667 gdk_window_invalidate_maybe_recurse_full (window, region, clear_bg,
4668 invalidate_children ?
4669 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4674 * gdk_window_invalidate_region:
4675 * @window: a #GdkWindow
4676 * @region: a #cairo_region_t
4677 * @invalidate_children: %TRUE to also invalidate child windows
4679 * Adds @region to the update area for @window. The update area is the
4680 * region that needs to be redrawn, or "dirty region." The call
4681 * gdk_window_process_updates() sends one or more expose events to the
4682 * window, which together cover the entire update area. An
4683 * application would normally redraw the contents of @window in
4684 * response to those expose events.
4686 * GDK will call gdk_window_process_all_updates() on your behalf
4687 * whenever your program returns to the main loop and becomes idle, so
4688 * normally there's no need to do that manually, you just need to
4689 * invalidate regions that you know should be redrawn.
4691 * The @invalidate_children parameter controls whether the region of
4692 * each child window that intersects @region will also be invalidated.
4693 * If %FALSE, then the update area for child windows will remain
4694 * unaffected. See gdk_window_invalidate_maybe_recurse if you need
4695 * fine grained control over which children are invalidated.
4698 gdk_window_invalidate_region (GdkWindow *window,
4699 const cairo_region_t *region,
4700 gboolean invalidate_children)
4702 gdk_window_invalidate_maybe_recurse (window, region,
4703 invalidate_children ?
4704 true_predicate : (gboolean (*) (GdkWindow *, gpointer))NULL,
4709 * _gdk_window_invalidate_for_expose:
4710 * @window: a #GdkWindow
4711 * @region: a #cairo_region_t
4713 * Adds @region to the update area for @window. The update area is the
4714 * region that needs to be redrawn, or "dirty region." The call
4715 * gdk_window_process_updates() sends one or more expose events to the
4716 * window, which together cover the entire update area. An
4717 * application would normally redraw the contents of @window in
4718 * response to those expose events.
4720 * GDK will call gdk_window_process_all_updates() on your behalf
4721 * whenever your program returns to the main loop and becomes idle, so
4722 * normally there's no need to do that manually, you just need to
4723 * invalidate regions that you know should be redrawn.
4725 * This version of invalidation is used when you recieve expose events
4726 * from the native window system. It exposes the native window, plus
4727 * any non-native child windows (but not native child windows, as those would
4728 * have gotten their own expose events).
4731 _gdk_window_invalidate_for_expose (GdkWindow *window,
4732 cairo_region_t *region)
4734 GdkWindowRegionMove *move;
4735 cairo_region_t *move_region;
4738 /* Any invalidations comming from the windowing system will
4739 be in areas that may be moved by outstanding moves,
4740 so we need to modify the expose region correspondingly,
4741 otherwise we would expose in the wrong place, as the
4742 outstanding moves will be copied before we draw the
4744 for (l = window->outstanding_moves; l != NULL; l = l->next)
4748 /* covert to move source region */
4749 move_region = cairo_region_copy (move->dest_region);
4750 cairo_region_translate (move_region, -move->dx, -move->dy);
4752 /* Move area of region that intersects with move source
4753 by dx, dy of the move*/
4754 cairo_region_intersect (move_region, region);
4755 cairo_region_subtract (region, move_region);
4756 cairo_region_translate (move_region, move->dx, move->dy);
4757 cairo_region_union (region, move_region);
4759 cairo_region_destroy (move_region);
4762 gdk_window_invalidate_maybe_recurse_full (window, region, CLEAR_BG_WINCLEARED,
4763 (gboolean (*) (GdkWindow *, gpointer))gdk_window_has_no_impl,
4769 * gdk_window_get_update_area:
4770 * @window: a #GdkWindow
4772 * Transfers ownership of the update area from @window to the caller
4773 * of the function. That is, after calling this function, @window will
4774 * no longer have an invalid/dirty region; the update area is removed
4775 * from @window and handed to you. If a window has no update area,
4776 * gdk_window_get_update_area() returns %NULL. You are responsible for
4777 * calling cairo_region_destroy() on the returned region if it's non-%NULL.
4779 * Return value: the update area for @window
4782 gdk_window_get_update_area (GdkWindow *window)
4784 GdkWindow *impl_window;
4785 cairo_region_t *tmp_region, *to_remove;
4787 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4789 impl_window = gdk_window_get_impl_window (window);
4791 if (impl_window->update_area)
4793 tmp_region = cairo_region_copy (window->clip_region_with_children);
4794 /* Convert to impl coords */
4795 cairo_region_translate (tmp_region, window->abs_x, window->abs_y);
4796 cairo_region_intersect (tmp_region, impl_window->update_area);
4798 if (cairo_region_is_empty (tmp_region))
4800 cairo_region_destroy (tmp_region);
4805 /* Convert from impl coords */
4806 cairo_region_translate (tmp_region, -window->abs_x, -window->abs_y);
4808 /* Don't remove any update area that is overlapped by non-opaque windows
4809 (children or siblings) with alpha, as these really need to be repainted
4810 independently of this window. */
4811 to_remove = cairo_region_copy (tmp_region);
4812 cairo_region_subtract (to_remove, window->parent->layered_region);
4813 remove_layered_child_area (window, to_remove);
4815 /* Remove from update_area */
4816 cairo_region_translate (to_remove, window->abs_x, window->abs_y);
4817 cairo_region_subtract (impl_window->update_area, to_remove);
4819 cairo_region_destroy (to_remove);
4821 if (cairo_region_is_empty (impl_window->update_area) &&
4822 impl_window->outstanding_moves == NULL)
4824 cairo_region_destroy (impl_window->update_area);
4825 impl_window->update_area = NULL;
4827 gdk_window_remove_update_window ((GdkWindow *)impl_window);
4838 * _gdk_window_clear_update_area:
4839 * @window: a #GdkWindow.
4841 * Internal function to clear the update area for a window. This
4842 * is called when the window is hidden or destroyed.
4845 _gdk_window_clear_update_area (GdkWindow *window)
4847 g_return_if_fail (GDK_IS_WINDOW (window));
4849 if (window->update_area)
4851 gdk_window_remove_update_window (window);
4853 cairo_region_destroy (window->update_area);
4854 window->update_area = NULL;
4859 * gdk_window_freeze_updates:
4860 * @window: a #GdkWindow
4862 * Temporarily freezes a window such that it won't receive expose
4863 * events. The window will begin receiving expose events again when
4864 * gdk_window_thaw_updates() is called. If gdk_window_freeze_updates()
4865 * has been called more than once, gdk_window_thaw_updates() must be called
4866 * an equal number of times to begin processing exposes.
4869 gdk_window_freeze_updates (GdkWindow *window)
4871 GdkWindow *impl_window;
4873 g_return_if_fail (GDK_IS_WINDOW (window));
4875 impl_window = gdk_window_get_impl_window (window);
4876 impl_window->update_freeze_count++;
4880 * gdk_window_thaw_updates:
4881 * @window: a #GdkWindow
4883 * Thaws a window frozen with gdk_window_freeze_updates().
4886 gdk_window_thaw_updates (GdkWindow *window)
4888 GdkWindow *impl_window;
4890 g_return_if_fail (GDK_IS_WINDOW (window));
4892 impl_window = gdk_window_get_impl_window (window);
4894 g_return_if_fail (impl_window->update_freeze_count > 0);
4896 if (--impl_window->update_freeze_count == 0)
4897 gdk_window_schedule_update (GDK_WINDOW (impl_window));
4901 * gdk_window_freeze_toplevel_updates_libgtk_only:
4902 * @window: a #GdkWindow
4904 * Temporarily freezes a window and all its descendants such that it won't
4905 * receive expose events. The window will begin receiving expose events
4906 * again when gdk_window_thaw_toplevel_updates_libgtk_only() is called. If
4907 * gdk_window_freeze_toplevel_updates_libgtk_only()
4908 * has been called more than once,
4909 * gdk_window_thaw_toplevel_updates_libgtk_only() must be called
4910 * an equal number of times to begin processing exposes.
4912 * This function is not part of the GDK public API and is only
4916 gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window)
4918 g_return_if_fail (GDK_IS_WINDOW (window));
4919 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4921 window->update_and_descendants_freeze_count++;
4922 gdk_frame_clock_freeze (gdk_window_get_frame_clock (window));
4926 * gdk_window_thaw_toplevel_updates_libgtk_only:
4927 * @window: a #GdkWindow
4929 * Thaws a window frozen with
4930 * gdk_window_freeze_toplevel_updates_libgtk_only().
4932 * This function is not part of the GDK public API and is only
4936 gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window)
4938 g_return_if_fail (GDK_IS_WINDOW (window));
4939 g_return_if_fail (window->window_type != GDK_WINDOW_CHILD);
4940 g_return_if_fail (window->update_and_descendants_freeze_count > 0);
4942 window->update_and_descendants_freeze_count--;
4943 gdk_frame_clock_thaw (gdk_window_get_frame_clock (window));
4945 gdk_window_schedule_update (window);
4949 * gdk_window_set_debug_updates:
4950 * @setting: %TRUE to turn on update debugging
4952 * With update debugging enabled, calls to
4953 * gdk_window_invalidate_region() clear the invalidated region of the
4954 * screen to a noticeable color, and GDK pauses for a short time
4955 * before sending exposes to windows during
4956 * gdk_window_process_updates(). The net effect is that you can see
4957 * the invalid region for each window and watch redraws as they
4958 * occur. This allows you to diagnose inefficiencies in your application.
4960 * In essence, because the GDK rendering model prevents all flicker,
4961 * if you are redrawing the same region 400 times you may never
4962 * notice, aside from noticing a speed problem. Enabling update
4963 * debugging causes GTK to flicker slowly and noticeably, so you can
4964 * see exactly what's being redrawn when, in what order.
4966 * The --gtk-debug=updates command line option passed to GTK+ programs
4967 * enables this debug option at application startup time. That's
4968 * usually more useful than calling gdk_window_set_debug_updates()
4969 * yourself, though you might want to use this function to enable
4970 * updates sometime after application startup time.
4974 gdk_window_set_debug_updates (gboolean setting)
4976 debug_updates = setting;
4980 * gdk_window_constrain_size:
4981 * @geometry: a #GdkGeometry structure
4982 * @flags: a mask indicating what portions of @geometry are set
4983 * @width: desired width of window
4984 * @height: desired height of the window
4985 * @new_width: (out): location to store resulting width
4986 * @new_height: (out): location to store resulting height
4988 * Constrains a desired width and height according to a
4989 * set of geometry hints (such as minimum and maximum size).
4992 gdk_window_constrain_size (GdkGeometry *geometry,
4999 /* This routine is partially borrowed from fvwm.
5001 * Copyright 1993, Robert Nation
5002 * You may use this code for any purpose, as long as the original
5003 * copyright remains in the source code and all documentation
5005 * which in turn borrows parts of the algorithm from uwm
5008 gint min_height = 0;
5009 gint base_width = 0;
5010 gint base_height = 0;
5013 gint max_width = G_MAXINT;
5014 gint max_height = G_MAXINT;
5016 #define FLOOR(value, base) ( ((gint) ((value) / (base))) * (base) )
5018 if ((flags & GDK_HINT_BASE_SIZE) && (flags & GDK_HINT_MIN_SIZE))
5020 base_width = geometry->base_width;
5021 base_height = geometry->base_height;
5022 min_width = geometry->min_width;
5023 min_height = geometry->min_height;
5025 else if (flags & GDK_HINT_BASE_SIZE)
5027 base_width = geometry->base_width;
5028 base_height = geometry->base_height;
5029 min_width = geometry->base_width;
5030 min_height = geometry->base_height;
5032 else if (flags & GDK_HINT_MIN_SIZE)
5034 base_width = geometry->min_width;
5035 base_height = geometry->min_height;
5036 min_width = geometry->min_width;
5037 min_height = geometry->min_height;
5040 if (flags & GDK_HINT_MAX_SIZE)
5042 max_width = geometry->max_width ;
5043 max_height = geometry->max_height;
5046 if (flags & GDK_HINT_RESIZE_INC)
5048 xinc = MAX (xinc, geometry->width_inc);
5049 yinc = MAX (yinc, geometry->height_inc);
5052 /* clamp width and height to min and max values
5054 width = CLAMP (width, min_width, max_width);
5055 height = CLAMP (height, min_height, max_height);
5057 /* shrink to base + N * inc
5059 width = base_width + FLOOR (width - base_width, xinc);
5060 height = base_height + FLOOR (height - base_height, yinc);
5062 /* constrain aspect ratio, according to:
5065 * min_aspect <= -------- <= max_aspect
5069 if (flags & GDK_HINT_ASPECT &&
5070 geometry->min_aspect > 0 &&
5071 geometry->max_aspect > 0)
5075 if (geometry->min_aspect * height > width)
5077 delta = FLOOR (height - width / geometry->min_aspect, yinc);
5078 if (height - delta >= min_height)
5082 delta = FLOOR (height * geometry->min_aspect - width, xinc);
5083 if (width + delta <= max_width)
5088 if (geometry->max_aspect * height < width)
5090 delta = FLOOR (width - height * geometry->max_aspect, xinc);
5091 if (width - delta >= min_width)
5095 delta = FLOOR (width / geometry->max_aspect - height, yinc);
5096 if (height + delta <= max_height)
5105 *new_height = height;
5109 * gdk_window_get_pointer:
5110 * @window: a #GdkWindow
5111 * @x: (out) (allow-none): return location for X coordinate of pointer or %NULL to not
5112 * return the X coordinate
5113 * @y: (out) (allow-none): return location for Y coordinate of pointer or %NULL to not
5114 * return the Y coordinate
5115 * @mask: (out) (allow-none): return location for modifier mask or %NULL to not return the
5118 * Obtains the current pointer position and modifier state.
5119 * The position is given in coordinates relative to the upper left
5120 * corner of @window.
5122 * Return value: (transfer none): the window containing the pointer (as with
5123 * gdk_window_at_pointer()), or %NULL if the window containing the
5124 * pointer isn't known to GDK
5126 * Deprecated: 3.0: Use gdk_window_get_device_position() instead.
5129 gdk_window_get_pointer (GdkWindow *window,
5132 GdkModifierType *mask)
5134 GdkDisplay *display;
5136 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5138 display = gdk_window_get_display (window);
5140 return gdk_window_get_device_position (window, display->core_pointer, x, y, mask);
5144 * gdk_window_get_device_position:
5145 * @window: a #GdkWindow.
5146 * @device: pointer #GdkDevice to query to.
5147 * @x: (out) (allow-none): return location for the X coordinate of @device, or %NULL.
5148 * @y: (out) (allow-none): return location for the Y coordinate of @device, or %NULL.
5149 * @mask: (out) (allow-none): return location for the modifier mask, or %NULL.
5151 * Obtains the current device position and modifier state.
5152 * The position is given in coordinates relative to the upper left
5153 * corner of @window.
5155 * Return value: (transfer none): The window underneath @device (as with
5156 * gdk_device_get_window_at_position()), or %NULL if the window is not known to GDK.
5161 gdk_window_get_device_position (GdkWindow *window,
5165 GdkModifierType *mask)
5168 GdkModifierType tmp_mask;
5169 gboolean normal_child;
5171 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
5172 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
5173 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
5175 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
5179 /* We got the coords on the impl, convert to the window */
5180 tmp_x -= window->abs_x;
5181 tmp_y -= window->abs_y;
5190 _gdk_display_enable_motion_hints (gdk_window_get_display (window), device);
5193 return _gdk_window_find_child_at (window, tmp_x, tmp_y);
5198 * gdk_get_default_root_window:
5200 * Obtains the root window (parent all other windows are inside)
5201 * for the default display and screen.
5203 * Return value: (transfer none): the default root window
5206 gdk_get_default_root_window (void)
5208 return gdk_screen_get_root_window (gdk_screen_get_default ());
5212 get_all_native_children (GdkWindow *window,
5218 for (l = window->children; l != NULL; l = l->next)
5222 if (gdk_window_has_impl (child))
5223 *native = g_list_prepend (*native, child);
5225 get_all_native_children (child, native);
5231 gdk_window_raise_internal (GdkWindow *window)
5233 GdkWindow *parent = window->parent;
5235 GList *native_children;
5237 GdkWindowImplClass *impl_class;
5241 parent->children = g_list_remove (parent->children, window);
5242 parent->children = g_list_prepend (parent->children, window);
5245 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5246 /* Just do native raise for toplevels */
5247 if (gdk_window_is_toplevel (window) ||
5248 /* The restack_under codepath should work correctly even if the parent
5249 is native, but it relies on the order of ->children to be correct,
5250 and some apps like SWT reorder the x windows without gdks knowledge,
5251 so we use raise directly in order to make these behave as before
5252 when using native windows */
5253 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5255 impl_class->raise (window);
5257 else if (gdk_window_has_impl (window))
5259 above = find_native_sibling_above (parent, window);
5262 listhead.data = window;
5263 listhead.next = NULL;
5264 listhead.prev = NULL;
5265 impl_class->restack_under ((GdkWindow *)above,
5269 impl_class->raise (window);
5273 native_children = NULL;
5274 get_all_native_children (window, &native_children);
5275 if (native_children != NULL)
5277 above = find_native_sibling_above (parent, window);
5280 impl_class->restack_under (above, native_children);
5283 /* Right order, since native_children is bottom-topmost first */
5284 for (l = native_children; l != NULL; l = l->next)
5285 impl_class->raise (l->data);
5288 g_list_free (native_children);
5294 /* Returns TRUE If the native window was mapped or unmapped */
5296 set_viewable (GdkWindow *w,
5300 GdkWindowImplClass *impl_class;
5303 if (w->viewable == val)
5309 recompute_visible_regions (w, FALSE, FALSE);
5311 for (l = w->children; l != NULL; l = l->next)
5315 if (GDK_WINDOW_IS_MAPPED (child) &&
5316 child->window_type != GDK_WINDOW_FOREIGN)
5317 set_viewable (child, val);
5320 if (gdk_window_has_impl (w) &&
5321 w->window_type != GDK_WINDOW_FOREIGN &&
5322 !gdk_window_is_toplevel (w))
5324 /* For most native windows we show/hide them not when they are
5325 * mapped/unmapped, because that may not produce the correct results.
5326 * For instance, if a native window have a non-native parent which is
5327 * hidden, but its native parent is viewable then showing the window
5328 * would make it viewable to X but its not viewable wrt the non-native
5329 * hierarchy. In order to handle this we track the gdk side viewability
5330 * and only map really viewable windows.
5332 * There are two exceptions though:
5334 * For foreign windows we don't want ever change the mapped state
5335 * except when explicitly done via gdk_window_show/hide, as this may
5336 * cause problems for client owning the foreign window when its window
5337 * is suddenly mapped or unmapped.
5339 * For toplevel windows embedded in a foreign window (e.g. a plug)
5340 * we sometimes synthesize a map of a window, but the native
5341 * window is really shown by the embedder, so we don't want to
5342 * do the show ourselves. We can't really tell this case from the normal
5343 * toplevel show as such toplevels are seen by gdk as parents of the
5344 * root window, so we make an exception for all toplevels.
5347 impl_class = GDK_WINDOW_IMPL_GET_CLASS (w->impl);
5349 impl_class->show ((GdkWindow *)w, FALSE);
5351 impl_class->hide ((GdkWindow *)w);
5359 /* Returns TRUE If the native window was mapped or unmapped */
5361 _gdk_window_update_viewable (GdkWindow *window)
5365 if (window->window_type == GDK_WINDOW_FOREIGN ||
5366 window->window_type == GDK_WINDOW_ROOT)
5368 else if (gdk_window_is_toplevel (window) ||
5369 window->parent->viewable)
5370 viewable = GDK_WINDOW_IS_MAPPED (window);
5374 return set_viewable (window, viewable);
5378 gdk_window_show_internal (GdkWindow *window, gboolean raise)
5380 GdkWindowImplClass *impl_class;
5381 gboolean was_mapped, was_viewable;
5384 g_return_if_fail (GDK_IS_WINDOW (window));
5386 if (window->destroyed)
5389 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5390 was_viewable = window->viewable;
5393 /* Keep children in (reverse) stacking order */
5394 gdk_window_raise_internal (window);
5396 if (gdk_window_has_impl (window))
5399 gdk_synthesize_window_state (window,
5400 GDK_WINDOW_STATE_WITHDRAWN,
5401 GDK_WINDOW_STATE_FOCUSED);
5408 did_show = _gdk_window_update_viewable (window);
5410 /* If it was already viewable the backend show op won't be called, call it
5411 again to ensure things happen right if the mapped tracking was not right
5412 for e.g. a foreign window.
5413 Dunno if this is strictly needed but its what happened pre-csw.
5414 Also show if not done by gdk_window_update_viewable. */
5415 if (gdk_window_has_impl (window) && (was_viewable || !did_show))
5417 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5418 impl_class->show (window, !did_show ? was_mapped : TRUE);
5421 if (!was_mapped && !gdk_window_has_impl (window))
5423 if (window->event_mask & GDK_STRUCTURE_MASK)
5424 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5426 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5427 _gdk_make_event (window, GDK_MAP, NULL, FALSE);
5430 if (!was_mapped || raise)
5432 recompute_visible_regions (window, TRUE, FALSE);
5434 /* If any decendants became visible we need to send visibility notify */
5435 gdk_window_update_visibility_recursively (window, NULL);
5437 if (gdk_window_is_viewable (window))
5439 _gdk_synthesize_crossing_events_for_geometry_change (window);
5440 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
5446 * gdk_window_show_unraised:
5447 * @window: a #GdkWindow
5449 * Shows a #GdkWindow onscreen, but does not modify its stacking
5450 * order. In contrast, gdk_window_show() will raise the window
5451 * to the top of the window stack.
5453 * On the X11 platform, in Xlib terms, this function calls
5454 * XMapWindow() (it also updates some internal GDK state, which means
5455 * that you can't really use XMapWindow() directly on a GDK window).
5458 gdk_window_show_unraised (GdkWindow *window)
5460 gdk_window_show_internal (window, FALSE);
5465 * @window: a #GdkWindow
5467 * Raises @window to the top of the Z-order (stacking order), so that
5468 * other windows with the same parent window appear below @window.
5469 * This is true whether or not the windows are visible.
5471 * If @window is a toplevel, the window manager may choose to deny the
5472 * request to move the window in the Z-order, gdk_window_raise() only
5473 * requests the restack, does not guarantee it.
5476 gdk_window_raise (GdkWindow *window)
5478 g_return_if_fail (GDK_IS_WINDOW (window));
5480 if (window->destroyed)
5483 /* Keep children in (reverse) stacking order */
5484 gdk_window_raise_internal (window);
5486 recompute_visible_regions (window, TRUE, FALSE);
5488 if (gdk_window_is_viewable (window) &&
5489 !window->input_only)
5490 gdk_window_invalidate_region_full (window, window->clip_region, TRUE, CLEAR_BG_ALL);
5494 gdk_window_lower_internal (GdkWindow *window)
5496 GdkWindow *parent = window->parent;
5497 GdkWindowImplClass *impl_class;
5499 GList *native_children;
5504 parent->children = g_list_remove (parent->children, window);
5505 parent->children = g_list_append (parent->children, window);
5508 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5509 /* Just do native lower for toplevels */
5510 if (gdk_window_is_toplevel (window) ||
5511 /* The restack_under codepath should work correctly even if the parent
5512 is native, but it relies on the order of ->children to be correct,
5513 and some apps like SWT reorder the x windows without gdks knowledge,
5514 so we use lower directly in order to make these behave as before
5515 when using native windows */
5516 (gdk_window_has_impl (window) && gdk_window_has_impl (parent)))
5518 impl_class->lower (window);
5520 else if (gdk_window_has_impl (window))
5522 above = find_native_sibling_above (parent, window);
5525 listhead.data = window;
5526 listhead.next = NULL;
5527 listhead.prev = NULL;
5528 impl_class->restack_under ((GdkWindow *)above, &listhead);
5531 impl_class->raise (window);
5535 native_children = NULL;
5536 get_all_native_children (window, &native_children);
5537 if (native_children != NULL)
5539 above = find_native_sibling_above (parent, window);
5542 impl_class->restack_under ((GdkWindow *)above,
5546 /* Right order, since native_children is bottom-topmost first */
5547 for (l = native_children; l != NULL; l = l->next)
5548 impl_class->raise (l->data);
5551 g_list_free (native_children);
5558 gdk_window_invalidate_in_parent (GdkWindow *private)
5560 GdkRectangle r, child;
5562 if (gdk_window_is_toplevel (private))
5565 /* get the visible rectangle of the parent */
5567 r.width = private->parent->width;
5568 r.height = private->parent->height;
5570 child.x = private->x;
5571 child.y = private->y;
5572 child.width = private->width;
5573 child.height = private->height;
5574 gdk_rectangle_intersect (&r, &child, &r);
5576 gdk_window_invalidate_rect_full (private->parent, &r, TRUE, CLEAR_BG_ALL);
5582 * @window: a #GdkWindow
5584 * Lowers @window to the bottom of the Z-order (stacking order), so that
5585 * other windows with the same parent window appear above @window.
5586 * This is true whether or not the other windows are visible.
5588 * If @window is a toplevel, the window manager may choose to deny the
5589 * request to move the window in the Z-order, gdk_window_lower() only
5590 * requests the restack, does not guarantee it.
5592 * Note that gdk_window_show() raises the window again, so don't call this
5593 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
5596 gdk_window_lower (GdkWindow *window)
5598 g_return_if_fail (GDK_IS_WINDOW (window));
5600 if (window->destroyed)
5603 /* Keep children in (reverse) stacking order */
5604 gdk_window_lower_internal (window);
5606 recompute_visible_regions (window, TRUE, FALSE);
5608 _gdk_synthesize_crossing_events_for_geometry_change (window);
5609 gdk_window_invalidate_in_parent (window);
5613 * gdk_window_restack:
5614 * @window: a #GdkWindow
5615 * @sibling: (allow-none): a #GdkWindow that is a sibling of @window, or %NULL
5618 * Changes the position of @window in the Z-order (stacking order), so that
5619 * it is above @sibling (if @above is %TRUE) or below @sibling (if @above is
5622 * If @sibling is %NULL, then this either raises (if @above is %TRUE) or
5623 * lowers the window.
5625 * If @window is a toplevel, the window manager may choose to deny the
5626 * request to move the window in the Z-order, gdk_window_restack() only
5627 * requests the restack, does not guarantee it.
5632 gdk_window_restack (GdkWindow *window,
5636 GdkWindowImplClass *impl_class;
5638 GdkWindow *above_native;
5639 GList *sibling_link;
5640 GList *native_children;
5643 g_return_if_fail (GDK_IS_WINDOW (window));
5644 g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
5646 if (window->destroyed)
5649 if (sibling == NULL)
5652 gdk_window_raise (window);
5654 gdk_window_lower (window);
5658 if (gdk_window_is_toplevel (window))
5660 g_return_if_fail (gdk_window_is_toplevel (sibling));
5661 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5662 impl_class->restack_toplevel (window, sibling, above);
5666 parent = window->parent;
5669 sibling_link = g_list_find (parent->children, sibling);
5670 g_return_if_fail (sibling_link != NULL);
5671 if (sibling_link == NULL)
5674 parent->children = g_list_remove (parent->children, window);
5676 parent->children = g_list_insert_before (parent->children,
5680 parent->children = g_list_insert_before (parent->children,
5684 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5685 if (gdk_window_has_impl (window))
5687 above_native = find_native_sibling_above (parent, window);
5690 listhead.data = window;
5691 listhead.next = NULL;
5692 listhead.prev = NULL;
5693 impl_class->restack_under (above_native, &listhead);
5696 impl_class->raise (window);
5700 native_children = NULL;
5701 get_all_native_children (window, &native_children);
5702 if (native_children != NULL)
5704 above_native = find_native_sibling_above (parent, window);
5706 impl_class->restack_under (above_native,
5710 /* Right order, since native_children is bottom-topmost first */
5711 for (l = native_children; l != NULL; l = l->next)
5712 impl_class->raise (l->data);
5715 g_list_free (native_children);
5720 recompute_visible_regions (window, TRUE, FALSE);
5722 _gdk_synthesize_crossing_events_for_geometry_change (window);
5723 gdk_window_invalidate_in_parent (window);
5729 * @window: a #GdkWindow
5731 * Like gdk_window_show_unraised(), but also raises the window to the
5732 * top of the window stack (moves the window to the front of the
5735 * This function maps a window so it's visible onscreen. Its opposite
5736 * is gdk_window_hide().
5738 * When implementing a #GtkWidget, you should call this function on the widget's
5739 * #GdkWindow as part of the "map" method.
5742 gdk_window_show (GdkWindow *window)
5744 gdk_window_show_internal (window, TRUE);
5749 * @window: a #GdkWindow
5751 * For toplevel windows, withdraws them, so they will no longer be
5752 * known to the window manager; for all windows, unmaps them, so
5753 * they won't be displayed. Normally done automatically as
5754 * part of gtk_widget_hide().
5757 gdk_window_hide (GdkWindow *window)
5759 GdkWindowImplClass *impl_class;
5760 gboolean was_mapped, did_hide;
5762 g_return_if_fail (GDK_IS_WINDOW (window));
5764 if (window->destroyed)
5767 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5769 if (gdk_window_has_impl (window))
5772 if (GDK_WINDOW_IS_MAPPED (window))
5773 gdk_synthesize_window_state (window,
5775 GDK_WINDOW_STATE_WITHDRAWN);
5777 else if (was_mapped)
5779 GdkDisplay *display;
5780 GdkDeviceManager *device_manager;
5783 /* May need to break grabs on children */
5784 display = gdk_window_get_display (window);
5785 device_manager = gdk_display_get_device_manager (display);
5787 /* Get all devices */
5788 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
5789 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE));
5790 devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING));
5792 for (d = devices; d; d = d->next)
5794 GdkDevice *device = d->data;
5796 if (_gdk_display_end_device_grab (display,
5798 _gdk_display_get_next_serial (display),
5801 gdk_device_ungrab (device, GDK_CURRENT_TIME);
5804 window->state = GDK_WINDOW_STATE_WITHDRAWN;
5805 g_list_free (devices);
5808 did_hide = _gdk_window_update_viewable (window);
5810 /* Hide foreign window as those are not handled by update_viewable. */
5811 if (gdk_window_has_impl (window) && (!did_hide))
5813 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5814 impl_class->hide (window);
5817 recompute_visible_regions (window, TRUE, FALSE);
5819 /* all decendants became non-visible, we need to send visibility notify */
5820 gdk_window_update_visibility_recursively (window, NULL);
5822 if (was_mapped && !gdk_window_has_impl (window))
5824 if (window->event_mask & GDK_STRUCTURE_MASK)
5825 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5827 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5828 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5830 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5833 /* Invalidate the rect */
5835 gdk_window_invalidate_in_parent (window);
5839 * gdk_window_withdraw:
5840 * @window: a toplevel #GdkWindow
5842 * Withdraws a window (unmaps it and asks the window manager to forget about it).
5843 * This function is not really useful as gdk_window_hide() automatically
5844 * withdraws toplevel windows before hiding them.
5847 gdk_window_withdraw (GdkWindow *window)
5849 GdkWindowImplClass *impl_class;
5850 gboolean was_mapped;
5852 g_return_if_fail (GDK_IS_WINDOW (window));
5854 if (window->destroyed)
5857 was_mapped = GDK_WINDOW_IS_MAPPED (window);
5859 if (gdk_window_has_impl (window))
5861 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5862 impl_class->withdraw (window);
5866 if (window->event_mask & GDK_STRUCTURE_MASK)
5867 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5869 if (window->parent && window->parent->event_mask & GDK_SUBSTRUCTURE_MASK)
5870 _gdk_make_event (window, GDK_UNMAP, NULL, FALSE);
5872 _gdk_synthesize_crossing_events_for_geometry_change (window->parent);
5875 recompute_visible_regions (window, TRUE, FALSE);
5880 * gdk_window_set_events:
5881 * @window: a #GdkWindow
5882 * @event_mask: event mask for @window
5884 * The event mask for a window determines which events will be reported
5885 * for that window from all master input devices. For example, an event mask
5886 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5887 * press events. The event mask is the bitwise OR of values from the
5888 * #GdkEventMask enumeration.
5891 gdk_window_set_events (GdkWindow *window,
5892 GdkEventMask event_mask)
5894 GdkWindowImplClass *impl_class;
5895 GdkDisplay *display;
5897 g_return_if_fail (GDK_IS_WINDOW (window));
5899 if (window->destroyed)
5902 /* If motion hint is disabled, enable motion events again */
5903 display = gdk_window_get_display (window);
5904 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5905 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5907 GList *devices = window->devices_inside;
5911 _gdk_display_enable_motion_hints (display, (GdkDevice *) devices->data);
5912 devices = devices->next;
5916 window->event_mask = event_mask;
5918 if (gdk_window_has_impl (window))
5920 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
5921 impl_class->set_events (window,
5922 get_native_event_mask (window));
5928 * gdk_window_get_events:
5929 * @window: a #GdkWindow
5931 * Gets the event mask for @window for all master input devices. See
5932 * gdk_window_set_events().
5934 * Return value: event mask for @window
5937 gdk_window_get_events (GdkWindow *window)
5939 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
5941 if (window->destroyed)
5944 return window->event_mask;
5948 * gdk_window_set_device_events:
5949 * @window: a #GdkWindow
5950 * @device: #GdkDevice to enable events for.
5951 * @event_mask: event mask for @window
5953 * Sets the event mask for a given device (Normally a floating device, not
5954 * attached to any visible pointer) to @window. For example, an event mask
5955 * including #GDK_BUTTON_PRESS_MASK means the window should report button
5956 * press events. The event mask is the bitwise OR of values from the
5957 * #GdkEventMask enumeration.
5962 gdk_window_set_device_events (GdkWindow *window,
5964 GdkEventMask event_mask)
5966 GdkEventMask device_mask;
5967 GdkDisplay *display;
5970 g_return_if_fail (GDK_IS_WINDOW (window));
5971 g_return_if_fail (GDK_IS_DEVICE (device));
5973 if (GDK_WINDOW_DESTROYED (window))
5976 /* If motion hint is disabled, enable motion events again */
5977 display = gdk_window_get_display (window);
5978 if ((window->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
5979 !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
5980 _gdk_display_enable_motion_hints (display, device);
5982 if (G_UNLIKELY (!window->device_events))
5983 window->device_events = g_hash_table_new (NULL, NULL);
5985 if (event_mask == 0)
5987 /* FIXME: unsetting events on a master device
5988 * would restore window->event_mask
5990 g_hash_table_remove (window->device_events, device);
5993 g_hash_table_insert (window->device_events, device,
5994 GINT_TO_POINTER (event_mask));
5996 native = gdk_window_get_toplevel (window);
5998 while (gdk_window_is_offscreen (native))
6000 native = gdk_offscreen_window_get_embedder (native);
6002 if (native == NULL ||
6003 (!_gdk_window_has_impl (native) &&
6004 !gdk_window_is_viewable (native)))
6007 native = gdk_window_get_toplevel (native);
6010 device_mask = get_native_device_event_mask (window, device);
6011 GDK_DEVICE_GET_CLASS (device)->select_window_events (device, native, device_mask);
6015 * gdk_window_get_device_events:
6016 * @window: a #GdkWindow.
6017 * @device: a #GdkDevice.
6019 * Returns the event mask for @window corresponding to an specific device.
6021 * Returns: device event mask for @window
6026 gdk_window_get_device_events (GdkWindow *window,
6031 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
6032 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
6034 if (GDK_WINDOW_DESTROYED (window))
6037 if (!window->device_events)
6040 mask = GPOINTER_TO_INT (g_hash_table_lookup (window->device_events, device));
6042 /* FIXME: device could be controlled by window->event_mask */
6048 gdk_window_move_resize_toplevel (GdkWindow *window,
6055 cairo_region_t *old_region, *new_region;
6056 GdkWindowImplClass *impl_class;
6063 is_resize = (width != -1) || (height != -1);
6065 if (gdk_window_is_viewable (window) &&
6066 !window->input_only)
6069 old_region = cairo_region_copy (window->clip_region);
6072 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6073 impl_class->move_resize (window, with_move, x, y, width, height);
6075 /* Avoid recomputing for pure toplevel moves, for performance reasons */
6077 recompute_visible_regions (window, TRUE, FALSE);
6081 new_region = cairo_region_copy (window->clip_region);
6083 /* This is the newly exposed area (due to any resize),
6084 * X will expose it, but lets do that without the roundtrip
6086 cairo_region_subtract (new_region, old_region);
6087 gdk_window_invalidate_region_full (window, new_region, TRUE, CLEAR_BG_WINCLEARED);
6089 cairo_region_destroy (old_region);
6090 cairo_region_destroy (new_region);
6093 _gdk_synthesize_crossing_events_for_geometry_change (window);
6098 move_native_children (GdkWindow *private)
6102 GdkWindowImplClass *impl_class;
6104 for (l = private->children; l; l = l->next)
6108 if (child->impl != private->impl)
6110 impl_class = GDK_WINDOW_IMPL_GET_CLASS (child->impl);
6111 impl_class->move_resize (child, TRUE,
6113 child->width, child->height);
6116 move_native_children (child);
6121 collect_native_child_region_helper (GdkWindow *window,
6122 GdkWindowImpl *impl,
6123 cairo_region_t **region,
6128 cairo_region_t *tmp;
6131 for (l = window->children; l != NULL; l = l->next)
6135 if (!GDK_WINDOW_IS_MAPPED (child) || child->input_only)
6138 if (child->impl != impl)
6140 tmp = cairo_region_copy (child->clip_region);
6141 cairo_region_translate (tmp,
6142 x_offset + child->x,
6143 y_offset + child->y);
6144 if (*region == NULL)
6148 cairo_region_union (*region, tmp);
6149 cairo_region_destroy (tmp);
6153 collect_native_child_region_helper (child, impl, region,
6154 x_offset + child->x,
6155 y_offset + child->y);
6161 static cairo_region_t *
6162 collect_native_child_region (GdkWindow *window,
6163 gboolean include_this)
6165 cairo_region_t *region;
6167 if (include_this && gdk_window_has_impl (window) && window->viewable)
6168 return cairo_region_copy (window->clip_region);
6172 collect_native_child_region_helper (window, window->impl, ®ion, 0, 0);
6179 gdk_window_move_resize_internal (GdkWindow *window,
6186 cairo_region_t *old_region, *old_layered, *new_region, *copy_area;
6187 cairo_region_t *old_native_child_region, *new_native_child_region;
6188 GdkWindow *impl_window;
6189 GdkWindowImplClass *impl_class;
6191 int old_x, old_y, old_abs_x, old_abs_y;
6194 g_return_if_fail (GDK_IS_WINDOW (window));
6196 if (window->destroyed)
6199 if (gdk_window_is_toplevel (window))
6201 gdk_window_move_resize_toplevel (window, with_move, x, y, width, height);
6205 /* Bail early if no change */
6206 if (window->width == width &&
6207 window->height == height &&
6213 /* Handle child windows */
6219 impl_window = gdk_window_get_impl_window (window);
6224 old_native_child_region = NULL;
6225 if (gdk_window_is_viewable (window) &&
6226 !window->input_only)
6230 old_region = cairo_region_copy (window->clip_region);
6231 old_layered = cairo_region_copy (window->layered_region);
6232 /* Adjust regions to parent window coords */
6233 cairo_region_translate (old_region, window->x, window->y);
6234 cairo_region_translate (old_layered, window->x, window->y);
6236 old_native_child_region = collect_native_child_region (window, TRUE);
6237 if (old_native_child_region)
6239 /* Adjust region to parent window coords */
6240 cairo_region_translate (old_native_child_region, window->x, window->y);
6242 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6243 * source or destination for a delayed GdkWindowRegionMove. So, we need
6244 * to flush those here for the parent window and all overlapped subwindows
6245 * of it. And we need to do this before setting the new clips as those will be
6248 gdk_window_flush_recursive (window->parent);
6252 /* Set the new position and size */
6258 if (!(width < 0 && height < 0))
6262 window->width = width;
6265 window->height = height;
6268 dx = window->x - old_x;
6269 dy = window->y - old_y;
6271 old_abs_x = window->abs_x;
6272 old_abs_y = window->abs_y;
6274 recompute_visible_regions (window, TRUE, FALSE);
6276 new_native_child_region = NULL;
6277 if (old_native_child_region)
6279 new_native_child_region = collect_native_child_region (window, TRUE);
6280 /* Adjust region to parent window coords */
6281 cairo_region_translate (new_native_child_region, window->x, window->y);
6284 if (gdk_window_has_impl (window))
6286 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6288 /* Do the actual move after recomputing things, as this will have set the shape to
6289 the now correct one, thus avoiding copying regions that should not be copied. */
6290 impl_class->move_resize (window, TRUE,
6291 window->x, window->y,
6292 window->width, window->height);
6294 else if (old_abs_x != window->abs_x ||
6295 old_abs_y != window->abs_y)
6296 move_native_children (window);
6300 new_region = cairo_region_copy (window->clip_region);
6301 /* Adjust region to parent window coords */
6302 cairo_region_translate (new_region, window->x, window->y);
6305 * Part of the data at the new location can be copied from the
6306 * old location, this area is the intersection of the old region
6307 * moved as the copy will move it and then intersected with
6311 * Everything in the old and new regions that is not copied must be
6312 * invalidated (including children) as this is newly exposed
6314 if (gdk_window_has_alpha (window))
6315 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6317 copy_area = cairo_region_copy (new_region);
6319 /* Don't copy from a previously layered region */
6320 cairo_region_translate (old_layered, dx, dy);
6321 cairo_region_subtract (copy_area, old_layered);
6323 /* Don't copy into a layered region */
6324 cairo_region_translate (copy_area, -window->x, -window->y);
6325 cairo_region_subtract (copy_area, window->layered_region);
6326 cairo_region_translate (copy_area, window->x, window->y);
6328 cairo_region_union (new_region, old_region);
6330 if (old_native_child_region)
6332 /* Don't copy from inside native children, as this is copied by
6333 * the native window move.
6335 cairo_region_subtract (old_region, old_native_child_region);
6337 cairo_region_translate (old_region, dx, dy);
6339 cairo_region_intersect (copy_area, old_region);
6341 if (new_native_child_region)
6343 /* Don't copy any bits that would cause a read from the moved
6344 native windows, as we can't read that data */
6345 cairo_region_translate (new_native_child_region, dx, dy);
6346 cairo_region_subtract (copy_area, new_native_child_region);
6347 cairo_region_translate (new_native_child_region, -dx, -dy);
6350 cairo_region_subtract (new_region, copy_area);
6352 /* Convert old region to impl coords */
6353 cairo_region_translate (old_region, -dx + window->abs_x - window->x, -dy + window->abs_y - window->y);
6355 /* convert from parent coords to impl */
6356 cairo_region_translate (copy_area, window->abs_x - window->x, window->abs_y - window->y);
6358 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6360 /* Invalidate affected part in the parent window
6361 * (no higher window should be affected)
6362 * We also invalidate any children in that area, which could include
6363 * this window if it still overlaps that area.
6365 if (old_native_child_region)
6367 /* No need to expose the region that the native window move copies */
6368 cairo_region_translate (old_native_child_region, dx, dy);
6369 cairo_region_intersect (old_native_child_region, new_native_child_region);
6370 cairo_region_subtract (new_region, old_native_child_region);
6372 gdk_window_invalidate_region_full (window->parent, new_region, TRUE, CLEAR_BG_ALL);
6374 cairo_region_destroy (old_region);
6375 cairo_region_destroy (old_layered);
6376 cairo_region_destroy (new_region);
6379 if (old_native_child_region)
6381 cairo_region_destroy (old_native_child_region);
6382 cairo_region_destroy (new_native_child_region);
6385 _gdk_synthesize_crossing_events_for_geometry_change (window);
6392 * @window: a #GdkWindow
6393 * @x: X coordinate relative to window's parent
6394 * @y: Y coordinate relative to window's parent
6396 * Repositions a window relative to its parent window.
6397 * For toplevel windows, window managers may ignore or modify the move;
6398 * you should probably use gtk_window_move() on a #GtkWindow widget
6399 * anyway, instead of using GDK functions. For child windows,
6400 * the move will reliably succeed.
6402 * If you're also planning to resize the window, use gdk_window_move_resize()
6403 * to both move and resize simultaneously, for a nicer visual effect.
6406 gdk_window_move (GdkWindow *window,
6410 gdk_window_move_resize_internal (window, TRUE, x, y, -1, -1);
6414 * gdk_window_resize:
6415 * @window: a #GdkWindow
6416 * @width: new width of the window
6417 * @height: new height of the window
6419 * Resizes @window; for toplevel windows, asks the window manager to resize
6420 * the window. The window manager may not allow the resize. When using GTK+,
6421 * use gtk_window_resize() instead of this low-level GDK function.
6423 * Windows may not be resized below 1x1.
6425 * If you're also planning to move the window, use gdk_window_move_resize()
6426 * to both move and resize simultaneously, for a nicer visual effect.
6429 gdk_window_resize (GdkWindow *window,
6433 gdk_window_move_resize_internal (window, FALSE, 0, 0, width, height);
6438 * gdk_window_move_resize:
6439 * @window: a #GdkWindow
6440 * @x: new X position relative to window's parent
6441 * @y: new Y position relative to window's parent
6443 * @height: new height
6445 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
6446 * except that both operations are performed at once, avoiding strange
6447 * visual effects. (i.e. the user may be able to see the window first
6448 * move, then resize, if you don't use gdk_window_move_resize().)
6451 gdk_window_move_resize (GdkWindow *window,
6457 gdk_window_move_resize_internal (window, TRUE, x, y, width, height);
6462 * gdk_window_scroll:
6463 * @window: a #GdkWindow
6464 * @dx: Amount to scroll in the X direction
6465 * @dy: Amount to scroll in the Y direction
6467 * Scroll the contents of @window, both pixels and children, by the
6468 * given amount. @window itself does not move. Portions of the window
6469 * that the scroll operation brings in from offscreen areas are
6470 * invalidated. The invalidated region may be bigger than what would
6471 * strictly be necessary.
6473 * For X11, a minimum area will be invalidated if the window has no
6474 * subwindows, or if the edges of the window's parent do not extend
6475 * beyond the edges of the window. In other cases, a multi-step process
6476 * is used to scroll the window which may produce temporary visual
6477 * artifacts and unnecessary invalidations.
6480 gdk_window_scroll (GdkWindow *window,
6484 GdkWindow *impl_window;
6485 cairo_region_t *copy_area, *noncopy_area, *old_layered_area;
6486 cairo_region_t *old_native_child_region, *new_native_child_region;
6489 g_return_if_fail (GDK_IS_WINDOW (window));
6491 if (dx == 0 && dy == 0)
6494 if (window->destroyed)
6497 old_layered_area = cairo_region_copy (window->layered_region);
6498 old_native_child_region = collect_native_child_region (window, FALSE);
6499 if (old_native_child_region)
6501 /* Any native window move will immediately copy stuff to the destination, which may overwrite a
6502 * source or destination for a delayed GdkWindowRegionMove. So, we need
6503 * to flush those here for the window and all overlapped subwindows
6504 * of it. And we need to do this before setting the new clips as those will be
6507 gdk_window_flush_recursive (window);
6511 /* First move all child windows, without causing invalidation */
6513 tmp_list = window->children;
6516 GdkWindow *child = GDK_WINDOW (tmp_list->data);
6518 /* Just update the positions, the bits will move with the copy */
6522 tmp_list = tmp_list->next;
6525 recompute_visible_regions (window, FALSE, TRUE);
6527 new_native_child_region = NULL;
6528 if (old_native_child_region)
6529 new_native_child_region = collect_native_child_region (window, FALSE);
6531 move_native_children (window);
6533 /* Then copy the actual bits of the window w/ child windows */
6535 impl_window = gdk_window_get_impl_window (window);
6537 /* Calculate the area that can be gotten by copying the old area */
6538 if (gdk_window_has_alpha (window))
6539 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6541 copy_area = cairo_region_copy (window->clip_region);
6542 cairo_region_subtract (copy_area, old_layered_area);
6543 if (old_native_child_region)
6545 /* Don't copy from inside native children, as this is copied by
6546 * the native window move.
6548 cairo_region_subtract (copy_area, old_native_child_region);
6550 /* Don't copy any bits that would cause a read from the moved
6551 native windows, as we can't read that data */
6552 cairo_region_subtract (copy_area, new_native_child_region);
6554 cairo_region_translate (copy_area, dx, dy);
6555 cairo_region_intersect (copy_area, window->clip_region);
6556 cairo_region_subtract (copy_area, window->layered_region);
6558 /* And the rest need to be invalidated */
6559 noncopy_area = cairo_region_copy (window->clip_region);
6560 cairo_region_subtract (noncopy_area, copy_area);
6562 /* convert from window coords to impl */
6563 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6565 move_region_on_impl (impl_window, copy_area, dx, dy); /* takes ownership of copy_area */
6567 /* Invalidate not copied regions */
6568 if (old_native_child_region)
6570 /* No need to expose the region that the native window move copies */
6571 cairo_region_translate (old_native_child_region, dx, dy);
6572 cairo_region_intersect (old_native_child_region, new_native_child_region);
6573 cairo_region_subtract (noncopy_area, old_native_child_region);
6575 gdk_window_invalidate_region_full (window, noncopy_area, TRUE, CLEAR_BG_ALL);
6577 cairo_region_destroy (noncopy_area);
6578 cairo_region_destroy (old_layered_area);
6580 if (old_native_child_region)
6582 cairo_region_destroy (old_native_child_region);
6583 cairo_region_destroy (new_native_child_region);
6586 _gdk_synthesize_crossing_events_for_geometry_change (window);
6590 * gdk_window_move_region:
6591 * @window: a #GdkWindow
6592 * @region: The #cairo_region_t to move
6593 * @dx: Amount to move in the X direction
6594 * @dy: Amount to move in the Y direction
6596 * Move the part of @window indicated by @region by @dy pixels in the Y
6597 * direction and @dx pixels in the X direction. The portions of @region
6598 * that not covered by the new position of @region are invalidated.
6600 * Child windows are not moved.
6605 gdk_window_move_region (GdkWindow *window,
6606 const cairo_region_t *region,
6610 GdkWindow *impl_window;
6611 cairo_region_t *nocopy_area;
6612 cairo_region_t *copy_area;
6614 g_return_if_fail (GDK_IS_WINDOW (window));
6615 g_return_if_fail (region != NULL);
6617 if (dx == 0 && dy == 0)
6620 if (window->destroyed)
6623 impl_window = gdk_window_get_impl_window (window);
6625 /* compute source regions */
6626 if (gdk_window_has_alpha (window))
6627 copy_area = cairo_region_create (); /* Copy nothing for alpha windows */
6629 copy_area = cairo_region_copy (region);
6630 cairo_region_intersect (copy_area, window->clip_region_with_children);
6631 cairo_region_subtract (copy_area, window->layered_region);
6632 remove_layered_child_area (window, copy_area);
6634 /* compute destination regions */
6635 cairo_region_translate (copy_area, dx, dy);
6636 cairo_region_intersect (copy_area, window->clip_region_with_children);
6637 cairo_region_subtract (copy_area, window->layered_region);
6638 remove_layered_child_area (window, copy_area);
6640 /* Invalidate parts of the region (source and dest) not covered
6642 nocopy_area = cairo_region_copy (region);
6643 cairo_region_translate (nocopy_area, dx, dy);
6644 cairo_region_union (nocopy_area, region);
6645 cairo_region_subtract (nocopy_area, copy_area);
6647 /* convert from window coords to impl */
6648 cairo_region_translate (copy_area, window->abs_x, window->abs_y);
6649 move_region_on_impl (impl_window, copy_area, dx, dy); /* Takes ownership of copy_area */
6651 gdk_window_invalidate_region_full (window, nocopy_area, FALSE, CLEAR_BG_ALL);
6652 cairo_region_destroy (nocopy_area);
6656 * gdk_window_set_background:
6657 * @window: a #GdkWindow
6658 * @color: a #GdkColor
6660 * Sets the background color of @window. (However, when using GTK+,
6661 * set the background of a widget with gtk_widget_modify_bg() - if
6662 * you're an application - or gtk_style_set_background() - if you're
6663 * implementing a custom widget.)
6665 * See also gdk_window_set_background_pattern().
6667 * Deprecated: 3.4: Use gdk_window_set_background_rgba() instead.
6670 gdk_window_set_background (GdkWindow *window,
6671 const GdkColor *color)
6673 cairo_pattern_t *pattern;
6675 g_return_if_fail (GDK_IS_WINDOW (window));
6677 pattern = cairo_pattern_create_rgb (color->red / 65535.,
6678 color->green / 65535.,
6679 color->blue / 65535.);
6681 gdk_window_set_background_pattern (window, pattern);
6683 cairo_pattern_destroy (pattern);
6687 * gdk_window_set_background_rgba:
6688 * @window: a #GdkWindow
6689 * @rgba: a #GdkRGBA color
6691 * Sets the background color of @window.
6693 * See also gdk_window_set_background_pattern().
6696 gdk_window_set_background_rgba (GdkWindow *window,
6697 const GdkRGBA *rgba)
6699 cairo_pattern_t *pattern;
6701 g_return_if_fail (GDK_IS_WINDOW (window));
6702 g_return_if_fail (rgba != NULL);
6704 pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
6705 rgba->blue, rgba->alpha);
6707 gdk_window_set_background_pattern (window, pattern);
6709 cairo_pattern_destroy (pattern);
6713 /* Updates has_alpha_background recursively for all child windows
6714 that have parent-relative alpha */
6716 _gdk_window_propagate_has_alpha_background (GdkWindow *window)
6721 for (l = window->children; l; l = l->next)
6725 if (child->background == NULL &&
6726 child->has_alpha_background != window->has_alpha_background)
6728 child->has_alpha_background = window->has_alpha_background;
6729 recompute_visible_regions (child, TRUE, FALSE);
6730 _gdk_window_propagate_has_alpha_background (child);
6736 * gdk_window_set_background_pattern:
6737 * @window: a #GdkWindow
6738 * @pattern: (allow-none): a pattern to use, or %NULL
6740 * Sets the background of @window.
6742 * A background of %NULL means that the window will inherit its
6743 * background form its parent window.
6745 * The windowing system will normally fill a window with its background
6746 * when the window is obscured then exposed.
6749 gdk_window_set_background_pattern (GdkWindow *window,
6750 cairo_pattern_t *pattern)
6753 cairo_pattern_type_t type;
6755 g_return_if_fail (GDK_IS_WINDOW (window));
6757 if (window->input_only)
6761 cairo_pattern_reference (pattern);
6762 if (window->background)
6763 cairo_pattern_destroy (window->background);
6764 window->background = pattern;
6768 if (pattern == NULL)
6770 /* parent-relative, copy has_alpha from parent */
6771 if (window->parent == NULL ||
6772 window->parent->window_type == GDK_WINDOW_ROOT)
6775 has_alpha = window->parent->has_alpha_background;
6779 type = cairo_pattern_get_type (pattern);
6781 if (type == CAIRO_PATTERN_TYPE_SOLID)
6784 cairo_pattern_get_rgba (pattern, NULL, NULL, NULL, &alpha);
6788 else if (type == CAIRO_PATTERN_TYPE_LINEAR ||
6789 type == CAIRO_PATTERN_TYPE_RADIAL)
6795 cairo_pattern_get_color_stop_count (pattern, &n);
6797 for (i = 0; i < n; i++)
6799 cairo_pattern_get_color_stop_rgba (pattern, i, NULL,
6800 NULL, NULL, NULL, &alpha);
6808 else if (type == CAIRO_PATTERN_TYPE_SURFACE)
6810 cairo_surface_t *surface;
6811 cairo_content_t content;
6813 cairo_pattern_get_surface (pattern, &surface);
6814 content = cairo_surface_get_content (surface);
6816 (content == CAIRO_CONTENT_ALPHA) ||
6817 (content == CAIRO_CONTENT_COLOR_ALPHA);
6821 if (has_alpha != window->has_alpha_background)
6823 window->has_alpha_background = has_alpha;
6824 recompute_visible_regions (window, TRUE, FALSE);
6826 _gdk_window_propagate_has_alpha_background (window);
6829 if (gdk_window_has_impl (window))
6831 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
6832 impl_class->set_background (window, pattern);
6835 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
6839 * gdk_window_get_background_pattern:
6842 * Gets the pattern used to clear the background on @window. If @window
6843 * does not have its own background and reuses the parent's, %NULL is
6844 * returned and you'll have to query it yourself.
6846 * Returns: (transfer none): The pattern to use for the background or
6847 * %NULL to use the parent's background.
6852 gdk_window_get_background_pattern (GdkWindow *window)
6854 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6856 return window->background;
6860 gdk_window_set_cursor_internal (GdkWindow *window,
6864 if (GDK_WINDOW_DESTROYED (window))
6867 if (window->window_type == GDK_WINDOW_ROOT ||
6868 window->window_type == GDK_WINDOW_FOREIGN)
6869 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_device_cursor (window, device, cursor);
6872 GdkPointerWindowInfo *pointer_info;
6873 GdkDisplay *display;
6875 display = gdk_window_get_display (window);
6876 pointer_info = _gdk_display_get_pointer_info (display, device);
6878 if (_gdk_window_event_parent_of (window, pointer_info->window_under_pointer))
6879 update_cursor (display, device);
6884 * gdk_window_get_cursor:
6885 * @window: a #GdkWindow
6887 * Retrieves a #GdkCursor pointer for the cursor currently set on the
6888 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6889 * there is no custom cursor set on the specified window, and it is
6890 * using the cursor for its parent window.
6892 * Return value: (transfer none): a #GdkCursor, or %NULL. The returned
6893 * object is owned by the #GdkWindow and should not be unreferenced
6894 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6900 gdk_window_get_cursor (GdkWindow *window)
6902 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6904 return window->cursor;
6908 * gdk_window_set_cursor:
6909 * @window: a #GdkWindow
6910 * @cursor: (allow-none): a cursor
6912 * Sets the default mouse pointer for a #GdkWindow. Use gdk_cursor_new_for_display()
6913 * or gdk_cursor_new_from_pixbuf() to create the cursor. To make the cursor
6914 * invisible, use %GDK_BLANK_CURSOR. Passing %NULL for the @cursor argument
6915 * to gdk_window_set_cursor() means that @window will use the cursor of its
6916 * parent window. Most windows should use this default.
6919 gdk_window_set_cursor (GdkWindow *window,
6922 GdkDisplay *display;
6924 g_return_if_fail (GDK_IS_WINDOW (window));
6926 display = gdk_window_get_display (window);
6930 g_object_unref (window->cursor);
6931 window->cursor = NULL;
6934 if (!GDK_WINDOW_DESTROYED (window))
6936 GdkDeviceManager *device_manager;
6940 window->cursor = g_object_ref (cursor);
6942 device_manager = gdk_display_get_device_manager (display);
6943 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
6945 for (d = devices; d; d = d->next)
6951 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
6954 gdk_window_set_cursor_internal (window, device, window->cursor);
6957 g_list_free (devices);
6958 g_object_notify (G_OBJECT (window), "cursor");
6963 * gdk_window_get_device_cursor:
6964 * @window: a #GdkWindow.
6965 * @device: a master, pointer #GdkDevice.
6967 * Retrieves a #GdkCursor pointer for the @device currently set on the
6968 * specified #GdkWindow, or %NULL. If the return value is %NULL then
6969 * there is no custom cursor set on the specified window, and it is
6970 * using the cursor for its parent window.
6972 * Returns: (transfer none): a #GdkCursor, or %NULL. The returned
6973 * object is owned by the #GdkWindow and should not be unreferenced
6974 * directly. Use gdk_window_set_cursor() to unset the cursor of the
6980 gdk_window_get_device_cursor (GdkWindow *window,
6983 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
6984 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
6985 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
6986 g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
6988 return g_hash_table_lookup (window->device_cursor, device);
6992 * gdk_window_set_device_cursor:
6993 * @window: a #Gdkwindow
6994 * @device: a master, pointer #GdkDevice
6995 * @cursor: a #GdkCursor
6997 * Sets a specific #GdkCursor for a given device when it gets inside @window.
6998 * Use gdk_cursor_new_for_display() or gdk_cursor_new_from_pixbuf() to create
6999 * the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR. Passing
7000 * %NULL for the @cursor argument to gdk_window_set_cursor() means that
7001 * @window will use the cursor of its parent window. Most windows should
7007 gdk_window_set_device_cursor (GdkWindow *window,
7011 g_return_if_fail (GDK_IS_WINDOW (window));
7012 g_return_if_fail (GDK_IS_DEVICE (device));
7013 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
7014 g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
7017 g_hash_table_remove (window->device_cursor, device);
7019 g_hash_table_replace (window->device_cursor, device, g_object_ref (cursor));
7021 gdk_window_set_cursor_internal (window, device, cursor);
7025 * gdk_window_get_geometry:
7026 * @window: a #GdkWindow
7027 * @x: (out) (allow-none): return location for X coordinate of window (relative to its parent)
7028 * @y: (out) (allow-none): return location for Y coordinate of window (relative to its parent)
7029 * @width: (out) (allow-none): return location for width of window
7030 * @height: (out) (allow-none): return location for height of window
7032 * Any of the return location arguments to this function may be %NULL,
7033 * if you aren't interested in getting the value of that field.
7035 * The X and Y coordinates returned are relative to the parent window
7036 * of @window, which for toplevels usually means relative to the
7037 * window decorations (titlebar, etc.) rather than relative to the
7038 * root window (screen-size background window).
7040 * On the X11 platform, the geometry is obtained from the X server,
7041 * so reflects the latest position of @window; this may be out-of-sync
7042 * with the position of @window delivered in the most-recently-processed
7043 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
7044 * position from the most recent configure event.
7047 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
7048 * to call gdk_window_get_position(), gdk_window_get_width() and
7049 * gdk_window_get_height() instead, because it avoids the roundtrip to
7050 * the X server and because these functions support the full 32-bit
7051 * coordinate space, whereas gdk_window_get_geometry() is restricted to
7052 * the 16-bit coordinates of X11.
7056 gdk_window_get_geometry (GdkWindow *window,
7063 GdkWindowImplClass *impl_class;
7067 GDK_NOTE (MULTIHEAD,
7068 g_message ("gdk_window_get_geometry(): Window needs "
7069 "to be non-NULL to be multi head safe"));
7070 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
7073 g_return_if_fail (GDK_IS_WINDOW (window));
7075 if (!GDK_WINDOW_DESTROYED (window))
7077 if (gdk_window_has_impl (window))
7079 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7080 impl_class->get_geometry (window, x, y,
7082 /* This reports the position wrt to the native parent, we need to convert
7083 it to be relative to the client side parent */
7084 parent = window->parent;
7085 if (parent && !gdk_window_has_impl (parent))
7088 *x -= parent->abs_x;
7090 *y -= parent->abs_y;
7100 *width = window->width;
7102 *height = window->height;
7108 * gdk_window_get_width:
7109 * @window: a #GdkWindow
7111 * Returns the width of the given @window.
7113 * On the X11 platform the returned size is the size reported in the
7114 * most-recently-processed configure event, rather than the current
7115 * size on the X server.
7117 * Returns: The width of @window
7122 gdk_window_get_width (GdkWindow *window)
7124 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7126 return window->width;
7130 * gdk_window_get_height:
7131 * @window: a #GdkWindow
7133 * Returns the height of the given @window.
7135 * On the X11 platform the returned size is the size reported in the
7136 * most-recently-processed configure event, rather than the current
7137 * size on the X server.
7139 * Returns: The height of @window
7144 gdk_window_get_height (GdkWindow *window)
7146 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7148 return window->height;
7152 * gdk_window_get_origin:
7153 * @window: a #GdkWindow
7154 * @x: (out) (allow-none): return location for X coordinate
7155 * @y: (out) (allow-none): return location for Y coordinate
7157 * Obtains the position of a window in root window coordinates.
7158 * (Compare with gdk_window_get_position() and
7159 * gdk_window_get_geometry() which return the position of a window
7160 * relative to its parent window.)
7162 * Return value: not meaningful, ignore
7165 gdk_window_get_origin (GdkWindow *window,
7169 GdkWindowImplClass *impl_class;
7171 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
7173 if (GDK_WINDOW_DESTROYED (window))
7182 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7183 impl_class->get_root_coords (window,
7192 * gdk_window_get_root_coords:
7193 * @window: a #GdkWindow
7194 * @x: X coordinate in window
7195 * @y: Y coordinate in window
7196 * @root_x: (out): return location for X coordinate
7197 * @root_y: (out): return location for Y coordinate
7199 * Obtains the position of a window position in root
7200 * window coordinates. This is similar to
7201 * gdk_window_get_origin() but allows you go pass
7202 * in any position in the window, not just the origin.
7207 gdk_window_get_root_coords (GdkWindow *window,
7213 GdkWindowImplClass *impl_class;
7215 g_return_if_fail (GDK_IS_WINDOW (window));
7217 if (GDK_WINDOW_DESTROYED (window))
7224 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7225 impl_class->get_root_coords (window,
7232 * gdk_window_coords_to_parent:
7233 * @window: a child window
7234 * @x: X coordinate in child's coordinate system
7235 * @y: Y coordinate in child's coordinate system
7236 * @parent_x: (out) (allow-none): return location for X coordinate
7237 * in parent's coordinate system, or %NULL
7238 * @parent_y: (out) (allow-none): return location for Y coordinate
7239 * in parent's coordinate system, or %NULL
7241 * Transforms window coordinates from a child window to its parent
7242 * window, where the parent window is the normal parent as returned by
7243 * gdk_window_get_parent() for normal windows, and the window's
7244 * embedder as returned by gdk_offscreen_window_get_embedder() for
7245 * offscreen windows.
7247 * For normal windows, calling this function is equivalent to adding
7248 * the return values of gdk_window_get_position() to the child coordinates.
7249 * For offscreen windows however (which can be arbitrarily transformed),
7250 * this function calls the GdkWindow::to-embedder: signal to translate
7253 * You should always use this function when writing generic code that
7254 * walks up a window hierarchy.
7256 * See also: gdk_window_coords_from_parent()
7261 gdk_window_coords_to_parent (GdkWindow *window,
7267 g_return_if_fail (GDK_IS_WINDOW (window));
7269 if (gdk_window_is_offscreen (window))
7273 to_embedder (window, x, y, &px, &py);
7284 *parent_x = x + window->x;
7287 *parent_y = y + window->y;
7292 * gdk_window_coords_from_parent:
7293 * @window: a child window
7294 * @parent_x: X coordinate in parent's coordinate system
7295 * @parent_y: Y coordinate in parent's coordinate system
7296 * @x: (out) (allow-none): return location for X coordinate in child's coordinate system
7297 * @y: (out) (allow-none): return location for Y coordinate in child's coordinate system
7299 * Transforms window coordinates from a parent window to a child
7300 * window, where the parent window is the normal parent as returned by
7301 * gdk_window_get_parent() for normal windows, and the window's
7302 * embedder as returned by gdk_offscreen_window_get_embedder() for
7303 * offscreen windows.
7305 * For normal windows, calling this function is equivalent to subtracting
7306 * the return values of gdk_window_get_position() from the parent coordinates.
7307 * For offscreen windows however (which can be arbitrarily transformed),
7308 * this function calls the GdkWindow::from-embedder: signal to translate
7311 * You should always use this function when writing generic code that
7312 * walks down a window hierarchy.
7314 * See also: gdk_window_coords_to_parent()
7319 gdk_window_coords_from_parent (GdkWindow *window,
7325 g_return_if_fail (GDK_IS_WINDOW (window));
7327 if (gdk_window_is_offscreen (window))
7331 from_embedder (window, parent_x, parent_y, &cx, &cy);
7342 *x = parent_x - window->x;
7345 *y = parent_y - window->y;
7350 * gdk_window_shape_combine_region:
7351 * @window: a #GdkWindow
7352 * @shape_region: (allow-none): region of window to be non-transparent
7353 * @offset_x: X position of @shape_region in @window coordinates
7354 * @offset_y: Y position of @shape_region in @window coordinates
7356 * Makes pixels in @window outside @shape_region be transparent,
7357 * so that the window may be nonrectangular.
7359 * If @shape_region is %NULL, the shape will be unset, so the whole
7360 * window will be opaque again. @offset_x and @offset_y are ignored
7361 * if @shape_region is %NULL.
7363 * On the X11 platform, this uses an X server extension which is
7364 * widely available on most common platforms, but not available on
7365 * very old X servers, and occasionally the implementation will be
7366 * buggy. On servers without the shape extension, this function
7369 * This function works on both toplevel and child windows.
7372 gdk_window_shape_combine_region (GdkWindow *window,
7373 const cairo_region_t *shape_region,
7377 cairo_region_t *old_region, *new_region, *diff;
7379 g_return_if_fail (GDK_IS_WINDOW (window));
7381 if (GDK_WINDOW_DESTROYED (window))
7384 if (!window->shape && shape_region == NULL)
7387 window->shaped = (shape_region != NULL);
7390 cairo_region_destroy (window->shape);
7393 if (GDK_WINDOW_IS_MAPPED (window))
7394 old_region = cairo_region_copy (window->clip_region);
7398 window->shape = cairo_region_copy (shape_region);
7399 cairo_region_translate (window->shape, offset_x, offset_y);
7402 window->shape = NULL;
7404 recompute_visible_regions (window, TRUE, FALSE);
7406 if (gdk_window_has_impl (window) &&
7407 !should_apply_clip_as_shape (window))
7408 apply_shape (window, window->shape);
7412 new_region = cairo_region_copy (window->clip_region);
7414 /* New area in the window, needs invalidation */
7415 diff = cairo_region_copy (new_region);
7416 cairo_region_subtract (diff, old_region);
7418 gdk_window_invalidate_region_full (window, diff, TRUE, CLEAR_BG_ALL);
7420 cairo_region_destroy (diff);
7422 if (!gdk_window_is_toplevel (window))
7424 /* New area in the non-root parent window, needs invalidation */
7425 diff = cairo_region_copy (old_region);
7426 cairo_region_subtract (diff, new_region);
7428 /* Adjust region to parent window coords */
7429 cairo_region_translate (diff, window->x, window->y);
7431 gdk_window_invalidate_region_full (window->parent, diff, TRUE, CLEAR_BG_ALL);
7433 cairo_region_destroy (diff);
7436 cairo_region_destroy (new_region);
7437 cairo_region_destroy (old_region);
7442 do_child_shapes (GdkWindow *window,
7446 cairo_region_t *region;
7450 r.width = window->width;
7451 r.height = window->height;
7453 region = cairo_region_create_rectangle (&r);
7454 remove_child_area (window, NULL, FALSE, region, NULL);
7456 if (merge && window->shape)
7457 cairo_region_subtract (region, window->shape);
7459 gdk_window_shape_combine_region (window, region, 0, 0);
7463 * gdk_window_set_child_shapes:
7464 * @window: a #GdkWindow
7466 * Sets the shape mask of @window to the union of shape masks
7467 * for all children of @window, ignoring the shape mask of @window
7468 * itself. Contrast with gdk_window_merge_child_shapes() which includes
7469 * the shape mask of @window in the masks to be merged.
7472 gdk_window_set_child_shapes (GdkWindow *window)
7474 g_return_if_fail (GDK_IS_WINDOW (window));
7476 do_child_shapes (window, FALSE);
7480 * gdk_window_merge_child_shapes:
7481 * @window: a #GdkWindow
7483 * Merges the shape masks for any child windows into the
7484 * shape mask for @window. i.e. the union of all masks
7485 * for @window and its children will become the new mask
7486 * for @window. See gdk_window_shape_combine_region().
7488 * This function is distinct from gdk_window_set_child_shapes()
7489 * because it includes @window's shape mask in the set of shapes to
7493 gdk_window_merge_child_shapes (GdkWindow *window)
7495 g_return_if_fail (GDK_IS_WINDOW (window));
7497 do_child_shapes (window, TRUE);
7501 * gdk_window_input_shape_combine_region:
7502 * @window: a #GdkWindow
7503 * @shape_region: region of window to be non-transparent
7504 * @offset_x: X position of @shape_region in @window coordinates
7505 * @offset_y: Y position of @shape_region in @window coordinates
7507 * Like gdk_window_shape_combine_region(), but the shape applies
7508 * only to event handling. Mouse events which happen while
7509 * the pointer position corresponds to an unset bit in the
7510 * mask will be passed on the window below @window.
7512 * An input shape is typically used with RGBA windows.
7513 * The alpha channel of the window defines which pixels are
7514 * invisible and allows for nicely antialiased borders,
7515 * and the input shape controls where the window is
7518 * On the X11 platform, this requires version 1.1 of the
7521 * On the Win32 platform, this functionality is not present and the
7522 * function does nothing.
7527 gdk_window_input_shape_combine_region (GdkWindow *window,
7528 const cairo_region_t *shape_region,
7532 GdkWindowImplClass *impl_class;
7534 g_return_if_fail (GDK_IS_WINDOW (window));
7536 if (GDK_WINDOW_DESTROYED (window))
7539 if (window->input_shape)
7540 cairo_region_destroy (window->input_shape);
7544 window->input_shape = cairo_region_copy (shape_region);
7545 cairo_region_translate (window->input_shape, offset_x, offset_y);
7548 window->input_shape = NULL;
7550 if (gdk_window_has_impl (window))
7552 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7553 impl_class->input_shape_combine_region (window, window->input_shape, 0, 0);
7556 /* Pointer may have e.g. moved outside window due to the input mask change */
7557 _gdk_synthesize_crossing_events_for_geometry_change (window);
7561 do_child_input_shapes (GdkWindow *window,
7565 cairo_region_t *region;
7569 r.width = window->width;
7570 r.height = window->height;
7572 region = cairo_region_create_rectangle (&r);
7573 remove_child_area (window, NULL, TRUE, region, NULL);
7575 if (merge && window->shape)
7576 cairo_region_subtract (region, window->shape);
7577 if (merge && window->input_shape)
7578 cairo_region_subtract (region, window->input_shape);
7580 gdk_window_input_shape_combine_region (window, region, 0, 0);
7585 * gdk_window_set_child_input_shapes:
7586 * @window: a #GdkWindow
7588 * Sets the input shape mask of @window to the union of input shape masks
7589 * for all children of @window, ignoring the input shape mask of @window
7590 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
7591 * the input shape mask of @window in the masks to be merged.
7596 gdk_window_set_child_input_shapes (GdkWindow *window)
7598 g_return_if_fail (GDK_IS_WINDOW (window));
7600 do_child_input_shapes (window, FALSE);
7604 * gdk_window_merge_child_input_shapes:
7605 * @window: a #GdkWindow
7607 * Merges the input shape masks for any child windows into the
7608 * input shape mask for @window. i.e. the union of all input masks
7609 * for @window and its children will become the new input mask
7610 * for @window. See gdk_window_input_shape_combine_region().
7612 * This function is distinct from gdk_window_set_child_input_shapes()
7613 * because it includes @window's input shape mask in the set of
7614 * shapes to be merged.
7619 gdk_window_merge_child_input_shapes (GdkWindow *window)
7621 g_return_if_fail (GDK_IS_WINDOW (window));
7623 do_child_input_shapes (window, TRUE);
7628 * gdk_window_set_static_gravities:
7629 * @window: a #GdkWindow
7630 * @use_static: %TRUE to turn on static gravity
7632 * Set the bit gravity of the given window to static, and flag it so
7633 * all children get static subwindow gravity. This is used if you are
7634 * implementing scary features that involve deep knowledge of the
7635 * windowing system. Don't worry about it unless you have to.
7637 * Return value: %TRUE if the server supports static gravity
7640 gdk_window_set_static_gravities (GdkWindow *window,
7641 gboolean use_static)
7643 GdkWindowImplClass *impl_class;
7645 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7647 if (gdk_window_has_impl (window))
7649 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7650 return impl_class->set_static_gravities (window, use_static);
7657 * gdk_window_get_composited:
7658 * @window: a #GdkWindow
7660 * Determines whether @window is composited.
7662 * See gdk_window_set_composited().
7664 * Returns: %TRUE if the window is composited.
7669 gdk_window_get_composited (GdkWindow *window)
7671 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7673 return window->composited;
7677 * gdk_window_set_composited:
7678 * @window: a #GdkWindow
7679 * @composited: %TRUE to set the window as composited
7681 * Sets a #GdkWindow as composited, or unsets it. Composited
7682 * windows do not automatically have their contents drawn to
7683 * the screen. Drawing is redirected to an offscreen buffer
7684 * and an expose event is emitted on the parent of the composited
7685 * window. It is the responsibility of the parent's expose handler
7686 * to manually merge the off-screen content onto the screen in
7687 * whatever way it sees fit. See <xref linkend="composited-window-example"/>
7690 * It only makes sense for child windows to be composited; see
7691 * gdk_window_set_opacity() if you need translucent toplevel
7694 * An additional effect of this call is that the area of this
7695 * window is no longer clipped from regions marked for
7696 * invalidation on its parent. Draws done on the parent
7697 * window are also no longer clipped by the child.
7699 * This call is only supported on some systems (currently,
7700 * only X11 with new enough Xcomposite and Xdamage extensions).
7701 * You must call gdk_display_supports_composite() to check if
7702 * setting a window as composited is supported before
7703 * attempting to do so.
7708 gdk_window_set_composited (GdkWindow *window,
7709 gboolean composited)
7711 GdkDisplay *display;
7712 GdkWindowImplClass *impl_class;
7714 g_return_if_fail (GDK_IS_WINDOW (window));
7716 composited = composited != FALSE;
7718 if (window->composited == composited)
7722 gdk_window_ensure_native (window);
7724 display = gdk_window_get_display (window);
7726 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
7728 if (composited && (!gdk_display_supports_composite (display) || !impl_class->set_composited))
7730 g_warning ("gdk_window_set_composited called but "
7731 "compositing is not supported");
7735 impl_class->set_composited (window, composited);
7737 recompute_visible_regions (window, TRUE, FALSE);
7739 if (GDK_WINDOW_IS_MAPPED (window))
7740 gdk_window_invalidate_in_parent (window);
7742 window->composited = composited;
7746 * gdk_window_get_modal_hint:
7747 * @window: A toplevel #GdkWindow.
7749 * Determines whether or not the window manager is hinted that @window
7750 * has modal behaviour.
7752 * Return value: whether or not the window has the modal hint set.
7757 gdk_window_get_modal_hint (GdkWindow *window)
7759 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7761 return window->modal_hint;
7765 * gdk_window_get_accept_focus:
7766 * @window: a toplevel #GdkWindow.
7768 * Determines whether or not the desktop environment shuld be hinted that
7769 * the window does not want to receive input focus.
7771 * Return value: whether or not the window should receive input focus.
7776 gdk_window_get_accept_focus (GdkWindow *window)
7778 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7780 return window->accept_focus;
7784 * gdk_window_get_focus_on_map:
7785 * @window: a toplevel #GdkWindow.
7787 * Determines whether or not the desktop environment should be hinted that the
7788 * window does not want to receive input focus when it is mapped.
7790 * Return value: whether or not the window wants to receive input focus when
7796 gdk_window_get_focus_on_map (GdkWindow *window)
7798 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7800 return window->focus_on_map;
7804 * gdk_window_is_input_only:
7805 * @window: a toplevel #GdkWindow
7807 * Determines whether or not the window is an input only window.
7809 * Return value: %TRUE if @window is input only
7814 gdk_window_is_input_only (GdkWindow *window)
7816 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7818 return window->input_only;
7822 * gdk_window_is_shaped:
7823 * @window: a toplevel #GdkWindow
7825 * Determines whether or not the window is shaped.
7827 * Return value: %TRUE if @window is shaped
7832 gdk_window_is_shaped (GdkWindow *window)
7834 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
7836 return window->shaped;
7840 _gdk_window_add_damage (GdkWindow *toplevel,
7841 cairo_region_t *damaged_region)
7843 GdkDisplay *display;
7844 GdkEvent event = { 0, };
7845 event.expose.type = GDK_DAMAGE;
7846 event.expose.window = toplevel;
7847 event.expose.send_event = FALSE;
7848 event.expose.region = damaged_region;
7849 cairo_region_get_extents (event.expose.region, &event.expose.area);
7850 display = gdk_window_get_display (event.expose.window);
7851 _gdk_event_queue_append (display, gdk_event_copy (&event));
7854 /* Gets the toplevel for a window as used for events,
7855 i.e. including offscreen parents */
7857 get_event_parent (GdkWindow *window)
7859 if (gdk_window_is_offscreen (window))
7860 return gdk_offscreen_window_get_embedder ((GdkWindow *)window);
7862 return window->parent;
7865 /* Gets the toplevel for a window as used for events,
7866 i.e. including offscreen parents going up to the native
7869 get_event_toplevel (GdkWindow *window)
7873 while ((parent = get_event_parent (window)) != NULL &&
7874 (parent->window_type != GDK_WINDOW_ROOT))
7881 _gdk_window_event_parent_of (GdkWindow *parent,
7892 w = get_event_parent (w);
7899 update_cursor (GdkDisplay *display,
7902 GdkWindow *cursor_window, *parent, *toplevel;
7903 GdkWindow *pointer_window;
7904 GdkWindowImplClass *impl_class;
7905 GdkPointerWindowInfo *pointer_info;
7906 GdkDeviceGrabInfo *grab;
7909 pointer_info = _gdk_display_get_pointer_info (display, device);
7910 pointer_window = pointer_info->window_under_pointer;
7912 /* We ignore the serials here and just pick the last grab
7913 we've sent, as that would shortly be used anyway. */
7914 grab = _gdk_display_get_last_device_grab (display, device);
7917 /* the pointer is not in a descendant of the grab window */
7918 !_gdk_window_event_parent_of (grab->window, pointer_window))
7920 /* use the cursor from the grab window */
7921 cursor_window = grab->window;
7925 /* otherwise use the cursor from the pointer window */
7926 cursor_window = pointer_window;
7929 /* Find the first window with the cursor actually set, as
7930 the cursor is inherited from the parent */
7931 while (cursor_window->cursor == NULL &&
7932 (parent = get_event_parent (cursor_window)) != NULL &&
7933 parent->window_type != GDK_WINDOW_ROOT)
7934 cursor_window = parent;
7936 cursor = g_hash_table_lookup (cursor_window->device_cursor, device);
7939 cursor = cursor_window->cursor;
7941 /* Set all cursors on toplevel, otherwise its tricky to keep track of
7942 * which native window has what cursor set. */
7943 toplevel = get_event_toplevel (pointer_window);
7944 impl_class = GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl);
7945 impl_class->set_device_cursor (toplevel, device, cursor);
7949 point_in_window (GdkWindow *window,
7954 x >= 0 && x < window->width &&
7955 y >= 0 && y < window->height &&
7956 (window->shape == NULL ||
7957 cairo_region_contains_point (window->shape,
7959 (window->input_shape == NULL ||
7960 cairo_region_contains_point (window->input_shape,
7965 convert_native_coords_to_toplevel (GdkWindow *window,
7968 gdouble *toplevel_x,
7969 gdouble *toplevel_y)
7976 while (!gdk_window_is_toplevel (window))
7980 window = window->parent;
7990 convert_toplevel_coords_to_window (GdkWindow *window,
7998 GList *children, *l;
8004 while ((parent = get_event_parent (window)) != NULL &&
8005 (parent->window_type != GDK_WINDOW_ROOT))
8007 children = g_list_prepend (children, window);
8011 for (l = children; l != NULL; l = l->next)
8012 gdk_window_coords_from_parent (l->data, x, y, &x, &y);
8014 g_list_free (children);
8021 pick_embedded_child (GdkWindow *window,
8028 g_signal_emit (window,
8029 signals[PICK_EMBEDDED_CHILD], 0,
8036 _gdk_window_find_child_at (GdkWindow *window,
8041 double child_x, child_y;
8044 if (point_in_window (window, x, y))
8046 /* Children is ordered in reverse stack order, i.e. first is topmost */
8047 for (l = window->children; l != NULL; l = l->next)
8051 if (!GDK_WINDOW_IS_MAPPED (sub))
8054 gdk_window_coords_from_parent ((GdkWindow *)sub,
8056 &child_x, &child_y);
8057 if (point_in_window (sub, child_x, child_y))
8058 return (GdkWindow *)sub;
8061 if (window->num_offscreen_children > 0)
8063 sub = pick_embedded_child (window,
8066 return (GdkWindow *)sub;
8074 _gdk_window_find_descendant_at (GdkWindow *window,
8081 gdouble child_x, child_y;
8085 if (point_in_window (window, x, y))
8090 /* Children is ordered in reverse stack order, i.e. first is topmost */
8091 for (l = window->children; l != NULL; l = l->next)
8095 if (!GDK_WINDOW_IS_MAPPED (sub))
8098 gdk_window_coords_from_parent ((GdkWindow *)sub,
8100 &child_x, &child_y);
8101 if (point_in_window (sub, child_x, child_y))
8111 window->num_offscreen_children > 0)
8113 sub = pick_embedded_child (window,
8119 from_embedder (sub, x, y, &x, &y);
8127 /* Not in window at all */
8141 * @window: a toplevel #GdkWindow
8143 * Emits a short beep associated to @window in the appropriate
8144 * display, if supported. Otherwise, emits a short beep on
8145 * the display just as gdk_display_beep().
8150 gdk_window_beep (GdkWindow *window)
8152 GdkDisplay *display;
8153 GdkWindow *toplevel;
8155 g_return_if_fail (GDK_IS_WINDOW (window));
8157 if (GDK_WINDOW_DESTROYED (window))
8160 toplevel = get_event_toplevel (window);
8161 display = gdk_window_get_display (window);
8165 if (GDK_WINDOW_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
8169 /* If windows fail to beep, we beep the display. */
8170 gdk_display_beep (display);
8174 * gdk_window_set_support_multidevice:
8175 * @window: a #GdkWindow.
8176 * @support_multidevice: %TRUE to enable multidevice support in @window.
8178 * This function will enable multidevice features in @window.
8180 * Multidevice aware windows will need to handle properly multiple,
8181 * per device enter/leave events, device grabs and grab ownerships.
8186 gdk_window_set_support_multidevice (GdkWindow *window,
8187 gboolean support_multidevice)
8189 g_return_if_fail (GDK_IS_WINDOW (window));
8191 if (GDK_WINDOW_DESTROYED (window))
8194 if (window->support_multidevice == support_multidevice)
8197 window->support_multidevice = support_multidevice;
8199 /* FIXME: What to do if called when some pointers are inside the window ? */
8203 * gdk_window_get_support_multidevice:
8204 * @window: a #GdkWindow.
8206 * Returns %TRUE if the window is aware of the existence of multiple
8209 * Returns: %TRUE if the window handles multidevice features.
8214 gdk_window_get_support_multidevice (GdkWindow *window)
8216 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
8218 if (GDK_WINDOW_DESTROYED (window))
8221 return window->support_multidevice;
8224 static const guint type_masks[] = {
8225 GDK_SUBSTRUCTURE_MASK, /* GDK_DELETE = 0 */
8226 GDK_STRUCTURE_MASK, /* GDK_DESTROY = 1 */
8227 GDK_EXPOSURE_MASK, /* GDK_EXPOSE = 2 */
8228 GDK_POINTER_MOTION_MASK, /* GDK_MOTION_NOTIFY = 3 */
8229 GDK_BUTTON_PRESS_MASK, /* GDK_BUTTON_PRESS = 4 */
8230 GDK_BUTTON_PRESS_MASK, /* GDK_2BUTTON_PRESS = 5 */
8231 GDK_BUTTON_PRESS_MASK, /* GDK_3BUTTON_PRESS = 6 */
8232 GDK_BUTTON_RELEASE_MASK, /* GDK_BUTTON_RELEASE = 7 */
8233 GDK_KEY_PRESS_MASK, /* GDK_KEY_PRESS = 8 */
8234 GDK_KEY_RELEASE_MASK, /* GDK_KEY_RELEASE = 9 */
8235 GDK_ENTER_NOTIFY_MASK, /* GDK_ENTER_NOTIFY = 10 */
8236 GDK_LEAVE_NOTIFY_MASK, /* GDK_LEAVE_NOTIFY = 11 */
8237 GDK_FOCUS_CHANGE_MASK, /* GDK_FOCUS_CHANGE = 12 */
8238 GDK_STRUCTURE_MASK, /* GDK_CONFIGURE = 13 */
8239 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_MAP = 14 */
8240 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_UNMAP = 15 */
8241 GDK_PROPERTY_CHANGE_MASK, /* GDK_PROPERTY_NOTIFY = 16 */
8242 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_CLEAR = 17 */
8243 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_REQUEST = 18 */
8244 GDK_PROPERTY_CHANGE_MASK, /* GDK_SELECTION_NOTIFY = 19 */
8245 GDK_PROXIMITY_IN_MASK, /* GDK_PROXIMITY_IN = 20 */
8246 GDK_PROXIMITY_OUT_MASK, /* GDK_PROXIMITY_OUT = 21 */
8247 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_ENTER = 22 */
8248 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_LEAVE = 23 */
8249 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_MOTION = 24 */
8250 GDK_ALL_EVENTS_MASK, /* GDK_DRAG_STATUS = 25 */
8251 GDK_ALL_EVENTS_MASK, /* GDK_DROP_START = 26 */
8252 GDK_ALL_EVENTS_MASK, /* GDK_DROP_FINISHED = 27 */
8253 GDK_ALL_EVENTS_MASK, /* GDK_CLIENT_EVENT = 28 */
8254 GDK_VISIBILITY_NOTIFY_MASK, /* GDK_VISIBILITY_NOTIFY = 29 */
8255 GDK_EXPOSURE_MASK, /* GDK_NO_EXPOSE = 30 */
8256 GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK,/* GDK_SCROLL= 31 */
8257 0, /* GDK_WINDOW_STATE = 32 */
8258 0, /* GDK_SETTING = 33 */
8259 0, /* GDK_OWNER_CHANGE = 34 */
8260 0, /* GDK_GRAB_BROKEN = 35 */
8261 0, /* GDK_DAMAGE = 36 */
8262 GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */
8263 GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */
8264 GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */
8265 GDK_TOUCH_MASK /* GDK_TOUCH_CANCEL = 40 */
8267 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
8269 /* send motion events if the right buttons are down */
8271 update_evmask_for_button_motion (guint evmask,
8272 GdkModifierType mask)
8274 if (evmask & GDK_BUTTON_MOTION_MASK &&
8275 mask & (GDK_BUTTON1_MASK |
8280 evmask |= GDK_POINTER_MOTION_MASK;
8282 if ((evmask & GDK_BUTTON1_MOTION_MASK && mask & GDK_BUTTON1_MASK) ||
8283 (evmask & GDK_BUTTON2_MOTION_MASK && mask & GDK_BUTTON2_MASK) ||
8284 (evmask & GDK_BUTTON3_MOTION_MASK && mask & GDK_BUTTON3_MASK))
8285 evmask |= GDK_POINTER_MOTION_MASK;
8291 is_button_type (GdkEventType type)
8293 return type == GDK_BUTTON_PRESS ||
8294 type == GDK_2BUTTON_PRESS ||
8295 type == GDK_3BUTTON_PRESS ||
8296 type == GDK_BUTTON_RELEASE ||
8297 type == GDK_TOUCH_BEGIN ||
8298 type == GDK_TOUCH_END ||
8303 is_motion_type (GdkEventType type)
8305 return type == GDK_MOTION_NOTIFY ||
8306 type == GDK_TOUCH_UPDATE ||
8307 type == GDK_ENTER_NOTIFY ||
8308 type == GDK_LEAVE_NOTIFY;
8312 is_touch_type (GdkEventType type)
8314 return type == GDK_TOUCH_BEGIN ||
8315 type == GDK_TOUCH_UPDATE ||
8316 type == GDK_TOUCH_END ||
8317 type == GDK_TOUCH_CANCEL;
8321 find_common_ancestor (GdkWindow *win1,
8325 GList *path1 = NULL, *path2 = NULL;
8326 GList *list1, *list2;
8329 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8331 path1 = g_list_prepend (path1, tmp);
8332 tmp = get_event_parent (tmp);
8336 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
8338 path2 = g_list_prepend (path2, tmp);
8339 tmp = get_event_parent (tmp);
8345 while (list1 && list2 && (list1->data == list2->data))
8348 list1 = g_list_next (list1);
8349 list2 = g_list_next (list2);
8351 g_list_free (path1);
8352 g_list_free (path2);
8358 _gdk_make_event (GdkWindow *window,
8360 GdkEvent *event_in_queue,
8361 gboolean before_event)
8363 GdkEvent *event = gdk_event_new (type);
8365 GdkModifierType the_state;
8367 the_time = gdk_event_get_time (event_in_queue);
8368 gdk_event_get_state (event_in_queue, &the_state);
8370 event->any.window = g_object_ref (window);
8371 event->any.send_event = FALSE;
8372 if (event_in_queue && event_in_queue->any.send_event)
8373 event->any.send_event = TRUE;
8377 case GDK_MOTION_NOTIFY:
8378 event->motion.time = the_time;
8379 event->motion.axes = NULL;
8380 event->motion.state = the_state;
8383 case GDK_BUTTON_PRESS:
8384 case GDK_2BUTTON_PRESS:
8385 case GDK_3BUTTON_PRESS:
8386 case GDK_BUTTON_RELEASE:
8387 event->button.time = the_time;
8388 event->button.axes = NULL;
8389 event->button.state = the_state;
8392 case GDK_TOUCH_BEGIN:
8393 case GDK_TOUCH_UPDATE:
8395 case GDK_TOUCH_CANCEL:
8396 event->touch.time = the_time;
8397 event->touch.axes = NULL;
8398 event->touch.state = the_state;
8402 event->scroll.time = the_time;
8403 event->scroll.state = the_state;
8407 case GDK_KEY_RELEASE:
8408 event->key.time = the_time;
8409 event->key.state = the_state;
8412 case GDK_ENTER_NOTIFY:
8413 case GDK_LEAVE_NOTIFY:
8414 event->crossing.time = the_time;
8415 event->crossing.state = the_state;
8418 case GDK_PROPERTY_NOTIFY:
8419 event->property.time = the_time;
8420 event->property.state = the_state;
8423 case GDK_SELECTION_CLEAR:
8424 case GDK_SELECTION_REQUEST:
8425 case GDK_SELECTION_NOTIFY:
8426 event->selection.time = the_time;
8429 case GDK_PROXIMITY_IN:
8430 case GDK_PROXIMITY_OUT:
8431 event->proximity.time = the_time;
8434 case GDK_DRAG_ENTER:
8435 case GDK_DRAG_LEAVE:
8436 case GDK_DRAG_MOTION:
8437 case GDK_DRAG_STATUS:
8438 case GDK_DROP_START:
8439 case GDK_DROP_FINISHED:
8440 event->dnd.time = the_time;
8443 case GDK_FOCUS_CHANGE:
8447 case GDK_CLIENT_EVENT:
8448 case GDK_VISIBILITY_NOTIFY:
8459 _gdk_event_queue_insert_before (gdk_window_get_display (window), event_in_queue, event);
8461 _gdk_event_queue_insert_after (gdk_window_get_display (window), event_in_queue, event);
8464 _gdk_event_queue_append (gdk_window_get_display (window), event);
8470 send_crossing_event (GdkDisplay *display,
8471 GdkWindow *toplevel,
8474 GdkCrossingMode mode,
8475 GdkNotifyType notify_type,
8476 GdkWindow *subwindow,
8478 GdkDevice *source_device,
8481 GdkModifierType mask,
8483 GdkEvent *event_in_queue,
8487 guint32 window_event_mask, type_event_mask;
8488 GdkDeviceGrabInfo *grab;
8489 GdkTouchGrabInfo *touch_grab = NULL;
8490 GdkPointerWindowInfo *pointer_info;
8491 gboolean block_event = FALSE;
8492 GdkEventSequence *sequence;
8494 grab = _gdk_display_has_device_grab (display, device, serial);
8495 pointer_info = _gdk_display_get_pointer_info (display, device);
8497 sequence = gdk_event_get_event_sequence (event_in_queue);
8499 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
8503 if (window != touch_grab->window)
8506 window_event_mask = touch_grab->event_mask;
8508 else if (grab != NULL &&
8509 !grab->owner_events)
8511 /* !owner_event => only report events wrt grab window, ignore rest */
8512 if ((GdkWindow *)window != grab->window)
8514 window_event_mask = grab->event_mask;
8517 window_event_mask = window->event_mask;
8519 if (type == GDK_ENTER_NOTIFY &&
8520 (pointer_info->need_touch_press_enter ||
8521 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN) &&
8522 mode != GDK_CROSSING_TOUCH_BEGIN &&
8523 mode != GDK_CROSSING_TOUCH_END)
8525 pointer_info->need_touch_press_enter = TRUE;
8528 else if (type == GDK_LEAVE_NOTIFY)
8530 type_event_mask = GDK_LEAVE_NOTIFY_MASK;
8531 window->devices_inside = g_list_remove (window->devices_inside, device);
8533 if (!window->support_multidevice && window->devices_inside)
8535 /* Block leave events unless it's the last pointer */
8541 type_event_mask = GDK_ENTER_NOTIFY_MASK;
8543 if (!window->support_multidevice && window->devices_inside)
8545 /* Only emit enter events for the first device */
8549 if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER &&
8550 gdk_device_get_mode (device) != GDK_MODE_DISABLED &&
8551 !g_list_find (window->devices_inside, device))
8552 window->devices_inside = g_list_prepend (window->devices_inside, device);
8558 if (window_event_mask & type_event_mask)
8560 event = _gdk_make_event ((GdkWindow *)window, type, event_in_queue, TRUE);
8561 gdk_event_set_device (event, device);
8564 gdk_event_set_source_device (event, source_device);
8566 event->crossing.time = time_;
8567 event->crossing.subwindow = subwindow;
8569 g_object_ref (subwindow);
8570 convert_toplevel_coords_to_window ((GdkWindow *)window,
8571 toplevel_x, toplevel_y,
8572 &event->crossing.x, &event->crossing.y);
8573 event->crossing.x_root = toplevel_x + toplevel->x;
8574 event->crossing.y_root = toplevel_y + toplevel->y;
8575 event->crossing.mode = mode;
8576 event->crossing.detail = notify_type;
8577 event->crossing.focus = FALSE;
8578 event->crossing.state = mask;
8583 /* The coordinates are in the toplevel window that src/dest are in.
8584 * src and dest are always (if != NULL) in the same toplevel, as
8585 * we get a leave-notify and set the window_under_pointer to null
8586 * before crossing to another toplevel.
8589 _gdk_synthesize_crossing_events (GdkDisplay *display,
8593 GdkDevice *source_device,
8594 GdkCrossingMode mode,
8597 GdkModifierType mask,
8599 GdkEvent *event_in_queue,
8601 gboolean non_linear)
8604 GdkWindow *win, *last, *next;
8608 GdkWindow *toplevel;
8609 GdkNotifyType notify_type;
8611 /* TODO: Don't send events to toplevel, as we get those from the windowing system */
8616 return; /* No crossings generated between src and dest */
8618 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
8620 if (a && gdk_window_get_device_events (src, device) == 0)
8623 if (b && gdk_window_get_device_events (dest, device) == 0)
8630 c = find_common_ancestor (a, b);
8632 non_linear |= (c != a) && (c != b);
8634 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
8636 toplevel = gdk_window_get_toplevel (a);
8638 /* Traverse up from a to (excluding) c sending leave events */
8640 notify_type = GDK_NOTIFY_NONLINEAR;
8642 notify_type = GDK_NOTIFY_INFERIOR;
8644 notify_type = GDK_NOTIFY_ANCESTOR;
8645 send_crossing_event (display, toplevel,
8646 a, GDK_LEAVE_NOTIFY,
8649 NULL, device, source_device,
8650 toplevel_x, toplevel_y,
8658 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8660 notify_type = GDK_NOTIFY_VIRTUAL;
8663 win = get_event_parent (a);
8664 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8666 send_crossing_event (display, toplevel,
8667 win, GDK_LEAVE_NOTIFY,
8671 device, source_device,
8672 toplevel_x, toplevel_y,
8678 win = get_event_parent (win);
8683 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
8685 toplevel = gdk_window_get_toplevel ((GdkWindow *)b);
8687 /* Traverse down from c to b */
8691 win = get_event_parent (b);
8692 while (win != c && win->window_type != GDK_WINDOW_ROOT)
8694 path = g_list_prepend (path, win);
8695 win = get_event_parent (win);
8699 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
8701 notify_type = GDK_NOTIFY_VIRTUAL;
8707 list = g_list_next (list);
8713 send_crossing_event (display, toplevel,
8714 win, GDK_ENTER_NOTIFY,
8718 device, source_device,
8719 toplevel_x, toplevel_y,
8729 notify_type = GDK_NOTIFY_NONLINEAR;
8731 notify_type = GDK_NOTIFY_ANCESTOR;
8733 notify_type = GDK_NOTIFY_INFERIOR;
8735 send_crossing_event (display, toplevel,
8736 b, GDK_ENTER_NOTIFY,
8740 device, source_device,
8741 toplevel_x, toplevel_y,
8748 /* Returns the window inside the event window with the pointer in it
8749 * at the specified coordinates, or NULL if its not in any child of
8750 * the toplevel. It also takes into account !owner_events grabs.
8753 get_pointer_window (GdkDisplay *display,
8754 GdkWindow *event_window,
8760 GdkWindow *pointer_window;
8761 GdkDeviceGrabInfo *grab;
8762 GdkPointerWindowInfo *pointer_info;
8764 pointer_info = _gdk_display_get_pointer_info (display, device);
8766 if (event_window == pointer_info->toplevel_under_pointer)
8768 _gdk_window_find_descendant_at (event_window,
8769 toplevel_x, toplevel_y,
8772 pointer_window = NULL;
8774 grab = _gdk_display_has_device_grab (display, device, serial);
8776 !grab->owner_events &&
8777 pointer_window != grab->window)
8778 pointer_window = NULL;
8780 return pointer_window;
8784 _gdk_display_set_window_under_pointer (GdkDisplay *display,
8788 GdkPointerWindowInfo *device_info;
8790 device_info = _gdk_display_get_pointer_info (display, device);
8792 if (device_info->window_under_pointer)
8793 g_object_unref (device_info->window_under_pointer);
8794 device_info->window_under_pointer = window;
8798 g_object_ref (window);
8799 update_cursor (display, device);
8802 _gdk_display_enable_motion_hints (display, device);
8807 * @window: the #GdkWindow which will own the grab (the grab window).
8808 * @owner_events: if %FALSE then all pointer events are reported with respect to
8809 * @window and are only reported if selected by @event_mask. If %TRUE then pointer
8810 * events for this application are reported as normal, but pointer events outside
8811 * this application are reported with respect to @window and only if selected by
8812 * @event_mask. In either mode, unreported events are discarded.
8813 * @event_mask: specifies the event mask, which is used in accordance with
8814 * @owner_events. Note that only pointer events (i.e. button and motion events)
8816 * @confine_to: (allow-none): If non-%NULL, the pointer will be confined to this
8817 * window during the grab. If the pointer is outside @confine_to, it will
8818 * automatically be moved to the closest edge of @confine_to and enter
8819 * and leave events will be generated as necessary.
8820 * @cursor: (allow-none): the cursor to display while the grab is active. If this is %NULL then
8821 * the normal cursors are used for @window and its descendants, and the cursor
8822 * for @window is used for all other windows.
8823 * @time_: the timestamp of the event which led to this pointer grab. This usually
8824 * comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
8825 * the time isn't known.
8827 * Grabs the pointer (usually a mouse) so that all events are passed to this
8828 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
8829 * the grab window becomes unviewable.
8830 * This overrides any previous pointer grab by this client.
8832 * Pointer grabs are used for operations which need complete control over mouse
8833 * events, even if the mouse leaves the application.
8834 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
8835 * the #GtkHPaned and #GtkVPaned widgets.
8837 * Note that if the event mask of an X window has selected both button press and
8838 * button release events, then a button press event will cause an automatic
8839 * pointer grab until the button is released.
8840 * X does this automatically since most applications expect to receive button
8841 * press and release events in pairs.
8842 * It is equivalent to a pointer grab on the window with @owner_events set to
8845 * If you set up anything at the time you take the grab that needs to be cleaned
8846 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8847 * are emitted when the grab ends unvoluntarily.
8849 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8851 * Deprecated: 3.0: Use gdk_device_grab() instead.
8854 gdk_pointer_grab (GdkWindow * window,
8855 gboolean owner_events,
8856 GdkEventMask event_mask,
8857 GdkWindow * confine_to,
8862 GdkDisplay *display;
8863 GdkDeviceManager *device_manager;
8865 GdkGrabStatus res = 0;
8867 GList *devices, *dev;
8869 g_return_val_if_fail (window != NULL, 0);
8870 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8871 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
8873 /* We need a native window for confine to to work, ensure we have one */
8876 if (!gdk_window_ensure_native (confine_to))
8878 g_warning ("Can't confine to grabbed window, not native");
8883 /* Non-viewable client side window => fail */
8884 if (!_gdk_window_has_impl (window) &&
8885 !gdk_window_is_viewable (window))
8886 return GDK_GRAB_NOT_VIEWABLE;
8888 native = gdk_window_get_toplevel (window);
8889 while (gdk_window_is_offscreen (native))
8891 native = gdk_offscreen_window_get_embedder (native);
8893 if (native == NULL ||
8894 (!_gdk_window_has_impl (native) &&
8895 !gdk_window_is_viewable (native)))
8896 return GDK_GRAB_NOT_VIEWABLE;
8898 native = gdk_window_get_toplevel (native);
8901 display = gdk_window_get_display (window);
8903 serial = _gdk_display_get_next_serial (display);
8904 device_manager = gdk_display_get_device_manager (display);
8905 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
8907 /* FIXME: Should this be generic to all backends? */
8908 /* FIXME: What happens with extended devices? */
8909 for (dev = devices; dev; dev = dev->next)
8913 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
8916 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
8919 get_native_grab_event_mask (event_mask),
8924 if (res == GDK_GRAB_SUCCESS)
8925 _gdk_display_add_device_grab (display,
8937 /* FIXME: handle errors when grabbing */
8939 g_list_free (devices);
8945 * gdk_keyboard_grab:
8946 * @window: the #GdkWindow which will own the grab (the grab window).
8947 * @owner_events: if %FALSE then all keyboard events are reported with respect to
8948 * @window. If %TRUE then keyboard events for this application are
8949 * reported as normal, but keyboard events outside this application
8950 * are reported with respect to @window. Both key press and key
8951 * release events are always reported, independant of the event mask
8952 * set by the application.
8953 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
8956 * Grabs the keyboard so that all events are passed to this
8957 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
8958 * This overrides any previous keyboard grab by this client.
8960 * If you set up anything at the time you take the grab that needs to be cleaned
8961 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
8962 * are emitted when the grab ends unvoluntarily.
8964 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
8966 * Deprecated: 3.0: Use gdk_device_grab() instead.
8969 gdk_keyboard_grab (GdkWindow *window,
8970 gboolean owner_events,
8974 GdkDisplay *display;
8975 GdkDeviceManager *device_manager;
8977 GdkGrabStatus res = 0;
8979 GList *devices, *dev;
8981 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8983 /* Non-viewable client side window => fail */
8984 if (!_gdk_window_has_impl (window) &&
8985 !gdk_window_is_viewable (window))
8986 return GDK_GRAB_NOT_VIEWABLE;
8988 native = gdk_window_get_toplevel (window);
8990 while (gdk_window_is_offscreen (native))
8992 native = gdk_offscreen_window_get_embedder (native);
8994 if (native == NULL ||
8995 (!_gdk_window_has_impl (native) &&
8996 !gdk_window_is_viewable (native)))
8997 return GDK_GRAB_NOT_VIEWABLE;
8999 native = gdk_window_get_toplevel (native);
9002 display = gdk_window_get_display (window);
9003 serial = _gdk_display_get_next_serial (display);
9004 device_manager = gdk_display_get_device_manager (display);
9005 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
9007 /* FIXME: Should this be generic to all backends? */
9008 /* FIXME: What happens with extended devices? */
9009 for (dev = devices; dev; dev = dev->next)
9013 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
9016 res = GDK_DEVICE_GET_CLASS (device)->grab (device,
9019 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
9024 if (res == GDK_GRAB_SUCCESS)
9025 _gdk_display_add_device_grab (display,
9036 /* FIXME: handle errors when grabbing */
9038 g_list_free (devices);
9044 * gdk_window_geometry_changed:
9045 * @window: an embedded offscreen #GdkWindow
9047 * This function informs GDK that the geometry of an embedded
9048 * offscreen window has changed. This is necessary for GDK to keep
9049 * track of which offscreen window the pointer is in.
9054 gdk_window_geometry_changed (GdkWindow *window)
9056 _gdk_synthesize_crossing_events_for_geometry_change (window);
9060 source_events_device_added (GdkDeviceManager *device_manager,
9065 GdkEventMask event_mask;
9066 GdkInputSource source;
9068 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_FLOATING)
9072 source = gdk_device_get_source (device);
9074 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
9075 GINT_TO_POINTER (source)));
9077 gdk_window_set_device_events (window, device, event_mask);
9081 source_events_device_changed (GdkDeviceManager *device_manager,
9086 GdkInputSource source;
9087 GdkEventMask event_mask;
9091 type = gdk_device_get_device_type (device);
9092 source = gdk_device_get_source (device);
9094 event_mask = GPOINTER_TO_INT (g_hash_table_lookup (window->source_event_masks,
9095 GINT_TO_POINTER (source)));
9100 if (type == GDK_DEVICE_TYPE_FLOATING)
9102 /* The device was just floated, enable its event mask */
9103 gdk_window_set_device_events (window, device, event_mask);
9105 else if (type == GDK_DEVICE_TYPE_SLAVE)
9106 gdk_window_set_device_events (window, device, 0);
9110 * gdk_window_set_source_events:
9111 * @window: a #GdkWindow
9112 * @source: a #GdkInputSource to define the source class.
9113 * @event_mask: event mask for @window
9115 * Sets the event mask for any floating device (i.e. not attached to any
9116 * visible pointer) that has the source defined as @source. This event
9117 * mask will be applied both to currently existing, newly added devices
9118 * after this call, and devices being attached/detached.
9123 gdk_window_set_source_events (GdkWindow *window,
9124 GdkInputSource source,
9125 GdkEventMask event_mask)
9127 GdkDeviceManager *device_manager;
9128 GdkDisplay *display;
9132 g_return_if_fail (GDK_IS_WINDOW (window));
9134 display = gdk_window_get_display (window);
9135 device_manager = gdk_display_get_device_manager (display);
9137 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
9139 /* Set event mask for existing devices */
9140 for (d = devices; d; d = d->next)
9142 GdkDevice *device = d->data;
9144 if (source == gdk_device_get_source (device))
9145 gdk_window_set_device_events (window, device, event_mask);
9148 g_list_free (devices);
9150 /* Update accounting */
9151 if (G_UNLIKELY (!window->source_event_masks))
9152 window->source_event_masks = g_hash_table_new (NULL, NULL);
9155 g_hash_table_insert (window->source_event_masks,
9156 GUINT_TO_POINTER (source),
9157 GUINT_TO_POINTER (event_mask));
9159 g_hash_table_remove (window->source_event_masks,
9160 GUINT_TO_POINTER (source));
9162 size = g_hash_table_size (window->source_event_masks);
9164 /* Update handler if needed */
9165 if (!window->device_added_handler_id && size > 0)
9167 window->device_added_handler_id =
9168 g_signal_connect (device_manager, "device-added",
9169 G_CALLBACK (source_events_device_added), window);
9170 window->device_changed_handler_id =
9171 g_signal_connect (device_manager, "device-changed",
9172 G_CALLBACK (source_events_device_changed), window);
9174 else if (window->device_added_handler_id && size == 0)
9175 g_signal_handler_disconnect (device_manager, window->device_added_handler_id);
9179 * gdk_window_get_source_events:
9180 * @window: a #GdkWindow
9181 * @source: a #GdkInputSource to define the source class.
9183 * Returns the event mask for @window corresponding to the device class specified
9186 * Returns: source event mask for @window
9189 gdk_window_get_source_events (GdkWindow *window,
9190 GdkInputSource source)
9192 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
9194 return GPOINTER_TO_UINT (g_hash_table_lookup (window->source_event_masks,
9195 GUINT_TO_POINTER (source)));
9199 do_synthesize_crossing_event (gpointer data)
9201 GdkDisplay *display;
9202 GdkWindow *changed_toplevel;
9203 GHashTableIter iter;
9204 gpointer key, value;
9207 changed_toplevel = data;
9209 changed_toplevel->synthesize_crossing_event_queued = FALSE;
9211 if (GDK_WINDOW_DESTROYED (changed_toplevel))
9214 display = gdk_window_get_display (changed_toplevel);
9215 serial = _gdk_display_get_next_serial (display);
9216 g_hash_table_iter_init (&iter, display->pointers_info);
9218 while (g_hash_table_iter_next (&iter, &key, &value))
9220 GdkWindow *new_window_under_pointer;
9221 GdkPointerWindowInfo *pointer_info = value;
9222 GdkDevice *device = key;
9224 if (changed_toplevel == pointer_info->toplevel_under_pointer)
9226 new_window_under_pointer =
9227 get_pointer_window (display, changed_toplevel,
9229 pointer_info->toplevel_x,
9230 pointer_info->toplevel_y,
9232 if (new_window_under_pointer != pointer_info->window_under_pointer)
9234 GdkDevice *source_device;
9236 if (pointer_info->last_slave)
9237 source_device = pointer_info->last_slave;
9239 source_device = device;
9241 _gdk_synthesize_crossing_events (display,
9242 pointer_info->window_under_pointer,
9243 new_window_under_pointer,
9244 device, source_device,
9245 GDK_CROSSING_NORMAL,
9246 pointer_info->toplevel_x,
9247 pointer_info->toplevel_y,
9248 pointer_info->state,
9253 _gdk_display_set_window_under_pointer (display, device, new_window_under_pointer);
9262 _gdk_synthesize_crossing_events_for_geometry_change (GdkWindow *changed_window)
9264 GdkWindow *toplevel;
9266 toplevel = get_event_toplevel (changed_window);
9268 if (!toplevel->synthesize_crossing_event_queued)
9270 toplevel->synthesize_crossing_event_queued = TRUE;
9272 gdk_threads_add_idle_full (GDK_PRIORITY_EVENTS - 1,
9273 do_synthesize_crossing_event,
9274 g_object_ref (toplevel),
9279 /* Don't use for crossing events */
9281 get_event_window (GdkDisplay *display,
9283 GdkEventSequence *sequence,
9284 GdkWindow *pointer_window,
9286 GdkModifierType mask,
9288 gboolean pointer_emulated,
9291 guint evmask, emulated_mask = 0;
9292 GdkWindow *grab_window;
9293 GdkDeviceGrabInfo *grab;
9294 GdkTouchGrabInfo *touch_grab;
9296 touch_grab = _gdk_display_has_touch_grab (display, device, sequence, serial);
9297 grab = _gdk_display_get_last_device_grab (display, device);
9299 if (is_touch_type (type) && pointer_emulated)
9303 case GDK_TOUCH_BEGIN:
9304 emulated_mask |= GDK_BUTTON_PRESS_MASK;
9306 case GDK_TOUCH_UPDATE:
9307 emulated_mask |= GDK_POINTER_MOTION_MASK;
9310 emulated_mask |= GDK_BUTTON_RELEASE_MASK;
9316 if (touch_grab != NULL &&
9317 (!grab || grab->implicit || touch_grab->serial >= grab->serial_start))
9319 evmask = touch_grab->event_mask;
9320 evmask = update_evmask_for_button_motion (evmask, mask);
9322 if (evmask & (type_masks[type] | emulated_mask))
9325 *evmask_out = evmask;
9326 return touch_grab->window;
9332 if (grab != NULL && !grab->owner_events)
9334 evmask = grab->event_mask;
9335 evmask = update_evmask_for_button_motion (evmask, mask);
9337 grab_window = grab->window;
9339 if (evmask & (type_masks[type] | emulated_mask))
9342 *evmask_out = evmask;
9349 while (pointer_window != NULL)
9351 evmask = pointer_window->event_mask;
9352 evmask = update_evmask_for_button_motion (evmask, mask);
9354 if (evmask & (type_masks[type] | emulated_mask))
9357 *evmask_out = evmask;
9358 return pointer_window;
9361 pointer_window = get_event_parent (pointer_window);
9367 evmask = grab->event_mask;
9368 evmask = update_evmask_for_button_motion (evmask, mask);
9370 if (evmask & (type_masks[type] | emulated_mask))
9373 *evmask_out = evmask;
9374 return grab->window;
9384 proxy_pointer_event (GdkDisplay *display,
9385 GdkEvent *source_event,
9388 GdkWindow *toplevel_window, *event_window;
9389 GdkWindow *pointer_window;
9390 GdkPointerWindowInfo *pointer_info;
9391 GdkDevice *device, *source_device;
9394 gdouble toplevel_x, toplevel_y;
9396 gboolean non_linear, need_synthetic_enter = FALSE;
9399 event_type = source_event->type;
9400 event_window = source_event->any.window;
9401 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9402 gdk_event_get_state (source_event, &state);
9403 time_ = gdk_event_get_time (source_event);
9404 device = gdk_event_get_device (source_event);
9405 source_device = gdk_event_get_source_device (source_event);
9406 pointer_info = _gdk_display_get_pointer_info (display, device);
9407 toplevel_window = convert_native_coords_to_toplevel (event_window,
9408 toplevel_x, toplevel_y,
9409 &toplevel_x, &toplevel_y);
9412 if ((source_event->type == GDK_LEAVE_NOTIFY ||
9413 source_event->type == GDK_ENTER_NOTIFY) &&
9414 (source_event->crossing.detail == GDK_NOTIFY_NONLINEAR ||
9415 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))
9418 if (pointer_info->need_touch_press_enter &&
9419 gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCHSCREEN &&
9420 (source_event->type != GDK_TOUCH_UPDATE ||
9421 _gdk_event_get_pointer_emulated (source_event)))
9423 pointer_info->need_touch_press_enter = FALSE;
9424 need_synthetic_enter = TRUE;
9427 /* If we get crossing events with subwindow unexpectedly being NULL
9428 that means there is a native subwindow that gdk doesn't know about.
9429 We track these and forward them, with the correct virtual window
9431 This is important to get right, as metacity uses gdk for the frame
9432 windows, but gdk doesn't know about the client windows reparented
9434 if (((source_event->type == GDK_LEAVE_NOTIFY &&
9435 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9436 (source_event->type == GDK_ENTER_NOTIFY &&
9437 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9438 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9439 source_event->crossing.subwindow == NULL)
9441 /* Left for an unknown (to gdk) subwindow */
9443 /* Send leave events from window under pointer to event window
9444 that will get the subwindow == NULL window */
9445 _gdk_synthesize_crossing_events (display,
9446 pointer_info->window_under_pointer,
9448 device, source_device,
9449 source_event->crossing.mode,
9450 toplevel_x, toplevel_y,
9456 /* Send subwindow == NULL event */
9457 send_crossing_event (display,
9461 source_event->crossing.mode,
9462 source_event->crossing.detail,
9464 device, source_device,
9465 toplevel_x, toplevel_y,
9470 _gdk_display_set_window_under_pointer (display, device, NULL);
9474 pointer_window = get_pointer_window (display, toplevel_window, device,
9475 toplevel_x, toplevel_y, serial);
9477 if (((source_event->type == GDK_ENTER_NOTIFY &&
9478 source_event->crossing.detail == GDK_NOTIFY_INFERIOR) ||
9479 (source_event->type == GDK_LEAVE_NOTIFY &&
9480 (source_event->crossing.detail == GDK_NOTIFY_VIRTUAL ||
9481 source_event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL))) &&
9482 source_event->crossing.subwindow == NULL)
9484 /* Entered from an unknown (to gdk) subwindow */
9486 /* Send subwindow == NULL event */
9487 send_crossing_event (display,
9491 source_event->crossing.mode,
9492 source_event->crossing.detail,
9494 device, source_device,
9495 toplevel_x, toplevel_y,
9500 /* Send enter events from event window to pointer_window */
9501 _gdk_synthesize_crossing_events (display,
9504 device, source_device,
9505 source_event->crossing.mode,
9506 toplevel_x, toplevel_y,
9509 serial, non_linear);
9510 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9514 if ((source_event->type != GDK_TOUCH_UPDATE ||
9515 _gdk_event_get_pointer_emulated (source_event)) &&
9516 pointer_info->window_under_pointer != pointer_window)
9518 /* Either a toplevel crossing notify that ended up inside a child window,
9519 or a motion notify that got into another child window */
9521 /* Different than last time, send crossing events */
9522 _gdk_synthesize_crossing_events (display,
9523 pointer_info->window_under_pointer,
9525 device, source_device,
9526 GDK_CROSSING_NORMAL,
9527 toplevel_x, toplevel_y,
9530 serial, non_linear);
9531 _gdk_display_set_window_under_pointer (display, device, pointer_window);
9533 else if (source_event->type == GDK_MOTION_NOTIFY ||
9534 source_event->type == GDK_TOUCH_UPDATE)
9536 GdkWindow *event_win;
9539 GdkEventSequence *sequence;
9541 sequence = gdk_event_get_event_sequence (source_event);
9543 event_win = get_event_window (display,
9550 _gdk_event_get_pointer_emulated (source_event),
9553 if (event_type == GDK_TOUCH_UPDATE)
9555 if (_gdk_event_get_pointer_emulated (source_event))
9557 /* Touch events emulating pointer events are transformed back
9558 * to pointer events if:
9559 * 1 - The event window doesn't select for touch events
9560 * 2 - There's no touch grab for this sequence, which means
9561 * it was started as a pointer sequence, but a device
9562 * grab added touch events afterwards, the sequence must
9563 * not mutate in this case.
9565 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9566 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9567 event_type = GDK_MOTION_NOTIFY;
9569 else if ((evmask & GDK_TOUCH_MASK) == 0)
9573 if (is_touch_type (source_event->type) && !is_touch_type (event_type))
9574 state |= GDK_BUTTON1_MASK;
9577 gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9578 gdk_window_get_device_events (event_win, device) == 0)
9581 /* The last device to interact with the window was a touch device,
9582 * which synthesized a leave notify event, so synthesize another enter
9583 * notify to tell the pointer is on the window.
9585 if (need_synthetic_enter)
9586 _gdk_synthesize_crossing_events (display,
9587 NULL, pointer_window,
9588 device, source_device,
9589 GDK_CROSSING_DEVICE_SWITCH,
9590 toplevel_x, toplevel_y,
9597 event_type == GDK_MOTION_NOTIFY &&
9598 (evmask & GDK_POINTER_MOTION_HINT_MASK))
9600 gulong *device_serial;
9602 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
9604 if (!device_serial ||
9605 (*device_serial != 0 &&
9606 serial < *device_serial))
9607 event_win = NULL; /* Ignore event */
9611 *device_serial = G_MAXULONG;
9618 event = gdk_event_new (event_type);
9619 event->any.window = g_object_ref (event_win);
9620 event->any.send_event = source_event->any.send_event;
9622 gdk_event_set_device (event, gdk_event_get_device (source_event));
9623 gdk_event_set_source_device (event, source_device);
9625 if (event_type == GDK_TOUCH_UPDATE)
9627 event->touch.time = time_;
9628 event->touch.state = state | GDK_BUTTON1_MASK;
9629 event->touch.sequence = source_event->touch.sequence;
9630 event->touch.emulating_pointer = source_event->touch.emulating_pointer;
9631 convert_toplevel_coords_to_window (event_win,
9632 toplevel_x, toplevel_y,
9633 &event->touch.x, &event->touch.y);
9634 gdk_event_get_root_coords (source_event,
9635 &event->touch.x_root,
9636 &event->touch.y_root);
9638 event->touch.axes = g_memdup (source_event->touch.axes,
9639 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9643 event->motion.time = time_;
9644 event->motion.state = state;
9645 event->motion.is_hint = is_hint;
9647 convert_toplevel_coords_to_window (event_win,
9648 toplevel_x, toplevel_y,
9649 &event->motion.x, &event->motion.y);
9650 gdk_event_get_root_coords (source_event,
9651 &event->motion.x_root,
9652 &event->motion.y_root);
9654 if (is_touch_type (source_event->type))
9655 event->motion.axes = g_memdup (source_event->touch.axes,
9656 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9658 event->motion.axes = g_memdup (source_event->motion.axes,
9659 sizeof (gdouble) * gdk_device_get_n_axes (source_event->motion.device));
9662 /* Just insert the event */
9663 _gdk_event_queue_insert_after (gdk_window_get_display (event_win),
9664 source_event, event);
9667 /* unlink all move events from queue.
9668 We handle our own, including our emulated masks. */
9672 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
9673 GDK_BUTTON2_MASK | \
9674 GDK_BUTTON3_MASK | \
9675 GDK_BUTTON4_MASK | \
9679 proxy_button_event (GdkEvent *source_event,
9682 GdkWindow *toplevel_window, *event_window;
9683 GdkWindow *event_win;
9684 GdkWindow *pointer_window;
9687 GdkPointerWindowInfo *pointer_info;
9688 GdkDeviceGrabInfo *pointer_grab;
9692 gdouble toplevel_x, toplevel_y;
9693 GdkDisplay *display;
9695 GdkDevice *device, *source_device;
9696 GdkEventMask evmask;
9697 GdkEventSequence *sequence;
9699 type = source_event->any.type;
9700 event_window = source_event->any.window;
9701 gdk_event_get_coords (source_event, &toplevel_x, &toplevel_y);
9702 gdk_event_get_state (source_event, &state);
9703 time_ = gdk_event_get_time (source_event);
9704 device = gdk_event_get_device (source_event);
9705 source_device = gdk_event_get_source_device (source_event);
9706 display = gdk_window_get_display (source_event->any.window);
9707 toplevel_window = convert_native_coords_to_toplevel (event_window,
9708 toplevel_x, toplevel_y,
9709 &toplevel_x, &toplevel_y);
9711 sequence = gdk_event_get_event_sequence (source_event);
9713 pointer_info = _gdk_display_get_pointer_info (display, device);
9714 pointer_grab = _gdk_display_has_device_grab (display, device, serial);
9716 if ((type == GDK_BUTTON_PRESS ||
9717 type == GDK_TOUCH_BEGIN) &&
9718 !source_event->any.send_event &&
9720 (type == GDK_TOUCH_BEGIN && pointer_grab->implicit &&
9721 !_gdk_event_get_pointer_emulated (source_event))))
9724 _gdk_window_find_descendant_at (toplevel_window,
9725 toplevel_x, toplevel_y,
9728 /* Find the event window, that gets the grab */
9731 (parent = get_event_parent (w)) != NULL &&
9732 parent->window_type != GDK_WINDOW_ROOT)
9734 if (w->event_mask & GDK_BUTTON_PRESS_MASK &&
9735 (type == GDK_BUTTON_PRESS ||
9736 _gdk_event_get_pointer_emulated (source_event)))
9739 if (type == GDK_TOUCH_BEGIN &&
9740 w->event_mask & GDK_TOUCH_MASK)
9749 if (type == GDK_TOUCH_BEGIN &&
9750 pointer_window->event_mask & GDK_TOUCH_MASK)
9752 _gdk_display_add_touch_grab (display, device, sequence,
9753 pointer_window, event_window,
9754 gdk_window_get_events (pointer_window),
9757 else if (type == GDK_BUTTON_PRESS ||
9758 _gdk_event_get_pointer_emulated (source_event))
9760 _gdk_display_add_device_grab (display,
9766 gdk_window_get_events (pointer_window),
9770 _gdk_display_device_grab_update (display, device,
9771 source_device, serial);
9776 pointer_window = get_pointer_window (display, toplevel_window, device,
9777 toplevel_x, toplevel_y,
9780 event_win = get_event_window (display,
9786 _gdk_event_get_pointer_emulated (source_event),
9789 if (type == GDK_TOUCH_BEGIN || type == GDK_TOUCH_END)
9791 if (_gdk_event_get_pointer_emulated (source_event))
9793 if ((evmask & GDK_TOUCH_MASK) == 0 ||
9794 !_gdk_display_has_touch_grab (display, device, sequence, serial))
9796 if (type == GDK_TOUCH_BEGIN)
9797 type = GDK_BUTTON_PRESS;
9798 else if (type == GDK_TOUCH_END)
9799 type = GDK_BUTTON_RELEASE;
9802 else if ((evmask & GDK_TOUCH_MASK) == 0)
9806 if (source_event->type == GDK_TOUCH_END && !is_touch_type (type))
9807 state |= GDK_BUTTON1_MASK;
9809 if (event_win == NULL)
9812 if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
9813 gdk_window_get_device_events (event_win, device) == 0)
9816 if ((type == GDK_BUTTON_PRESS ||
9817 (type == GDK_TOUCH_BEGIN &&
9818 _gdk_event_get_pointer_emulated (source_event))) &&
9819 pointer_info->need_touch_press_enter)
9821 GdkCrossingMode mode;
9823 /* The last device to interact with the window was a touch device,
9824 * which synthesized a leave notify event, so synthesize another enter
9825 * notify to tell the pointer is on the window.
9827 if (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9828 mode = GDK_CROSSING_TOUCH_BEGIN;
9830 mode = GDK_CROSSING_DEVICE_SWITCH;
9832 pointer_info->need_touch_press_enter = FALSE;
9833 _gdk_synthesize_crossing_events (display,
9835 pointer_info->window_under_pointer,
9836 device, source_device, mode,
9837 toplevel_x, toplevel_y,
9838 state, time_, source_event,
9841 else if (type == GDK_SCROLL &&
9842 (((evmask & GDK_SMOOTH_SCROLL_MASK) == 0 &&
9843 source_event->scroll.direction == GDK_SCROLL_SMOOTH) ||
9844 ((evmask & GDK_SMOOTH_SCROLL_MASK) != 0 &&
9845 source_event->scroll.direction != GDK_SCROLL_SMOOTH &&
9846 _gdk_event_get_pointer_emulated (source_event))))
9849 event = _gdk_make_event (event_win, type, source_event, FALSE);
9853 case GDK_BUTTON_PRESS:
9854 case GDK_BUTTON_RELEASE:
9855 event->button.button = source_event->button.button;
9856 convert_toplevel_coords_to_window (event_win,
9857 toplevel_x, toplevel_y,
9858 &event->button.x, &event->button.y);
9859 gdk_event_get_root_coords (source_event,
9860 &event->button.x_root,
9861 &event->button.y_root);
9862 gdk_event_set_device (event, gdk_event_get_device (source_event));
9863 gdk_event_set_source_device (event, source_device);
9865 if (is_touch_type (source_event->type))
9867 if (type == GDK_BUTTON_RELEASE)
9868 event->button.state |= GDK_BUTTON1_MASK;
9869 event->button.button = 1;
9870 event->button.axes = g_memdup (source_event->touch.axes,
9871 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9875 event->button.button = source_event->button.button;
9876 event->button.axes = g_memdup (source_event->button.axes,
9877 sizeof (gdouble) * gdk_device_get_n_axes (source_event->button.device));
9880 if (type == GDK_BUTTON_PRESS)
9881 _gdk_event_button_generate (display, event);
9882 else if ((type == GDK_BUTTON_RELEASE ||
9883 (type == GDK_TOUCH_END &&
9884 _gdk_event_get_pointer_emulated (source_event))) &&
9885 pointer_window == pointer_info->window_under_pointer &&
9886 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9888 /* Synthesize a leave notify event
9889 * whenever a touch device is released
9891 pointer_info->need_touch_press_enter = TRUE;
9892 _gdk_synthesize_crossing_events (display,
9893 pointer_window, NULL,
9894 device, source_device,
9895 GDK_CROSSING_TOUCH_END,
9896 toplevel_x, toplevel_y,
9902 case GDK_TOUCH_BEGIN:
9904 convert_toplevel_coords_to_window (event_win,
9905 toplevel_x, toplevel_y,
9906 &event->button.x, &event->button.y);
9907 gdk_event_get_root_coords (source_event,
9908 &event->touch.x_root,
9909 &event->touch.y_root);
9910 event->touch.state = state;
9911 event->touch.device = source_event->touch.device;
9912 event->touch.axes = g_memdup (source_event->touch.axes,
9913 sizeof (gdouble) * gdk_device_get_n_axes (source_event->touch.device));
9914 event->touch.sequence = source_event->touch.sequence;
9915 event->touch.emulating_pointer = source_event->touch.emulating_pointer;
9917 gdk_event_set_source_device (event, source_device);
9919 if ((type == GDK_TOUCH_END &&
9920 _gdk_event_get_pointer_emulated (source_event)) &&
9921 pointer_window == pointer_info->window_under_pointer &&
9922 gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN)
9924 /* Synthesize a leave notify event
9925 * whenever a touch device is released
9927 pointer_info->need_touch_press_enter = TRUE;
9928 _gdk_synthesize_crossing_events (display,
9929 pointer_window, NULL,
9930 device, source_device,
9931 GDK_CROSSING_TOUCH_END,
9932 toplevel_x, toplevel_y,
9939 event->scroll.direction = source_event->scroll.direction;
9940 convert_toplevel_coords_to_window (event_win,
9941 toplevel_x, toplevel_y,
9942 &event->scroll.x, &event->scroll.y);
9943 event->scroll.x_root = source_event->scroll.x_root;
9944 event->scroll.y_root = source_event->scroll.y_root;
9945 event->scroll.state = state;
9946 event->scroll.device = source_event->scroll.device;
9947 event->scroll.delta_x = source_event->scroll.delta_x;
9948 event->scroll.delta_y = source_event->scroll.delta_y;
9949 gdk_event_set_source_device (event, source_device);
9956 return TRUE; /* Always unlink original, we want to obey the emulated event mask */
9959 #ifdef DEBUG_WINDOW_PRINTING
9961 #ifdef GDK_WINDOWING_X11
9962 #include "x11/gdkx.h"
9966 gdk_window_print (GdkWindow *window,
9970 const char *window_types[] = {
9980 g_print ("%*s%p: [%s] %d,%d %dx%d", indent, "", window,
9981 window->user_data ? g_type_name_from_instance (window->user_data) : "no widget",
9982 window->x, window->y,
9983 window->width, window->height
9986 if (gdk_window_has_impl (window))
9988 #ifdef GDK_WINDOWING_X11
9989 g_print (" impl(0x%lx)", gdk_x11_window_get_xid (window));
9993 if (window->window_type != GDK_WINDOW_CHILD)
9994 g_print (" %s", window_types[window->window_type]);
9996 if (window->input_only)
9997 g_print (" input-only");
10000 g_print (" shaped");
10002 if (!gdk_window_is_visible ((GdkWindow *)window))
10003 g_print (" hidden");
10005 g_print (" abs[%d,%d]",
10006 window->abs_x, window->abs_y);
10008 s = print_region (window->clip_region);
10009 g_print (" clipbox[%s]", s);
10016 gdk_window_print_tree (GdkWindow *window,
10018 gboolean include_input_only)
10022 if (window->input_only && !include_input_only)
10025 gdk_window_print (window, indent);
10027 for (l = window->children; l != NULL; l = l->next)
10028 gdk_window_print_tree (l->data, indent + 4, include_input_only);
10031 #endif /* DEBUG_WINDOW_PRINTING */
10034 _gdk_windowing_got_event (GdkDisplay *display,
10039 GdkWindow *event_window;
10041 gboolean unlink_event = FALSE;
10042 GdkDeviceGrabInfo *button_release_grab;
10043 GdkPointerWindowInfo *pointer_info = NULL;
10044 GdkDevice *device, *source_device;
10045 gboolean is_toplevel;
10047 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
10048 display->last_event_time = gdk_event_get_time (event);
10050 device = gdk_event_get_device (event);
10051 source_device = gdk_event_get_source_device (event);
10057 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
10059 pointer_info = _gdk_display_get_pointer_info (display, device);
10061 if (source_device != pointer_info->last_slave &&
10062 gdk_device_get_device_type (source_device) == GDK_DEVICE_TYPE_SLAVE)
10063 pointer_info->last_slave = source_device;
10064 else if (pointer_info->last_slave)
10065 source_device = pointer_info->last_slave;
10068 g_object_get (device, "input-mode", &mode, NULL);
10069 _gdk_display_device_grab_update (display, device, source_device, serial);
10071 if (mode == GDK_MODE_DISABLED ||
10072 !_gdk_display_check_grab_ownership (display, device, serial))
10074 /* Device events are blocked by another
10075 * device grab, or the device is disabled
10077 unlink_event = TRUE;
10082 event_window = event->any.window;
10086 #ifdef DEBUG_WINDOW_PRINTING
10087 if (event->type == GDK_KEY_PRESS &&
10088 (event->key.keyval == 0xa7 ||
10089 event->key.keyval == 0xbd))
10091 gdk_window_print_tree (event_window, 0, event->key.keyval == 0xbd);
10095 if (event->type == GDK_VISIBILITY_NOTIFY)
10097 event_window->native_visibility = event->visibility.state;
10098 gdk_window_update_visibility_recursively (event_window, event_window);
10102 if (!(is_button_type (event->type) ||
10103 is_motion_type (event->type)) ||
10104 event_window->window_type == GDK_WINDOW_ROOT)
10107 is_toplevel = gdk_window_is_toplevel (event_window);
10109 if ((event->type == GDK_ENTER_NOTIFY ||
10110 event->type == GDK_LEAVE_NOTIFY) &&
10111 (event->crossing.mode == GDK_CROSSING_GRAB ||
10112 event->crossing.mode == GDK_CROSSING_UNGRAB) &&
10113 (_gdk_display_has_device_grab (display, device, serial) ||
10114 event->crossing.detail == GDK_NOTIFY_INFERIOR))
10116 /* We synthesize all crossing events due to grabs ourselves,
10117 * so we ignore the native ones caused by our native pointer_grab
10118 * calls. Otherwise we would proxy these crossing event and cause
10119 * multiple copies of crossing events for grabs.
10121 * We do want to handle grabs from other clients though, as for
10122 * instance alt-tab in metacity causes grabs like these and
10123 * we want to handle those. Thus the has_pointer_grab check.
10125 * Implicit grabs on child windows create some grabbing events
10126 * that are sent before the button press. This means we can't
10127 * detect these with the has_pointer_grab check (as the implicit
10128 * grab is only noticed when we get button press event), so we
10129 * detect these events by checking for INFERIOR enter or leave
10130 * events. These should never be a problem to filter out.
10133 /* We ended up in this window after some (perhaps other clients)
10134 * grab, so update the toplevel_under_window state
10137 event->type == GDK_ENTER_NOTIFY &&
10138 event->crossing.mode == GDK_CROSSING_UNGRAB)
10140 if (pointer_info->toplevel_under_pointer)
10141 g_object_unref (pointer_info->toplevel_under_pointer);
10142 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
10145 unlink_event = TRUE;
10149 /* Track toplevel_under_pointer */
10152 if (event->type == GDK_ENTER_NOTIFY &&
10153 event->crossing.detail != GDK_NOTIFY_INFERIOR)
10155 if (pointer_info->toplevel_under_pointer)
10156 g_object_unref (pointer_info->toplevel_under_pointer);
10157 pointer_info->toplevel_under_pointer = g_object_ref (event_window);
10159 else if (event->type == GDK_LEAVE_NOTIFY &&
10160 event->crossing.detail != GDK_NOTIFY_INFERIOR &&
10161 pointer_info->toplevel_under_pointer == event_window)
10163 if (pointer_info->toplevel_under_pointer)
10164 g_object_unref (pointer_info->toplevel_under_pointer);
10165 pointer_info->toplevel_under_pointer = NULL;
10169 if (pointer_info &&
10170 (!is_touch_type (event->type) ||
10171 _gdk_event_get_pointer_emulated (event)))
10173 guint old_state, old_button;
10175 /* Store last pointer window and position/state */
10176 old_state = pointer_info->state;
10177 old_button = pointer_info->button;
10179 gdk_event_get_coords (event, &x, &y);
10180 convert_native_coords_to_toplevel (event_window, x, y, &x, &y);
10181 pointer_info->toplevel_x = x;
10182 pointer_info->toplevel_y = y;
10183 gdk_event_get_state (event, &pointer_info->state);
10185 if (event->type == GDK_BUTTON_PRESS ||
10186 event->type == GDK_BUTTON_RELEASE)
10187 pointer_info->button = event->button.button;
10188 else if (event->type == GDK_TOUCH_BEGIN ||
10189 event->type == GDK_TOUCH_END)
10190 pointer_info->button = 1;
10193 (pointer_info->state != old_state ||
10194 pointer_info->button != old_button))
10195 _gdk_display_enable_motion_hints (display, device);
10198 if (is_motion_type (event->type))
10199 unlink_event = proxy_pointer_event (display, event, serial);
10200 else if (is_button_type (event->type))
10201 unlink_event = proxy_button_event (event, serial);
10203 if ((event->type == GDK_BUTTON_RELEASE ||
10204 event->type == GDK_TOUCH_END) &&
10205 !event->any.send_event)
10207 GdkEventSequence *sequence;
10209 sequence = gdk_event_get_event_sequence (event);
10210 if (event->type == GDK_TOUCH_END && sequence)
10212 _gdk_display_end_touch_grab (display, device, sequence);
10215 if (event->type == GDK_BUTTON_RELEASE ||
10216 _gdk_event_get_pointer_emulated (event))
10218 button_release_grab =
10219 _gdk_display_has_device_grab (display, device, serial);
10221 if (button_release_grab &&
10222 button_release_grab->implicit &&
10223 (event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
10225 button_release_grab->serial_end = serial;
10226 button_release_grab->implicit_ungrab = FALSE;
10227 _gdk_display_device_grab_update (display, device, source_device, serial);
10235 _gdk_event_queue_remove_link (display, event_link);
10236 g_list_free_1 (event_link);
10237 gdk_event_free (event);
10240 /* This does two things - first it sees if there are motions at the
10241 * end of the queue that can be compressed. Second, if there is just
10242 * a single motion that won't be dispatched because it is a compression
10243 * candidate it queues up flushing the event queue.
10245 _gdk_event_queue_handle_motion_compression (display);
10249 * gdk_window_create_similar_surface:
10250 * @window: window to make new surface similar to
10251 * @content: the content for the new surface
10252 * @width: width of the new surface
10253 * @height: height of the new surface
10255 * Create a new surface that is as compatible as possible with the
10256 * given @window. For example the new surface will have the same
10257 * fallback resolution and font options as @window. Generally, the new
10258 * surface will also use the same backend as @window, unless that is
10259 * not possible for some reason. The type of the returned surface may
10260 * be examined with cairo_surface_get_type().
10262 * Initially the surface contents are all 0 (transparent if contents
10263 * have transparency, black otherwise.)
10265 * Returns: a pointer to the newly allocated surface. The caller
10266 * owns the surface and should call cairo_surface_destroy() when done
10269 * This function always returns a valid pointer, but it will return a
10270 * pointer to a "nil" surface if @other is already in an error state
10271 * or any other error occurs.
10276 gdk_window_create_similar_surface (GdkWindow * window,
10277 cairo_content_t content,
10281 cairo_surface_t *window_surface, *surface;
10283 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
10285 window_surface = gdk_window_ref_impl_surface (window);
10287 switch (_gdk_rendering_mode)
10289 case GDK_RENDERING_MODE_RECORDING:
10291 cairo_rectangle_t rect = { 0, 0, width, height };
10292 surface = cairo_recording_surface_create (content, &rect);
10295 case GDK_RENDERING_MODE_IMAGE:
10296 surface = cairo_image_surface_create (content == CAIRO_CONTENT_COLOR ? CAIRO_FORMAT_RGB24 :
10297 content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
10300 case GDK_RENDERING_MODE_SIMILAR:
10302 surface = cairo_surface_create_similar (window_surface,
10308 cairo_surface_destroy (window_surface);
10314 * gdk_window_focus:
10315 * @window: a #GdkWindow
10316 * @timestamp: timestamp of the event triggering the window focus
10318 * Sets keyboard focus to @window. In most cases, gtk_window_present()
10319 * should be used on a #GtkWindow, rather than calling this function.
10323 gdk_window_focus (GdkWindow *window,
10326 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->focus (window, timestamp);
10330 * gdk_window_set_type_hint:
10331 * @window: A toplevel #GdkWindow
10332 * @hint: A hint of the function this window will have
10334 * The application can use this call to provide a hint to the window
10335 * manager about the functionality of a window. The window manager
10336 * can use this information when determining the decoration and behaviour
10339 * The hint must be set before the window is mapped.
10342 gdk_window_set_type_hint (GdkWindow *window,
10343 GdkWindowTypeHint hint)
10345 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_type_hint (window, hint);
10349 * gdk_window_get_type_hint:
10350 * @window: A toplevel #GdkWindow
10352 * This function returns the type hint set for a window.
10354 * Return value: The type hint set for @window
10359 gdk_window_get_type_hint (GdkWindow *window)
10361 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_type_hint (window);
10365 * gdk_window_set_modal_hint:
10366 * @window: A toplevel #GdkWindow
10367 * @modal: %TRUE if the window is modal, %FALSE otherwise.
10369 * The application can use this hint to tell the window manager
10370 * that a certain window has modal behaviour. The window manager
10371 * can use this information to handle modal windows in a special
10374 * You should only use this on windows for which you have
10375 * previously called gdk_window_set_transient_for()
10378 gdk_window_set_modal_hint (GdkWindow *window,
10381 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_modal_hint (window, modal);
10385 * gdk_window_set_skip_taskbar_hint:
10386 * @window: a toplevel #GdkWindow
10387 * @skips_taskbar: %TRUE to skip the taskbar
10389 * Toggles whether a window should appear in a task list or window
10390 * list. If a window's semantic type as specified with
10391 * gdk_window_set_type_hint() already fully describes the window, this
10392 * function should <emphasis>not</emphasis> be called in addition,
10393 * instead you should allow the window to be treated according to
10394 * standard policy for its semantic type.
10399 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
10400 gboolean skips_taskbar)
10402 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_taskbar_hint (window, skips_taskbar);
10406 * gdk_window_set_skip_pager_hint:
10407 * @window: a toplevel #GdkWindow
10408 * @skips_pager: %TRUE to skip the pager
10410 * Toggles whether a window should appear in a pager (workspace
10411 * switcher, or other desktop utility program that displays a small
10412 * thumbnail representation of the windows on the desktop). If a
10413 * window's semantic type as specified with gdk_window_set_type_hint()
10414 * already fully describes the window, this function should
10415 * <emphasis>not</emphasis> be called in addition, instead you should
10416 * allow the window to be treated according to standard policy for
10417 * its semantic type.
10422 gdk_window_set_skip_pager_hint (GdkWindow *window,
10423 gboolean skips_pager)
10425 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_skip_pager_hint (window, skips_pager);
10429 * gdk_window_set_urgency_hint:
10430 * @window: a toplevel #GdkWindow
10431 * @urgent: %TRUE if the window is urgent
10433 * Toggles whether a window needs the user's
10434 * urgent attention.
10439 gdk_window_set_urgency_hint (GdkWindow *window,
10442 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_urgency_hint (window, urgent);
10446 * gdk_window_set_geometry_hints:
10447 * @window: a toplevel #GdkWindow
10448 * @geometry: geometry hints
10449 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
10451 * Sets the geometry hints for @window. Hints flagged in @geom_mask
10452 * are set, hints not flagged in @geom_mask are unset.
10453 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
10455 * This function provides hints to the windowing system about
10456 * acceptable sizes for a toplevel window. The purpose of
10457 * this is to constrain user resizing, but the windowing system
10458 * will typically (but is not required to) also constrain the
10459 * current size of the window to the provided values and
10460 * constrain programatic resizing via gdk_window_resize() or
10461 * gdk_window_move_resize().
10463 * Note that on X11, this effect has no effect on windows
10464 * of type %GDK_WINDOW_TEMP or windows where override redirect
10465 * has been turned on via gdk_window_set_override_redirect()
10466 * since these windows are not resizable by the user.
10468 * Since you can't count on the windowing system doing the
10469 * constraints for programmatic resizes, you should generally
10470 * call gdk_window_constrain_size() yourself to determine
10471 * appropriate sizes.
10475 gdk_window_set_geometry_hints (GdkWindow *window,
10476 const GdkGeometry *geometry,
10477 GdkWindowHints geom_mask)
10479 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_geometry_hints (window, geometry, geom_mask);
10483 * gdk_window_set_title:
10484 * @window: a toplevel #GdkWindow
10485 * @title: title of @window
10487 * Sets the title of a toplevel window, to be displayed in the titlebar.
10488 * If you haven't explicitly set the icon name for the window
10489 * (using gdk_window_set_icon_name()), the icon name will be set to
10490 * @title as well. @title must be in UTF-8 encoding (as with all
10491 * user-readable strings in GDK/GTK+). @title may not be %NULL.
10494 gdk_window_set_title (GdkWindow *window,
10495 const gchar *title)
10497 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_title (window, title);
10501 * gdk_window_set_role:
10502 * @window: a toplevel #GdkWindow
10503 * @role: a string indicating its role
10505 * When using GTK+, typically you should use gtk_window_set_role() instead
10506 * of this low-level function.
10508 * The window manager and session manager use a window's role to
10509 * distinguish it from other kinds of window in the same application.
10510 * When an application is restarted after being saved in a previous
10511 * session, all windows with the same title and role are treated as
10512 * interchangeable. So if you have two windows with the same title
10513 * that should be distinguished for session management purposes, you
10514 * should set the role on those windows. It doesn't matter what string
10515 * you use for the role, as long as you have a different role for each
10516 * non-interchangeable kind of window.
10520 gdk_window_set_role (GdkWindow *window,
10523 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_role (window, role);
10527 * gdk_window_set_startup_id:
10528 * @window: a toplevel #GdkWindow
10529 * @startup_id: a string with startup-notification identifier
10531 * When using GTK+, typically you should use gtk_window_set_startup_id()
10532 * instead of this low-level function.
10538 gdk_window_set_startup_id (GdkWindow *window,
10539 const gchar *startup_id)
10541 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_startup_id (window, startup_id);
10545 * gdk_window_set_transient_for:
10546 * @window: a toplevel #GdkWindow
10547 * @parent: another toplevel #GdkWindow
10549 * Indicates to the window manager that @window is a transient dialog
10550 * associated with the application window @parent. This allows the
10551 * window manager to do things like center @window on @parent and
10552 * keep @window above @parent.
10554 * See gtk_window_set_transient_for() if you're using #GtkWindow or
10558 gdk_window_set_transient_for (GdkWindow *window,
10561 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_transient_for (window, parent);
10565 * gdk_window_get_root_origin:
10566 * @window: a toplevel #GdkWindow
10567 * @x: (out): return location for X position of window frame
10568 * @y: (out): return location for Y position of window frame
10570 * Obtains the top-left corner of the window manager frame in root
10571 * window coordinates.
10575 gdk_window_get_root_origin (GdkWindow *window,
10579 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_root_origin (window, x, y);
10583 * gdk_window_get_frame_extents:
10584 * @window: a toplevel #GdkWindow
10585 * @rect: (out): rectangle to fill with bounding box of the window frame
10587 * Obtains the bounding box of the window, including window manager
10588 * titlebar/borders if any. The frame position is given in root window
10589 * coordinates. To get the position of the window itself (rather than
10590 * the frame) in root window coordinates, use gdk_window_get_origin().
10594 gdk_window_get_frame_extents (GdkWindow *window,
10595 GdkRectangle *rect)
10597 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_frame_extents (window, rect);
10601 * gdk_window_set_override_redirect:
10602 * @window: a toplevel #GdkWindow
10603 * @override_redirect: %TRUE if window should be override redirect
10605 * An override redirect window is not under the control of the window manager.
10606 * This means it won't have a titlebar, won't be minimizable, etc. - it will
10607 * be entirely under the control of the application. The window manager
10608 * can't see the override redirect window at all.
10610 * Override redirect should only be used for short-lived temporary
10611 * windows, such as popup menus. #GtkMenu uses an override redirect
10612 * window in its implementation, for example.
10616 gdk_window_set_override_redirect (GdkWindow *window,
10617 gboolean override_redirect)
10619 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_override_redirect (window, override_redirect);
10623 * gdk_window_set_accept_focus:
10624 * @window: a toplevel #GdkWindow
10625 * @accept_focus: %TRUE if the window should receive input focus
10627 * Setting @accept_focus to %FALSE hints the desktop environment that the
10628 * window doesn't want to receive input focus.
10630 * On X, it is the responsibility of the window manager to interpret this
10631 * hint. ICCCM-compliant window manager usually respect it.
10636 gdk_window_set_accept_focus (GdkWindow *window,
10637 gboolean accept_focus)
10639 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_accept_focus (window, accept_focus);
10643 * gdk_window_set_focus_on_map:
10644 * @window: a toplevel #GdkWindow
10645 * @focus_on_map: %TRUE if the window should receive input focus when mapped
10647 * Setting @focus_on_map to %FALSE hints the desktop environment that the
10648 * window doesn't want to receive input focus when it is mapped.
10649 * focus_on_map should be turned off for windows that aren't triggered
10650 * interactively (such as popups from network activity).
10652 * On X, it is the responsibility of the window manager to interpret
10653 * this hint. Window managers following the freedesktop.org window
10654 * manager extension specification should respect it.
10659 gdk_window_set_focus_on_map (GdkWindow *window,
10660 gboolean focus_on_map)
10662 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_focus_on_map (window, focus_on_map);
10666 * gdk_window_set_icon_list:
10667 * @window: The #GdkWindow toplevel window to set the icon of.
10668 * @pixbufs: (transfer none) (element-type GdkPixbuf):
10669 * A list of pixbufs, of different sizes.
10671 * Sets a list of icons for the window. One of these will be used
10672 * to represent the window when it has been iconified. The icon is
10673 * usually shown in an icon box or some sort of task bar. Which icon
10674 * size is shown depends on the window manager. The window manager
10675 * can scale the icon but setting several size icons can give better
10676 * image quality since the window manager may only need to scale the
10677 * icon by a small amount or not at all.
10681 gdk_window_set_icon_list (GdkWindow *window,
10684 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, pixbufs);
10688 * gdk_window_set_icon_name:
10689 * @window: a toplevel #GdkWindow
10690 * @name: (allow-none): name of window while iconified (minimized)
10692 * Windows may have a name used while minimized, distinct from the
10693 * name they display in their titlebar. Most of the time this is a bad
10694 * idea from a user interface standpoint. But you can set such a name
10695 * with this function, if you like.
10697 * After calling this with a non-%NULL @name, calls to gdk_window_set_title()
10698 * will not update the icon title.
10700 * Using %NULL for @name unsets the icon title; further calls to
10701 * gdk_window_set_title() will again update the icon title as well.
10704 gdk_window_set_icon_name (GdkWindow *window,
10707 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_name (window, name);
10711 * gdk_window_iconify:
10712 * @window: a toplevel #GdkWindow
10714 * Asks to iconify (minimize) @window. The window manager may choose
10715 * to ignore the request, but normally will honor it. Using
10716 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
10718 * This function only makes sense when @window is a toplevel window.
10722 gdk_window_iconify (GdkWindow *window)
10724 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->iconify (window);
10728 * gdk_window_deiconify:
10729 * @window: a toplevel #GdkWindow
10731 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
10732 * choose to ignore the request to deiconify. When using GTK+,
10733 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
10734 * you probably want to use gtk_window_present(), which raises the window, focuses it,
10735 * unminimizes it, and puts it on the current desktop.
10739 gdk_window_deiconify (GdkWindow *window)
10741 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->deiconify (window);
10745 * gdk_window_stick:
10746 * @window: a toplevel #GdkWindow
10748 * "Pins" a window such that it's on all workspaces and does not scroll
10749 * with viewports, for window managers that have scrollable viewports.
10750 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
10752 * On the X11 platform, this function depends on window manager
10753 * support, so may have no effect with many window managers. However,
10754 * GDK will do the best it can to convince the window manager to stick
10755 * the window. For window managers that don't support this operation,
10756 * there's nothing you can do to force it to happen.
10760 gdk_window_stick (GdkWindow *window)
10762 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->stick (window);
10766 * gdk_window_unstick:
10767 * @window: a toplevel #GdkWindow
10769 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
10770 * and gtk_window_unstick().
10774 gdk_window_unstick (GdkWindow *window)
10776 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unstick (window);
10780 * gdk_window_maximize:
10781 * @window: a toplevel #GdkWindow
10783 * Maximizes the window. If the window was already maximized, then
10784 * this function does nothing.
10786 * On X11, asks the window manager to maximize @window, if the window
10787 * manager supports this operation. Not all window managers support
10788 * this, and some deliberately ignore it or don't have a concept of
10789 * "maximized"; so you can't rely on the maximization actually
10790 * happening. But it will happen with most standard window managers,
10791 * and GDK makes a best effort to get it to happen.
10793 * On Windows, reliably maximizes the window.
10797 gdk_window_maximize (GdkWindow *window)
10799 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->maximize (window);
10803 * gdk_window_unmaximize:
10804 * @window: a toplevel #GdkWindow
10806 * Unmaximizes the window. If the window wasn't maximized, then this
10807 * function does nothing.
10809 * On X11, asks the window manager to unmaximize @window, if the
10810 * window manager supports this operation. Not all window managers
10811 * support this, and some deliberately ignore it or don't have a
10812 * concept of "maximized"; so you can't rely on the unmaximization
10813 * actually happening. But it will happen with most standard window
10814 * managers, and GDK makes a best effort to get it to happen.
10816 * On Windows, reliably unmaximizes the window.
10820 gdk_window_unmaximize (GdkWindow *window)
10822 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unmaximize (window);
10826 * gdk_window_fullscreen:
10827 * @window: a toplevel #GdkWindow
10829 * Moves the window into fullscreen mode. This means the
10830 * window covers the entire screen and is above any panels
10833 * If the window was already fullscreen, then this function does nothing.
10835 * On X11, asks the window manager to put @window in a fullscreen
10836 * state, if the window manager supports this operation. Not all
10837 * window managers support this, and some deliberately ignore it or
10838 * don't have a concept of "fullscreen"; so you can't rely on the
10839 * fullscreenification actually happening. But it will happen with
10840 * most standard window managers, and GDK makes a best effort to get
10846 gdk_window_fullscreen (GdkWindow *window)
10848 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->fullscreen (window);
10852 * gdk_window_set_fullscreen_mode:
10853 * @window: a toplevel #GdkWindow
10854 * @mode: fullscreen mode
10856 * Specifies whether the @window should span over all monitors (in a multi-head
10857 * setup) or only the current monitor when in fullscreen mode.
10859 * The @mode argument is from the #GdkFullscreenMode enumeration.
10860 * If #GDK_FULLSCREEN_ON_ALL_MONITORS is specified, the fullscreen @window will
10861 * span over all monitors from the #GdkScreen.
10863 * On X11, searches through the list of monitors from the #GdkScreen the ones
10864 * which delimit the 4 edges of the entire #GdkScreen and will ask the window
10865 * manager to span the @window over these monitors.
10867 * If the XINERAMA extension is not available or not usable, this function
10870 * Not all window managers support this, so you can't rely on the fullscreen
10871 * window to span over the multiple monitors when #GDK_FULLSCREEN_ON_ALL_MONITORS
10877 gdk_window_set_fullscreen_mode (GdkWindow *window,
10878 GdkFullscreenMode mode)
10880 GdkWindowImplClass *impl_class;
10882 g_return_if_fail (GDK_IS_WINDOW (window));
10884 if (window->fullscreen_mode != mode)
10886 window->fullscreen_mode = mode;
10888 impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
10889 if (impl_class->apply_fullscreen_mode != NULL)
10890 impl_class->apply_fullscreen_mode (window);
10895 * gdk_window_get_fullscreen_mode:
10896 * @window: a toplevel #GdkWindow
10898 * Obtains the #GdkFullscreenMode of the @window.
10900 * Returns: The #GdkFullscreenMode applied to the window when fullscreen.
10905 gdk_window_get_fullscreen_mode (GdkWindow *window)
10907 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_FULLSCREEN_ON_CURRENT_MONITOR);
10909 return window->fullscreen_mode;
10913 * gdk_window_unfullscreen:
10914 * @window: a toplevel #GdkWindow
10916 * Moves the window out of fullscreen mode. If the window was not
10917 * fullscreen, does nothing.
10919 * On X11, asks the window manager to move @window out of the fullscreen
10920 * state, if the window manager supports this operation. Not all
10921 * window managers support this, and some deliberately ignore it or
10922 * don't have a concept of "fullscreen"; so you can't rely on the
10923 * unfullscreenification actually happening. But it will happen with
10924 * most standard window managers, and GDK makes a best effort to get
10930 gdk_window_unfullscreen (GdkWindow *window)
10932 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->unfullscreen (window);
10936 * gdk_window_set_keep_above:
10937 * @window: a toplevel #GdkWindow
10938 * @setting: whether to keep @window above other windows
10940 * Set if @window must be kept above other windows. If the
10941 * window was already above, then this function does nothing.
10943 * On X11, asks the window manager to keep @window above, if the window
10944 * manager supports this operation. Not all window managers support
10945 * this, and some deliberately ignore it or don't have a concept of
10946 * "keep above"; so you can't rely on the window being kept above.
10947 * But it will happen with most standard window managers,
10948 * and GDK makes a best effort to get it to happen.
10953 gdk_window_set_keep_above (GdkWindow *window,
10956 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_above (window, setting);
10960 * gdk_window_set_keep_below:
10961 * @window: a toplevel #GdkWindow
10962 * @setting: whether to keep @window below other windows
10964 * Set if @window must be kept below other windows. If the
10965 * window was already below, then this function does nothing.
10967 * On X11, asks the window manager to keep @window below, if the window
10968 * manager supports this operation. Not all window managers support
10969 * this, and some deliberately ignore it or don't have a concept of
10970 * "keep below"; so you can't rely on the window being kept below.
10971 * But it will happen with most standard window managers,
10972 * and GDK makes a best effort to get it to happen.
10977 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
10979 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_keep_below (window, setting);
10983 * gdk_window_get_group:
10984 * @window: a toplevel #GdkWindow
10986 * Returns the group leader window for @window. See gdk_window_set_group().
10988 * Return value: (transfer none): the group leader window for @window
10993 gdk_window_get_group (GdkWindow *window)
10995 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_group (window);
10999 * gdk_window_set_group:
11000 * @window: a toplevel #GdkWindow
11001 * @leader: (allow-none): group leader window, or %NULL to restore the default group leader window
11003 * Sets the group leader window for @window. By default,
11004 * GDK sets the group leader for all toplevel windows
11005 * to a global window implicitly created by GDK. With this function
11006 * you can override this default.
11008 * The group leader window allows the window manager to distinguish
11009 * all windows that belong to a single application. It may for example
11010 * allow users to minimize/unminimize all windows belonging to an
11011 * application at once. You should only set a non-default group window
11012 * if your application pretends to be multiple applications.
11015 gdk_window_set_group (GdkWindow *window,
11018 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_group (window, leader);
11022 * gdk_window_set_decorations:
11023 * @window: a toplevel #GdkWindow
11024 * @decorations: decoration hint mask
11026 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
11027 * This function sets the traditional Motif window manager hints that tell the
11028 * window manager which decorations you would like your window to have.
11029 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
11030 * using the GDK function directly.
11032 * The @decorations argument is the logical OR of the fields in
11033 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
11034 * mask, the other bits indicate which decorations should be turned off.
11035 * If #GDK_DECOR_ALL is not included, then the other bits indicate
11036 * which decorations should be turned on.
11038 * Most window managers honor a decorations hint of 0 to disable all decorations,
11039 * but very few honor all possible combinations of bits.
11043 gdk_window_set_decorations (GdkWindow *window,
11044 GdkWMDecoration decorations)
11046 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_decorations (window, decorations);
11050 * gdk_window_get_decorations:
11051 * @window: The toplevel #GdkWindow to get the decorations from
11052 * @decorations: (out): The window decorations will be written here
11054 * Returns the decorations set on the GdkWindow with
11055 * gdk_window_set_decorations().
11057 * Returns: %TRUE if the window has decorations set, %FALSE otherwise.
11060 gdk_window_get_decorations(GdkWindow *window,
11061 GdkWMDecoration *decorations)
11063 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_decorations (window, decorations);
11067 * gdk_window_set_functions:
11068 * @window: a toplevel #GdkWindow
11069 * @functions: bitmask of operations to allow on @window
11071 * Sets hints about the window management functions to make available
11072 * via buttons on the window frame.
11074 * On the X backend, this function sets the traditional Motif window
11075 * manager hint for this purpose. However, few window managers do
11076 * anything reliable or interesting with this hint. Many ignore it
11079 * The @functions argument is the logical OR of values from the
11080 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
11081 * then the other bits indicate which functions to disable; if
11082 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
11087 gdk_window_set_functions (GdkWindow *window,
11088 GdkWMFunction functions)
11090 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_functions (window, functions);
11094 * gdk_window_begin_resize_drag_for_device:
11095 * @window: a toplevel #GdkWindow
11096 * @edge: the edge or corner from which the drag is started
11097 * @device: the device used for the operation
11098 * @button: the button being used to drag
11099 * @root_x: root window X coordinate of mouse click that began the drag
11100 * @root_y: root window Y coordinate of mouse click that began the drag
11101 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
11103 * Begins a window resize operation (for a toplevel window).
11104 * You might use this function to implement a "window resize grip," for
11105 * example; in fact #GtkStatusbar uses it. The function works best
11106 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
11107 * fallback implementation for other window managers.
11112 gdk_window_begin_resize_drag_for_device (GdkWindow *window,
11113 GdkWindowEdge edge,
11120 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_resize_drag (window, edge, device, button, root_x, root_y, timestamp);
11124 * gdk_window_begin_resize_drag:
11125 * @window: a toplevel #GdkWindow
11126 * @edge: the edge or corner from which the drag is started
11127 * @button: the button being used to drag
11128 * @root_x: root window X coordinate of mouse click that began the drag
11129 * @root_y: root window Y coordinate of mouse click that began the drag
11130 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
11132 * Begins a window resize operation (for a toplevel window).
11134 * This function assumes that the drag is controlled by the
11135 * client pointer device, use gdk_window_begin_resize_drag_for_device()
11136 * to begin a drag with a different device.
11139 gdk_window_begin_resize_drag (GdkWindow *window,
11140 GdkWindowEdge edge,
11146 GdkDeviceManager *device_manager;
11149 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11150 device = gdk_device_manager_get_client_pointer (device_manager);
11151 gdk_window_begin_resize_drag_for_device (window, edge,
11152 device, button, root_x, root_y, timestamp);
11156 * gdk_window_begin_move_drag_for_device:
11157 * @window: a toplevel #GdkWindow
11158 * @device: the device used for the operation
11159 * @button: the button being used to drag
11160 * @root_x: root window X coordinate of mouse click that began the drag
11161 * @root_y: root window Y coordinate of mouse click that began the drag
11162 * @timestamp: timestamp of mouse click that began the drag
11164 * Begins a window move operation (for a toplevel window).
11165 * You might use this function to implement a "window move grip," for
11166 * example. The function works best with window managers that support
11167 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
11168 * Window Manager Hints</ulink>, but has a fallback implementation for
11169 * other window managers.
11174 gdk_window_begin_move_drag_for_device (GdkWindow *window,
11181 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->begin_move_drag (window,
11182 device, button, root_x, root_y, timestamp);
11186 * gdk_window_begin_move_drag:
11187 * @window: a toplevel #GdkWindow
11188 * @button: the button being used to drag
11189 * @root_x: root window X coordinate of mouse click that began the drag
11190 * @root_y: root window Y coordinate of mouse click that began the drag
11191 * @timestamp: timestamp of mouse click that began the drag
11193 * Begins a window move operation (for a toplevel window).
11195 * This function assumes that the drag is controlled by the
11196 * client pointer device, use gdk_window_begin_move_drag_for_device()
11197 * to begin a drag with a different device.
11200 gdk_window_begin_move_drag (GdkWindow *window,
11206 GdkDeviceManager *device_manager;
11209 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11210 device = gdk_device_manager_get_client_pointer (device_manager);
11211 gdk_window_begin_move_drag_for_device (window, device, button, root_x, root_y, timestamp);
11215 * gdk_window_enable_synchronized_configure:
11216 * @window: a toplevel #GdkWindow
11218 * Indicates that the application will cooperate with the window
11219 * system in synchronizing the window repaint with the window
11220 * manager during resizing operations. After an application calls
11221 * this function, it must call gdk_window_configure_finished() every
11222 * time it has finished all processing associated with a set of
11223 * Configure events. Toplevel GTK+ windows automatically use this
11226 * On X, calling this function makes @window participate in the
11227 * _NET_WM_SYNC_REQUEST window manager protocol.
11232 gdk_window_enable_synchronized_configure (GdkWindow *window)
11234 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->enable_synchronized_configure (window);
11238 * gdk_window_configure_finished:
11239 * @window: a toplevel #GdkWindow
11241 * Signal to the window system that the application has finished
11242 * handling Configure events it has received. Window Managers can
11243 * use this to better synchronize the frame repaint with the
11244 * application. GTK+ applications will automatically call this
11245 * function when appropriate.
11247 * This function can only be called if gdk_window_enable_synchronized_configure()
11248 * was called previously.
11253 gdk_window_configure_finished (GdkWindow *window)
11255 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->configure_finished (window);
11259 * gdk_window_set_opacity:
11260 * @window: a top-level or non-native #GdkWindow
11261 * @opacity: opacity
11263 * Set @window to render as partially transparent,
11264 * with opacity 0 being fully transparent and 1 fully opaque. (Values
11265 * of the opacity parameter are clamped to the [0,1] range.)
11267 * For toplevel windows this depends on support from the windowing system
11268 * that may not always be there. For instance, On X11, this works only on
11269 * X screens with a compositing manager running.
11271 * For child windows this function only works for non-native windows.
11273 * For setting up per-pixel alpha topelevels, see gdk_screen_get_rgba_visual(),
11274 * and for non-toplevels, see gdk_window_set_composited().
11276 * Support for non-toplevel windows was added in 3.8.
11281 gdk_window_set_opacity (GdkWindow *window,
11286 else if (opacity > 1)
11289 window->alpha = round (opacity * 255);
11291 if (window->destroyed)
11294 if (gdk_window_has_impl (window))
11295 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_opacity (window, opacity);
11298 recompute_visible_regions (window, TRUE, FALSE);
11299 gdk_window_invalidate_rect_full (window, NULL, TRUE, CLEAR_BG_ALL);
11303 /* This function is called when the XWindow is really gone.
11306 gdk_window_destroy_notify (GdkWindow *window)
11308 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->destroy_notify (window);
11312 * gdk_window_register_dnd:
11313 * @window: a #GdkWindow.
11315 * Registers a window as a potential drop destination.
11318 gdk_window_register_dnd (GdkWindow *window)
11320 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->register_dnd (window);
11324 * gdk_window_get_drag_protocol:
11325 * @window: the destination window
11326 * @target: (out) (allow-none) (transfer full): location of the window
11327 * where the drop should happen. This may be @window or a proxy window,
11328 * or %NULL if @window does not support Drag and Drop.
11330 * Finds out the DND protocol supported by a window.
11332 * Returns: the supported DND protocol.
11337 gdk_window_get_drag_protocol (GdkWindow *window,
11338 GdkWindow **target)
11340 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_DRAG_PROTO_NONE);
11342 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_drag_protocol (window, target);
11347 * @window: the source window for this drag.
11348 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11349 * as list of #GdkAtoms
11351 * Starts a drag and creates a new drag context for it.
11352 * This function assumes that the drag is controlled by the
11353 * client pointer device, use gdk_drag_begin_for_device() to
11354 * begin a drag with a different device.
11356 * This function is called by the drag source.
11358 * Return value: (transfer full): a newly created #GdkDragContext
11361 gdk_drag_begin (GdkWindow *window,
11364 GdkDeviceManager *device_manager;
11367 device_manager = gdk_display_get_device_manager (gdk_window_get_display (window));
11368 device = gdk_device_manager_get_client_pointer (device_manager);
11370 return gdk_drag_begin_for_device (window, device, targets);
11374 * gdk_drag_begin_for_device:
11375 * @window: the source window for this drag
11376 * @device: the device that controls this drag
11377 * @targets: (transfer none) (element-type GdkAtom): the offered targets,
11378 * as list of #GdkAtoms
11380 * Starts a drag and creates a new drag context for it.
11382 * This function is called by the drag source.
11384 * Return value: (transfer full): a newly created #GdkDragContext
11387 gdk_drag_begin_for_device (GdkWindow *window,
11391 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, targets);
11395 * gdk_test_render_sync:
11396 * @window: a mapped #GdkWindow
11398 * Retrieves a pixel from @window to force the windowing
11399 * system to carry out any pending rendering commands.
11401 * This function is intended to be used to synchronize with rendering
11402 * pipelines, to benchmark windowing system rendering operations.
11407 gdk_test_render_sync (GdkWindow *window)
11409 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->sync_rendering (window);
11413 * gdk_test_simulate_key:
11414 * @window: a #GdkWindow to simulate a key event for
11415 * @x: x coordinate within @window for the key event
11416 * @y: y coordinate within @window for the key event
11417 * @keyval: A GDK keyboard value
11418 * @modifiers: Keyboard modifiers the event is setup with
11419 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
11421 * This function is intended to be used in GTK+ test programs.
11422 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
11423 * the given (@x,@y) coordinates within @window and simulate a
11424 * key press or release event.
11426 * When the mouse pointer is warped to the target location, use
11427 * of this function outside of test programs that run in their
11428 * own virtual windowing system (e.g. Xvfb) is not recommended.
11429 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
11430 * be warped and @window origin will be used as mouse pointer
11431 * location for the event.
11433 * Also, gdk_test_simulate_key() is a fairly low level function,
11434 * for most testing purposes, gtk_test_widget_send_key() is the
11435 * right function to call which will generate a key press event
11436 * followed by its accompanying key release event.
11438 * Returns: whether all actions necessary for a key event simulation
11439 * were carried out successfully
11444 gdk_test_simulate_key (GdkWindow *window,
11448 GdkModifierType modifiers,
11449 GdkEventType key_pressrelease)
11451 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11452 ->simulate_key (window, x, y, keyval, modifiers, key_pressrelease);
11456 * gdk_test_simulate_button:
11457 * @window: a #GdkWindow to simulate a button event for
11458 * @x: x coordinate within @window for the button event
11459 * @y: y coordinate within @window for the button event
11460 * @button: Number of the pointer button for the event, usually 1, 2 or 3
11461 * @modifiers: Keyboard modifiers the event is setup with
11462 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
11464 * This function is intended to be used in GTK+ test programs.
11465 * It will warp the mouse pointer to the given (@x,@y) coordinates
11466 * within @window and simulate a button press or release event.
11467 * Because the mouse pointer needs to be warped to the target
11468 * location, use of this function outside of test programs that
11469 * run in their own virtual windowing system (e.g. Xvfb) is not
11472 * Also, gdk_test_simulate_button() is a fairly low level function,
11473 * for most testing purposes, gtk_test_widget_click() is the right
11474 * function to call which will generate a button press event followed
11475 * by its accompanying button release event.
11477 * Returns: whether all actions necessary for a button event simulation
11478 * were carried out successfully
11483 gdk_test_simulate_button (GdkWindow *window,
11486 guint button, /*1..3*/
11487 GdkModifierType modifiers,
11488 GdkEventType button_pressrelease)
11490 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11491 ->simulate_button (window, x, y, button, modifiers, button_pressrelease);
11495 * gdk_property_get:
11496 * @window: a #GdkWindow
11497 * @property: the property to retrieve
11498 * @type: the desired property type, or %GDK_NONE, if any type of data
11499 * is acceptable. If this does not match the actual
11500 * type, then @actual_format and @actual_length will
11501 * be filled in, a warning will be printed to stderr
11502 * and no data will be returned.
11503 * @offset: the offset into the property at which to begin
11504 * retrieving data, in 4 byte units.
11505 * @length: the length of the data to retrieve in bytes. Data is
11506 * considered to be retrieved in 4 byte chunks, so @length
11507 * will be rounded up to the next highest 4 byte boundary
11508 * (so be careful not to pass a value that might overflow
11509 * when rounded up).
11510 * @pdelete: if %TRUE, delete the property after retrieving the
11512 * @actual_property_type: (out) (transfer none): location to store the
11513 * actual type of the property.
11514 * @actual_format: (out): location to store the actual return format of the
11515 * data; either 8, 16 or 32 bits.
11516 * @actual_length: location to store the length of the retrieved data, in
11517 * bytes. Data returned in the 32 bit format is stored
11518 * in a long variable, so the actual number of 32 bit
11519 * elements should be be calculated via
11520 * @actual_length / sizeof(glong) to ensure portability to
11522 * @data: (out) (array length=actual_length) (transfer full): location
11523 * to store a pointer to the data. The retrieved data should be
11524 * freed with g_free() when you are finished using it.
11526 * Retrieves a portion of the contents of a property. If the
11527 * property does not exist, then the function returns %FALSE,
11528 * and %GDK_NONE will be stored in @actual_property_type.
11532 * The XGetWindowProperty() function that gdk_property_get()
11533 * uses has a very confusing and complicated set of semantics.
11534 * Unfortunately, gdk_property_get() makes the situation
11535 * worse instead of better (the semantics should be considered
11536 * undefined), and also prints warnings to stderr in cases where it
11537 * should return a useful error to the program. You are advised to use
11538 * XGetWindowProperty() directly until a replacement function for
11539 * gdk_property_get()
11544 * Returns: %TRUE if data was successfully received and stored
11545 * in @data, otherwise %FALSE.
11548 gdk_property_get (GdkWindow *window,
11554 GdkAtom *actual_property_type,
11555 gint *actual_format_type,
11556 gint *actual_length,
11559 return GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11560 ->get_property (window, property, type, offset, length, pdelete,
11561 actual_property_type, actual_format_type,
11562 actual_length, data);
11566 * gdk_property_change: (skip)
11567 * @window: a #GdkWindow
11568 * @property: the property to change
11569 * @type: the new type for the property. If @mode is
11570 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11571 * must match the existing type or an error will occur.
11572 * @format: the new format for the property. If @mode is
11573 * %GDK_PROP_MODE_PREPEND or %GDK_PROP_MODE_APPEND, then this
11574 * must match the existing format or an error will occur.
11575 * @mode: a value describing how the new data is to be combined
11576 * with the current data.
11577 * @data: the data (a <literal>guchar *</literal>
11578 * <literal>gushort *</literal>, or <literal>gulong *</literal>,
11579 * depending on @format), cast to a <literal>guchar *</literal>.
11580 * @nelements: the number of elements of size determined by the format,
11581 * contained in @data.
11583 * Changes the contents of a property on a window.
11586 gdk_property_change (GdkWindow *window,
11591 const guchar *data,
11594 GDK_WINDOW_IMPL_GET_CLASS (window->impl)
11595 ->change_property (window, property, type, format, mode, data, nelements);
11599 * gdk_property_delete:
11600 * @window: a #GdkWindow
11601 * @property: the property to delete
11603 * Deletes a property from a window.
11606 gdk_property_delete (GdkWindow *window,
11609 GDK_WINDOW_IMPL_GET_CLASS (window->impl)->delete_property (window, property);
11613 gdk_window_flush_events (GdkFrameClock *clock,
11617 GdkDisplay *display;
11619 window = GDK_WINDOW (data);
11621 display = gdk_window_get_display (window);
11622 _gdk_display_flush_events (display);
11623 _gdk_display_set_events_paused (display, TRUE);
11625 gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_RESUME_EVENTS);
11629 gdk_window_paint_on_clock (GdkFrameClock *clock,
11634 window = GDK_WINDOW (data);
11636 /* Update window and any children on the same clock.
11638 gdk_window_process_updates_with_mode (window, PROCESS_UPDATES_WITH_SAME_CLOCK_CHILDREN);
11642 gdk_window_resume_events (GdkFrameClock *clock,
11646 GdkDisplay *display;
11648 window = GDK_WINDOW (data);
11650 display = gdk_window_get_display (window);
11651 _gdk_display_set_events_paused (display, FALSE);
11655 * gdk_window_set_frame_clock:
11656 * @window: window to set frame clock on
11657 * @clock: the clock
11659 * Sets the frame clock for the window. The frame clock for a window
11660 * cannot be changed while the window is mapped. Set the frame
11661 * clock to #NULL to use the default frame clock. (By default the
11662 * frame clock comes from the window's parent or is a global default
11668 gdk_window_set_frame_clock (GdkWindow *window,
11669 GdkFrameClock *clock)
11671 g_return_if_fail (GDK_IS_WINDOW (window));
11672 g_return_if_fail (clock == NULL || GDK_IS_FRAME_CLOCK (clock));
11673 g_return_if_fail (!GDK_WINDOW_IS_MAPPED (window));
11675 if (clock == window->frame_clock)
11678 /* If we are using our parent's clock, then the parent will repaint
11679 * us when that clock fires. If we are using the default clock, then
11680 * it does a gdk_window_process_all_updates() which will repaint us
11681 * when the clock fires. If we are using our own clock, then we have
11682 * to connect to "paint" on it ourselves and paint ourselves and
11683 * any child windows.
11688 g_object_ref (clock);
11689 g_signal_connect (G_OBJECT (clock),
11691 G_CALLBACK (gdk_window_flush_events),
11693 g_signal_connect (G_OBJECT (clock),
11695 G_CALLBACK (gdk_window_paint_on_clock),
11697 g_signal_connect (G_OBJECT (clock),
11699 G_CALLBACK (gdk_window_resume_events),
11703 if (window->frame_clock)
11705 g_signal_handlers_disconnect_by_func (G_OBJECT (window->frame_clock),
11706 G_CALLBACK (gdk_window_flush_events),
11708 g_signal_handlers_disconnect_by_func (G_OBJECT (window->frame_clock),
11709 G_CALLBACK (gdk_window_paint_on_clock),
11711 g_signal_handlers_disconnect_by_func (G_OBJECT (window->frame_clock),
11712 G_CALLBACK (gdk_window_resume_events),
11714 g_object_unref (window->frame_clock);
11717 window->frame_clock = clock;
11718 g_object_notify (G_OBJECT (window), "paint-clock");
11720 /* We probably should recurse child windows and emit notify on their
11721 * paint-clock properties also, and we should emit notify when a
11722 * window is first parented.
11727 * gdk_window_get_frame_clock:
11728 * @window: window to get frame clock for
11730 * Gets the frame clock for the window. The frame clock for a window
11731 * never changes while the window is mapped. It may be changed at
11735 * Return value: (transfer none): the frame clock
11738 gdk_window_get_frame_clock (GdkWindow *window)
11740 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
11742 if (window->frame_clock != NULL)
11744 /* Frame clock set explicitly on this window */
11745 return window->frame_clock;
11751 /* parent's frame clock or default */
11752 parent = gdk_window_get_effective_parent (window);
11753 if (parent != NULL)
11755 return gdk_window_get_frame_clock (parent);
11759 gdk_ensure_default_frame_clock ();
11760 return _gdk_default_frame_clock;