diff options
| author | gnidorah <gnidorah@users.noreply.github.com> | 2017-10-25 15:04:23 +0300 |
|---|---|---|
| committer | Calvin Lee <cyrus296@gmail.com> | 2017-12-29 12:11:51 -0700 |
| commit | bd121999cab98b8deefbbff4f39460c08071024e (patch) | |
| tree | ba31c5762c814771a3386cc469efeba2d4afed5a | |
| parent | ad99d9dff8f8e8ee78b5195d6ca440af130f6ab6 (diff) | |
Allow paths to icons in iconName property
| -rw-r--r-- | swaybar/tray/icon.c | 36 |
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) { } +static bool isfile(const char *path) { + struct stat statbuf; + if (stat(path, &statbuf) != -1) { + if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode)) { + return true; + } + } + return false; + +} + /** * Returns the directory of a given theme if it exists. * The returned pointer must be freed. @@ -290,6 +301,24 @@ fail: return dirs; } +/* Returns true if full path and file exists */ +static bool is_valid_path(const char *file) { + if (strstr(file, "/") == NULL || !isfile(file)) { + return false; + } +#ifdef WITH_GDK_PIXBUF + if (strstr(file, ".png") == NULL && + strstr(file, ".xpm") == NULL && + strstr(file, ".svg") == NULL) { +#else + if (strstr(file, ".png") == NULL) { +#endif + return false; + } + + return true; +} + /* Returns the file of an icon given its name and size */ static char *find_icon_file(const char *name, int size) { int namelen = strlen(name); @@ -372,7 +401,12 @@ static char *find_icon_file(const char *name, int size) { } cairo_surface_t *find_icon(const char *name, int size) { - char *image_path = find_icon_file(name, size); + char *image_path; + if (is_valid_path(name)) { + image_path = strdup(name); + } else { + image_path = find_icon_file(name, size); + } if (image_path == NULL) { return NULL; } |
