diff options
| author | Calvin Lee <cyrus296@gmail.com> | 2017-10-26 12:56:37 -0600 |
|---|---|---|
| committer | Calvin Lee <cyrus296@gmail.com> | 2017-12-29 12:11:51 -0700 |
| commit | 210e5bb893598f2bcf9011e29d22146850969b1e (patch) | |
| tree | 1e086911f6b19a60bdcc6ced274816b122456ebf | |
| parent | 5bc46f458c1ac36aa17979af9583fc3060bac094 (diff) | |
Improve Icon Theme Implimentation
| -rw-r--r-- | swaybar/tray/icon.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c index 8a7c0415..fc9b176d 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/tray/icon.c @@ -122,15 +122,28 @@ static char *find_theme_dir(const char *theme) { } if ((basedir = getenv("XDG_DATA_DIRS"))) { - if (snprintf(icon_dir, 1024, "%s/icons/%s", basedir, theme) >= 1024) { - sway_log(L_ERROR, "Path too long to render"); - // ditto + if (!(basedir = strdup(basedir))) { + sway_log_errno(L_ERROR, "Path too long to render"); 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)) { - return icon_dir; + if (isdir(icon_dir)) { + free(basedir); + return icon_dir; + } + token = strtok(NULL, ":"); } + free(basedir); } // 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_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"); if (dir) { list_add(dirs, dir); |
