mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 04:25:42 +02:00
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.
80 lines
1.9 KiB
Text
80 lines
1.9 KiB
Text
%{
|
|
#include <string.h>
|
|
#include "map.h"
|
|
#include "map.tab.h"
|
|
void yyerror(const char *s);
|
|
%}
|
|
|
|
%option warn nodefault nounput noinput noyywrap
|
|
|
|
char *quoted = NULL;
|
|
size_t quote_len = 0;
|
|
|
|
%x QUOTE
|
|
|
|
%%
|
|
|
|
[[:alnum:]_-]+ yylval.str = strdup(yytext); return WORD;
|
|
|
|
\" {
|
|
BEGIN(QUOTE);
|
|
quoted = calloc(1, sizeof(quoted[0]));
|
|
}
|
|
|
|
<QUOTE>[^\\\"]* {
|
|
/* printf("CAT: %s\n", yytext); */
|
|
const size_t yy_length = strlen(yytext);
|
|
quoted = realloc(quoted, quote_len + yy_length + 1);
|
|
strcat(quoted, yytext);
|
|
quote_len += yy_length;
|
|
}
|
|
|
|
<QUOTE>\\\" {
|
|
/* printf("escaped quote\n"); */
|
|
quoted = realloc(quoted, quote_len + 1 + 1);
|
|
strcat(quoted, "\"");
|
|
quote_len++;
|
|
}
|
|
|
|
<QUOTE>\\. {
|
|
/* printf("CAT: %s\n", yytext); */
|
|
const size_t yy_length = strlen(yytext);
|
|
quoted = realloc(quoted, quote_len + yy_length + 1);
|
|
strcat(quoted, yytext);
|
|
quote_len += yy_length;
|
|
}
|
|
|
|
<QUOTE>\\ {
|
|
/* quoted string that ends with a backslash: "string\ */
|
|
quoted = realloc(quoted, quote_len + 1 + 1);
|
|
strcat(quoted, "\\");
|
|
quote_len++;
|
|
}
|
|
|
|
<QUOTE>\" {
|
|
/* printf("QUOTED=%s\n", quoted); */
|
|
yylval.str = strdup(quoted);
|
|
|
|
free(quoted);
|
|
quoted = NULL;
|
|
quote_len = 0;
|
|
|
|
BEGIN(INITIAL);
|
|
return STRING;
|
|
}
|
|
|
|
== yylval.op = MAP_OP_EQ; return CMP_OP;
|
|
!= yylval.op = MAP_OP_NE; return CMP_OP;
|
|
\<= yylval.op = MAP_OP_LE; return CMP_OP;
|
|
\< yylval.op = MAP_OP_LT; return CMP_OP;
|
|
>= yylval.op = MAP_OP_GE; return CMP_OP;
|
|
> yylval.op = MAP_OP_GT; return CMP_OP;
|
|
&& yylval.op = MAP_OP_AND; return BOOL_OP;
|
|
\|\| yylval.op = MAP_OP_OR; return BOOL_OP;
|
|
~ return NOT;
|
|
\+ return AT;
|
|
\( return L_PAR;
|
|
\) return R_PAR;
|
|
[ \t\n] ;
|
|
. yylval.str = strdup(yytext); return STRING;
|
|
%%
|