mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Allow linking to top level properties.
This commit is contained in:
parent
50479057bc
commit
4cc21b93a5
4 changed files with 100 additions and 35 deletions
|
@ -55,6 +55,8 @@ typedef enum {
|
||||||
P_COLOR,
|
P_COLOR,
|
||||||
/** Padding */
|
/** Padding */
|
||||||
P_PADDING,
|
P_PADDING,
|
||||||
|
/** Link to global setting */
|
||||||
|
P_LINK,
|
||||||
} PropertyType;
|
} PropertyType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,14 +78,14 @@ typedef struct
|
||||||
* Padding
|
* Padding
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Distance top;
|
Distance top;
|
||||||
Distance right;
|
Distance right;
|
||||||
Distance bottom;
|
Distance bottom;
|
||||||
Distance left;
|
Distance left;
|
||||||
} Padding;
|
} Padding;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Property {
|
||||||
char *name;
|
char *name;
|
||||||
PropertyType type;
|
PropertyType type;
|
||||||
union {
|
union {
|
||||||
|
@ -93,6 +95,10 @@ typedef struct {
|
||||||
int b;
|
int b;
|
||||||
ThemeColor color;
|
ThemeColor color;
|
||||||
Padding padding;
|
Padding padding;
|
||||||
|
struct {
|
||||||
|
char *name;
|
||||||
|
struct Property *ref;
|
||||||
|
} link;
|
||||||
} value;
|
} value;
|
||||||
} Property;
|
} Property;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -109,6 +109,10 @@ if ( queue == NULL ){
|
||||||
<PROPERTIES>{NUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
|
<PROPERTIES>{NUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
|
||||||
<PROPERTIES>{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
|
<PROPERTIES>{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
|
||||||
<PROPERTIES>\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;}
|
<PROPERTIES>\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;}
|
||||||
|
<PROPERTIES>@{WORD} {
|
||||||
|
yylval->sval = g_strdup(yytext);
|
||||||
|
return T_LINK;
|
||||||
|
}
|
||||||
|
|
||||||
<PROPERTIES>{REAL}{EM} {
|
<PROPERTIES>{REAL}{EM} {
|
||||||
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
||||||
|
@ -208,6 +212,11 @@ if ( queue == NULL ){
|
||||||
return T_COLOR;
|
return T_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<*>'\n' {
|
||||||
|
printf("newlines\n");
|
||||||
|
yylloc->last_column = 1;
|
||||||
|
yylloc->last_line ++;
|
||||||
|
};
|
||||||
<*>(\r\n) {
|
<*>(\r\n) {
|
||||||
printf("newlines\n");
|
printf("newlines\n");
|
||||||
yylloc->last_column = 1;
|
yylloc->last_column = 1;
|
||||||
|
|
|
@ -42,6 +42,7 @@ int yylex (YYSTYPE *, YYLTYPE *);
|
||||||
%token <bval> T_BOOLEAN
|
%token <bval> T_BOOLEAN
|
||||||
%token <colorval> T_COLOR
|
%token <colorval> T_COLOR
|
||||||
%token <distance> T_PIXEL
|
%token <distance> T_PIXEL
|
||||||
|
%token <sval> T_LINK
|
||||||
%token <sval> FIRST_NAME
|
%token <sval> FIRST_NAME
|
||||||
|
|
||||||
%token BOPEN "bracket open";
|
%token BOPEN "bracket open";
|
||||||
|
@ -146,6 +147,11 @@ property
|
||||||
$$->name = $1;
|
$$->name = $1;
|
||||||
$$->value.s = $3;
|
$$->value.s = $3;
|
||||||
}
|
}
|
||||||
|
| pvalue PSEP T_LINK PCLOSE {
|
||||||
|
$$ = rofi_theme_property_create ( P_LINK );
|
||||||
|
$$->name = $1;
|
||||||
|
$$->value.link.name = $3;
|
||||||
|
}
|
||||||
| pvalue PSEP T_BOOLEAN PCLOSE {
|
| pvalue PSEP T_BOOLEAN PCLOSE {
|
||||||
$$ = rofi_theme_property_create ( P_BOOLEAN );
|
$$ = rofi_theme_property_create ( P_BOOLEAN );
|
||||||
$$->name = $1;
|
$$->name = $1;
|
||||||
|
|
110
source/theme.c
110
source/theme.c
|
@ -50,6 +50,8 @@ void rofi_theme_property_free ( Property *p )
|
||||||
g_free ( p->name );
|
g_free ( p->name );
|
||||||
if ( p->type == P_STRING ) {
|
if ( p->type == P_STRING ) {
|
||||||
g_free ( p->value.s );
|
g_free ( p->value.s );
|
||||||
|
} else if ( p->type == P_LINK ) {
|
||||||
|
g_free ( p->value.link.name );
|
||||||
}
|
}
|
||||||
g_free(p);
|
g_free(p);
|
||||||
}
|
}
|
||||||
|
@ -92,45 +94,48 @@ static void rofi_theme_print_property_index ( int depth, Property *p )
|
||||||
switch ( p->type )
|
switch ( p->type )
|
||||||
{
|
{
|
||||||
case P_STRING:
|
case P_STRING:
|
||||||
printf("\"%s\";", p->value.s);
|
printf("\"%s\";", p->value.s);
|
||||||
break;
|
break;
|
||||||
case P_INTEGER:
|
case P_INTEGER:
|
||||||
printf("%d;", p->value.i);
|
printf("%d;", p->value.i);
|
||||||
break;
|
break;
|
||||||
case P_DOUBLE:
|
case P_DOUBLE:
|
||||||
printf("%.2f;", p->value.f);
|
printf("%.2f;", p->value.f);
|
||||||
break;
|
break;
|
||||||
case P_BOOLEAN:
|
case P_BOOLEAN:
|
||||||
printf("%s;", p->value.b?"true":"false");
|
printf("%s;", p->value.b?"true":"false");
|
||||||
break;
|
break;
|
||||||
case P_COLOR:
|
case P_COLOR:
|
||||||
printf("#%02X%02X%02X%02X;",
|
printf("#%02X%02X%02X%02X;",
|
||||||
(unsigned char)(p->value.color.alpha*255.0),
|
(unsigned char)(p->value.color.alpha*255.0),
|
||||||
(unsigned char)(p->value.color.red*255.0),
|
(unsigned char)(p->value.color.red*255.0),
|
||||||
(unsigned char)(p->value.color.green*255.0),
|
(unsigned char)(p->value.color.green*255.0),
|
||||||
(unsigned char)(p->value.color.blue*255.0));
|
(unsigned char)(p->value.color.blue*255.0));
|
||||||
break;
|
break;
|
||||||
case P_PADDING:
|
case P_PADDING:
|
||||||
if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
|
if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
|
||||||
distance_compare ( p->value.padding.left, p->value.padding.right) &&
|
distance_compare ( p->value.padding.left, p->value.padding.right) &&
|
||||||
distance_compare ( p->value.padding.left, p->value.padding.top) ) {
|
distance_compare ( p->value.padding.left, p->value.padding.top) ) {
|
||||||
rofi_theme_print_distance ( p->value.padding.left );
|
rofi_theme_print_distance ( p->value.padding.left );
|
||||||
} else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
|
} else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
|
||||||
distance_compare ( p->value.padding.left, p->value.padding.right)){
|
distance_compare ( p->value.padding.left, p->value.padding.right)){
|
||||||
rofi_theme_print_distance ( p->value.padding.top );
|
rofi_theme_print_distance ( p->value.padding.top );
|
||||||
rofi_theme_print_distance ( p->value.padding.left );
|
rofi_theme_print_distance ( p->value.padding.left );
|
||||||
} else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
|
} else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
|
||||||
distance_compare ( p->value.padding.left, p->value.padding.right)){
|
distance_compare ( p->value.padding.left, p->value.padding.right)){
|
||||||
rofi_theme_print_distance ( p->value.padding.top );
|
rofi_theme_print_distance ( p->value.padding.top );
|
||||||
rofi_theme_print_distance ( p->value.padding.left );
|
rofi_theme_print_distance ( p->value.padding.left );
|
||||||
rofi_theme_print_distance ( p->value.padding.bottom);
|
rofi_theme_print_distance ( p->value.padding.bottom);
|
||||||
} else {
|
} else {
|
||||||
rofi_theme_print_distance ( p->value.padding.top );
|
rofi_theme_print_distance ( p->value.padding.top );
|
||||||
rofi_theme_print_distance ( p->value.padding.right );
|
rofi_theme_print_distance ( p->value.padding.right );
|
||||||
rofi_theme_print_distance ( p->value.padding.bottom);
|
rofi_theme_print_distance ( p->value.padding.bottom);
|
||||||
rofi_theme_print_distance ( p->value.padding.left );
|
rofi_theme_print_distance ( p->value.padding.left );
|
||||||
}
|
}
|
||||||
printf(";\n");
|
printf(";");
|
||||||
|
break;
|
||||||
|
case P_LINK:
|
||||||
|
printf("@%s;", p->value.link.name);
|
||||||
}
|
}
|
||||||
putchar ( '\n' );
|
putchar ( '\n' );
|
||||||
}
|
}
|
||||||
|
@ -272,11 +277,50 @@ static ThemeWidget *rofi_theme_find ( ThemeWidget *widget , const char *name, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rofi_theme_resolve_link_property ( Property *p, int depth )
|
||||||
|
{
|
||||||
|
// Set name, remove '@' prefix.
|
||||||
|
const char *name = p->value.link.name +1;
|
||||||
|
if ( depth > 20 ){
|
||||||
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Found more then 20 redirects for property. Stopping.");
|
||||||
|
p->value.link.ref = p;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( g_hash_table_contains ( rofi_theme->properties, name ) ) {
|
||||||
|
Property *pr = g_hash_table_lookup ( rofi_theme->properties, name );
|
||||||
|
if ( pr->type == P_LINK ) {
|
||||||
|
if ( pr->value.link.ref == NULL ) {
|
||||||
|
rofi_theme_resolve_link_property ( pr, depth+1);
|
||||||
|
}
|
||||||
|
if ( pr->value.link.ref != pr ){
|
||||||
|
p->value.link.ref = pr->value.link.ref;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p->value.link.ref = pr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No found, set ref to self.
|
||||||
|
p->value.link.ref = p;
|
||||||
|
}
|
||||||
|
|
||||||
static Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, const char *property )
|
static Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, const char *property )
|
||||||
{
|
{
|
||||||
while ( widget ) {
|
while ( widget ) {
|
||||||
if ( widget->properties && g_hash_table_contains ( widget->properties, property) ) {
|
if ( widget->properties && g_hash_table_contains ( widget->properties, property) ) {
|
||||||
Property *p = g_hash_table_lookup ( widget->properties, property);
|
Property *p = g_hash_table_lookup ( widget->properties, property);
|
||||||
|
if ( p->type == P_LINK ) {
|
||||||
|
if ( p->value.link.ref == NULL ) {
|
||||||
|
// Resolve link.
|
||||||
|
rofi_theme_resolve_link_property ( p, 0 );
|
||||||
|
}
|
||||||
|
if ( p->value.link.ref->type == type ){
|
||||||
|
return p->value.link.ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( p->type == type ){
|
if ( p->type == type ){
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue