icon-loader: rename to desktop-entry

Also rename `struct icon_loader` to `struct sfdo`.
This commit is contained in:
Jens Peters 2024-11-18 18:59:49 +01:00
parent e647fc7b23
commit f69576f8a6
No known key found for this signature in database
7 changed files with 60 additions and 59 deletions

12
include/desktop-entry.h Normal file
View file

@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_DESKTOP_ENTRY_H
#define LABWC_DESKTOP_ENTRY_H
struct server;
void desktop_entry_init(struct server *server);
void desktop_entry_finish(struct server *server);
struct lab_data_buffer *desktop_entry_icon_lookup(struct server *server,
const char *app_id, int size, float scale);
#endif /* LABWC_DESKTOP_ENTRY_H */

View file

@ -1,12 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_ICON_LOADER_H
#define LABWC_ICON_LOADER_H
struct server;
void icon_loader_init(struct server *server);
void icon_loader_finish(struct server *server);
struct lab_data_buffer *icon_loader_lookup(struct server *server,
const char *app_id, int size, float scale);
#endif /* LABWC_ICON_LOADER_H */

View file

@ -379,7 +379,7 @@ struct server {
struct menu *menu_current; struct menu *menu_current;
struct wl_list menus; struct wl_list menus;
struct icon_loader *icon_loader; struct sfdo *sfdo;
pid_t primary_client_pid; pid_t primary_client_pid;
}; };

View file

@ -9,7 +9,7 @@
#include "common/mem.h" #include "common/mem.h"
#include "common/string-helpers.h" #include "common/string-helpers.h"
#include "config.h" #include "config.h"
#include "icon-loader.h" #include "desktop-entry.h"
#include "img/img-png.h" #include "img/img-png.h"
#include "img/img-xpm.h" #include "img/img-xpm.h"
@ -19,7 +19,7 @@
#include "labwc.h" #include "labwc.h"
struct icon_loader { struct sfdo {
struct sfdo_desktop_ctx *desktop_ctx; struct sfdo_desktop_ctx *desktop_ctx;
struct sfdo_icon_ctx *icon_ctx; struct sfdo_icon_ctx *icon_ctx;
struct sfdo_desktop_db *desktop_db; struct sfdo_desktop_db *desktop_db;
@ -40,20 +40,20 @@ log_handler(enum sfdo_log_level level, const char *fmt, va_list args, void *tag)
} }
void void
icon_loader_init(struct server *server) desktop_entry_init(struct server *server)
{ {
struct icon_loader *loader = znew(*loader); struct sfdo *sfdo = znew(*sfdo);
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 err_basedir_ctx; goto err_basedir_ctx;
} }
loader->desktop_ctx = sfdo_desktop_ctx_create(basedir_ctx); sfdo->desktop_ctx = sfdo_desktop_ctx_create(basedir_ctx);
if (!loader->desktop_ctx) { if (!sfdo->desktop_ctx) {
goto err_desktop_ctx; goto err_desktop_ctx;
} }
loader->icon_ctx = sfdo_icon_ctx_create(basedir_ctx); sfdo->icon_ctx = sfdo_icon_ctx_create(basedir_ctx);
if (!loader->icon_ctx) { if (!sfdo->icon_ctx) {
goto err_icon_ctx; goto err_icon_ctx;
} }
@ -61,12 +61,12 @@ icon_loader_init(struct server *server)
enum sfdo_log_level level = enum sfdo_log_level level =
(enum sfdo_log_level)wlr_log_get_verbosity(); (enum sfdo_log_level)wlr_log_get_verbosity();
sfdo_desktop_ctx_set_log_handler( sfdo_desktop_ctx_set_log_handler(
loader->desktop_ctx, level, log_handler, "sfdo-desktop"); sfdo->desktop_ctx, level, log_handler, "sfdo-desktop");
sfdo_icon_ctx_set_log_handler( sfdo_icon_ctx_set_log_handler(
loader->icon_ctx, level, log_handler, "sfdo-icon"); sfdo->icon_ctx, level, log_handler, "sfdo-icon");
loader->desktop_db = sfdo_desktop_db_load(loader->desktop_ctx, NULL); sfdo->desktop_db = sfdo_desktop_db_load(sfdo->desktop_ctx, NULL);
if (!loader->desktop_db) { if (!sfdo->desktop_db) {
goto err_desktop_db; goto err_desktop_db;
} }
@ -84,45 +84,46 @@ icon_loader_init(struct server *server)
| 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;
loader->icon_theme = sfdo_icon_theme_load(loader->icon_ctx, sfdo->icon_theme = sfdo_icon_theme_load(
sfdo->icon_ctx,
rc.icon_theme_name, load_options); rc.icon_theme_name, load_options);
if (!loader->icon_theme) { if (!sfdo->icon_theme) {
goto err_icon_theme; goto err_icon_theme;
} }
/* basedir_ctx is not referenced by other objects */ /* basedir_ctx is not referenced by other objects */
sfdo_basedir_ctx_destroy(basedir_ctx); sfdo_basedir_ctx_destroy(basedir_ctx);
server->icon_loader = loader; server->sfdo = sfdo;
return; return;
err_icon_theme: err_icon_theme:
sfdo_desktop_db_destroy(loader->desktop_db); sfdo_desktop_db_destroy(sfdo->desktop_db);
err_desktop_db: err_desktop_db:
sfdo_icon_ctx_destroy(loader->icon_ctx); sfdo_icon_ctx_destroy(sfdo->icon_ctx);
err_icon_ctx: err_icon_ctx:
sfdo_desktop_ctx_destroy(loader->desktop_ctx); sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
err_desktop_ctx: err_desktop_ctx:
sfdo_basedir_ctx_destroy(basedir_ctx); sfdo_basedir_ctx_destroy(basedir_ctx);
err_basedir_ctx: err_basedir_ctx:
free(loader); free(sfdo);
wlr_log(WLR_ERROR, "Failed to initialize icon loader"); wlr_log(WLR_ERROR, "Failed to initialize icon loader");
} }
void void
icon_loader_finish(struct server *server) desktop_entry_finish(struct server *server)
{ {
struct icon_loader *loader = server->icon_loader; struct sfdo *sfdo = server->sfdo;
if (!loader) { if (!sfdo) {
return; return;
} }
sfdo_icon_theme_destroy(loader->icon_theme); sfdo_icon_theme_destroy(sfdo->icon_theme);
sfdo_desktop_db_destroy(loader->desktop_db); sfdo_desktop_db_destroy(sfdo->desktop_db);
sfdo_icon_ctx_destroy(loader->icon_ctx); sfdo_icon_ctx_destroy(sfdo->icon_ctx);
sfdo_desktop_ctx_destroy(loader->desktop_ctx); sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
free(loader); free(sfdo);
server->icon_loader = NULL; server->sfdo = NULL;
} }
struct icon_ctx { struct icon_ctx {
@ -153,7 +154,7 @@ length_without_extension(const char *name)
*/ */
static int static int
process_rel_name(struct icon_ctx *ctx, const char *icon_name, process_rel_name(struct icon_ctx *ctx, const char *icon_name,
struct icon_loader *loader, int size, int scale) struct sfdo *sfdo, int size, int scale)
{ {
int ret = 0; int ret = 0;
int lookup_options = SFDO_ICON_THEME_LOOKUP_OPTIONS_DEFAULT; int lookup_options = SFDO_ICON_THEME_LOOKUP_OPTIONS_DEFAULT;
@ -168,7 +169,7 @@ process_rel_name(struct icon_ctx *ctx, const char *icon_name,
*/ */
size_t name_len = length_without_extension(icon_name); size_t name_len = length_without_extension(icon_name);
struct sfdo_icon_file *icon_file = sfdo_icon_theme_lookup( struct sfdo_icon_file *icon_file = sfdo_icon_theme_lookup(
loader->icon_theme, icon_name, name_len, size, scale, sfdo->icon_theme, icon_name, name_len, size, scale,
lookup_options); lookup_options);
if (!icon_file || icon_file == SFDO_ICON_FILE_INVALID) { if (!icon_file || icon_file == SFDO_ICON_FILE_INVALID) {
ret = -1; ret = -1;
@ -255,19 +256,19 @@ get_db_entry_by_id_fuzzy(struct sfdo_desktop_db *db, const char *app_id)
} }
struct lab_data_buffer * struct lab_data_buffer *
icon_loader_lookup(struct server *server, const char *app_id, int size, desktop_entry_icon_lookup(struct server *server, const char *app_id, int size,
float scale) float scale)
{ {
struct icon_loader *loader = server->icon_loader; struct sfdo *sfdo = server->sfdo;
if (!loader) { if (!sfdo) {
return NULL; return NULL;
} }
const char *icon_name = NULL; const char *icon_name = NULL;
struct sfdo_desktop_entry *entry = sfdo_desktop_db_get_entry_by_id( struct sfdo_desktop_entry *entry = sfdo_desktop_db_get_entry_by_id(
loader->desktop_db, app_id, SFDO_NT); sfdo->desktop_db, app_id, SFDO_NT);
if (!entry) { if (!entry) {
entry = get_db_entry_by_id_fuzzy(loader->desktop_db, app_id); entry = get_db_entry_by_id_fuzzy(sfdo->desktop_db, app_id);
} }
if (entry) { if (entry) {
icon_name = sfdo_desktop_entry_get_icon(entry, NULL); icon_name = sfdo_desktop_entry_get_icon(entry, NULL);
@ -284,15 +285,15 @@ icon_loader_lookup(struct server *server, const char *app_id, int size,
int ret; int ret;
if (!icon_name) { if (!icon_name) {
/* fall back to app id */ /* fall back to app id */
ret = process_rel_name(&ctx, app_id, loader, lookup_size, lookup_scale); ret = process_rel_name(&ctx, app_id, sfdo, lookup_size, lookup_scale);
} else if (icon_name[0] == '/') { } else if (icon_name[0] == '/') {
ret = process_abs_name(&ctx, icon_name); ret = process_abs_name(&ctx, icon_name);
} else { } else {
/* this should be the case for most icons */ /* this should be the case for most icons */
ret = process_rel_name(&ctx, icon_name, loader, lookup_size, lookup_scale); ret = process_rel_name(&ctx, icon_name, sfdo, lookup_size, lookup_scale);
/* Icon defined in .desktop file could not be loaded, retry with app_id */ /* Icon defined in .desktop file could not be loaded, retry with app_id */
if (ret < 0) { if (ret < 0) {
ret = process_rel_name(&ctx, app_id, loader, lookup_size, lookup_scale); ret = process_rel_name(&ctx, app_id, sfdo, lookup_size, lookup_scale);
} }
} }
if (ret < 0) { if (ret < 0) {

View file

@ -45,7 +45,7 @@ endif
if have_libsfdo if have_libsfdo
labwc_sources += files( labwc_sources += files(
'icon-loader.c', 'desktop-entry.c',
) )
endif endif

View file

@ -30,7 +30,7 @@
#include "config/session.h" #include "config/session.h"
#include "decorations.h" #include "decorations.h"
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
#include "icon-loader.h" #include "desktop-entry.h"
#endif #endif
#include "idle.h" #include "idle.h"
#include "labwc.h" #include "labwc.h"
@ -66,8 +66,8 @@ reload_config_and_theme(struct server *server)
theme_init(server->theme, server, rc.theme_name); theme_init(server->theme, server, rc.theme_name);
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
icon_loader_finish(server); desktop_entry_finish(server);
icon_loader_init(server); desktop_entry_init(server);
#endif #endif
struct view *view; struct view *view;
@ -585,7 +585,7 @@ server_init(struct server *server)
layers_init(server); layers_init(server);
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
icon_loader_init(server); desktop_entry_init(server);
#endif #endif
#if HAVE_XWAYLAND #if HAVE_XWAYLAND
@ -629,7 +629,7 @@ server_finish(struct server *server)
xwayland_server_finish(server); xwayland_server_finish(server);
#endif #endif
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
icon_loader_finish(server); desktop_entry_finish(server);
#endif #endif
if (sighup_source) { if (sighup_source) {
wl_event_source_remove(sighup_source); wl_event_source_remove(sighup_source);

View file

@ -10,7 +10,7 @@
#include "common/scene-helpers.h" #include "common/scene-helpers.h"
#include "common/string-helpers.h" #include "common/string-helpers.h"
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
#include "icon-loader.h" #include "desktop-entry.h"
#endif #endif
#include "labwc.h" #include "labwc.h"
#include "node.h" #include "node.h"
@ -610,7 +610,7 @@ ssd_update_window_icon(struct ssd *ssd)
*/ */
float icon_scale = output_max_scale(ssd->view->server); float icon_scale = output_max_scale(ssd->view->server);
struct lab_data_buffer *icon_buffer = icon_loader_lookup( struct lab_data_buffer *icon_buffer = desktop_entry_icon_lookup(
ssd->view->server, app_id, icon_size, icon_scale); ssd->view->server, app_id, icon_size, icon_scale);
if (!icon_buffer) { if (!icon_buffer) {
wlr_log(WLR_DEBUG, "icon could not be loaded for %s", app_id); wlr_log(WLR_DEBUG, "icon could not be loaded for %s", app_id);