diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-03-28 22:56:33 +0200 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-03-28 22:56:33 +0200 |
commit | b25439c63390850c5a756dafe00015f46a05cbe2 (patch) | |
tree | d52825d89e3c94e447bffe8e18f576119cadc22d /source/rofi.c | |
parent | c5b49407036986e526c594792e1b64809cd0ce29 (diff) | |
parent | e45f0194d116a69abe77d74116eb5f1cf50e76ed (diff) |
Merge branch 'master' into wip/wayland
Diffstat (limited to 'source/rofi.c')
-rw-r--r-- | source/rofi.c | 103 |
1 files changed, 39 insertions, 64 deletions
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; } |