diff --git a/doc/default_theme.rasi b/doc/default_theme.rasi index 284010b2..3b346a6d 100644 --- a/doc/default_theme.rasi +++ b/doc/default_theme.rasi @@ -2,37 +2,37 @@ * rofi -dump-theme output. **/ * { - selected-normal-foreground: @lightbg; + selected-normal-foreground: var(lightbg); foreground: rgba ( 0, 43, 54, 100 % ); - normal-foreground: @foreground; - alternate-normal-background: @lightbg; + normal-foreground: var(foreground); + alternate-normal-background: var(lightbg); red: rgba ( 220, 50, 47, 100 % ); - selected-urgent-foreground: @background; + selected-urgent-foreground: var(background); blue: rgba ( 38, 139, 210, 100 % ); - urgent-foreground: @red; - alternate-urgent-background: @lightbg; - active-foreground: @blue; + urgent-foreground: var(red); + alternate-urgent-background: var(lightbg); + active-foreground: var(blue); lightbg: rgba ( 238, 232, 213, 100 % ); - selected-active-foreground: @background; - alternate-active-background: @lightbg; + selected-active-foreground: var(background); + alternate-active-background: var(lightbg); background: rgba ( 253, 246, 227, 100 % ); - alternate-normal-foreground: @foreground; - normal-background: @background; + alternate-normal-foreground: var(foreground); + normal-background: var(background); lightfg: rgba ( 88, 104, 117, 100 % ); - selected-normal-background: @lightfg; - border-color: @foreground; + selected-normal-background: var(lightfg); + border-color: var(foreground); spacing: 2; - separatorcolor: @foreground; - urgent-background: @background; - selected-urgent-background: @red; - alternate-urgent-foreground: @red; + separatorcolor: var(foreground); + urgent-background: var(background); + selected-urgent-background: var(red); + alternate-urgent-foreground: var(red); background-color: rgba ( 0, 0, 0, 0 % ); - alternate-active-foreground: @blue; - active-background: @background; - selected-active-background: @blue; + alternate-active-foreground: var(blue); + active-background: var(background); + selected-active-background: var(blue); } window { - background-color: @background; + background-color: var(background); border: 1; padding: 5; } @@ -42,16 +42,16 @@ mainbox { } message { border: 2px dash 0px 0px ; - border-color: @separatorcolor; + border-color: var(separatorcolor); padding: 1px ; } textbox { - text-color: @foreground; + text-color: var(foreground); } listview { fixed-height: 0; border: 2px dash 0px 0px ; - border-color: @separatorcolor; + border-color: var(separatorcolor); spacing: 2px ; scrollbar: true; padding: 2px 0px 0px ; @@ -61,77 +61,77 @@ element { padding: 1px ; } element normal.normal { - background-color: @normal-background; - text-color: @normal-foreground; + background-color: var(normal-background); + text-color: var(normal-foreground); } element normal.urgent { - background-color: @urgent-background; - text-color: @urgent-foreground; + background-color: var(urgent-background); + text-color: var(urgent-foreground); } element normal.active { - background-color: @active-background; - text-color: @active-foreground; + background-color: var(active-background); + text-color: var(active-foreground); } element selected.normal { - background-color: @selected-normal-background; - text-color: @selected-normal-foreground; + background-color: var(selected-normal-background); + text-color: var(selected-normal-foreground); } element selected.urgent { - background-color: @selected-urgent-background; - text-color: @selected-urgent-foreground; + background-color: var(selected-urgent-background); + text-color: var(selected-urgent-foreground); } element selected.active { - background-color: @selected-active-background; - text-color: @selected-active-foreground; + background-color: var(selected-active-background); + text-color: var(selected-active-foreground); } element alternate.normal { - background-color: @alternate-normal-background; - text-color: @alternate-normal-foreground; + background-color: var(alternate-normal-background); + text-color: var(alternate-normal-foreground); } element alternate.urgent { - background-color: @alternate-urgent-background; - text-color: @alternate-urgent-foreground; + background-color: var(alternate-urgent-background); + text-color: var(alternate-urgent-foreground); } element alternate.active { - background-color: @alternate-active-background; - text-color: @alternate-active-foreground; + background-color: var(alternate-active-background); + text-color: var(alternate-active-foreground); } scrollbar { width: 4px ; border: 0; - handle-color: @normal-foreground; + handle-color: var(normal-foreground); handle-width: 8px ; padding: 0; } sidebar { border: 2px dash 0px 0px ; - border-color: @separatorcolor; + border-color: var(separatorcolor); } button { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } button selected { - background-color: @selected-normal-background; - text-color: @selected-normal-foreground; + background-color: var(selected-normal-background); + text-color: var(selected-normal-foreground); } inputbar { spacing: 0px ; - text-color: @normal-foreground; + text-color: var(normal-foreground); padding: 1px ; children: [ prompt,textbox-prompt-colon,entry,case-indicator ]; } case-indicator { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } entry { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } prompt { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } textbox-prompt-colon { expand: false; @@ -141,5 +141,5 @@ textbox-prompt-colon { } error-message { background-color: rgba ( 0, 0, 0, 0 % ); - text-color: @normal-foreground; + text-color: var(normal-foreground); } diff --git a/doc/old-theme-convert-output.rasi b/doc/old-theme-convert-output.rasi index e7dcc32d..e8461206 100644 --- a/doc/old-theme-convert-output.rasi +++ b/doc/old-theme-convert-output.rasi @@ -4,7 +4,7 @@ * { selected-normal-foreground: rgba ( 2, 20, 63, 100 % ); foreground: rgba ( 219, 223, 188, 100 % ); - normal-foreground: @foreground; + normal-foreground: var(foreground); alternate-normal-background: rgba ( 0, 0, 0, 0 % ); red: rgba ( 220, 50, 47, 100 % ); selected-urgent-foreground: rgba ( 2, 20, 63, 100 % ); @@ -16,7 +16,7 @@ selected-active-foreground: rgba ( 2, 20, 63, 100 % ); alternate-active-background: rgba ( 0, 0, 0, 0 % ); background: rgba ( 0, 0, 33, 87 % ); - alternate-normal-foreground: @foreground; + alternate-normal-foreground: var(foreground); normal-background: rgba ( 0, 0, 0, 0 % ); lightfg: rgba ( 88, 104, 117, 100 % ); selected-normal-background: rgba ( 219, 223, 188, 100 % ); @@ -25,14 +25,14 @@ separatorcolor: rgba ( 219, 223, 188, 100 % ); urgent-background: rgba ( 0, 0, 0, 0 % ); selected-urgent-background: rgba ( 255, 129, 127, 100 % ); - alternate-urgent-foreground: @urgent-foreground; + alternate-urgent-foreground: var(urgent-foreground); background-color: rgba ( 0, 0, 0, 0 % ); - alternate-active-foreground: @active-foreground; + alternate-active-foreground: var(active-foreground); active-background: rgba ( 0, 0, 0, 0 % ); selected-active-background: rgba ( 138, 196, 255, 100 % ); } window { - background-color: @background; + background-color: var(background); border: 1; padding: 5; } @@ -42,16 +42,16 @@ mainbox { } message { border: 2px 0px 0px ; - border-color: @separatorcolor; + border-color: var(separatorcolor); padding: 1px ; } textbox { - text-color: @foreground; + text-color: var(foreground); } listview { fixed-height: 0; border: 2px 0px 0px ; - border-color: @separatorcolor; + border-color: var(separatorcolor); spacing: 2px ; scrollbar: true; padding: 2px 0px 0px ; @@ -61,77 +61,77 @@ element { padding: 1px ; } element normal.normal { - background-color: @normal-background; - text-color: @normal-foreground; + background-color: var(normal-background); + text-color: var(normal-foreground); } element normal.urgent { - background-color: @urgent-background; - text-color: @urgent-foreground; + background-color: var(urgent-background); + text-color: var(urgent-foreground); } element normal.active { - background-color: @active-background; - text-color: @active-foreground; + background-color: var(active-background); + text-color: var(active-foreground); } element selected.normal { - background-color: @selected-normal-background; - text-color: @selected-normal-foreground; + background-color: var(selected-normal-background); + text-color: var(selected-normal-foreground); } element selected.urgent { - background-color: @selected-urgent-background; - text-color: @selected-urgent-foreground; + background-color: var(selected-urgent-background); + text-color: var(selected-urgent-foreground); } element selected.active { - background-color: @selected-active-background; - text-color: @selected-active-foreground; + background-color: var(selected-active-background); + text-color: var(selected-active-foreground); } element alternate.normal { - background-color: @alternate-normal-background; - text-color: @alternate-normal-foreground; + background-color: var(alternate-normal-background); + text-color: var(alternate-normal-foreground); } element alternate.urgent { - background-color: @alternate-urgent-background; - text-color: @alternate-urgent-foreground; + background-color: var(alternate-urgent-background); + text-color: var(alternate-urgent-foreground); } element alternate.active { - background-color: @alternate-active-background; - text-color: @alternate-active-foreground; + background-color: var(alternate-active-background); + text-color: var(alternate-active-foreground); } scrollbar { width: 4px ; border: 0; - handle-color: @normal-foreground; + handle-color: var(normal-foreground); handle-width: 8px ; padding: 0; } sidebar { border: 2px 0px 0px ; - border-color: @separatorcolor; + border-color: var(separatorcolor); } button { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } button selected { - background-color: @selected-normal-background; - text-color: @selected-normal-foreground; + background-color: var(selected-normal-background); + text-color: var(selected-normal-foreground); } inputbar { spacing: 0px ; - text-color: @normal-foreground; + text-color: var(normal-foreground); padding: 1px ; children: [ prompt,textbox-prompt-colon,entry,case-indicator ]; } case-indicator { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } entry { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } prompt { spacing: 0; - text-color: @normal-foreground; + text-color: var(normal-foreground); } textbox-prompt-colon { expand: false; @@ -141,5 +141,5 @@ textbox-prompt-colon { } error-message { background-color: rgba ( 0, 0, 0, 0 % ); - text-color: @normal-foreground; + text-color: var(normal-foreground); } diff --git a/include/rofi-types.h b/include/rofi-types.h index 46b01f1b..ae9ccf02 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -176,7 +176,7 @@ typedef enum WL_SOUTH_WEST = WL_SOUTH | WL_WEST, } WindowLocation; -typedef union +typedef union _PropertyValue { /** integer */ int i; @@ -197,6 +197,8 @@ typedef union char *name; /** Cached looked up ref */ struct Property *ref; + /** Property default */ + struct Property *def_value; } link; /** Highlight Style */ RofiHighlightColorStyle highlight; diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 385b28b8..d6a4c675 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -229,6 +229,8 @@ FORWARD_SLASH \/ LIST_OPEN \[ LIST_CLOSE \] +VAR_START "var" + CPP_COMMENT "//" C_COMMENT_OPEN "/*" @@ -241,6 +243,8 @@ CONFIGURATION (?i:configuration) %x INCLUDE %x PROPERTIES %x PROPERTIES_ENV +%x PROPERTIES_VAR +%x PROPERTIES_VAR_DEFAULT %x PROPERTIES_LIST %x NAMESTR %x SECTION @@ -419,30 +423,30 @@ if ( queue == NULL ){ /* After Namestr/Classstr we want to go to state str, then to { */ {WHITESPACE}+ ; // ignore all whitespace -{WHITESPACE}+ ; // ignore all whitespace +{WHITESPACE}+ ; // ignore all whitespace
":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return T_PSEP; } ";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return T_PCLOSE;} -(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} -{PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} -{PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} -{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;} +(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} +{PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} +{PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} +{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;} -@{WORD} { - yylval->sval = g_strdup(yytext); +@{WORD} { + yylval->sval = g_strdup(yytext+1); return T_LINK; } -{EM} { return T_UNIT_EM; } -{CH} { return T_UNIT_CH; } -{PX} { return T_UNIT_PX; } -{PERCENT} { return T_PERCENT; } -{LS_SOLID} { return T_SOLID; } -{LS_DASH} { return T_DASH; } +{EM} { return T_UNIT_EM; } +{CH} { return T_UNIT_CH; } +{PX} { return T_UNIT_PX; } +{PERCENT} { return T_PERCENT; } +{LS_SOLID} { return T_SOLID; } +{LS_DASH} { return T_DASH; } -{INHERIT} { return T_INHERIT; } +{INHERIT} { return T_INHERIT; } -{ENV} { +{ENV} { yytext[yyleng-1] = '\0'; const char *val = g_getenv(yytext+2); if ( val ) { @@ -468,54 +472,74 @@ if ( queue == NULL ){ * Color parsing. It is easier to do this at lexer level. * Other schemes are done at yacc level. */ -#{HEX}{8} { +#{HEX}{8} { yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[2]); yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[3],yytext[4]); yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[5],yytext[6]); yylval->colorval.alpha = rofi_theme_parse_convert_hex(yytext[7],yytext[8]); return T_COLOR; } -#{HEX}{6} { +#{HEX}{6} { yylval->colorval.alpha = 1.0; yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[2]); yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[3],yytext[4]); yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[5],yytext[6]); return T_COLOR; } -#{HEX}{3} { +#{HEX}{3} { yylval->colorval.alpha = 1.0; yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[1]); yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[2],yytext[2]); yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[3],yytext[3]); return T_COLOR; } -#{HEX}{4} { +#{HEX}{4} { yylval->colorval.alpha = rofi_theme_parse_convert_hex(yytext[4],yytext[4]); yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[1]); yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[2],yytext[2]); yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[3],yytext[3]); return T_COLOR; } -argb:{HEX}{8} { +argb:{HEX}{8} { yylval->colorval.alpha = rofi_theme_parse_convert_hex(yytext[5],yytext[6]); yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[7],yytext[8]); yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[9],yytext[10]); yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[11],yytext[12]); return T_COLOR; } -argb:{HEX}{7} { +argb:{HEX}{7} { return T_ERROR_ARGB_SPEC; } /* Color schemes */ -{RGBA} { return T_COL_RGBA; } -{HSL} { return T_COL_HSL; } -{HWB} { return T_COL_HWB; } -{CMYK} { return T_COL_CMYK; } +{RGBA} { return T_COL_RGBA; } +{HSL} { return T_COL_HSL; } +{HWB} { return T_COL_HWB; } +{CMYK} { return T_COL_CMYK; } /* Fluff */ +{VAR_START}{S_T_PARENT_LEFT} { + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(PROPERTIES_VAR); + return T_VAR_START; +} +{S_T_PARENT_RIGHT} { + BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); + return T_VAR_CLOSE; +} +{COMMA} { + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(PROPERTIES_VAR_DEFAULT); + return T_COMMA; +} +{S_T_PARENT_RIGHT} { + // Pop 2. + g_queue_pop_head ( queue ); + BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); + return T_VAR_CLOSE; +} {S_T_PARENT_LEFT} { return T_PARENT_LEFT; } {S_T_PARENT_RIGHT} { return T_PARENT_RIGHT; } -{COMMA} { return T_COMMA; } -{LIST_OPEN} { +{COMMA} { return T_COMMA; } +{LIST_OPEN} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_LIST); return T_LIST_OPEN; @@ -524,33 +548,33 @@ if ( queue == NULL ){ BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); return T_LIST_CLOSE; } -{FORWARD_SLASH} { return T_FORWARD_SLASH; } +{FORWARD_SLASH} { return T_FORWARD_SLASH; } /* Position */ -{CENTER} { return T_POS_CENTER; } -{EAST} { return T_POS_EAST; } -{WEST} { return T_POS_WEST; } -{SOUTH} { return T_POS_SOUTH; } -{NORTH} { return T_POS_NORTH; } +{CENTER} { return T_POS_CENTER; } +{EAST} { return T_POS_EAST; } +{WEST} { return T_POS_WEST; } +{SOUTH} { return T_POS_SOUTH; } +{NORTH} { return T_POS_NORTH; } /* Highlight style */ -{NONE} { return T_NONE; } -{BOLD} { return T_BOLD; } -{ITALIC} { return T_ITALIC; } -{UNDERLINE} { return T_UNDERLINE; } -{STRIKETHROUGH} { return T_STRIKETHROUGH; } -{SMALLCAPS} { return T_SMALLCAPS; } +{NONE} { return T_NONE; } +{BOLD} { return T_BOLD; } +{ITALIC} { return T_ITALIC; } +{UNDERLINE} { return T_UNDERLINE; } +{STRIKETHROUGH} { return T_STRIKETHROUGH; } +{SMALLCAPS} { return T_SMALLCAPS; } -{ANGLE_DEG} { return T_ANGLE_DEG; } -{ANGLE_RAD} { return T_ANGLE_RAD; } -{ANGLE_GRAD} { return T_ANGLE_GRAD; } -{ANGLE_TURN} { return T_ANGLE_TURN; } +{ANGLE_DEG} { return T_ANGLE_DEG; } +{ANGLE_RAD} { return T_ANGLE_RAD; } +{ANGLE_GRAD} { return T_ANGLE_GRAD; } +{ANGLE_TURN} { return T_ANGLE_TURN; } -{ORIENTATION_HORI} { return ORIENTATION_HORI; } -{ORIENTATION_VERT} { return ORIENTATION_VERT; } +{ORIENTATION_HORI} { return ORIENTATION_HORI; } +{ORIENTATION_VERT} { return ORIENTATION_VERT; } -{COLOR_TRANSPARENT} { +{COLOR_TRANSPARENT} { return T_COLOR_TRANSPARENT; } -{COLOR_NAME} { +{COLOR_NAME} { for ( unsigned int iter = 0; iter < num_CSSColors; iter++){ if ( strcasecmp(yytext, CSSColors[iter].name )== 0 ) { yylval->colorval.alpha = 1.0; @@ -563,7 +587,7 @@ if ( queue == NULL ){ REJECT; } -<> { +<> { ParseObject *po = g_queue_pop_head ( file_queue ); if ( po ) { if ( po->type == PT_FILE ){ @@ -610,7 +634,7 @@ if ( queue == NULL ){
. { return T_ERROR_SECTION; } -{WORD} { +{WORD} { yylval->sval = g_strdup(yytext); return T_ELEMENT; } @@ -620,7 +644,7 @@ if ( queue == NULL ){ return T_ELEMENT; } -. { +. { return T_ERROR_PROPERTY; } . { diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 0aa0d227..642d583c 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -199,6 +199,8 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_COL_HWB "hwb colorscheme" %token T_COL_CMYK "cmyk colorscheme" +%token T_VAR_START "Variable" +%token T_VAR_CLOSE "Variable close" %token T_PARENT_LEFT "Parent left ('(')" %token T_PARENT_RIGHT "Parent right (')')" %token T_COMMA "comma separator (',')" @@ -228,6 +230,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %type t_entry_name_path %type t_entry_name_path_selectors %type t_property +%type t_property_element %type t_property_list %type t_property_list_optional %type t_property_color @@ -361,85 +364,86 @@ t_property_list: ; t_property -: t_property_name T_PSEP T_INHERIT T_PCLOSE { - $$ = rofi_theme_property_create ( P_INHERIT ); - $$->name = $1; - } -| t_property_name T_PSEP T_INT T_PCLOSE { - $$ = rofi_theme_property_create ( P_INTEGER ); - $$->name = $1; - $$->value.i = $3; - } -| t_property_name T_PSEP T_DOUBLE T_PCLOSE { - $$ = rofi_theme_property_create ( P_DOUBLE ); - $$->name = $1; - $$->value.f = $3; - } -| t_property_name T_PSEP T_STRING T_PCLOSE { - $$ = rofi_theme_property_create ( P_STRING ); - $$->name = $1; - $$->value.s = $3; - } -| t_property_name T_PSEP T_LINK T_PCLOSE { +: t_property_name T_PSEP t_property_element T_PCLOSE { + $$ = $3; + $$->name = $1; + } +| t_property_name T_PSEP T_VAR_START T_ELEMENT T_VAR_CLOSE T_PCLOSE{ $$ = rofi_theme_property_create ( P_LINK ); $$->name = $1; - $$->value.link.name = $3; + $$->value.link.name = $4; } -| t_property_name T_PSEP T_BOOLEAN T_PCLOSE { +| t_property_name T_PSEP T_VAR_START T_ELEMENT T_COMMA t_property_element T_VAR_CLOSE T_PCLOSE{ + $$ = rofi_theme_property_create ( P_LINK ); + $$->name = $1; + $$->value.link.name = $4; + $$->value.link.def_value = $6; + } + +t_property_element +: T_INHERIT { + $$ = rofi_theme_property_create ( P_INHERIT ); + } +| T_INT { + $$ = rofi_theme_property_create ( P_INTEGER ); + $$->value.i = $1; + } +| T_DOUBLE { + $$ = rofi_theme_property_create ( P_DOUBLE ); + $$->value.f = $1; + } +| T_STRING { + $$ = rofi_theme_property_create ( P_STRING ); + $$->value.s = $1; + } +| T_LINK { + $$ = rofi_theme_property_create ( P_LINK ); + $$->value.link.name = $1; + } +| T_BOOLEAN { $$ = rofi_theme_property_create ( P_BOOLEAN ); - $$->name = $1; - $$->value.b = $3; + $$->value.b = $1; } -| t_property_name T_PSEP t_property_distance T_PCLOSE { +| t_property_distance { $$ = rofi_theme_property_create ( P_PADDING ); - $$->name = $1; - $$->value.padding = (RofiPadding){ $3, $3, $3, $3 }; + $$->value.padding = (RofiPadding){ $1, $1, $1, $1 }; } -| t_property_name T_PSEP t_property_distance_zero t_property_distance_zero T_PCLOSE { +| t_property_distance_zero t_property_distance_zero { $$ = rofi_theme_property_create ( P_PADDING ); - $$->name = $1; - $$->value.padding = (RofiPadding){ $3, $4, $3, $4 }; + $$->value.padding = (RofiPadding){ $1, $2, $1, $2 }; } -| t_property_name T_PSEP t_property_distance_zero t_property_distance_zero t_property_distance_zero T_PCLOSE { +| t_property_distance_zero t_property_distance_zero t_property_distance_zero { $$ = rofi_theme_property_create ( P_PADDING ); - $$->name = $1; - $$->value.padding = (RofiPadding){ $3, $4, $5, $4 }; + $$->value.padding = (RofiPadding){ $1, $2, $3, $2 }; } -| t_property_name T_PSEP t_property_distance_zero t_property_distance_zero t_property_distance_zero t_property_distance_zero T_PCLOSE { +| t_property_distance_zero t_property_distance_zero t_property_distance_zero t_property_distance_zero { $$ = rofi_theme_property_create ( P_PADDING ); - $$->name = $1; - $$->value.padding = (RofiPadding){ $3, $4, $5, $6 }; + $$->value.padding = (RofiPadding){ $1, $2, $3, $4 }; } -| t_property_name T_PSEP t_property_position T_PCLOSE{ +| t_property_position { $$ = rofi_theme_property_create ( P_POSITION ); - $$->name = $1; - $$->value.i = $3; + $$->value.i = $1; } -| t_property_name T_PSEP t_property_highlight_styles t_property_color T_PCLOSE { +| t_property_highlight_styles t_property_color { $$ = rofi_theme_property_create ( P_HIGHLIGHT ); - $$->name = $1; - $$->value.highlight.style = $3|ROFI_HL_COLOR; - $$->value.highlight.color = $4; + $$->value.highlight.style = $1|ROFI_HL_COLOR; + $$->value.highlight.color = $2; } -| t_property_name T_PSEP t_property_highlight_styles T_PCLOSE { +| t_property_highlight_styles { $$ = rofi_theme_property_create ( P_HIGHLIGHT ); - $$->name = $1; - $$->value.highlight.style = $3; + $$->value.highlight.style = $1; } -| t_property_name T_PSEP t_property_color T_PCLOSE { +| t_property_color { $$ = rofi_theme_property_create ( P_COLOR ); - $$->name = $1; - $$->value.color = $3; + $$->value.color = $1; } -| t_property_name T_PSEP T_LIST_OPEN t_property_element_list_optional T_LIST_CLOSE T_PCLOSE { +| T_LIST_OPEN t_property_element_list_optional T_LIST_CLOSE { $$ = rofi_theme_property_create ( P_LIST ); - $$->name = $1; - $$->value.list = $4; + $$->value.list = $2; } -| t_property_name T_PSEP t_property_orientation T_PCLOSE { +| t_property_orientation { $$ = rofi_theme_property_create ( P_ORIENTATION ); - $$->name = $1; - $$->value.i = $3; + $$->value.i = $1; } ; diff --git a/source/theme.c b/source/theme.c index a02344cf..98cb74f0 100644 --- a/source/theme.c +++ b/source/theme.c @@ -91,6 +91,9 @@ Property* rofi_theme_property_copy ( Property *p ) case P_LINK: retv->value.link.name = g_strdup ( p->value.link.name ); retv->value.link.ref = NULL; + if ( p->value.link.def_value ){ + retv->value.link.def_value = rofi_theme_property_copy(p->value.link.def_value); + } break; default: retv->value = p->value; @@ -109,6 +112,9 @@ void rofi_theme_property_free ( Property *p ) } else if ( p->type == P_LINK ) { g_free ( p->value.link.name ); + if ( p->value.link.def_value ) { + rofi_theme_property_free ( p->value.link.def_value ); + } } g_slice_free ( Property, p ); } @@ -176,103 +182,114 @@ const char * const WindowLocationStr[9] = { "west" }; +static void int_rofi_theme_print_property ( Property *p ) +{ + switch ( p->type ) + { + case P_LIST: + printf ( "[ " ); + for ( GList *iter = p->value.list; iter != NULL; iter = g_list_next ( iter ) ) { + printf ( "%s", (char *) ( iter->data ) ); + if ( iter->next != NULL ) { + printf ( "," ); + } + } + printf ( " ]" ); + break; + case P_ORIENTATION: + printf ( "%s", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" ); + break; + case P_HIGHLIGHT: + if ( p->value.highlight.style & ROFI_HL_BOLD ) { + printf ( "bold " ); + } + if ( p->value.highlight.style & ROFI_HL_UNDERLINE ) { + printf ( "underline " ); + } + if ( p->value.highlight.style & ROFI_HL_STRIKETHROUGH ) { + printf ( "strikethrough " ); + } + if ( p->value.highlight.style & ROFI_HL_ITALIC ) { + printf ( "italic " ); + } + if ( p->value.highlight.style & ROFI_HL_COLOR ) { + printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", + ( p->value.highlight.color.red * 255.0 ), + ( p->value.highlight.color.green * 255.0 ), + ( p->value.highlight.color.blue * 255.0 ), + ( p->value.highlight.color.alpha * 100.0 ) ); + } + break; + case P_POSITION: + printf ( "%s", WindowLocationStr[p->value.i] ); + break; + case P_STRING: + printf ( "\"%s\"", p->value.s ); + break; + case P_INTEGER: + printf ( "%d", p->value.i ); + break; + case P_DOUBLE: + printf ( "%.2f", p->value.f ); + break; + case P_BOOLEAN: + printf ( "%s", p->value.b ? "true" : "false" ); + break; + case P_COLOR: + printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", + ( p->value.color.red * 255.0 ), + ( p->value.color.green * 255.0 ), + ( p->value.color.blue * 255.0 ), + ( p->value.color.alpha * 100.0 ) ); + break; + case P_PADDING: + 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.top ) ) { + rofi_theme_print_distance ( p->value.padding.left ); + } + else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && + 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.left ); + } + else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) && + 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.left ); + rofi_theme_print_distance ( p->value.padding.bottom ); + } + else { + rofi_theme_print_distance ( p->value.padding.top ); + rofi_theme_print_distance ( p->value.padding.right ); + rofi_theme_print_distance ( p->value.padding.bottom ); + rofi_theme_print_distance ( p->value.padding.left ); + } + break; + case P_LINK: + if ( p->value.link.def_value) { + printf( "var( %s, ", p->value.link.name ); + int_rofi_theme_print_property ( p->value.link.def_value ); + printf (")"); + }else { + printf ( "var(%s)", p->value.link.name ); + } + break; + case P_INHERIT: + printf ( "inherit" ); + break; + default: + break; + } + +} + static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p ) { int pl = strlen ( p->name ); printf ( "%*s%s:%*s ", depth, "", p->name, (int) pnl - pl, "" ); - switch ( p->type ) - { - case P_LIST: - printf ( "[ " ); - for ( GList *iter = p->value.list; iter != NULL; iter = g_list_next ( iter ) ) { - printf ( "%s", (char *) ( iter->data ) ); - if ( iter->next != NULL ) { - printf ( "," ); - } - } - printf ( " ];" ); - break; - case P_ORIENTATION: - printf ( "%s;", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" ); - break; - case P_HIGHLIGHT: - if ( p->value.highlight.style & ROFI_HL_BOLD ) { - printf ( "bold " ); - } - if ( p->value.highlight.style & ROFI_HL_UNDERLINE ) { - printf ( "underline " ); - } - if ( p->value.highlight.style & ROFI_HL_STRIKETHROUGH ) { - printf ( "strikethrough " ); - } - if ( p->value.highlight.style & ROFI_HL_ITALIC ) { - printf ( "italic " ); - } - if ( p->value.highlight.style & ROFI_HL_COLOR ) { - printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", - ( p->value.highlight.color.red * 255.0 ), - ( p->value.highlight.color.green * 255.0 ), - ( p->value.highlight.color.blue * 255.0 ), - ( p->value.highlight.color.alpha * 100.0 ) ); - } - printf ( ";" ); - break; - case P_POSITION: - printf ( "%s;", WindowLocationStr[p->value.i] ); - break; - case P_STRING: - printf ( "\"%s\";", p->value.s ); - break; - case P_INTEGER: - printf ( "%d;", p->value.i ); - break; - case P_DOUBLE: - printf ( "%.2f;", p->value.f ); - break; - case P_BOOLEAN: - printf ( "%s;", p->value.b ? "true" : "false" ); - break; - case P_COLOR: - printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% );", - ( p->value.color.red * 255.0 ), - ( p->value.color.green * 255.0 ), - ( p->value.color.blue * 255.0 ), - ( p->value.color.alpha * 100.0 ) ); - break; - case P_PADDING: - 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.top ) ) { - rofi_theme_print_distance ( p->value.padding.left ); - } - else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && - 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.left ); - } - else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) && - 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.left ); - rofi_theme_print_distance ( p->value.padding.bottom ); - } - else { - rofi_theme_print_distance ( p->value.padding.top ); - rofi_theme_print_distance ( p->value.padding.right ); - rofi_theme_print_distance ( p->value.padding.bottom ); - rofi_theme_print_distance ( p->value.padding.left ); - } - printf ( ";" ); - break; - case P_LINK: - printf ( "%s;", p->value.link.name ); - break; - case P_INHERIT: - printf ( "inherit;" ); - break; - default: - break; - } + int_rofi_theme_print_property ( p ); + putchar ( ';' ); putchar ( '\n' ); } @@ -439,7 +456,8 @@ static ThemeWidget *rofi_theme_find ( ThemeWidget *widget, const char *name, con static void rofi_theme_resolve_link_property ( Property *p, int depth ) { // Set name, remove '@' prefix. - const char *name = p->value.link.name + 1; + const char *name = p->value.link.name;// + (*(p->value.link.name)== '@'?1:0; + g_info ( "Resolving link to %s", p->value.link.name); if ( depth > 20 ) { g_warning ( "Found more then 20 redirects for property. Stopping." ); p->value.link.ref = p; @@ -448,6 +466,7 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth ) if ( rofi_theme->properties && g_hash_table_contains ( rofi_theme->properties, name ) ) { Property *pr = g_hash_table_lookup ( rofi_theme->properties, name ); + g_info ("Resolving link %s found: %s", p->value.link.name, pr->name); if ( pr->type == P_LINK ) { if ( pr->value.link.ref == NULL ) { rofi_theme_resolve_link_property ( pr, depth + 1 ); @@ -462,6 +481,11 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth ) return; } } + // No found and we have default value. + if ( p->value.link.def_value ){ + p->value.link.ref = p->value.link.def_value; + return; + } // No found, set ref to self. p->value.link.ref = p;