Skip to content

Commit b0e758e

Browse files
committed
[Theme] add alpha override support to references and hex colors.
this adds support for the syntax `@color / 50%;` and `#123456 / 50%` to override the alpha of a given color. - extended grammar rules for `t_property_element` and `t_property_color` - added `gboolean` member to link `union` to differentiate modified links from normal links - added definition of `rofi_theme_resolve_modified_link()` - added implementation of modified link resolving in `rofi_theme_parse_process_links_int()`
1 parent c2fd6a7 commit b0e758e

5 files changed

Lines changed: 40 additions & 2 deletions

File tree

doc/rofi-theme.5.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ some of CSS 4)
484484

485485
- Format: `{named-color} [ / {PERCENTAGE} ]`
486486

487+
- Format: `#{HEX} [ / {PERCENTAGE} ]`
488+
489+
- Format: `@{color-reference} [ / {PERCENTAGE} ]`
490+
487491
The white-space format proposed in CSS4 is also supported.
488492

489493
The different values are:

include/rofi-types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ typedef union _PropertyValue {
268268
struct {
269269
/** Name */
270270
char *name;
271+
/** Is modified link */
272+
gboolean modified;
271273
/** Cached looked up ref */
272274
struct Property *ref;
273275
/** Property default */

include/theme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,7 @@ typedef guint (*disp_scale_func)(void);
417417
* depending on the display library
418418
*/
419419
void rofi_theme_set_disp_scale_func(disp_scale_func func);
420+
421+
void rofi_theme_resolve_modified_link(Property*);
422+
420423
#endif

lexer/theme-parser.y

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ t_property_element
570570
$$ = rofi_theme_property_create ( P_LINK );
571571
$$->value.link.name = $1;
572572
}
573+
/** @color_reference / 0-100% */
574+
| T_LINK T_FORWARD_SLASH t_property_color_value_unit {
575+
$$ = rofi_theme_property_create ( P_COLOR );
576+
$$->value.link.name = $1;
577+
$$->value.color.alpha = $3;
578+
$$->value.link.modified = TRUE;
579+
}
573580
| T_BOOLEAN {
574581
$$ = rofi_theme_property_create ( P_BOOLEAN );
575582
$$->value.b = $1;
@@ -999,16 +1006,17 @@ t_property_color
9991006
$$.alpha = $8;
10001007
}
10011008
/** Hex colors parsed by lexer. */
1002-
| T_COLOR {
1009+
| T_COLOR t_property_color_opt_alpha_ws {
10031010
$$ = $1;
1011+
$$.alpha = $2;
10041012
}
10051013
| T_COLOR_TRANSPARENT {
10061014
$$.alpha = 0.0;
10071015
$$.red = $$.green = $$.blue = 0.0;
10081016
}
10091017
| T_COLOR_NAME t_property_color_opt_alpha_ws {
10101018
$$ = $1;
1011-
$$.alpha = $2;
1019+
$$.alpha = $2;
10121020
}
10131021
;
10141022
t_property_color_opt_alpha_c

source/theme.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,18 @@ static void rofi_theme_parse_process_links_int(ThemeWidget *wid) {
15921592
}
15931593
}
15941594
}
1595+
if (pv->type == P_COLOR && pv->value.link.modified == 1) {
1596+
if (pv->value.link.ref == NULL) {
1597+
rofi_theme_resolve_modified_link(pv);
1598+
if (pv->value.link.ref && pv->value.link.ref->type == P_COLOR) {
1599+
ThemeColor referenced_color = pv->value.link.ref->value.color;
1600+
referenced_color.alpha = pv->value.color.alpha;
1601+
pv->value.color = referenced_color;
1602+
} else {
1603+
g_warning("Reference in alpha overriding does not point to color.");
1604+
}
1605+
}
1606+
}
15951607
}
15961608
}
15971609
}
@@ -1660,3 +1672,12 @@ gboolean rofi_theme_has_property(const widget *wid_in, const PropertyType type,
16601672
}
16611673

16621674
void rofi_theme_set_disp_scale_func(disp_scale_func func) { disp_scale = func; }
1675+
1676+
void rofi_theme_resolve_modified_link(Property* p) {
1677+
g_info("Resolving modified link to %s", p->value.link.name);
1678+
Property* temp_link = rofi_theme_property_create(P_LINK);
1679+
temp_link->value.link.name = p->value.link.name;
1680+
rofi_theme_resolve_link_property(temp_link, 0);
1681+
p->value.link.ref = temp_link->value.link.ref;
1682+
rofi_theme_property_free(temp_link);
1683+
}

0 commit comments

Comments
 (0)