Added config file support per module
This commit is contained in:
parent
3937dc1c37
commit
d7f7cf634f
22
main.cpp
22
main.cpp
@ -13,6 +13,7 @@
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
|
||||
// POSIX
|
||||
#include <getopt.h>
|
||||
@ -94,7 +95,7 @@ int main(int argc, const char * argv[]) {
|
||||
std::string plugin_dir {"/usr/local/share/screensaver/plugins"};
|
||||
#endif
|
||||
sc::plugin<ScreensaverPlugin>::scan_plugins(plugin_dir, "saver");
|
||||
std::unique_ptr<ScreensaverPlugin> 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<std::string> names {sc::plugin<ScreensaverPlugin>::names()};
|
||||
std::string name {sc::random::choice(names)};
|
||||
saver = sc::plugin<ScreensaverPlugin>::get(name)();
|
||||
saver_name = sc::random::choice(names);
|
||||
} else {
|
||||
saver = sc::plugin<ScreensaverPlugin>::get("Default")();
|
||||
saver_name = "Default";
|
||||
}
|
||||
}
|
||||
for (int i = optind; i < argc; ++i) {
|
||||
try {
|
||||
// process file argv[i]
|
||||
saver = sc::plugin<ScreensaverPlugin>::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<ScreensaverPlugin>::get("Default")();
|
||||
if (saver_name.size() == 0) {
|
||||
saver_name = "Default";
|
||||
std::cerr << "screensaver: using standard 'Default' module\n";
|
||||
}
|
||||
std::unique_ptr<ScreensaverPlugin> saver {sc::plugin<ScreensaverPlugin>::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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user