diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/drun.c | 4 | ||||
-rw-r--r-- | source/mode.c | 3 | ||||
-rw-r--r-- | source/rofi.c | 103 | ||||
-rw-r--r-- | source/theme.c | 2 | ||||
-rw-r--r-- | source/view.c | 2 | ||||
-rw-r--r-- | source/xrmoptions.c | 79 |
6 files changed, 96 insertions, 97 deletions
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 844bb7ef..1eab9d19 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -371,8 +371,8 @@ static void get_apps_history ( DRunModePrivateData *pd ) for ( unsigned int index = 0; index < length; index++ ) { char **st = g_strsplit ( retv[index], ":::", 2 ); if ( st && st[0] && st[1] ) { - if ( ! read_desktop_file ( pd, st[0], st[1] ) ) { - history_remove ( path, retv[index]); + if ( !read_desktop_file ( pd, st[0], st[1] ) ) { + history_remove ( path, retv[index] ); } } g_strfreev ( st ); diff --git a/source/mode.c b/source/mode.c index c3a1456f..e3e24a6d 100644 --- a/source/mode.c +++ b/source/mode.c @@ -17,8 +17,7 @@ int mode_init ( Mode *mode ) { g_return_val_if_fail ( mode != NULL, FALSE ); g_return_val_if_fail ( mode->_init != NULL, FALSE ); - mode->_init ( mode ); - return TRUE; + return mode->_init ( mode ); } void mode_destroy ( Mode *mode ) diff --git a/source/rofi.c b/source/rofi.c index ebdd713e..14a46111 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -65,7 +65,7 @@ // TODO: move this check to mode.c #include "mode-private.h" -#define LOG_DOMAIN "Rofi" +#define LOG_DOMAIN "Rofi" // Pidfile. char *pidfile = NULL; @@ -149,7 +149,7 @@ static int setup () */ static void teardown ( int pfd ) { - g_log ( LOG_DOMAIN , G_LOG_LEVEL_DEBUG, "Teardown"); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Teardown" ); // Cleanup font setup. textbox_cleanup ( ); @@ -305,7 +305,6 @@ static void help ( G_GNUC_UNUSED int argc, char **argv ) } /** - * Function bound by 'atexit'. * Cleanup globally allocated memory. */ static void cleanup () @@ -490,7 +489,6 @@ static int add_mode ( const char * token ) Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { modi[num_modi] = sw; - mode_set_config ( sw ); num_modi++; } else { @@ -512,34 +510,6 @@ static void setup_modi ( void ) } // Free string that was modified by strtok_r g_free ( switcher_str ); - rofi_collect_modi_setup (); -} - -/** - * Load configuration. - * Following priority: (current), X, commandline arguments - */ -static inline void load_configuration ( ) -{ - // Load distro default settings - 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 ); - } - g_free ( etc ); - // Load in config from X resources. - config_parse_xresource_options_file ( config_path ); -} -static inline void load_configuration_dynamic ( ) -{ - // Load distro default settings - gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); - if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { - config_parse_xresource_options_dynamic_file ( etc ); - } - g_free ( etc ); - // Load in config from X resources. - config_parse_xresource_options_dynamic_file ( config_path ); } /** @@ -744,7 +714,7 @@ int main ( int argc, char *argv[] ) #else fprintf ( stdout, "Version: "VERSION "\n" ); #endif - exit ( EXIT_SUCCESS ); + return EXIT_SUCCESS; } // Detect if we are in dmenu mode. @@ -775,10 +745,12 @@ int main ( int argc, char *argv[] ) const char *path = g_get_user_runtime_dir (); if ( path ) { if ( g_mkdir_with_parents ( path, 0700 ) < 0 ) { - fprintf ( stderr, "Failed to create user runtime directory: %s\n", strerror ( errno ) ); - return EXIT_FAILURE; + g_log ( LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Failed to create user runtime directory: %s with error: %s\n", path, strerror ( errno ) ); + pidfile = g_build_filename ( g_get_home_dir (), ".rofi.pid", NULL ); + } + else { + pidfile = g_build_filename ( path, "rofi.pid", NULL ); } - pidfile = g_build_filename ( path, "rofi.pid", NULL ); } config_parser_add_option ( xrm_String, "pid", (void * *) &pidfile, "Pidfile location" ); @@ -795,12 +767,9 @@ int main ( int argc, char *argv[] ) } TICK (); - // Register cleanup function. - atexit ( cleanup ); - - TICK (); if ( setlocale ( LC_ALL, "" ) == NULL ) { fprintf ( stderr, "Failed to set locale.\n" ); + cleanup (); return EXIT_FAILURE; } @@ -811,6 +780,7 @@ int main ( int argc, char *argv[] ) TICK_N ( "Open Display" ); rofi_collect_modi (); + rofi_collect_modi_setup (); TICK_N ( "Collect MODI" ); main_loop = g_main_loop_new ( NULL, FALSE ); @@ -822,10 +792,29 @@ int main ( int argc, char *argv[] ) TICK_N ( "Setup abe" ); if ( find_arg ( "-no-config" ) < 0 ) { - load_configuration ( ); + // Load distro default settings + 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 ); + } + g_free ( etc ); + // Load in config from X resources. + config_parse_xresource_options_file ( config_path ); + + find_arg_str ( "-theme", &( config.theme ) ); + if ( config.theme ) { + TICK_N ( "Parse theme" ); + if ( rofi_theme_parse_file ( config.theme ) ) { + // TODO: instantiate fallback theme.? + rofi_theme_free ( rofi_theme ); + rofi_theme = NULL; + } + TICK_N ( "Parsed theme" ); + } } // Parse command line for settings, independent of other -no-config. config_parse_cmd_options ( ); + TICK_N ( "Load cmd config " ); if ( !dmenu_mode ) { // setup_modi @@ -833,25 +822,6 @@ int main ( int argc, char *argv[] ) TICK_N ( "Setup Modi" ); } - if ( find_arg ( "-no-config" ) < 0 ) { - // Reload for dynamic part. - load_configuration_dynamic ( ); - TICK_N ( "Load config dynamic" ); - } - // Parse command line for settings, independent of other -no-config. - config_parse_cmd_options_dynamic ( ); - TICK_N ( "Load cmd config dynamic" ); - - if ( config.theme ) { - TICK_N ( "Parse theme" ); - if ( rofi_theme_parse_file ( config.theme ) ) { - // TODO: instantiate fallback theme.? - rofi_theme_free ( rofi_theme ); - rofi_theme = NULL; - } - TICK_N ( "Parsed theme" ); - } - const char ** theme_str = find_arg_strv ( "-theme-str" ); if ( theme_str ) { for ( int index = 0; theme_str && theme_str[index]; index++ ) { @@ -868,21 +838,25 @@ int main ( int argc, char *argv[] ) if ( find_arg ( "-dump-theme" ) >= 0 ) { rofi_theme_print ( rofi_theme ); - exit ( EXIT_SUCCESS ); + cleanup (); + return EXIT_SUCCESS; } // Dump. // catch help request if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) { help ( argc, argv ); - exit ( EXIT_SUCCESS ); + cleanup (); + return EXIT_SUCCESS; } if ( find_arg ( "-dump-xresources" ) >= 0 ) { config_parse_xresource_dump (); - exit ( EXIT_SUCCESS ); + cleanup (); + return EXIT_SUCCESS; } if ( find_arg ( "-dump-xresources-theme" ) >= 0 ) { config_parse_xresources_theme_dump (); - exit ( EXIT_SUCCESS ); + cleanup (); + return EXIT_SUCCESS; } if ( ! display_init ( main_loop, display_str ) ) @@ -909,5 +883,6 @@ int main ( int argc, char *argv[] ) // Start mainloop. g_main_loop_run ( main_loop ); teardown ( pfd ); + cleanup (); return return_code; } diff --git a/source/theme.c b/source/theme.c index aa66218e..c04ff1aa 100644 --- a/source/theme.c +++ b/source/theme.c @@ -769,7 +769,7 @@ void rofi_theme_convert_old_theme ( void ) ThemeWidget *walternate = rofi_theme_find_or_create_name ( widget, "alternate" ); rofi_theme_convert_create_property_ht ( widget ); - Property *p= rofi_theme_property_create ( P_INTEGER ); + Property *p = rofi_theme_property_create ( P_INTEGER ); p->name = g_strdup ( "border" ); p->value.i = 0; g_hash_table_replace ( widget->properties, p->name, p ); diff --git a/source/view.c b/source/view.c index df8277f9..23a4c0ca 100644 --- a/source/view.c +++ b/source/view.c @@ -1350,7 +1350,7 @@ void rofi_view_workers_initialize ( void ) void rofi_view_workers_finalize ( void ) { if ( tpool ) { - g_thread_pool_free ( tpool, TRUE, FALSE ); + g_thread_pool_free ( tpool, TRUE, TRUE ); tpool = NULL; } } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 0e0ee836..c103c6d6 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -44,6 +44,7 @@ const char * const ConfigSourceStr[] = { "Default", "XResources", "File", + "Rasi File", "Commandline", }; /** Enumerator of different sources of configuration. */ @@ -52,7 +53,8 @@ enum ConfigSource CONFIG_DEFAULT = 0, CONFIG_XRESOURCES = 1, CONFIG_FILE = 2, - CONFIG_CMDLINE = 3 + CONFIG_FILE_THEME = 3, + CONFIG_CMDLINE = 4 }; typedef struct @@ -325,48 +327,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; + } + 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 ) |