1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

[Config system] Add a bit of a hack to auto-add commandline options.

For new config system.
This commit is contained in:
Dave Davenport 2021-06-27 12:21:26 +02:00
parent 33248f511c
commit 067a3b82ad
4 changed files with 67 additions and 10 deletions

View file

@ -70,6 +70,7 @@ const Mode * rofi_get_mode ( unsigned int index );
*/
void rofi_add_error_message ( GString *str );
void rofi_clear_error_messages ( void );
/**
* @param code the code to return
*

View file

@ -66,9 +66,9 @@ const char *const monitor_position_entries[] = {
"on monitor that has mouse pointer"
};
/** copy of the argc for use in commandline argument parser. */
static int stored_argc = 0;
int stored_argc = 0;
/** copy of the argv pointer for use in the commandline argument parser */
static char **stored_argv = NULL;
char **stored_argv = NULL;
char *helper_string_replace_if_exists_v ( char * string, GHashTable *h );

View file

@ -91,6 +91,17 @@ void rofi_add_error_message ( GString *str )
{
list_of_error_msgs = g_list_append ( list_of_error_msgs, str );
}
void rofi_clear_error_messages ( void )
{
if ( list_of_error_msgs ) {
for ( GList *iter = g_list_first ( list_of_error_msgs );
iter != NULL; iter = g_list_next ( iter ) ) {
g_string_free ( (GString *) iter->data, TRUE );
}
g_list_free ( list_of_error_msgs );
list_of_error_msgs = NULL;
}
}
/** Path to the configuration file */
G_MODULE_EXPORT char *config_path = NULL;
@ -457,13 +468,7 @@ static void cleanup ()
g_free ( config_path );
if ( list_of_error_msgs ) {
for ( GList *iter = g_list_first ( list_of_error_msgs );
iter != NULL; iter = g_list_next ( iter ) ) {
g_string_free ( (GString *) iter->data, TRUE );
}
g_list_free ( list_of_error_msgs );
}
rofi_clear_error_messages();
if ( rofi_theme ) {
rofi_theme_free ( rofi_theme );

View file

@ -27,6 +27,7 @@
/** Log domain for this module */
#define G_LOG_DOMAIN "XrmOptions"
#include <ctype.h>
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
@ -301,6 +302,8 @@ static void config_parse_cmd_option ( XrmOption *option )
break;
}
g_free ( key );
}
void config_parse_cmd_options ( void )
@ -313,6 +316,55 @@ void config_parse_cmd_options ( void )
XrmOption *op = &( extra_options[i] );
config_parse_cmd_option ( op );
}
/** copy of the argc for use in commandline argument parser. */
extern int stored_argc;
/** copy of the argv pointer for use in the commandline argument parser */
extern char **stored_argv;
for ( int in = 1; in < (stored_argc-1) ; in ++ ) {
if ( stored_argv[in][0] == '-' ) {
/** TODO: This is a hack, and should be fixed in a nicer way. */
char **tokens = g_strsplit(stored_argv[in], "-", 3);
int count = 1;
for ( int j = 1; tokens && tokens[j]; j++ ){
count++;
}
if ( count > 2 && g_strcmp0(tokens[1], "no") != 0 ){
GString *str = g_string_new("configuration { ");
for ( int j = 1; j < (count-1); j++ ){
g_string_append_printf(str, "%s { ", tokens[j]);
}
g_string_append_printf ( str, "%s: %s;", tokens[count-1], stored_argv[in+1]);
for ( int j = 0; j < (count-1); j++ ){
g_string_append(str, " } ");
}
if ( rofi_theme_parse_string(str->str) == 1 ) {
/** Failed to parse, try again as string. */
rofi_clear_error_messages();
g_string_assign ( str, "configuration { ");
for ( int j = 1; j < (count-1); j++ ){
g_string_append_printf(str, "%s { ", tokens[j]);
}
char *esc = g_strescape(stored_argv[in+1], NULL);
g_string_append_printf ( str, "%s: \"%s\";", tokens[count-1], esc);
g_free(esc);
printf("%s %s\r\n", stored_argv[in], stored_argv[in+1]);
for ( int j = 0; j < (count-1); j++ ){
g_string_append(str, " } ");
}
printf("str: %s\n", str->str);
if ( rofi_theme_parse_string(str->str) == 1 ) {
printf("failed\n");
}
}
g_string_free(str,TRUE);
in++;
}
g_strfreev(tokens);
}
}
}
static gboolean __config_parser_set_property ( XrmOption *option, const Property *p, char **error )
@ -407,7 +459,6 @@ gboolean config_parse_set_property ( const Property *p, char **error )
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;