Remove conditionals and old code for locating and loading icons

With libsfdo a hard dependency we can locate and load icons always,
regardless of whether we have tray or not. Old locating and loading code
can also be removed.
This commit is contained in:
myrslint 2025-07-02 21:59:38 +00:00
parent 0872673472
commit 6d7c0d52d6
10 changed files with 7 additions and 134 deletions

View file

@ -399,9 +399,7 @@ struct bar_config {
char *binding_mode_text;
} colors;
#if HAVE_TRAY || HAVE_LIBSFDO
char *icon_theme;
#endif
#if HAVE_TRAY
struct wl_list tray_bindings; // struct tray_binding::link

View file

@ -9,9 +9,7 @@
#include "sway/xwayland.h"
#endif
#if HAVE_LIBSFDO
#include "sfdo.h"
#endif
struct sway_transaction;
@ -151,10 +149,7 @@ struct sway_server {
struct wl_event_source *delayed_modeset;
#if HAVE_LIBSFDO
struct sfdo *sfdo;
#endif
};
extern struct sway_server server;

View file

@ -16,9 +16,7 @@ struct swaybar_tray;
struct swaybar_workspace;
struct loop;
#if HAVE_LIBSFDO
struct sfdo;
#endif
struct swaybar {
char *id;
@ -54,9 +52,7 @@ struct swaybar {
struct swaybar_tray *tray;
#endif
#if HAVE_LIBSFDO
struct sfdo *sfdo;
#endif
bool running;
};

View file

@ -8,9 +8,7 @@
#include "util.h"
#include <pango/pangocairo.h>
#if HAVE_LIBSFDO
#include "sfdo.h"
#endif
struct box_colors {
uint32_t border;
@ -77,9 +75,7 @@ struct swaybar_config {
struct box_colors binding_mode;
} colors;
#if HAVE_TRAY || HAVE_LIBSFDO
char *icon_theme;
#endif
#if HAVE_TRAY
struct wl_list tray_bindings; // struct tray_binding::link
@ -88,9 +84,7 @@ struct swaybar_config {
int tray_padding;
#endif
#if HAVE_LIBSFDO
struct sfdo *sfdo;
#endif
};
#if HAVE_TRAY

View file

@ -71,16 +71,13 @@ void free_bar_config(struct bar_config *bar) {
free(bar->colors.binding_mode_bg);
free(bar->colors.binding_mode_text);
// this is to cover the case where tray support is not compiled in
// but we have libsfdo support which implies at least a default
// icon_theme string was allocated
#if HAVE_LIBSFDO && !HAVE_TRAY
free(bar->icone_theme);
#endif
// since libsfdo is a hard depedency now we always have at least
// a default icon theme and need to free the string that contains
// its name
free(bar->icon_theme);
#if HAVE_TRAY
list_free_items_and_destroy(bar->tray_outputs);
free(bar->icon_theme);
struct tray_binding *tray_bind = NULL, *tmp_tray_bind = NULL;
wl_list_for_each_safe(tray_bind, tmp_tray_bind, &bar->tray_bindings, link) {
@ -179,11 +176,9 @@ struct bar_config *default_bar_config(void) {
bar->colors.binding_mode_text = NULL;
// we need some default when we initialize sfdo
#if HAVE_LIBSFDO
if (!(bar->icon_theme = strdup("Hicolor"))) {
goto cleanup;
}
#endif
#if HAVE_TRAY
bar->tray_padding = 2;

View file

@ -69,9 +69,7 @@
#include <wlr/types/wlr_drm_lease_v1.h>
#endif
#if HAVE_LIBSFDO
#include "sfdo.h"
#endif
#define SWAY_XDG_SHELL_VERSION 5
#define SWAY_LAYER_SHELL_VERSION 4
@ -545,9 +543,7 @@ void server_fini(struct sway_server *server) {
wlr_backend_destroy(server->backend);
wl_display_destroy(server->wl_display);
list_free(server->dirty_nodes);
#if HAVE_LIBSFDO
sfdo_destroy(server->sfdo);
#endif
free(server->socket);
}
@ -589,11 +585,9 @@ bool server_start(struct sway_server *server) {
return false;
}
#if HAVE_LIBSFDO
// TODO: allow configurability of global sway icon theme if and when
// it is applicable (titlebar icons? ssd icons?)
server->sfdo = sfdo_create("Hicolor");
#endif
return true;
}
@ -603,73 +597,3 @@ void server_run(struct sway_server *server) {
server->socket);
wl_display_run(server->wl_display);
}
#if HAVE_LIBSFDO
struct sfdo *sfdo_create(char *theme) {
struct sfdo *sfdo = calloc(1, sizeof(struct sfdo));
if (!sfdo) {
goto error_calloc;
}
struct sfdo_basedir_ctx *basedir_ctx = sfdo_basedir_ctx_create();
if (!basedir_ctx) {
goto error_basedir_ctx;
}
sfdo->desktop_ctx = sfdo_desktop_ctx_create(basedir_ctx);
if (!sfdo->desktop_ctx) {
goto error_desktop_ctx;
}
sfdo->icon_ctx = sfdo_icon_ctx_create(basedir_ctx);
if (!sfdo->icon_ctx) {
goto error_icon_ctx;
}
sfdo->desktop_db = sfdo_desktop_db_load(sfdo->desktop_ctx, NULL);
if (!sfdo->desktop_db) {
goto error_desktop_db;
}
int load_options = SFDO_ICON_THEME_LOAD_OPTIONS_DEFAULT |
SFDO_ICON_THEME_LOAD_OPTION_ALLOW_MISSING |
SFDO_ICON_THEME_LOAD_OPTION_RELAXED;
sfdo->icon_theme = sfdo_icon_theme_load(sfdo->icon_ctx, theme, load_options);
if (!sfdo->icon_theme) {
goto error_icon_theme;
}
sfdo_basedir_ctx_destroy(basedir_ctx);
sway_log(SWAY_DEBUG, "Successfully setup sfdo");
return sfdo;
error_icon_theme:
sfdo_desktop_db_destroy(sfdo->desktop_db);
error_desktop_db:
sfdo_icon_ctx_destroy(sfdo->icon_ctx);
error_icon_ctx:
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
error_desktop_ctx:
sfdo_basedir_ctx_destroy(basedir_ctx);
error_basedir_ctx:
free(sfdo);
error_calloc:
sway_log(SWAY_ERROR, "Failed to setup sfdo");
return NULL;
}
void sfdo_destroy(struct sfdo *sfdo) {
if (!sfdo) {
sway_log(SWAY_DEBUG, "Null sfdo passed in");
return;
}
sfdo_icon_theme_destroy(sfdo->icon_theme);
sfdo_desktop_db_destroy(sfdo->desktop_db);
sfdo_icon_ctx_destroy(sfdo->icon_ctx);
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
sway_log(SWAY_DEBUG, "Successfully destroyed sfdo");
}
#endif

View file

@ -538,9 +538,7 @@ void bar_teardown(struct swaybar *bar) {
#if HAVE_TRAY
destroy_tray(bar->tray);
#endif
#if HAVE_LIBSFDO
sfdo_destroy(bar->config->sfdo);
#endif
free_outputs(&bar->outputs);
free_outputs(&bar->unused_outputs);
free_seats(&bar->seats);

View file

@ -7,9 +7,7 @@
#include "list.h"
#include "log.h"
#if HAVE_LIBSFDO
#include "sfdo.h"
#endif
uint32_t parse_position(const char *position) {
uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
@ -132,18 +130,11 @@ void free_config(struct swaybar_config *config) {
wl_list_remove(&tray_bind->link);
free_tray_binding(tray_bind);
}
free(config->icon_theme);
#endif
#if HAVE_LIBSFDO && !HAVE_TRAY
free(config->icon_theme);
#endif
#if HAVE_LIBSFDO
sfdo_destroy(config->sfdo);
sway_log(SWAY_DEBUG, "Destroyed swaybar sfdo");
#endif
free(config);
}

View file

@ -18,9 +18,7 @@
#include "stringop.h"
#include "util.h"
#if HAVE_LIBSFDO
#include "sfdo.h"
#endif
void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
uint32_t size = strlen("workspace \"\"") + strlen(ws);
@ -332,14 +330,14 @@ static bool ipc_parse_config(
}
}
#endif
// whether or not there is a tray, we now always have an icon theme
if ((json_object_object_get_ex(bar_config, "icon_theme", &icon_theme))) {
config->icon_theme = strdup(json_object_get_string(icon_theme));
#if HAVE_LIBSFDO
sfdo_destroy(config->sfdo);
config->sfdo = sfdo_create(config->icon_theme);
#endif
}
#endif
json_object_put(bar_config);
return true;

View file

@ -20,9 +20,7 @@
#include "stringop.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#if HAVE_LIBSFDO
#include "sfdo.h"
#endif
// TODO menu
@ -426,16 +424,6 @@ static void reload_sni(struct swaybar_sni *sni, char *icon_theme, int target_siz
sni->attention_icon_name : sni->icon_name;
if (icon_name) {
char *icon_path = NULL;
#if !HAVE_LIBSFDO
list_t *icon_search_paths = create_list();
list_cat(icon_search_paths, sni->tray->basedirs);
if (sni->icon_theme_path) {
list_add(icon_search_paths, sni->icon_theme_path);
}
icon_path = find_icon(sni->tray->themes, icon_search_paths,
icon_name, target_size, icon_theme,
&sni->min_size, &sni->max_size);
#else
// TODO: at some point we will need to make this scaling-aware
int scale = 1;
struct sfdo *sfdo = sni->tray->bar->config->sfdo;
@ -446,10 +434,6 @@ static void reload_sni(struct swaybar_sni *sni, char *icon_theme, int target_siz
icon_name, icon_theme, target_size);
}
}
#endif
#if !HAVE_LIBSFDO
list_free(icon_search_paths);
#endif
if (icon_path) {
cairo_surface_destroy(sni->icon);
sni->icon = load_image(icon_path, target_size, scale);