29#define G_LOG_DOMAIN "Theme"
42#include "theme-parser.h"
65 printf(
"\nParsed files:\n");
67 iter = g_list_next(iter)) {
68 printf(
"\t\u2023 %s%s%s\n", is_term ?
color_bold :
"",
69 (
const char *)(iter->data), is_term ?
color_reset :
"");
74void yyerror(YYLTYPE *yylloc,
const char *,
const char *);
83 for (
unsigned int i = 0; i < base->
num_widgets; i++) {
94 retv->
name = g_strdup(name);
132 G_GNUC_UNUSED
void *data) {
169 l = g_list_next(l)) {
251 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
263 char buf[G_ASCII_DTOSTR_BUF_SIZE + 1] = {
266 g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE,
"%.4f", d);
279 fputs(
" + ", stdout);
281 fputs(
" - ", stdout);
283 fputs(
" / ", stdout);
285 fputs(
" * ", stdout);
287 fputs(
" modulo ", stdout);
289 fputs(
" min ", stdout);
291 fputs(
" max ", stdout);
293 fputs(
" round ", stdout);
295 fputs(
" floor ", stdout);
297 fputs(
" ceil ", stdout);
305 printf(
"%upx ", (
unsigned int)unit->
distance);
308 fputs(
"mm ", stdout);
314 fputs(
"ch ", stdout);
317 fputs(
"em ", stdout);
327 g = 255 * color.
green;
329 b = 255 * color.
blue;
330 if (color.
alpha < 0.00001) {
331 printf(
"transparent");
337 if (color.
alpha < 1) {
338 printf(
"/%.0f%%", color.
alpha * 100.0);
343 printf(
"rgba ( %.0f, %.0f, %.0f, %.0f %% )", (color.
red * 255.0),
344 (color.
green * 255.0), (color.
blue * 255.0), (color.
alpha * 100.0));
348 fputs(
"calc( ", stdout);
369 for (GList *iter = p->
value.
list; iter != NULL; iter = g_list_next(iter)) {
371 if (iter->next != NULL) {
389 printf(
"underline ");
392 printf(
"strikethrough ");
398 printf(
"uppercase ");
401 printf(
"lowercase ");
404 printf(
"capitalize ");
413 fputs(
"center", stdout);
416 fputs(
"north", stdout);
419 fputs(
"south", stdout);
422 fputs(
"west", stdout);
425 fputs(
"east", stdout);
428 fputs(
"northeast", stdout);
431 fputs(
"southeast", stdout);
434 fputs(
"northwest", stdout);
437 fputs(
"southwest", stdout);
443 printf(
"\"%s\"", p->
value.
s);
449 char sign = (p->
value.
f < 0);
450 int top = (int)fabs(p->
value.
f);
451 int bottom = (fabs(fmod(p->
value.
f, 1.0))) * 100;
452 printf(
"%s%d.%02d", sign ?
"-" :
"", top, bottom);
456 printf(
"%s", p->
value.
b ?
"true" :
"false");
463 printf(
"url (\"%s\")", p->
value.
s);
465 printf(
"linear-gradient ( ");
469 l = g_list_next(l)) {
473 if (index < length) {
526 int pl = strlen(p->
name);
527 printf(
"%*s%s:%*s ", cur_depth,
"", p->
name, (
int)pnl - pl,
"");
538 printf(
"%s {\n", wid->
name);
539 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
548 if (g_strcmp0(w->
name,
"Root") == 0) {
554 list = g_list_prepend(list, w->
name);
557 if (g_list_length(list) > 0) {
558 printf(
"%*s", index,
"");
559 for (GList *citer = g_list_first(list); citer != NULL;
560 citer = g_list_next(citer)) {
561 char *name = (
char *)citer->data;
563 if (citer->prev == NULL && citer->next) {
565 }
else if (citer->next) {
571 printf(
"%*s* {\n", index,
"");
573 size_t property_name_length = 0;
574 g_hash_table_iter_init(&iter, wid->
properties);
575 while (g_hash_table_iter_next(&iter, &key, &value)) {
577 property_name_length = MAX(strlen(pv->
name), property_name_length);
579 g_hash_table_iter_init(&iter, wid->
properties);
580 while (g_hash_table_iter_next(&iter, &key, &value)) {
584 printf(
"%*s}\n", index,
"");
587 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
595 printf(
"/**\n * rofi -dump-theme output.\n * Rofi version: %s\n **/\n",
618void yyerror(YYLTYPE *yylloc,
const char *what,
const char *s) {
619 char *what_esc = what ? g_markup_escape_text(what, -1) : g_strdup(
"");
620 GString *str = g_string_new(
"");
622 "<big><b>Error while parsing theme:</b></big> <i>%s</i>\n",
625 char *esc = g_markup_escape_text(s, -1);
626 g_string_append_printf(
628 "\tParser error: <span size=\"smaller\" style=\"italic\">%s</span>\n",
631 if (yylloc->filename != NULL) {
632 g_string_append_printf(
634 "\tLocation: line %d column %d to line %d column %d.\n"
636 yylloc->first_line, yylloc->first_column, yylloc->last_line,
637 yylloc->last_column, yylloc->filename);
639 g_string_append_printf(
640 str,
"\tLocation: line %d column %d to line %d column %d\n",
641 yylloc->first_line, yylloc->first_column, yylloc->last_line,
642 yylloc->last_column);
644 g_log(
"Parser", G_LOG_LEVEL_DEBUG,
"Failed to parse theme:\n%s", str->str);
649 gpointer value, gpointer user_data) {
650 GHashTable *table = (GHashTable *)user_data;
652 g_hash_table_replace(table, p->
name, p);
660 g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
672 for (
unsigned int j = 0; wid && j < wid->
num_widgets; j++) {
681 const gboolean exact) {
682 if (wid == NULL || name == NULL) {
685 char *tname = g_strdup(name);
686 char *saveptr = NULL;
688 for (
const char *iter = strtok_r(tname,
".", &saveptr); iter != NULL;
689 iter = strtok_r(NULL,
".", &saveptr)) {
700 if (!exact || found) {
710 if (cur_depth > 20) {
711 g_warning(
"Found more then 20 redirects for property. Stopping.");
717 g_hash_table_contains(
rofi_theme->properties, name)) {
744 const char *property, gboolean exact) {
760 if (p->
type == type) {
767 g_debug(
"Found property: '%s' on '%s', but type %s does not match "
798 const char *property,
int def) {
812 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
822 const char *property,
int def) {
836 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
847 const char *property,
869 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
883 const char *property,
int def) {
897 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
909 const char *property,
925 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
930 const char *property,
940 const char *property,
956 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
961 const char *property,
968 const char *property,
983 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
996 const char *property,
1012 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1018 const char *property,
double def) {
1045 const char *property, cairo_t *d) {
1060 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1072 const char *property, cairo_t *d) {
1112 cairo_pattern_t *pat = cairo_pattern_create_for_surface(img);
1113 cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
1114 cairo_set_source(d, pat);
1115 cairo_pattern_destroy(pat);
1119 cairo_pattern_t *pat = NULL;
1122 pat = cairo_pattern_create_linear(0.0, 0.0, wid->
w, 0.0);
1125 pat = cairo_pattern_create_linear(wid->
w, 0.0, 0.0, 0.0);
1128 pat = cairo_pattern_create_linear(0.0, 0.0, 0.0, wid->
h);
1131 pat = cairo_pattern_create_linear(0.0, wid->
h, 0.0, 0.0);
1136 pat = cairo_pattern_create_linear(
1137 wid->
w / 2.0 - offsetx1, wid->
h / 2.0 - offsety1,
1138 wid->
w / 2.0 + offsetx1, wid->
h / 2.0 + offsety1);
1145 guint color_index = 0;
1147 l = g_list_next(l)) {
1149 cairo_pattern_add_color_stop_rgba(pat, (color_index) / (
double)length,
1154 cairo_set_source(d, pat);
1155 cairo_pattern_destroy(pat);
1160 cairo_pattern_add_color_stop_rgba(pat, 0, c->
red, c->
green, c->
blue,
1162 cairo_set_source(d, pat);
1163 cairo_pattern_destroy(pat);
1168 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1180 const char *property,
1203 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1215 const char *property,
1238 for (GList *iter = g_list_first(list); iter != NULL;
1239 iter = g_list_next(iter)) {
1244 retv = g_list_append(retv, pnew);
1252 retv = g_list_append(retv, pnew);
1254 g_warning(
"Invalid type detected in list.");
1264 for (GList *iter = g_list_first(list); iter != NULL;
1265 iter = g_list_next(iter)) {
1268 retv = g_list_append(retv, g_strdup(prop->
value.
s));
1270 g_warning(
"Invalid type detected in list.");
1305 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1310 const char *property,
1331 val = (unit->
distance * height) / (100.0);
1335 val = (unit->
distance * width) / (100.0);
1387 return (
double)(round(a / b) * b);
1392 return (
double)(ceil(a / b) * b);
1397 return (
double)(floor(a / b) * b);
1411 const double dashes[1] = {4};
1412 cairo_set_dash(draw, dashes, 1, 0.0);
1414 cairo_set_dash(draw, NULL, 0, 0.0);
1419 char *filename = g_strdup(file);
1421 GFile *gf = g_file_new_for_path(filename);
1423 filename = g_file_get_path(gf);
1430 g_assert(parent != NULL);
1431 g_assert(child != NULL);
1444 for (
unsigned int i = 0; i < child->
num_widgets; i++) {
1451 if (rwidget == NULL) {
1456 while (i < rwidget->num_widgets) {
1458 if (child_widget->
media != NULL) {
1460 for (
unsigned x = i; x < rwidget->
num_widgets; x++) {
1468 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1477 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1486 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1496 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1504 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1512 if ((
mon.w / (
double)
mon.h) >= r) {
1513 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1521 if ((
mon.w / (
double)
mon.h) < r) {
1522 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1530 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1551 GString *str = g_string_new(wid->
name);
1553 g_string_prepend_c(str,
' ');
1554 g_string_prepend(str, i->name);
1556 char *retv = str->str;
1557 g_string_free(str, FALSE);
1566 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
1572 GHashTableIter iter;
1573 gpointer key, value;
1574 g_hash_table_iter_init(&iter, child_widget->
properties);
1575 while (g_hash_table_iter_next(&iter, &key, &value)) {
1582 GString *str = g_string_new(NULL);
1583 g_string_printf(str,
1584 "Validating the theme failed: the variable '%s' in "
1585 "`%s { %s: var(%s);}` failed to resolve.",
1609 if (g_strcmp0(type,
"monitor-id") == 0) {
1612 if (g_strcmp0(type,
"min-width") == 0) {
1615 if (g_strcmp0(type,
"min-height") == 0) {
1618 if (g_strcmp0(type,
"max-width") == 0) {
1621 if (g_strcmp0(type,
"max-height") == 0) {
1624 if (g_strcmp0(type,
"min-aspect-ratio") == 0) {
1627 if (g_strcmp0(type,
"max-aspect-ratio") == 0) {
1630 if (g_strcmp0(type,
"enabled") == 0) {
1638 const char *property) {
const unsigned int num_CSSColors
const CSSColor CSSColors[]
Property * rofi_theme_find_property(ThemeWidget *wid, PropertyType type, const char *property, gboolean exact)
ThemeWidget * rofi_config_find_widget(const char *name, const char *state, gboolean exact)
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize, const int hsize)
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
void rofi_add_error_message(GString *str)
void rofi_add_warning_message(GString *str)
double textbox_get_estimated_char_height(void)
double textbox_get_estimated_ch(void)
void rofi_view_get_current_monitor(int *width, int *height)
const char *const PropertyTypeName[P_NUM_TYPES]
@ THEME_MEDIA_TYPE_MAX_HEIGHT
@ THEME_MEDIA_TYPE_MON_ID
@ THEME_MEDIA_TYPE_INVALID
@ THEME_MEDIA_TYPE_MIN_WIDTH
@ THEME_MEDIA_TYPE_MIN_ASPECT_RATIO
@ THEME_MEDIA_TYPE_BOOLEAN
@ THEME_MEDIA_TYPE_MAX_ASPECT_RATIO
@ THEME_MEDIA_TYPE_MAX_WIDTH
@ THEME_MEDIA_TYPE_MIN_HEIGHT
@ ROFI_IMAGE_LINEAR_GRADIENT
@ ROFI_ORIENTATION_HORIZONTAL
@ ROFI_ORIENTATION_VERTICAL
@ ROFI_DISTANCE_MODIFIER_GROUP
@ ROFI_DISTANCE_MODIFIER_CEIL
@ ROFI_DISTANCE_MODIFIER_SUBTRACT
@ ROFI_DISTANCE_MODIFIER_MODULO
@ ROFI_DISTANCE_MODIFIER_FLOOR
@ ROFI_DISTANCE_MODIFIER_ROUND
@ ROFI_DISTANCE_MODIFIER_MULTIPLY
@ ROFI_DISTANCE_MODIFIER_MAX
@ ROFI_DISTANCE_MODIFIER_MIN
@ ROFI_DISTANCE_MODIFIER_DIVIDE
@ ROFI_DISTANCE_MODIFIER_ADD
@ ROFI_DISTANCE_MODIFIER_NONE
RofiDistanceModifier modtype
struct RofiDistanceUnit * right
struct RofiDistanceUnit * left
int rofi_theme_get_integer(const widget *wid, const char *property, int def)
ThemeWidget * rofi_theme_find_or_create_name(ThemeWidget *base, const char *name)
void rofi_theme_free_parsed_files(void)
GList * parsed_config_files
const char *const RofiCursorTypeStr[3]
RofiHighlightColorStyle rofi_theme_get_highlight(widget *wid, const char *property, RofiHighlightColorStyle th)
int rofi_theme_get_position(const widget *wid, const char *property, int def)
static void int_rofi_theme_print_property(Property *p)
void rofi_theme_print_parsed_files(gboolean is_term)
void rofi_theme_print(ThemeWidget *wid)
static int rofi_theme_get_boolean_inside(Property *p, const widget *wid, const char *property, int def)
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
static GList * rofi_theme_get_list_inside(Property *p, const widget *wid, const char *property, PropertyType child_type)
void rofi_theme_parse_process_links(void)
double rofi_theme_get_double(const widget *wid, const char *property, double def)
gboolean rofi_theme_get_image(const widget *wid, const char *property, cairo_t *d)
static void rofi_theme_parse_process_links_int(ThemeWidget *wid)
static const char * rofi_theme_get_string_inside(Property *p, const widget *wid, const char *property, const char *def)
static ThemeWidget * rofi_theme_find(ThemeWidget *wid, const char *name, const gboolean exact)
static RofiCursorType rofi_theme_get_cursor_type_inside(Property *p, const widget *wid, const char *property, RofiCursorType def)
static double rofi_theme_get_double_integer_fb_inside(Property *p, const widget *wid, const char *property, double def)
static gboolean distance_compare(RofiDistance d, RofiDistance e)
void rofi_theme_parse_process_conditionals(void)
static double get_pixels(RofiDistanceUnit *unit, RofiOrientation ori)
void rofi_theme_free(ThemeWidget *wid)
static gboolean rofi_theme_has_property_inside(Property *p, const widget *wid_in, const char *property)
static void rofi_theme_print_distance_unit(RofiDistanceUnit *unit)
static void rofi_theme_copy_property_int(G_GNUC_UNUSED gpointer key, gpointer value, gpointer user_data)
static void rofi_theme_distance_property_free(RofiDistance *distance)
static RofiHighlightColorStyle rofi_theme_get_highlight_inside(Property *p, widget *wid, const char *property, RofiHighlightColorStyle th)
int rofi_theme_get_boolean(const widget *wid, const char *property, int def)
GList * rofi_theme_get_list_distance(const widget *wid, const char *property)
static int rofi_theme_get_integer_inside(Property *p, const widget *wid, const char *property, int def)
Property * rofi_theme_property_create(PropertyType type)
ThemeMediaType rofi_theme_parse_media_type(const char *type)
RofiCursorType rofi_theme_get_cursor_type(const widget *wid, const char *property, RofiCursorType def)
gboolean rofi_theme_has_property(const widget *wid_in, const char *property)
static void rofi_theme_print_distance(RofiDistance d)
static double rofi_theme_get_double_inside(const widget *orig, Property *p, const widget *wid, const char *property, double def)
static RofiDistanceUnit * rofi_theme_property_copy_distance_unit(RofiDistanceUnit *unit)
char * rofi_theme_parse_prepare_file(const char *file)
static void rofi_theme_get_color_inside(const widget *wid, Property *p, const char *property, cairo_t *d)
static gboolean rofi_theme_get_image_inside(Property *p, const widget *wid, const char *property, cairo_t *d)
static void printf_double(double d)
static void rofi_theme_print_property_index(size_t pnl, int cur_depth, Property *p)
static char * rofi_theme_widget_get_name(ThemeWidget *wid)
void rofi_theme_reset(void)
void rofi_theme_parse_merge_widgets(ThemeWidget *parent, ThemeWidget *child)
static void rofi_theme_distance_unit_property_free(RofiDistanceUnit *unit)
static RofiOrientation rofi_theme_get_orientation_inside(Property *p, const widget *wid, const char *property, RofiOrientation def)
static int rofi_theme_get_position_inside(Property *p, const widget *wid, const char *property, int def)
static void rofi_theme_print_color(ThemeColor color)
RofiOrientation rofi_theme_get_orientation(const widget *wid, const char *property, RofiOrientation def)
RofiDistance rofi_theme_get_distance(const widget *wid, const char *property, int def)
static ThemeWidget * rofi_theme_find_single(ThemeWidget *wid, const char *name)
void rofi_theme_print_index(ThemeWidget *wid, int index)
RofiPadding rofi_theme_get_padding(const widget *wid, const char *property, RofiPadding pad)
ThemeWidget * rofi_theme_find_widget(const char *name, const char *state, gboolean exact)
Property * rofi_theme_property_copy(const Property *p, G_GNUC_UNUSED void *data)
static RofiDistance rofi_theme_get_distance_inside(Property *p, const widget *wid, const char *property, int def)
static double distance_unit_get_pixel(RofiDistanceUnit *unit, RofiOrientation ori)
static void rofi_theme_parse_process_conditionals_int(workarea mon, ThemeWidget *rwidget)
void rofi_theme_get_color(const widget *wid, const char *property, cairo_t *d)
static RofiPadding rofi_theme_get_padding_inside(Property *p, const widget *wid, const char *property, RofiPadding pad)
GList * rofi_theme_get_list_strings(const widget *wid, const char *property)
const char * rofi_theme_get_string(const widget *wid, const char *property, const char *def)
void yyerror(YYLTYPE *yylloc, const char *, const char *)
RofiDistance rofi_theme_property_copy_distance(RofiDistance const distance)
void rofi_theme_property_free(Property *p)
static void rofi_theme_resolve_link_property(Property *p, int cur_depth)
void distance_get_linestyle(RofiDistance d, cairo_t *draw)
void rofi_theme_widget_add_properties(ThemeWidget *wid, GHashTable *table)
RofiHighlightColorStyle highlight
struct Property * def_value
struct _PropertyValue::@177257320242313332105321213366232047010330373373 link
int monitor_active(workarea *mon)
struct _workarea workarea
ThemeWidget * rofi_configuration