diff options
author | Ian Fan <ianfan0@gmail.com> | 2020-03-04 14:34:32 +0000 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-03-30 17:31:00 +0200 |
commit | 68f53cd509af8812562d743a55128a1b341247f5 (patch) | |
tree | 269042ba89e26b4124bb9f53cd9debf29e6f2599 /swaybar/tray | |
parent | 3b894c387dc38e8715186d5c0171b6048b36c435 (diff) |
tray: tidy code
This includes some refactoring and fixing a small memory leak.
Diffstat (limited to 'swaybar/tray')
-rw-r--r-- | swaybar/tray/host.c | 8 | ||||
-rw-r--r-- | swaybar/tray/icon.c | 18 | ||||
-rw-r--r-- | swaybar/tray/item.c | 4 |
3 files changed, 10 insertions, 20 deletions
diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c index 451b0896..ddf2416d 100644 --- a/swaybar/tray/host.c +++ b/swaybar/tray/host.c @@ -65,9 +65,9 @@ static int handle_sni_unregistered(sd_bus_message *msg, void *data, static int get_registered_snis_callback(sd_bus_message *msg, void *data, sd_bus_error *error) { if (sd_bus_message_is_method_error(msg, NULL)) { - sd_bus_error err = *sd_bus_message_get_error(msg); - sway_log(SWAY_ERROR, "Failed to get registered SNIs: %s", err.message); - return -sd_bus_error_get_errno(&err); + const sd_bus_error *err = sd_bus_message_get_error(msg); + sway_log(SWAY_ERROR, "Failed to get registered SNIs: %s", err->message); + return -sd_bus_error_get_errno(err); } int ret = sd_bus_message_enter_container(msg, 'v', NULL); @@ -87,9 +87,11 @@ static int get_registered_snis_callback(sd_bus_message *msg, void *data, struct swaybar_tray *tray = data; for (char **id = ids; *id; ++id) { add_sni(tray, *id); + free(*id); } } + free(ids); return ret; } diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c index 69df3582..c426c3d4 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/tray/icon.c @@ -412,7 +412,7 @@ static char *find_icon_in_subdir(char *name, char *basedir, char *theme, #endif "png", #if HAVE_GDK_PIXBUF - "xpm" + "xpm" // deprecated #endif }; @@ -508,21 +508,13 @@ static char *find_icon_with_theme(list_t *basedirs, list_t *themes, char *name, return icon; } -char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size) { - char *icon = find_icon_in_subdir(name, dir, "", ""); - if (icon) { - *min_size = 1; - *max_size = 512; - } - return icon; - -} - static char *find_fallback_icon(list_t *basedirs, char *name, int *min_size, int *max_size) { for (int i = 0; i < basedirs->length; ++i) { - char *icon = find_icon_in_dir(name, basedirs->items[i], min_size, max_size); + char *icon = find_icon_in_subdir(name, basedirs->items[i], "", ""); if (icon) { + *min_size = 1; + *max_size = 512; return icon; } } @@ -537,7 +529,7 @@ char *find_icon(list_t *themes, list_t *basedirs, char *name, int size, icon = find_icon_with_theme(basedirs, themes, name, size, theme, min_size, max_size); } - if (!icon) { + if (!icon && !(theme && strcmp(theme, "Hicolor") == 0)) { icon = find_icon_with_theme(basedirs, themes, name, size, "Hicolor", min_size, max_size); } diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index b4238417..63578cd9 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c @@ -416,10 +416,6 @@ static void reload_sni(struct swaybar_sni *sni, char *icon_theme, icon_name, target_size, icon_theme, &sni->min_size, &sni->max_size); list_free(icon_search_paths); - if (!icon_path && sni->icon_theme_path) { - icon_path = find_icon_in_dir(icon_name, sni->icon_theme_path, - &sni->min_size, &sni->max_size); - } if (icon_path) { cairo_surface_destroy(sni->icon); sni->icon = load_background_image(icon_path); |