mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-06-18 00:45:38 +02:00
particles/icon: init
Introduce a new icon particle. It follows the icon spec (https://specifications.freedesktop.org/icon-theme-spec/latest/index.html). Rendering logic is taken from fuzzel (using nanosvg + libpng), while loading logic is taken from sway. Standard usage is with `use-tag = false` which expands the provided string template and then loads the string as the icon name. There are settings to manually override the base paths, themes, etc. The second usage which is required for tray support is a special icon tag that transfers raw pixmaps. With `use-tag = true` it first expands the string, and then uses that output to find an icon pixmap tag. To reduce memory usage, themes are reference counted so they can be passed down the configuration stack without having to load them in multiple times. For programmability, a fallback particle can be specified if no icon/tag is found `fallback: ...`. And the new icon pixmap tag can be existence checked in map conditions using `+{tag_name}`. Future work to be done in follow up diffs: 1. Icon caching. Currently performs an icon lookup on each instantiation & a render on each refresh. 2. Theme caching. Changing theme directories results in a new "theme collection" being created resulting in the possibility of duplicated theme loading.
This commit is contained in:
parent
1a323c6d21
commit
6113f9b94e
51 changed files with 8473 additions and 40 deletions
42
stringop.c
Normal file
42
stringop.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LOG_MODULE "icon"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
#include "log.h"
|
||||
|
||||
char *
|
||||
vformat_str(const char *fmt, va_list args)
|
||||
{
|
||||
char *str = NULL;
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
int len = vsnprintf(NULL, 0, fmt, args);
|
||||
if (len < 0) {
|
||||
LOG_ERR("vsnprintf(\"%s\") failed", fmt);
|
||||
goto out;
|
||||
}
|
||||
|
||||
str = malloc(len + 1);
|
||||
if (str == NULL) {
|
||||
LOG_ERR("malloc() failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
vsnprintf(str, len + 1, fmt, args_copy);
|
||||
|
||||
out:
|
||||
va_end(args_copy);
|
||||
return str;
|
||||
}
|
||||
|
||||
char *
|
||||
format_str(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
char *str = vformat_str(fmt, args);
|
||||
va_end(args);
|
||||
return str;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue