Improve Icon Theme Implimentation

This commit is contained in:
Calvin Lee 2017-10-26 12:56:37 -06:00
parent 5bc46f458c
commit 210e5bb893

View file

@ -122,15 +122,28 @@ static char *find_theme_dir(const char *theme) {
} }
if ((basedir = getenv("XDG_DATA_DIRS"))) { if ((basedir = getenv("XDG_DATA_DIRS"))) {
if (snprintf(icon_dir, 1024, "%s/icons/%s", basedir, theme) >= 1024) { if (!(basedir = strdup(basedir))) {
sway_log(L_ERROR, "Path too long to render"); sway_log_errno(L_ERROR, "Path too long to render");
// ditto
goto fail; goto fail;
} }
char *token = strtok(basedir, ":");
while (token) {
// By peeking at the spec, there should be a slash at
// the end of the data dir.
if (snprintf(icon_dir, 1024, "%sicons/%s", token, theme) >= 1024) {
sway_log(L_ERROR, "Path too long to render");
// ditto
free(basedir);
goto fail;
}
if (isdir(icon_dir)) { if (isdir(icon_dir)) {
return icon_dir; free(basedir);
return icon_dir;
}
token = strtok(NULL, ":");
} }
free(basedir);
} }
// Spec says use "/usr/share/pixmaps/", but I see everything in // Spec says use "/usr/share/pixmaps/", but I see everything in
@ -173,6 +186,15 @@ static list_t *find_all_theme_dirs(const char *theme) {
list_cat(dirs, inherits); list_cat(dirs, inherits);
list_free(inherits); list_free(inherits);
} }
// 'default' usually inherits the default theme. I don't believe it has
// any icons, but look for them anyway
dir = find_theme_dir("default");
if (dir) {
list_add(dirs, dir);
list_t *inherits = find_inherits(dir);
list_cat(dirs, inherits);
list_free(inherits);
}
dir = find_theme_dir("hicolor"); dir = find_theme_dir("hicolor");
if (dir) { if (dir) {
list_add(dirs, dir); list_add(dirs, dir);