summaryrefslogtreecommitdiffstats
path: root/source/xrmoptions.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/xrmoptions.c')
-rw-r--r--source/xrmoptions.c110
1 files changed, 73 insertions, 37 deletions
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index 9c017377..04126acd 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -49,6 +49,7 @@ const char * const ConfigSourceStr[] = {
"Default",
"XResources",
"File",
+ "Rasi File",
"Commandline",
};
/** Enumerator of different sources of configuration. */
@@ -57,7 +58,8 @@ enum ConfigSource
CONFIG_DEFAULT = 0,
CONFIG_XRESOURCES = 1,
CONFIG_FILE = 2,
- CONFIG_CMDLINE = 3
+ CONFIG_FILE_THEME = 3,
+ CONFIG_CMDLINE = 4
};
typedef struct
@@ -275,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 );
}
}
@@ -294,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 );
}
@@ -356,58 +379,71 @@ 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 )
+static void __config_parser_set_property ( XrmOption *option, const Property *p )
{
- 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 ( option->type == xrm_String ) {
+ if ( p->type != P_STRING ) {
+ fprintf ( stderr, "Option: %s needs to be set with a string.\n", option->name );
+ return;
}
- if ( xrmValue ) {
- free ( xrmValue );
+ if ( ( option )->mem != NULL ) {
+ g_free ( option->mem );
+ option->mem = NULL;
}
+ *( option->value.str ) = g_strdup ( p->value.s );
- g_free ( name );
+ // Memory
+ ( option )->mem = *( option->value.str );
+ option->source = CONFIG_FILE_THEME;
}
-}
-
-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 );
+ else if ( option->type == xrm_Number ) {
+ if ( p->type != P_INTEGER ) {
+ fprintf ( stderr, "Option: %s needs to be set with a number.\n", option->name );
+ return;
+ }
+ *( option->value.snum ) = p->value.i;
+ option->source = CONFIG_FILE_THEME;
+ }
+ else if ( option->type == xrm_SNumber ) {
+ if ( p->type != P_INTEGER ) {
+ fprintf ( stderr, "Option: %s needs to be set with a number.\n", option->name );
+ return;
+ }
+ *( option->value.num ) = (unsigned int ) ( p->value.i );
+ option->source = CONFIG_FILE_THEME;
+ }
+ else if ( option->type == xrm_Boolean ) {
+ if ( p->type != P_BOOLEAN ) {
+ fprintf ( stderr, "Option: %s needs to be set with a boolean.\n", option->name );
+ return;
+ }
+ *( option->value.num ) = ( p->value.b );
+ option->source = CONFIG_FILE_THEME;
}
}
-void config_parse_xresource_options_dynamic_file ( const char *filename )
+
+void config_parse_set_property ( const Property *p )
{
- if ( !filename ) {
- return;
+ for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
+ XrmOption *op = &( xrmOptions[i] );
+ if ( g_strcmp0 ( op->name, p->name ) == 0 ) {
+ __config_parser_set_property ( op, p );
+ return;
+ }
}
- // Map Xresource entries to rofi config options.
- xcb_xrm_database_t *xDB = xcb_xrm_database_from_file ( filename );
- if ( xDB == NULL ) {
- return;
+ for ( unsigned int i = 0; i < num_extra_options; ++i ) {
+ XrmOption *op = &( extra_options[i] );
+ if ( g_strcmp0 ( op->name, p->name ) == 0 ) {
+ __config_parser_set_property ( op, p );
+ return;
+ }
}
- __config_parse_xresource_options_dynamic ( xDB, CONFIG_FILE );
- xcb_xrm_database_free ( xDB );
}
void config_xresource_free ( void )