diff options
author | Dave Davenport <qball@gmpclient.org> | 2021-06-01 12:17:59 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2021-06-01 12:17:59 +0200 |
commit | 3598ebe60377abf2abd7fd787d61f79c0ddd58b4 (patch) | |
tree | 32785738234fe339a92ef493eadec99ddcf59285 /source | |
parent | 3b297ee80dbddcfbf9f8e08bf3fd65e286b762df (diff) |
[Config] Quick hackish workaround for handling dynamic options from config file
Quick hackish workaround for having options that are added *after*
config file is parsed.
This needs to be replaced once the config system is revamped.
Fixes: #905
Diffstat (limited to 'source')
-rw-r--r-- | source/rofi.c | 1 | ||||
-rw-r--r-- | source/theme.c | 2 | ||||
-rw-r--r-- | source/xrmoptions.c | 38 |
3 files changed, 40 insertions, 1 deletions
diff --git a/source/rofi.c b/source/rofi.c index ba7d0940..9727f9d2 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -620,6 +620,7 @@ static int add_mode ( const char * token ) if ( sw != NULL ) { // Add to available list, so combi can find it. rofi_collect_modi_add ( sw ); + mode_set_config ( sw ); modi[num_modi] = sw; num_modi++; } diff --git a/source/theme.c b/source/theme.c index 2aaa3762..753046d5 100644 --- a/source/theme.c +++ b/source/theme.c @@ -106,7 +106,7 @@ RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance ) return retv; } -Property* rofi_theme_property_copy ( Property *p ) +Property* rofi_theme_property_copy ( const Property *p ) { Property *retv = rofi_theme_property_create ( p->type ); retv->name = g_strdup ( p->name ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 427bb5dd..14b9a66a 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -24,6 +24,8 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ +/** Log domain for this module */ +#define G_LOG_DOMAIN "XrmOptions" #include <config.h> #include <stdio.h> @@ -41,6 +43,8 @@ #include "helper.h" #include "rofi-types.h" + + /** Different sources of configuration. */ const char * const ConfigSourceStr[] = { "Default", @@ -237,6 +241,12 @@ XrmOption *extra_options = NULL; /** Number of entries in extra options array */ unsigned int num_extra_options = 0; +/** This is a big hack, we need to fix this. */ +GList *extra_parsed_options = NULL; + + +static gboolean __config_parser_set_property ( XrmOption *option, const Property *p, char **error ); + void config_parser_add_option ( XrmOptionType type, const char *key, void **value, const char *comment ) { extra_options = g_realloc ( extra_options, ( num_extra_options + 1 ) * sizeof ( XrmOption ) ); @@ -256,7 +266,21 @@ void config_parser_add_option ( XrmOptionType type, const char *key, void **valu break; } + + for ( GList *iter = g_list_first ( extra_parsed_options) ; iter != NULL; iter = g_list_next ( iter ) ) { + if ( g_strcmp0(((Property *)(iter->data))->name, key ) == 0 ){ + char *error = NULL; + g_debug("Setting property from backup list: %s", key); + if ( __config_parser_set_property ( &(extra_options[num_extra_options]), (Property *)(iter->data), &error ) ){ + g_debug("Failed to set property on custom entry: %s", key); + g_free( error ); + } + num_extra_options++; + return; + } + } num_extra_options++; + } /** @@ -397,6 +421,7 @@ static gboolean __config_parser_set_property ( XrmOption *option, const Property return FALSE; } + gboolean config_parse_set_property ( const Property *p, char **error ) { for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) { @@ -412,6 +437,18 @@ gboolean config_parse_set_property ( const Property *p, char **error ) } } *error = g_strdup_printf ( "Option: %s is not found.", p->name ); + + for ( GList *iter = g_list_first ( extra_parsed_options) ; iter != NULL; iter = g_list_next ( iter ) ) { + if ( g_strcmp0(((Property *)(iter->data))->name, p->name ) == 0 ){ + + rofi_theme_property_free ( (Property *)(iter->data)); + iter->data = (void *)rofi_theme_property_copy ( p ) ; + return TRUE; + } + } + g_debug("Adding option: %s to backup list.", p->name); + extra_parsed_options = g_list_append ( extra_parsed_options , rofi_theme_property_copy ( p ) ); + return TRUE; } @@ -432,6 +469,7 @@ void config_xresource_free ( void ) if ( extra_options != NULL ) { g_free ( extra_options ); } + g_list_free_full ( extra_parsed_options, (GDestroyNotify)rofi_theme_property_free ); } static void config_parse_dump_config_option ( FILE *out, XrmOption *option ) |