1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gdkinternals.h"
21 #include "gdkrectangle.h"
22 #include "gdkprivate-x11.h"
23 #include "gdkscreen-x11.h"
24 #include "gdkdisplay-x11.h"
25 #include "gdkwindow-x11.h"
28 typedef struct _GdkWindowQueueItem GdkWindowQueueItem;
29 typedef struct _GdkWindowParentPos GdkWindowParentPos;
32 GDK_WINDOW_QUEUE_TRANSLATE,
33 GDK_WINDOW_QUEUE_ANTIEXPOSE
36 struct _GdkWindowQueueItem
40 GdkWindowQueueType type;
54 _gdk_x11_window_move_resize_child (GdkWindow *window,
60 g_return_if_fail (window != NULL);
61 g_return_if_fail (GDK_IS_WINDOW (window));
66 g_warning ("Native children wider or taller than 65535 pixels are not supported");
76 window->width = width;
77 window->height = height;
79 /* We don't really care about origin overflow, because on overflow
80 * the window won't be visible anyway and thus it will be shaped
83 _gdk_x11_window_tmp_unset_parent_bg (window);
84 _gdk_x11_window_tmp_unset_bg (window, TRUE);
85 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
86 GDK_WINDOW_XID (window),
87 window->x + window->parent->abs_x,
88 window->y + window->parent->abs_y,
90 _gdk_x11_window_tmp_reset_parent_bg (window);
91 _gdk_x11_window_tmp_reset_bg (window, TRUE);
95 expose_serial_predicate (Display *xdisplay,
99 gulong *serial = (gulong *)arg;
101 if (xev->xany.type == Expose || xev->xany.type == GraphicsExpose)
102 *serial = MIN (*serial, xev->xany.serial);
107 /* Find oldest possible serial for an outstanding expose event
110 find_current_serial (Display *xdisplay)
113 gulong serial = NextRequest (xdisplay);
115 XSync (xdisplay, False);
117 XCheckIfEvent (xdisplay, &xev, expose_serial_predicate, (XPointer)&serial);
123 queue_delete_link (GQueue *queue,
126 if (queue->tail == link)
127 queue->tail = link->prev;
129 queue->head = g_list_remove_link (queue->head, link);
130 g_list_free_1 (link);
135 queue_item_free (GdkWindowQueueItem *item)
139 g_object_remove_weak_pointer (G_OBJECT (item->window),
140 (gpointer *)&(item->window));
143 if (item->type == GDK_WINDOW_QUEUE_ANTIEXPOSE)
144 cairo_region_destroy (item->u.antiexpose.area);
147 if (item->u.translate.area)
148 cairo_region_destroy (item->u.translate.area);
155 _gdk_x11_display_free_translate_queue (GdkDisplay *display)
157 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
159 if (display_x11->translate_queue)
161 g_queue_foreach (display_x11->translate_queue, (GFunc)queue_item_free, NULL);
162 g_queue_free (display_x11->translate_queue);
163 display_x11->translate_queue = NULL;
168 gdk_window_queue (GdkWindow *window,
169 GdkWindowQueueItem *item)
171 GdkX11Display *display_x11 = GDK_X11_DISPLAY (GDK_WINDOW_DISPLAY (window));
173 if (!display_x11->translate_queue)
174 display_x11->translate_queue = g_queue_new ();
176 /* Keep length of queue finite by, if it grows too long,
177 * figuring out the latest relevant serial and discarding
178 * irrelevant queue items.
180 if (display_x11->translate_queue->length >= 64)
182 gulong serial = find_current_serial (GDK_WINDOW_XDISPLAY (window));
183 GList *tmp_list = display_x11->translate_queue->head;
187 GdkWindowQueueItem *item = tmp_list->data;
188 GList *next = tmp_list->next;
190 /* an overflow-safe (item->serial < serial) */
191 if (item->serial - serial > (gulong) G_MAXLONG)
193 queue_delete_link (display_x11->translate_queue, tmp_list);
194 queue_item_free (item);
201 /* Catch the case where someone isn't processing events and there
202 * is an event stuck in the event queue with an old serial:
203 * If we can't reduce the queue length by the above method,
204 * discard anti-expose items. (We can't discard translate
207 if (display_x11->translate_queue->length >= 64)
209 GList *tmp_list = display_x11->translate_queue->head;
213 GdkWindowQueueItem *item = tmp_list->data;
214 GList *next = tmp_list->next;
216 if (item->type == GDK_WINDOW_QUEUE_ANTIEXPOSE)
218 queue_delete_link (display_x11->translate_queue, tmp_list);
219 queue_item_free (item);
226 item->window = window;
227 item->serial = NextRequest (GDK_WINDOW_XDISPLAY (window));
229 g_object_add_weak_pointer (G_OBJECT (window),
230 (gpointer *)&(item->window));
232 g_queue_push_tail (display_x11->translate_queue, item);
236 _get_scratch_gc (GdkWindow *window, cairo_region_t *clip_region)
238 GdkX11Screen *screen;
239 XRectangle *rectangles;
243 screen = GDK_X11_SCREEN (gdk_window_get_screen (window));
244 depth = gdk_visual_get_depth (gdk_window_get_visual (window)) - 1;
246 if (!screen->subwindow_gcs[depth])
250 values.graphics_exposures = True;
251 values.subwindow_mode = IncludeInferiors;
253 screen->subwindow_gcs[depth] = XCreateGC (screen->xdisplay,
254 GDK_WINDOW_XID (window),
255 GCSubwindowMode | GCGraphicsExposures,
259 _gdk_x11_region_get_xrectangles (clip_region,
264 XSetClipRectangles (screen->xdisplay,
265 screen->subwindow_gcs[depth],
271 return screen->subwindow_gcs[depth];
277 _gdk_x11_window_translate (GdkWindow *window,
278 cairo_region_t *area,
282 GdkWindowQueueItem *item;
284 GdkRectangle extents;
286 cairo_region_get_extents (area, &extents);
288 xgc = _get_scratch_gc (window, area);
290 cairo_region_translate (area, -dx, -dy); /* Move to source region */
292 item = g_new (GdkWindowQueueItem, 1);
293 item->type = GDK_WINDOW_QUEUE_TRANSLATE;
294 item->u.translate.area = cairo_region_copy (area);
295 item->u.translate.dx = dx;
296 item->u.translate.dy = dy;
297 gdk_window_queue (window, item);
299 XCopyArea (GDK_WINDOW_XDISPLAY (window),
300 GDK_WINDOW_XID (window),
301 GDK_WINDOW_XID (window),
303 extents.x - dx, extents.y - dy,
304 extents.width, extents.height,
305 extents.x, extents.y);
309 _gdk_x11_window_queue_antiexpose (GdkWindow *window,
310 cairo_region_t *area)
312 GdkWindowQueueItem *item = g_new (GdkWindowQueueItem, 1);
313 item->type = GDK_WINDOW_QUEUE_ANTIEXPOSE;
314 item->u.antiexpose.area = area;
316 gdk_window_queue (window, item);
322 _gdk_x11_window_process_expose (GdkWindow *window,
326 cairo_region_t *invalidate_region = cairo_region_create_rectangle (area);
327 GdkX11Display *display_x11 = GDK_X11_DISPLAY (GDK_WINDOW_DISPLAY (window));
329 if (display_x11->translate_queue)
331 GList *tmp_list = display_x11->translate_queue->head;
335 GdkWindowQueueItem *item = tmp_list->data;
336 GList *next = tmp_list->next;
338 /* an overflow-safe (serial < item->serial) */
339 if (serial - item->serial > (gulong) G_MAXLONG)
341 if (item->window == window)
343 if (item->type == GDK_WINDOW_QUEUE_TRANSLATE)
345 if (item->u.translate.area)
347 cairo_region_t *intersection;
349 intersection = cairo_region_copy (invalidate_region);
350 cairo_region_intersect (intersection, item->u.translate.area);
351 cairo_region_subtract (invalidate_region, intersection);
352 cairo_region_translate (intersection, item->u.translate.dx, item->u.translate.dy);
353 cairo_region_union (invalidate_region, intersection);
354 cairo_region_destroy (intersection);
357 cairo_region_translate (invalidate_region, item->u.translate.dx, item->u.translate.dy);
359 else /* anti-expose */
361 cairo_region_subtract (invalidate_region, item->u.antiexpose.area);
367 queue_delete_link (display_x11->translate_queue, tmp_list);
368 queue_item_free (item);
374 if (!cairo_region_is_empty (invalidate_region))
375 _gdk_window_invalidate_for_expose (window, invalidate_region);
377 cairo_region_destroy (invalidate_region);