From bd121999cab98b8deefbbff4f39460c08071024e Mon Sep 17 00:00:00 2001 From: gnidorah Date: Wed, 25 Oct 2017 15:04:23 +0300 Subject: Allow paths to icons in iconName property --- swaybar/tray/icon.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3