2000-03-28 01:24:44 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2000-03-28 01:24:44 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
* Lesser General Public License for more details.
|
2000-03-28 01:24:44 +00:00
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2000-03-28 01:24:44 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
|
2010-12-16 03:09:35 +00:00
|
|
|
#include "gdkinternals.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
#include "gdkrectangle.h"
|
2000-03-28 01:24:44 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
2002-04-25 22:29:14 +00:00
|
|
|
#include "gdkscreen-x11.h"
|
|
|
|
#include "gdkdisplay-x11.h"
|
2004-07-09 22:44:35 +00:00
|
|
|
#include "gdkwindow-x11.h"
|
2010-07-09 00:34:45 +00:00
|
|
|
|
2000-03-28 01:24:44 +00:00
|
|
|
|
|
|
|
typedef struct _GdkWindowQueueItem GdkWindowQueueItem;
|
|
|
|
typedef struct _GdkWindowParentPos GdkWindowParentPos;
|
|
|
|
|
|
|
|
struct _GdkWindowQueueItem
|
|
|
|
{
|
|
|
|
GdkWindow *window;
|
|
|
|
gulong serial;
|
2013-04-17 12:15:51 +00:00
|
|
|
cairo_region_t *antiexpose_area;
|
2000-03-28 01:24:44 +00:00
|
|
|
};
|
|
|
|
|
2004-05-10 20:51:19 +00:00
|
|
|
static Bool
|
2002-02-06 00:41:07 +00:00
|
|
|
expose_serial_predicate (Display *xdisplay,
|
|
|
|
XEvent *xev,
|
|
|
|
XPointer arg)
|
|
|
|
{
|
|
|
|
gulong *serial = (gulong *)arg;
|
|
|
|
|
2009-08-13 11:07:13 +00:00
|
|
|
if (xev->xany.type == Expose || xev->xany.type == GraphicsExpose)
|
2002-02-06 00:41:07 +00:00
|
|
|
*serial = MIN (*serial, xev->xany.serial);
|
|
|
|
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find oldest possible serial for an outstanding expose event
|
|
|
|
*/
|
|
|
|
static gulong
|
|
|
|
find_current_serial (Display *xdisplay)
|
|
|
|
{
|
|
|
|
XEvent xev;
|
|
|
|
gulong serial = NextRequest (xdisplay);
|
|
|
|
|
|
|
|
XSync (xdisplay, False);
|
|
|
|
|
|
|
|
XCheckIfEvent (xdisplay, &xev, expose_serial_predicate, (XPointer)&serial);
|
|
|
|
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
queue_delete_link (GQueue *queue,
|
|
|
|
GList *link)
|
|
|
|
{
|
|
|
|
if (queue->tail == link)
|
|
|
|
queue->tail = link->prev;
|
|
|
|
|
|
|
|
queue->head = g_list_remove_link (queue->head, link);
|
|
|
|
g_list_free_1 (link);
|
|
|
|
queue->length--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
queue_item_free (GdkWindowQueueItem *item)
|
|
|
|
{
|
2004-02-02 23:26:55 +00:00
|
|
|
if (item->window)
|
|
|
|
{
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (item->window),
|
|
|
|
(gpointer *)&(item->window));
|
|
|
|
}
|
2002-02-06 00:41:07 +00:00
|
|
|
|
2013-04-17 12:15:51 +00:00
|
|
|
cairo_region_destroy (item->antiexpose_area);
|
2002-02-06 00:41:07 +00:00
|
|
|
g_free (item);
|
|
|
|
}
|
|
|
|
|
2011-04-09 01:34:25 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_display_free_translate_queue (GdkDisplay *display)
|
|
|
|
{
|
|
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
|
|
|
|
|
|
|
|
if (display_x11->translate_queue)
|
|
|
|
{
|
|
|
|
g_queue_foreach (display_x11->translate_queue, (GFunc)queue_item_free, NULL);
|
|
|
|
g_queue_free (display_x11->translate_queue);
|
|
|
|
display_x11->translate_queue = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-06 00:41:07 +00:00
|
|
|
static void
|
|
|
|
gdk_window_queue (GdkWindow *window,
|
2015-05-31 01:17:45 +00:00
|
|
|
GdkWindowQueueItem *new_item)
|
2002-02-06 00:41:07 +00:00
|
|
|
{
|
2010-12-20 18:20:10 +00:00
|
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (GDK_WINDOW_DISPLAY (window));
|
2002-04-25 22:29:14 +00:00
|
|
|
|
|
|
|
if (!display_x11->translate_queue)
|
|
|
|
display_x11->translate_queue = g_queue_new ();
|
2002-02-06 00:41:07 +00:00
|
|
|
|
|
|
|
/* Keep length of queue finite by, if it grows too long,
|
|
|
|
* figuring out the latest relevant serial and discarding
|
|
|
|
* irrelevant queue items.
|
|
|
|
*/
|
2002-04-25 22:29:14 +00:00
|
|
|
if (display_x11->translate_queue->length >= 64)
|
2002-02-06 00:41:07 +00:00
|
|
|
{
|
|
|
|
gulong serial = find_current_serial (GDK_WINDOW_XDISPLAY (window));
|
2002-04-25 22:29:14 +00:00
|
|
|
GList *tmp_list = display_x11->translate_queue->head;
|
2002-02-06 00:41:07 +00:00
|
|
|
|
|
|
|
while (tmp_list)
|
|
|
|
{
|
|
|
|
GdkWindowQueueItem *item = tmp_list->data;
|
|
|
|
GList *next = tmp_list->next;
|
|
|
|
|
2007-09-10 18:07:39 +00:00
|
|
|
/* an overflow-safe (item->serial < serial) */
|
|
|
|
if (item->serial - serial > (gulong) G_MAXLONG)
|
2002-02-06 00:41:07 +00:00
|
|
|
{
|
2002-04-25 22:29:14 +00:00
|
|
|
queue_delete_link (display_x11->translate_queue, tmp_list);
|
2002-02-06 00:41:07 +00:00
|
|
|
queue_item_free (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_list = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Catch the case where someone isn't processing events and there
|
|
|
|
* is an event stuck in the event queue with an old serial:
|
|
|
|
* If we can't reduce the queue length by the above method,
|
|
|
|
* discard anti-expose items. (We can't discard translate
|
|
|
|
* items
|
|
|
|
*/
|
2002-04-25 22:29:14 +00:00
|
|
|
if (display_x11->translate_queue->length >= 64)
|
2002-02-06 00:41:07 +00:00
|
|
|
{
|
2002-04-25 22:29:14 +00:00
|
|
|
GList *tmp_list = display_x11->translate_queue->head;
|
2002-02-06 00:41:07 +00:00
|
|
|
|
|
|
|
while (tmp_list)
|
|
|
|
{
|
|
|
|
GdkWindowQueueItem *item = tmp_list->data;
|
|
|
|
GList *next = tmp_list->next;
|
|
|
|
|
2013-04-17 12:15:51 +00:00
|
|
|
queue_delete_link (display_x11->translate_queue, tmp_list);
|
|
|
|
queue_item_free (item);
|
2002-02-06 00:41:07 +00:00
|
|
|
|
|
|
|
tmp_list = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-31 01:17:45 +00:00
|
|
|
new_item->window = window;
|
|
|
|
new_item->serial = NextRequest (GDK_WINDOW_XDISPLAY (window));
|
2002-02-06 00:41:07 +00:00
|
|
|
|
2004-02-02 23:26:55 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window),
|
2015-05-31 01:17:45 +00:00
|
|
|
(gpointer *)&(new_item->window));
|
2004-02-02 23:26:55 +00:00
|
|
|
|
2015-05-31 01:17:45 +00:00
|
|
|
g_queue_push_tail (display_x11->translate_queue, new_item);
|
2002-02-06 00:41:07 +00:00
|
|
|
}
|
|
|
|
|
2014-06-21 22:03:56 +00:00
|
|
|
void
|
2008-07-18 13:03:42 +00:00
|
|
|
_gdk_x11_window_queue_antiexpose (GdkWindow *window,
|
2010-06-28 12:54:37 +00:00
|
|
|
cairo_region_t *area)
|
2000-03-28 01:24:44 +00:00
|
|
|
{
|
|
|
|
GdkWindowQueueItem *item = g_new (GdkWindowQueueItem, 1);
|
2014-06-21 22:03:56 +00:00
|
|
|
item->antiexpose_area = cairo_region_reference (area);
|
2000-03-28 01:24:44 +00:00
|
|
|
|
2002-02-06 00:41:07 +00:00
|
|
|
gdk_window_queue (window, item);
|
2000-03-28 01:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-16 03:21:39 +00:00
|
|
|
_gdk_x11_window_process_expose (GdkWindow *window,
|
|
|
|
gulong serial,
|
|
|
|
GdkRectangle *area)
|
2000-03-28 01:24:44 +00:00
|
|
|
{
|
2010-06-28 12:54:37 +00:00
|
|
|
cairo_region_t *invalidate_region = cairo_region_create_rectangle (area);
|
2010-12-20 18:20:10 +00:00
|
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (GDK_WINDOW_DISPLAY (window));
|
2005-06-21 04:09:52 +00:00
|
|
|
|
2002-04-25 22:29:14 +00:00
|
|
|
if (display_x11->translate_queue)
|
2000-03-28 01:24:44 +00:00
|
|
|
{
|
2002-04-25 22:29:14 +00:00
|
|
|
GList *tmp_list = display_x11->translate_queue->head;
|
2009-09-10 02:40:44 +00:00
|
|
|
|
2002-02-06 00:41:07 +00:00
|
|
|
while (tmp_list)
|
2010-12-16 03:21:39 +00:00
|
|
|
{
|
|
|
|
GdkWindowQueueItem *item = tmp_list->data;
|
2007-09-09 16:24:34 +00:00
|
|
|
GList *next = tmp_list->next;
|
2009-09-10 02:40:44 +00:00
|
|
|
|
2010-12-16 03:21:39 +00:00
|
|
|
/* an overflow-safe (serial < item->serial) */
|
|
|
|
if (serial - item->serial > (gulong) G_MAXLONG)
|
|
|
|
{
|
|
|
|
if (item->window == window)
|
2013-04-17 12:15:51 +00:00
|
|
|
cairo_region_subtract (invalidate_region, item->antiexpose_area);
|
2010-12-16 03:21:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
queue_delete_link (display_x11->translate_queue, tmp_list);
|
|
|
|
queue_item_free (item);
|
|
|
|
}
|
|
|
|
tmp_list = next;
|
|
|
|
}
|
2000-03-28 01:24:44 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 12:44:12 +00:00
|
|
|
if (!cairo_region_is_empty (invalidate_region))
|
2008-07-18 13:03:42 +00:00
|
|
|
_gdk_window_invalidate_for_expose (window, invalidate_region);
|
2009-09-10 02:40:44 +00:00
|
|
|
|
2010-06-28 12:44:12 +00:00
|
|
|
cairo_region_destroy (invalidate_region);
|
2000-03-28 01:24:44 +00:00
|
|
|
}
|