29 #define G_LOG_DOMAIN "Theme" 39 #include "theme-parser.h" 47 void yyerror ( YYLTYPE *yylloc,
const char *,
const char * );
55 for (
unsigned int i = 0; i < base->
num_widgets; i++ ) {
56 if ( g_strcmp0 ( base->
widgets[i]->
name, name ) == 0 ) {
65 retv->
name = g_strdup ( name );
128 if (
widget->properties ) {
129 g_hash_table_destroy (
widget->properties );
130 widget->properties = NULL;
132 for (
unsigned int i = 0; i <
widget->num_widgets; i++ ) {
135 g_free (
widget->widgets );
145 char buf[G_ASCII_DTOSTR_BUF_SIZE];
146 g_ascii_formatd ( buf, G_ASCII_DTOSTR_BUF_SIZE,
"%.4lf", d );
147 fputs ( buf, stdout );
152 printf (
"%upx ", (
unsigned int) d.
distance );
156 fputs (
"%% ", stdout );
160 fputs (
"em ", stdout );
181 int pl = strlen ( p->
name );
182 printf (
"%*s%s:%*s ",
depth,
"", p->
name, (
int) pnl - pl,
"" );
187 for ( GList *iter = p->
value.
list; iter != NULL; iter = g_list_next ( iter ) ) {
188 printf (
"%s", (
char *) ( iter->data ) );
189 if ( iter->next != NULL ) {
203 printf (
"underline " );
206 printf (
"strikethrough " );
209 printf (
"italic " );
212 printf (
"rgba ( %.0f, %.0f, %.0f, %.0f %% )",
224 printf (
"\"%s\";", p->
value.
s );
227 printf (
"%d;", p->
value.
i );
230 printf (
"%.2f;", p->
value.
f );
233 printf (
"%s;", p->
value.
b ?
"true" :
"false" );
236 printf (
"rgba ( %.0f, %.0f, %.0f, %.0f %% );",
271 printf (
"inherit;" );
283 if (
widget->properties ) {
288 if ( g_strcmp0 ( w->
name,
"Root" ) == 0 ) {
291 list = g_list_prepend ( list, w->
name );
294 if ( g_list_length ( list ) > 0 ) {
296 for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
297 char *name = (
char *) iter->data;
298 fputs ( name, stdout );
299 if ( iter->prev == NULL && iter->next ) {
302 else if ( iter->next ) {
312 size_t property_name_length = 0;
313 g_hash_table_iter_init ( &iter,
widget->properties );
314 while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
316 property_name_length = MAX ( strlen ( p->
name ), property_name_length );
318 g_hash_table_iter_init ( &iter,
widget->properties );
319 while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
324 g_list_free ( list );
326 for (
unsigned int i = 0; i <
widget->num_widgets; i++ ) {
333 printf (
"/**\n * rofi -dump-theme output.\n * Rofi version: %s\n **/\n", PACKAGE_VERSION );
360 void yyerror ( YYLTYPE *yylloc,
const char *what,
const char* s )
362 char *what_esc = what ? g_markup_escape_text ( what, -1 ) : g_strdup (
"" );
363 GString *str = g_string_new (
"" );
364 g_string_printf ( str,
"<big><b>Error while parsing theme:</b></big> <i>%s</i>\n", what_esc );
366 char *esc = g_markup_escape_text ( s, -1 );
367 g_string_append_printf ( str,
"\tParser error: <span size=\"smaller\" style=\"italic\">%s</span>\n", esc );
369 if ( yylloc->filename != NULL ) {
370 g_string_append_printf ( str,
"\tLocation: line %d column %d to line %d column %d.\n" \
371 "\tFile '%s'\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column, yylloc->filename );
374 g_string_append_printf ( str,
"\tLocation: line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column );
376 g_log (
"Parser", G_LOG_LEVEL_DEBUG,
"Failed to parse theme:\n%s", str->str );
382 GHashTable *table = (GHashTable *) user_data;
384 g_hash_table_replace ( table, p->
name, p );
388 if ( table == NULL ) {
391 if (
widget->properties == NULL ) {
403 for (
unsigned int j = 0;
widget && j <
widget->num_widgets; j++ ) {
404 if ( g_strcmp0 (
widget->widgets[j]->
name, name ) == 0 ) {
405 return widget->widgets[j];
413 if (
widget == NULL || name == NULL ) {
416 char *tname = g_strdup ( name );
417 char *saveptr = NULL;
419 for (
const char *iter = strtok_r ( tname,
".", &saveptr ); iter != NULL; iter = strtok_r ( NULL,
".", &saveptr ) ) {
431 if ( !exact || found ) {
444 g_warning (
"Found more then 20 redirects for property. Stopping." );
473 if (
widget->properties && g_hash_table_contains (
widget->properties, property ) ) {
474 Property *p = g_hash_table_lookup (
widget->properties, property );
487 if ( p->
type == type ) {
494 g_debug (
"Found property: '%s' on '%s', but type %s does not match expected type %s.",
643 return (
double) p->
value.
i;
659 cairo_set_source_rgba ( d,
704 return g_list_copy_deep ( p->
value.
list, (GCopyFunc) g_strdup, NULL );
707 char **r = defaults ? g_strsplit ( defaults,
",", 0 ) : NULL;
710 for (
int i = 0; r[i] != NULL; i++ ) {
711 l = g_list_append ( l, r[i] );
748 return ( d.
distance * height ) / ( 100.0 );
753 return ( d.
distance * width ) / ( 100.0 );
762 const double dashes[1] = { 4 };
763 cairo_set_dash ( draw, dashes, 1, 0.0 );
766 cairo_set_dash ( draw, NULL, 0, 0.0 );
782 #ifdef THEME_CONVERTER 784 static char * rofi_theme_convert_color (
char *col )
786 char *r = g_strstrip ( col );
787 if ( *r ==
'#' && strlen ( r ) == 9 ) {
802 void rofi_theme_convert_old (
void )
811 const char *
const conf[] = {
812 "* { background: %s; }",
813 "* { border-color: %s; }",
814 "* { separatorcolor: %s; }" 816 for (
int i = 0; retv && i < 3 && retv[i]; i++ ) {
817 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
825 const char *
const conf[] = {
826 "* { normal-background: %s; }",
827 "* { foreground: %s; normal-foreground: @foreground; alternate-normal-foreground: @foreground; }",
828 "* { alternate-normal-background: %s; }",
829 "* { selected-normal-background: %s; }",
830 "* { selected-normal-foreground: %s; }" 832 for (
int i = 0; retv && retv[i] && i < 5; i++ ) {
833 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
841 const char *
const conf[] = {
842 "* { urgent-background: %s; }",
843 "* { urgent-foreground: %s; alternate-urgent-foreground: @urgent-foreground;}",
844 "* { alternate-urgent-background: %s; }",
845 "* { selected-urgent-background: %s; }",
846 "* { selected-urgent-foreground: %s; }" 848 for (
int i = 0; retv && retv[i] && i < 5; i++ ) {
849 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
857 const char *
const conf[] = {
858 "* { active-background: %s; }",
859 "* { active-foreground: %s; alternate-active-foreground: @active-foreground;}",
860 "* { alternate-active-background: %s; }",
861 "* { selected-active-background: %s; }",
862 "* { selected-active-foreground: %s; }" 864 for (
int i = 0; retv && retv[i] && i < 5; i++ ) {
865 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
874 const char *
const str =
"#listview { border: 0px; }";
876 const char *
const str2 =
"#sidebar { border: 0px; }";
878 const char *
const str3 =
"#message { border: 0px; }";
882 const char *
const str =
"#listview { border: 2px solid 0px 0px 0px; }";
884 const char *
const str2 =
"#sidebar { border: 2px solid 0px 0px 0px; }";
886 const char *
const str3 =
"#message { border: 2px solid 0px 0px 0px; }";
892 char *str = g_strdup_printf (
"#listview { spacing: %dpx;}",
config.
line_margin );
898 char *str = g_strdup_printf (
"#element, inputbar, message { padding: %dpx;}",
config.
line_padding );
903 const char *str =
"#listview { scrollbar: false; }";
907 const char *str =
"#listview { scrollbar: true; }";
919 #endif // THEME_CONVERTER 925 if ( parent_file != NULL && !g_path_is_absolute ( filename ) ) {
926 char *basedir = g_path_get_dirname ( parent_file );
927 char *path = g_build_filename ( basedir, filename, NULL );
932 GFile *gf = g_file_new_for_path ( filename );
934 filename = g_file_get_path ( gf );
935 g_object_unref ( gf );
static void rofi_theme_print_property_index(size_t pnl, int depth, Property *p)
void rofi_theme_free(ThemeWidget *widget)
GList * rofi_theme_get_list(const widget *widget, const char *property, const char *defaults)
void rofi_view_get_current_monitor(int *width, int *height)
ThemeWidget * rofi_theme_find_or_create_name(ThemeWidget *base, const char *name)
unsigned int fake_transparency
void rofi_theme_get_color(const widget *widget, const char *property, cairo_t *d)
void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table)
Property * rofi_theme_property_copy(Property *p)
ThemeWidget * rofi_theme_find_widget(const char *name, const char *state, gboolean exact)
static void printf_double(double d)
char * rofi_theme_parse_prepare_file(const char *file, const char *parent_file)
Property * rofi_theme_find_property(ThemeWidget *widget, PropertyType type, const char *property, gboolean exact)
const char * rofi_theme_get_string(const widget *widget, const char *property, const char *def)
unsigned int scrollbar_width
double rofi_theme_get_double(const widget *widget, const char *property, double def)
RofiPadding rofi_theme_get_padding(const widget *widget, const char *property, RofiPadding pad)
int rofi_theme_get_boolean(const widget *widget, const char *property, int def)
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, int def)
struct PropertyValue::@3 link
static void rofi_theme_print_distance(RofiDistance d)
void rofi_theme_property_free(Property *p)
RofiHighlightColorStyle rofi_theme_get_highlight(widget *widget, const char *property, RofiHighlightColorStyle th)
static void rofi_theme_resolve_link_property(Property *p, int depth)
void yyerror(YYLTYPE *yylloc, const char *, const char *)
Property * rofi_theme_property_create(PropertyType type)
double textbox_get_estimated_ch(void)
void rofi_theme_reset(void)
void rofi_add_error_message(GString *str)
char * rofi_expand_path(const char *input)
void rofi_theme_print(ThemeWidget *widget)
static void rofi_theme_print_index(ThemeWidget *widget)
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
const char *const WindowLocationStr[9]
RofiOrientation rofi_theme_get_orientation(const widget *widget, const char *property, RofiOrientation def)
unsigned int hide_scrollbar
const char *const PropertyTypeName[P_NUM_TYPES]
static void rofi_theme_copy_property_int(G_GNUC_UNUSED gpointer key, gpointer value, gpointer user_data)
int rofi_theme_get_position(const widget *widget, const char *property, int def)
RofiHighlightColorStyle highlight
static ThemeWidget * rofi_theme_find(ThemeWidget *widget, const char *name, const gboolean exact)
static gboolean distance_compare(RofiDistance d, RofiDistance e)
static ThemeWidget * rofi_theme_find_single(ThemeWidget *widget, const char *name)
double textbox_get_estimated_char_height(void)
int rofi_theme_get_integer(const widget *widget, const char *property, int def)
gboolean rofi_theme_parse_string(const char *string)
gboolean rofi_theme_is_empty(void)
unsigned int line_padding
void distance_get_linestyle(RofiDistance d, cairo_t *draw)