summaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar gnidorah <gnidorah@users.noreply.github.com>2017-10-25 15:04:23 +0300
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-12-29 12:11:51 -0700
commitbd121999cab98b8deefbbff4f39460c08071024e (patch)
treeba31c5762c814771a3386cc469efeba2d4afed5a /swaybar
parentAllow registering StatusNotifierItems by obj path (diff)
downloadsway-bd121999cab98b8deefbbff4f39460c08071024e.tar.gz
sway-bd121999cab98b8deefbbff4f39460c08071024e.tar.zst
sway-bd121999cab98b8deefbbff4f39460c08071024e.zip
Allow paths to icons in iconName property
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/tray/icon.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c
index c146bf32..8a7c0415 100644
--- a/swaybar/tray/icon.c
+++ b/swaybar/tray/icon.c
@@ -80,6 +80,17 @@ static bool isdir(const char *path) {
80 80
81} 81}
82 82
83static bool isfile(const char *path) {
84 struct stat statbuf;
85 if (stat(path, &statbuf) != -1) {
86 if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode)) {
87 return true;
88 }
89 }
90 return false;
91
92}
93
83/** 94/**
84 * Returns the directory of a given theme if it exists. 95 * Returns the directory of a given theme if it exists.
85 * The returned pointer must be freed. 96 * The returned pointer must be freed.
@@ -290,6 +301,24 @@ fail:
290 return dirs; 301 return dirs;
291} 302}
292 303
304/* Returns true if full path and file exists */
305static bool is_valid_path(const char *file) {
306 if (strstr(file, "/") == NULL || !isfile(file)) {
307 return false;
308 }
309#ifdef WITH_GDK_PIXBUF
310 if (strstr(file, ".png") == NULL &&
311 strstr(file, ".xpm") == NULL &&
312 strstr(file, ".svg") == NULL) {
313#else
314 if (strstr(file, ".png") == NULL) {
315#endif
316 return false;
317 }
318
319 return true;
320}
321
293/* Returns the file of an icon given its name and size */ 322/* Returns the file of an icon given its name and size */
294static char *find_icon_file(const char *name, int size) { 323static char *find_icon_file(const char *name, int size) {
295 int namelen = strlen(name); 324 int namelen = strlen(name);
@@ -372,7 +401,12 @@ static char *find_icon_file(const char *name, int size) {
372} 401}
373 402
374cairo_surface_t *find_icon(const char *name, int size) { 403cairo_surface_t *find_icon(const char *name, int size) {
375 char *image_path = find_icon_file(name, size); 404 char *image_path;
405 if (is_valid_path(name)) {
406 image_path = strdup(name);
407 } else {
408 image_path = find_icon_file(name, size);
409 }
376 if (image_path == NULL) { 410 if (image_path == NULL) {
377 return NULL; 411 return NULL;
378 } 412 }