1
0
Fork 0
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:
Dave Davenport 2017-01-05 18:22:34 +01:00
parent 50479057bc
commit 4cc21b93a5
4 changed files with 100 additions and 35 deletions

View file

@ -55,6 +55,8 @@ typedef enum {
P_COLOR, P_COLOR,
/** Padding */ /** Padding */
P_PADDING, P_PADDING,
/** Link to global setting */
P_LINK,
} PropertyType; } PropertyType;
/** /**
@ -83,7 +85,7 @@ typedef struct
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;
/** /**

View file

@ -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;

View file

@ -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;

View file

@ -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);
} }
@ -130,7 +132,10 @@ static void rofi_theme_print_property_index ( int depth, Property *p )
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;
} }