Finds paths to icon files using libsfdo. Libsfdo is currently an

optional compile time dependency. This means the former code paths are
all retained and new ones are wrapped in #if HAVE_LIBSFDO. Behavior
should be identical now between the two code paths. Later commits will
add the handling of icons specified as absolute paths which both former
swaybar code and libsfdo have thus far avoided.

Rebased from origin/master.
This commit is contained in:
myrslint 2025-04-29 17:37:58 +00:00 committed by myrslint
parent b5dfcd96bc
commit 2dc1a41e6d
4 changed files with 593 additions and 553 deletions

View file

@ -1,104 +1,123 @@
#include <sys/stat.h>
#include <stdlib.h>
#include <sfdo-basedir.h> #include <sfdo-basedir.h>
#include <sfdo-desktop.h> #include <sfdo-desktop.h>
#include <sfdo-icon.h> #include <sfdo-icon.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "log.h" #include "log.h"
#include "sfdo.h" #include "sfdo.h"
// this extends libsfdo's behavior to also handle icons specified as absolute paths <<<<<<< HEAD
char *sfdo_icon_lookup_extended(struct sfdo *sfdo, char *icon_name, int target_size, int scale) { // this extends libsfdo's behavior to also handle icons specified as
char *icon_path = NULL; // absolute paths
if (icon_name[0] == '/') { char *
struct stat sb; sfdo_icon_lookup_extended(struct sfdo *sfdo, char *icon_name,
if (!stat(icon_name, &sb)) { int target_size, int scale) {
icon_path = strdup(icon_name); char *icon_path = NULL;
} if (icon_name[0] == '/') {
} else { struct stat sb;
int lookup_options = SFDO_ICON_THEME_LOOKUP_OPTIONS_DEFAULT; if (!stat(icon_name, &sb)) {
struct sfdo_icon_file *icon_file = \ icon_path = strdup(icon_name);
sfdo_icon_theme_lookup(sfdo->icon_theme, icon_name, SFDO_NT, \ }
target_size, scale, lookup_options); } else {
if (icon_file && icon_file != SFDO_ICON_FILE_INVALID) { int lookup_options = SFDO_ICON_THEME_LOOKUP_OPTIONS_DEFAULT;
icon_path = strdup(sfdo_icon_file_get_path(icon_file, NULL)); struct sfdo_icon_file *icon_file =
} sfdo_icon_theme_lookup(sfdo->icon_theme, icon_name, SFDO_NT,
sfdo_icon_file_destroy(icon_file); target_size, scale, lookup_options);
} if (icon_file && icon_file != SFDO_ICON_FILE_INVALID) {
return icon_path; icon_path = strdup(sfdo_icon_file_get_path(icon_file, NULL));
} }
sfdo_icon_file_destroy(icon_file);
}
=======
char *sfdo_icon_lookup_extended(struct sfdo * sfdo, char *icon_name,
int target_size, int scale) {
int lookup_options = SFDO_ICON_THEME_LOOKUP_OPTIONS_DEFAULT;
struct sfdo_icon_file *icon_file =
sfdo_icon_theme_lookup(sfdo->icon_theme, icon_name, SFDO_NT,
target_size, scale, lookup_options);
char *icon_path = NULL;
if (icon_file && icon_file != SFDO_ICON_FILE_INVALID) {
icon_path = strdup(sfdo_icon_file_get_path(icon_file, NULL));
}
sfdo_icon_file_destroy(icon_file);
>>>>>>> 92e27bd9 (Finds paths to icon files using libsfdo. Libsfdo is currently an)
return icon_path;
}
struct sfdo *sfdo_create(char *icon_theme) { struct sfdo *sfdo_create(char *icon_theme) {
if (!icon_theme) { if (!icon_theme) {
goto error_null; goto error_null;
} }
struct sfdo *sfdo = calloc(1, sizeof(struct sfdo)); struct sfdo *sfdo = calloc(1, sizeof(struct sfdo));
if (!sfdo) { if (!sfdo) {
goto error_calloc; goto error_calloc;
} }
struct sfdo_basedir_ctx *basedir_ctx = sfdo_basedir_ctx_create(); struct sfdo_basedir_ctx *basedir_ctx = sfdo_basedir_ctx_create();
if (!basedir_ctx) { if (!basedir_ctx) {
goto error_basedir_ctx; goto error_basedir_ctx;
} }
sfdo->desktop_ctx = sfdo_desktop_ctx_create(basedir_ctx); sfdo->desktop_ctx = sfdo_desktop_ctx_create(basedir_ctx);
if (!sfdo->desktop_ctx) { if (!sfdo->desktop_ctx) {
goto error_desktop_ctx; goto error_desktop_ctx;
} }
sfdo->icon_ctx = sfdo_icon_ctx_create(basedir_ctx); sfdo->icon_ctx = sfdo_icon_ctx_create(basedir_ctx);
if (!sfdo->icon_ctx) { if (!sfdo->icon_ctx) {
goto error_icon_ctx; goto error_icon_ctx;
} }
sfdo->desktop_db = sfdo_desktop_db_load(sfdo->desktop_ctx, NULL); sfdo->desktop_db = sfdo_desktop_db_load(sfdo->desktop_ctx, NULL);
if (!sfdo->desktop_db) { if (!sfdo->desktop_db) {
goto error_desktop_db; goto error_desktop_db;
} }
int load_options = SFDO_ICON_THEME_LOAD_OPTIONS_DEFAULT int load_options = SFDO_ICON_THEME_LOAD_OPTIONS_DEFAULT |
| SFDO_ICON_THEME_LOAD_OPTION_ALLOW_MISSING SFDO_ICON_THEME_LOAD_OPTION_ALLOW_MISSING |
| SFDO_ICON_THEME_LOAD_OPTION_RELAXED; SFDO_ICON_THEME_LOAD_OPTION_RELAXED;
sfdo->icon_theme = sfdo_icon_theme_load(sfdo->icon_ctx, icon_theme, load_options); sfdo->icon_theme =
if (!sfdo->icon_theme) { sfdo_icon_theme_load(sfdo->icon_ctx, icon_theme, load_options);
goto error_icon_theme; if (!sfdo->icon_theme) {
} goto error_icon_theme;
}
sfdo_basedir_ctx_destroy(basedir_ctx); sfdo_basedir_ctx_destroy(basedir_ctx);
sway_log(SWAY_INFO, "Successfully setup sfdo with icon theme %s", icon_theme); sway_log(SWAY_INFO, "Successfully setup sfdo with icon theme %s",
return sfdo; icon_theme);
return sfdo;
error_icon_theme: error_icon_theme:
sfdo_desktop_db_destroy(sfdo->desktop_db); sfdo_desktop_db_destroy(sfdo->desktop_db);
error_desktop_db: error_desktop_db:
sfdo_icon_ctx_destroy(sfdo->icon_ctx); sfdo_icon_ctx_destroy(sfdo->icon_ctx);
error_icon_ctx: error_icon_ctx:
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx); sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
error_desktop_ctx: error_desktop_ctx:
sfdo_basedir_ctx_destroy(basedir_ctx); sfdo_basedir_ctx_destroy(basedir_ctx);
error_basedir_ctx: error_basedir_ctx:
free(sfdo); free(sfdo);
error_calloc: error_calloc:
error_null: error_null:
// it's safe to call with null // it's safe to call with null
sway_log(SWAY_ERROR, "Failed to setup sfdo with icon theme %s", icon_theme); sway_log(SWAY_ERROR, "Failed to setup sfdo with icon theme %s", icon_theme);
return NULL; return NULL;
} }
void sfdo_destroy(struct sfdo *sfdo) { void sfdo_destroy(struct sfdo * sfdo) {
if (!sfdo) { if (!sfdo) {
sway_log(SWAY_DEBUG, "Null sfdo passed in"); sway_log(SWAY_DEBUG, "Null sfdo passed in");
return; return;
} }
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx); sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
sfdo_icon_ctx_destroy(sfdo->icon_ctx); sfdo_icon_ctx_destroy(sfdo->icon_ctx);
sfdo_desktop_db_destroy(sfdo->desktop_db); sfdo_desktop_db_destroy(sfdo->desktop_db);
sfdo_icon_theme_destroy(sfdo->icon_theme); sfdo_icon_theme_destroy(sfdo->icon_theme);
free(sfdo); free(sfdo);
sway_log(SWAY_DEBUG, "Successfully destroyed sfdo"); sway_log(SWAY_DEBUG, "Successfully destroyed sfdo");
} }

View file

@ -211,9 +211,4 @@ void set_rr_scheduling(void);
void handle_new_tearing_hint(struct wl_listener *listener, void *data); void handle_new_tearing_hint(struct wl_listener *listener, void *data);
#if HAVE_LIBSFDO
struct sfdo *sfdo_create(char *theme);
void sfdo_destroy(struct sfdo *sfdo);
#endif
#endif #endif

View file

@ -71,12 +71,16 @@
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
#include "sfdo.h" #include "sfdo.h"
======= =======
#include <sfdo-basedir.h> #include <sfdo-basedir.h>
#include <sfdo-desktop.h> #include <sfdo-desktop.h>
#include <sfdo-icon.h> #include <sfdo-icon.h>
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and) >>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
=======
#include "sfdo.h"
>>>>>>> 92e27bd9 (Finds paths to icon files using libsfdo. Libsfdo is currently an)
#endif #endif
#define SWAY_XDG_SHELL_VERSION 5 #define SWAY_XDG_SHELL_VERSION 5
@ -84,7 +88,7 @@
#define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1 #define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1
#define SWAY_PRESENTATION_VERSION 2 #define SWAY_PRESENTATION_VERSION 2
bool allow_unsupported_gpu = false; bool allow_unsupported_gpu = false;
#if WLR_HAS_DRM_BACKEND #if WLR_HAS_DRM_BACKEND
static void handle_drm_lease_request(struct wl_listener *listener, void *data) { static void handle_drm_lease_request(struct wl_listener *listener, void *data) {
@ -532,25 +536,13 @@ void server_fini(struct sway_server *server) {
wl_list_remove(&server->drm_lease_request.link); wl_list_remove(&server->drm_lease_request.link);
} }
#endif #endif
<<<<<<< HEAD
<<<<<<< HEAD wl_list_remove(&server->tearing_control_new_object.link);
wl_list_remove(&server->xdg_activation_v1_request_activate.link);
wl_list_remove(&server->xdg_activation_v1_new_token.link);
wl_list_remove(&server->request_set_cursor_shape.link);
input_manager_finish(server->input);
=======
=======
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
wl_list_remove(&server->tearing_control_new_object.link); wl_list_remove(&server->tearing_control_new_object.link);
wl_list_remove(&server->xdg_activation_v1_request_activate.link); wl_list_remove(&server->xdg_activation_v1_request_activate.link);
wl_list_remove(&server->xdg_activation_v1_new_token.link); wl_list_remove(&server->xdg_activation_v1_new_token.link);
wl_list_remove(&server->request_set_cursor_shape.link); wl_list_remove(&server->request_set_cursor_shape.link);
wl_list_remove(&server->new_foreign_toplevel_capture_request.link); wl_list_remove(&server->new_foreign_toplevel_capture_request.link);
input_manager_finish(server->input); input_manager_finish(server->input);
<<<<<<< HEAD
>>>>>>> 170c9c95 (Add support for toplevel capture)
=======
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
// TODO: free sway-specific resources // TODO: free sway-specific resources
#if WLR_HAS_XWAYLAND #if WLR_HAS_XWAYLAND
@ -580,7 +572,7 @@ void server_fini(struct sway_server *server) {
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
sfdo_destroy(server->sfdo); sfdo_destroy(server->sfdo);
#endif #endif
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and) >>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
} }
bool server_start(struct sway_server *server) { bool server_start(struct sway_server *server) {

File diff suppressed because it is too large Load diff