[glib: 1/8] gio: icons should fallback to non-preferred style appropriately.
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/8] gio: icons should fallback to non-preferred style appropriately.
- Date: Fri, 17 Aug 2018 12:52:15 +0000 (UTC)
commit e0f2671a4adca4b09bd84de186955d13a090ff49
Author: Jehan <jehan girinstud io>
Date: Thu Jun 7 01:54:36 2018 +0200
gio: icons should fallback to non-preferred style appropriately.
Whatever the preferred icon style is (symbolic, regular or the requested
style), fallbacking to the other style in case of absent variant is
better than not finding any icon at all.
Also style fallbacking should be managed separately from property
"use-default-fallbacks". Default fallbacks are meant for the process of
getting up in context levels (as separated by dashes in icon name). Even
though it also uses dash characters in format, this is a different
concept as the variant of styles.
Without this commit for instance, if an icon only had a symbolic
variant, and the theme had "-gtk-icon-style" set to "regular" while your
GTK+ application requested the regular icon name, you were getting no
icons, and the application would look completely broken.
Now one would at least fallback to the symbolic icon as last resort
(which is infinitely better than having no icons).
gio/gthemedicon.c | 58 +++++++++++++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/gio/gthemedicon.c b/gio/gthemedicon.c
index 3ada77b6c..71a692bd2 100644
--- a/gio/gthemedicon.c
+++ b/gio/gthemedicon.c
@@ -143,25 +143,27 @@ g_themed_icon_set_property (GObject *object,
static void
g_themed_icon_constructed (GObject *object)
{
- GThemedIcon *themed = G_THEMED_ICON (object);
+ GThemedIcon *themed = G_THEMED_ICON (object);
+ gchar **names;
+ gchar *name;
+ gboolean is_symbolic;
+ gint i = 0;
+ gint n_names;
g_return_if_fail (themed->names != NULL && themed->names[0] != NULL);
+ is_symbolic = g_str_has_suffix (themed->names[0], "-symbolic");
+ if (is_symbolic)
+ name = g_strndup (themed->names[0], strlen (themed->names[0]) - 9);
+ else
+ name = g_strdup (themed->names[0]);
+
if (themed->use_default_fallbacks)
{
- int i = 0, dashes = 0;
+ int dashes = 0;
const char *p;
char *dashp;
char *last;
- gboolean is_symbolic;
- char *name;
- char **names;
-
- is_symbolic = g_str_has_suffix (themed->names[0], "-symbolic");
- if (is_symbolic)
- name = g_strndup (themed->names[0], strlen (themed->names[0]) - 9);
- else
- name = g_strdup (themed->names[0]);
p = name;
while (*p)
@@ -173,33 +175,39 @@ g_themed_icon_constructed (GObject *object)
last = name;
- g_strfreev (themed->names);
-
names = g_new (char *, dashes + 1 + 1);
names[i++] = last;
while ((dashp = strrchr (last, '-')) != NULL)
names[i++] = last = g_strndup (last, dashp - last);
+ }
+ else
+ {
+ names = g_new (char *, 2);
+ names[i++] = name;
+ }
+ names[i] = NULL;
+ n_names = i;
+ g_strfreev (themed->names);
- names[i++] = NULL;
-
+ /* All icons must be searched in symbolic and regular form. */
+ themed->names = g_new (char *, 2 * n_names + 1);
+ for (i = 0; names[i] != NULL; i++)
+ {
if (is_symbolic)
{
- themed->names = g_new (char *, 2 * dashes + 3);
- for (i = 0; names[i] != NULL; i++)
- {
- themed->names[i] = g_strconcat (names[i], "-symbolic", NULL);
- themed->names[dashes + 1 + i] = names[i];
- }
-
- themed->names[dashes + 1 + i] = NULL;
- g_free (names);
+ themed->names[i] = g_strconcat (names[i], "-symbolic", NULL);
+ themed->names[n_names + i] = names[i];
}
else
{
- themed->names = names;
+ themed->names[i] = names[i];
+ themed->names[n_names + i] = g_strconcat (names[i], "-symbolic", NULL);
}
}
+ themed->names[2 * n_names] = NULL;
+
+ g_free (names);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]