Merge the configuration loading into something more simple (2)

This commit is contained in:
Dave Davenport 2017-03-28 17:13:38 +02:00
parent 9210ce9aad
commit 14b43523be
3 changed files with 21 additions and 74 deletions

View File

@ -76,30 +76,6 @@ void config_parse_xresource_options_file ( const char *filename );
*/
void config_parse_cmd_options ( void );
/**
* Parse dynamic commandline options.
* @ingroup CONFCommandline
*/
void config_parse_cmd_options_dynamic ( void );
/**
* @param xcb Handler object that holds connection to X11 server to fetch the settings from.
*
* Parse the rofi related X resource options of the
* connected X server.
*
* @ingroup CONFXServer
*/
void config_parse_xresource_options_dynamic ( xcb_stuff *xcb );
/**
* @param filename The xresources file to parse
*
* Parses filename and updates the config. For dynamic options.
* @ingroup CONFFile
*/
void config_parse_xresource_options_dynamic_file ( const char *filename );
/**
* Free any allocated memory.
*

View File

@ -1045,14 +1045,11 @@ int main ( int argc, char *argv[] )
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL );
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
config_parse_xresource_options_file ( etc );
config_parse_xresource_options_dynamic_file ( etc );
}
g_free ( etc );
// Load in config from X resources.
config_parse_xresource_options ( xcb );
config_parse_xresource_options_dynamic ( xcb );
config_parse_xresource_options_file ( config_path );
config_parse_xresource_options_dynamic_file ( config_path );
find_arg_str ( "-theme", &(config.theme));
if ( config.theme ) {
@ -1067,7 +1064,6 @@ int main ( int argc, char *argv[] )
}
// Parse command line for settings, independent of other -no-config.
config_parse_cmd_options ( );
config_parse_cmd_options_dynamic ( );
TICK_N ( "Load cmd config " );
if ( !dmenu_mode ) {

View File

@ -277,11 +277,31 @@ static void __config_parse_xresource_options ( xcb_xrm_database_t *xDB, enum Con
g_free ( name );
}
}
static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB, enum ConfigSource source )
{
const char * namePrefix = "rofi";
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
char *name;
name = g_strdup_printf ( "%s.%s", namePrefix, extra_options[i].name );
char *xrmValue = NULL;
if ( xcb_xrm_resource_get_string ( xDB, name, NULL, &xrmValue ) == 0 ) {
config_parser_set ( &( extra_options[i] ), xrmValue, source );
}
if ( xrmValue ) {
free ( xrmValue );
}
g_free ( name );
}
}
void config_parse_xresource_options ( xcb_stuff *xcb )
{
xcb_xrm_database_t *xDB = xcb_xrm_database_from_default ( xcb->connection );
if ( xDB ) {
__config_parse_xresource_options ( xDB, CONFIG_XRESOURCES );
__config_parse_xresource_options_dynamic ( xDB, CONFIG_XRESOURCES );
xcb_xrm_database_free ( xDB );
}
}
@ -296,6 +316,7 @@ void config_parse_xresource_options_file ( const char *filename )
return;
}
__config_parse_xresource_options ( xDB, CONFIG_FILE );
__config_parse_xresource_options_dynamic ( xDB, CONFIG_FILE );
xcb_xrm_database_free ( xDB );
}
@ -358,35 +379,13 @@ void config_parse_cmd_options ( void )
XrmOption *op = &( xrmOptions[i] );
config_parse_cmd_option ( op );
}
}
void config_parse_cmd_options_dynamic ( void )
{
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
XrmOption *op = &( extra_options[i] );
config_parse_cmd_option ( op );
}
}
static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB, enum ConfigSource source )
{
const char * namePrefix = "rofi";
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
char *name;
name = g_strdup_printf ( "%s.%s", namePrefix, extra_options[i].name );
char *xrmValue = NULL;
if ( xcb_xrm_resource_get_string ( xDB, name, NULL, &xrmValue ) == 0 ) {
config_parser_set ( &( extra_options[i] ), xrmValue, source );
}
if ( xrmValue ) {
free ( xrmValue );
}
g_free ( name );
}
}
void config_parser_set_option ( char *option, char *value)
{
@ -406,30 +405,6 @@ void config_parser_set_option ( char *option, char *value)
}
}
void config_parse_xresource_options_dynamic ( xcb_stuff *xcb )
{
char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER );
if ( name ) {
xcb_xrm_database_t *xDB = xcb_xrm_database_from_string ( name );
__config_parse_xresource_options_dynamic ( xDB, CONFIG_XRESOURCES );
xcb_xrm_database_free ( xDB );
g_free ( name );
}
}
void config_parse_xresource_options_dynamic_file ( const char *filename )
{
if ( !filename ) {
return;
}
// Map Xresource entries to rofi config options.
xcb_xrm_database_t *xDB = xcb_xrm_database_from_file ( filename );
if ( xDB == NULL ) {
return;
}
__config_parse_xresource_options_dynamic ( xDB, CONFIG_FILE );
xcb_xrm_database_free ( xDB );
}
void config_xresource_free ( void )
{
for ( unsigned int i = 0; i < ( sizeof ( xrmOptions ) / sizeof ( *xrmOptions ) ); ++i ) {