summaryrefslogtreecommitdiffstats
path: root/swaybar/tray/icon.c
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-10-26 12:56:37 -0600
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-12-29 12:11:51 -0700
commit210e5bb893598f2bcf9011e29d22146850969b1e (patch)
tree1e086911f6b19a60bdcc6ced274816b122456ebf /swaybar/tray/icon.c
parentPrevent segfault in `get_items()` (diff)
downloadsway-210e5bb893598f2bcf9011e29d22146850969b1e.tar.gz
sway-210e5bb893598f2bcf9011e29d22146850969b1e.tar.zst
sway-210e5bb893598f2bcf9011e29d22146850969b1e.zip
Improve Icon Theme Implimentation
Diffstat (limited to 'swaybar/tray/icon.c')
-rw-r--r--swaybar/tray/icon.c32
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) {
122 } 122 }
123 123
124 if ((basedir = getenv("XDG_DATA_DIRS"))) { 124 if ((basedir = getenv("XDG_DATA_DIRS"))) {
125 if (snprintf(icon_dir, 1024, "%s/icons/%s", basedir, theme) >= 1024) { 125 if (!(basedir = strdup(basedir))) {
126 sway_log(L_ERROR, "Path too long to render"); 126 sway_log_errno(L_ERROR, "Path too long to render");
127 // ditto
128 goto fail; 127 goto fail;
129 } 128 }
129 char *token = strtok(basedir, ":");
130 while (token) {
131 // By peeking at the spec, there should be a slash at
132 // the end of the data dir.
133 if (snprintf(icon_dir, 1024, "%sicons/%s", token, theme) >= 1024) {
134 sway_log(L_ERROR, "Path too long to render");
135 // ditto
136 free(basedir);
137 goto fail;
138 }
130 139
131 if (isdir(icon_dir)) { 140 if (isdir(icon_dir)) {
132 return icon_dir; 141 free(basedir);
142 return icon_dir;
143 }
144 token = strtok(NULL, ":");
133 } 145 }
146 free(basedir);
134 } 147 }
135 148
136 // Spec says use "/usr/share/pixmaps/", but I see everything in 149 // 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) {
173 list_cat(dirs, inherits); 186 list_cat(dirs, inherits);
174 list_free(inherits); 187 list_free(inherits);
175 } 188 }
189 // 'default' usually inherits the default theme. I don't believe it has
190 // any icons, but look for them anyway
191 dir = find_theme_dir("default");
192 if (dir) {
193 list_add(dirs, dir);
194 list_t *inherits = find_inherits(dir);
195 list_cat(dirs, inherits);
196 list_free(inherits);
197 }
176 dir = find_theme_dir("hicolor"); 198 dir = find_theme_dir("hicolor");
177 if (dir) { 199 if (dir) {
178 list_add(dirs, dir); 200 list_add(dirs, dir);