diff --git a/main.cpp b/main.cpp index 73e287a..b602cdc 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include // POSIX #include @@ -94,7 +95,7 @@ int main(int argc, const char * argv[]) { std::string plugin_dir {"/usr/local/share/screensaver/plugins"}; #endif sc::plugin::scan_plugins(plugin_dir, "saver"); - std::unique_ptr saver; + std::string saver_name; bool random_saver {false}; int opt_char, opt_val; struct option long_options[] = { @@ -133,16 +134,15 @@ int main(int argc, const char * argv[]) { // here when no file args if (random_saver) { std::vector names {sc::plugin::names()}; - std::string name {sc::random::choice(names)}; - saver = sc::plugin::get(name)(); + saver_name = sc::random::choice(names); } else { - saver = sc::plugin::get("Default")(); + saver_name = "Default"; } } for (int i = optind; i < argc; ++i) { try { // process file argv[i] - saver = sc::plugin::get(argv[i])(); + saver_name = argv[i]; if (random_saver) { std::cerr << "screensaver: warning: -r option overridden by file arg\n"; } @@ -168,12 +168,20 @@ int main(int argc, const char * argv[]) { create_image(WIDTH, HEIGHT); // setup screen saver module - if (!saver) { - saver = sc::plugin::get("Default")(); + if (saver_name.size() == 0) { + saver_name = "Default"; std::cerr << "screensaver: using standard 'Default' module\n"; } + std::unique_ptr saver {sc::plugin::get(saver_name)()}; main_saver = saver.get(); main_saver->setup(main_context.get(), {0, 0, WIDTH, HEIGHT}); + std::string config_path {plugin_dir + "/" + saver_name + ".json"}; + if (sc::file_exists(config_path)) { + std::ifstream config_file {config_path}; + nlohmann::json j; + config_file >> j; + main_saver->config(j); + } sc::gui::app().fps(main_saver->fps()); sc::gui::app().add_run_loop_action(draw);