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

View file

@ -21,7 +21,7 @@ void yyerror(const char *str);
enum map_op op;
}
%token WORD STRING CMP_OP L_PAR R_PAR
%token WORD STRING CMP_OP L_PAR R_PAR AT
%left BOOL_OP
%precedence NOT
@ -33,29 +33,35 @@ void yyerror(const char *str);
result: condition { MAP_CONDITION_PARSE_RESULT = $<condition>1; };
condition:
AT WORD {
$<condition>$ = malloc(sizeof(struct map_condition));
$<condition>$->tag = $<str>2;
$<condition>$->op = MAP_OP_ICON_TAG;
}
|
WORD {
$<condition>$ = malloc(sizeof(struct map_condition));
$<condition>$->tag = $<str>1;
$<condition>$->tag = $<str>1;
$<condition>$->op = MAP_OP_SELF;
}
|
WORD CMP_OP WORD {
$<condition>$ = malloc(sizeof(struct map_condition));
$<condition>$->tag = $<str>1;
$<condition>$->tag = $<str>1;
$<condition>$->op = $<op>2;
$<condition>$->value = $<str>3;
$<condition>$->value = $<str>3;
}
|
WORD CMP_OP STRING {
$<condition>$ = malloc(sizeof(struct map_condition));
$<condition>$->tag = $<str>1;
$<condition>$->tag = $<str>1;
$<condition>$->op = $<op>2;
$<condition>$->value = $<str>3;
$<condition>$->value = $<str>3;
}
|
L_PAR condition R_PAR { $<condition>$ = $<condition>2; }
|
NOT condition {
NOT condition {
$<condition>$ = malloc(sizeof(struct map_condition));
$<condition>$->cond1 = $<condition>2;
$<condition>$->op = MAP_OP_NOT;
@ -84,6 +90,7 @@ token_to_str(yysymbol_kind_t tkn)
case YYSYMBOL_L_PAR: return "(";
case YYSYMBOL_R_PAR: return ")";
case YYSYMBOL_NOT: return "~";
case YYSYMBOL_AT: return "+";
default: return yysymbol_name(tkn);
}
}