29 #define G_LOG_DOMAIN "Theme"
43 #include "theme-parser.h"
49 void yyerror(YYLTYPE *yylloc,
const char *,
const char *);
57 G_GNUC_UNUSED gpointer user_data) {
58 return g_strdup(data);
63 for (
unsigned int i = 0; i < base->
num_widgets; i++) {
74 retv->
name = g_strdup(name);
148 l = g_list_next(l)) {
221 g_hash_table_destroy(
widget->properties);
222 widget->properties = NULL;
227 for (
unsigned int i = 0; i <
widget->num_widgets; i++) {
239 char buf[G_ASCII_DTOSTR_BUF_SIZE];
240 g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE,
"%.4lf", d);
253 fputs(
" + ", stdout);
255 fputs(
" - ", stdout);
257 fputs(
" / ", stdout);
259 fputs(
" * ", stdout);
261 fputs(
" % ", stdout);
263 fputs(
" min ", stdout);
265 fputs(
" max ", stdout);
273 printf(
"%upx ", (
unsigned int)unit->
distance);
276 fputs(
"mm ", stdout);
282 fputs(
"ch ", stdout);
285 fputs(
"em ", stdout);
295 fputs(
"calc( ", stdout);
316 for (GList *iter = p->
value.
list; iter != NULL; iter = g_list_next(iter)) {
317 printf(
"%s", (
char *)(iter->data));
318 if (iter->next != NULL) {
336 printf(
"underline ");
339 printf(
"strikethrough ");
345 printf(
"rgba ( %.0f, %.0f, %.0f, %.0f %% )",
355 fputs(
"center", stdout);
358 fputs(
"north", stdout);
361 fputs(
"south", stdout);
364 fputs(
"west", stdout);
367 fputs(
"east", stdout);
370 fputs(
"northeast", stdout);
373 fputs(
"southeast", stdout);
376 fputs(
"northwest", stdout);
379 fputs(
"southwest", stdout);
385 printf(
"\"%s\"", p->
value.
s);
391 char sign = (p->
value.
f < 0);
392 int top = (int)fabs(p->
value.
f);
393 int bottom = (fabs(fmod(p->
value.
f, 1.0))) * 100;
394 printf(
"%s%d.%02d", sign ?
"-" :
"", top, bottom);
398 printf(
"%s", p->
value.
b ?
"true" :
"false");
401 printf(
"rgba ( %.0f, %.0f, %.0f, %.0f %% )", (p->
value.
color.
red * 255.0),
407 printf(
"url (\"%s\")", p->
value.
s);
409 printf(
"linear-gradient ( ");
413 l = g_list_next(l)) {
415 printf(
"rgba ( %.0f, %.0f, %.0f, %.0f %% )", (color->
red * 255.0),
416 (color->
green * 255.0), (color->
blue * 255.0),
417 (color->
alpha * 100.0));
419 if (index < length) {
472 int pl = strlen(p->
name);
473 printf(
"%*s%s:%*s ",
depth,
"", p->
name, (
int)pnl - pl,
"");
485 for (
unsigned int i = 0; i <
widget->num_widgets; i++) {
494 if (g_strcmp0(w->
name,
"Root") == 0) {
500 list = g_list_prepend(list, w->
name);
503 if (g_list_length(list) > 0) {
504 printf(
"%*s", index,
"");
505 for (GList *citer = g_list_first(list); citer != NULL;
506 citer = g_list_next(citer)) {
507 char *name = (
char *)citer->data;
509 if (citer->prev == NULL && citer->next) {
511 }
else if (citer->next) {
517 printf(
"%*s* {\n", index,
"");
519 size_t property_name_length = 0;
520 g_hash_table_iter_init(&iter,
widget->properties);
521 while (g_hash_table_iter_next(&iter, &key, &value)) {
523 property_name_length = MAX(strlen(pv->
name), property_name_length);
525 g_hash_table_iter_init(&iter,
widget->properties);
526 while (g_hash_table_iter_next(&iter, &key, &value)) {
530 printf(
"%*s}\n", index,
"");
533 for (
unsigned int i = 0; i <
widget->num_widgets; i++) {
541 printf(
"/**\n * rofi -dump-theme output.\n * Rofi version: %s\n **/\n",
569 void yyerror(YYLTYPE *yylloc,
const char *what,
const char *s) {
570 char *what_esc = what ? g_markup_escape_text(what, -1) : g_strdup(
"");
571 GString *str = g_string_new(
"");
573 "<big><b>Error while parsing theme:</b></big> <i>%s</i>\n",
576 char *esc = g_markup_escape_text(s, -1);
577 g_string_append_printf(
579 "\tParser error: <span size=\"smaller\" style=\"italic\">%s</span>\n",
582 if (yylloc->filename != NULL) {
583 g_string_append_printf(
585 "\tLocation: line %d column %d to line %d column %d.\n"
587 yylloc->first_line, yylloc->first_column, yylloc->last_line,
588 yylloc->last_column, yylloc->filename);
590 g_string_append_printf(
591 str,
"\tLocation: line %d column %d to line %d column %d\n",
592 yylloc->first_line, yylloc->first_column, yylloc->last_line,
593 yylloc->last_column);
595 g_log(
"Parser", G_LOG_LEVEL_DEBUG,
"Failed to parse theme:\n%s", str->str);
600 gpointer value, gpointer user_data) {
601 GHashTable *table = (GHashTable *)user_data;
603 g_hash_table_replace(table, p->
name, p);
609 if (
widget->properties == NULL) {
611 g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
623 for (
unsigned int j = 0;
widget && j <
widget->num_widgets; j++) {
624 if (g_strcmp0(
widget->widgets[j]->
name, name) == 0) {
625 return widget->widgets[j];
632 const gboolean exact) {
633 if (
widget == NULL || name == NULL) {
636 char *tname = g_strdup(name);
637 char *saveptr = NULL;
639 for (
const char *iter = strtok_r(tname,
".", &saveptr); iter != NULL;
640 iter = strtok_r(NULL,
".", &saveptr)) {
651 if (!exact || found) {
662 g_warning(
"Found more then 20 redirects for property. Stopping.");
695 const char *property, gboolean exact) {
698 g_hash_table_contains(
widget->properties, property)) {
712 if (p->
type == type) {
719 g_debug(
"Found property: '%s' on '%s', but type %s does not match "
750 const char *property,
int def) {
764 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
775 const char *property,
int def) {
789 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
801 const char *property,
824 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
838 const char *property,
int def) {
852 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
865 const char *property,
880 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
885 const char *property,
894 const char *property,
909 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
914 const char *property,
922 const char *property,
937 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
949 const char *property,
double def) {
976 const char *property, cairo_t *d) {
991 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
1004 const char *property, cairo_t *d) {
1044 cairo_pattern_t *pat = cairo_pattern_create_for_surface(img);
1045 cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
1046 cairo_set_source(d, pat);
1047 cairo_pattern_destroy(pat);
1051 cairo_pattern_t *pat = NULL;
1054 pat = cairo_pattern_create_linear(0.0, 0.0,
widget->
w, 0.0);
1057 pat = cairo_pattern_create_linear(
widget->
w, 0.0, 0.0, 0.0);
1060 pat = cairo_pattern_create_linear(0.0, 0.0, 0.0,
widget->
h);
1063 pat = cairo_pattern_create_linear(0.0,
widget->
h, 0.0, 0.0);
1070 pat = cairo_pattern_create_linear(
1079 guint color_index = 0;
1081 l = g_list_next(l)) {
1083 cairo_pattern_add_color_stop_rgba(pat, (color_index) / (
double)length,
1088 cairo_set_source(d, pat);
1089 cairo_pattern_destroy(pat);
1094 cairo_pattern_add_color_stop_rgba(pat, 0, c->
red, c->
green, c->
blue,
1096 cairo_set_source(d, pat);
1097 cairo_pattern_destroy(pat);
1102 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
1115 const char *property,
1138 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
1150 const char *property,
1151 const char *defaults) {
1165 char **r = defaults ? g_strsplit(defaults,
",", 0) : NULL;
1168 for (
int i = 0; r[i] != NULL; i++) {
1169 l = g_list_append(l, r[i]);
1177 const char *defaults) {
1185 const char *property,
1201 g_debug(
"Theme entry: #%s %s property %s unset.",
widget->
name,
1206 const char *property,
1223 val = (unit->
distance * height) / (100.0);
1227 val = (unit->
distance * width) / (100.0);
1288 const double dashes[1] = {4};
1289 cairo_set_dash(draw, dashes, 1, 0.0);
1291 cairo_set_dash(draw, NULL, 0, 0.0);
1308 if (parent_file != NULL && !g_path_is_absolute(filename)) {
1309 char *basedir = g_path_get_dirname(parent_file);
1310 char *path = g_build_filename(basedir, filename, NULL);
1315 GFile *gf = g_file_new_for_path(filename);
1317 filename = g_file_get_path(gf);
1325 g_assert(parent != NULL);
1326 g_assert(child != NULL);
1335 for (
unsigned int i = 0; i < child->
num_widgets; i++) {
1340 g_assert(parent != NULL);
1341 g_assert(child != NULL);
1354 for (
unsigned int i = 0; i < child->
num_widgets; i++) {
1361 if (rwidget == NULL) {
1364 for (
unsigned int i = 0; i < rwidget->
num_widgets; i++) {
1367 if (
widget->media != NULL) {
1370 int w =
widget->media->value;
1372 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1380 int w =
widget->media->value;
1382 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1390 int h =
widget->media->value;
1392 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1400 int h =
widget->media->value;
1402 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1411 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1419 double r =
widget->media->value;
1420 if ((
mon.
w / (
double)
mon.
h) >= r) {
1421 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1429 double r =
widget->media->value;
1431 for (
unsigned int x = 0; x <
widget->num_widgets; x++) {
1452 if (g_strcmp0(type,
"monitor-id") == 0) {
1455 if (g_strcmp0(type,
"min-width") == 0) {
1458 if (g_strcmp0(type,
"min-height") == 0) {
1461 if (g_strcmp0(type,
"max-width") == 0) {
1464 if (g_strcmp0(type,
"max-height") == 0) {
1467 if (g_strcmp0(type,
"min-aspect-ratio") == 0) {
1470 if (g_strcmp0(type,
"max-aspect-ratio") == 0) {
1478 const char *property) {
char * rofi_expand_path(const char *input)
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)
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]
@ ROFI_IMAGE_LINEAR_GRADIENT
@ ROFI_ORIENTATION_HORIZONTAL
@ ROFI_ORIENTATION_VERTICAL
@ ROFI_DISTANCE_MODIFIER_GROUP
@ ROFI_DISTANCE_MODIFIER_SUBTRACT
@ ROFI_DISTANCE_MODIFIER_MODULO
@ 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
RofiPadding rofi_theme_get_padding(const widget *widget, const char *property, RofiPadding pad)
gboolean rofi_theme_get_image(const widget *widget, const char *property, cairo_t *d)
static void rofi_theme_print_property_index(size_t pnl, int depth, Property *p)
const char *const RofiCursorTypeStr[3]
static RofiDistanceUnit * rofi_theme_property_copy_distance_unit(RofiDistanceUnit *unit)
static int distance_unit_get_pixel(RofiDistanceUnit *unit, RofiOrientation ori)
static void int_rofi_theme_print_property(Property *p)
Property * rofi_theme_property_copy(const Property *p)
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, int def)
ThemeWidget * rofi_config_find_widget(const char *name, const char *state, gboolean exact)
int rofi_theme_get_boolean(const widget *widget, const char *property, int def)
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
static RofiHighlightColorStyle rofi_theme_get_highlight_inside(Property *p, widget *widget, const char *property, RofiHighlightColorStyle th)
Property * rofi_theme_find_property(ThemeWidget *widget, PropertyType type, const char *property, gboolean exact)
RofiCursorType rofi_theme_get_cursor_type(const widget *widget, const char *property, RofiCursorType def)
ThemeWidget * rofi_theme_find_widget(const char *name, const char *state, gboolean exact)
static GList * rofi_theme_get_list_inside(Property *p, const widget *widget, const char *property, const char *defaults)
static int rofi_theme_get_integer_inside(Property *p, const widget *widget, const char *property, int def)
static RofiDistance rofi_theme_get_distance_inside(Property *p, const widget *widget, const char *property, int def)
static gboolean distance_compare(RofiDistance d, RofiDistance e)
static void rofi_theme_get_color_inside(const widget *widget, Property *p, const char *property, cairo_t *d)
void rofi_theme_parse_process_conditionals(void)
void rofi_theme_get_color(const widget *widget, const char *property, cairo_t *d)
RofiHighlightColorStyle rofi_theme_get_highlight(widget *widget, const char *property, RofiHighlightColorStyle th)
static RofiCursorType rofi_theme_get_cursor_type_inside(Property *p, const widget *widget, const char *property, RofiCursorType def)
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)
RofiOrientation rofi_theme_get_orientation(const widget *widget, const char *property, RofiOrientation def)
static void rofi_theme_parse_merge_widgets_no_media(ThemeWidget *parent, ThemeWidget *child)
static int get_pixels(RofiDistanceUnit *unit, RofiOrientation ori)
Property * rofi_theme_property_create(PropertyType type)
char * rofi_theme_parse_prepare_file(const char *file, const char *parent_file)
static gpointer rofi_g_list_strdup(gconstpointer data, G_GNUC_UNUSED gpointer user_data)
ThemeMediaType rofi_theme_parse_media_type(const char *type)
void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table)
static double rofi_theme_get_double_inside(const widget *orig, Property *p, const widget *widget, const char *property, double def)
static RofiOrientation rofi_theme_get_orientation_inside(Property *p, const widget *widget, const char *property, RofiOrientation def)
double rofi_theme_get_double(const widget *widget, const char *property, double def)
static void rofi_theme_print_distance(RofiDistance d)
int rofi_theme_get_integer(const widget *widget, const char *property, int def)
void rofi_theme_print(ThemeWidget *widget)
static gboolean rofi_theme_has_property_inside(Property *p, const widget *widget, const char *property)
static void printf_double(double d)
gboolean rofi_theme_has_property(const widget *widget, const char *property)
void rofi_theme_reset(void)
static int rofi_theme_get_position_inside(Property *p, const widget *widget, const char *property, int def)
void rofi_theme_parse_merge_widgets(ThemeWidget *parent, ThemeWidget *child)
static void rofi_theme_distance_unit_property_free(RofiDistanceUnit *unit)
static ThemeWidget * rofi_theme_find_single(ThemeWidget *widget, const char *name)
GList * rofi_theme_get_list(const widget *widget, const char *property, const char *defaults)
int rofi_theme_get_position(const widget *widget, const char *property, int def)
static void rofi_theme_resolve_link_property(Property *p, int depth)
static void rofi_theme_parse_process_conditionals_int(workarea mon, ThemeWidget *rwidget)
void rofi_theme_print_index(ThemeWidget *widget, int index)
void rofi_theme_free(ThemeWidget *widget)
static const char * rofi_theme_get_string_inside(Property *p, const widget *widget, const char *property, const char *def)
ThemeWidget * rofi_theme_find_or_create_name(ThemeWidget *base, const char *name)
static ThemeWidget * rofi_theme_find(ThemeWidget *widget, const char *name, const gboolean exact)
gboolean rofi_theme_is_empty(void)
static int rofi_theme_get_boolean_inside(Property *p, const widget *widget, const char *property, int 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 RofiPadding rofi_theme_get_padding_inside(Property *p, const widget *widget, const char *property, RofiPadding pad)
const char * rofi_theme_get_string(const widget *widget, const char *property, const char *def)
static gboolean rofi_theme_get_image_inside(Property *p, const widget *widget, const char *property, cairo_t *d)
void distance_get_linestyle(RofiDistance d, cairo_t *draw)
@ 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_MAX_ASPECT_RATIO
@ THEME_MEDIA_TYPE_MAX_WIDTH
@ THEME_MEDIA_TYPE_MIN_HEIGHT
struct _PropertyValue::@6 link
RofiHighlightColorStyle highlight
struct Property * def_value
int monitor_active(workarea *mon)
ThemeWidget * rofi_configuration