Commit e0f2671a authored by Jehan's avatar Jehan

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).
parent caf68ed8
...@@ -143,25 +143,27 @@ g_themed_icon_set_property (GObject *object, ...@@ -143,25 +143,27 @@ g_themed_icon_set_property (GObject *object,
static void static void
g_themed_icon_constructed (GObject *object) 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); 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) if (themed->use_default_fallbacks)
{ {
int i = 0, dashes = 0; int dashes = 0;
const char *p; const char *p;
char *dashp; char *dashp;
char *last; 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; p = name;
while (*p) while (*p)
...@@ -173,33 +175,39 @@ g_themed_icon_constructed (GObject *object) ...@@ -173,33 +175,39 @@ g_themed_icon_constructed (GObject *object)
last = name; last = name;
g_strfreev (themed->names);
names = g_new (char *, dashes + 1 + 1); names = g_new (char *, dashes + 1 + 1);
names[i++] = last; names[i++] = last;
while ((dashp = strrchr (last, '-')) != NULL) while ((dashp = strrchr (last, '-')) != NULL)
names[i++] = last = g_strndup (last, dashp - last); 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) if (is_symbolic)
{ {
themed->names = g_new (char *, 2 * dashes + 3); themed->names[i] = g_strconcat (names[i], "-symbolic", NULL);
for (i = 0; names[i] != NULL; i++) themed->names[n_names + i] = names[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);
} }
else 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 static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment