Skip to content

Instantly share code, notes, and snippets.

@chergert
Last active September 13, 2015 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chergert/7b2b6e038c1ae09cb0dc to your computer and use it in GitHub Desktop.
Save chergert/7b2b6e038c1ae09cb0dc to your computer and use it in GitHub Desktop.
Patch to use my GArrayList to drop GList. still room for more.
diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h
index e5ec4b2..080d61a 100644
--- a/gdk/gdkinternals.h
+++ b/gdk/gdkinternals.h
@@ -211,7 +211,7 @@ struct _GdkWindow
gint8 toplevel_window_type;
GList *filters;
- GList *children;
+ GArrayList children;
GList *native_children;
cairo_pattern_t *background;
diff --git a/gdk/gdkoffscreenwindow.c b/gdk/gdkoffscreenwindow.c
index 614e3f0..68065fe 100644
--- a/gdk/gdkoffscreenwindow.c
+++ b/gdk/gdkoffscreenwindow.c
@@ -195,7 +195,7 @@ gdk_offscreen_window_reparent (GdkWindow *window,
gdk_window_hide (window);
if (window->parent)
- window->parent->children = g_list_remove (window->parent->children, window);
+ g_array_list_remove (&window->parent->children, window);
old_parent = window->parent;
window->parent = new_parent;
@@ -203,7 +203,7 @@ gdk_offscreen_window_reparent (GdkWindow *window,
window->y = y;
if (new_parent)
- window->parent->children = g_list_prepend (window->parent->children, window);
+ g_array_list_prepend (&window->parent->children, window);
_gdk_synthesize_crossing_events_for_geometry_change (window);
if (old_parent)
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 44c30d1..54cd7b5 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -258,6 +258,8 @@ gdk_window_init (GdkWindow *window)
window->device_cursor = g_hash_table_new_full (NULL, NULL,
NULL, g_object_unref);
+
+ g_array_list_init (&window->children, NULL);
}
/* Stop and return on the first non-NULL parent */
@@ -508,6 +510,8 @@ gdk_window_finalize (GObject *object)
if (window->devices_inside)
g_list_free (window->devices_inside);
+ g_array_list_destroy (&window->children);
+
G_OBJECT_CLASS (gdk_window_parent_class)->finalize (object);
}
@@ -603,7 +607,7 @@ remove_sibling_overlapped_area (GdkWindow *window,
GdkWindow *sibling;
cairo_region_t *child_region;
GdkRectangle r;
- GList *l;
+ const GList *l;
cairo_region_t *shape;
parent = window->parent;
@@ -614,7 +618,7 @@ remove_sibling_overlapped_area (GdkWindow *window,
/* Convert from from window coords to parent coords */
cairo_region_translate (region, window->x, window->y);
- for (l = parent->children; l; l = l->next)
+ for (l = g_array_list_peek (&parent->children); l; l = l->next)
{
sibling = l->data;
@@ -671,10 +675,10 @@ remove_child_area (GdkWindow *window,
GdkWindow *child;
cairo_region_t *child_region;
GdkRectangle r;
- GList *l;
+ const GList *l;
cairo_region_t *shape;
- for (l = window->children; l; l = l->next)
+ for (l = g_array_list_peek (&window->children); l; l = l->next)
{
child = l->data;
@@ -785,12 +789,12 @@ gdk_window_update_visibility_recursively (GdkWindow *window,
GdkWindow *only_for_impl)
{
GdkWindow *child;
- GList *l;
+ gsize i;
gdk_window_update_visibility (window);
- for (l = window->children; l != NULL; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&window->children, i);
if ((only_for_impl == NULL) ||
(only_for_impl == child->impl_window))
gdk_window_update_visibility_recursively (child, only_for_impl);
@@ -882,12 +886,12 @@ recompute_visible_regions_internal (GdkWindow *private,
gboolean recalculate_children)
{
GdkRectangle r;
- GList *l;
GdkWindow *child;
cairo_region_t *new_clip;
gboolean clip_region_changed;
gboolean abs_pos_changed;
int old_abs_x, old_abs_y;
+ gsize i;
old_abs_x = private->abs_x;
old_abs_y = private->abs_y;
@@ -986,9 +990,9 @@ recompute_visible_regions_internal (GdkWindow *private,
if ((abs_pos_changed || clip_region_changed || recalculate_children) &&
private->window_type != GDK_WINDOW_ROOT)
{
- for (l = private->children; l; l = l->next)
+ for (i = 0; i < private->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&private->children, i);
/* Only recalculate clip if the the clip region changed, otherwise
* there is no way the child clip region could change (its has not e.g. moved)
* Except if recalculate_children is set to force child updates
@@ -1072,16 +1076,19 @@ find_native_sibling_above_helper (GdkWindow *parent,
GdkWindow *child)
{
GdkWindow *w;
- GList *l;
+ const GList *children;
+ const GList *l;
+
+ children = g_array_list_peek (&parent->children);
if (child)
{
- l = g_list_find (parent->children, child);
+ l = g_list_find ((GList *)children, child);
g_assert (l != NULL); /* Better be a child of its parent... */
l = l->prev; /* Start looking at the one above the child */
}
else
- l = g_list_last (parent->children);
+ l = g_array_list_last_link (&parent->children);
for (; l != NULL; l = l->prev)
{
@@ -1369,7 +1376,7 @@ gdk_window_new (GdkWindow *parent,
window->input_only = TRUE;
}
- window->parent->children = g_list_prepend (window->parent->children, window);
+ g_array_list_add (&window->parent->children, window);
if (window->parent->window_type == GDK_WINDOW_ROOT)
{
@@ -1456,7 +1463,7 @@ change_impl (GdkWindow *private,
GdkWindow *impl_window,
GdkWindowImpl *new)
{
- GList *l;
+ const GList *l;
GdkWindow *child;
GdkWindowImpl *old_impl;
GdkWindow *old_impl_window;
@@ -1472,7 +1479,7 @@ change_impl (GdkWindow *private,
g_object_unref (old_impl_window);
g_object_unref (old_impl);
- for (l = private->children; l != NULL; l = l->next)
+ for (l = g_array_list_peek (&private->children); l != NULL; l = l->next)
{
child = l->data;
@@ -1492,18 +1499,18 @@ change_impl (GdkWindow *private,
static void
reparent_to_impl (GdkWindow *private)
{
- GList *l;
GdkWindow *child;
gboolean show;
GdkWindowImplClass *impl_class;
+ gsize i;
impl_class = GDK_WINDOW_IMPL_GET_CLASS (private->impl);
/* Enumerate in reverse order so we get the right order for the native
windows (first in childrens list is topmost, and reparent places on top) */
- for (l = g_list_last (private->children); l != NULL; l = l->prev)
+ for (i = private->children.len; i > 0; i--)
{
- child = l->data;
+ child = g_array_list_index (&private->children, i - 1);
if (child->impl == private->impl)
reparent_to_impl (child);
@@ -1606,7 +1613,7 @@ gdk_window_reparent (GdkWindow *window,
if (old_parent)
{
- old_parent->children = g_list_remove (old_parent->children, window);
+ g_array_list_remove (&old_parent->children, window);
if (gdk_window_has_impl (window))
old_parent->impl_window->native_children =
@@ -1617,7 +1624,7 @@ gdk_window_reparent (GdkWindow *window,
window->x = x;
window->y = y;
- new_parent->children = g_list_prepend (new_parent->children, window);
+ g_array_list_prepend (&new_parent->children, window);
if (gdk_window_has_impl (window))
new_parent->impl_window->native_children = g_list_prepend (new_parent->impl_window->native_children, window);
@@ -1973,8 +1980,8 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
{
if (window->parent)
{
- if (window->parent->children)
- window->parent->children = g_list_remove (window->parent->children, window);
+ if (window->parent->children.len)
+ g_array_list_remove (&window->parent->children, window);
if (gdk_window_has_impl (window))
window->parent->impl_window->native_children =
@@ -2011,11 +2018,11 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
}
if (window->window_type == GDK_WINDOW_FOREIGN)
- g_assert (window->children == NULL);
+ g_assert (window->children.len == 0);
else
{
- children = tmp = window->children;
- window->children = NULL;
+ children = tmp = g_list_copy ((GList *)g_array_list_peek (&window->children));
+ g_array_list_clear (&window->children);
while (tmp)
{
@@ -2434,7 +2441,7 @@ gdk_window_get_children (GdkWindow *window)
if (GDK_WINDOW_DESTROYED (window))
return NULL;
- return g_list_copy (window->children);
+ return g_list_copy ((GList *)g_array_list_peek (&window->children));
}
/**
@@ -2455,7 +2462,7 @@ gdk_window_peek_children (GdkWindow *window)
if (GDK_WINDOW_DESTROYED (window))
return NULL;
- return window->children;
+ return (GList *)g_array_list_peek (&window->children);
}
@@ -2483,7 +2490,8 @@ gdk_window_get_children_with_user_data (GdkWindow *window,
gpointer user_data)
{
GdkWindow *child;
- GList *res, *l;
+ gsize i;
+ GList *res;
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
@@ -2491,9 +2499,9 @@ gdk_window_get_children_with_user_data (GdkWindow *window,
return NULL;
res = NULL;
- for (l = window->children; l != NULL; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&window->children, i);
if (child->user_data == user_data)
res = g_list_prepend (res, child);
@@ -2625,13 +2633,13 @@ gdk_screen_get_toplevel_windows (GdkScreen *screen)
{
GdkWindow * root_window;
GList *new_list = NULL;
- GList *tmp_list;
+ const GList *tmp_list;
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
root_window = gdk_screen_get_root_window (screen);
- tmp_list = root_window->children;
+ tmp_list = g_array_list_peek (&root_window->children);
while (tmp_list)
{
GdkWindow *w = tmp_list->data;
@@ -3390,10 +3398,10 @@ gdk_window_add_update_window (GdkWindow *window)
*/
if (parent == GDK_WINDOW (tmp->data)->parent)
{
- gint index = g_list_index (parent->children, window);
+ gint index = g_array_list_find (&parent->children, window);
for (; tmp && parent == GDK_WINDOW (tmp->data)->parent; tmp = tmp->next)
{
- gint sibling_index = g_list_index (parent->children, tmp->data);
+ gint sibling_index = g_array_list_find (&parent->children, tmp->data);
if (index > sibling_index)
break;
prev = tmp;
@@ -3508,7 +3516,9 @@ _gdk_window_process_updates_recurse_helper (GdkWindow *window,
{
GdkWindow *child;
cairo_region_t *clipped_expose_region;
- GList *l, *children;
+ gpointer *children;
+ gsize len;
+ gsize i;
if (window->destroyed)
return;
@@ -3554,13 +3564,13 @@ _gdk_window_process_updates_recurse_helper (GdkWindow *window,
}
/* Make this reentrancy safe for expose handlers freeing windows */
- children = g_list_copy (window->children);
- g_list_foreach (children, (GFunc)g_object_ref, NULL);
+ children = g_array_list_copy_reversed (&window->children, (GCopyFunc)g_object_ref, NULL);
+ len = window->children.len;
/* Iterate over children, starting at bottommost */
- for (l = g_list_last (children); l != NULL; l = l->prev)
+ for (i = 0; i < len; i++)
{
- child = l->data;
+ child = children [i];
if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child) || child->input_only || child->composited)
continue;
@@ -3575,7 +3585,10 @@ _gdk_window_process_updates_recurse_helper (GdkWindow *window,
_gdk_window_process_updates_recurse_helper ((GdkWindow *)child, clipped_expose_region);
}
- g_list_free_full (children, g_object_unref);
+ for (i = 0; i < len; i++)
+ g_object_unref (children [i]);
+
+ g_free (children);
out:
cairo_region_destroy (clipped_expose_region);
@@ -3814,7 +3827,7 @@ find_impl_windows_to_update (GList *list,
GdkWindow *window,
gint recurse_mode)
{
- GList *node;
+ const GList *node;
if (GDK_WINDOW_DESTROYED (window))
return list;
@@ -3825,7 +3838,7 @@ find_impl_windows_to_update (GList *list,
*/
if (recurse_mode != PROCESS_UPDATES_NO_RECURSE)
{
- for (node = window->children; node; node = node->next)
+ for (node = g_array_list_peek (&window->children); node; node = node->next)
{
GdkWindow *child = node->data;
@@ -4028,14 +4041,11 @@ invalidate_impl_subwindows (GdkWindow *window,
gpointer user_data,
int dx, int dy)
{
- GList *tmp_list;
+ gsize i;
- tmp_list = window->children;
-
- while (tmp_list)
+ for (i = 0; i < window->children.len; i++)
{
- GdkWindow *child = tmp_list->data;
- tmp_list = tmp_list->next;
+ GdkWindow *child = g_array_list_index (&window->children, i);
if (child->input_only ||
!window->viewable)
@@ -4745,11 +4755,11 @@ get_all_native_children (GdkWindow *window,
GList **native)
{
GdkWindow *child;
- GList *l;
+ gsize i;
- for (l = window->children; l != NULL; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&window->children, i);
if (gdk_window_has_impl (child))
*native = g_list_prepend (*native, child);
@@ -4768,11 +4778,12 @@ gdk_window_raise_internal (GdkWindow *window)
GList *l, listhead;
GdkWindowImplClass *impl_class;
gboolean did_raise = FALSE;
+ gsize index;
- if (parent && parent->children->data != window)
+ if (parent && g_array_list_first (&parent->children) != window)
{
- parent->children = g_list_remove (parent->children, window);
- parent->children = g_list_prepend (parent->children, window);
+ index = g_array_list_find (&parent->children, window);
+ g_array_list_move (&parent->children, index, 0);
did_raise = TRUE;
}
@@ -4833,7 +4844,7 @@ set_viewable (GdkWindow *w,
{
GdkWindow *child;
GdkWindowImplClass *impl_class;
- GList *l;
+ gsize i;
if (w->viewable == val)
return FALSE;
@@ -4843,9 +4854,9 @@ set_viewable (GdkWindow *w,
if (val)
recompute_visible_regions (w, FALSE);
- for (l = w->children; l != NULL; l = l->next)
+ for (i = 0; i < w->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&w->children, i);
if (GDK_WINDOW_IS_MAPPED (child) &&
child->window_type != GDK_WINDOW_FOREIGN)
@@ -5037,11 +5048,12 @@ gdk_window_lower_internal (GdkWindow *window)
GdkWindow *above;
GList *native_children;
GList *l, listhead;
+ gsize index;
if (parent)
{
- parent->children = g_list_remove (parent->children, window);
- parent->children = g_list_append (parent->children, window);
+ index = g_array_list_find (&parent->children, window);
+ g_array_list_move (&parent->children, index, parent->children.len - 1);
}
impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
@@ -5173,9 +5185,10 @@ gdk_window_restack (GdkWindow *window,
GdkWindowImplClass *impl_class;
GdkWindow *parent;
GdkWindow *above_native;
- GList *sibling_link;
GList *native_children;
GList *l, listhead;
+ gssize sibling_index;
+ gsize our_index;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (sibling == NULL || GDK_IS_WINDOW (sibling));
@@ -5203,20 +5216,16 @@ gdk_window_restack (GdkWindow *window,
parent = window->parent;
if (parent)
{
- sibling_link = g_list_find (parent->children, sibling);
- g_return_if_fail (sibling_link != NULL);
- if (sibling_link == NULL)
+ our_index = g_array_list_find (&parent->children, window);
+ sibling_index = g_array_list_find (&parent->children, sibling);
+ g_return_if_fail (sibling_index >= 0);
+ if (sibling_index < 0)
return;
- parent->children = g_list_remove (parent->children, window);
- if (above)
- parent->children = g_list_insert_before (parent->children,
- sibling_link,
- window);
- else
- parent->children = g_list_insert_before (parent->children,
- sibling_link->next,
- window);
+ if (above && sibling_index > our_index)
+ g_array_list_move (&parent->children, sibling_index, our_index);
+ else if (!above && sibling_index < our_index)
+ g_array_list_move (&parent->children, sibling_index, our_index);
impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
if (gdk_window_has_impl (window))
@@ -5638,13 +5647,13 @@ gdk_window_move_resize_toplevel (GdkWindow *window,
static void
move_native_children (GdkWindow *private)
{
- GList *l;
GdkWindow *child;
GdkWindowImplClass *impl_class;
+ gsize i;
- for (l = private->children; l; l = l->next)
+ for (i = 0; i < private->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&private->children, i);
if (child->impl != private->impl)
{
@@ -5854,7 +5863,7 @@ gdk_window_scroll (GdkWindow *window,
gint dx,
gint dy)
{
- GList *tmp_list;
+ gsize i;
g_return_if_fail (GDK_IS_WINDOW (window));
@@ -5866,16 +5875,13 @@ gdk_window_scroll (GdkWindow *window,
/* First move all child windows, without causing invalidation */
- tmp_list = window->children;
- while (tmp_list)
+ for (i = 0; i < window->children.len; i++)
{
- GdkWindow *child = GDK_WINDOW (tmp_list->data);
+ GdkWindow *child = GDK_WINDOW (g_array_list_index (&window->children, i));
/* Just update the positions, the bits will move with the copy */
child->x += dx;
child->y += dy;
-
- tmp_list = tmp_list->next;
}
recompute_visible_regions (window, TRUE);
@@ -7214,7 +7220,7 @@ point_in_input_window (GdkWindow *window,
{
GdkWindow *sub;
double child_x, child_y;
- GList *l;
+ gsize i;
if (!point_in_window (window, x, y))
return FALSE;
@@ -7233,9 +7239,9 @@ point_in_input_window (GdkWindow *window,
/* For pass-through, must be over a child input window */
/* Children is ordered in reverse stack order, i.e. first is topmost */
- for (l = window->children; l != NULL; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- sub = l->data;
+ sub = g_array_list_index (&window->children, i);
if (!GDK_WINDOW_IS_MAPPED (sub))
continue;
@@ -7337,14 +7343,14 @@ _gdk_window_find_child_at (GdkWindow *window,
{
GdkWindow *sub;
double child_x, child_y;
- GList *l;
+ gsize i;
if (point_in_window (window, x, y))
{
/* Children is ordered in reverse stack order, i.e. first is topmost */
- for (l = window->children; l != NULL; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- sub = l->data;
+ sub = g_array_list_index (&window->children, i);
if (!GDK_WINDOW_IS_MAPPED (sub))
continue;
@@ -7378,8 +7384,8 @@ _gdk_window_find_descendant_at (GdkWindow *window,
{
GdkWindow *sub, *input_window;
gdouble child_x, child_y;
- GList *l;
gboolean found;
+ gsize i;
if (point_in_window (window, x, y))
{
@@ -7387,9 +7393,9 @@ _gdk_window_find_descendant_at (GdkWindow *window,
{
found = FALSE;
/* Children is ordered in reverse stack order, i.e. first is topmost */
- for (l = window->children; l != NULL; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- sub = l->data;
+ sub = g_array_list_index (&window->children, i);
if (!GDK_WINDOW_IS_MAPPED (sub))
continue;
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index 1ace677..d98ae14 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -662,9 +662,9 @@ _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
if (recurse)
{
- GList *l;
+ const GList *l;
- for (l = window->children; l != NULL; l = l->next)
+ for (l = g_array_list_peek (&window->children); l != NULL; l = l->next)
_gdk_x11_window_tmp_unset_bg (l->data, TRUE);
}
}
@@ -699,9 +699,9 @@ _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
if (recurse)
{
- GList *l;
+ const GList *l;
- for (l = window->children; l != NULL; l = l->next)
+ for (l = g_array_list_peek (&window->children); l != NULL; l = l->next)
_gdk_x11_window_tmp_reset_bg (l->data, TRUE);
}
}
@@ -1239,7 +1239,7 @@ gdk_x11_window_foreign_new_for_display (GdkDisplay *display,
if (!win->parent || GDK_WINDOW_TYPE (win->parent) == GDK_WINDOW_FOREIGN)
win->parent = gdk_screen_get_root_window (screen);
- win->parent->children = g_list_prepend (win->parent->children, win);
+ g_array_list_prepend (&win->parent->children, win);
win->parent->impl_window->native_children =
g_list_prepend (win->parent->impl_window->native_children, win);
@@ -1895,11 +1895,11 @@ static void
set_scale_recursive (GdkWindow *window, int scale)
{
GdkWindow *child;
- GList *l;
+ gsize i;
- for (l = window->children; l; l = l->next)
+ for (i = 0; i < window->children.len; i++)
{
- child = l->data;
+ child = g_array_list_index (&window->children, i);
if (child->impl != window->impl)
_gdk_x11_window_set_window_scale (child, scale);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment