diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 449987423..246dcf1b8 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -45,6 +45,9 @@ struct swaybar { struct wl_list unused_outputs; // swaybar_output::link struct wl_list seats; // swaybar_seat::link + list_t *basedirs; // char * + list_t *themes; // struct swaybar_theme * + struct swaybar_window *focused_window; // TOOD: Better name diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 4cacd21a4..920fd3e9c 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -67,8 +67,8 @@ struct swaybar_config { struct box_colors binding_mode; } colors; -#if HAVE_TRAY char *icon_theme; +#if HAVE_TRAY struct wl_list tray_bindings; // struct tray_binding::link bool tray_hidden; list_t *tray_outputs; // char * diff --git a/include/swaybar/tray/icon.h b/include/swaybar/icon.h similarity index 100% rename from include/swaybar/tray/icon.h rename to include/swaybar/icon.h diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h index d2e80a6d4..4a4240e2c 100644 --- a/include/swaybar/tray/tray.h +++ b/include/swaybar/tray/tray.h @@ -29,9 +29,6 @@ struct swaybar_tray { list_t *items; // struct swaybar_sni * struct swaybar_watcher *watcher_xdg; struct swaybar_watcher *watcher_kde; - - list_t *basedirs; // char * - list_t *themes; // struct swaybar_theme * }; struct swaybar_tray *create_tray(struct swaybar *bar); diff --git a/swaybar/bar.c b/swaybar/bar.c index c94949080..6a7e2b8be 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -19,6 +19,7 @@ #include "swaybar/ipc.h" #include "swaybar/status_line.h" #include "swaybar/render.h" +#include "swaybar/icon.h" #if HAVE_TRAY #include "swaybar/tray/tray.h" #endif @@ -462,6 +463,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { bar->tray = create_tray(bar); } #endif + init_themes(&bar->themes, &bar->basedirs); if (bar->config->workspace_buttons) { ipc_get_workspaces(bar); @@ -536,6 +538,7 @@ void bar_teardown(struct swaybar *bar) { #if HAVE_TRAY destroy_tray(bar->tray); #endif + finish_themes(bar->themes, bar->basedirs); free_outputs(&bar->outputs); free_outputs(&bar->unused_outputs); free_seats(&bar->seats); diff --git a/swaybar/config.c b/swaybar/config.c index abedaec0e..29bfcee6c 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -129,8 +129,7 @@ void free_config(struct swaybar_config *config) { wl_list_remove(&tray_bind->link); free_tray_binding(tray_bind); } - - free(config->icon_theme); #endif + free(config->icon_theme); free(config); } diff --git a/swaybar/desktop.c b/swaybar/desktop.c index e0631ab2d..8cd3301a2 100644 --- a/swaybar/desktop.c +++ b/swaybar/desktop.c @@ -7,7 +7,7 @@ #include #include -#include "swaybar/tray/icon.h" +#include "swaybar/icon.h" #include "desktop.h" #include "log.h" diff --git a/swaybar/tray/icon.c b/swaybar/icon.c similarity index 99% rename from swaybar/tray/icon.c rename to swaybar/icon.c index a1c2969f3..fee46dc8f 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/icon.c @@ -9,7 +9,7 @@ #include #include #include -#include "swaybar/tray/icon.h" +#include "swaybar/icon.h" #include "config.h" #include "list.h" #include "log.h" diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 275cc2c45..6232dcbfd 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -14,7 +14,7 @@ #endif #include "desktop.h" #include "config.h" -#include "swaybar/tray/icon.h" +#include "swaybar/icon.h" #include "ipc-client.h" #include "background-image.h" #include "list.h" diff --git a/swaybar/meson.build b/swaybar/meson.build index ad6b6ffb9..26a9ef41b 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build @@ -1,6 +1,5 @@ tray_files = have_tray ? [ 'tray/host.c', - 'tray/icon.c', 'tray/item.c', 'tray/tray.c', 'tray/watcher.c' @@ -29,6 +28,7 @@ executable( 'i3bar.c', 'input.c', 'ipc.c', + 'icon.c', 'main.c', 'render.c', 'status_line.c', diff --git a/swaybar/render.c b/swaybar/render.c index f1293fd58..bcf47f235 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -14,7 +14,7 @@ #include "swaybar/ipc.h" #include "swaybar/render.h" #include "swaybar/status_line.h" -#include "swaybar/tray/icon.h" +#include "swaybar/icon.h" #include "log.h" #include "background-image.h" #if HAVE_TRAY @@ -759,9 +759,9 @@ uint32_t render_focused_window_icon(cairo_t *cairo, // TODO: Load correct theme list_add(themes, "Adwaita"); - assert(output->bar->tray); - assert(output->bar->tray->themes); - char *icon_path = find_icon(output->bar->tray->themes, + assert(output->bar); + assert(output->bar->themes); + char *icon_path = find_icon(output->bar->themes, basedirs, icon_name, target_size, diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index c9da51d41..cac350bdd 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c @@ -9,7 +9,7 @@ #include "swaybar/config.h" #include "swaybar/input.h" #include "swaybar/tray/host.h" -#include "swaybar/tray/icon.h" +#include "swaybar/icon.h" #include "swaybar/tray/item.h" #include "swaybar/tray/tray.h" #include "background-image.h" @@ -410,19 +410,26 @@ static enum hotspot_event_handling icon_hotspot_callback( return HOTSPOT_PROCESS; } -static void reload_sni(struct swaybar_sni *sni, char *icon_theme, +static void reload_sni(struct swaybar_sni *sni, + char *icon_theme, + list_t *basedirs, // char * + list_t *themes, // struct swaybar_theme * int target_size) { char *icon_name = sni->status[0] == 'N' ? sni->attention_icon_name : sni->icon_name; if (icon_name) { list_t *icon_search_paths = create_list(); - list_cat(icon_search_paths, sni->tray->basedirs); + list_cat(icon_search_paths, basedirs); if (sni->icon_theme_path) { list_add(icon_search_paths, sni->icon_theme_path); } - char *icon_path = find_icon(sni->tray->themes, icon_search_paths, - icon_name, target_size, icon_theme, - &sni->min_size, &sni->max_size); + char *icon_path = find_icon(themes, + icon_search_paths, + icon_name, + target_size, + icon_theme, + &sni->min_size, + &sni->max_size); list_free(icon_search_paths); if (icon_path) { cairo_surface_destroy(sni->icon); @@ -460,7 +467,11 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x, if (target_size != sni->target_size && sni_ready(sni)) { // check if another icon should be loaded if (target_size < sni->min_size || target_size > sni->max_size) { - reload_sni(sni, output->bar->config->icon_theme, target_size); + reload_sni(sni, + output->bar->config->icon_theme, + output->bar->basedirs, + output->bar->themes, + target_size); } sni->target_size = target_size; diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index 5fe6f9c31..f0e004c47 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -4,7 +4,7 @@ #include #include "swaybar/config.h" #include "swaybar/bar.h" -#include "swaybar/tray/icon.h" +#include "swaybar/icon.h" #include "swaybar/tray/host.h" #include "swaybar/tray/item.h" #include "swaybar/tray/tray.h" @@ -67,8 +67,6 @@ struct swaybar_tray *create_tray(struct swaybar *bar) { init_host(&tray->host_xdg, "freedesktop", tray); init_host(&tray->host_kde, "kde", tray); - init_themes(&tray->themes, &tray->basedirs); - return tray; } @@ -85,7 +83,6 @@ void destroy_tray(struct swaybar_tray *tray) { destroy_watcher(tray->watcher_xdg); destroy_watcher(tray->watcher_kde); sd_bus_flush_close_unref(tray->bus); - finish_themes(tray->themes, tray->basedirs); free(tray); }