diff options
author | Timm Bäder <mail@baedert.org> | 2018-12-25 12:02:11 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2018-12-25 12:06:06 +0100 |
commit | cc56dca251a7013da5083e7a0c7e64866ed637fd (patch) | |
tree | fc913bed143e9f86243dc538d832b3354d0e636f | |
parent | 1cfbca09b5561e388e3978609e297027d82b3abe (diff) | |
download | gtk+-cc56dca251a7013da5083e7a0c7e64866ed637fd.tar.gz |
window: Don't allocate GLists when changing cursors
We do this all the time when moving the cursor and we can now do it
without the GList allocations.
-rw-r--r-- | gtk/gtkwindow.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 339b0e6f89..85af7b29f6 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -11260,39 +11260,45 @@ update_cursor (GtkWindow *toplevel, GtkWidget *target) { GdkCursor *cursor = NULL; - GList *widgets = NULL, *l; + GtkWidget **widgets; + int n_widgets = 0; + int i; if (grab_widget && !gtk_widget_is_ancestor (target, grab_widget)) { /* Outside the grab widget, cursor stays to whatever the grab * widget says. */ - widgets = g_list_prepend (widgets, grab_widget); + widgets = g_alloca (sizeof (*widgets)); + widgets[0] = grab_widget; + n_widgets = 1; } else { /* Inside the grab widget or in absence of grabs, allow walking * up the hierarchy to find out the cursor. */ + widgets = g_alloca (sizeof (*widgets) * gtk_widget_get_depth (target)); + while (target) { - widgets = g_list_prepend (widgets, target); + widgets[n_widgets] = target; + n_widgets ++; if (grab_widget && target == grab_widget) break; target = _gtk_widget_get_parent (target); } } - for (l = g_list_last (widgets); l; l = l->prev) + for (i = 0; i < n_widgets; i ++) { - cursor = gtk_widget_get_cursor (l->data); + cursor = gtk_widget_get_cursor (widgets[i]); if (cursor) break; } gdk_surface_set_device_cursor (gtk_widget_get_surface (GTK_WIDGET (toplevel)), - device, cursor); - g_list_free (widgets); + device, cursor); } void |