diff --git a/include/theme.h b/include/theme.h index c0182e64..28c8f225 100644 --- a/include/theme.h +++ b/include/theme.h @@ -239,6 +239,13 @@ ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *nam */ void rofi_theme_print ( ThemeWidget *widget ); +/** + * @param widget The widget handle. + * + * Print out the theme and config to the commandline. + */ +void rofi_dump_config ( ThemeWidget *widget ); + /** * @param type The type of the property to create. * diff --git a/include/xrmoptions.h b/include/xrmoptions.h index 791121a3..2a01d72c 100644 --- a/include/xrmoptions.h +++ b/include/xrmoptions.h @@ -165,5 +165,10 @@ char ** config_parser_return_display_help ( unsigned int *length ); * @returns true when failed to set property. */ gboolean config_parse_set_property ( const Property *p, char **error ); + +/** + * @brief Dump configuration in rasi format. + */ +void config_parse_dump_config ( void ); /* @}*/ #endif diff --git a/source/rofi.c b/source/rofi.c index 39013f09..fbce9631 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -267,6 +267,8 @@ static void print_main_application_options ( int is_term ) print_help_msg ( "-show", "[mode]", "Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term ); print_help_msg ( "-no-lazy-grab", "", "Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term ); print_help_msg ( "-no-plugins", "", "Disable loading of external plugins.", NULL, is_term ); + print_help_msg ( "-dump-config", "", "Dump the current configuration and theme in rasi format and exit.", NULL, is_term ); + print_help_msg ( "-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term ); } static void help ( G_GNUC_UNUSED int argc, char **argv ) { @@ -895,6 +897,11 @@ int main ( int argc, char *argv[] ) cleanup (); return EXIT_SUCCESS; } + if ( find_arg ( "-dump-config" ) >= 0 ) { + rofi_dump_config ( rofi_theme ); + cleanup (); + return EXIT_SUCCESS; + } // Dump. // catch help request if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) { diff --git a/source/theme.c b/source/theme.c index b929a9ea..c09f9c52 100644 --- a/source/theme.c +++ b/source/theme.c @@ -290,6 +290,14 @@ void rofi_theme_print ( ThemeWidget *widget ) } } +void rofi_dump_config ( ThemeWidget *widget ) +{ + config_parse_dump_config ( ); + if ( widget != NULL ) { + rofi_theme_print_index ( widget ); + } +} + /** * Main lex parser. */ diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 91d69c3a..03ded07c 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -513,6 +513,75 @@ void config_parse_xresource_dump ( void ) } } +static void config_parse_dump_config_option ( XrmOption *option ) +{ + if ( option->type == xrm_Char ) { + printf ( "/*" ); + } + printf ( "\t%s: ", option->name ); + switch ( option->type ) + { + case xrm_Number: + printf ( "%u", *( option->value.num ) ); + break; + case xrm_SNumber: + printf ( "%i", *( option->value.snum ) ); + break; + case xrm_String: + if ( ( *( option->value.str ) ) != NULL ) { + // TODO should this be escaped? + printf ( "\"%s\"", *( option->value.str ) ); + } + break; + case xrm_Boolean: + printf ( "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" ); + break; + case xrm_Char: + // TODO + if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) { + printf ( "'%c'", *( option->value.charc ) ); + } + else { + printf ( "'\\x%02X'", *( option->value.charc ) ); + } + printf ( " /* unsupported */" ); + break; + default: + break; + } + + printf ( ";" ); + if ( option->type == xrm_Char ) { + printf ( "*/" ); + } + printf ( "\n" ); +} + +void config_parse_dump_config ( void ) +{ + printf ( "configuration {\n" ); + + unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); + for ( unsigned int i = 0; i < entries; ++i ) { + // Skip duplicates. + if ( ( i + 1 ) < entries ) { + if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) { + continue; + } + } + if ( xrmOptions[i].source != CONFIG_DEFAULT ) { + config_parse_dump_config_option ( &( xrmOptions[i] ) ); + } + } + for ( unsigned int i = 0; i < num_extra_options; i++ ) { + if ( extra_options[i].source != CONFIG_DEFAULT ) { + config_parse_dump_config_option ( &( extra_options[i] ) ); + } + } + + printf ( "}\n" ); +} + static void print_option_string ( XrmOption *xo, int is_term ) { int l = strlen ( xo->name );