[gtk/wip/sort-icons-by-size] window: sort icons before adding to _NET_WM_ICON
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/sort-icons-by-size] window: sort icons before adding to _NET_WM_ICON
- Date: Thu, 1 Aug 2019 20:49:25 +0000 (UTC)
commit 1612e38cdaba54fb6a88c333be7a148110bd1748
Author: Ray Strode <rstrode redhat com>
Date: Thu Aug 1 16:28:00 2019 -0400
window: sort icons before adding to _NET_WM_ICON
When processing the list of icons for a window to add them to
_NET_WM_ICON gdk_x11_surface_set_icon_list only adds as many
icon sizes as will fit within X protocol limits.
It achieves this by keeping a running total of the number of
bytes taken up by icons already processed and bails as soon
as it goes over the limit.
The problem is, one 512x512 icon is already over the limit,
and so no icons will get added at all if the first icon in
list is 512x512.
Indeed, the code seems to assume the list is sorted from smallest
icon to biggest icon.
This commit changes the caller to sort the list.
gtk/gtkwindow.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 1ee033f193..bda39f9156 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -4007,6 +4007,18 @@ ensure_icon_info (GtkWindow *window)
return info;
}
+static int
+icon_size_compare (GdkTexture *a,
+ GdkTexture *b)
+{
+ int area_a, area_b;
+
+ area_a = gdk_texture_get_width (a) * gdk_texture_get_height (a);
+ area_b = gdk_texture_get_width (b) * gdk_texture_get_height (b);
+
+ return area_a - area_b;
+}
+
static GList *
icon_list_from_theme (GtkWindow *window,
const gchar *name)
@@ -4044,7 +4056,7 @@ icon_list_from_theme (GtkWindow *window,
0);
if (info)
{
- list = g_list_append (list, gtk_icon_info_load_texture (info));
+ list = g_list_insert_sorted (list, gtk_icon_info_load_texture (info), (GCompareFunc)
icon_size_compare);
g_object_unref (info);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]