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:
Jordan Isaacs 2023-11-13 23:25:05 -08:00
parent 1a323c6d21
commit 6113f9b94e
No known key found for this signature in database
GPG key ID: 98983D44651F8116
51 changed files with 8473 additions and 40 deletions

17
tag.h
View file

@ -1,8 +1,11 @@
#pragma once
#include <pixman.h>
#include <stdbool.h>
#include <stddef.h>
#include "icon.h"
enum tag_type {
TAG_TYPE_BOOL,
TAG_TYPE_INT,
@ -37,9 +40,20 @@ struct tag {
bool (*refresh_in)(const struct tag *tag, long units);
};
struct icon_tag {
void *private;
struct module *owner;
void (*destroy)(struct icon_tag *destroy);
const char *(*name)(const struct icon_tag *tag);
struct icon_pixmaps *(*pixmaps)(const struct icon_tag *tag);
};
struct tag_set {
struct tag **tags;
struct icon_tag **icon_tags;
size_t count;
size_t icon_count;
};
struct tag *tag_new_int(struct module *owner, const char *name, long value);
@ -50,7 +64,10 @@ struct tag *tag_new_bool(struct module *owner, const char *name, bool value);
struct tag *tag_new_float(struct module *owner, const char *name, double value);
struct tag *tag_new_string(struct module *owner, const char *name, const char *value);
struct icon_tag *icon_tag_new_pixmap(struct module *owner, const char *name, struct icon_pixmaps *icon_pixmap);
const struct tag *tag_for_name(const struct tag_set *set, const char *name);
const struct icon_tag *icon_tag_for_name(const struct tag_set *set, const char *name);
void tag_set_destroy(struct tag_set *set);
/* Utility functions */