28 #define G_LOG_DOMAIN "Theme" 38 #include "theme-parser.h" 46 void yyerror ( YYLTYPE *yylloc,
const char *,
const char * );
54 for (
unsigned int i = 0; i < base->
num_widgets; i++ ) {
55 if ( g_strcmp0 ( base->
widgets[i]->
name, name ) == 0 ) {
64 retv->
name = g_strdup ( name );
127 if (
widget->properties ) {
128 g_hash_table_destroy (
widget->properties );
129 widget->properties = NULL;
131 for (
unsigned int i = 0; i <
widget->num_widgets; i++ ) {
134 g_free (
widget->widgets );
144 char buf[G_ASCII_DTOSTR_BUF_SIZE];
145 g_ascii_formatd ( buf, G_ASCII_DTOSTR_BUF_SIZE,
"%.4lf", d );
146 fputs ( buf, stdout );
151 printf (
"%upx ", (
unsigned int) d.
distance );
155 fputs (
"%% ", stdout );
159 fputs (
"em ", stdout );
180 int pl = strlen ( p->
name );
181 printf (
"%*s%s:%*s ",
depth,
"", p->
name, (
int) pnl - pl,
"" );
186 for ( GList *iter = p->
value.
list; iter != NULL; iter = g_list_next ( iter ) ) {
187 printf (
"%s", (
char *) ( iter->data ) );
188 if ( iter->next != NULL ) {
202 printf (
"underline " );
205 printf (
"strikethrough " );
208 printf (
"italic " );
211 printf (
"rgba ( %.0f, %.0f, %.0f, %.0f %% )",
223 printf (
"\"%s\";", p->
value.
s );
226 printf (
"%d;", p->
value.
i );
229 printf (
"%.2f;", p->
value.
f );
232 printf (
"%s;", p->
value.
b ?
"true" :
"false" );
235 printf (
"rgba ( %.0f, %.0f, %.0f, %.0f %% );",
270 printf (
"inherit;" );
282 if (
widget->properties ) {
287 if ( g_strcmp0 ( w->
name,
"Root" ) == 0 ) {
290 list = g_list_prepend ( list, w->
name );
293 if ( g_list_length ( list ) > 0 ) {
295 for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
296 char *name = (
char *) iter->data;
297 fputs ( name, stdout );
298 if ( iter->prev == NULL && iter->next ) {
301 else if ( iter->next ) {
311 size_t property_name_length = 0;
312 g_hash_table_iter_init ( &iter,
widget->properties );
313 while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
315 property_name_length = MAX ( strlen ( p->
name ), property_name_length );
317 g_hash_table_iter_init ( &iter,
widget->properties );
318 while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
323 g_list_free ( list );
325 for (
unsigned int i = 0; i <
widget->num_widgets; i++ ) {
332 printf (
"/**\n * rofi -dump-theme output.\n * Rofi version: %s\n **/\n", PACKAGE_VERSION );
359 void yyerror ( YYLTYPE *yylloc,
const char *what,
const char* s )
361 char *what_esc = what ? g_markup_escape_text ( what, -1 ) : g_strdup (
"" );
362 GString *str = g_string_new (
"" );
363 g_string_printf ( str,
"<big><b>Error while parsing theme:</b></big> <i>%s</i>\n", what_esc );
365 char *esc = g_markup_escape_text ( s, -1 );
366 g_string_append_printf ( str,
"\tParser error: <span size=\"smaller\" style=\"italic\">%s</span>\n", esc );
368 if ( yylloc->filename != NULL ) {
369 g_string_append_printf ( str,
"\tLocation: line %d column %d to line %d column %d.\n" \
370 "\tFile '%s'\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column, yylloc->filename );
373 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 );
375 g_log (
"Parser", G_LOG_LEVEL_DEBUG,
"Failed to parse theme:\n%s", str->str );
381 GHashTable *table = (GHashTable *) user_data;
383 g_hash_table_replace ( table, p->
name, p );
387 if ( table == NULL ) {
390 if (
widget->properties == NULL ) {
402 for (
unsigned int j = 0;
widget && j <
widget->num_widgets; j++ ) {
403 if ( g_strcmp0 (
widget->widgets[j]->
name, name ) == 0 ) {
404 return widget->widgets[j];
412 if (
widget == NULL || name == NULL ) {
415 char *tname = g_strdup ( name );
416 char *saveptr = NULL;
418 for (
const char *iter = strtok_r ( tname,
".", &saveptr ); iter != NULL; iter = strtok_r ( NULL,
".", &saveptr ) ) {
430 if ( !exact || found ) {
443 g_warning (
"Found more then 20 redirects for property. Stopping." );
472 if (
widget->properties && g_hash_table_contains (
widget->properties, property ) ) {
473 Property *p = g_hash_table_lookup (
widget->properties, property );
486 if ( p->
type == type ) {
493 g_debug (
"Found property: '%s' on '%s', but type %s does not match expected type %s.",
642 return (
double)p->
value.
i;
658 cairo_set_source_rgba ( d,
703 return g_list_copy_deep ( p->
value.
list, (GCopyFunc) g_strdup, NULL );
706 char **r = defaults ? g_strsplit ( defaults,
",", 0 ) : NULL;
709 for (
int i = 0; r[i] != NULL; i++ ) {
710 l = g_list_append ( l, r[i] );
747 return ( d.
distance * height ) / ( 100.0 );
752 return ( d.
distance * width ) / ( 100.0 );
761 const double dashes[1] = { 4 };
762 cairo_set_dash ( draw, dashes, 1, 0.0 );
765 cairo_set_dash ( draw, NULL, 0, 0.0 );
781 #ifdef THEME_CONVERTER 783 static char * rofi_theme_convert_color (
char *col )
785 char *r = g_strstrip ( col );
786 if ( *r ==
'#' && strlen ( r ) == 9 ) {
801 void rofi_theme_convert_old (
void )
810 const char *
const conf[] = {
811 "* { background: %s; }",
812 "* { border-color: %s; }",
813 "* { separatorcolor: %s; }" 815 for (
int i = 0; retv && i < 3 && retv[i]; i++ ) {
816 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
824 const char *
const conf[] = {
825 "* { normal-background: %s; }",
826 "* { foreground: %s; normal-foreground: @foreground; alternate-normal-foreground: @foreground; }",
827 "* { alternate-normal-background: %s; }",
828 "* { selected-normal-background: %s; }",
829 "* { selected-normal-foreground: %s; }" 831 for (
int i = 0; retv && retv[i] && i < 5; i++ ) {
832 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
840 const char *
const conf[] = {
841 "* { urgent-background: %s; }",
842 "* { urgent-foreground: %s; alternate-urgent-foreground: @urgent-foreground;}",
843 "* { alternate-urgent-background: %s; }",
844 "* { selected-urgent-background: %s; }",
845 "* { selected-urgent-foreground: %s; }" 847 for (
int i = 0; retv && retv[i] && i < 5; i++ ) {
848 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
856 const char *
const conf[] = {
857 "* { active-background: %s; }",
858 "* { active-foreground: %s; alternate-active-foreground: @active-foreground;}",
859 "* { alternate-active-background: %s; }",
860 "* { selected-active-background: %s; }",
861 "* { selected-active-foreground: %s; }" 863 for (
int i = 0; retv && retv[i] && i < 5; i++ ) {
864 char *str = g_strdup_printf ( conf[i], rofi_theme_convert_color ( retv[i] ) );
873 const char *
const str =
"#listview { border: 0px; }";
875 const char *
const str2 =
"#sidebar { border: 0px; }";
877 const char *
const str3 =
"#message { border: 0px; }";
881 const char *
const str =
"#listview { border: 2px solid 0px 0px 0px; }";
883 const char *
const str2 =
"#sidebar { border: 2px solid 0px 0px 0px; }";
885 const char *
const str3 =
"#message { border: 2px solid 0px 0px 0px; }";
891 char *str = g_strdup_printf (
"#listview { spacing: %dpx;}",
config.
line_margin );
897 char *str = g_strdup_printf (
"#element, inputbar, message { padding: %dpx;}",
config.
line_padding );
902 const char *str =
"#listview { scrollbar: false; }";
906 const char *str =
"#listview { scrollbar: true; }";
918 #endif // THEME_CONVERTER 924 if ( parent_file != NULL && !g_path_is_absolute ( filename ) ) {
925 char *basedir = g_path_get_dirname ( parent_file );
926 char *path = g_build_filename ( basedir, filename, NULL );
931 GFile *gf = g_file_new_for_path ( filename );
933 filename = g_file_get_path ( gf );
934 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)