29#define G_LOG_DOMAIN "Theme"
43#include "theme-parser.h"
67 printf(
"\nParsed files:\n");
69 iter = g_list_next(iter)) {
70 printf(
"\t\u2023 %s%s%s\n", is_term ?
color_bold :
"",
71 (
const char *)(iter->data), is_term ?
color_reset :
"");
76void yyerror(YYLTYPE *yylloc,
const char *,
const char *);
85 for (
unsigned int i = 0; i < base->
num_widgets; i++) {
96 retv->
name = g_strdup(name);
134 G_GNUC_UNUSED
void *data) {
171 l = g_list_next(l)) {
253 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
265 char buf[G_ASCII_DTOSTR_BUF_SIZE + 1] = {
268 g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE,
"%.4f", d);
281 fputs(
" + ", stdout);
283 fputs(
" - ", stdout);
285 fputs(
" / ", stdout);
287 fputs(
" * ", stdout);
289 fputs(
" modulo ", stdout);
291 fputs(
" min ", stdout);
293 fputs(
" max ", stdout);
295 fputs(
" round ", stdout);
297 fputs(
" floor ", stdout);
299 fputs(
" ceil ", stdout);
307 printf(
"%upx ", (
unsigned int)unit->
distance);
310 fputs(
"mm ", stdout);
316 fputs(
"ch ", stdout);
319 fputs(
"em ", stdout);
329 g = 255 * color.
green;
331 b = 255 * color.
blue;
332 if (color.
alpha < 0.00001) {
333 printf(
"transparent");
339 if (color.
alpha < 1) {
340 printf(
"/%.0f%%", color.
alpha * 100.0);
345 printf(
"rgba ( %.0f, %.0f, %.0f, %.0f %% )", (color.
red * 255.0),
346 (color.
green * 255.0), (color.
blue * 255.0), (color.
alpha * 100.0));
350 fputs(
"calc( ", stdout);
371 for (GList *iter = p->
value.
list; iter != NULL; iter = g_list_next(iter)) {
373 if (iter->next != NULL) {
391 printf(
"underline ");
394 printf(
"strikethrough ");
400 printf(
"uppercase ");
403 printf(
"lowercase ");
406 printf(
"capitalize ");
415 fputs(
"center", stdout);
418 fputs(
"north", stdout);
421 fputs(
"south", stdout);
424 fputs(
"west", stdout);
427 fputs(
"east", stdout);
430 fputs(
"northeast", stdout);
433 fputs(
"southeast", stdout);
436 fputs(
"northwest", stdout);
439 fputs(
"southwest", stdout);
445 printf(
"\"%s\"", p->
value.
s);
451 char sign = (p->
value.
f < 0);
452 int top = (int)fabs(p->
value.
f);
453 int bottom = (fabs(fmod(p->
value.
f, 1.0))) * 100;
454 printf(
"%s%d.%02d", sign ?
"-" :
"", top, bottom);
458 printf(
"%s", p->
value.
b ?
"true" :
"false");
465 printf(
"url (\"%s\")", p->
value.
s);
467 printf(
"linear-gradient ( ");
471 l = g_list_next(l)) {
475 if (index < length) {
528 int pl = strlen(p->
name);
529 printf(
"%*s%s:%*s ", cur_depth,
"", p->
name, (
int)pnl - pl,
"");
540 printf(
"%s {\n", wid->
name);
541 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
550 if (g_strcmp0(w->
name,
"Root") == 0) {
556 list = g_list_prepend(list, w->
name);
559 if (g_list_length(list) > 0) {
560 printf(
"%*s", index,
"");
561 for (GList *citer = g_list_first(list); citer != NULL;
562 citer = g_list_next(citer)) {
563 char *name = (
char *)citer->data;
565 if (citer->prev == NULL && citer->next) {
567 }
else if (citer->next) {
573 printf(
"%*s* {\n", index,
"");
575 size_t property_name_length = 0;
576 g_hash_table_iter_init(&iter, wid->
properties);
577 while (g_hash_table_iter_next(&iter, &key, &value)) {
579 property_name_length = MAX(strlen(pv->
name), property_name_length);
581 g_hash_table_iter_init(&iter, wid->
properties);
582 while (g_hash_table_iter_next(&iter, &key, &value)) {
586 printf(
"%*s}\n", index,
"");
589 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
597 printf(
"/**\n * rofi -dump-theme output.\n * Rofi version: %s\n **/\n",
620void yyerror(YYLTYPE *yylloc,
const char *what,
const char *s) {
621 char *what_esc = what ? g_markup_escape_text(what, -1) : g_strdup(
"");
622 GString *str = g_string_new(
"");
624 "<big><b>Error while parsing theme:</b></big> <i>%s</i>\n",
627 char *esc = g_markup_escape_text(s, -1);
628 g_string_append_printf(
630 "\tParser error: <span size=\"smaller\" style=\"italic\">%s</span>\n",
633 if (yylloc->filename != NULL) {
634 g_string_append_printf(
636 "\tLocation: line %d column %d to line %d column %d.\n"
638 yylloc->first_line, yylloc->first_column, yylloc->last_line,
639 yylloc->last_column, yylloc->filename);
641 g_string_append_printf(
642 str,
"\tLocation: line %d column %d to line %d column %d\n",
643 yylloc->first_line, yylloc->first_column, yylloc->last_line,
644 yylloc->last_column);
646 g_log(
"Parser", G_LOG_LEVEL_DEBUG,
"Failed to parse theme:\n%s", str->str);
651 gpointer value, gpointer user_data) {
652 GHashTable *table = (GHashTable *)user_data;
654 g_hash_table_replace(table, p->
name, p);
662 g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
674 for (
unsigned int j = 0; wid && j < wid->
num_widgets; j++) {
683 const gboolean exact) {
684 if (wid == NULL || name == NULL) {
687 char *tname = g_strdup(name);
688 char *saveptr = NULL;
690 for (
const char *iter = strtok_r(tname,
".", &saveptr); iter != NULL;
691 iter = strtok_r(NULL,
".", &saveptr)) {
702 if (!exact || found) {
712 if (cur_depth > 20) {
713 g_warning(
"Found more then 20 redirects for property. Stopping.");
719 g_hash_table_contains(
rofi_theme->properties, name)) {
746 const char *property, gboolean exact) {
762 if (p->
type == type) {
769 g_debug(
"Found property: '%s' on '%s', but type %s does not match "
800 const char *property,
int def) {
814 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
824 const char *property,
int def) {
838 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
849 const char *property,
871 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
885 const char *property,
int def) {
899 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
911 const char *property,
927 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
932 const char *property,
942 const char *property,
958 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
963 const char *property,
970 const char *property,
985 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
998 const char *property,
1014 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1020 const char *property,
double def) {
1047 const char *property, cairo_t *d) {
1062 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1074 const char *property, cairo_t *d) {
1112 cairo_pattern_t *pat = cairo_pattern_create_for_surface(img);
1113 cairo_surface_set_device_scale(img, scale, scale);
1114 cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
1115 cairo_set_source(d, pat);
1116 cairo_pattern_destroy(pat);
1120 cairo_pattern_t *pat = NULL;
1123 pat = cairo_pattern_create_linear(0.0, 0.0, wid->
w, 0.0);
1126 pat = cairo_pattern_create_linear(wid->
w, 0.0, 0.0, 0.0);
1129 pat = cairo_pattern_create_linear(0.0, 0.0, 0.0, wid->
h);
1132 pat = cairo_pattern_create_linear(0.0, wid->
h, 0.0, 0.0);
1137 pat = cairo_pattern_create_linear(
1138 wid->
w / 2.0 - offsetx1, wid->
h / 2.0 - offsety1,
1139 wid->
w / 2.0 + offsetx1, wid->
h / 2.0 + offsety1);
1146 guint color_index = 0;
1148 l = g_list_next(l)) {
1150 cairo_pattern_add_color_stop_rgba(pat, (color_index) / (
double)length,
1155 cairo_set_source(d, pat);
1156 cairo_pattern_destroy(pat);
1161 cairo_pattern_add_color_stop_rgba(pat, 0, c->
red, c->
green, c->
blue,
1163 cairo_set_source(d, pat);
1164 cairo_pattern_destroy(pat);
1169 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1181 const char *property,
1204 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1216 const char *property,
1239 for (GList *iter = g_list_first(list); iter != NULL;
1240 iter = g_list_next(iter)) {
1245 retv = g_list_append(retv, pnew);
1253 retv = g_list_append(retv, pnew);
1255 g_warning(
"Invalid type detected in list.");
1265 for (GList *iter = g_list_first(list); iter != NULL;
1266 iter = g_list_next(iter)) {
1269 retv = g_list_append(retv, g_strdup(prop->
value.
s));
1271 g_warning(
"Invalid type detected in list.");
1306 g_debug(
"Theme entry: #%s %s property %s unset.", wid->
name,
1311 const char *property,
1332 val = (unit->
distance * height) / (100.0);
1336 val = (unit->
distance * width) / (100.0);
1388 return (
double)(round(a / b) * b);
1393 return (
double)(ceil(a / b) * b);
1398 return (
double)(floor(a / b) * b);
1412 const double dashes[1] = {4};
1413 cairo_set_dash(draw, dashes, 1, 0.0);
1415 cairo_set_dash(draw, NULL, 0, 0.0);
1420 char *filename = g_strdup(file);
1422 GFile *gf = g_file_new_for_path(filename);
1424 filename = g_file_get_path(gf);
1431 g_assert(parent != NULL);
1432 g_assert(child != NULL);
1445 for (
unsigned int i = 0; i < child->
num_widgets; i++) {
1452 if (rwidget == NULL) {
1457 while (i < rwidget->num_widgets) {
1459 if (child_widget->
media != NULL) {
1461 for (
unsigned x = i; x < rwidget->
num_widgets; x++) {
1469 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1478 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1487 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1497 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1505 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1513 if ((
mon.w / (
double)
mon.h) >= r) {
1514 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1522 if ((
mon.w / (
double)
mon.h) < r) {
1523 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1531 for (
unsigned int x = 0; x < child_widget->
num_widgets; x++) {
1552 GString *str = g_string_new(wid->
name);
1554 g_string_prepend_c(str,
' ');
1555 g_string_prepend(str, i->name);
1557 char *retv = str->str;
1558 g_string_free(str, FALSE);
1567 for (
unsigned int i = 0; i < wid->
num_widgets; i++) {
1573 GHashTableIter iter;
1574 gpointer key, value;
1575 g_hash_table_iter_init(&iter, child_widget->
properties);
1576 while (g_hash_table_iter_next(&iter, &key, &value)) {
1583 GString *str = g_string_new(NULL);
1584 g_string_printf(str,
1585 "Validating the theme failed: the variable '%s' in "
1586 "`%s { %s: var(%s);}` failed to resolve.",
1610 if (g_strcmp0(type,
"monitor-id") == 0) {
1613 if (g_strcmp0(type,
"min-width") == 0) {
1616 if (g_strcmp0(type,
"min-height") == 0) {
1619 if (g_strcmp0(type,
"max-width") == 0) {
1622 if (g_strcmp0(type,
"max-height") == 0) {
1625 if (g_strcmp0(type,
"min-aspect-ratio") == 0) {
1628 if (g_strcmp0(type,
"max-aspect-ratio") == 0) {
1631 if (g_strcmp0(type,
"enabled") == 0) {
1639 const char *property) {
int monitor_active(workarea *mon)
struct _workarea workarea
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)
static disp_scale_func disp_scale
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_set_disp_scale_func(disp_scale_func func)
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)
guint(* disp_scale_func)(void)
RofiHighlightColorStyle highlight
struct Property * def_value
struct _PropertyValue::@005205057126162341352067070323165034173231020213 link
ThemeWidget * rofi_configuration