Skip to content

Commit

Permalink
xdg-theme: Add PNG symbolic icons support
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
  • Loading branch information
sardemff7 committed Jun 7, 2017
1 parent 53314c0 commit 376e7a3
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 25 deletions.
19 changes: 14 additions & 5 deletions src/xdg-theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ typedef struct {
const gchar *context_custom;
gint size;
gint scale;
gboolean svg;
const gchar **extensions;
} NkXdgThemeIconFindData;

typedef struct {
Expand Down Expand Up @@ -159,6 +159,14 @@ static const gchar *_nk_xdg_theme_icon_extensions[] = {
NULL
};

static const gchar *_nk_xdg_theme_icon_symbolic_extensions[] = {
".svg",
".png",
".symbolic.png",
".xpm",
NULL
};

static const gchar *_nk_xdg_theme_sound_extensions[] = {
".disabled",
".oga",
Expand Down Expand Up @@ -654,7 +662,7 @@ _nk_xdg_theme_icon_find_file(NkXdgThemeTheme *self, const gchar *name, gpointer
for ( path = subdir->base.paths ; *path != NULL ; ++path )
{
gchar *file;
if ( _nk_xdg_theme_try_file(*path, name, data->svg ? _nk_xdg_theme_icon_extensions : _nk_xdg_theme_icon_extensions + 1, &file) )
if ( _nk_xdg_theme_try_file(*path, name, data->extensions, &file) )
{
if ( try_best )
{
Expand Down Expand Up @@ -692,13 +700,14 @@ nk_xdg_theme_get_icon(NkXdgThemeContext *self, const gchar *theme_name, const gc
g_return_val_if_fail(name != NULL, NULL);
g_return_val_if_fail(scale > 0, NULL);

gboolean symbolic = g_str_has_suffix(name, "-symbolic");
guint64 value;
NkXdgThemeIconFindData data = {
.context = ICONDIR_CONTEXT_CUSTOM,
.context_custom = context_name,
.size = size * scale,
.scale = scale,
.svg = svg,
.extensions = ( symbolic ? _nk_xdg_theme_icon_symbolic_extensions : _nk_xdg_theme_icon_extensions ) + ( svg ? 0 : 1 ),
};
if ( nk_enum_parse(context_name, _nk_xdg_theme_icon_dir_context_names, G_N_ELEMENTS(_nk_xdg_theme_icon_dir_context_names), TRUE, &value) )
data.context = value;
Expand All @@ -714,10 +723,10 @@ nk_xdg_theme_get_icon(NkXdgThemeContext *self, const gchar *theme_name, const gc
if ( ( theme != NULL ) && _nk_xdg_theme_get_file(theme, name, _nk_xdg_theme_icon_find_file, &data, &file) )
return file;

if ( _nk_xdg_theme_try_fallback(self->dirs[TYPE_ICON], G_DIR_SEPARATOR_S "usr" G_DIR_SEPARATOR_S "share" G_DIR_SEPARATOR_S "pixmaps", theme_name, name, svg ? _nk_xdg_theme_icon_extensions : _nk_xdg_theme_icon_extensions + 1, &file) )
if ( _nk_xdg_theme_try_fallback(self->dirs[TYPE_ICON], G_DIR_SEPARATOR_S "usr" G_DIR_SEPARATOR_S "share" G_DIR_SEPARATOR_S "pixmaps", theme_name, name, data.extensions, &file) )
return file;

if ( g_str_has_suffix(name, "-symbolic") )
if ( symbolic )
{
gchar *no_symbolic_name;
gsize l;
Expand Down
173 changes: 153 additions & 20 deletions tests/xdg-theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,101 @@ static const struct {
NkXdgThemeTestData data;
} _nk_uuid_tests_list[] = {
{
.testpath = "/nkutils/xdg-theme/icon/symbolic/found",
.testpath = "/nkutils/xdg-theme/icon/Adwaita/symbolic/found",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "zoom-in-symbolic",
.size = 48,
.scale = 1,
.svg = TRUE,
.result = "/usr/share/icons/Adwaita/scalable/actions/zoom-in-symbolic.svg",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/symbolic/not-scalable",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "zoom-in-symbolic",
.size = 48,
.scale = 1,
.svg = FALSE,
.result = "/usr/share/icons/Adwaita/48x48/actions/zoom-in-symbolic.symbolic.png",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/symbolic/found-no-symbolic",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "trophy-gold-symbolic",
.size = 48,
.scale = 1,
.svg = TRUE,
.result = "/usr/share/icons/Adwaita/48x48/status/trophy-gold.png",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/theme-found/fallback",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "geany",
.size = 16,
.scale = 1,
.svg = FALSE,
.result = "/usr/share/icons/hicolor/16x16/apps/geany.png",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/context/exist-match/1",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "network-wireless-signal-ok-symbolic",
.context = "Status",
.size = 48,
.scale = 1,
.svg = TRUE,
.result = "/usr/share/icons/Adwaita/scalable/status/network-wireless-signal-ok-symbolic.svg",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/context/exist-no-match",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "network-wireless-signal-ok-symbolic",
.context = "Applications",
.size = 48,
.scale = 1,
.svg = TRUE,
.result = NULL,
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/context/exist-match/2",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "emblem-favorite-symbolic",
.context = "Emblems",
.size = 48,
.scale = 1,
.svg = TRUE,
.result = "/usr/share/icons/Adwaita/scalable/emblems/emblem-favorite-symbolic.svg",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/gnome/symbolic/found",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -72,7 +166,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/symbolic/not-scalable",
.testpath = "/nkutils/xdg-theme/icon/gnome/symbolic/not-scalable",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -85,7 +179,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/symbolic/found-no-symbolic",
.testpath = "/nkutils/xdg-theme/icon/gnome/symbolic/found-no-symbolic",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -98,7 +192,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/theme-found/fallback",
.testpath = "/nkutils/xdg-theme/icon/gnome/theme-found/fallback",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -111,7 +205,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/context/exist-match/1",
.testpath = "/nkutils/xdg-theme/icon/gnome/context/exist-match/1",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -125,7 +219,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/context/exist-no-match",
.testpath = "/nkutils/xdg-theme/icon/gnome/context/exist-no-match",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -139,7 +233,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/context/exist-match/2",
.testpath = "/nkutils/xdg-theme/icon/gnome/context/exist-match/2",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -153,7 +247,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/threshold/found/1",
.testpath = "/nkutils/xdg-theme/icon/no-theme/threshold/found/1",
.data = {
.type = TYPE_ICON,
.theme = NULL,
Expand All @@ -166,7 +260,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/threshold/found/2",
.testpath = "/nkutils/xdg-theme/icon/no-theme/threshold/found/2",
.data = {
.type = TYPE_ICON,
.theme = NULL,
Expand All @@ -179,20 +273,20 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/size/fallback/hicolor/1",
.testpath = "/nkutils/xdg-theme/icon/no-theme/size/fallback/hicolor/1",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
.theme = "Adwaita",
.name = "pidgin",
.size = 0,
.scale = 1,
.svg = TRUE,
.result = "/usr/share/icons/hicolor/scalable/apps/pidgin.svg",
.theme_test = "/usr/share/icons/gnome/index.theme",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/size/fallback/pixmaps/1",
.testpath = "/nkutils/xdg-theme/icon/no-theme/size/fallback/pixmaps/1",
.data = {
.type = TYPE_ICON,
.theme = NULL,
Expand All @@ -204,7 +298,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/size/fallback/pixmaps/2",
.testpath = "/nkutils/xdg-theme/icon/no-theme/size/fallback/pixmaps/2",
.data = {
.type = TYPE_ICON,
.theme = NULL,
Expand All @@ -216,20 +310,59 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/size/biggest/fixed",
.testpath = "/nkutils/xdg-theme/icon/Adwaita/size/biggest/fixed",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "edit-find-symbolic",
.size = 0,
.scale = 1,
.svg = FALSE,
.result = "/usr/share/icons/Adwaita/96x96/actions/edit-find-symbolic.symbolic.png",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/size/biggest/svg",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "edit-find-symbolic",
.size = 0,
.scale = 1,
.svg = TRUE,
.result = "/usr/share/icons/Adwaita/scalable/actions/edit-find-symbolic.svg",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/Adwaita/size/best-distance",
.data = {
.type = TYPE_ICON,
.theme = "Adwaita",
.name = "edit-find",
.size = 19,
.scale = 1,
.svg = FALSE,
.result = "/usr/share/icons/Adwaita/22x22/actions/edit-find.png",
.theme_test = "/usr/share/icons/Adwaita/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/gnome/size/biggest/fixed",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
.name = "edit-find-symbolic",
.size = 0,
.scale = 1,
.svg = FALSE,
.result = "/usr/share/icons/gnome/256x256/actions/edit-find.png",
.result = "/usr/share/icons/gnome/96x96/actions/edit-find-symbolic.symbolic.png",
.theme_test = "/usr/share/icons/gnome/index.theme",
}
},
{
.testpath = "/nkutils/xdg-theme/icon/size/biggest/svg",
.testpath = "/nkutils/xdg-theme/icon/gnome/size/biggest/svg",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -242,7 +375,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/size/best-distance",
.testpath = "/nkutils/xdg-theme/icon/gnome/size/best-distance",
.data = {
.type = TYPE_ICON,
.theme = "gnome",
Expand All @@ -255,7 +388,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/not-found",
.testpath = "/nkutils/xdg-theme/icon/wrong-theme/not-found",
.data = {
.type = TYPE_ICON,
.theme = "do-not-exists-hopefully",
Expand All @@ -267,7 +400,7 @@ static const struct {
}
},
{
.testpath = "/nkutils/xdg-theme/icon/no-theme",
.testpath = "/nkutils/xdg-theme/icon/no-theme/not-found",
.data = {
.type = TYPE_ICON,
.theme = NULL,
Expand Down

0 comments on commit 376e7a3

Please sign in to comment.