diff options
author | 2020-03-04 14:34:32 +0000 | |
---|---|---|
committer | 2020-03-30 17:31:00 +0200 | |
commit | 68f53cd509af8812562d743a55128a1b341247f5 (patch) | |
tree | 269042ba89e26b4124bb9f53cd9debf29e6f2599 | |
parent | tray: allow themes to inherit from multiple themes (diff) | |
download | sway-68f53cd509af8812562d743a55128a1b341247f5.tar.gz sway-68f53cd509af8812562d743a55128a1b341247f5.tar.zst sway-68f53cd509af8812562d743a55128a1b341247f5.zip |
tray: tidy code
This includes some refactoring and fixing a small memory leak.
-rw-r--r-- | include/swaybar/tray/icon.h | 15 | ||||
-rw-r--r-- | swaybar/tray/host.c | 8 | ||||
-rw-r--r-- | swaybar/tray/icon.c | 18 | ||||
-rw-r--r-- | swaybar/tray/item.c | 4 |
4 files changed, 17 insertions, 28 deletions
diff --git a/include/swaybar/tray/icon.h b/include/swaybar/tray/icon.h index 8e1d471e..3673674b 100644 --- a/include/swaybar/tray/icon.h +++ b/include/swaybar/tray/icon.h | |||
@@ -3,16 +3,16 @@ | |||
3 | 3 | ||
4 | #include "list.h" | 4 | #include "list.h" |
5 | 5 | ||
6 | enum subdir_type { | ||
7 | THRESHOLD, | ||
8 | SCALABLE, | ||
9 | FIXED | ||
10 | }; | ||
11 | |||
12 | struct icon_theme_subdir { | 6 | struct icon_theme_subdir { |
13 | char *name; | 7 | char *name; |
14 | int size; | 8 | int size; |
15 | enum subdir_type type; | 9 | |
10 | enum { | ||
11 | THRESHOLD, | ||
12 | SCALABLE, | ||
13 | FIXED | ||
14 | } type; | ||
15 | |||
16 | int max_size; | 16 | int max_size; |
17 | int min_size; | 17 | int min_size; |
18 | int threshold; | 18 | int threshold; |
@@ -39,6 +39,5 @@ void finish_themes(list_t *themes, list_t *basedirs); | |||
39 | */ | 39 | */ |
40 | char *find_icon(list_t *themes, list_t *basedirs, char *name, int size, | 40 | char *find_icon(list_t *themes, list_t *basedirs, char *name, int size, |
41 | char *theme, int *min_size, int *max_size); | 41 | char *theme, int *min_size, int *max_size); |
42 | char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size); | ||
43 | 42 | ||
44 | #endif | 43 | #endif |
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, | |||
65 | static int get_registered_snis_callback(sd_bus_message *msg, void *data, | 65 | static int get_registered_snis_callback(sd_bus_message *msg, void *data, |
66 | sd_bus_error *error) { | 66 | sd_bus_error *error) { |
67 | if (sd_bus_message_is_method_error(msg, NULL)) { | 67 | if (sd_bus_message_is_method_error(msg, NULL)) { |
68 | sd_bus_error err = *sd_bus_message_get_error(msg); | 68 | const sd_bus_error *err = sd_bus_message_get_error(msg); |
69 | sway_log(SWAY_ERROR, "Failed to get registered SNIs: %s", err.message); | 69 | sway_log(SWAY_ERROR, "Failed to get registered SNIs: %s", err->message); |
70 | return -sd_bus_error_get_errno(&err); | 70 | return -sd_bus_error_get_errno(err); |
71 | } | 71 | } |
72 | 72 | ||
73 | int ret = sd_bus_message_enter_container(msg, 'v', NULL); | 73 | 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, | |||
87 | struct swaybar_tray *tray = data; | 87 | struct swaybar_tray *tray = data; |
88 | for (char **id = ids; *id; ++id) { | 88 | for (char **id = ids; *id; ++id) { |
89 | add_sni(tray, *id); | 89 | add_sni(tray, *id); |
90 | free(*id); | ||
90 | } | 91 | } |
91 | } | 92 | } |
92 | 93 | ||
94 | free(ids); | ||
93 | return ret; | 95 | return ret; |
94 | } | 96 | } |
95 | 97 | ||
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, | |||
412 | #endif | 412 | #endif |
413 | "png", | 413 | "png", |
414 | #if HAVE_GDK_PIXBUF | 414 | #if HAVE_GDK_PIXBUF |
415 | "xpm" | 415 | "xpm" // deprecated |
416 | #endif | 416 | #endif |
417 | }; | 417 | }; |
418 | 418 | ||
@@ -508,21 +508,13 @@ static char *find_icon_with_theme(list_t *basedirs, list_t *themes, char *name, | |||
508 | return icon; | 508 | return icon; |
509 | } | 509 | } |
510 | 510 | ||
511 | char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size) { | ||
512 | char *icon = find_icon_in_subdir(name, dir, "", ""); | ||
513 | if (icon) { | ||
514 | *min_size = 1; | ||
515 | *max_size = 512; | ||
516 | } | ||
517 | return icon; | ||
518 | |||
519 | } | ||
520 | |||
521 | static char *find_fallback_icon(list_t *basedirs, char *name, int *min_size, | 511 | static char *find_fallback_icon(list_t *basedirs, char *name, int *min_size, |
522 | int *max_size) { | 512 | int *max_size) { |
523 | for (int i = 0; i < basedirs->length; ++i) { | 513 | for (int i = 0; i < basedirs->length; ++i) { |
524 | char *icon = find_icon_in_dir(name, basedirs->items[i], min_size, max_size); | 514 | char *icon = find_icon_in_subdir(name, basedirs->items[i], "", ""); |
525 | if (icon) { | 515 | if (icon) { |
516 | *min_size = 1; | ||
517 | *max_size = 512; | ||
526 | return icon; | 518 | return icon; |
527 | } | 519 | } |
528 | } | 520 | } |
@@ -537,7 +529,7 @@ char *find_icon(list_t *themes, list_t *basedirs, char *name, int size, | |||
537 | icon = find_icon_with_theme(basedirs, themes, name, size, theme, | 529 | icon = find_icon_with_theme(basedirs, themes, name, size, theme, |
538 | min_size, max_size); | 530 | min_size, max_size); |
539 | } | 531 | } |
540 | if (!icon) { | 532 | if (!icon && !(theme && strcmp(theme, "Hicolor") == 0)) { |
541 | icon = find_icon_with_theme(basedirs, themes, name, size, "Hicolor", | 533 | icon = find_icon_with_theme(basedirs, themes, name, size, "Hicolor", |
542 | min_size, max_size); | 534 | min_size, max_size); |
543 | } | 535 | } |
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, | |||
416 | icon_name, target_size, icon_theme, | 416 | icon_name, target_size, icon_theme, |
417 | &sni->min_size, &sni->max_size); | 417 | &sni->min_size, &sni->max_size); |
418 | list_free(icon_search_paths); | 418 | list_free(icon_search_paths); |
419 | if (!icon_path && sni->icon_theme_path) { | ||
420 | icon_path = find_icon_in_dir(icon_name, sni->icon_theme_path, | ||
421 | &sni->min_size, &sni->max_size); | ||
422 | } | ||
423 | if (icon_path) { | 419 | if (icon_path) { |
424 | cairo_surface_destroy(sni->icon); | 420 | cairo_surface_destroy(sni->icon); |
425 | sni->icon = load_background_image(icon_path); | 421 | sni->icon = load_background_image(icon_path); |